1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index ac474a6..284cee9 100644
8 @@ -255,6 +255,7 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/exofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 293733f..12d19d0 100644
20 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
21 obj-$(CONFIG_CEPH_FS) += ceph/
22 obj-$(CONFIG_PSTORE) += pstore/
23 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index b2f710e..d211619 100644
32 @@ -2605,6 +2605,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: linux-unionfs@vger.kernel.org
39 +L: aufs-users@lists.sourceforge.net (members only)
40 +W: http://aufs.sourceforge.net
41 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/filesystems/aufs/
44 +F: Documentation/ABI/testing/debugfs-aufs
45 +F: Documentation/ABI/testing/sysfs-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 ea9debf..9e534a3 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -739,6 +739,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 2e7e8d8..9f57bd8 100644
85 @@ -1238,7 +1238,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 4137d96..c91b3e3 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 42f6d25..fa6ae6a 100644
120 @@ -1657,7 +1657,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 int (*update_time)(struct inode *, struct timespec64 *, int);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index 9918655..72c93f3 100644
133 @@ -770,6 +770,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/read_write.c b/fs/read_write.c
147 index 8a2737f..42f64cc 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -489,6 +489,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
154 +vfs_readf_t vfs_readf(struct file *file)
156 + const struct file_operations *fop = file->f_op;
160 + if (fop->read_iter)
161 + return new_sync_read;
162 + return ERR_PTR(-ENOSYS);
165 +vfs_writef_t vfs_writef(struct file *file)
167 + const struct file_operations *fop = file->f_op;
171 + if (fop->write_iter)
172 + return new_sync_write;
173 + return ERR_PTR(-ENOSYS);
176 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
179 diff --git a/fs/splice.c b/fs/splice.c
180 index b3daa97..1dd7f96 100644
183 @@ -838,8 +838,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
185 * Attempt to initiate a splice from pipe to file.
187 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
188 - loff_t *ppos, size_t len, unsigned int flags)
189 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
190 + loff_t *ppos, size_t len, unsigned int flags)
192 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
193 loff_t *, size_t, unsigned int);
194 @@ -855,9 +855,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
196 * Attempt to initiate a splice from a file to a pipe.
198 -static long do_splice_to(struct file *in, loff_t *ppos,
199 - struct pipe_inode_info *pipe, size_t len,
200 - unsigned int flags)
201 +long do_splice_to(struct file *in, loff_t *ppos,
202 + struct pipe_inode_info *pipe, size_t len,
203 + unsigned int flags)
205 ssize_t (*splice_read)(struct file *, loff_t *,
206 struct pipe_inode_info *, size_t, unsigned int);
207 diff --git a/fs/sync.c b/fs/sync.c
208 index b54e054..2860782 100644
212 * wait == 1 case since in that case write_inode() functions do
213 * sync_dirty_buffer() and thus effectively write one block at a time.
215 -static int __sync_filesystem(struct super_block *sb, int wait)
216 +int __sync_filesystem(struct super_block *sb, int wait)
220 diff --git a/include/linux/fs.h b/include/linux/fs.h
221 index 897eae8..7fb92a9 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1286,6 +1286,7 @@ extern void fasync_free(struct fasync_struct *);
225 /* can be called from interrupts */
226 extern void kill_fasync(struct fasync_struct **, int, int);
228 +extern int setfl(int fd, struct file * filp, unsigned long arg);
229 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
230 extern int f_setown(struct file *filp, unsigned long arg, int force);
231 extern void f_delown(struct file *filp);
232 @@ -1747,6 +1748,7 @@ struct file_operations {
233 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
234 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
235 int (*check_flags)(int);
236 + int (*setfl)(struct file *, unsigned long);
237 int (*flock) (struct file *, int, struct file_lock *);
238 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
239 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
240 @@ -1818,6 +1820,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
241 struct iovec *fast_pointer,
242 struct iovec **ret_pointer);
244 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
245 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
247 +vfs_readf_t vfs_readf(struct file *file);
248 +vfs_writef_t vfs_writef(struct file *file);
250 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
251 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
252 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
253 @@ -2243,6 +2251,7 @@ extern int current_umask(void);
254 extern void ihold(struct inode * inode);
255 extern void iput(struct inode *);
256 extern int generic_update_time(struct inode *, struct timespec64 *, int);
257 +extern int update_time(struct inode *, struct timespec64 *, int);
260 extern struct kobject *fs_kobj;
261 @@ -2530,6 +2539,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
265 +extern int __sync_filesystem(struct super_block *, int);
266 extern int sync_filesystem(struct super_block *);
267 extern const struct file_operations def_blk_fops;
268 extern const struct file_operations def_chr_fops;
269 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
270 index b0d0b51..f73ffaa 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -313,6 +313,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
274 return lock->key == key;
277 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
282 @@ -439,6 +441,7 @@ struct lockdep_map { };
284 #define lockdep_depth(tsk) (0)
286 +#define lockdep_is_held(lock) (1)
287 #define lockdep_is_held_type(l, r) (1)
289 #define lockdep_assert_held(l) do { (void)(l); } while (0)
290 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
291 index 3594208..24f5fd1 100644
292 --- a/include/linux/mnt_namespace.h
293 +++ b/include/linux/mnt_namespace.h
295 struct mnt_namespace;
297 struct user_namespace;
300 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
301 struct user_namespace *, struct fs_struct *);
302 extern void put_mnt_ns(struct mnt_namespace *ns);
304 +extern int is_current_mnt_ns(struct vfsmount *mnt);
306 extern const struct file_operations proc_mounts_operations;
307 extern const struct file_operations proc_mountinfo_operations;
308 extern const struct file_operations proc_mountstats_operations;
309 diff --git a/include/linux/splice.h b/include/linux/splice.h
310 index 74b4911..19789fb 100644
311 --- a/include/linux/splice.h
312 +++ b/include/linux/splice.h
313 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
315 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
316 extern const struct pipe_buf_operations default_pipe_buf_ops;
318 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
319 + loff_t *ppos, size_t len, unsigned int flags);
320 +extern long do_splice_to(struct file *in, loff_t *ppos,
321 + struct pipe_inode_info *pipe, size_t len,
322 + unsigned int flags);
324 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
325 index dd13f86..fa6f559 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -140,7 +140,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
329 unsigned long nr_lock_classes;
330 static struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
332 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
333 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
335 if (!hlock->class_idx) {
337 @@ -151,6 +151,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
339 return lock_classes + hlock->class_idx - 1;
341 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
343 #ifdef CONFIG_LOCK_STAT
344 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
345 SPDX-License-Identifier: GPL-2.0
348 diff --git a/fs/proc/base.c b/fs/proc/base.c
349 index 7e9f07bf..3ab5901 100644
352 @@ -2016,7 +2016,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
353 down_read(&mm->mmap_sem);
354 vma = find_exact_vma(mm, vm_start, vm_end);
355 if (vma && vma->vm_file) {
356 - *path = vma->vm_file->f_path;
357 + *path = vma_pr_or_file(vma)->f_path;
361 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
362 index 3b63be6..fb9913b 100644
363 --- a/fs/proc/nommu.c
364 +++ b/fs/proc/nommu.c
365 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
366 file = region->vm_file;
369 - struct inode *inode = file_inode(region->vm_file);
370 + struct inode *inode;
372 + file = vmr_pr_or_file(region);
373 + inode = file_inode(file);
374 dev = inode->i_sb->s_dev;
377 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
378 index 5ea1d64..7865a470 100644
379 --- a/fs/proc/task_mmu.c
380 +++ b/fs/proc/task_mmu.c
381 @@ -305,7 +305,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
382 const char *name = NULL;
385 - struct inode *inode = file_inode(vma->vm_file);
386 + struct inode *inode;
388 + file = vma_pr_or_file(vma);
389 + inode = file_inode(file);
390 dev = inode->i_sb->s_dev;
392 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
393 @@ -1727,7 +1730,7 @@ static int show_numa_map(struct seq_file *m, void *v)
394 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
395 struct vm_area_struct *vma = v;
396 struct numa_maps *md = &numa_priv->md;
397 - struct file *file = vma->vm_file;
398 + struct file *file = vma_pr_or_file(vma);
399 struct mm_struct *mm = vma->vm_mm;
400 struct mm_walk walk = {
401 .hugetlb_entry = gather_hugetlb_stats,
402 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
403 index 0b63d68..400d1c5 100644
404 --- a/fs/proc/task_nommu.c
405 +++ b/fs/proc/task_nommu.c
406 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
410 - struct inode *inode = file_inode(vma->vm_file);
411 + struct inode *inode;
413 + file = vma_pr_or_file(vma);
414 + inode = file_inode(file);
415 dev = inode->i_sb->s_dev;
417 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
418 diff --git a/include/linux/mm.h b/include/linux/mm.h
419 index 0416a72..4a298a9 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1440,6 +1440,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
423 unmap_mapping_range(mapping, holebegin, holelen, 0);
426 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
427 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
429 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
430 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
432 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
434 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
436 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
437 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
440 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
441 +extern void vmr_do_fput(struct vm_region *, const char[], int);
443 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
445 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
446 +#endif /* !CONFIG_MMU */
448 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
449 void *buf, int len, unsigned int gup_flags);
450 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
451 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
452 index 5ed8f62..0122975 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -239,6 +239,7 @@ struct vm_region {
456 unsigned long vm_top; /* region allocated to here */
457 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
458 struct file *vm_file; /* the backing file or NULL */
459 + struct file *vm_prfile; /* the virtual backing file or NULL */
461 int vm_usage; /* region usage count (access under nommu_region_sem) */
462 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
463 @@ -313,6 +314,7 @@ struct vm_area_struct {
464 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
466 struct file * vm_file; /* File we map to (can be NULL). */
467 + struct file *vm_prfile; /* shadow of vm_file */
468 void * vm_private_data; /* was vm_pte (shared mem) */
470 atomic_long_t swap_readahead_info;
471 diff --git a/kernel/fork.c b/kernel/fork.c
472 index f0b5847..fa562c3 100644
475 @@ -505,7 +505,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
476 struct inode *inode = file_inode(file);
477 struct address_space *mapping = file->f_mapping;
481 if (tmp->vm_flags & VM_DENYWRITE)
482 atomic_dec(&inode->i_writecount);
483 i_mmap_lock_write(mapping);
484 diff --git a/mm/Makefile b/mm/Makefile
485 index 26ef77a..b2869af 100644
488 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
489 mm_init.o mmu_context.o percpu.o slab_common.o \
490 compaction.o vmacache.o \
491 interval_tree.o list_lru.o workingset.o \
493 + prfile.o debug.o $(mmu-y)
497 diff --git a/mm/filemap.c b/mm/filemap.c
498 index 52517f2..250f675 100644
501 @@ -2700,7 +2700,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
502 vm_fault_t ret = VM_FAULT_LOCKED;
504 sb_start_pagefault(inode->i_sb);
505 - file_update_time(vmf->vma->vm_file);
506 + vma_file_update_time(vmf->vma);
508 if (page->mapping != inode->i_mapping) {
510 diff --git a/mm/mmap.c b/mm/mmap.c
511 index f7cd9cb..515e88a 100644
514 @@ -180,7 +180,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
515 if (vma->vm_ops && vma->vm_ops->close)
516 vma->vm_ops->close(vma);
518 - fput(vma->vm_file);
520 mpol_put(vma_policy(vma));
523 @@ -905,7 +905,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
526 uprobe_munmap(next, next->vm_start, next->vm_end);
531 anon_vma_merge(vma, next);
532 @@ -1821,8 +1821,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
540 /* Undo any partial mapping done by a device driver. */
541 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
542 @@ -2641,7 +2641,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
546 - get_file(new->vm_file);
549 if (new->vm_ops && new->vm_ops->open)
550 new->vm_ops->open(new);
551 @@ -2660,7 +2660,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
552 if (new->vm_ops && new->vm_ops->close)
553 new->vm_ops->close(new);
555 - fput(new->vm_file);
557 unlink_anon_vmas(new);
559 mpol_put(vma_policy(new));
560 @@ -2822,7 +2822,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
561 struct vm_area_struct *vma;
562 unsigned long populate = 0;
563 unsigned long ret = -EINVAL;
565 + struct file *file, *prfile;
567 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
568 current->comm, current->pid);
569 @@ -2897,10 +2897,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 - file = get_file(vma->vm_file);
575 + file = vma->vm_file;
576 + prfile = vma->vm_prfile;
577 ret = do_mmap_pgoff(vma->vm_file, start, size,
578 prot, flags, pgoff, &populate, NULL);
579 + if (!IS_ERR_VALUE(ret) && file && prfile) {
580 + struct vm_area_struct *new_vma;
582 + new_vma = find_vma(mm, ret);
583 + if (!new_vma->vm_prfile)
584 + new_vma->vm_prfile = prfile;
585 + if (new_vma != vma)
589 + * two fput()s instead of vma_fput(vma),
590 + * coz vma may not be available anymore.
596 up_write(&mm->mmap_sem);
598 @@ -3206,7 +3223,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
599 if (anon_vma_clone(new_vma, vma))
600 goto out_free_mempol;
601 if (new_vma->vm_file)
602 - get_file(new_vma->vm_file);
603 + vma_get_file(new_vma);
604 if (new_vma->vm_ops && new_vma->vm_ops->open)
605 new_vma->vm_ops->open(new_vma);
606 vma_link(mm, new_vma, prev, rb_link, rb_parent);
607 diff --git a/mm/nommu.c b/mm/nommu.c
608 index e4aac33..b27b200 100644
611 @@ -625,7 +625,7 @@ static void __put_nommu_region(struct vm_region *region)
612 up_write(&nommu_region_sem);
615 - fput(region->vm_file);
618 /* IO memory and memory shared directly out of the pagecache
619 * from ramfs/tmpfs mustn't be released here */
620 @@ -763,7 +763,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
621 if (vma->vm_ops && vma->vm_ops->close)
622 vma->vm_ops->close(vma);
624 - fput(vma->vm_file);
626 put_nommu_region(vma->vm_region);
629 @@ -1286,7 +1286,7 @@ unsigned long do_mmap(struct file *file,
630 goto error_just_free;
633 - fput(region->vm_file);
635 kmem_cache_free(vm_region_jar, region);
638 @@ -1361,7 +1361,7 @@ unsigned long do_mmap(struct file *file,
639 up_write(&nommu_region_sem);
642 - fput(region->vm_file);
644 kmem_cache_free(vm_region_jar, region);
647 diff --git a/mm/prfile.c b/mm/prfile.c
649 index 0000000..a27ac36
653 +// SPDX-License-Identifier: GPL-2.0
655 + * Mainly for aufs which mmap(2) different file and wants to print different
656 + * path in /proc/PID/maps.
657 + * Call these functions via macros defined in linux/mm.h.
659 + * See Documentation/filesystems/aufs/design/06mmap.txt
661 + * Copyright (c) 2014-2018 Junjro R. Okajima
662 + * Copyright (c) 2014 Ian Campbell
665 +#include <linux/mm.h>
666 +#include <linux/file.h>
667 +#include <linux/fs.h>
669 +/* #define PRFILE_TRACE */
670 +static inline void prfile_trace(struct file *f, struct file *pr,
671 + const char func[], int line, const char func2[])
675 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
679 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
682 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
684 + prfile_trace(f, pr, func, line, __func__);
685 + file_update_time(f);
687 + file_update_time(pr);
690 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
693 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
695 + prfile_trace(f, pr, func, line, __func__);
696 + return (f && pr) ? pr : f;
699 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
701 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
703 + prfile_trace(f, pr, func, line, __func__);
709 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
711 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
713 + prfile_trace(f, pr, func, line, __func__);
720 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
723 + struct file *f = region->vm_file, *pr = region->vm_prfile;
725 + prfile_trace(f, pr, func, line, __func__);
726 + return (f && pr) ? pr : f;
729 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
731 + struct file *f = region->vm_file, *pr = region->vm_prfile;
733 + prfile_trace(f, pr, func, line, __func__);
738 +#endif /* !CONFIG_MMU */
739 SPDX-License-Identifier: GPL-2.0
740 aufs4.19 standalone patch
742 diff --git a/fs/dcache.c b/fs/dcache.c
743 index 9f57bd8..328a136 100644
746 @@ -1343,6 +1343,7 @@ void d_walk(struct dentry *parent, void *data,
750 +EXPORT_SYMBOL_GPL(d_walk);
753 struct vfsmount *mnt;
754 @@ -2837,6 +2838,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
756 write_sequnlock(&rename_lock);
758 +EXPORT_SYMBOL_GPL(d_exchange);
761 * d_ancestor - search for an ancestor
762 diff --git a/fs/exec.c b/fs/exec.c
763 index 1ebf6e5..a72c294 100644
766 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
767 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
768 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
770 +EXPORT_SYMBOL_GPL(path_noexec);
774 diff --git a/fs/fcntl.c b/fs/fcntl.c
775 index c91b3e3..7751309 100644
778 @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
782 +EXPORT_SYMBOL_GPL(setfl);
784 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
786 diff --git a/fs/file_table.c b/fs/file_table.c
787 index e49af4c..569020f 100644
788 --- a/fs/file_table.c
789 +++ b/fs/file_table.c
790 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
792 return ERR_PTR(-ENFILE);
794 +EXPORT_SYMBOL_GPL(alloc_empty_file);
797 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
798 @@ -323,6 +324,7 @@ void flush_delayed_fput(void)
802 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
804 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
806 @@ -365,6 +367,7 @@ void __fput_sync(struct file *file)
810 +EXPORT_SYMBOL_GPL(__fput_sync);
812 void __init files_init(void)
814 diff --git a/fs/inode.c b/fs/inode.c
815 index fa6ae6a..69d4a6c 100644
818 @@ -1666,6 +1666,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
820 return update_time(inode, time, flags);
822 +EXPORT_SYMBOL_GPL(update_time);
825 * touch_atime - update the access time
826 diff --git a/fs/namespace.c b/fs/namespace.c
827 index 72c93f3..c49803c 100644
830 @@ -437,6 +437,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
831 mnt_dec_writers(real_mount(mnt));
834 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
837 * mnt_drop_write - give up write access to a mount
838 @@ -775,6 +776,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
840 return check_mnt(real_mount(mnt));
842 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
845 * vfsmount lock must be held for write
846 @@ -1832,6 +1834,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
850 +EXPORT_SYMBOL_GPL(iterate_mounts);
852 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
854 diff --git a/fs/notify/group.c b/fs/notify/group.c
855 index c03b836..817f22c 100644
856 --- a/fs/notify/group.c
857 +++ b/fs/notify/group.c
859 #include <linux/rculist.h>
860 #include <linux/wait.h>
861 #include <linux/memcontrol.h>
862 +#include <linux/module.h>
864 #include <linux/fsnotify_backend.h>
865 #include "fsnotify.h"
866 @@ -112,6 +113,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
868 refcount_inc(&group->refcnt);
870 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
873 * Drop a reference to a group. Free it if it's through.
874 @@ -121,6 +123,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
875 if (refcount_dec_and_test(&group->refcnt))
876 fsnotify_final_destroy_group(group);
878 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
881 * Create a new fsnotify_group and hold a reference for the group returned.
882 @@ -150,6 +153,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
886 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
888 int fsnotify_fasync(int fd, struct file *file, int on)
890 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
891 index 59cdb27..ce365c7 100644
892 --- a/fs/notify/mark.c
893 +++ b/fs/notify/mark.c
894 @@ -263,6 +263,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
895 queue_delayed_work(system_unbound_wq, &reaper_work,
896 FSNOTIFY_REAPER_DELAY);
898 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
901 * Get mark reference when we found the mark via lockless traversal of object
902 @@ -417,6 +418,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
903 mutex_unlock(&group->mark_mutex);
904 fsnotify_free_mark(mark);
906 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
909 * Sorting function for lists of fsnotify marks.
910 @@ -632,6 +634,7 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
911 mutex_unlock(&group->mark_mutex);
914 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
917 * Given a list of marks, find the mark associated with given group. If found
918 @@ -754,6 +757,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
919 fsnotify_get_group(group);
922 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
925 * Destroy all marks in destroy_list, waits for SRCU period to finish before
926 diff --git a/fs/open.c b/fs/open.c
927 index 0285ce7..cb81623 100644
930 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
931 inode_unlock(dentry->d_inode);
934 +EXPORT_SYMBOL_GPL(do_truncate);
936 long vfs_truncate(const struct path *path, loff_t length)
938 diff --git a/fs/read_write.c b/fs/read_write.c
939 index 42f64cc..d9cb969 100644
940 --- a/fs/read_write.c
941 +++ b/fs/read_write.c
942 @@ -459,6 +459,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
946 +EXPORT_SYMBOL_GPL(vfs_read);
948 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
950 @@ -499,6 +500,7 @@ vfs_readf_t vfs_readf(struct file *file)
951 return new_sync_read;
952 return ERR_PTR(-ENOSYS);
954 +EXPORT_SYMBOL_GPL(vfs_readf);
956 vfs_writef_t vfs_writef(struct file *file)
958 @@ -510,6 +512,7 @@ vfs_writef_t vfs_writef(struct file *file)
959 return new_sync_write;
960 return ERR_PTR(-ENOSYS);
962 +EXPORT_SYMBOL_GPL(vfs_writef);
964 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
966 @@ -579,6 +582,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
970 +EXPORT_SYMBOL_GPL(vfs_write);
972 static inline loff_t file_pos_read(struct file *file)
974 diff --git a/fs/splice.c b/fs/splice.c
975 index 1dd7f96..a5e3bcb 100644
978 @@ -851,6 +851,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
980 return splice_write(pipe, out, ppos, len, flags);
982 +EXPORT_SYMBOL_GPL(do_splice_from);
985 * Attempt to initiate a splice from a file to a pipe.
986 @@ -880,6 +881,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
988 return splice_read(in, ppos, pipe, len, flags);
990 +EXPORT_SYMBOL_GPL(do_splice_to);
993 * splice_direct_to_actor - splices data directly between two non-pipes
994 diff --git a/fs/sync.c b/fs/sync.c
995 index 2860782..ffd7ea4 100644
998 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
999 sb->s_op->sync_fs(sb, wait);
1000 return __sync_blockdev(sb->s_bdev, wait);
1002 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1005 * Write out and wait upon all dirty data associated with this
1006 diff --git a/fs/xattr.c b/fs/xattr.c
1007 index 0d6a6a4..7ce4701 100644
1010 @@ -295,6 +295,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1011 *xattr_value = value;
1014 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1017 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1018 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1019 index fa6f559..7ac19ef 100644
1020 --- a/kernel/locking/lockdep.c
1021 +++ b/kernel/locking/lockdep.c
1022 @@ -151,6 +151,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1024 return lock_classes + hlock->class_idx - 1;
1026 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1027 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1029 #ifdef CONFIG_LOCK_STAT
1030 diff --git a/kernel/task_work.c b/kernel/task_work.c
1031 index 0fef395..83fb1ec 100644
1032 --- a/kernel/task_work.c
1033 +++ b/kernel/task_work.c
1034 @@ -116,3 +116,4 @@ void task_work_run(void)
1038 +EXPORT_SYMBOL_GPL(task_work_run);
1039 diff --git a/security/commoncap.c b/security/commoncap.c
1040 index 2e489d6..1e146da 100644
1041 --- a/security/commoncap.c
1042 +++ b/security/commoncap.c
1043 @@ -1336,12 +1336,14 @@ int cap_mmap_addr(unsigned long addr)
1047 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1049 int cap_mmap_file(struct file *file, unsigned long reqprot,
1050 unsigned long prot, unsigned long flags)
1054 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1056 #ifdef CONFIG_SECURITY
1058 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1059 index cd97929..424fd23 100644
1060 --- a/security/device_cgroup.c
1061 +++ b/security/device_cgroup.c
1063 #include <linux/device_cgroup.h>
1064 #include <linux/cgroup.h>
1065 #include <linux/ctype.h>
1066 +#include <linux/export.h>
1067 #include <linux/list.h>
1068 #include <linux/uaccess.h>
1069 #include <linux/seq_file.h>
1070 @@ -824,3 +825,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1074 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1075 diff --git a/security/security.c b/security/security.c
1076 index 736e78d..b314539 100644
1077 --- a/security/security.c
1078 +++ b/security/security.c
1079 @@ -542,6 +542,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1081 return call_int_hook(path_rmdir, 0, dir, dentry);
1083 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1085 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1087 @@ -558,6 +559,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1089 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1091 +EXPORT_SYMBOL_GPL(security_path_symlink);
1093 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1094 struct dentry *new_dentry)
1095 @@ -566,6 +568,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1097 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1099 +EXPORT_SYMBOL_GPL(security_path_link);
1101 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1102 const struct path *new_dir, struct dentry *new_dentry,
1103 @@ -593,6 +596,7 @@ int security_path_truncate(const struct path *path)
1105 return call_int_hook(path_truncate, 0, path);
1107 +EXPORT_SYMBOL_GPL(security_path_truncate);
1109 int security_path_chmod(const struct path *path, umode_t mode)
1111 @@ -600,6 +604,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1113 return call_int_hook(path_chmod, 0, path, mode);
1115 +EXPORT_SYMBOL_GPL(security_path_chmod);
1117 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1119 @@ -607,6 +612,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1121 return call_int_hook(path_chown, 0, path, uid, gid);
1123 +EXPORT_SYMBOL_GPL(security_path_chown);
1125 int security_path_chroot(const struct path *path)
1127 @@ -692,6 +698,7 @@ int security_inode_readlink(struct dentry *dentry)
1129 return call_int_hook(inode_readlink, 0, dentry);
1131 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1133 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1135 @@ -707,6 +714,7 @@ int security_inode_permission(struct inode *inode, int mask)
1137 return call_int_hook(inode_permission, 0, inode, mask);
1139 +EXPORT_SYMBOL_GPL(security_inode_permission);
1141 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1143 @@ -878,6 +886,7 @@ int security_file_permission(struct file *file, int mask)
1145 return fsnotify_perm(file, mask);
1147 +EXPORT_SYMBOL_GPL(security_file_permission);
1149 int security_file_alloc(struct file *file)
1151 @@ -937,6 +946,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1153 return ima_file_mmap(file, prot);
1155 +EXPORT_SYMBOL_GPL(security_mmap_file);
1157 int security_mmap_addr(unsigned long addr)
1159 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1160 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1161 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-01-28 14:36:12.215751270 +0100
1163 +What: /debug/aufs/si_<id>/
1165 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1167 + Under /debug/aufs, a directory named si_<id> is created
1168 + per aufs mount, where <id> is a unique id generated
1171 +What: /debug/aufs/si_<id>/plink
1173 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1175 + It has three lines and shows the information about the
1176 + pseudo-link. The first line is a single number
1177 + representing a number of buckets. The second line is a
1178 + number of pseudo-links per buckets (separated by a
1179 + blank). The last line is a single number representing a
1180 + total number of psedo-links.
1181 + When the aufs mount option 'noplink' is specified, it
1182 + will show "1\n0\n0\n".
1184 +What: /debug/aufs/si_<id>/xib
1186 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1188 + It shows the consumed blocks by xib (External Inode Number
1189 + Bitmap), its block size and file size.
1190 + When the aufs mount option 'noxino' is specified, it
1191 + will be empty. About XINO files, see the aufs manual.
1193 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1195 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1197 + It shows the consumed blocks by xino (External Inode Number
1198 + Translation Table), its link count, block size and file
1200 + Due to the file size limit, there may exist multiple
1201 + xino files per branch. In this case, "-N" is added to
1202 + the filename and it corresponds to the index of the
1203 + internal xino array. "-0" is omitted.
1204 + When the aufs mount option 'noxino' is specified, Those
1205 + entries won't exist. About XINO files, see the aufs
1208 +What: /debug/aufs/si_<id>/xigen
1210 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1212 + It shows the consumed blocks by xigen (External Inode
1213 + Generation Table), its block size and file size.
1214 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1216 + When the aufs mount option 'noxino' is specified, it
1217 + will be empty. About XINO files, see the aufs manual.
1218 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1219 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1220 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-01-28 14:36:12.215751270 +0100
1222 +What: /sys/fs/aufs/si_<id>/
1224 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1226 + Under /sys/fs/aufs, a directory named si_<id> is created
1227 + per aufs mount, where <id> is a unique id generated
1230 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1232 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1234 + It shows the abolute path of a member directory (which
1235 + is called branch) in aufs, and its permission.
1237 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1239 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1241 + It shows the id of a member directory (which is called
1244 +What: /sys/fs/aufs/si_<id>/xi_path
1246 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1248 + It shows the abolute path of XINO (External Inode Number
1249 + Bitmap, Translation Table and Generation Table) file
1250 + even if it is the default path.
1251 + When the aufs mount option 'noxino' is specified, it
1252 + will be empty. About XINO files, see the aufs manual.
1253 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1254 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1255 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2019-01-28 14:36:12.215751270 +0100
1258 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1260 +# This program is free software; you can redistribute it and/or modify
1261 +# it under the terms of the GNU General Public License as published by
1262 +# the Free Software Foundation; either version 2 of the License, or
1263 +# (at your option) any later version.
1265 +# This program is distributed in the hope that it will be useful,
1266 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1267 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1268 +# GNU General Public License for more details.
1270 +# You should have received a copy of the GNU General Public License
1271 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1274 +----------------------------------------
1276 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1277 +1. abbrev. for "advanced multi-layered unification filesystem".
1278 +2. abbrev. for "another unionfs".
1279 +3. abbrev. for "auf das" in German which means "on the" in English.
1280 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1281 + But "Filesystem aufs Filesystem" is hard to understand.
1282 +4. abbrev. for "African Urban Fashion Show".
1284 +AUFS is a filesystem with features:
1285 +- multi layered stackable unification filesystem, the member directory
1286 + is called as a branch.
1287 +- branch permission and attribute, 'readonly', 'real-readonly',
1288 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1290 +- internal "file copy-on-write".
1291 +- logical deletion, whiteout.
1292 +- dynamic branch manipulation, adding, deleting and changing permission.
1293 +- allow bypassing aufs, user's direct branch access.
1294 +- external inode number translation table and bitmap which maintains the
1295 + persistent aufs inode number.
1296 +- seekable directory, including NFS readdir.
1297 +- file mapping, mmap and sharing pages.
1298 +- pseudo-link, hardlink over branches.
1299 +- loopback mounted filesystem as a branch.
1300 +- several policies to select one among multiple writable branches.
1301 +- revert a single systemcall when an error occurs in aufs.
1305 +Multi Layered Stackable Unification Filesystem
1306 +----------------------------------------------------------------------
1307 +Most people already knows what it is.
1308 +It is a filesystem which unifies several directories and provides a
1309 +merged single directory. When users access a file, the access will be
1310 +passed/re-directed/converted (sorry, I am not sure which English word is
1311 +correct) to the real file on the member filesystem. The member
1312 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1313 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1314 +readonly branch is handled by creating 'whiteout' on the upper writable
1317 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1318 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1319 +different approaches to implement the merged-view.
1320 +The former tries putting it into VFS, and the latter implements as a
1321 +separate filesystem.
1322 +(If I misunderstand about these implementations, please let me know and
1323 +I shall correct it. Because it is a long time ago when I read their
1324 +source files last time).
1326 +UnionMount's approach will be able to small, but may be hard to share
1327 +branches between several UnionMount since the whiteout in it is
1328 +implemented in the inode on branch filesystem and always
1329 +shared. According to Bharata's post, readdir does not seems to be
1331 +There are several missing features known in this implementations such as
1332 +- for users, the inode number may change silently. eg. copy-up.
1333 +- link(2) may break by copy-up.
1334 +- read(2) may get an obsoleted filedata (fstat(2) too).
1335 +- fcntl(F_SETLK) may be broken by copy-up.
1336 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1339 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1340 +merged into mainline. This is another implementation of UnionMount as a
1341 +separated filesystem. All the limitations and known problems which
1342 +UnionMount are equally inherited to "overlay" filesystem.
1344 +Unionfs has a longer history. When I started implementing a stackable
1345 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1346 +inode, dentry and file objects and they have an array pointing lower
1347 +same kind objects. After contributing many patches for Unionfs, I
1348 +re-started my project AUFS (Jun 2006).
1350 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1351 +implemented my own ideas, approaches and enhancements and it became
1352 +totally different one.
1354 +Comparing DM snapshot and fs based implementation
1355 +- the number of bytes to be copied between devices is much smaller.
1356 +- the type of filesystem must be one and only.
1357 +- the fs must be writable, no readonly fs, even for the lower original
1358 + device. so the compression fs will not be usable. but if we use
1359 + loopback mount, we may address this issue.
1361 + mount /cdrom/squashfs.img /sq
1362 + losetup /sq/ext2.img
1363 + losetup /somewhere/cow
1364 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1365 +- it will be difficult (or needs more operations) to extract the
1366 + difference between the original device and COW.
1367 +- DM snapshot-merge may help a lot when users try merging. in the
1368 + fs-layer union, users will use rsync(1).
1370 +You may want to read my old paper "Filesystems in LiveCD"
1371 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1374 +Several characters/aspects/persona of aufs
1375 +----------------------------------------------------------------------
1377 +Aufs has several characters, aspects or persona.
1378 +1. a filesystem, callee of VFS helper
1379 +2. sub-VFS, caller of VFS helper for branches
1380 +3. a virtual filesystem which maintains persistent inode number
1381 +4. reader/writer of files on branches such like an application
1383 +1. Callee of VFS Helper
1384 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1385 +unlink(2) from an application reaches sys_unlink() kernel function and
1386 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1387 +calls filesystem specific unlink operation. Actually aufs implements the
1388 +unlink operation but it behaves like a redirector.
1390 +2. Caller of VFS Helper for Branches
1391 +aufs_unlink() passes the unlink request to the branch filesystem as if
1392 +it were called from VFS. So the called unlink operation of the branch
1393 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1394 +every necessary pre/post operation for the branch filesystem.
1395 +- acquire the lock for the parent dir on a branch
1396 +- lookup in a branch
1397 +- revalidate dentry on a branch
1398 +- mnt_want_write() for a branch
1399 +- vfs_unlink() for a branch
1400 +- mnt_drop_write() for a branch
1401 +- release the lock on a branch
1403 +3. Persistent Inode Number
1404 +One of the most important issue for a filesystem is to maintain inode
1405 +numbers. This is particularly important to support exporting a
1406 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1407 +backend block device for its own. But some storage is necessary to
1408 +keep and maintain the inode numbers. It may be a large space and may not
1409 +suit to keep in memory. Aufs rents some space from its first writable
1410 +branch filesystem (by default) and creates file(s) on it. These files
1411 +are created by aufs internally and removed soon (currently) keeping
1413 +Note: Because these files are removed, they are totally gone after
1414 + unmounting aufs. It means the inode numbers are not persistent
1415 + across unmount or reboot. I have a plan to make them really
1416 + persistent which will be important for aufs on NFS server.
1418 +4. Read/Write Files Internally (copy-on-write)
1419 +Because a branch can be readonly, when you write a file on it, aufs will
1420 +"copy-up" it to the upper writable branch internally. And then write the
1421 +originally requested thing to the file. Generally kernel doesn't
1422 +open/read/write file actively. In aufs, even a single write may cause a
1423 +internal "file copy". This behaviour is very similar to cp(1) command.
1425 +Some people may think it is better to pass such work to user space
1426 +helper, instead of doing in kernel space. Actually I am still thinking
1427 +about it. But currently I have implemented it in kernel space.
1428 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1429 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1430 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2019-01-28 14:36:12.215751270 +0100
1433 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1435 +# This program is free software; you can redistribute it and/or modify
1436 +# it under the terms of the GNU General Public License as published by
1437 +# the Free Software Foundation; either version 2 of the License, or
1438 +# (at your option) any later version.
1440 +# This program is distributed in the hope that it will be useful,
1441 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1442 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1443 +# GNU General Public License for more details.
1445 +# You should have received a copy of the GNU General Public License
1446 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1448 +Basic Aufs Internal Structure
1450 +Superblock/Inode/Dentry/File Objects
1451 +----------------------------------------------------------------------
1452 +As like an ordinary filesystem, aufs has its own
1453 +superblock/inode/dentry/file objects. All these objects have a
1454 +dynamically allocated array and store the same kind of pointers to the
1455 +lower filesystem, branch.
1456 +For example, when you build a union with one readwrite branch and one
1457 +readonly, mounted /au, /rw and /ro respectively.
1459 +- /ro/fileA exists but /rw/fileA
1461 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1462 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1463 +- [0] = NULL (because /rw/fileA doesn't exist)
1466 +This style of an array is essentially same to the aufs
1467 +superblock/inode/dentry/file objects.
1469 +Because aufs supports manipulating branches, ie. add/delete/change
1470 +branches dynamically, these objects has its own generation. When
1471 +branches are changed, the generation in aufs superblock is
1472 +incremented. And a generation in other object are compared when it is
1473 +accessed. When a generation in other objects are obsoleted, aufs
1474 +refreshes the internal array.
1478 +----------------------------------------------------------------------
1479 +Additionally aufs superblock has some data for policies to select one
1480 +among multiple writable branches, XIB files, pseudo-links and kobject.
1481 +See below in detail.
1482 +About the policies which supports copy-down a directory, see
1483 +wbr_policy.txt too.
1486 +Branch and XINO(External Inode Number Translation Table)
1487 +----------------------------------------------------------------------
1488 +Every branch has its own xino (external inode number translation table)
1489 +file. The xino file is created and unlinked by aufs internally. When two
1490 +members of a union exist on the same filesystem, they share the single
1492 +The struct of a xino file is simple, just a sequence of aufs inode
1493 +numbers which is indexed by the lower inode number.
1494 +In the above sample, assume the inode number of /ro/fileA is i111 and
1495 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1496 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1498 +When the inode numbers are not contiguous, the xino file will be sparse
1499 +which has a hole in it and doesn't consume as much disk space as it
1500 +might appear. If your branch filesystem consumes disk space for such
1501 +holes, then you should specify 'xino=' option at mounting aufs.
1503 +Aufs has a mount option to free the disk blocks for such holes in XINO
1504 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1505 +meet a problem of disk shortage due to XINO files, then you should try
1506 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1507 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1508 +the holes in XINO files.
1510 +Also a writable branch has three kinds of "whiteout bases". All these
1511 +are existed when the branch is joined to aufs, and their names are
1512 +whiteout-ed doubly, so that users will never see their names in aufs
1514 +1. a regular file which will be hardlinked to all whiteouts.
1515 +2. a directory to store a pseudo-link.
1516 +3. a directory to store an "orphan"-ed file temporary.
1519 + When you remove a file on a readonly branch, aufs handles it as a
1520 + logical deletion and creates a whiteout on the upper writable branch
1521 + as a hardlink of this file in order not to consume inode on the
1524 + See below, Pseudo-link.
1526 + When "fileC" exists on the lower readonly branch only and it is
1527 + opened and removed with its parent dir, and then user writes
1528 + something into it, then aufs copies-up fileC to this
1529 + directory. Because there is no other dir to store fileC. After
1530 + creating a file under this dir, the file is unlinked.
1532 +Because aufs supports manipulating branches, ie. add/delete/change
1533 +dynamically, a branch has its own id. When the branch order changes,
1534 +aufs finds the new index by searching the branch id.
1538 +----------------------------------------------------------------------
1539 +Assume "fileA" exists on the lower readonly branch only and it is
1540 +hardlinked to "fileB" on the branch. When you write something to fileA,
1541 +aufs copies-up it to the upper writable branch. Additionally aufs
1542 +creates a hardlink under the Pseudo-link Directory of the writable
1543 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1544 +simple list. If fileB is read after unlinking fileA, aufs returns
1545 +filedata from the pseudo-link instead of the lower readonly
1546 +branch. Because the pseudo-link is based upon the inode, to keep the
1547 +inode number by xino (see above) is essentially necessary.
1549 +All the hardlinks under the Pseudo-link Directory of the writable branch
1550 +should be restored in a proper location later. Aufs provides a utility
1551 +to do this. The userspace helpers executed at remounting and unmounting
1553 +During this utility is running, it puts aufs into the pseudo-link
1554 +maintenance mode. In this mode, only the process which began the
1555 +maintenance mode (and its child processes) is allowed to operate in
1556 +aufs. Some other processes which are not related to the pseudo-link will
1557 +be allowed to run too, but the rest have to return an error or wait
1558 +until the maintenance mode ends. If a process already acquires an inode
1559 +mutex (in VFS), it has to return an error.
1562 +XIB(external inode number bitmap)
1563 +----------------------------------------------------------------------
1564 +Addition to the xino file per a branch, aufs has an external inode number
1565 +bitmap in a superblock object. It is also an internal file such like a
1567 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1569 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1571 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1572 +reduce the number of consumed disk blocks for these files.
1575 +Virtual or Vertical Dir, and Readdir in Userspace
1576 +----------------------------------------------------------------------
1577 +In order to support multiple layers (branches), aufs readdir operation
1578 +constructs a virtual dir block on memory. For readdir, aufs calls
1579 +vfs_readdir() internally for each dir on branches, merges their entries
1580 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1581 +object. So the file object has its entry list until it is closed. The
1582 +entry list will be updated when the file position is zero and becomes
1583 +obsoleted. This decision is made in aufs automatically.
1585 +The dynamically allocated memory block for the name of entries has a
1586 +unit of 512 bytes (by default) and stores the names contiguously (no
1587 +padding). Another block for each entry is handled by kmem_cache too.
1588 +During building dir blocks, aufs creates hash list and judging whether
1589 +the entry is whiteouted by its upper branch or already listed.
1590 +The merged result is cached in the corresponding inode object and
1591 +maintained by a customizable life-time option.
1593 +Some people may call it can be a security hole or invite DoS attack
1594 +since the opened and once readdir-ed dir (file object) holds its entry
1595 +list and becomes a pressure for system memory. But I'd say it is similar
1596 +to files under /proc or /sys. The virtual files in them also holds a
1597 +memory page (generally) while they are opened. When an idea to reduce
1598 +memory for them is introduced, it will be applied to aufs too.
1599 +For those who really hate this situation, I've developed readdir(3)
1600 +library which operates this merging in userspace. You just need to set
1601 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1602 +kernel space for readdir(3).
1606 +----------------------------------------------------------------------
1607 +Aufs sometimes requires privilege access to a branch. For instance,
1608 +in copy-up/down operation. When a user process is going to make changes
1609 +to a file which exists in the lower readonly branch only, and the mode
1610 +of one of ancestor directories may not be writable by a user
1611 +process. Here aufs copy-up the file with its ancestors and they may
1612 +require privilege to set its owner/group/mode/etc.
1613 +This is a typical case of a application character of aufs (see
1616 +Aufs uses workqueue synchronously for this case. It creates its own
1617 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1618 +passes the request to call mkdir or write (for example), and wait for
1619 +its completion. This approach solves a problem of a signal handler
1621 +If aufs didn't adopt the workqueue and changed the privilege of the
1622 +process, then the process may receive the unexpected SIGXFSZ or other
1625 +Also aufs uses the system global workqueue ("events" kernel thread) too
1626 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1627 +whiteout base and etc. This is unrelated to a privilege.
1628 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1629 +superblock at the beginning, at the same time waits for the completion
1630 +of all queued asynchronous tasks.
1634 +----------------------------------------------------------------------
1635 +The whiteout in aufs is very similar to Unionfs's. That is represented
1636 +by its filename. UnionMount takes an approach of a file mode, but I am
1637 +afraid several utilities (find(1) or something) will have to support it.
1639 +Basically the whiteout represents "logical deletion" which stops aufs to
1640 +lookup further, but also it represents "dir is opaque" which also stop
1643 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1644 +In order to make several functions in a single systemcall to be
1645 +revertible, aufs adopts an approach to rename a directory to a temporary
1646 +unique whiteouted name.
1647 +For example, in rename(2) dir where the target dir already existed, aufs
1648 +renames the target dir to a temporary unique whiteouted name before the
1649 +actual rename on a branch, and then handles other actions (make it opaque,
1650 +update the attributes, etc). If an error happens in these actions, aufs
1651 +simply renames the whiteouted name back and returns an error. If all are
1652 +succeeded, aufs registers a function to remove the whiteouted unique
1653 +temporary name completely and asynchronously to the system global
1658 +----------------------------------------------------------------------
1659 +It is a well-known feature or concept.
1660 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1661 +internally and makes change to the new file on the upper writable branch.
1662 +When the trigger systemcall does not update the timestamps of the parent
1663 +dir, aufs reverts it after copy-up.
1666 +Move-down (aufs3.9 and later)
1667 +----------------------------------------------------------------------
1668 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1669 +the lower readonly branch to the upper writable branch when a user
1670 +changes something about the file.
1671 +"Move-down" is an opposite action of copy-up. Basically this action is
1672 +ran manually instead of automatically and internally.
1673 +For desgin and implementation, aufs has to consider these issues.
1674 +- whiteout for the file may exist on the lower branch.
1675 +- ancestor directories may not exist on the lower branch.
1676 +- diropq for the ancestor directories may exist on the upper branch.
1677 +- free space on the lower branch will reduce.
1678 +- another access to the file may happen during moving-down, including
1679 + UDBA (see "Revalidate Dentry and UDBA").
1680 +- the file should not be hard-linked nor pseudo-linked. they should be
1681 + handled by auplink utility later.
1683 +Sometimes users want to move-down a file from the upper writable branch
1684 +to the lower readonly or writable branch. For instance,
1685 +- the free space of the upper writable branch is going to run out.
1686 +- create a new intermediate branch between the upper and lower branch.
1689 +For this purpose, use "aumvdown" command in aufs-util.git.
1690 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1691 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1692 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2019-01-28 14:36:12.215751270 +0100
1695 +# Copyright (C) 2015-2018 Junjiro R. Okajima
1697 +# This program is free software; you can redistribute it and/or modify
1698 +# it under the terms of the GNU General Public License as published by
1699 +# the Free Software Foundation; either version 2 of the License, or
1700 +# (at your option) any later version.
1702 +# This program is distributed in the hope that it will be useful,
1703 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1704 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1705 +# GNU General Public License for more details.
1707 +# You should have received a copy of the GNU General Public License
1708 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1710 +Support for a branch who has its ->atomic_open()
1711 +----------------------------------------------------------------------
1712 +The filesystems who implement its ->atomic_open() are not majority. For
1713 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1714 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1715 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1716 +sure whether all filesystems who have ->atomic_open() behave like this,
1717 +but NFSv4 surely returns the error.
1719 +In order to support ->atomic_open() for aufs, there are a few
1722 +A. Introduce aufs_atomic_open()
1723 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1725 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1726 + an aufs user Pip Cet's approach
1727 + - calls aufs_create(), VFS finish_open() and notify_change().
1728 + - pass fake-mode to finish_open(), and then correct the mode by
1730 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1731 + - no aufs_atomic_open().
1732 + - aufs_lookup() registers the TID to an aufs internal object.
1733 + - aufs_create() does nothing when the matching TID is registered, but
1734 + registers the mode.
1735 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1736 + TID is registered.
1737 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1739 + - no aufs_atomic_open().
1740 + - aufs_create() registers the TID to an internal object. this info
1741 + represents "this process created this file just now."
1742 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1743 + registered TID and re-try open() with superuser's credential.
1745 +Pros and cons for each approach.
1748 + - straightforward but highly depends upon VFS internal.
1749 + - the atomic behavaiour is kept.
1750 + - some of parameters such as nameidata are hard to reproduce for
1754 + - easy to implement.
1755 + - the atomic behavaiour is lost.
1757 + - the atomic behavaiour is kept.
1758 + - dirty and tricky.
1759 + - VFS checks whether the file is created correctly after calling
1760 + ->create(), which means this approach doesn't work.
1762 + - easy to implement.
1763 + - the atomic behavaiour is lost.
1764 + - to open a file with superuser's credential and give it to a user
1765 + process is a bad idea, since the file object keeps the credential
1766 + in it. It may affect LSM or something. This approach doesn't work
1769 +The approach A is ideal, but it hard to implement. So here is a
1770 +variation of A, which is to be implemented.
1772 +A-1. Introduce aufs_atomic_open()
1773 + - calls branch fs ->atomic_open() if exists. otherwise calls
1774 + vfs_create() and finish_open().
1775 + - the demerit is that the several checks after branch fs
1776 + ->atomic_open() are lost. in the ordinary case, the checks are
1777 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1778 + be implemented in aufs, but not all I am afraid.
1779 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1780 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1781 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2019-01-28 14:36:12.215751270 +0100
1784 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1786 +# This program is free software; you can redistribute it and/or modify
1787 +# it under the terms of the GNU General Public License as published by
1788 +# the Free Software Foundation; either version 2 of the License, or
1789 +# (at your option) any later version.
1791 +# This program is distributed in the hope that it will be useful,
1792 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1793 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1794 +# GNU General Public License for more details.
1796 +# You should have received a copy of the GNU General Public License
1797 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1800 +----------------------------------------------------------------------
1801 +Since aufs has a character of sub-VFS (see Introduction), it operates
1802 +lookup for branches as VFS does. It may be a heavy work. But almost all
1803 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1804 +directly connected to its parent. Digging down the directory hierarchy
1805 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1808 +When a branch is a remote filesystem, aufs basically relies upon its
1809 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1811 +For d_revalidate, aufs implements three levels of revalidate tests. See
1812 +"Revalidate Dentry and UDBA" in detail.
1815 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1816 +----------------------------------------------------------------------
1817 +Let's try case study.
1818 +- aufs has two branches, upper readwrite and lower readonly.
1820 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1821 +- user invoked "chmod a+rx /au/dirA"
1822 +- the internal copy-up is activated and "/rw/dirA" is created and its
1823 + permission bits are set to world readable.
1824 +- then "/au/dirA" becomes world readable?
1826 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1827 +or it may be a natively readonly filesystem. If aufs respects the lower
1828 +branch, it should not respond readdir request from other users. But user
1829 +allowed it by chmod. Should really aufs rejects showing the entries
1832 +To be honest, I don't have a good solution for this case. So aufs
1833 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1835 +When dirperm1 is specified, aufs checks only the highest one for the
1836 +directory permission, and shows the entries. Otherwise, as usual, checks
1837 +every dir existing on all branches and rejects the request.
1839 +As a side effect, dirperm1 option improves the performance of aufs
1840 +because the number of permission check is reduced when the number of
1844 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1845 +----------------------------------------------------------------------
1846 +Generally VFS helpers re-validate a dentry as a part of lookup.
1847 +0. digging down the directory hierarchy.
1848 +1. lock the parent dir by its i_mutex.
1849 +2. lookup the final (child) entry.
1851 +4. call the actual operation (create, unlink, etc.)
1852 +5. unlock the parent dir
1854 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1855 +called. Actually aufs implements it and checks the dentry on a branch is
1857 +But it is not enough. Because aufs has to release the lock for the
1858 +parent dir on a branch at the end of ->lookup() (step 2) and
1859 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1861 +If the file on a branch is changed directly, eg. bypassing aufs, after
1862 +aufs released the lock, then the subsequent operation may cause
1863 +something unpleasant result.
1865 +This situation is a result of VFS architecture, ->lookup() and
1866 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1867 +design from VFS's point of view. It is just not suitable for sub-VFS
1870 +Aufs supports such case by three level of revalidation which is
1871 +selectable by user.
1872 +1. Simple Revalidate
1873 + Addition to the native flow in VFS's, confirm the child-parent
1874 + relationship on the branch just after locking the parent dir on the
1875 + branch in the "actual operation" (step 4). When this validation
1876 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1877 + checks the validation of the dentry on branches.
1878 +2. Monitor Changes Internally by Inotify/Fsnotify
1879 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1880 + the dentry on the branch, and returns EBUSY if it finds different
1882 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1883 + during it is in cache. When the event is notified, aufs registers a
1884 + function to kernel 'events' thread by schedule_work(). And the
1885 + function sets some special status to the cached aufs dentry and inode
1886 + private data. If they are not cached, then aufs has nothing to
1887 + do. When the same file is accessed through aufs (step 0-3) later,
1888 + aufs will detect the status and refresh all necessary data.
1889 + In this mode, aufs has to ignore the event which is fired by aufs
1891 +3. No Extra Validation
1892 + This is the simplest test and doesn't add any additional revalidation
1893 + test, and skip the revalidation in step 4. It is useful and improves
1894 + aufs performance when system surely hide the aufs branches from user,
1895 + by over-mounting something (or another method).
1896 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1897 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1898 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2019-01-28 14:36:12.215751270 +0100
1901 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1903 +# This program is free software; you can redistribute it and/or modify
1904 +# it under the terms of the GNU General Public License as published by
1905 +# the Free Software Foundation; either version 2 of the License, or
1906 +# (at your option) any later version.
1908 +# This program is distributed in the hope that it will be useful,
1909 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1910 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1911 +# GNU General Public License for more details.
1913 +# You should have received a copy of the GNU General Public License
1914 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1916 +Branch Manipulation
1918 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1919 +and changing its permission/attribute, there are a lot of works to do.
1923 +----------------------------------------------------------------------
1924 +o Confirm the adding dir exists outside of aufs, including loopback
1925 + mount, and its various attributes.
1926 +o Initialize the xino file and whiteout bases if necessary.
1929 +o Check the owner/group/mode of the directory
1930 + When the owner/group/mode of the adding directory differs from the
1931 + existing branch, aufs issues a warning because it may impose a
1933 + For example, when a upper writable branch has a world writable empty
1934 + top directory, a malicious user can create any files on the writable
1935 + branch directly, like copy-up and modify manually. If something like
1936 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1937 + writable branch, and the writable branch is world-writable, then a
1938 + malicious guy may create /etc/passwd on the writable branch directly
1939 + and the infected file will be valid in aufs.
1940 + I am afraid it can be a security issue, but aufs can do nothing except
1941 + producing a warning.
1945 +----------------------------------------------------------------------
1946 +o Confirm the deleting branch is not busy
1947 + To be general, there is one merit to adopt "remount" interface to
1948 + manipulate branches. It is to discard caches. At deleting a branch,
1949 + aufs checks the still cached (and connected) dentries and inodes. If
1950 + there are any, then they are all in-use. An inode without its
1951 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1953 + For the cached one, aufs checks whether the same named entry exists on
1955 + If the cached one is a directory, because aufs provides a merged view
1956 + to users, as long as one dir is left on any branch aufs can show the
1957 + dir to users. In this case, the branch can be removed from aufs.
1958 + Otherwise aufs rejects deleting the branch.
1960 + If any file on the deleting branch is opened by aufs, then aufs
1964 +Modify the Permission of a Branch
1965 +----------------------------------------------------------------------
1966 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1969 +o rw --> ro: Confirm the modifying branch is not busy
1970 + Aufs rejects the request if any of these conditions are true.
1971 + - a file on the branch is mmap-ed.
1972 + - a regular file on the branch is opened for write and there is no
1973 + same named entry on the upper branch.
1974 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1975 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1976 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2019-01-28 14:36:12.215751270 +0100
1979 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1981 +# This program is free software; you can redistribute it and/or modify
1982 +# it under the terms of the GNU General Public License as published by
1983 +# the Free Software Foundation; either version 2 of the License, or
1984 +# (at your option) any later version.
1986 +# This program is distributed in the hope that it will be useful,
1987 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1988 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1989 +# GNU General Public License for more details.
1991 +# You should have received a copy of the GNU General Public License
1992 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1994 +Policies to Select One among Multiple Writable Branches
1995 +----------------------------------------------------------------------
1996 +When the number of writable branch is more than one, aufs has to decide
1997 +the target branch for file creation or copy-up. By default, the highest
1998 +writable branch which has the parent (or ancestor) dir of the target
1999 +file is chosen (top-down-parent policy).
2000 +By user's request, aufs implements some other policies to select the
2001 +writable branch, for file creation several policies, round-robin,
2002 +most-free-space, and other policies. For copy-up, top-down-parent,
2003 +bottom-up-parent, bottom-up and others.
2005 +As expected, the round-robin policy selects the branch in circular. When
2006 +you have two writable branches and creates 10 new files, 5 files will be
2007 +created for each branch. mkdir(2) systemcall is an exception. When you
2008 +create 10 new directories, all will be created on the same branch.
2009 +And the most-free-space policy selects the one which has most free
2010 +space among the writable branches. The amount of free space will be
2011 +checked by aufs internally, and users can specify its time interval.
2013 +The policies for copy-up is more simple,
2014 +top-down-parent is equivalent to the same named on in create policy,
2015 +bottom-up-parent selects the writable branch where the parent dir
2016 +exists and the nearest upper one from the copyup-source,
2017 +bottom-up selects the nearest upper writable branch from the
2018 +copyup-source, regardless the existence of the parent dir.
2020 +There are some rules or exceptions to apply these policies.
2021 +- If there is a readonly branch above the policy-selected branch and
2022 + the parent dir is marked as opaque (a variation of whiteout), or the
2023 + target (creating) file is whiteout-ed on the upper readonly branch,
2024 + then the result of the policy is ignored and the target file will be
2025 + created on the nearest upper writable branch than the readonly branch.
2026 +- If there is a writable branch above the policy-selected branch and
2027 + the parent dir is marked as opaque or the target file is whiteouted
2028 + on the branch, then the result of the policy is ignored and the target
2029 + file will be created on the highest one among the upper writable
2030 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2032 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2033 + They try selecting the branch where the source exists as possible
2034 + since copyup a large file will take long time. If it can't be,
2035 + ie. the branch where the source exists is readonly, then they will
2036 + follow the copyup policy.
2037 +- There is an exception for rename(2) when the target exists.
2038 + If the rename target exists, aufs compares the index of the branches
2039 + where the source and the target exists and selects the higher
2040 + one. If the selected branch is readonly, then aufs follows the
2042 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2043 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2044 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-01-28 14:36:12.215751270 +0100
2047 +// to view this graph, run dot(1) command in GRAPHVIZ.
2051 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2055 +aufs_rename -> whinfo [label="store/remove"];
2058 +inode_list [label="h_inum list in branch\ncache"];
2061 +whinode [label="h_inum list file"];
2064 +brmgmt [label="br_add/del/mod/umount"];
2066 +brmgmt -> inode_list [label="create/remove"];
2067 +brmgmt -> whinode [label="load/store"];
2069 +inode_list -> whinode [style=dashed,dir=both];
2071 +aufs_rename -> inode_list [label="add/del"];
2073 +aufs_lookup -> inode_list [label="search"];
2075 +aufs_lookup -> whinfo [label="load/remove"];
2077 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2078 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2079 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2019-01-28 14:36:12.215751270 +0100
2082 +# Copyright (C) 2017-2018 Junjiro R. Okajima
2084 +# This program is free software; you can redistribute it and/or modify
2085 +# it under the terms of the GNU General Public License as published by
2086 +# the Free Software Foundation; either version 2 of the License, or
2087 +# (at your option) any later version.
2089 +# This program is distributed in the hope that it will be useful,
2090 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2091 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2092 +# GNU General Public License for more details.
2094 +# You should have received a copy of the GNU General Public License
2095 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2097 +Special handling for renaming a directory (DIRREN)
2098 +----------------------------------------------------------------------
2099 +First, let's assume we have a simple usecase.
2103 +- /ro/dirA and /ro/dirA/file exist too
2104 +- there is no dirB on both branches
2105 +- a user issues rename("dirA", "dirB")
2107 +Now, what should aufs behave against this rename(2)?
2108 +There are a few possible cases.
2111 + since dirA exists on a readonly branch which cannot be renamed.
2113 + it is possible to copy-up dirA (only the dir itself), but the child
2114 + entries ("file" in this case) should not be. it must be a bad
2115 + approach to copy-up recursively.
2116 +C. returns a success.
2117 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2118 + is a violation of aufs' policy.
2119 +D. construct an extra information which indicates that /ro/dirA should
2120 + be handled as the name of dirB.
2121 + overlayfs has a similar feature called REDIRECT.
2123 +Until now, aufs implements the case B only which returns EXDEV, and
2124 +expects the userspace application behaves like mv(1) which tries
2125 +issueing rename(2) recursively.
2127 +A new aufs feature called DIRREN is introduced which implements the case
2128 +D. There are several "extra information" added.
2130 +1. detailed info per renamed directory
2131 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2132 +2. the inode-number list of directories on a branch
2133 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2135 +The filename of "detailed info per directory" represents the lower
2136 +branch, and its format is
2137 +- a type of the branch id
2139 + + uuid (not implemented yet)
2142 +- the inode-number of the branch root dir
2144 +And it contains these info in a single regular file.
2146 +- branch's inode-number of the logically renamed dir
2147 +- the name of the before-renamed dir
2149 +The "detailed info per directory" file is created in aufs rename(2), and
2150 +loaded in any lookup.
2151 +The info is considered in lookup for the matching case only. Here
2152 +"matching" means that the root of branch (in the info filename) is same
2153 +to the current looking-up branch. After looking-up the before-renamed
2154 +name, the inode-number is compared. And the matched dentry is used.
2156 +The "inode-number list of directories" is a regular file which contains
2157 +simply the inode-numbers on the branch. The file is created or updated
2158 +in removing the branch, and loaded in adding the branch. Its lifetime is
2159 +equal to the branch.
2160 +The list is refered in lookup, and when the current target inode is
2161 +found in the list, the aufs tries loading the "detailed info per
2162 +directory" and get the changed and valid name of the dir.
2164 +Theoretically these "extra informaiton" may be able to be put into XATTR
2165 +in the dir inode. But aufs doesn't choose this way because
2166 +1. XATTR may not be supported by the branch (or its configuration)
2167 +2. XATTR may have its size limit.
2168 +3. XATTR may be less easy to convert than a regular file, when the
2169 + format of the info is changed in the future.
2170 +At the same time, I agree that the regular file approach is much slower
2171 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2174 +This DIRREN feature is enabled by aufs configuration, and is activated
2175 +by a new mount option.
2177 +For the more complicated case, there is a work with UDBA option, which
2178 +is to dected the direct access to the branches (by-passing aufs) and to
2179 +maintain the cashes in aufs. Since a single cached aufs dentry may
2180 +contains two names, before- and after-rename, the name comparision in
2181 +UDBA handler may not work correctly. In this case, the behaviour will be
2182 +equivalen to udba=reval case.
2183 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2184 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2185 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2019-01-28 14:36:12.215751270 +0100
2188 +# Copyright (C) 2011-2018 Junjiro R. Okajima
2190 +# This program is free software; you can redistribute it and/or modify
2191 +# it under the terms of the GNU General Public License as published by
2192 +# the Free Software Foundation; either version 2 of the License, or
2193 +# (at your option) any later version.
2195 +# This program is distributed in the hope that it will be useful,
2196 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2197 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2198 +# GNU General Public License for more details.
2200 +# You should have received a copy of the GNU General Public License
2201 +# along with this program; if not, write to the Free Software
2202 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2205 +File-based Hierarchical Storage Management (FHSM)
2206 +----------------------------------------------------------------------
2207 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2208 +storage world. Aufs provides this feature as file-based with multiple
2209 +writable branches, based upon the principle of "Colder, the Lower".
2210 +Here the word "colder" means that the less used files, and "lower" means
2211 +that the position in the order of the stacked branches vertically.
2212 +These multiple writable branches are prioritized, ie. the topmost one
2213 +should be the fastest drive and be used heavily.
2215 +o Characters in aufs FHSM story
2216 +- aufs itself and a new branch attribute.
2217 +- a new ioctl interface to move-down and to establish a connection with
2218 + the daemon ("move-down" is a converse of "copy-up").
2219 +- userspace tool and daemon.
2221 +The userspace daemon establishes a connection with aufs and waits for
2222 +the notification. The notified information is very similar to struct
2223 +statfs containing the number of consumed blocks and inodes.
2224 +When the consumed blocks/inodes of a branch exceeds the user-specified
2225 +upper watermark, the daemon activates its move-down process until the
2226 +consumed blocks/inodes reaches the user-specified lower watermark.
2228 +The actual move-down is done by aufs based upon the request from
2229 +user-space since we need to maintain the inode number and the internal
2230 +pointer arrays in aufs.
2232 +Currently aufs FHSM handles the regular files only. Additionally they
2233 +must not be hard-linked nor pseudo-linked.
2236 +o Cowork of aufs and the user-space daemon
2237 + During the userspace daemon established the connection, aufs sends a
2238 + small notification to it whenever aufs writes something into the
2239 + writable branch. But it may cost high since aufs issues statfs(2)
2240 + internally. So user can specify a new option to cache the
2241 + info. Actually the notification is controlled by these factors.
2242 + + the specified cache time.
2243 + + classified as "force" by aufs internally.
2244 + Until the specified time expires, aufs doesn't send the info
2245 + except the forced cases. When aufs decide forcing, the info is always
2246 + notified to userspace.
2247 + For example, the number of free inodes is generally large enough and
2248 + the shortage of it happens rarely. So aufs doesn't force the
2249 + notification when creating a new file, directory and others. This is
2250 + the typical case which aufs doesn't force.
2251 + When aufs writes the actual filedata and the files consumes any of new
2252 + blocks, the aufs forces notifying.
2255 +o Interfaces in aufs
2256 +- New branch attribute.
2258 + Specifies that the branch is managed by FHSM feature. In other word,
2259 + participant in the FHSM.
2260 + When nofhsm is set to the branch, it will not be the source/target
2261 + branch of the move-down operation. This attribute is set
2262 + independently from coo and moo attributes, and if you want full
2263 + FHSM, you should specify them as well.
2264 +- New mount option.
2266 + Specifies a second to suppress many less important info to be
2269 + + AUFS_CTL_FHSM_FD
2270 + create a new file descriptor which userspace can read the notification
2271 + (a subset of struct statfs) from aufs.
2272 +- Module parameter 'brs'
2273 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2275 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2276 + When there are two or more branches with fhsm attributes,
2277 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2278 + terminates it. As a result of remounting and branch-manipulation, the
2279 + number of branches with fhsm attribute can be one. In this case,
2280 + /sbin/mount.aufs will terminate the user-space daemon.
2283 +Finally the operation is done as these steps in kernel-space.
2285 + + no one else is using the file.
2286 + + the file is not hard-linked.
2287 + + the file is not pseudo-linked.
2288 + + the file is a regular file.
2289 + + the parent dir is not opaqued.
2290 +- find the target writable branch.
2291 +- make sure the file is not whiteout-ed by the upper (than the target)
2293 +- make the parent dir on the target branch.
2294 +- mutex lock the inode on the branch.
2295 +- unlink the whiteout on the target branch (if exists).
2296 +- lookup and create the whiteout-ed temporary name on the target branch.
2297 +- copy the file as the whiteout-ed temporary name on the target branch.
2298 +- rename the whiteout-ed temporary name to the original name.
2299 +- unlink the file on the source branch.
2300 +- maintain the internal pointer array and the external inode number
2302 +- maintain the timestamps and other attributes of the parent dir and the
2305 +And of course, in every step, an error may happen. So the operation
2306 +should restore the original file state after an error happens.
2307 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2308 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2309 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2019-01-28 14:36:12.215751270 +0100
2312 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2314 +# This program is free software; you can redistribute it and/or modify
2315 +# it under the terms of the GNU General Public License as published by
2316 +# the Free Software Foundation; either version 2 of the License, or
2317 +# (at your option) any later version.
2319 +# This program is distributed in the hope that it will be useful,
2320 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2321 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2322 +# GNU General Public License for more details.
2324 +# You should have received a copy of the GNU General Public License
2325 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2327 +mmap(2) -- File Memory Mapping
2328 +----------------------------------------------------------------------
2329 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2330 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2332 +This approach is simple and good, but there is one problem.
2333 +Under /proc, several entries show the mmapped files by its path (with
2334 +device and inode number), and the printed path will be the path on the
2335 +branch fs's instead of virtual aufs's.
2336 +This is not a problem in most cases, but some utilities lsof(1) (and its
2337 +user) may expect the path on aufs.
2339 +To address this issue, aufs adds a new member called vm_prfile in struct
2340 +vm_area_struct (and struct vm_region). The original vm_file points to
2341 +the file on the branch fs in order to handle everything correctly as
2342 +usual. The new vm_prfile points to a virtual file in aufs, and the
2343 +show-functions in procfs refers to vm_prfile if it is set.
2344 +Also we need to maintain several other places where touching vm_file
2346 +- fork()/clone() copies vma and the reference count of vm_file is
2348 +- merging vma maintains the ref count too.
2350 +This is not a good approach. It just fakes the printed path. But it
2351 +leaves all behaviour around f_mapping unchanged. This is surely an
2353 +Actually aufs had adopted another complicated approach which calls
2354 +generic_file_mmap() and handles struct vm_operations_struct. In this
2355 +approach, aufs met a hard problem and I could not solve it without
2356 +switching the approach.
2358 +There may be one more another approach which is
2359 +- bind-mount the branch-root onto the aufs-root internally
2360 +- grab the new vfsmount (ie. struct mount)
2361 +- lazy-umount the branch-root internally
2362 +- in open(2) the aufs-file, open the branch-file with the hidden
2363 + vfsmount (instead of the original branch's vfsmount)
2364 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2365 + but it may be possible from userspace by the mount helper.
2367 +Adding the internal hidden vfsmount and using it in opening a file, the
2368 +file path under /proc will be printed correctly. This approach looks
2369 +smarter, but is not possible I am afraid.
2370 +- aufs-root may be bind-mount later. when it happens, another hidden
2371 + vfsmount will be required.
2372 +- it is hard to get the chance to bind-mount and lazy-umount
2373 + + in kernel-space, FS can have vfsmount in open(2) via
2374 + file->f_path, and aufs can know its vfsmount. But several locks are
2375 + already acquired, and if aufs tries to bind-mount and lazy-umount
2376 + here, then it may cause a deadlock.
2377 + + in user-space, bind-mount doesn't invoke the mount helper.
2378 +- since /proc shows dev and ino, aufs has to give vma these info. it
2379 + means a new member vm_prinode will be necessary. this is essentially
2380 + equivalent to vm_prfile described above.
2382 +I have to give up this "looks-smater" approach.
2383 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2384 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2385 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2019-01-28 14:36:12.215751270 +0100
2388 +# Copyright (C) 2014-2018 Junjiro R. Okajima
2390 +# This program is free software; you can redistribute it and/or modify
2391 +# it under the terms of the GNU General Public License as published by
2392 +# the Free Software Foundation; either version 2 of the License, or
2393 +# (at your option) any later version.
2395 +# This program is distributed in the hope that it will be useful,
2396 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2397 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2398 +# GNU General Public License for more details.
2400 +# You should have received a copy of the GNU General Public License
2401 +# along with this program; if not, write to the Free Software
2402 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2405 +Listing XATTR/EA and getting the value
2406 +----------------------------------------------------------------------
2407 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2408 +shows the values from the topmost existing file. This behaviour is good
2409 +for the non-dir entries since the bahaviour exactly matches the shown
2410 +information. But for the directories, aufs considers all the same named
2411 +entries on the lower branches. Which means, if one of the lower entry
2412 +rejects readdir call, then aufs returns an error even if the topmost
2413 +entry allows it. This behaviour is necessary to respect the branch fs's
2414 +security, but can make users confused since the user-visible standard
2415 +attributes don't match the behaviour.
2416 +To address this issue, aufs has a mount option called dirperm1 which
2417 +checks the permission for the topmost entry only, and ignores the lower
2418 +entry's permission.
2420 +A similar issue can happen around XATTR.
2421 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2422 +always set. Otherwise these very unpleasant situation would happen.
2423 +- listxattr(2) may return the duplicated entries.
2424 +- users may not be able to remove or reset the XATTR forever,
2427 +XATTR/EA support in the internal (copy,move)-(up,down)
2428 +----------------------------------------------------------------------
2429 +Generally the extended attributes of inode are categorized as these.
2430 +- "security" for LSM and capability.
2431 +- "system" for posix ACL, 'acl' mount option is required for the branch
2433 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2434 +- "user" for userspace, 'user_xattr' mount option is required for the
2435 + branch fs generally.
2437 +Moreover there are some other categories. Aufs handles these rather
2438 +unpopular categories as the ordinary ones, ie. there is no special
2439 +condition nor exception.
2441 +In copy-up, the support for XATTR on the dst branch may differ from the
2442 +src branch. In this case, the copy-up operation will get an error and
2443 +the original user operation which triggered the copy-up will fail. It
2444 +can happen that even all copy-up will fail.
2445 +When both of src and dst branches support XATTR and if an error occurs
2446 +during copying XATTR, then the copy-up should fail obviously. That is a
2447 +good reason and aufs should return an error to userspace. But when only
2448 +the src branch support that XATTR, aufs should not return an error.
2449 +For example, the src branch supports ACL but the dst branch doesn't
2450 +because the dst branch may natively un-support it or temporary
2451 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2452 +may NOT return an error even if the XATTR is not supported. It is
2453 +totally up to the branch fs.
2455 +Anyway when the aufs internal copy-up gets an error from the dst branch
2456 +fs, then aufs tries removing the just copied entry and returns the error
2457 +to the userspace. The worst case of this situation will be all copy-up
2460 +For the copy-up operation, there two basic approaches.
2461 +- copy the specified XATTR only (by category above), and return the
2462 + error unconditionally if it happens.
2463 +- copy all XATTR, and ignore the error on the specified category only.
2465 +In order to support XATTR and to implement the correct behaviour, aufs
2466 +chooses the latter approach and introduces some new branch attributes,
2467 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2468 +They correspond to the XATTR namespaces (see above). Additionally, to be
2469 +convenient, "icex" is also provided which means all "icex*" attributes
2470 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2472 +The meaning of these attributes is to ignore the error from setting
2473 +XATTR on that branch.
2474 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2475 +error from the dst branch according to the specified attributes.
2477 +Some XATTR may have its default value. The default value may come from
2478 +the parent dir or the environment. If the default value is set at the
2479 +file creating-time, it will be overwritten by copy-up.
2480 +Some contradiction may happen I am afraid.
2481 +Do we need another attribute to stop copying XATTR? I am unsure. For
2482 +now, aufs implements the branch attributes to ignore the error.
2483 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2484 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2485 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2019-01-28 14:36:12.215751270 +0100
2488 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2490 +# This program is free software; you can redistribute it and/or modify
2491 +# it under the terms of the GNU General Public License as published by
2492 +# the Free Software Foundation; either version 2 of the License, or
2493 +# (at your option) any later version.
2495 +# This program is distributed in the hope that it will be useful,
2496 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2497 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2498 +# GNU General Public License for more details.
2500 +# You should have received a copy of the GNU General Public License
2501 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2503 +Export Aufs via NFS
2504 +----------------------------------------------------------------------
2505 +Here is an approach.
2506 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2508 +- iget_locked(): initialize aufs inode generation for a new inode, and
2509 + store it in xigen file.
2510 +- destroy_inode(): increment aufs inode generation and store it in xigen
2511 + file. it is necessary even if it is not unlinked, because any data of
2512 + inode may be changed by UDBA.
2513 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2514 + build file handle by
2515 + + branch id (4 bytes)
2516 + + superblock generation (4 bytes)
2517 + + inode number (4 or 8 bytes)
2518 + + parent dir inode number (4 or 8 bytes)
2519 + + inode generation (4 bytes))
2520 + + return value of exportfs_encode_fh() for the parent on a branch (4
2522 + + file handle for a branch (by exportfs_encode_fh())
2524 + + find the index of a branch from its id in handle, and check it is
2525 + still exist in aufs.
2526 + + 1st level: get the inode number from handle and search it in cache.
2527 + + 2nd level: if not found in cache, get the parent inode number from
2528 + the handle and search it in cache. and then open the found parent
2529 + dir, find the matching inode number by vfs_readdir() and get its
2530 + name, and call lookup_one_len() for the target dentry.
2531 + + 3rd level: if the parent dir is not cached, call
2532 + exportfs_decode_fh() for a branch and get the parent on a branch,
2533 + build a pathname of it, convert it a pathname in aufs, call
2534 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2536 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2537 + for every branch, but not itself. to get this, (currently) aufs
2538 + searches in current->nsproxy->mnt_ns list. it may not be a good
2539 + idea, but I didn't get other approach.
2540 + + test the generation of the gotten inode.
2541 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2542 + convert it into ESTALE for NFSD.
2543 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2544 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2545 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2546 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2547 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2019-01-28 14:36:12.215751270 +0100
2550 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2552 +# This program is free software; you can redistribute it and/or modify
2553 +# it under the terms of the GNU General Public License as published by
2554 +# the Free Software Foundation; either version 2 of the License, or
2555 +# (at your option) any later version.
2557 +# This program is distributed in the hope that it will be useful,
2558 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2559 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2560 +# GNU General Public License for more details.
2562 +# You should have received a copy of the GNU General Public License
2563 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2565 +Show Whiteout Mode (shwh)
2566 +----------------------------------------------------------------------
2567 +Generally aufs hides the name of whiteouts. But in some cases, to show
2568 +them is very useful for users. For instance, creating a new middle layer
2569 +(branch) by merging existing layers.
2571 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2572 +When you have three branches,
2573 +- Bottom: 'system', squashfs (underlying base system), read-only
2574 +- Middle: 'mods', squashfs, read-only
2575 +- Top: 'overlay', ram (tmpfs), read-write
2577 +The top layer is loaded at boot time and saved at shutdown, to preserve
2578 +the changes made to the system during the session.
2579 +When larger changes have been made, or smaller changes have accumulated,
2580 +the size of the saved top layer data grows. At this point, it would be
2581 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2582 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2583 +restoring save and load speed.
2585 +This merging is simplified by the use of another aufs mount, of just the
2586 +two overlay branches using the 'shwh' option.
2587 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2588 + aufs /livesys/merge_union
2590 +A merged view of these two branches is then available at
2591 +/livesys/merge_union, and the new feature is that the whiteouts are
2593 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2594 +writing to all branches. Also the default mode for all branches is 'ro'.
2595 +It is now possible to save the combined contents of the two overlay
2596 +branches to a new squashfs, e.g.:
2597 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2599 +This new squashfs archive can be stored on the boot device and the
2600 +initramfs will use it to replace the old one at the next boot.
2601 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2602 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2603 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2019-01-28 14:36:12.215751270 +0100
2606 +# Copyright (C) 2010-2018 Junjiro R. Okajima
2608 +# This program is free software; you can redistribute it and/or modify
2609 +# it under the terms of the GNU General Public License as published by
2610 +# the Free Software Foundation; either version 2 of the License, or
2611 +# (at your option) any later version.
2613 +# This program is distributed in the hope that it will be useful,
2614 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2615 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2616 +# GNU General Public License for more details.
2618 +# You should have received a copy of the GNU General Public License
2619 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2621 +Dynamically customizable FS operations
2622 +----------------------------------------------------------------------
2623 +Generally FS operations (struct inode_operations, struct
2624 +address_space_operations, struct file_operations, etc.) are defined as
2625 +"static const", but it never means that FS have only one set of
2626 +operation. Some FS have multiple sets of them. For instance, ext2 has
2627 +three sets, one for XIP, for NOBH, and for normal.
2628 +Since aufs overrides and redirects these operations, sometimes aufs has
2629 +to change its behaviour according to the branch FS type. More importantly
2630 +VFS acts differently if a function (member in the struct) is set or
2631 +not. It means aufs should have several sets of operations and select one
2632 +among them according to the branch FS definition.
2634 +In order to solve this problem and not to affect the behaviour of VFS,
2635 +aufs defines these operations dynamically. For instance, aufs defines
2636 +dummy direct_IO function for struct address_space_operations, but it may
2637 +not be set to the address_space_operations actually. When the branch FS
2638 +doesn't have it, aufs doesn't set it to its address_space_operations
2639 +while the function definition itself is still alive. So the behaviour
2640 +itself will not change, and it will return an error when direct_IO is
2643 +The lifetime of these dynamically generated operation object is
2644 +maintained by aufs branch object. When the branch is removed from aufs,
2645 +the reference counter of the object is decremented. When it reaches
2646 +zero, the dynamically generated operation object will be freed.
2648 +This approach is designed to support AIO (io_submit), Direct I/O and
2650 +Currently this approach is applied to address_space_operations for
2651 +regular files only.
2652 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2653 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2654 +++ linux/Documentation/filesystems/aufs/README 2019-01-28 14:36:12.215751270 +0100
2657 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2663 +----------------------------------------
2664 +In the early days, aufs was entirely re-designed and re-implemented
2665 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2666 +improvements and implementations, it becomes totally different from
2667 +Unionfs while keeping the basic features.
2668 +Recently, Unionfs Version 2.x series begin taking some of the same
2669 +approaches to aufs1's.
2670 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2671 +University and his team.
2673 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2674 +If you want older kernel version support, try aufs2-2.6.git or
2675 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2677 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2678 + According to Christoph Hellwig, linux rejects all union-type
2679 + filesystems but UnionMount.
2680 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2682 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2683 + UnionMount, and he pointed out an issue around a directory mutex
2684 + lock and aufs addressed it. But it is still unsure whether aufs will
2685 + be merged (or any other union solution).
2686 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2690 +----------------------------------------
2691 +- unite several directories into a single virtual filesystem. The member
2692 + directory is called as a branch.
2693 +- you can specify the permission flags to the branch, which are 'readonly',
2694 + 'readwrite' and 'whiteout-able.'
2695 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2696 + readonly branch are modifiable logically.
2697 +- dynamic branch manipulation, add, del.
2700 +Also there are many enhancements in aufs, such as:
2701 +- test only the highest one for the directory permission (dirperm1)
2702 +- copyup on open (coo=)
2703 +- 'move' policy for copy-up between two writable branches, after
2704 + checking free space.
2706 +- readdir(3) in userspace.
2707 +- keep inode number by external inode number table
2708 +- keep the timestamps of file/dir in internal copyup operation
2709 +- seekable directory, supporting NFS readdir.
2710 +- whiteout is hardlinked in order to reduce the consumption of inodes
2712 +- do not copyup, nor create a whiteout when it is unnecessary
2713 +- revert a single systemcall when an error occurs in aufs
2714 +- remount interface instead of ioctl
2715 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2716 +- loopback mounted filesystem as a branch
2717 +- kernel thread for removing the dir who has a plenty of whiteouts
2718 +- support copyup sparse file (a file which has a 'hole' in it)
2719 +- default permission flags for branches
2720 +- selectable permission flags for ro branch, whether whiteout can
2723 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2724 +- support multiple writable branches, some policies to select one
2725 + among multiple writable branches.
2726 +- a new semantics for link(2) and rename(2) to support multiple
2727 + writable branches.
2728 +- no glibc changes are required.
2729 +- pseudo hardlink (hardlink over branches)
2730 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2731 + including NFS or remote filesystem branch.
2732 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2735 +Currently these features are dropped temporary from aufs4.
2736 +See design/08plan.txt in detail.
2737 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2739 +- statistics of aufs thread (/sys/fs/aufs/stat)
2741 +Features or just an idea in the future (see also design/*.txt),
2742 +- reorder the branch index without del/re-add.
2743 +- permanent xino files for NFSD
2744 +- an option for refreshing the opened files after add/del branches
2745 +- light version, without branch manipulation. (unnecessary?)
2746 +- copyup in userspace
2747 +- inotify in userspace
2752 +----------------------------------------
2753 +There are three GIT trees for aufs4, aufs4-linux.git,
2754 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2756 +While the aufs-util is always necessary, you need either of aufs4-linux
2757 +or aufs4-standalone.
2759 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2760 +git://git.kernel.org/.../torvalds/linux.git.
2761 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2762 +build aufs4 as an external kernel module.
2763 +Several extra patches are not included in this tree. Only
2764 +aufs4-standalone tree contains them. They are described in the later
2765 +section "Configuration and Compilation."
2767 +On the other hand, the aufs4-standalone tree has only aufs source files
2768 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2769 +But you need to apply all aufs patches manually.
2771 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2772 +represents the linux kernel version, "linux-4.x". For instance,
2773 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2774 +"aufs4.x-rcN" branch.
2777 +$ git clone --reference /your/linux/git/tree \
2778 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2779 +- if you don't have linux GIT tree, then remove "--reference ..."
2780 +$ cd aufs4-linux.git
2781 +$ git checkout origin/aufs4.0
2783 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2784 +leave the patch-work to GIT.
2785 +$ cd /your/linux/git/tree
2786 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2788 +$ git checkout -b my4.0 v4.0
2789 +$ (add your local change...)
2790 +$ git pull aufs4 aufs4.0
2791 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2792 +- you may need to solve some conflicts between your_changes and
2793 + aufs4.0. in this case, git-rerere is recommended so that you can
2794 + solve the similar conflicts automatically when you upgrade to 4.1 or
2795 + later in the future.
2797 +o aufs4-standalone tree
2798 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2799 +$ cd aufs4-standalone.git
2800 +$ git checkout origin/aufs4.0
2803 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2804 +- note that the public aufs-util.git is on SourceForge instead of
2807 +$ git checkout origin/aufs4.0
2809 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2810 +The minor version number, 'x' in '4.x', of aufs may not always
2811 +follow the minor version number of the kernel.
2812 +Because changes in the kernel that cause the use of a new
2813 +minor version number do not always require changes to aufs-util.
2815 +Since aufs-util has its own minor version number, you may not be
2816 +able to find a GIT branch in aufs-util for your kernel's
2817 +exact minor version number.
2818 +In this case, you should git-checkout the branch for the
2819 +nearest lower number.
2821 +For (an unreleased) example:
2822 +If you are using "linux-4.10" and the "aufs4.10" branch
2823 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2824 +or something numerically smaller is the branch for your kernel.
2826 +Also you can view all branches by
2830 +3. Configuration and Compilation
2831 +----------------------------------------
2832 +Make sure you have git-checkout'ed the correct branch.
2834 +For aufs4-linux tree,
2835 +- enable CONFIG_AUFS_FS.
2836 +- set other aufs configurations if necessary.
2838 +For aufs4-standalone tree,
2839 +There are several ways to build.
2842 +- apply ./aufs4-kbuild.patch to your kernel source files.
2843 +- apply ./aufs4-base.patch too.
2844 +- apply ./aufs4-mmap.patch too.
2845 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2846 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2847 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2848 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2849 +- enable CONFIG_AUFS_FS, you can select either
2851 +- and build your kernel as usual.
2852 +- install the built kernel.
2853 + Note: Since linux-3.9, every filesystem module requires an alias
2854 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2855 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2856 +- install the header files too by "make headers_install" to the
2857 + directory where you specify. By default, it is $PWD/usr.
2858 + "make help" shows a brief note for headers_install.
2859 +- and reboot your system.
2862 +- module only (CONFIG_AUFS_FS=m).
2863 +- apply ./aufs4-base.patch to your kernel source files.
2864 +- apply ./aufs4-mmap.patch too.
2865 +- apply ./aufs4-standalone.patch too.
2866 +- build your kernel, don't forget "make headers_install", and reboot.
2867 +- edit ./config.mk and set other aufs configurations if necessary.
2868 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2869 + every aufs configurations.
2870 +- build the module by simple "make".
2871 + Note: Since linux-3.9, every filesystem module requires an alias
2872 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2873 + modules.aliases file.
2874 +- you can specify ${KDIR} make variable which points to your kernel
2876 +- install the files
2877 + + run "make install" to install the aufs module, or copy the built
2878 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2879 + + run "make install_headers" (instead of headers_install) to install
2880 + the modified aufs header file (you can specify DESTDIR which is
2881 + available in aufs standalone version's Makefile only), or copy
2882 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2883 + you like manually. By default, the target directory is $PWD/usr.
2884 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2885 + kernel source tree.
2887 +Note: The header file aufs_type.h is necessary to build aufs-util
2888 + as well as "make headers_install" in the kernel source tree.
2889 + headers_install is subject to be forgotten, but it is essentially
2890 + necessary, not only for building aufs-util.
2891 + You may not meet problems without headers_install in some older
2895 +- read README in aufs-util, build and install it
2896 +- note that your distribution may contain an obsoleted version of
2897 + aufs_type.h in /usr/include/linux or something. When you build aufs
2898 + utilities, make sure that your compiler refers the correct aufs header
2899 + file which is built by "make headers_install."
2900 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2901 + then run "make install_ulib" too. And refer to the aufs manual in
2904 +There several other patches in aufs4-standalone.git. They are all
2905 +optional. When you meet some problems, they will help you.
2906 +- aufs4-loopback.patch
2907 + Supports a nested loopback mount in a branch-fs. This patch is
2908 + unnecessary until aufs produces a message like "you may want to try
2909 + another patch for loopback file".
2911 + Modifies a system global kernel internal function get_next_ino() in
2912 + order to stop assigning 0 for an inode-number. Not directly related to
2913 + aufs, but recommended generally.
2915 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2916 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2917 + duplication of inode number, which is important for backup tools and
2918 + other utilities. When you find aufs XINO files for tmpfs branch
2919 + growing too much, try this patch.
2920 +- lockdep-debug.patch
2921 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2922 + also a caller of VFS functions for branch filesystems, subclassing of
2923 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2924 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2925 + need to apply this debug patch to expand several constant values.
2926 + If don't know what LOCKDEP, then you don't have apply this patch.
2930 +----------------------------------------
2931 +At first, make sure aufs-util are installed, and please read the aufs
2932 +manual, aufs.5 in aufs-util.git tree.
2936 +$ mkdir /tmp/rw /tmp/aufs
2937 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2939 +Here is another example. The result is equivalent.
2940 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2942 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2943 +# mount -o remount,append:${HOME} /tmp/aufs
2945 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2946 +you modify a file under /tmp/aufs, the one on your home directory is
2947 +not affected, instead the same named file will be newly created under
2948 +/tmp/rw. And all of your modification to a file will be applied to
2949 +the one under /tmp/rw. This is called the file based Copy on Write
2951 +Aufs mount options are described in aufs.5.
2952 +If you run chroot or something and make your aufs as a root directory,
2953 +then you need to customize the shutdown script. See the aufs manual in
2956 +Additionally, there are some sample usages of aufs which are a
2957 +diskless system with network booting, and LiveCD over NFS.
2958 +See sample dir in CVS tree on SourceForge.
2962 +----------------------------------------
2963 +When you have any problems or strange behaviour in aufs, please let me
2965 +- /proc/mounts (instead of the output of mount(8))
2966 +- /sys/module/aufs/*
2967 +- /sys/fs/aufs/* (if you have them)
2968 +- /debug/aufs/* (if you have them)
2969 +- linux kernel version
2970 + if your kernel is not plain, for example modified by distributor,
2971 + the url where i can download its source is necessary too.
2972 +- aufs version which was printed at loading the module or booting the
2973 + system, instead of the date you downloaded.
2974 +- configuration (define/undefine CONFIG_AUFS_xxx)
2975 +- kernel configuration or /proc/config.gz (if you have it)
2976 +- behaviour which you think to be incorrect
2977 +- actual operation, reproducible one is better
2978 +- mailto: aufs-users at lists.sourceforge.net
2980 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2981 +and Feature Requests) on SourceForge. Please join and write to
2985 +6. Acknowledgements
2986 +----------------------------------------
2987 +Thanks to everyone who have tried and are using aufs, whoever
2988 +have reported a bug or any feedback.
2990 +Especially donators:
2991 +Tomas Matejicek(slax.org) made a donation (much more than once).
2992 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2993 + scripts) is making "doubling" donations.
2994 + Unfortunately I cannot list all of the donators, but I really
2996 + It ends Aug 2010, but the ordinary donation URL is still available.
2997 + <http://sourceforge.net/donate/index.php?group_id=167503>
2998 +Dai Itasaka made a donation (2007/8).
2999 +Chuck Smith made a donation (2008/4, 10 and 12).
3000 +Henk Schoneveld made a donation (2008/9).
3001 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
3002 +Francois Dupoux made a donation (2008/11).
3003 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
3004 + aufs2 GIT tree (2009/2).
3005 +William Grant made a donation (2009/3).
3006 +Patrick Lane made a donation (2009/4).
3007 +The Mail Archive (mail-archive.com) made donations (2009/5).
3008 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
3009 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
3010 +Pavel Pronskiy made a donation (2011/2).
3011 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
3012 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
3013 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
3015 +Sam Liddicott made a donation (2011/9).
3016 +Era Scarecrow made a donation (2013/4).
3017 +Bor Ratajc made a donation (2013/4).
3018 +Alessandro Gorreta made a donation (2013/4).
3019 +POIRETTE Marc made a donation (2013/4).
3020 +Alessandro Gorreta made a donation (2013/4).
3021 +lauri kasvandik made a donation (2013/5).
3022 +"pemasu from Finland" made a donation (2013/7).
3023 +The Parted Magic Project made a donation (2013/9 and 11).
3024 +Pavel Barta made a donation (2013/10).
3025 +Nikolay Pertsev made a donation (2014/5).
3026 +James B made a donation (2014/7 and 2015/7).
3027 +Stefano Di Biase made a donation (2014/8).
3028 +Daniel Epellei made a donation (2015/1).
3029 +OmegaPhil made a donation (2016/1, 2018/4).
3030 +Tomasz Szewczyk made a donation (2016/4).
3031 +James Burry made a donation (2016/12).
3032 +Carsten Rose made a donation (2018/9).
3033 +Porteus Kiosk made a donation (2018/10).
3035 +Thank you very much.
3036 +Donations are always, including future donations, very important and
3037 +helpful for me to keep on developing aufs.
3041 +----------------------------------------
3042 +If you are an experienced user, no explanation is needed. Aufs is
3043 +just a linux filesystem.
3048 +# Local variables: ;
3051 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3052 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3053 +++ linux/fs/aufs/aufs.h 2019-01-28 14:36:12.219084659 +0100
3055 +/* SPDX-License-Identifier: GPL-2.0 */
3057 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3059 + * This program, aufs is free software; you can redistribute it and/or modify
3060 + * it under the terms of the GNU General Public License as published by
3061 + * the Free Software Foundation; either version 2 of the License, or
3062 + * (at your option) any later version.
3064 + * This program is distributed in the hope that it will be useful,
3065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3067 + * GNU General Public License for more details.
3069 + * You should have received a copy of the GNU General Public License
3070 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3074 + * all header files
3082 +#define AuStub(type, name, body, ...) \
3083 + static inline type name(__VA_ARGS__) { body; }
3085 +#define AuStubVoid(name, ...) \
3086 + AuStub(void, name, , __VA_ARGS__)
3087 +#define AuStubInt0(name, ...) \
3088 + AuStub(int, name, return 0, __VA_ARGS__)
3092 +#include "branch.h"
3095 +#include "dbgaufs.h"
3096 +#include "dentry.h"
3098 +#include "dirren.h"
3101 +#include "fstype.h"
3106 +#include "module.h"
3110 +#include "sysaufs.h"
3115 +#endif /* __KERNEL__ */
3116 +#endif /* __AUFS_H__ */
3117 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3118 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3119 +++ linux/fs/aufs/branch.c 2019-01-28 14:36:12.219084659 +0100
3121 +// SPDX-License-Identifier: GPL-2.0
3123 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3125 + * This program, aufs is free software; you can redistribute it and/or modify
3126 + * it under the terms of the GNU General Public License as published by
3127 + * the Free Software Foundation; either version 2 of the License, or
3128 + * (at your option) any later version.
3130 + * This program is distributed in the hope that it will be useful,
3131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3133 + * GNU General Public License for more details.
3135 + * You should have received a copy of the GNU General Public License
3136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3140 + * branch management
3143 +#include <linux/compat.h>
3144 +#include <linux/statfs.h>
3148 + * free a single branch
3150 +static void au_br_do_free(struct au_branch *br)
3153 + struct au_wbr *wbr;
3154 + struct au_dykey **key;
3156 + au_hnotify_fin_br(br);
3157 + /* always, regardless the mount option */
3158 + au_dr_hino_free(&br->br_dirren);
3161 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3162 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3163 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3164 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3168 + for (i = 0; i < AuBrWh_Last; i++)
3169 + dput(wbr->wbr_wh[i]);
3170 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3171 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3174 + if (br->br_fhsm) {
3175 + au_br_fhsm_fin(br->br_fhsm);
3176 + au_kfree_try_rcu(br->br_fhsm);
3179 + key = br->br_dykey;
3180 + for (i = 0; i < AuBrDynOp; i++, key++)
3186 + /* recursive lock, s_umount of branch's */
3187 + /* synchronize_rcu(); */ /* why? */
3189 + path_put(&br->br_path);
3191 + au_kfree_rcu(wbr);
3192 + au_lcnt_wait_for_fin(&br->br_nfiles);
3193 + au_lcnt_wait_for_fin(&br->br_count);
3194 + /* I don't know why, but percpu_refcount requires this */
3195 + /* synchronize_rcu(); */
3200 + * frees all branches
3202 +void au_br_free(struct au_sbinfo *sbinfo)
3204 + aufs_bindex_t bmax;
3205 + struct au_branch **br;
3207 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3209 + bmax = sbinfo->si_bbot + 1;
3210 + br = sbinfo->si_branch;
3212 + au_br_do_free(*br++);
3216 + * find the index of a branch which is specified by @br_id.
3218 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3220 + aufs_bindex_t bindex, bbot;
3222 + bbot = au_sbbot(sb);
3223 + for (bindex = 0; bindex <= bbot; bindex++)
3224 + if (au_sbr_id(sb, bindex) == br_id)
3229 +/* ---------------------------------------------------------------------- */
3235 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3236 + struct dentry *h_root)
3238 + if (unlikely(h_adding == h_root
3239 + || au_test_loopback_overlap(sb, h_adding)))
3241 + if (h_adding->d_sb != h_root->d_sb)
3243 + return au_test_subdir(h_adding, h_root)
3244 + || au_test_subdir(h_root, h_adding);
3248 + * returns a newly allocated branch. @new_nbranch is a number of branches
3249 + * after adding a branch.
3251 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3254 + struct au_branch *add_branch;
3255 + struct dentry *root;
3256 + struct inode *inode;
3260 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3261 + if (unlikely(!add_branch))
3263 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3264 + if (unlikely(!add_branch->br_xino))
3266 + err = au_hnotify_init_br(add_branch, perm);
3267 + if (unlikely(err))
3270 + if (au_br_writable(perm)) {
3271 + /* may be freed separately at changing the branch permission */
3272 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3274 + if (unlikely(!add_branch->br_wbr))
3278 + if (au_br_fhsm(perm)) {
3279 + err = au_fhsm_br_alloc(add_branch);
3280 + if (unlikely(err))
3284 + root = sb->s_root;
3285 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3287 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3289 + inode = d_inode(root);
3290 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3294 + return add_branch; /* success */
3297 + au_kfree_rcu(add_branch->br_wbr);
3299 + au_hnotify_fin_br(add_branch);
3301 + au_xino_put(add_branch);
3303 + au_kfree_rcu(add_branch);
3305 + return ERR_PTR(err);
3309 + * test if the branch permission is legal or not.
3311 +static int test_br(struct inode *inode, int brperm, char *path)
3315 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3320 + pr_err("write permission for readonly mount or inode, %s\n", path);
3328 + * 0: success, the caller will add it
3329 + * plus: success, it is already unified, the caller should ignore it
3332 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3335 + aufs_bindex_t bbot, bindex;
3336 + struct dentry *root, *h_dentry;
3337 + struct inode *inode, *h_inode;
3339 + root = sb->s_root;
3340 + bbot = au_sbbot(sb);
3341 + if (unlikely(bbot >= 0
3342 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3346 + pr_err("%s duplicated\n", add->pathname);
3351 + err = -ENOSPC; /* -E2BIG; */
3352 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3353 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3354 + pr_err("number of branches exceeded %s\n", add->pathname);
3359 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3360 + pr_err("bad index %d\n", add->bindex);
3364 + inode = d_inode(add->path.dentry);
3366 + if (unlikely(!inode->i_nlink)) {
3367 + pr_err("no existence %s\n", add->pathname);
3372 + if (unlikely(inode->i_sb == sb)) {
3373 + pr_err("%s must be outside\n", add->pathname);
3377 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3378 + pr_err("unsupported filesystem, %s (%s)\n",
3379 + add->pathname, au_sbtype(inode->i_sb));
3383 + if (unlikely(inode->i_sb->s_stack_depth)) {
3384 + pr_err("already stacked, %s (%s)\n",
3385 + add->pathname, au_sbtype(inode->i_sb));
3389 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3390 + if (unlikely(err))
3394 + return 0; /* success */
3397 + for (bindex = 0; bindex <= bbot; bindex++)
3398 + if (unlikely(test_overlap(sb, add->path.dentry,
3399 + au_h_dptr(root, bindex)))) {
3400 + pr_err("%s is overlapped\n", add->pathname);
3405 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3406 + h_dentry = au_h_dptr(root, 0);
3407 + h_inode = d_inode(h_dentry);
3408 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3409 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3410 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3411 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3413 + i_uid_read(inode), i_gid_read(inode),
3414 + (inode->i_mode & S_IALLUGO),
3415 + i_uid_read(h_inode), i_gid_read(h_inode),
3416 + (h_inode->i_mode & S_IALLUGO));
3424 + * initialize or clean the whiteouts for an adding branch
3426 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3429 + int err, old_perm;
3430 + aufs_bindex_t bindex;
3431 + struct inode *h_inode;
3432 + struct au_wbr *wbr;
3433 + struct au_hinode *hdir;
3434 + struct dentry *h_dentry;
3436 + err = vfsub_mnt_want_write(au_br_mnt(br));
3437 + if (unlikely(err))
3441 + old_perm = br->br_perm;
3442 + br->br_perm = new_perm;
3445 + bindex = au_br_index(sb, br->br_id);
3446 + if (0 <= bindex) {
3447 + hdir = au_hi(d_inode(sb->s_root), bindex);
3448 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3450 + h_dentry = au_br_dentry(br);
3451 + h_inode = d_inode(h_dentry);
3452 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3455 + err = au_wh_init(br, sb);
3457 + wbr_wh_write_lock(wbr);
3458 + err = au_wh_init(br, sb);
3459 + wbr_wh_write_unlock(wbr);
3462 + au_hn_inode_unlock(hdir);
3464 + inode_unlock(h_inode);
3465 + vfsub_mnt_drop_write(au_br_mnt(br));
3466 + br->br_perm = old_perm;
3468 + if (!err && wbr && !au_br_writable(new_perm)) {
3469 + au_kfree_rcu(wbr);
3470 + br->br_wbr = NULL;
3477 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3481 + struct kstatfs kst;
3482 + struct au_wbr *wbr;
3485 + au_rw_init(&wbr->wbr_wh_rwsem);
3486 + atomic_set(&wbr->wbr_wh_running, 0);
3489 + * a limit for rmdir/rename a dir
3490 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3492 + err = vfs_statfs(&br->br_path, &kst);
3493 + if (unlikely(err))
3496 + if (kst.f_namelen >= NAME_MAX)
3497 + err = au_br_init_wh(sb, br, perm);
3499 + pr_err("%pd(%s), unsupported namelen %ld\n",
3501 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3507 +/* initialize a new branch */
3508 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3509 + struct au_opt_add *add)
3512 + struct au_branch *brbase;
3514 + struct inode *h_inode;
3517 + br->br_perm = add->perm;
3518 + br->br_path = add->path; /* set first, path_get() later */
3519 + spin_lock_init(&br->br_dykey_lock);
3520 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3521 + au_lcnt_init(&br->br_count, /*release*/NULL);
3522 + br->br_id = au_new_br_id(sb);
3523 + AuDebugOn(br->br_id < 0);
3525 + /* always, regardless the given option */
3526 + err = au_dr_br_init(sb, br, &add->path);
3527 + if (unlikely(err))
3530 + if (au_br_writable(add->perm)) {
3531 + err = au_wbr_init(br, sb, add->perm);
3532 + if (unlikely(err))
3536 + if (au_opt_test(au_mntflags(sb), XINO)) {
3537 + brbase = au_sbr(sb, 0);
3538 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3540 + h_inode = d_inode(add->path.dentry);
3541 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3542 + if (unlikely(err)) {
3543 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3548 + sysaufs_br_init(br);
3549 + path_get(&br->br_path);
3550 + goto out; /* success */
3553 + memset(&br->br_path, 0, sizeof(br->br_path));
3558 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3559 + struct au_branch *br, aufs_bindex_t bbot,
3560 + aufs_bindex_t amount)
3562 + struct au_branch **brp;
3564 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3566 + brp = sbinfo->si_branch + bindex;
3567 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3569 + sbinfo->si_bbot++;
3570 + if (unlikely(bbot < 0))
3571 + sbinfo->si_bbot = 0;
3574 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3575 + aufs_bindex_t bbot, aufs_bindex_t amount)
3577 + struct au_hdentry *hdp;
3579 + AuRwMustWriteLock(&dinfo->di_rwsem);
3581 + hdp = au_hdentry(dinfo, bindex);
3582 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3583 + au_h_dentry_init(hdp);
3585 + if (unlikely(bbot < 0))
3586 + dinfo->di_btop = 0;
3589 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3590 + aufs_bindex_t bbot, aufs_bindex_t amount)
3592 + struct au_hinode *hip;
3594 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3596 + hip = au_hinode(iinfo, bindex);
3597 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3598 + au_hinode_init(hip);
3600 + if (unlikely(bbot < 0))
3601 + iinfo->ii_btop = 0;
3604 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3605 + aufs_bindex_t bindex)
3607 + struct dentry *root, *h_dentry;
3608 + struct inode *root_inode, *h_inode;
3609 + aufs_bindex_t bbot, amount;
3611 + root = sb->s_root;
3612 + root_inode = d_inode(root);
3613 + bbot = au_sbbot(sb);
3614 + amount = bbot + 1 - bindex;
3615 + h_dentry = au_br_dentry(br);
3616 + au_sbilist_lock();
3617 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3618 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3619 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3620 + au_set_h_dptr(root, bindex, dget(h_dentry));
3621 + h_inode = d_inode(h_dentry);
3622 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3623 + au_sbilist_unlock();
3626 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3629 + aufs_bindex_t bbot, add_bindex;
3630 + struct dentry *root, *h_dentry;
3631 + struct inode *root_inode;
3632 + struct au_branch *add_branch;
3634 + root = sb->s_root;
3635 + root_inode = d_inode(root);
3636 + IMustLock(root_inode);
3637 + IiMustWriteLock(root_inode);
3638 + err = test_add(sb, add, remount);
3639 + if (unlikely(err < 0))
3643 + goto out; /* success */
3646 + bbot = au_sbbot(sb);
3647 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3648 + err = PTR_ERR(add_branch);
3649 + if (IS_ERR(add_branch))
3652 + err = au_br_init(add_branch, sb, add);
3653 + if (unlikely(err)) {
3654 + au_br_do_free(add_branch);
3658 + add_bindex = add->bindex;
3659 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3660 + au_br_do_add(sb, add_branch, add_bindex);
3661 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3662 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3664 + h_dentry = add->path.dentry;
3665 + if (!add_bindex) {
3666 + au_cpup_attr_all(root_inode, /*force*/1);
3667 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3669 + au_add_nlink(root_inode, d_inode(h_dentry));
3675 +/* ---------------------------------------------------------------------- */
3677 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3678 + unsigned long long max __maybe_unused,
3681 + unsigned long long n;
3682 + struct file **p, *f;
3683 + struct hlist_bl_head *files;
3684 + struct hlist_bl_node *pos;
3685 + struct au_finfo *finfo;
3689 + files = &au_sbi(sb)->si_files;
3690 + hlist_bl_lock(files);
3691 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3692 + f = finfo->fi_file;
3694 + && !special_file(file_inode(f)->i_mode)) {
3698 + AuDebugOn(n > max);
3701 + hlist_bl_unlock(files);
3706 +static struct file **au_farray_alloc(struct super_block *sb,
3707 + unsigned long long *max)
3709 + struct au_sbinfo *sbi;
3712 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3713 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3716 +static void au_farray_free(struct file **a, unsigned long long max)
3718 + unsigned long long ull;
3720 + for (ull = 0; ull < max; ull++)
3726 +/* ---------------------------------------------------------------------- */
3732 +/* to show the line number, do not make it inlined function */
3733 +#define AuVerbose(do_info, fmt, ...) do { \
3735 + pr_info(fmt, ##__VA_ARGS__); \
3738 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3739 + aufs_bindex_t bbot)
3741 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3744 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3745 + aufs_bindex_t bbot)
3747 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3751 + * test if the branch is deletable or not.
3753 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3754 + unsigned int sigen, const unsigned int verbose)
3756 + int err, i, j, ndentry;
3757 + aufs_bindex_t btop, bbot;
3758 + struct au_dcsub_pages dpages;
3759 + struct au_dpage *dpage;
3762 + err = au_dpages_init(&dpages, GFP_NOFS);
3763 + if (unlikely(err))
3765 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3766 + if (unlikely(err))
3769 + for (i = 0; !err && i < dpages.ndpage; i++) {
3770 + dpage = dpages.dpages + i;
3771 + ndentry = dpage->ndentry;
3772 + for (j = 0; !err && j < ndentry; j++) {
3773 + d = dpage->dentries[j];
3774 + AuDebugOn(au_dcount(d) <= 0);
3775 + if (!au_digen_test(d, sigen)) {
3776 + di_read_lock_child(d, AuLock_IR);
3777 + if (unlikely(au_dbrange_test(d))) {
3778 + di_read_unlock(d, AuLock_IR);
3782 + di_write_lock_child(d);
3783 + if (unlikely(au_dbrange_test(d))) {
3784 + di_write_unlock(d);
3787 + err = au_reval_dpath(d, sigen);
3789 + di_downgrade_lock(d, AuLock_IR);
3791 + di_write_unlock(d);
3796 + /* AuDbgDentry(d); */
3797 + btop = au_dbtop(d);
3798 + bbot = au_dbbot(d);
3799 + if (btop <= bindex
3801 + && au_h_dptr(d, bindex)
3802 + && au_test_dbusy(d, btop, bbot)) {
3804 + AuVerbose(verbose, "busy %pd\n", d);
3807 + di_read_unlock(d, AuLock_IR);
3812 + au_dpages_free(&dpages);
3817 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3818 + unsigned int sigen, const unsigned int verbose)
3821 + unsigned long long max, ull;
3822 + struct inode *i, **array;
3823 + aufs_bindex_t btop, bbot;
3825 + array = au_iarray_alloc(sb, &max);
3826 + err = PTR_ERR(array);
3827 + if (IS_ERR(array))
3831 + AuDbg("b%d\n", bindex);
3832 + for (ull = 0; !err && ull < max; ull++) {
3836 + if (i->i_ino == AUFS_ROOT_INO)
3839 + /* AuDbgInode(i); */
3840 + if (au_iigen(i, NULL) == sigen)
3841 + ii_read_lock_child(i);
3843 + ii_write_lock_child(i);
3844 + err = au_refresh_hinode_self(i);
3847 + ii_downgrade_lock(i);
3849 + ii_write_unlock(i);
3854 + btop = au_ibtop(i);
3855 + bbot = au_ibbot(i);
3856 + if (btop <= bindex
3858 + && au_h_iptr(i, bindex)
3859 + && au_test_ibusy(i, btop, bbot)) {
3861 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3864 + ii_read_unlock(i);
3866 + au_iarray_free(array, max);
3872 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3873 + const unsigned int verbose)
3876 + unsigned int sigen;
3878 + sigen = au_sigen(root->d_sb);
3879 + DiMustNoWaiters(root);
3880 + IiMustNoWaiters(d_inode(root));
3881 + di_write_unlock(root);
3882 + err = test_dentry_busy(root, bindex, sigen, verbose);
3884 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3885 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3890 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3891 + struct file **to_free, int *idx)
3894 + unsigned char matched, root;
3895 + aufs_bindex_t bindex, bbot;
3896 + struct au_fidir *fidir;
3897 + struct au_hfile *hfile;
3900 + root = IS_ROOT(file->f_path.dentry);
3903 + to_free[*idx] = file;
3909 + fidir = au_fi(file)->fi_hdir;
3910 + AuDebugOn(!fidir);
3911 + bbot = au_fbbot_dir(file);
3912 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3913 + hfile = fidir->fd_hfile + bindex;
3914 + if (!hfile->hf_file)
3917 + if (hfile->hf_br->br_id == br_id) {
3929 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3930 + struct file **to_free, int opened)
3933 + unsigned long long ull, max;
3934 + aufs_bindex_t btop;
3935 + struct file *file, **array;
3936 + struct dentry *root;
3937 + struct au_hfile *hfile;
3939 + array = au_farray_alloc(sb, &max);
3940 + err = PTR_ERR(array);
3941 + if (IS_ERR(array))
3946 + root = sb->s_root;
3947 + di_write_unlock(root);
3948 + for (ull = 0; ull < max; ull++) {
3949 + file = array[ull];
3950 + if (unlikely(!file))
3953 + /* AuDbg("%pD\n", file); */
3954 + fi_read_lock(file);
3955 + btop = au_fbtop(file);
3956 + if (!d_is_dir(file->f_path.dentry)) {
3957 + hfile = &au_fi(file)->fi_htop;
3958 + if (hfile->hf_br->br_id == br_id)
3961 + err = test_dir_busy(file, br_id, to_free, &idx);
3962 + fi_read_unlock(file);
3963 + if (unlikely(err))
3966 + di_write_lock_child(root);
3967 + au_farray_free(array, max);
3968 + AuDebugOn(idx > opened);
3974 +static void br_del_file(struct file **to_free, unsigned long long opened,
3975 + aufs_bindex_t br_id)
3977 + unsigned long long ull;
3978 + aufs_bindex_t bindex, btop, bbot, bfound;
3979 + struct file *file;
3980 + struct au_fidir *fidir;
3981 + struct au_hfile *hfile;
3983 + for (ull = 0; ull < opened; ull++) {
3984 + file = to_free[ull];
3985 + if (unlikely(!file))
3988 + /* AuDbg("%pD\n", file); */
3989 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3991 + fidir = au_fi(file)->fi_hdir;
3992 + AuDebugOn(!fidir);
3993 + fi_write_lock(file);
3994 + btop = au_fbtop(file);
3995 + bbot = au_fbbot_dir(file);
3996 + for (bindex = btop; bindex <= bbot; bindex++) {
3997 + hfile = fidir->fd_hfile + bindex;
3998 + if (!hfile->hf_file)
4001 + if (hfile->hf_br->br_id == br_id) {
4006 + AuDebugOn(bfound < 0);
4007 + au_set_h_fptr(file, bfound, NULL);
4008 + if (bfound == btop) {
4009 + for (btop++; btop <= bbot; btop++)
4010 + if (au_hf_dir(file, btop)) {
4011 + au_set_fbtop(file, btop);
4015 + fi_write_unlock(file);
4019 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4020 + const aufs_bindex_t bindex,
4021 + const aufs_bindex_t bbot)
4023 + struct au_branch **brp, **p;
4025 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4027 + brp = sbinfo->si_branch + bindex;
4028 + if (bindex < bbot)
4029 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4030 + sbinfo->si_branch[0 + bbot] = NULL;
4031 + sbinfo->si_bbot--;
4033 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4036 + sbinfo->si_branch = p;
4037 + /* harmless error */
4040 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4041 + const aufs_bindex_t bbot)
4043 + struct au_hdentry *hdp, *p;
4045 + AuRwMustWriteLock(&dinfo->di_rwsem);
4047 + hdp = au_hdentry(dinfo, bindex);
4048 + if (bindex < bbot)
4049 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4050 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4053 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4056 + dinfo->di_hdentry = p;
4057 + /* harmless error */
4060 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4061 + const aufs_bindex_t bbot)
4063 + struct au_hinode *hip, *p;
4065 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4067 + hip = au_hinode(iinfo, bindex);
4068 + if (bindex < bbot)
4069 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4070 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4073 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4076 + iinfo->ii_hinode = p;
4077 + /* harmless error */
4080 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4081 + struct au_branch *br)
4083 + aufs_bindex_t bbot;
4084 + struct au_sbinfo *sbinfo;
4085 + struct dentry *root, *h_root;
4086 + struct inode *inode, *h_inode;
4087 + struct au_hinode *hinode;
4089 + SiMustWriteLock(sb);
4091 + root = sb->s_root;
4092 + inode = d_inode(root);
4093 + sbinfo = au_sbi(sb);
4094 + bbot = sbinfo->si_bbot;
4096 + h_root = au_h_dptr(root, bindex);
4097 + hinode = au_hi(inode, bindex);
4098 + h_inode = au_igrab(hinode->hi_inode);
4101 + au_sbilist_lock();
4102 + au_br_do_del_brp(sbinfo, bindex, bbot);
4103 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4104 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4105 + au_sbilist_unlock();
4107 + /* ignore an error */
4108 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4112 + au_br_do_free(br);
4115 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4116 + unsigned long long max, void *arg)
4121 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4124 + unsigned long long opened;
4125 + unsigned int mnt_flags;
4126 + aufs_bindex_t bindex, bbot, br_id;
4127 + unsigned char do_wh, verbose;
4128 + struct au_branch *br;
4129 + struct au_wbr *wbr;
4130 + struct dentry *root;
4131 + struct file **to_free;
4136 + root = sb->s_root;
4137 + bindex = au_find_dbindex(root, del->h_path.dentry);
4140 + goto out; /* success */
4142 + pr_err("%s no such branch\n", del->pathname);
4145 + AuDbg("bindex b%d\n", bindex);
4148 + mnt_flags = au_mntflags(sb);
4149 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4150 + bbot = au_sbbot(sb);
4151 + if (unlikely(!bbot)) {
4152 + AuVerbose(verbose, "no more branches left\n");
4156 + br = au_sbr(sb, bindex);
4157 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4158 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4159 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4163 + br_id = br->br_id;
4164 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4165 + if (unlikely(opened)) {
4166 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4167 + err = PTR_ERR(to_free);
4168 + if (IS_ERR(to_free))
4171 + err = test_file_busy(sb, br_id, to_free, opened);
4172 + if (unlikely(err)) {
4173 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4179 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4181 + /* instead of WbrWhMustWriteLock(wbr) */
4182 + SiMustWriteLock(sb);
4183 + for (i = 0; i < AuBrWh_Last; i++) {
4184 + dput(wbr->wbr_wh[i]);
4185 + wbr->wbr_wh[i] = NULL;
4189 + err = test_children_busy(root, bindex, verbose);
4190 + if (unlikely(err)) {
4199 + * now we confirmed the branch is deletable.
4200 + * let's free the remaining opened dirs on the branch.
4202 + di_write_unlock(root);
4203 + br_del_file(to_free, opened, br_id);
4204 + di_write_lock_child(root);
4207 + sysaufs_brs_del(sb, bindex); /* remove successors */
4208 + dbgaufs_xino_del(br); /* remove one */
4209 + au_br_do_del(sb, bindex, br);
4210 + sysaufs_brs_add(sb, bindex); /* append successors */
4211 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4214 + au_cpup_attr_all(d_inode(root), /*force*/1);
4215 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4217 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4218 + if (au_opt_test(mnt_flags, PLINK))
4219 + au_plink_half_refresh(sb, br_id);
4221 + goto out; /* success */
4225 + rerr = au_br_init_wh(sb, br, br->br_perm);
4227 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4228 + del->pathname, rerr);
4231 + au_farray_free(to_free, opened);
4235 +/* ---------------------------------------------------------------------- */
4237 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4240 + aufs_bindex_t btop, bbot;
4241 + struct aufs_ibusy ibusy;
4242 + struct inode *inode, *h_inode;
4245 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4248 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4250 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4251 + if (unlikely(err)) {
4258 + si_read_lock(sb, AuLock_FLUSH);
4259 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4263 + ibusy.h_ino = 0; /* invalid */
4264 + inode = ilookup(sb, ibusy.ino);
4266 + || inode->i_ino == AUFS_ROOT_INO
4267 + || au_is_bad_inode(inode))
4270 + ii_read_lock_child(inode);
4271 + btop = au_ibtop(inode);
4272 + bbot = au_ibbot(inode);
4273 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4274 + h_inode = au_h_iptr(inode, ibusy.bindex);
4275 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4276 + ibusy.h_ino = h_inode->i_ino;
4278 + ii_read_unlock(inode);
4282 + si_read_unlock(sb);
4284 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4285 + if (unlikely(err)) {
4294 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4296 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4299 +#ifdef CONFIG_COMPAT
4300 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4302 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4306 +/* ---------------------------------------------------------------------- */
4309 + * change a branch permission
4312 +static void au_warn_ima(void)
4315 + /* since it doesn't support mark_files_ro() */
4316 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4320 +static int do_need_sigen_inc(int a, int b)
4322 + return au_br_whable(a) && !au_br_whable(b);
4325 +static int need_sigen_inc(int old, int new)
4327 + return do_need_sigen_inc(old, new)
4328 + || do_need_sigen_inc(new, old);
4331 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4334 + unsigned int mnt_flags;
4335 + unsigned long long ull, max;
4336 + aufs_bindex_t br_id;
4337 + unsigned char verbose, writer;
4338 + struct file *file, *hf, **array;
4339 + struct au_hfile *hfile;
4341 + mnt_flags = au_mntflags(sb);
4342 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4344 + array = au_farray_alloc(sb, &max);
4345 + err = PTR_ERR(array);
4346 + if (IS_ERR(array))
4350 + br_id = au_sbr_id(sb, bindex);
4351 + for (ull = 0; ull < max; ull++) {
4352 + file = array[ull];
4353 + if (unlikely(!file))
4356 + /* AuDbg("%pD\n", file); */
4357 + fi_read_lock(file);
4358 + if (unlikely(au_test_mmapped(file))) {
4360 + AuVerbose(verbose, "mmapped %pD\n", file);
4362 + FiMustNoWaiters(file);
4363 + fi_read_unlock(file);
4367 + hfile = &au_fi(file)->fi_htop;
4368 + hf = hfile->hf_file;
4369 + if (!d_is_reg(file->f_path.dentry)
4370 + || !(file->f_mode & FMODE_WRITE)
4371 + || hfile->hf_br->br_id != br_id
4372 + || !(hf->f_mode & FMODE_WRITE))
4373 + array[ull] = NULL;
4379 + FiMustNoWaiters(file);
4380 + fi_read_unlock(file);
4388 + for (ull = 0; ull < max; ull++) {
4389 + file = array[ull];
4393 + /* todo: already flushed? */
4395 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4396 + * approach which resets f_mode and calls mnt_drop_write() and
4397 + * file_release_write() for each file, because the branch
4398 + * attribute in aufs world is totally different from the native
4401 + /* fi_read_lock(file); */
4402 + hfile = &au_fi(file)->fi_htop;
4403 + hf = hfile->hf_file;
4404 + /* fi_read_unlock(file); */
4405 + spin_lock(&hf->f_lock);
4406 + writer = !!(hf->f_mode & FMODE_WRITER);
4407 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4408 + spin_unlock(&hf->f_lock);
4410 + put_write_access(file_inode(hf));
4411 + __mnt_drop_write(hf->f_path.mnt);
4416 + au_farray_free(array, max);
4422 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4426 + aufs_bindex_t bindex;
4427 + struct dentry *root;
4428 + struct au_branch *br;
4429 + struct au_br_fhsm *bf;
4431 + root = sb->s_root;
4432 + bindex = au_find_dbindex(root, mod->h_root);
4435 + return 0; /* success */
4437 + pr_err("%s no such branch\n", mod->path);
4440 + AuDbg("bindex b%d\n", bindex);
4442 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4443 + if (unlikely(err))
4446 + br = au_sbr(sb, bindex);
4447 + AuDebugOn(mod->h_root != au_br_dentry(br));
4448 + if (br->br_perm == mod->perm)
4449 + return 0; /* success */
4451 + /* pre-allocate for non-fhsm --> fhsm */
4453 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4454 + err = au_fhsm_br_alloc(br);
4455 + if (unlikely(err))
4458 + br->br_fhsm = NULL;
4461 + if (au_br_writable(br->br_perm)) {
4462 + /* remove whiteout base */
4463 + err = au_br_init_wh(sb, br, mod->perm);
4464 + if (unlikely(err))
4467 + if (!au_br_writable(mod->perm)) {
4468 + /* rw --> ro, file might be mmapped */
4469 + DiMustNoWaiters(root);
4470 + IiMustNoWaiters(d_inode(root));
4471 + di_write_unlock(root);
4472 + err = au_br_mod_files_ro(sb, bindex);
4473 + /* aufs_write_lock() calls ..._child() */
4474 + di_write_lock_child(root);
4476 + if (unlikely(err)) {
4478 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4481 + rerr = au_wbr_init(br, sb, br->br_perm);
4482 + if (unlikely(rerr)) {
4483 + AuIOErr("nested error %d (%d)\n",
4485 + br->br_perm = mod->perm;
4489 + } else if (au_br_writable(mod->perm)) {
4492 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4494 + err = au_wbr_init(br, sb, mod->perm);
4495 + if (unlikely(err)) {
4496 + au_kfree_rcu(br->br_wbr);
4497 + br->br_wbr = NULL;
4501 + if (unlikely(err))
4504 + if (au_br_fhsm(br->br_perm)) {
4505 + if (!au_br_fhsm(mod->perm)) {
4506 + /* fhsm --> non-fhsm */
4507 + au_br_fhsm_fin(br->br_fhsm);
4508 + au_kfree_rcu(br->br_fhsm);
4509 + br->br_fhsm = NULL;
4511 + } else if (au_br_fhsm(mod->perm))
4512 + /* non-fhsm --> fhsm */
4515 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4516 + br->br_perm = mod->perm;
4517 + goto out; /* success */
4520 + au_kfree_try_rcu(bf);
4526 +/* ---------------------------------------------------------------------- */
4528 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4531 + struct kstatfs kstfs;
4533 + err = vfs_statfs(&br->br_path, &kstfs);
4535 + stfs->f_blocks = kstfs.f_blocks;
4536 + stfs->f_bavail = kstfs.f_bavail;
4537 + stfs->f_files = kstfs.f_files;
4538 + stfs->f_ffree = kstfs.f_ffree;
4543 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4544 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4545 +++ linux/fs/aufs/branch.h 2019-01-28 14:36:12.219084659 +0100
4547 +/* SPDX-License-Identifier: GPL-2.0 */
4549 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4551 + * This program, aufs is free software; you can redistribute it and/or modify
4552 + * it under the terms of the GNU General Public License as published by
4553 + * the Free Software Foundation; either version 2 of the License, or
4554 + * (at your option) any later version.
4556 + * This program is distributed in the hope that it will be useful,
4557 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4558 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4559 + * GNU General Public License for more details.
4561 + * You should have received a copy of the GNU General Public License
4562 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4566 + * branch filesystems and xino for them
4569 +#ifndef __AUFS_BRANCH_H__
4570 +#define __AUFS_BRANCH_H__
4574 +#include <linux/mount.h>
4575 +#include "dirren.h"
4581 +/* ---------------------------------------------------------------------- */
4585 + struct file **xi_file;
4586 + unsigned int xi_nfile;
4592 + /* reserved for future use */
4593 + /* unsigned long *bitmap; */
4594 + wait_queue_head_t wqh;
4597 + struct mutex xi_mtx; /* protects xi_file array */
4598 + struct hlist_bl_head xi_writing;
4600 + atomic_t xi_truncating;
4602 + struct kref xi_kref;
4605 +/* File-based Hierarchical Storage Management */
4606 +struct au_br_fhsm {
4607 +#ifdef CONFIG_AUFS_FHSM
4608 + struct mutex bf_lock;
4609 + unsigned long bf_jiffy;
4610 + struct aufs_stfs bf_stfs;
4615 +/* members for writable branch only */
4616 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4618 + struct au_rwsem wbr_wh_rwsem;
4619 + struct dentry *wbr_wh[AuBrWh_Last];
4620 + atomic_t wbr_wh_running;
4621 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4622 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4623 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4626 + unsigned long long wbr_bytes;
4629 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4630 +#define AuBrDynOp (AuDyLast * 4)
4632 +#ifdef CONFIG_AUFS_HFSNOTIFY
4633 +/* support for asynchronous destruction */
4634 +struct au_br_hfsnotify {
4635 + struct fsnotify_group *hfsn_group;
4639 +/* sysfs entries */
4640 +struct au_brsysfs {
4642 + struct attribute attr;
4651 +/* protected by superblock rwsem */
4653 + struct au_xino *br_xino;
4655 + aufs_bindex_t br_id;
4658 + struct path br_path;
4659 + spinlock_t br_dykey_lock;
4660 + struct au_dykey *br_dykey[AuBrDynOp];
4661 + au_lcnt_t br_nfiles; /* opened files */
4662 + au_lcnt_t br_count; /* in-use for other */
4664 + struct au_wbr *br_wbr;
4665 + struct au_br_fhsm *br_fhsm;
4667 +#ifdef CONFIG_AUFS_HFSNOTIFY
4668 + struct au_br_hfsnotify *br_hfsn;
4671 +#ifdef CONFIG_SYSFS
4672 + /* entries under sysfs per mount-point */
4673 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4676 +#ifdef CONFIG_DEBUG_FS
4677 + struct dentry *br_dbgaufs; /* xino */
4680 + struct au_dr_br br_dirren;
4683 +/* ---------------------------------------------------------------------- */
4685 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4687 + return br->br_path.mnt;
4690 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4692 + return br->br_path.dentry;
4695 +static inline struct super_block *au_br_sb(struct au_branch *br)
4697 + return au_br_mnt(br)->mnt_sb;
4700 +static inline int au_br_rdonly(struct au_branch *br)
4702 + return (sb_rdonly(au_br_sb(br))
4703 + || !au_br_writable(br->br_perm))
4707 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4709 +#ifdef CONFIG_AUFS_HNOTIFY
4710 + return !(brperm & AuBrPerm_RR);
4716 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4718 + int err, exec_flag;
4721 + exec_flag = oflag & __FMODE_EXEC;
4722 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4728 +static inline void au_xino_get(struct au_branch *br)
4730 + struct au_xino *xi;
4734 + kref_get(&xi->xi_kref);
4737 +static inline int au_xino_count(struct au_branch *br)
4740 + struct au_xino *xi;
4745 + v = kref_read(&xi->xi_kref);
4750 +/* ---------------------------------------------------------------------- */
4754 +void au_br_free(struct au_sbinfo *sinfo);
4755 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4757 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4759 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4760 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4761 +#ifdef CONFIG_COMPAT
4762 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4765 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4768 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4771 +static const loff_t au_loff_max = LLONG_MAX;
4773 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4774 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent);
4775 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4776 + struct file *copy_src);
4778 + struct au_xino *xi; /* switch between xino and xigen */
4780 + struct path *base;
4781 + struct file *copy_src;
4783 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4785 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4787 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4789 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4791 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4792 + size_t size, loff_t *pos);
4794 +int au_xib_trunc(struct super_block *sb);
4795 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4797 +struct au_xino *au_xino_alloc(unsigned int nfile);
4798 +int au_xino_put(struct au_branch *br);
4799 +struct file *au_xino_file1(struct au_xino *xi);
4801 +struct au_opt_xino;
4802 +void au_xino_clr(struct super_block *sb);
4803 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4804 +struct file *au_xino_def(struct super_block *sb);
4805 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4806 + struct path *base);
4808 +ino_t au_xino_new_ino(struct super_block *sb);
4809 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4811 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4812 + ino_t h_ino, int idx);
4813 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4816 +int au_xino_path(struct seq_file *seq, struct file *file);
4818 +/* ---------------------------------------------------------------------- */
4820 +/* @idx is signed to accept -1 meaning the first file */
4821 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4823 + struct file *file;
4830 + if (idx < xi->xi_nfile)
4831 + file = xi->xi_file[idx];
4833 + file = au_xino_file1(xi);
4839 +/* ---------------------------------------------------------------------- */
4841 +/* Superblock to branch */
4843 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4845 + return au_sbr(sb, bindex)->br_id;
4849 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4851 + return au_br_mnt(au_sbr(sb, bindex));
4855 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4857 + return au_br_sb(au_sbr(sb, bindex));
4860 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4862 + return au_sbr(sb, bindex)->br_perm;
4865 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4867 + return au_br_whable(au_sbr_perm(sb, bindex));
4870 +/* ---------------------------------------------------------------------- */
4872 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4873 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4874 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4875 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4877 +#define wbr_wh_read_trylock_nested(wbr) \
4878 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4879 +#define wbr_wh_write_trylock_nested(wbr) \
4880 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4883 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4884 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4885 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4887 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4888 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4889 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4891 +/* ---------------------------------------------------------------------- */
4893 +#ifdef CONFIG_AUFS_FHSM
4894 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4896 + mutex_init(&brfhsm->bf_lock);
4897 + brfhsm->bf_jiffy = 0;
4898 + brfhsm->bf_readable = 0;
4901 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4903 + mutex_destroy(&brfhsm->bf_lock);
4906 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4907 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4910 +#endif /* __KERNEL__ */
4911 +#endif /* __AUFS_BRANCH_H__ */
4912 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4913 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4914 +++ linux/fs/aufs/conf.mk 2019-01-28 14:36:12.219084659 +0100
4916 +# SPDX-License-Identifier: GPL-2.0
4918 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4922 +AuConfStr += ${1}=${${1}}
4926 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4928 + HNOTIFY HFSNOTIFY \
4940 +$(foreach i, ${AuConfAll}, \
4941 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4943 +AuConfName = ${obj}/conf.str
4944 +${AuConfName}.tmp: FORCE
4945 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4946 +${AuConfName}: ${AuConfName}.tmp
4947 + @diff -q $< $@ > /dev/null 2>&1 || { \
4948 + echo ' GEN ' $@; \
4952 +clean-files += ${AuConfName} ${AuConfName}.tmp
4953 +${obj}/sysfs.o: ${AuConfName}
4955 +-include ${srctree}/${src}/conf_priv.mk
4956 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4957 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4958 +++ linux/fs/aufs/cpup.c 2019-01-28 14:36:12.219084659 +0100
4960 +// SPDX-License-Identifier: GPL-2.0
4962 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4964 + * This program, aufs is free software; you can redistribute it and/or modify
4965 + * it under the terms of the GNU General Public License as published by
4966 + * the Free Software Foundation; either version 2 of the License, or
4967 + * (at your option) any later version.
4969 + * This program is distributed in the hope that it will be useful,
4970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4972 + * GNU General Public License for more details.
4974 + * You should have received a copy of the GNU General Public License
4975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4979 + * copy-up functions, see wbr_policy.c for copy-down
4982 +#include <linux/fs_stack.h>
4983 +#include <linux/mm.h>
4984 +#include <linux/task_work.h>
4987 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4989 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4990 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4992 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4994 + dst->i_flags |= iflags & ~mask;
4995 + if (au_test_fs_notime(dst->i_sb))
4996 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4999 +void au_cpup_attr_timesizes(struct inode *inode)
5001 + struct inode *h_inode;
5003 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5004 + fsstack_copy_attr_times(inode, h_inode);
5005 + fsstack_copy_inode_size(inode, h_inode);
5008 +void au_cpup_attr_nlink(struct inode *inode, int force)
5010 + struct inode *h_inode;
5011 + struct super_block *sb;
5012 + aufs_bindex_t bindex, bbot;
5015 + bindex = au_ibtop(inode);
5016 + h_inode = au_h_iptr(inode, bindex);
5018 + && !S_ISDIR(h_inode->i_mode)
5019 + && au_opt_test(au_mntflags(sb), PLINK)
5020 + && au_plink_test(inode))
5024 + * 0 can happen in revalidating.
5025 + * h_inode->i_mutex may not be held here, but it is harmless since once
5026 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5028 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5029 + * the incorrect link count.
5031 + set_nlink(inode, h_inode->i_nlink);
5034 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5035 + * it may includes whplink directory.
5037 + if (S_ISDIR(h_inode->i_mode)) {
5038 + bbot = au_ibbot(inode);
5039 + for (bindex++; bindex <= bbot; bindex++) {
5040 + h_inode = au_h_iptr(inode, bindex);
5042 + au_add_nlink(inode, h_inode);
5047 +void au_cpup_attr_changeable(struct inode *inode)
5049 + struct inode *h_inode;
5051 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5052 + inode->i_mode = h_inode->i_mode;
5053 + inode->i_uid = h_inode->i_uid;
5054 + inode->i_gid = h_inode->i_gid;
5055 + au_cpup_attr_timesizes(inode);
5056 + au_cpup_attr_flags(inode, h_inode->i_flags);
5059 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5061 + struct au_iinfo *iinfo = au_ii(inode);
5063 + IiMustWriteLock(inode);
5065 + iinfo->ii_higen = h_inode->i_generation;
5066 + iinfo->ii_hsb1 = h_inode->i_sb;
5069 +void au_cpup_attr_all(struct inode *inode, int force)
5071 + struct inode *h_inode;
5073 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5074 + au_cpup_attr_changeable(inode);
5075 + if (inode->i_nlink > 0)
5076 + au_cpup_attr_nlink(inode, force);
5077 + inode->i_rdev = h_inode->i_rdev;
5078 + inode->i_blkbits = h_inode->i_blkbits;
5079 + au_cpup_igen(inode, h_inode);
5082 +/* ---------------------------------------------------------------------- */
5084 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5086 +/* keep the timestamps of the parent dir when cpup */
5087 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5088 + struct path *h_path)
5090 + struct inode *h_inode;
5092 + dt->dt_dentry = dentry;
5093 + dt->dt_h_path = *h_path;
5094 + h_inode = d_inode(h_path->dentry);
5095 + dt->dt_atime = h_inode->i_atime;
5096 + dt->dt_mtime = h_inode->i_mtime;
5100 +void au_dtime_revert(struct au_dtime *dt)
5102 + struct iattr attr;
5105 + attr.ia_atime = dt->dt_atime;
5106 + attr.ia_mtime = dt->dt_mtime;
5107 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5108 + | ATTR_ATIME | ATTR_ATIME_SET;
5110 + /* no delegation since this is a directory */
5111 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5112 + if (unlikely(err))
5113 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5116 +/* ---------------------------------------------------------------------- */
5118 +/* internal use only */
5119 +struct au_cpup_reg_attr {
5122 + unsigned int iflags; /* inode->i_flags */
5125 +static noinline_for_stack
5126 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5127 + struct au_cpup_reg_attr *h_src_attr)
5129 + int err, sbits, icex;
5130 + unsigned int mnt_flags;
5131 + unsigned char verbose;
5133 + struct path h_path;
5134 + struct inode *h_isrc, *h_idst;
5135 + struct kstat *h_st;
5136 + struct au_branch *br;
5138 + h_path.dentry = au_h_dptr(dst, bindex);
5139 + h_idst = d_inode(h_path.dentry);
5140 + br = au_sbr(dst->d_sb, bindex);
5141 + h_path.mnt = au_br_mnt(br);
5142 + h_isrc = d_inode(h_src);
5143 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5144 + | ATTR_ATIME | ATTR_MTIME
5145 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5146 + if (h_src_attr && h_src_attr->valid) {
5147 + h_st = &h_src_attr->st;
5148 + ia.ia_uid = h_st->uid;
5149 + ia.ia_gid = h_st->gid;
5150 + ia.ia_atime = h_st->atime;
5151 + ia.ia_mtime = h_st->mtime;
5152 + if (h_idst->i_mode != h_st->mode
5153 + && !S_ISLNK(h_idst->i_mode)) {
5154 + ia.ia_valid |= ATTR_MODE;
5155 + ia.ia_mode = h_st->mode;
5157 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5158 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5160 + ia.ia_uid = h_isrc->i_uid;
5161 + ia.ia_gid = h_isrc->i_gid;
5162 + ia.ia_atime = h_isrc->i_atime;
5163 + ia.ia_mtime = h_isrc->i_mtime;
5164 + if (h_idst->i_mode != h_isrc->i_mode
5165 + && !S_ISLNK(h_idst->i_mode)) {
5166 + ia.ia_valid |= ATTR_MODE;
5167 + ia.ia_mode = h_isrc->i_mode;
5169 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5170 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5172 + /* no delegation since it is just created */
5173 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5175 + /* is this nfs only? */
5176 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5177 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5178 + ia.ia_mode = h_isrc->i_mode;
5179 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5182 + icex = br->br_perm & AuBrAttr_ICEX;
5184 + mnt_flags = au_mntflags(dst->d_sb);
5185 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5186 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5192 +/* ---------------------------------------------------------------------- */
5194 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5195 + char *buf, unsigned long blksize)
5198 + size_t sz, rbytes, wbytes;
5199 + unsigned char all_zero;
5201 + struct inode *h_inode;
5202 + /* reduce stack usage */
5205 + zp = page_address(ZERO_PAGE(0));
5206 + if (unlikely(!zp))
5207 + return -ENOMEM; /* possible? */
5212 + AuDbg("len %lld\n", len);
5214 + if (len < blksize)
5218 + /* todo: signal_pending? */
5219 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5220 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5223 + if (unlikely(err < 0))
5227 + if (len >= rbytes && rbytes == blksize)
5228 + all_zero = !memcmp(buf, zp, rbytes);
5235 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5237 + /* todo: signal_pending? */
5238 + if (unlikely(err == -EAGAIN || err == -EINTR))
5240 + if (unlikely(err < 0))
5245 + if (unlikely(err < 0))
5251 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5253 + if (unlikely(res < 0))
5260 + /* the last block may be a hole */
5261 + if (!err && all_zero) {
5262 + AuLabel(last hole);
5265 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5266 + /* nfs requires this step to make last hole */
5267 + /* is this only nfs? */
5269 + /* todo: signal_pending? */
5270 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5271 + } while (err == -EAGAIN || err == -EINTR);
5278 + ia->ia_size = dst->f_pos;
5279 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5280 + ia->ia_file = dst;
5281 + h_inode = file_inode(dst);
5282 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5283 + /* no delegation since it is just created */
5284 + err = vfsub_notify_change(&dst->f_path, ia,
5285 + /*delegated*/NULL);
5286 + inode_unlock(h_inode);
5293 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5296 + unsigned long blksize;
5297 + unsigned char do_kfree;
5299 + struct super_block *h_sb;
5302 + h_sb = file_inode(dst)->i_sb;
5303 + blksize = h_sb->s_blocksize;
5304 + if (!blksize || PAGE_SIZE < blksize)
5305 + blksize = PAGE_SIZE;
5306 + AuDbg("blksize %lu\n", blksize);
5307 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5309 + buf = kmalloc(blksize, GFP_NOFS);
5311 + buf = (void *)__get_free_page(GFP_NOFS);
5312 + if (unlikely(!buf))
5315 + if (len > (1 << 22))
5316 + AuDbg("copying a large file %lld\n", (long long)len);
5320 + err = au_do_copy_file(dst, src, len, buf, blksize);
5322 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5323 + au_kfree_do_rcu(buf);
5325 + free_page((unsigned long)buf);
5331 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5334 + struct super_block *h_src_sb;
5335 + struct inode *h_src_inode;
5337 + h_src_inode = file_inode(src);
5338 + h_src_sb = h_src_inode->i_sb;
5340 + /* XFS acquires inode_lock */
5341 + if (!au_test_xfs(h_src_sb))
5342 + err = au_copy_file(dst, src, len);
5344 + inode_unlock_shared(h_src_inode);
5345 + err = au_copy_file(dst, src, len);
5346 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5352 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5355 + struct super_block *h_src_sb;
5356 + struct inode *h_src_inode;
5358 + h_src_inode = file_inode(src);
5359 + h_src_sb = h_src_inode->i_sb;
5360 + if (h_src_sb != file_inode(dst)->i_sb
5361 + || !dst->f_op->clone_file_range) {
5362 + err = au_do_copy(dst, src, len);
5366 + if (!au_test_nfs(h_src_sb)) {
5367 + inode_unlock_shared(h_src_inode);
5368 + err = vfsub_clone_file_range(src, dst, len);
5369 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5371 + err = vfsub_clone_file_range(src, dst, len);
5372 + /* older XFS has a condition in cloning */
5373 + if (unlikely(err != -EOPNOTSUPP))
5376 + /* the backend fs on NFS may not support cloning */
5377 + err = au_do_copy(dst, src, len);
5385 + * to support a sparse file which is opened with O_APPEND,
5386 + * we need to close the file.
5388 +static int au_cp_regular(struct au_cp_generic *cpg)
5391 + enum { SRC, DST };
5393 + aufs_bindex_t bindex;
5394 + unsigned int flags;
5395 + struct dentry *dentry;
5397 + struct file *file;
5400 + .bindex = cpg->bsrc,
5401 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5404 + .bindex = cpg->bdst,
5405 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5406 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5409 + struct au_branch *br;
5410 + struct super_block *sb, *h_src_sb;
5411 + struct inode *h_src_inode;
5412 + struct task_struct *tsk = current;
5414 + /* bsrc branch can be ro/rw. */
5415 + sb = cpg->dentry->d_sb;
5417 + for (i = 0; i < 2; i++, f++) {
5418 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5419 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5420 + /*file*/NULL, f->force_wr);
5421 + if (IS_ERR(f->file)) {
5422 + err = PTR_ERR(f->file);
5430 + /* try stopping to update while we copyup */
5431 + h_src_inode = d_inode(file[SRC].dentry);
5432 + h_src_sb = h_src_inode->i_sb;
5433 + if (!au_test_nfs(h_src_sb))
5434 + IMustLock(h_src_inode);
5435 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5437 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5438 + if (tsk->flags & PF_KTHREAD)
5439 + __fput_sync(file[DST].file);
5441 + /* it happened actually */
5442 + fput(file[DST].file);
5445 + * we have to call both since we don't know which place the file
5449 + flush_delayed_fput();
5451 + br = au_sbr(sb, file[DST].bindex);
5452 + au_lcnt_dec(&br->br_nfiles);
5455 + fput(file[SRC].file);
5456 + br = au_sbr(sb, file[SRC].bindex);
5457 + au_lcnt_dec(&br->br_nfiles);
5462 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5463 + struct au_cpup_reg_attr *h_src_attr)
5467 + struct path h_path;
5468 + struct inode *h_src_inode, *h_dst_inode;
5471 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5472 + l = i_size_read(h_src_inode);
5473 + if (cpg->len == -1 || l < cpg->len)
5476 + /* try stopping to update while we are referencing */
5477 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5478 + au_pin_hdir_unlock(cpg->pin);
5480 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5481 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5482 + h_src_attr->iflags = h_src_inode->i_flags;
5483 + if (!au_test_nfs(h_src_inode->i_sb))
5484 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5486 + inode_unlock_shared(h_src_inode);
5487 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5488 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5490 + if (unlikely(err)) {
5491 + inode_unlock_shared(h_src_inode);
5494 + h_src_attr->valid = 1;
5495 + if (!au_test_nfs(h_src_inode->i_sb)) {
5496 + err = au_cp_regular(cpg);
5497 + inode_unlock_shared(h_src_inode);
5499 + inode_unlock_shared(h_src_inode);
5500 + err = au_cp_regular(cpg);
5502 + rerr = au_pin_hdir_relock(cpg->pin);
5506 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5507 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5508 + h_dst_inode = d_inode(h_path.dentry);
5509 + spin_lock(&h_dst_inode->i_lock);
5510 + h_dst_inode->i_state |= I_LINKABLE;
5511 + spin_unlock(&h_dst_inode->i_lock);
5518 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5519 + struct inode *h_dir)
5522 + mm_segment_t old_fs;
5529 + sym.k = (void *)__get_free_page(GFP_NOFS);
5530 + if (unlikely(!sym.k))
5533 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5534 + old_fs = get_fs();
5535 + set_fs(KERNEL_DS);
5536 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5541 + sym.k[symlen] = 0;
5542 + err = vfsub_symlink(h_dir, h_path, sym.k);
5544 + free_page((unsigned long)sym.k);
5551 + * regardless 'acl' option, reset all ACL.
5552 + * All ACL will be copied up later from the original entry on the lower branch.
5554 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5557 + struct dentry *h_dentry;
5558 + struct inode *h_inode;
5560 + h_dentry = h_path->dentry;
5561 + h_inode = d_inode(h_dentry);
5562 + /* forget_all_cached_acls(h_inode)); */
5563 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5565 + if (err == -EOPNOTSUPP)
5568 + err = vfsub_acl_chmod(h_inode, mode);
5574 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5575 + struct inode *h_dir, struct path *h_path)
5578 + struct inode *dir, *inode;
5580 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5582 + if (err == -EOPNOTSUPP)
5584 + if (unlikely(err))
5588 + * strange behaviour from the users view,
5589 + * particularly setattr case
5591 + dir = d_inode(dst_parent);
5592 + if (au_ibtop(dir) == cpg->bdst)
5593 + au_cpup_attr_nlink(dir, /*force*/1);
5594 + inode = d_inode(cpg->dentry);
5595 + au_cpup_attr_nlink(inode, /*force*/1);
5601 +static noinline_for_stack
5602 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5603 + struct au_cpup_reg_attr *h_src_attr)
5607 + unsigned int mnt_flags;
5608 + unsigned char isdir, isreg, force;
5609 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5610 + struct au_dtime dt;
5611 + struct path h_path;
5612 + struct dentry *h_src, *h_dst, *h_parent;
5613 + struct inode *h_inode, *h_dir;
5614 + struct super_block *sb;
5616 + /* bsrc branch can be ro/rw. */
5617 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5618 + h_inode = d_inode(h_src);
5619 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5621 + /* try stopping to be referenced while we are creating */
5622 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5623 + if (au_ftest_cpup(cpg->flags, RENAME))
5624 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5625 + AUFS_WH_PFX_LEN));
5626 + h_parent = h_dst->d_parent; /* dir inode is locked */
5627 + h_dir = d_inode(h_parent);
5629 + AuDebugOn(h_parent != h_dst->d_parent);
5631 + sb = cpg->dentry->d_sb;
5632 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5634 + h_path.dentry = h_parent;
5635 + au_dtime_store(&dt, dst_parent, &h_path);
5637 + h_path.dentry = h_dst;
5641 + mode = h_inode->i_mode;
5642 + switch (mode & S_IFMT) {
5645 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5647 + err = au_do_cpup_regular(cpg, h_src_attr);
5651 + err = vfsub_mkdir(h_dir, &h_path, mode);
5653 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5656 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5660 + AuDebugOn(!capable(CAP_MKNOD));
5664 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5667 + AuIOErr("Unknown inode type 0%o\n", mode);
5671 + err = au_reset_acl(h_dir, &h_path, mode);
5673 + mnt_flags = au_mntflags(sb);
5674 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5676 + && au_opt_test(mnt_flags, XINO)
5677 + && (h_inode->i_nlink == 1
5678 + || (h_inode->i_state & I_LINKABLE))
5679 + /* todo: unnecessary? */
5680 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5681 + && cpg->bdst < cpg->bsrc
5682 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5683 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5684 + /* ignore this error */
5689 + force = !!cpg->len;
5690 + if (cpg->len == -1)
5691 + force = !!i_size_read(h_inode);
5693 + au_fhsm_wrote(sb, cpg->bdst, force);
5697 + au_dtime_revert(&dt);
5701 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5704 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5705 + struct inode *h_dir;
5706 + aufs_bindex_t bdst;
5708 + dentry = cpg->dentry;
5710 + h_dentry = au_h_dptr(dentry, bdst);
5711 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5713 + au_set_h_dptr(dentry, bdst, NULL);
5714 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5716 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5717 + au_set_h_dptr(dentry, bdst, h_dentry);
5720 + parent = dget_parent(dentry);
5721 + h_parent = au_h_dptr(parent, bdst);
5723 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5724 + if (IS_ERR(h_path->dentry))
5725 + err = PTR_ERR(h_path->dentry);
5727 + if (unlikely(err))
5730 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5731 + h_dir = d_inode(h_parent);
5733 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5734 + /* no delegation since it is just created */
5735 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5737 + dput(h_path->dentry);
5744 + * copyup the @dentry from @bsrc to @bdst.
5745 + * the caller must set the both of lower dentries.
5746 + * @len is for truncating when it is -1 copyup the entire file.
5747 + * in link/rename cases, @dst_parent may be different from the real one.
5748 + * basic->bsrc can be larger than basic->bdst.
5749 + * aufs doesn't touch the credential so
5750 + * security_inode_copy_up{,_xattr}() are unnecessary.
5752 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5755 + aufs_bindex_t old_ibtop;
5756 + unsigned char isdir, plink;
5757 + struct dentry *h_src, *h_dst, *h_parent;
5758 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5759 + struct super_block *sb;
5760 + struct au_branch *br;
5761 + /* to reduce stack size */
5763 + struct au_dtime dt;
5764 + struct path h_path;
5765 + struct au_cpup_reg_attr h_src_attr;
5769 + a = kmalloc(sizeof(*a), GFP_NOFS);
5772 + a->h_src_attr.valid = 0;
5774 + sb = cpg->dentry->d_sb;
5775 + br = au_sbr(sb, cpg->bdst);
5776 + a->h_path.mnt = au_br_mnt(br);
5777 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5778 + h_parent = h_dst->d_parent; /* dir inode is locked */
5779 + h_dir = d_inode(h_parent);
5782 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5783 + inode = d_inode(cpg->dentry);
5786 + dst_parent = dget_parent(cpg->dentry);
5790 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5791 + dst_inode = au_h_iptr(inode, cpg->bdst);
5793 + if (unlikely(!plink)) {
5795 + AuIOErr("hi%lu(i%lu) exists on b%d "
5796 + "but plink is disabled\n",
5797 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5801 + if (dst_inode->i_nlink) {
5802 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5804 + h_src = au_plink_lkup(inode, cpg->bdst);
5805 + err = PTR_ERR(h_src);
5806 + if (IS_ERR(h_src))
5808 + if (unlikely(d_is_negative(h_src))) {
5810 + AuIOErr("i%lu exists on b%d "
5811 + "but not pseudo-linked\n",
5812 + inode->i_ino, cpg->bdst);
5818 + a->h_path.dentry = h_parent;
5819 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5822 + a->h_path.dentry = h_dst;
5824 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5825 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5826 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5828 + au_dtime_revert(&a->dt);
5829 + if (unlikely(err == -EWOULDBLOCK)) {
5830 + pr_warn("cannot retry for NFSv4 delegation"
5831 + " for an internal link\n");
5837 + /* todo: cpup_wh_file? */
5839 + au_update_ibrange(inode, /*do_put_zero*/1);
5842 + isdir = S_ISDIR(inode->i_mode);
5843 + old_ibtop = au_ibtop(inode);
5844 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5845 + if (unlikely(err))
5847 + dst_inode = d_inode(h_dst);
5848 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5849 + /* todo: necessary? */
5850 + /* au_pin_hdir_unlock(cpg->pin); */
5852 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5853 + if (unlikely(err)) {
5854 + /* todo: necessary? */
5855 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5856 + inode_unlock(dst_inode);
5860 + if (cpg->bdst < old_ibtop) {
5861 + if (S_ISREG(inode->i_mode)) {
5862 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5863 + if (unlikely(err)) {
5864 + /* ignore an error */
5865 + /* au_pin_hdir_relock(cpg->pin); */
5866 + inode_unlock(dst_inode);
5870 + au_set_ibtop(inode, cpg->bdst);
5872 + au_set_ibbot(inode, cpg->bdst);
5873 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5874 + au_hi_flags(inode, isdir));
5876 + /* todo: necessary? */
5877 + /* err = au_pin_hdir_relock(cpg->pin); */
5878 + inode_unlock(dst_inode);
5879 + if (unlikely(err))
5882 + src_inode = d_inode(h_src);
5884 + && (src_inode->i_nlink > 1
5885 + || src_inode->i_state & I_LINKABLE)
5887 + au_plink_append(inode, cpg->bdst, h_dst);
5889 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5890 + a->h_path.dentry = h_dst;
5891 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5894 + goto out_parent; /* success */
5898 + a->h_path.dentry = h_parent;
5899 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5900 + a->h_path.dentry = h_dst;
5902 + if (d_is_positive(h_dst)) {
5904 + /* no delegation since it is just created */
5905 + rerr = vfsub_unlink(h_dir, &a->h_path,
5906 + /*delegated*/NULL, /*force*/0);
5908 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5910 + au_dtime_revert(&a->dt);
5912 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5922 +#if 0 /* reserved */
5923 +struct au_cpup_single_args {
5925 + struct au_cp_generic *cpg;
5926 + struct dentry *dst_parent;
5929 +static void au_call_cpup_single(void *args)
5931 + struct au_cpup_single_args *a = args;
5933 + au_pin_hdir_acquire_nest(a->cpg->pin);
5934 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5935 + au_pin_hdir_release(a->cpg->pin);
5940 + * prevent SIGXFSZ in copy-up.
5941 + * testing CAP_MKNOD is for generic fs,
5942 + * but CAP_FSETID is for xfs only, currently.
5944 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5947 + struct super_block *sb;
5948 + struct inode *h_dir;
5951 + sb = au_pinned_parent(pin)->d_sb;
5952 + if (!au_wkq_test()
5953 + && (!au_sbi(sb)->si_plink_maint_pid
5954 + || au_plink_maint(sb, AuLock_NOPLM))) {
5955 + switch (mode & S_IFMT) {
5957 + /* no condition about RLIMIT_FSIZE and the file size */
5962 + do_sio = !capable(CAP_MKNOD);
5966 + do_sio = ((mode & (S_ISUID | S_ISGID))
5967 + && !capable(CAP_FSETID));
5968 + /* this workaround may be removed in the future */
5970 + h_dir = au_pinned_h_dir(pin);
5971 + do_sio = h_dir->i_mode & S_ISVTX;
5978 +#if 0 /* reserved */
5979 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5982 + struct dentry *h_dentry;
5984 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5985 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5986 + err = au_cpup_single(cpg, dst_parent);
5988 + struct au_cpup_single_args args = {
5991 + .dst_parent = dst_parent
5993 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5994 + if (unlikely(wkq_err))
6003 + * copyup the @dentry from the first active lower branch to @bdst,
6004 + * using au_cpup_single().
6006 +static int au_cpup_simple(struct au_cp_generic *cpg)
6009 + unsigned int flags_orig;
6010 + struct dentry *dentry;
6012 + AuDebugOn(cpg->bsrc < 0);
6014 + dentry = cpg->dentry;
6015 + DiMustWriteLock(dentry);
6017 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6019 + flags_orig = cpg->flags;
6020 + au_fset_cpup(cpg->flags, RENAME);
6021 + err = au_cpup_single(cpg, NULL);
6022 + cpg->flags = flags_orig;
6024 + return 0; /* success */
6027 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6028 + au_set_dbtop(dentry, cpg->bsrc);
6034 +struct au_cpup_simple_args {
6036 + struct au_cp_generic *cpg;
6039 +static void au_call_cpup_simple(void *args)
6041 + struct au_cpup_simple_args *a = args;
6043 + au_pin_hdir_acquire_nest(a->cpg->pin);
6044 + *a->errp = au_cpup_simple(a->cpg);
6045 + au_pin_hdir_release(a->cpg->pin);
6048 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6051 + struct dentry *dentry, *parent;
6052 + struct file *h_file;
6053 + struct inode *h_dir;
6055 + dentry = cpg->dentry;
6057 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6058 + AuDebugOn(cpg->bsrc < 0);
6059 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6060 + err = PTR_ERR(h_file);
6061 + if (IS_ERR(h_file))
6065 + parent = dget_parent(dentry);
6066 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6067 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6068 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6069 + err = au_cpup_simple(cpg);
6071 + struct au_cpup_simple_args args = {
6075 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6076 + if (unlikely(wkq_err))
6082 + au_h_open_post(dentry, cpg->bsrc, h_file);
6088 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6090 + aufs_bindex_t bsrc, bbot;
6091 + struct dentry *dentry, *h_dentry;
6093 + if (cpg->bsrc < 0) {
6094 + dentry = cpg->dentry;
6095 + bbot = au_dbbot(dentry);
6096 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6097 + h_dentry = au_h_dptr(dentry, bsrc);
6099 + AuDebugOn(d_is_negative(h_dentry));
6103 + AuDebugOn(bsrc > bbot);
6106 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6107 + return au_do_sio_cpup_simple(cpg);
6110 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6112 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6113 + return au_do_sio_cpup_simple(cpg);
6116 +/* ---------------------------------------------------------------------- */
6119 + * copyup the deleted file for writing.
6121 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6122 + struct file *file)
6125 + unsigned int flags_orig;
6126 + aufs_bindex_t bsrc_orig;
6127 + struct au_dinfo *dinfo;
6129 + struct au_hdentry *hd;
6130 + struct dentry *h_dentry;
6133 + dinfo = au_di(cpg->dentry);
6134 + AuRwMustWriteLock(&dinfo->di_rwsem);
6136 + bsrc_orig = cpg->bsrc;
6137 + cpg->bsrc = dinfo->di_btop;
6138 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6139 + hdst.h_dentry = hdst.hd->hd_dentry;
6140 + hdst.hd->hd_dentry = wh_dentry;
6141 + dinfo->di_btop = cpg->bdst;
6143 + hsrc.h_dentry = NULL;
6145 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6146 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6147 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6149 + flags_orig = cpg->flags;
6150 + cpg->flags = !AuCpup_DTIME;
6151 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6152 + cpg->flags = flags_orig;
6155 + err = au_reopen_nondir(file);
6156 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6158 + hdst.hd->hd_dentry = hdst.h_dentry;
6159 + dinfo->di_btop = cpg->bsrc;
6160 + cpg->bsrc = bsrc_orig;
6165 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6168 + aufs_bindex_t bdst;
6169 + struct au_dtime dt;
6170 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6171 + struct au_branch *br;
6172 + struct path h_path;
6174 + dentry = cpg->dentry;
6176 + br = au_sbr(dentry->d_sb, bdst);
6177 + parent = dget_parent(dentry);
6178 + h_parent = au_h_dptr(parent, bdst);
6179 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6180 + err = PTR_ERR(wh_dentry);
6181 + if (IS_ERR(wh_dentry))
6184 + h_path.dentry = h_parent;
6185 + h_path.mnt = au_br_mnt(br);
6186 + au_dtime_store(&dt, parent, &h_path);
6187 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6188 + if (unlikely(err))
6192 + h_path.dentry = wh_dentry;
6193 + if (!d_is_dir(wh_dentry)) {
6194 + /* no delegation since it is just created */
6195 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6196 + /*delegated*/NULL, /*force*/0);
6198 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6199 + if (unlikely(err)) {
6200 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6204 + au_dtime_revert(&dt);
6205 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6214 +struct au_cpup_wh_args {
6216 + struct au_cp_generic *cpg;
6217 + struct file *file;
6220 +static void au_call_cpup_wh(void *args)
6222 + struct au_cpup_wh_args *a = args;
6224 + au_pin_hdir_acquire_nest(a->cpg->pin);
6225 + *a->errp = au_cpup_wh(a->cpg, a->file);
6226 + au_pin_hdir_release(a->cpg->pin);
6229 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6232 + aufs_bindex_t bdst;
6233 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6234 + struct inode *dir, *h_dir, *h_tmpdir;
6235 + struct au_wbr *wbr;
6236 + struct au_pin wh_pin, *pin_orig;
6238 + dentry = cpg->dentry;
6240 + parent = dget_parent(dentry);
6241 + dir = d_inode(parent);
6244 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6247 + if (!h_dir->i_nlink) {
6248 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6249 + h_orph = wbr->wbr_orph;
6251 + h_parent = dget(au_h_dptr(parent, bdst));
6252 + au_set_h_dptr(parent, bdst, dget(h_orph));
6253 + h_tmpdir = d_inode(h_orph);
6254 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6256 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6257 + /* todo: au_h_open_pre()? */
6259 + pin_orig = cpg->pin;
6260 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6261 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6262 + cpg->pin = &wh_pin;
6265 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6266 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6267 + err = au_cpup_wh(cpg, file);
6269 + struct au_cpup_wh_args args = {
6274 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6275 + if (unlikely(wkq_err))
6280 + inode_unlock(h_tmpdir);
6281 + /* todo: au_h_open_post()? */
6282 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6283 + au_set_h_dptr(parent, bdst, h_parent);
6284 + AuDebugOn(!pin_orig);
6285 + cpg->pin = pin_orig;
6293 +/* ---------------------------------------------------------------------- */
6296 + * generic routine for both of copy-up and copy-down.
6298 +/* cf. revalidate function in file.c */
6299 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6300 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6301 + struct au_pin *pin,
6302 + struct dentry *h_parent, void *arg),
6306 + struct au_pin pin;
6307 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6310 + parent = dget_parent(dentry);
6311 + if (IS_ROOT(parent))
6314 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6315 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6317 + /* do not use au_dpage */
6318 + real_parent = parent;
6321 + parent = dget_parent(dentry);
6322 + h_parent = au_h_dptr(parent, bdst);
6324 + goto out; /* success */
6326 + /* find top dir which is necessary to cpup */
6330 + parent = dget_parent(d);
6331 + di_read_lock_parent3(parent, !AuLock_IR);
6332 + h_parent = au_h_dptr(parent, bdst);
6333 + di_read_unlock(parent, !AuLock_IR);
6334 + } while (!h_parent);
6336 + if (d != real_parent)
6337 + di_write_lock_child3(d);
6339 + /* somebody else might create while we were sleeping */
6340 + h_dentry = au_h_dptr(d, bdst);
6341 + if (!h_dentry || d_is_negative(h_dentry)) {
6343 + au_update_dbtop(d);
6345 + au_pin_set_dentry(&pin, d);
6346 + err = au_do_pin(&pin);
6348 + err = cp(d, bdst, &pin, h_parent, arg);
6353 + if (d != real_parent)
6354 + di_write_unlock(d);
6355 + if (unlikely(err))
6364 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6365 + struct au_pin *pin,
6366 + struct dentry *h_parent __maybe_unused,
6367 + void *arg __maybe_unused)
6369 + struct au_cp_generic cpg = {
6375 + .flags = AuCpup_DTIME
6377 + return au_sio_cpup_simple(&cpg);
6380 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6382 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6385 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6388 + struct dentry *parent;
6389 + struct inode *dir;
6391 + parent = dget_parent(dentry);
6392 + dir = d_inode(parent);
6394 + if (au_h_iptr(dir, bdst))
6397 + di_read_unlock(parent, AuLock_IR);
6398 + di_write_lock_parent(parent);
6399 + /* someone else might change our inode while we were sleeping */
6400 + if (!au_h_iptr(dir, bdst))
6401 + err = au_cpup_dirs(dentry, bdst);
6402 + di_downgrade_lock(parent, AuLock_IR);
6408 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6409 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6410 +++ linux/fs/aufs/cpup.h 2019-01-28 14:36:12.219084659 +0100
6412 +/* SPDX-License-Identifier: GPL-2.0 */
6414 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6416 + * This program, aufs is free software; you can redistribute it and/or modify
6417 + * it under the terms of the GNU General Public License as published by
6418 + * the Free Software Foundation; either version 2 of the License, or
6419 + * (at your option) any later version.
6421 + * This program is distributed in the hope that it will be useful,
6422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6424 + * GNU General Public License for more details.
6426 + * You should have received a copy of the GNU General Public License
6427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6431 + * copy-up/down functions
6434 +#ifndef __AUFS_CPUP_H__
6435 +#define __AUFS_CPUP_H__
6439 +#include <linux/path.h>
6445 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6446 +void au_cpup_attr_timesizes(struct inode *inode);
6447 +void au_cpup_attr_nlink(struct inode *inode, int force);
6448 +void au_cpup_attr_changeable(struct inode *inode);
6449 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6450 +void au_cpup_attr_all(struct inode *inode, int force);
6452 +/* ---------------------------------------------------------------------- */
6454 +struct au_cp_generic {
6455 + struct dentry *dentry;
6456 + aufs_bindex_t bdst, bsrc;
6458 + struct au_pin *pin;
6459 + unsigned int flags;
6463 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6464 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6466 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6467 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6469 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6471 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6472 + the branch is marked as RO */
6474 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6475 +#undef AuCpup_HOPEN
6476 +#define AuCpup_HOPEN 0
6479 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6480 +#define au_fset_cpup(flags, name) \
6481 + do { (flags) |= AuCpup_##name; } while (0)
6482 +#define au_fclr_cpup(flags, name) \
6483 + do { (flags) &= ~AuCpup_##name; } while (0)
6485 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6486 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6487 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6488 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6490 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6491 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6492 + struct au_pin *pin,
6493 + struct dentry *h_parent, void *arg),
6495 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6496 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6498 +/* ---------------------------------------------------------------------- */
6500 +/* keep timestamps when copyup */
6502 + struct dentry *dt_dentry;
6503 + struct path dt_h_path;
6504 + struct timespec64 dt_atime, dt_mtime;
6506 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6507 + struct path *h_path);
6508 +void au_dtime_revert(struct au_dtime *dt);
6510 +#endif /* __KERNEL__ */
6511 +#endif /* __AUFS_CPUP_H__ */
6512 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6513 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6514 +++ linux/fs/aufs/dbgaufs.c 2019-01-28 14:36:12.219084659 +0100
6516 +// SPDX-License-Identifier: GPL-2.0
6518 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6520 + * This program, aufs is free software; you can redistribute it and/or modify
6521 + * it under the terms of the GNU General Public License as published by
6522 + * the Free Software Foundation; either version 2 of the License, or
6523 + * (at your option) any later version.
6525 + * This program is distributed in the hope that it will be useful,
6526 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6527 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6528 + * GNU General Public License for more details.
6530 + * You should have received a copy of the GNU General Public License
6531 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6535 + * debugfs interface
6538 +#include <linux/debugfs.h>
6541 +#ifndef CONFIG_SYSFS
6542 +#error DEBUG_FS depends upon SYSFS
6545 +static struct dentry *dbgaufs;
6546 +static const mode_t dbgaufs_mode = 0444;
6548 +/* 20 is max digits length of ulong 64 */
6549 +struct dbgaufs_arg {
6555 + * common function for all XINO files
6557 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6558 + struct file *file)
6562 + p = file->private_data;
6564 + /* this is struct dbgaufs_arg */
6565 + AuDebugOn(!au_kfree_sz_test(p));
6566 + au_kfree_do_rcu(p);
6571 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6576 + struct dbgaufs_arg *p;
6579 + p = kmalloc(sizeof(*p), GFP_NOFS);
6585 + file->private_data = p;
6589 + err = vfsub_getattr(&xf->f_path, &st);
6593 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6594 + cnt, st.blocks, st.blksize,
6595 + (long long)st.size);
6597 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6598 + st.blocks, st.blksize,
6599 + (long long)st.size);
6600 + AuDebugOn(p->n >= sizeof(p->a));
6602 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6610 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6611 + size_t count, loff_t *ppos)
6613 + struct dbgaufs_arg *p;
6615 + p = file->private_data;
6616 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6619 +/* ---------------------------------------------------------------------- */
6621 +struct dbgaufs_plink_arg {
6626 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6627 + struct file *file)
6629 + free_page((unsigned long)file->private_data);
6633 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6635 + int err, i, limit;
6636 + unsigned long n, sum;
6637 + struct dbgaufs_plink_arg *p;
6638 + struct au_sbinfo *sbinfo;
6639 + struct super_block *sb;
6640 + struct hlist_bl_head *hbl;
6643 + p = (void *)get_zeroed_page(GFP_NOFS);
6648 + sbinfo = inode->i_private;
6649 + sb = sbinfo->si_sb;
6650 + si_noflush_read_lock(sb);
6651 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6652 + limit = PAGE_SIZE - sizeof(p->n);
6654 + /* the number of buckets */
6655 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6660 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6662 + n = au_hbl_count(hbl);
6665 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6668 + if (unlikely(limit <= 0))
6671 + p->a[p->n - 1] = '\n';
6673 + /* the sum of plinks */
6674 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6677 + if (unlikely(limit <= 0))
6680 +#define str "1\n0\n0\n"
6681 + p->n = sizeof(str) - 1;
6682 + strcpy(p->a, str);
6685 + si_read_unlock(sb);
6688 + file->private_data = p;
6689 + goto out; /* success */
6692 + free_page((unsigned long)p);
6697 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6698 + size_t count, loff_t *ppos)
6700 + struct dbgaufs_plink_arg *p;
6702 + p = file->private_data;
6703 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6706 +static const struct file_operations dbgaufs_plink_fop = {
6707 + .owner = THIS_MODULE,
6708 + .open = dbgaufs_plink_open,
6709 + .release = dbgaufs_plink_release,
6710 + .read = dbgaufs_plink_read
6713 +/* ---------------------------------------------------------------------- */
6715 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6718 + struct au_sbinfo *sbinfo;
6719 + struct super_block *sb;
6721 + sbinfo = inode->i_private;
6722 + sb = sbinfo->si_sb;
6723 + si_noflush_read_lock(sb);
6724 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6725 + si_read_unlock(sb);
6729 +static const struct file_operations dbgaufs_xib_fop = {
6730 + .owner = THIS_MODULE,
6731 + .open = dbgaufs_xib_open,
6732 + .release = dbgaufs_xi_release,
6733 + .read = dbgaufs_xi_read
6736 +/* ---------------------------------------------------------------------- */
6738 +#define DbgaufsXi_PREFIX "xi"
6740 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6744 + aufs_bindex_t bindex;
6745 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6746 + struct au_sbinfo *sbinfo;
6747 + struct super_block *sb;
6748 + struct au_xino *xi;
6750 + struct qstr *name;
6751 + struct au_branch *br;
6754 + name = &file->f_path.dentry->d_name;
6755 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6756 + || memcmp(name->name, DbgaufsXi_PREFIX,
6757 + sizeof(DbgaufsXi_PREFIX) - 1)))
6760 + AuDebugOn(name->len >= sizeof(a));
6761 + memcpy(a, name->name, name->len);
6762 + a[name->len] = '\0';
6763 + p = strchr(a, '-');
6766 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6767 + if (unlikely(err))
6772 + err = kstrtol(p + 1, 10, &l);
6773 + if (unlikely(err))
6779 + sbinfo = inode->i_private;
6780 + sb = sbinfo->si_sb;
6781 + si_noflush_read_lock(sb);
6782 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6784 + br = au_sbr(sb, bindex);
6786 + if (unlikely(idx >= xi->xi_nfile))
6788 + xf = au_xino_file(xi, idx);
6790 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6791 + au_xino_count(br));
6794 + si_read_unlock(sb);
6800 +static const struct file_operations dbgaufs_xino_fop = {
6801 + .owner = THIS_MODULE,
6802 + .open = dbgaufs_xino_open,
6803 + .release = dbgaufs_xi_release,
6804 + .read = dbgaufs_xi_read
6807 +void dbgaufs_xino_del(struct au_branch *br)
6809 + struct dentry *dbgaufs;
6811 + dbgaufs = br->br_dbgaufs;
6815 + br->br_dbgaufs = NULL;
6816 + /* debugfs acquires the parent i_mutex */
6818 + debugfs_remove(dbgaufs);
6822 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6824 + aufs_bindex_t bbot;
6825 + struct au_branch *br;
6827 + if (!au_sbi(sb)->si_dbgaufs)
6830 + bbot = au_sbbot(sb);
6831 + for (; bindex <= bbot; bindex++) {
6832 + br = au_sbr(sb, bindex);
6833 + dbgaufs_xino_del(br);
6837 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6838 + unsigned int idx, struct dentry *parent,
6839 + struct au_sbinfo *sbinfo)
6841 + struct au_branch *br;
6843 + /* "xi" bindex(5) "-" idx(2) NULL */
6844 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6847 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6849 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6851 + br = au_sbr(sb, bindex);
6852 + if (br->br_dbgaufs) {
6853 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6855 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6856 + /* debugfs acquires the parent i_mutex */
6858 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6862 + pr_warn("failed renaming %pd/%s, ignored.\n",
6867 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6868 + sbinfo, &dbgaufs_xino_fop);
6870 + if (unlikely(!br->br_dbgaufs))
6871 + pr_warn("failed creating %pd/%s, ignored.\n",
6876 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6877 + struct dentry *parent, struct au_sbinfo *sbinfo)
6879 + struct au_branch *br;
6880 + struct au_xino *xi;
6883 + br = au_sbr(sb, bindex);
6885 + for (u = 0; u < xi->xi_nfile; u++)
6886 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6889 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6891 + struct au_sbinfo *sbinfo;
6892 + struct dentry *parent;
6893 + aufs_bindex_t bbot;
6895 + if (!au_opt_test(au_mntflags(sb), XINO))
6898 + sbinfo = au_sbi(sb);
6899 + parent = sbinfo->si_dbgaufs;
6903 + bbot = au_sbbot(sb);
6905 + for (; bindex <= bbot; bindex++)
6906 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6908 + for (; bbot >= bindex; bbot--)
6909 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6912 +/* ---------------------------------------------------------------------- */
6914 +#ifdef CONFIG_AUFS_EXPORT
6915 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6918 + struct au_sbinfo *sbinfo;
6919 + struct super_block *sb;
6921 + sbinfo = inode->i_private;
6922 + sb = sbinfo->si_sb;
6923 + si_noflush_read_lock(sb);
6924 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6925 + si_read_unlock(sb);
6929 +static const struct file_operations dbgaufs_xigen_fop = {
6930 + .owner = THIS_MODULE,
6931 + .open = dbgaufs_xigen_open,
6932 + .release = dbgaufs_xi_release,
6933 + .read = dbgaufs_xi_read
6936 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6941 + * This function is a dynamic '__init' function actually,
6942 + * so the tiny check for si_rwsem is unnecessary.
6944 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6947 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6948 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6949 + &dbgaufs_xigen_fop);
6950 + if (sbinfo->si_dbgaufs_xigen)
6956 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6960 +#endif /* CONFIG_AUFS_EXPORT */
6962 +/* ---------------------------------------------------------------------- */
6964 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6967 + * This function is a dynamic '__fin' function actually,
6968 + * so the tiny check for si_rwsem is unnecessary.
6970 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6972 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6973 + sbinfo->si_dbgaufs = NULL;
6976 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6979 + char name[SysaufsSiNameLen];
6982 + * This function is a dynamic '__init' function actually,
6983 + * so the tiny check for si_rwsem is unnecessary.
6985 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6989 + AuErr1("/debug/aufs is uninitialized\n");
6994 + sysaufs_name(sbinfo, name);
6995 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6996 + if (unlikely(!sbinfo->si_dbgaufs))
6999 + /* regardless plink/noplink option */
7000 + sbinfo->si_dbgaufs_plink = debugfs_create_file
7001 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7002 + &dbgaufs_plink_fop);
7003 + if (unlikely(!sbinfo->si_dbgaufs_plink))
7006 + /* regardless xino/noxino option */
7007 + sbinfo->si_dbgaufs_xib = debugfs_create_file
7008 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7009 + &dbgaufs_xib_fop);
7010 + if (unlikely(!sbinfo->si_dbgaufs_xib))
7013 + err = dbgaufs_xigen_init(sbinfo);
7015 + goto out; /* success */
7018 + dbgaufs_si_fin(sbinfo);
7020 + if (unlikely(err))
7021 + pr_err("debugfs/aufs failed\n");
7025 +/* ---------------------------------------------------------------------- */
7027 +void dbgaufs_fin(void)
7029 + debugfs_remove(dbgaufs);
7032 +int __init dbgaufs_init(void)
7037 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7042 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7043 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7044 +++ linux/fs/aufs/dbgaufs.h 2019-01-28 14:36:12.219084659 +0100
7046 +/* SPDX-License-Identifier: GPL-2.0 */
7048 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7050 + * This program, aufs is free software; you can redistribute it and/or modify
7051 + * it under the terms of the GNU General Public License as published by
7052 + * the Free Software Foundation; either version 2 of the License, or
7053 + * (at your option) any later version.
7055 + * This program is distributed in the hope that it will be useful,
7056 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7057 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7058 + * GNU General Public License for more details.
7060 + * You should have received a copy of the GNU General Public License
7061 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7065 + * debugfs interface
7068 +#ifndef __DBGAUFS_H__
7069 +#define __DBGAUFS_H__
7073 +struct super_block;
7077 +#ifdef CONFIG_DEBUG_FS
7079 +void dbgaufs_xino_del(struct au_branch *br);
7080 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7081 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7082 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7083 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7084 +void dbgaufs_fin(void);
7085 +int __init dbgaufs_init(void);
7087 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7088 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7089 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7091 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7092 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7093 +AuStubVoid(dbgaufs_fin, void)
7094 +AuStubInt0(__init dbgaufs_init, void)
7095 +#endif /* CONFIG_DEBUG_FS */
7097 +#endif /* __KERNEL__ */
7098 +#endif /* __DBGAUFS_H__ */
7099 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7100 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7101 +++ linux/fs/aufs/dcsub.c 2019-01-28 14:36:12.219084659 +0100
7103 +// SPDX-License-Identifier: GPL-2.0
7105 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7107 + * This program, aufs is free software; you can redistribute it and/or modify
7108 + * it under the terms of the GNU General Public License as published by
7109 + * the Free Software Foundation; either version 2 of the License, or
7110 + * (at your option) any later version.
7112 + * This program is distributed in the hope that it will be useful,
7113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7115 + * GNU General Public License for more details.
7117 + * You should have received a copy of the GNU General Public License
7118 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7122 + * sub-routines for dentry cache
7127 +static void au_dpage_free(struct au_dpage *dpage)
7130 + struct dentry **p;
7132 + p = dpage->dentries;
7133 + for (i = 0; i < dpage->ndentry; i++)
7135 + free_page((unsigned long)dpage->dentries);
7138 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7144 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7145 + if (unlikely(!dpages->dpages))
7148 + p = (void *)__get_free_page(gfp);
7152 + dpages->dpages[0].ndentry = 0;
7153 + dpages->dpages[0].dentries = p;
7154 + dpages->ndpage = 1;
7155 + return 0; /* success */
7158 + au_kfree_try_rcu(dpages->dpages);
7163 +void au_dpages_free(struct au_dcsub_pages *dpages)
7166 + struct au_dpage *p;
7168 + p = dpages->dpages;
7169 + for (i = 0; i < dpages->ndpage; i++)
7170 + au_dpage_free(p++);
7171 + au_kfree_try_rcu(dpages->dpages);
7174 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7175 + struct dentry *dentry, gfp_t gfp)
7178 + struct au_dpage *dpage;
7181 + dpage = dpages->dpages + dpages->ndpage - 1;
7182 + sz = PAGE_SIZE / sizeof(dentry);
7183 + if (unlikely(dpage->ndentry >= sz)) {
7184 + AuLabel(new dpage);
7186 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7187 + p = au_kzrealloc(dpages->dpages, sz,
7188 + sz + sizeof(*dpages->dpages), gfp,
7193 + dpages->dpages = p;
7194 + dpage = dpages->dpages + dpages->ndpage;
7195 + p = (void *)__get_free_page(gfp);
7199 + dpage->ndentry = 0;
7200 + dpage->dentries = p;
7204 + AuDebugOn(au_dcount(dentry) <= 0);
7205 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7206 + return 0; /* success */
7212 +/* todo: BAD approach */
7213 +/* copied from linux/fs/dcache.c */
7221 +extern void d_walk(struct dentry *parent, void *data,
7222 + enum d_walk_ret (*enter)(void *, struct dentry *));
7224 +struct ac_dpages_arg {
7226 + struct au_dcsub_pages *dpages;
7227 + struct super_block *sb;
7228 + au_dpages_test test;
7232 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7234 + enum d_walk_ret ret;
7235 + struct ac_dpages_arg *arg = _arg;
7237 + ret = D_WALK_CONTINUE;
7238 + if (dentry->d_sb == arg->sb
7239 + && !IS_ROOT(dentry)
7240 + && au_dcount(dentry) > 0
7242 + && (!arg->test || arg->test(dentry, arg->arg))) {
7243 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7244 + if (unlikely(arg->err))
7245 + ret = D_WALK_QUIT;
7251 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7252 + au_dpages_test test, void *arg)
7254 + struct ac_dpages_arg args = {
7262 + d_walk(root, &args, au_call_dpages_append);
7267 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7268 + int do_include, au_dpages_test test, void *arg)
7273 + write_seqlock(&rename_lock);
7274 + spin_lock(&dentry->d_lock);
7276 + && au_dcount(dentry) > 0
7277 + && (!test || test(dentry, arg)))
7278 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7279 + spin_unlock(&dentry->d_lock);
7280 + if (unlikely(err))
7284 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7287 + while (!IS_ROOT(dentry)) {
7288 + dentry = dentry->d_parent; /* rename_lock is locked */
7289 + spin_lock(&dentry->d_lock);
7290 + if (au_dcount(dentry) > 0
7291 + && (!test || test(dentry, arg)))
7292 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7293 + spin_unlock(&dentry->d_lock);
7294 + if (unlikely(err))
7299 + write_sequnlock(&rename_lock);
7303 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7305 + return au_di(dentry) && dentry->d_sb == arg;
7308 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7309 + struct dentry *dentry, int do_include)
7311 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7312 + au_dcsub_dpages_aufs, dentry->d_sb);
7315 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7317 + struct path path[2] = {
7326 + return path_is_under(path + 0, path + 1);
7328 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7329 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7330 +++ linux/fs/aufs/dcsub.h 2019-01-28 14:36:12.219084659 +0100
7332 +/* SPDX-License-Identifier: GPL-2.0 */
7334 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7336 + * This program, aufs is free software; you can redistribute it and/or modify
7337 + * it under the terms of the GNU General Public License as published by
7338 + * the Free Software Foundation; either version 2 of the License, or
7339 + * (at your option) any later version.
7341 + * This program is distributed in the hope that it will be useful,
7342 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7343 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7344 + * GNU General Public License for more details.
7346 + * You should have received a copy of the GNU General Public License
7347 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7351 + * sub-routines for dentry cache
7354 +#ifndef __AUFS_DCSUB_H__
7355 +#define __AUFS_DCSUB_H__
7359 +#include <linux/dcache.h>
7360 +#include <linux/fs.h>
7364 + struct dentry **dentries;
7367 +struct au_dcsub_pages {
7369 + struct au_dpage *dpages;
7372 +/* ---------------------------------------------------------------------- */
7375 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7376 +void au_dpages_free(struct au_dcsub_pages *dpages);
7377 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7378 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7379 + au_dpages_test test, void *arg);
7380 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7381 + int do_include, au_dpages_test test, void *arg);
7382 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7383 + struct dentry *dentry, int do_include);
7384 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7386 +/* ---------------------------------------------------------------------- */
7389 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7390 + * include/linux/dcache.h. Try them (in the future).
7393 +static inline int au_d_hashed_positive(struct dentry *d)
7396 + struct inode *inode = d_inode(d);
7399 + if (unlikely(d_unhashed(d)
7400 + || d_is_negative(d)
7401 + || !inode->i_nlink))
7406 +static inline int au_d_linkable(struct dentry *d)
7409 + struct inode *inode = d_inode(d);
7411 + err = au_d_hashed_positive(d);
7413 + && d_is_positive(d)
7414 + && (inode->i_state & I_LINKABLE))
7419 +static inline int au_d_alive(struct dentry *d)
7422 + struct inode *inode;
7426 + err = au_d_hashed_positive(d);
7428 + inode = d_inode(d);
7429 + if (unlikely(d_unlinked(d)
7430 + || d_is_negative(d)
7431 + || !inode->i_nlink))
7437 +static inline int au_alive_dir(struct dentry *d)
7441 + err = au_d_alive(d);
7442 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7447 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7449 + return a->len == b->len
7450 + && !memcmp(a->name, b->name, a->len);
7455 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7457 + * the type of d_lockref.count became int, but the inlined function d_count()
7458 + * still returns unsigned int.
7459 + * I don't know why. Maybe it is for every d_count() users?
7460 + * Anyway au_dcount() lives on.
7462 +static inline int au_dcount(struct dentry *d)
7464 + return (int)d_count(d);
7467 +#endif /* __KERNEL__ */
7468 +#endif /* __AUFS_DCSUB_H__ */
7469 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7470 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7471 +++ linux/fs/aufs/debug.c 2019-01-28 14:36:12.219084659 +0100
7473 +// SPDX-License-Identifier: GPL-2.0
7475 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7477 + * This program, aufs is free software; you can redistribute it and/or modify
7478 + * it under the terms of the GNU General Public License as published by
7479 + * the Free Software Foundation; either version 2 of the License, or
7480 + * (at your option) any later version.
7482 + * This program is distributed in the hope that it will be useful,
7483 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7484 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7485 + * GNU General Public License for more details.
7487 + * You should have received a copy of the GNU General Public License
7488 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7492 + * debug print functions
7497 +/* Returns 0, or -errno. arg is in kp->arg. */
7498 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7502 + err = kstrtoint(val, 0, &n);
7512 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7513 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7518 + return sprintf(buffer, "%d", atomic_read(a));
7521 +static struct kernel_param_ops param_ops_atomic_t = {
7522 + .set = param_atomic_t_set,
7523 + .get = param_atomic_t_get
7524 + /* void (*free)(void *arg) */
7527 +atomic_t aufs_debug = ATOMIC_INIT(0);
7528 +MODULE_PARM_DESC(debug, "debug print");
7529 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7531 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7532 +char *au_plevel = KERN_DEBUG;
7533 +#define dpri(fmt, ...) do { \
7535 + && strcmp(au_plevel, KERN_DEBUG)) \
7536 + || au_debug_test()) \
7537 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7540 +/* ---------------------------------------------------------------------- */
7542 +void au_dpri_whlist(struct au_nhash *whlist)
7544 + unsigned long ul, n;
7545 + struct hlist_head *head;
7546 + struct au_vdir_wh *pos;
7548 + n = whlist->nh_num;
7549 + head = whlist->nh_head;
7550 + for (ul = 0; ul < n; ul++) {
7551 + hlist_for_each_entry(pos, head, wh_hash)
7552 + dpri("b%d, %.*s, %d\n",
7554 + pos->wh_str.len, pos->wh_str.name,
7560 +void au_dpri_vdir(struct au_vdir *vdir)
7563 + union au_vdir_deblk_p p;
7566 + if (!vdir || IS_ERR(vdir)) {
7567 + dpri("err %ld\n", PTR_ERR(vdir));
7571 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7572 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7573 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7574 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7575 + p.deblk = vdir->vd_deblk[ul];
7577 + dpri("[%lu]: %p\n", ul, o);
7581 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7582 + struct dentry *wh)
7587 + if (!inode || IS_ERR(inode)) {
7588 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7592 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7593 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7594 + && sizeof(inode->i_blocks) != sizeof(u64));
7596 + n = (void *)wh->d_name.name;
7597 + l = wh->d_name.len;
7600 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7601 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7603 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7604 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7605 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7606 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7607 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7608 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7609 + inode->i_generation,
7610 + l ? ", wh " : "", l, n);
7614 +void au_dpri_inode(struct inode *inode)
7616 + struct au_iinfo *iinfo;
7617 + struct au_hinode *hi;
7618 + aufs_bindex_t bindex;
7621 + err = do_pri_inode(-1, inode, -1, NULL);
7622 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7625 + iinfo = au_ii(inode);
7626 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7627 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7628 + if (iinfo->ii_btop < 0)
7631 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7632 + hi = au_hinode(iinfo, bindex);
7634 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7638 +void au_dpri_dalias(struct inode *inode)
7642 + spin_lock(&inode->i_lock);
7643 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7644 + au_dpri_dentry(d);
7645 + spin_unlock(&inode->i_lock);
7648 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7650 + struct dentry *wh = NULL;
7652 + struct inode *inode;
7653 + struct au_iinfo *iinfo;
7654 + struct au_hinode *hi;
7656 + if (!dentry || IS_ERR(dentry)) {
7657 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7660 + /* do not call dget_parent() here */
7661 + /* note: access d_xxx without d_lock */
7662 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7663 + bindex, dentry, dentry,
7664 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7665 + au_dcount(dentry), dentry->d_flags,
7666 + d_unhashed(dentry) ? "un" : "");
7669 + if (d_is_positive(dentry))
7670 + inode = d_inode(dentry);
7672 + && au_test_aufs(dentry->d_sb)
7674 + && !au_is_bad_inode(inode)) {
7675 + iinfo = au_ii(inode);
7676 + hi = au_hinode(iinfo, bindex);
7678 + wh = hi->hi_whdentry;
7680 + do_pri_inode(bindex, inode, hn, wh);
7684 +void au_dpri_dentry(struct dentry *dentry)
7686 + struct au_dinfo *dinfo;
7687 + aufs_bindex_t bindex;
7690 + err = do_pri_dentry(-1, dentry);
7691 + if (err || !au_test_aufs(dentry->d_sb))
7694 + dinfo = au_di(dentry);
7697 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7698 + dinfo->di_btop, dinfo->di_bbot,
7699 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7700 + dinfo->di_tmpfile);
7701 + if (dinfo->di_btop < 0)
7703 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7704 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7707 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7711 + if (!file || IS_ERR(file)) {
7712 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7717 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7718 + && au_test_aufs(file->f_path.dentry->d_sb)
7720 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7721 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7722 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7723 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7724 + file->f_version, file->f_pos, a);
7725 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7726 + do_pri_dentry(bindex, file->f_path.dentry);
7730 +void au_dpri_file(struct file *file)
7732 + struct au_finfo *finfo;
7733 + struct au_fidir *fidir;
7734 + struct au_hfile *hfile;
7735 + aufs_bindex_t bindex;
7738 + err = do_pri_file(-1, file);
7740 + || IS_ERR_OR_NULL(file->f_path.dentry)
7741 + || !au_test_aufs(file->f_path.dentry->d_sb))
7744 + finfo = au_fi(file);
7747 + if (finfo->fi_btop < 0)
7749 + fidir = finfo->fi_hdir;
7751 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7753 + for (bindex = finfo->fi_btop;
7754 + bindex >= 0 && bindex <= fidir->fd_bbot;
7756 + hfile = fidir->fd_hfile + bindex;
7757 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7761 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7763 + struct vfsmount *mnt;
7764 + struct super_block *sb;
7766 + if (!br || IS_ERR(br))
7768 + mnt = au_br_mnt(br);
7769 + if (!mnt || IS_ERR(mnt))
7772 + if (!sb || IS_ERR(sb))
7775 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7776 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7778 + bindex, br->br_perm, br->br_id, br->br_wbr,
7779 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7780 + sb->s_flags, sb->s_count,
7781 + atomic_read(&sb->s_active),
7782 + !!au_xino_file(br->br_xino, /*idx*/-1));
7786 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7790 +void au_dpri_sb(struct super_block *sb)
7792 + struct au_sbinfo *sbinfo;
7793 + aufs_bindex_t bindex;
7795 + /* to reduce stack size */
7797 + struct vfsmount mnt;
7798 + struct au_branch fake;
7801 + /* this function can be called from magic sysrq */
7802 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7803 + if (unlikely(!a)) {
7804 + dpri("no memory\n");
7808 + a->mnt.mnt_sb = sb;
7809 + a->fake.br_path.mnt = &a->mnt;
7810 + err = do_pri_br(-1, &a->fake);
7812 + dpri("dev 0x%x\n", sb->s_dev);
7813 + if (err || !au_test_aufs(sb))
7816 + sbinfo = au_sbi(sb);
7819 + dpri("nw %d, gen %u, kobj %d\n",
7820 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7821 + kref_read(&sbinfo->si_kobj.kref));
7822 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7823 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7826 +/* ---------------------------------------------------------------------- */
7828 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7830 + struct inode *h_inode, *inode = d_inode(dentry);
7831 + struct dentry *h_dentry;
7832 + aufs_bindex_t bindex, bbot, bi;
7834 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7837 + bbot = au_dbbot(dentry);
7838 + bi = au_ibbot(inode);
7841 + bindex = au_dbtop(dentry);
7842 + bi = au_ibtop(inode);
7846 + for (; bindex <= bbot; bindex++) {
7847 + h_dentry = au_h_dptr(dentry, bindex);
7850 + h_inode = au_h_iptr(inode, bindex);
7851 + if (unlikely(h_inode != d_inode(h_dentry))) {
7853 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7854 + AuDbgDentry(dentry);
7855 + AuDbgInode(inode);
7862 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7865 + struct au_dcsub_pages dpages;
7866 + struct au_dpage *dpage;
7867 + struct dentry **dentries;
7869 + err = au_dpages_init(&dpages, GFP_NOFS);
7871 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7873 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7874 + dpage = dpages.dpages + i;
7875 + dentries = dpage->dentries;
7876 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7877 + AuDebugOn(au_digen_test(dentries[j], sigen));
7879 + au_dpages_free(&dpages);
7882 +void au_dbg_verify_kthread(void)
7884 + if (au_wkq_test()) {
7887 + * It may be recursive, but udba=notify between two aufs mounts,
7888 + * where a single ro branch is shared, is not a problem.
7894 +/* ---------------------------------------------------------------------- */
7896 +int __init au_debug_init(void)
7898 + aufs_bindex_t bindex;
7899 + struct au_vdir_destr destr;
7902 + AuDebugOn(bindex >= 0);
7905 + AuDebugOn(destr.len < NAME_MAX);
7907 +#ifdef CONFIG_4KSTACKS
7908 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7913 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7914 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7915 +++ linux/fs/aufs/debug.h 2019-01-28 14:36:12.219084659 +0100
7917 +/* SPDX-License-Identifier: GPL-2.0 */
7919 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7921 + * This program, aufs is free software; you can redistribute it and/or modify
7922 + * it under the terms of the GNU General Public License as published by
7923 + * the Free Software Foundation; either version 2 of the License, or
7924 + * (at your option) any later version.
7926 + * This program is distributed in the hope that it will be useful,
7927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7929 + * GNU General Public License for more details.
7931 + * You should have received a copy of the GNU General Public License
7932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7936 + * debug print functions
7939 +#ifndef __AUFS_DEBUG_H__
7940 +#define __AUFS_DEBUG_H__
7944 +#include <linux/atomic.h>
7945 +#include <linux/module.h>
7946 +#include <linux/kallsyms.h>
7947 +#include <linux/sysrq.h>
7949 +#ifdef CONFIG_AUFS_DEBUG
7950 +#define AuDebugOn(a) BUG_ON(a)
7952 +/* module parameter */
7953 +extern atomic_t aufs_debug;
7954 +static inline void au_debug_on(void)
7956 + atomic_inc(&aufs_debug);
7958 +static inline void au_debug_off(void)
7960 + atomic_dec_if_positive(&aufs_debug);
7963 +static inline int au_debug_test(void)
7965 + return atomic_read(&aufs_debug) > 0;
7968 +#define AuDebugOn(a) do {} while (0)
7969 +AuStubVoid(au_debug_on, void)
7970 +AuStubVoid(au_debug_off, void)
7971 +AuStubInt0(au_debug_test, void)
7972 +#endif /* CONFIG_AUFS_DEBUG */
7974 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7976 +/* ---------------------------------------------------------------------- */
7980 +#define AuDbg(fmt, ...) do { \
7981 + if (au_debug_test()) \
7982 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7984 +#define AuLabel(l) AuDbg(#l "\n")
7985 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7986 +#define AuWarn1(fmt, ...) do { \
7987 + static unsigned char _c; \
7989 + pr_warn(fmt, ##__VA_ARGS__); \
7992 +#define AuErr1(fmt, ...) do { \
7993 + static unsigned char _c; \
7995 + pr_err(fmt, ##__VA_ARGS__); \
7998 +#define AuIOErr1(fmt, ...) do { \
7999 + static unsigned char _c; \
8001 + AuIOErr(fmt, ##__VA_ARGS__); \
8004 +#define AuUnsupportMsg "This operation is not supported." \
8005 + " Please report this application to aufs-users ML."
8006 +#define AuUnsupport(fmt, ...) do { \
8007 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
8011 +#define AuTraceErr(e) do { \
8012 + if (unlikely((e) < 0)) \
8013 + AuDbg("err %d\n", (int)(e)); \
8016 +#define AuTraceErrPtr(p) do { \
8018 + AuDbg("err %ld\n", PTR_ERR(p)); \
8021 +/* dirty macros for debug print, use with "%.*s" and caution */
8022 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8024 +/* ---------------------------------------------------------------------- */
8027 +#ifdef CONFIG_AUFS_DEBUG
8028 +extern struct mutex au_dbg_mtx;
8029 +extern char *au_plevel;
8031 +void au_dpri_whlist(struct au_nhash *whlist);
8033 +void au_dpri_vdir(struct au_vdir *vdir);
8035 +void au_dpri_inode(struct inode *inode);
8036 +void au_dpri_dalias(struct inode *inode);
8037 +void au_dpri_dentry(struct dentry *dentry);
8039 +void au_dpri_file(struct file *filp);
8040 +struct super_block;
8041 +void au_dpri_sb(struct super_block *sb);
8043 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8044 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8045 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8046 +void au_dbg_verify_kthread(void);
8048 +int __init au_debug_init(void);
8050 +#define AuDbgWhlist(w) do { \
8051 + mutex_lock(&au_dbg_mtx); \
8053 + au_dpri_whlist(w); \
8054 + mutex_unlock(&au_dbg_mtx); \
8057 +#define AuDbgVdir(v) do { \
8058 + mutex_lock(&au_dbg_mtx); \
8060 + au_dpri_vdir(v); \
8061 + mutex_unlock(&au_dbg_mtx); \
8064 +#define AuDbgInode(i) do { \
8065 + mutex_lock(&au_dbg_mtx); \
8067 + au_dpri_inode(i); \
8068 + mutex_unlock(&au_dbg_mtx); \
8071 +#define AuDbgDAlias(i) do { \
8072 + mutex_lock(&au_dbg_mtx); \
8074 + au_dpri_dalias(i); \
8075 + mutex_unlock(&au_dbg_mtx); \
8078 +#define AuDbgDentry(d) do { \
8079 + mutex_lock(&au_dbg_mtx); \
8081 + au_dpri_dentry(d); \
8082 + mutex_unlock(&au_dbg_mtx); \
8085 +#define AuDbgFile(f) do { \
8086 + mutex_lock(&au_dbg_mtx); \
8088 + au_dpri_file(f); \
8089 + mutex_unlock(&au_dbg_mtx); \
8092 +#define AuDbgSb(sb) do { \
8093 + mutex_lock(&au_dbg_mtx); \
8094 + AuDbg(#sb "\n"); \
8096 + mutex_unlock(&au_dbg_mtx); \
8099 +#define AuDbgSym(addr) do { \
8100 + char sym[KSYM_SYMBOL_LEN]; \
8101 + sprint_symbol(sym, (unsigned long)addr); \
8102 + AuDbg("%s\n", sym); \
8105 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8106 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8107 +AuStubVoid(au_dbg_verify_kthread, void)
8108 +AuStubInt0(__init au_debug_init, void)
8110 +#define AuDbgWhlist(w) do {} while (0)
8111 +#define AuDbgVdir(v) do {} while (0)
8112 +#define AuDbgInode(i) do {} while (0)
8113 +#define AuDbgDAlias(i) do {} while (0)
8114 +#define AuDbgDentry(d) do {} while (0)
8115 +#define AuDbgFile(f) do {} while (0)
8116 +#define AuDbgSb(sb) do {} while (0)
8117 +#define AuDbgSym(addr) do {} while (0)
8118 +#endif /* CONFIG_AUFS_DEBUG */
8120 +/* ---------------------------------------------------------------------- */
8122 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8123 +int __init au_sysrq_init(void);
8124 +void au_sysrq_fin(void);
8126 +#ifdef CONFIG_HW_CONSOLE
8127 +#define au_dbg_blocked() do { \
8129 + handle_sysrq('w'); \
8132 +AuStubVoid(au_dbg_blocked, void)
8136 +AuStubInt0(__init au_sysrq_init, void)
8137 +AuStubVoid(au_sysrq_fin, void)
8138 +AuStubVoid(au_dbg_blocked, void)
8139 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8141 +#endif /* __KERNEL__ */
8142 +#endif /* __AUFS_DEBUG_H__ */
8143 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8144 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8145 +++ linux/fs/aufs/dentry.c 2019-01-28 14:36:12.219084659 +0100
8147 +// SPDX-License-Identifier: GPL-2.0
8149 + * Copyright (C) 2005-2018 Junjiro R. Okajima
8151 + * This program, aufs is free software; you can redistribute it and/or modify
8152 + * it under the terms of the GNU General Public License as published by
8153 + * the Free Software Foundation; either version 2 of the License, or
8154 + * (at your option) any later version.
8156 + * This program is distributed in the hope that it will be useful,
8157 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8158 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8159 + * GNU General Public License for more details.
8161 + * You should have received a copy of the GNU General Public License
8162 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8166 + * lookup and dentry operations
8169 +#include <linux/namei.h>
8173 + * returns positive/negative dentry, NULL or an error.
8174 + * NULL means whiteout-ed or not-found.
8176 +static struct dentry*
8177 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8178 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8180 + struct dentry *h_dentry;
8181 + struct inode *h_inode;
8182 + struct au_branch *br;
8183 + int wh_found, opq;
8184 + unsigned char wh_able;
8185 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8186 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8190 + br = au_sbr(dentry->d_sb, bindex);
8191 + wh_able = !!au_br_whable(br->br_perm);
8193 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8194 + h_dentry = ERR_PTR(wh_found);
8197 + if (unlikely(wh_found < 0))
8200 + /* We found a whiteout */
8201 + /* au_set_dbbot(dentry, bindex); */
8202 + au_set_dbwh(dentry, bindex);
8204 + return NULL; /* success */
8208 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8210 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8211 + if (IS_ERR(h_dentry)) {
8212 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8218 + h_inode = d_inode(h_dentry);
8219 + if (d_is_negative(h_dentry)) {
8222 + } else if (wh_found
8223 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8225 + else if (au_ftest_lkup(args->flags, DIRREN)
8227 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8228 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8229 + (unsigned long long)h_inode->i_ino);
8233 + if (au_dbbot(dentry) <= bindex)
8234 + au_set_dbbot(dentry, bindex);
8235 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8236 + au_set_dbtop(dentry, bindex);
8237 + au_set_h_dptr(dentry, bindex, h_dentry);
8239 + if (!d_is_dir(h_dentry)
8241 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8242 + goto out; /* success */
8244 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8245 + opq = au_diropq_test(h_dentry);
8246 + inode_unlock_shared(h_inode);
8248 + au_set_dbdiropq(dentry, bindex);
8249 + else if (unlikely(opq < 0)) {
8250 + au_set_h_dptr(dentry, bindex, NULL);
8251 + h_dentry = ERR_PTR(opq);
8262 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8264 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8265 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8271 + * returns the number of lower positive dentries,
8272 + * otherwise an error.
8273 + * can be called at unlinking with @type is zero.
8275 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8276 + unsigned int flags)
8278 + int npositive, err;
8279 + aufs_bindex_t bindex, btail, bdiropq;
8280 + unsigned char isdir, dirperm1, dirren;
8281 + struct au_do_lookup_args args = {
8283 + .name = &dentry->d_name
8285 + struct dentry *parent;
8286 + struct super_block *sb;
8288 + sb = dentry->d_sb;
8289 + err = au_test_shwh(sb, args.name);
8290 + if (unlikely(err))
8293 + err = au_wh_name_alloc(&args.whname, args.name);
8294 + if (unlikely(err))
8297 + isdir = !!d_is_dir(dentry);
8298 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8299 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8301 + au_fset_lkup(args.flags, DIRREN);
8304 + parent = dget_parent(dentry);
8305 + btail = au_dbtaildir(parent);
8306 + for (bindex = btop; bindex <= btail; bindex++) {
8307 + struct dentry *h_parent, *h_dentry;
8308 + struct inode *h_inode, *h_dir;
8309 + struct au_branch *br;
8311 + h_dentry = au_h_dptr(dentry, bindex);
8313 + if (d_is_positive(h_dentry))
8317 + h_parent = au_h_dptr(parent, bindex);
8318 + if (!h_parent || !d_is_dir(h_parent))
8322 + /* if the inum matches, then use the prepared name */
8323 + err = au_dr_lkup_name(&args, bindex);
8324 + if (unlikely(err))
8328 + h_dir = d_inode(h_parent);
8329 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8330 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8331 + inode_unlock_shared(h_dir);
8332 + err = PTR_ERR(h_dentry);
8333 + if (IS_ERR(h_dentry))
8336 + au_fclr_lkup(args.flags, ALLOW_NEG);
8338 + au_fset_lkup(args.flags, IGNORE_PERM);
8340 + if (au_dbwh(dentry) == bindex)
8344 + if (d_is_negative(h_dentry))
8346 + h_inode = d_inode(h_dentry);
8349 + args.type = h_inode->i_mode & S_IFMT;
8350 + if (args.type != S_IFDIR)
8353 + /* the type of lower may be different */
8354 + bdiropq = au_dbdiropq(dentry);
8355 + if (bdiropq >= 0 && bdiropq <= bindex)
8358 + br = au_sbr(sb, bindex);
8360 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8361 + /*add_ent*/NULL)) {
8362 + /* prepare next name to lookup */
8363 + err = au_dr_lkup(&args, dentry, bindex);
8364 + if (unlikely(err))
8370 + AuLabel(positive);
8371 + au_update_dbtop(dentry);
8374 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8375 + && au_dbtop(dentry) < 0)) {
8377 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8383 + au_kfree_try_rcu(args.whname.name);
8385 + au_dr_lkup_fin(&args);
8390 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8392 + struct dentry *dentry;
8395 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8396 + dentry = vfsub_lkup_one(name, parent);
8398 + struct vfsub_lkup_one_args args = {
8404 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8405 + if (unlikely(wkq_err))
8406 + dentry = ERR_PTR(wkq_err);
8413 + * lookup @dentry on @bindex which should be negative.
8415 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8418 + struct dentry *parent, *h_parent, *h_dentry;
8419 + struct au_branch *br;
8421 + parent = dget_parent(dentry);
8422 + h_parent = au_h_dptr(parent, bindex);
8423 + br = au_sbr(dentry->d_sb, bindex);
8425 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8427 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8428 + err = PTR_ERR(h_dentry);
8429 + if (IS_ERR(h_dentry))
8431 + if (unlikely(d_is_positive(h_dentry))) {
8433 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8439 + if (bindex < au_dbtop(dentry))
8440 + au_set_dbtop(dentry, bindex);
8441 + if (au_dbbot(dentry) < bindex)
8442 + au_set_dbbot(dentry, bindex);
8443 + au_set_h_dptr(dentry, bindex, h_dentry);
8450 +/* ---------------------------------------------------------------------- */
8452 +/* subset of struct inode */
8454 + unsigned long i_ino;
8455 + /* unsigned int i_nlink; */
8461 + blkcnt_t i_blocks;
8466 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8468 + ia->i_ino = h_inode->i_ino;
8469 + /* ia->i_nlink = h_inode->i_nlink; */
8470 + ia->i_uid = h_inode->i_uid;
8471 + ia->i_gid = h_inode->i_gid;
8472 + ia->i_version = inode_query_iversion(h_inode);
8474 + ia->i_size = h_inode->i_size;
8475 + ia->i_blocks = h_inode->i_blocks;
8477 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8480 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8482 + return ia->i_ino != h_inode->i_ino
8483 + /* || ia->i_nlink != h_inode->i_nlink */
8484 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8485 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8486 + || !inode_eq_iversion(h_inode, ia->i_version)
8488 + || ia->i_size != h_inode->i_size
8489 + || ia->i_blocks != h_inode->i_blocks
8491 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8494 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8495 + struct au_branch *br)
8498 + struct au_iattr ia;
8499 + struct inode *h_inode;
8500 + struct dentry *h_d;
8501 + struct super_block *h_sb;
8504 + memset(&ia, -1, sizeof(ia));
8505 + h_sb = h_dentry->d_sb;
8507 + if (d_is_positive(h_dentry)) {
8508 + h_inode = d_inode(h_dentry);
8509 + au_iattr_save(&ia, h_inode);
8510 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8511 + /* nfs d_revalidate may return 0 for negative dentry */
8512 + /* fuse d_revalidate always return 0 for negative dentry */
8515 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8516 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8517 + err = PTR_ERR(h_d);
8522 + if (unlikely(h_d != h_dentry
8523 + || d_inode(h_d) != h_inode
8524 + || (h_inode && au_iattr_test(&ia, h_inode))))
8525 + err = au_busy_or_stale();
8533 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8534 + struct dentry *h_parent, struct au_branch *br)
8539 + if (udba == AuOpt_UDBA_REVAL
8540 + && !au_test_fs_remote(h_dentry->d_sb)) {
8542 + err = (d_inode(h_dentry->d_parent) != h_dir);
8543 + } else if (udba != AuOpt_UDBA_NONE)
8544 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8549 +/* ---------------------------------------------------------------------- */
8551 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8554 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8555 + struct au_hdentry tmp, *p, *q;
8556 + struct au_dinfo *dinfo;
8557 + struct super_block *sb;
8559 + DiMustWriteLock(dentry);
8561 + sb = dentry->d_sb;
8562 + dinfo = au_di(dentry);
8563 + bbot = dinfo->di_bbot;
8564 + bwh = dinfo->di_bwh;
8565 + bdiropq = dinfo->di_bdiropq;
8566 + bindex = dinfo->di_btop;
8567 + p = au_hdentry(dinfo, bindex);
8568 + for (; bindex <= bbot; bindex++, p++) {
8569 + if (!p->hd_dentry)
8572 + new_bindex = au_br_index(sb, p->hd_id);
8573 + if (new_bindex == bindex)
8576 + if (dinfo->di_bwh == bindex)
8578 + if (dinfo->di_bdiropq == bindex)
8579 + bdiropq = new_bindex;
8580 + if (new_bindex < 0) {
8582 + p->hd_dentry = NULL;
8586 + /* swap two lower dentries, and loop again */
8587 + q = au_hdentry(dinfo, new_bindex);
8591 + if (tmp.hd_dentry) {
8597 + dinfo->di_bwh = -1;
8598 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8599 + dinfo->di_bwh = bwh;
8601 + dinfo->di_bdiropq = -1;
8603 + && bdiropq <= au_sbbot(sb)
8604 + && au_sbr_whable(sb, bdiropq))
8605 + dinfo->di_bdiropq = bdiropq;
8608 + dinfo->di_btop = -1;
8609 + dinfo->di_bbot = -1;
8610 + bbot = au_dbbot(parent);
8612 + p = au_hdentry(dinfo, bindex);
8613 + for (; bindex <= bbot; bindex++, p++)
8614 + if (p->hd_dentry) {
8615 + dinfo->di_btop = bindex;
8619 + if (dinfo->di_btop >= 0) {
8621 + p = au_hdentry(dinfo, bindex);
8622 + for (; bindex >= 0; bindex--, p--)
8623 + if (p->hd_dentry) {
8624 + dinfo->di_bbot = bindex;
8633 +static void au_do_hide(struct dentry *dentry)
8635 + struct inode *inode;
8637 + if (d_really_is_positive(dentry)) {
8638 + inode = d_inode(dentry);
8639 + if (!d_is_dir(dentry)) {
8640 + if (inode->i_nlink && !d_unhashed(dentry))
8641 + drop_nlink(inode);
8643 + clear_nlink(inode);
8644 + /* stop next lookup */
8645 + inode->i_flags |= S_DEAD;
8647 + smp_mb(); /* necessary? */
8652 +static int au_hide_children(struct dentry *parent)
8654 + int err, i, j, ndentry;
8655 + struct au_dcsub_pages dpages;
8656 + struct au_dpage *dpage;
8657 + struct dentry *dentry;
8659 + err = au_dpages_init(&dpages, GFP_NOFS);
8660 + if (unlikely(err))
8662 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8663 + if (unlikely(err))
8666 + /* in reverse order */
8667 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8668 + dpage = dpages.dpages + i;
8669 + ndentry = dpage->ndentry;
8670 + for (j = ndentry - 1; j >= 0; j--) {
8671 + dentry = dpage->dentries[j];
8672 + if (dentry != parent)
8673 + au_do_hide(dentry);
8678 + au_dpages_free(&dpages);
8683 +static void au_hide(struct dentry *dentry)
8687 + AuDbgDentry(dentry);
8688 + if (d_is_dir(dentry)) {
8689 + /* shrink_dcache_parent(dentry); */
8690 + err = au_hide_children(dentry);
8691 + if (unlikely(err))
8692 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8695 + au_do_hide(dentry);
8699 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8701 + * a dirty branch is added
8702 + * - on the top of layers
8703 + * - in the middle of layers
8704 + * - to the bottom of layers
8706 + * on the added branch there exists
8709 + * - a same named entry
8711 + * * negative --> positive
8712 + * * positive --> positive
8713 + * - type is unchanged
8714 + * - type is changed
8716 + * * negative --> negative
8717 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8720 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8721 + struct au_dinfo *tmp)
8724 + aufs_bindex_t bindex, bbot;
8726 + struct dentry *dentry;
8727 + struct inode *inode;
8729 + } orig_h, tmp_h = {
8732 + struct au_hdentry *hd;
8733 + struct inode *inode, *h_inode;
8734 + struct dentry *h_dentry;
8737 + AuDebugOn(dinfo->di_btop < 0);
8739 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8740 + orig_h.inode = NULL;
8741 + if (d_is_positive(orig_h.dentry)) {
8742 + orig_h.inode = d_inode(orig_h.dentry);
8743 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8745 + if (tmp->di_btop >= 0) {
8746 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8747 + if (d_is_positive(tmp_h.dentry)) {
8748 + tmp_h.inode = d_inode(tmp_h.dentry);
8749 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8754 + if (d_really_is_positive(dentry))
8755 + inode = d_inode(dentry);
8756 + if (!orig_h.inode) {
8757 + AuDbg("negative originally\n");
8763 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8764 + AuDebugOn(dinfo->di_bdiropq != -1);
8766 + if (!tmp_h.inode) {
8767 + AuDbg("negative --> negative\n");
8768 + /* should have only one negative lower */
8769 + if (tmp->di_btop >= 0
8770 + && tmp->di_btop < dinfo->di_btop) {
8771 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8772 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8773 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8774 + au_di_cp(dinfo, tmp);
8775 + hd = au_hdentry(tmp, tmp->di_btop);
8776 + au_set_h_dptr(dentry, tmp->di_btop,
8777 + dget(hd->hd_dentry));
8779 + au_dbg_verify_dinode(dentry);
8781 + AuDbg("negative --> positive\n");
8783 + * similar to the behaviour of creating with bypassing
8785 + * unhash it in order to force an error in the
8786 + * succeeding create operation.
8787 + * we should not set S_DEAD here.
8790 + /* au_di_swap(tmp, dinfo); */
8791 + au_dbg_verify_dinode(dentry);
8794 + AuDbg("positive originally\n");
8795 + /* inode may be NULL */
8796 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8797 + if (!tmp_h.inode) {
8798 + AuDbg("positive --> negative\n");
8799 + /* or bypassing aufs */
8801 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8802 + dinfo->di_bwh = tmp->di_bwh;
8804 + err = au_refresh_hinode_self(inode);
8805 + au_dbg_verify_dinode(dentry);
8806 + } else if (orig_h.mode == tmp_h.mode) {
8807 + AuDbg("positive --> positive, same type\n");
8808 + if (!S_ISDIR(orig_h.mode)
8809 + && dinfo->di_btop > tmp->di_btop) {
8811 + * similar to the behaviour of removing and
8816 + err = au_refresh_hinode_self(inode);
8817 + au_dbg_verify_dinode(dentry);
8819 + /* fill empty slots */
8820 + if (dinfo->di_btop > tmp->di_btop)
8821 + dinfo->di_btop = tmp->di_btop;
8822 + if (dinfo->di_bbot < tmp->di_bbot)
8823 + dinfo->di_bbot = tmp->di_bbot;
8824 + dinfo->di_bwh = tmp->di_bwh;
8825 + dinfo->di_bdiropq = tmp->di_bdiropq;
8826 + bbot = dinfo->di_bbot;
8827 + bindex = tmp->di_btop;
8828 + hd = au_hdentry(tmp, bindex);
8829 + for (; bindex <= bbot; bindex++, hd++) {
8830 + if (au_h_dptr(dentry, bindex))
8832 + h_dentry = hd->hd_dentry;
8835 + AuDebugOn(d_is_negative(h_dentry));
8836 + h_inode = d_inode(h_dentry);
8837 + AuDebugOn(orig_h.mode
8838 + != (h_inode->i_mode
8840 + au_set_h_dptr(dentry, bindex,
8844 + err = au_refresh_hinode(inode, dentry);
8845 + au_dbg_verify_dinode(dentry);
8848 + AuDbg("positive --> positive, different type\n");
8849 + /* similar to the behaviour of removing and creating */
8852 + err = au_refresh_hinode_self(inode);
8853 + au_dbg_verify_dinode(dentry);
8861 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8863 + const struct dentry_operations *dop
8864 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8865 + static const unsigned int mask
8866 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8868 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8870 + if (dentry->d_op == dop)
8873 + AuDbg("%pd\n", dentry);
8874 + spin_lock(&dentry->d_lock);
8875 + if (dop == &aufs_dop)
8876 + dentry->d_flags |= mask;
8878 + dentry->d_flags &= ~mask;
8879 + dentry->d_op = dop;
8880 + spin_unlock(&dentry->d_lock);
8883 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8885 + int err, ebrange, nbr;
8886 + unsigned int sigen;
8887 + struct au_dinfo *dinfo, *tmp;
8888 + struct super_block *sb;
8889 + struct inode *inode;
8891 + DiMustWriteLock(dentry);
8892 + AuDebugOn(IS_ROOT(dentry));
8893 + AuDebugOn(d_really_is_negative(parent));
8895 + sb = dentry->d_sb;
8896 + sigen = au_sigen(sb);
8897 + err = au_digen_test(parent, sigen);
8898 + if (unlikely(err))
8901 + nbr = au_sbbot(sb) + 1;
8902 + dinfo = au_di(dentry);
8903 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8904 + if (unlikely(err))
8906 + ebrange = au_dbrange_test(dentry);
8908 + ebrange = au_do_refresh_hdentry(dentry, parent);
8910 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8911 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8912 + if (d_really_is_positive(dentry)) {
8913 + inode = d_inode(dentry);
8914 + err = au_refresh_hinode_self(inode);
8916 + au_dbg_verify_dinode(dentry);
8918 + goto out_dgen; /* success */
8922 + /* temporary dinfo */
8923 + AuDbgDentry(dentry);
8925 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8926 + if (unlikely(!tmp))
8928 + au_di_swap(tmp, dinfo);
8929 + /* returns the number of positive dentries */
8931 + * if current working dir is removed, it returns an error.
8932 + * but the dentry is legal.
8934 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8935 + AuDbgDentry(dentry);
8936 + au_di_swap(tmp, dinfo);
8937 + if (err == -ENOENT)
8940 + /* compare/refresh by dinfo */
8941 + AuDbgDentry(dentry);
8942 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8943 + au_dbg_verify_dinode(dentry);
8946 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8947 + au_rw_write_unlock(&tmp->di_rwsem);
8949 + if (unlikely(err))
8953 + au_update_digen(dentry);
8955 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8956 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8957 + AuDbgDentry(dentry);
8963 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8964 + struct dentry *dentry, aufs_bindex_t bindex)
8969 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8972 + AuDbg("b%d\n", bindex);
8974 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8975 + * due to whiteout and branch permission.
8977 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8978 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8979 + /* it may return tri-state */
8980 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8982 + if (unlikely(valid < 0))
8992 +/* todo: remove this */
8993 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8994 + unsigned int flags, int do_udba, int dirren)
8997 + umode_t mode, h_mode;
8998 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8999 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
9000 + struct inode *h_inode, *h_cached_inode;
9001 + struct dentry *h_dentry;
9002 + struct qstr *name, *h_name;
9009 + unhashed = !!d_unhashed(dentry);
9010 + is_root = !!IS_ROOT(dentry);
9011 + name = &dentry->d_name;
9012 + tmpfile = au_di(dentry)->di_tmpfile;
9015 + * Theoretically, REVAL test should be unnecessary in case of
9017 + * But {fs,i}notify doesn't fire some necessary events,
9018 + * IN_ATTRIB for atime/nlink/pageio
9019 + * Let's do REVAL test too.
9021 + if (do_udba && inode) {
9022 + mode = (inode->i_mode & S_IFMT);
9023 + plus = (inode->i_nlink > 0);
9024 + ibs = au_ibtop(inode);
9025 + ibe = au_ibbot(inode);
9028 + btop = au_dbtop(dentry);
9030 + if (inode && S_ISDIR(inode->i_mode))
9031 + btail = au_dbtaildir(dentry);
9032 + for (bindex = btop; bindex <= btail; bindex++) {
9033 + h_dentry = au_h_dptr(dentry, bindex);
9037 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9038 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9039 + spin_lock(&h_dentry->d_lock);
9040 + h_name = &h_dentry->d_name;
9041 + if (unlikely(do_udba
9044 + && (unhashed != !!d_unhashed(h_dentry)
9045 + || (!tmpfile && !dirren
9046 + && !au_qstreq(name, h_name))
9049 + && !(flags & LOOKUP_OPEN)
9050 + && (h_dentry->d_flags
9051 + & DCACHE_NFSFS_RENAMED)))
9055 + h_unhashed = d_unhashed(h_dentry);
9056 + spin_unlock(&h_dentry->d_lock);
9057 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9058 + unhashed, h_unhashed, dentry, h_dentry);
9061 + spin_unlock(&h_dentry->d_lock);
9063 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9064 + if (unlikely(err))
9065 + /* do not goto err, to keep the errno */
9068 + /* todo: plink too? */
9073 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9077 + if (d_is_positive(h_dentry))
9078 + h_inode = d_inode(h_dentry);
9081 + h_cached_inode = h_inode;
9083 + h_mode = (h_inode->i_mode & S_IFMT);
9084 + h_plus = (h_inode->i_nlink > 0);
9086 + if (inode && ibs <= bindex && bindex <= ibe)
9087 + h_cached_inode = au_h_iptr(inode, bindex);
9090 + if (unlikely(plus != h_plus && !tmpfile))
9093 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9095 + && !IS_ROOT(h_dentry)
9096 + && unhashed != d_unhashed(h_dentry)))
9099 + if (unlikely(mode != h_mode
9100 + || h_cached_inode != h_inode))
9113 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9114 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9117 + struct dentry *parent;
9119 + if (!au_digen_test(dentry, sigen))
9122 + parent = dget_parent(dentry);
9123 + di_read_lock_parent(parent, AuLock_IR);
9124 + AuDebugOn(au_digen_test(parent, sigen));
9125 + au_dbg_verify_gen(parent, sigen);
9126 + err = au_refresh_dentry(dentry, parent);
9127 + di_read_unlock(parent, AuLock_IR);
9133 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9136 + struct dentry *d, *parent;
9138 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9139 + return simple_reval_dpath(dentry, sigen);
9141 + /* slow loop, keep it simple and stupid */
9142 + /* cf: au_cpup_dirs() */
9145 + while (au_digen_test(dentry, sigen)) {
9149 + parent = dget_parent(d);
9150 + if (!au_digen_test(parent, sigen))
9156 + di_write_lock_child2(d);
9158 + /* someone might update our dentry while we were sleeping */
9159 + if (au_digen_test(d, sigen)) {
9161 + * todo: consolidate with simple_reval_dpath(),
9162 + * do_refresh() and au_reval_for_attr().
9164 + di_read_lock_parent(parent, AuLock_IR);
9165 + err = au_refresh_dentry(d, parent);
9166 + di_read_unlock(parent, AuLock_IR);
9170 + di_write_unlock(d);
9172 + if (unlikely(err))
9180 + * if valid returns 1, otherwise 0.
9182 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9185 + unsigned int sigen;
9186 + unsigned char do_udba, dirren;
9187 + struct super_block *sb;
9188 + struct inode *inode;
9190 + /* todo: support rcu-walk? */
9191 + if (flags & LOOKUP_RCU)
9195 + if (unlikely(!au_di(dentry)))
9199 + sb = dentry->d_sb;
9202 + * i_mutex of parent dir may be held,
9203 + * but we should not return 'invalid' due to busy.
9205 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9206 + if (unlikely(err)) {
9212 + if (d_really_is_positive(dentry))
9213 + inode = d_inode(dentry);
9214 + if (unlikely(inode && au_is_bad_inode(inode))) {
9219 + if (unlikely(au_dbrange_test(dentry))) {
9225 + sigen = au_sigen(sb);
9226 + if (au_digen_test(dentry, sigen)) {
9227 + AuDebugOn(IS_ROOT(dentry));
9228 + err = au_reval_dpath(dentry, sigen);
9229 + if (unlikely(err)) {
9234 + di_downgrade_lock(dentry, AuLock_IR);
9237 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9239 + && !(inode->i_state && I_LINKABLE)
9240 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9245 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9246 + if (do_udba && inode) {
9247 + aufs_bindex_t btop = au_ibtop(inode);
9248 + struct inode *h_inode;
9251 + h_inode = au_h_iptr(inode, btop);
9252 + if (h_inode && au_test_higen(inode, h_inode)) {
9259 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9260 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9261 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9263 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9269 + di_downgrade_lock(dentry, AuLock_IR);
9271 + aufs_read_unlock(dentry, AuLock_IR);
9276 + AuDbg("%pd invalid, %d\n", dentry, valid);
9282 +static void aufs_d_release(struct dentry *dentry)
9284 + if (au_di(dentry)) {
9285 + au_di_fin(dentry);
9286 + au_hn_di_reinit(dentry);
9290 +const struct dentry_operations aufs_dop = {
9291 + .d_revalidate = aufs_d_revalidate,
9292 + .d_weak_revalidate = aufs_d_revalidate,
9293 + .d_release = aufs_d_release
9296 +/* aufs_dop without d_revalidate */
9297 +const struct dentry_operations aufs_dop_noreval = {
9298 + .d_release = aufs_d_release
9300 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9301 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9302 +++ linux/fs/aufs/dentry.h 2019-01-28 14:36:12.219084659 +0100
9304 +/* SPDX-License-Identifier: GPL-2.0 */
9306 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9308 + * This program, aufs is free software; you can redistribute it and/or modify
9309 + * it under the terms of the GNU General Public License as published by
9310 + * the Free Software Foundation; either version 2 of the License, or
9311 + * (at your option) any later version.
9313 + * This program is distributed in the hope that it will be useful,
9314 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9315 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9316 + * GNU General Public License for more details.
9318 + * You should have received a copy of the GNU General Public License
9319 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9323 + * lookup and dentry operations
9326 +#ifndef __AUFS_DENTRY_H__
9327 +#define __AUFS_DENTRY_H__
9331 +#include <linux/dcache.h>
9332 +#include "dirren.h"
9335 +struct au_hdentry {
9336 + struct dentry *hd_dentry;
9337 + aufs_bindex_t hd_id;
9341 + atomic_t di_generation;
9343 + struct au_rwsem di_rwsem;
9344 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9345 + unsigned char di_tmpfile; /* to allow the different name */
9346 + struct au_hdentry *di_hdentry;
9347 + struct rcu_head rcu;
9348 +} ____cacheline_aligned_in_smp;
9350 +/* ---------------------------------------------------------------------- */
9352 +/* flags for au_lkup_dentry() */
9353 +#define AuLkup_ALLOW_NEG 1
9354 +#define AuLkup_IGNORE_PERM (1 << 1)
9355 +#define AuLkup_DIRREN (1 << 2)
9356 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9357 +#define au_fset_lkup(flags, name) \
9358 + do { (flags) |= AuLkup_##name; } while (0)
9359 +#define au_fclr_lkup(flags, name) \
9360 + do { (flags) &= ~AuLkup_##name; } while (0)
9362 +#ifndef CONFIG_AUFS_DIRREN
9363 +#undef AuLkup_DIRREN
9364 +#define AuLkup_DIRREN 0
9367 +struct au_do_lookup_args {
9368 + unsigned int flags;
9370 + struct qstr whname, *name;
9371 + struct au_dr_lookup dirren;
9374 +/* ---------------------------------------------------------------------- */
9377 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9379 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9380 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9381 + struct dentry *h_parent, struct au_branch *br);
9383 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9384 + unsigned int flags);
9385 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9386 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9387 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9388 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9391 +void au_di_init_once(void *_di);
9392 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9393 +void au_di_free(struct au_dinfo *dinfo);
9394 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9395 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9396 +int au_di_init(struct dentry *dentry);
9397 +void au_di_fin(struct dentry *dentry);
9398 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9400 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9401 +void di_read_unlock(struct dentry *d, int flags);
9402 +void di_downgrade_lock(struct dentry *d, int flags);
9403 +void di_write_lock(struct dentry *d, unsigned int lsc);
9404 +void di_write_unlock(struct dentry *d);
9405 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9406 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9407 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9409 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9410 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9411 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9412 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9414 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9415 + struct dentry *h_dentry);
9416 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9417 +int au_dbrange_test(struct dentry *dentry);
9418 +void au_update_digen(struct dentry *dentry);
9419 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9420 +void au_update_dbtop(struct dentry *dentry);
9421 +void au_update_dbbot(struct dentry *dentry);
9422 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9424 +/* ---------------------------------------------------------------------- */
9426 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9428 + return dentry->d_fsdata;
9431 +/* ---------------------------------------------------------------------- */
9433 +/* lock subclass for dinfo */
9435 + AuLsc_DI_CHILD, /* child first */
9436 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9437 + AuLsc_DI_CHILD3, /* copyup dirs */
9441 + AuLsc_DI_TMP /* temp for replacing dinfo */
9445 + * di_read_lock_child, di_write_lock_child,
9446 + * di_read_lock_child2, di_write_lock_child2,
9447 + * di_read_lock_child3, di_write_lock_child3,
9448 + * di_read_lock_parent, di_write_lock_parent,
9449 + * di_read_lock_parent2, di_write_lock_parent2,
9450 + * di_read_lock_parent3, di_write_lock_parent3,
9452 +#define AuReadLockFunc(name, lsc) \
9453 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9454 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9456 +#define AuWriteLockFunc(name, lsc) \
9457 +static inline void di_write_lock_##name(struct dentry *d) \
9458 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9460 +#define AuRWLockFuncs(name, lsc) \
9461 + AuReadLockFunc(name, lsc) \
9462 + AuWriteLockFunc(name, lsc)
9464 +AuRWLockFuncs(child, CHILD);
9465 +AuRWLockFuncs(child2, CHILD2);
9466 +AuRWLockFuncs(child3, CHILD3);
9467 +AuRWLockFuncs(parent, PARENT);
9468 +AuRWLockFuncs(parent2, PARENT2);
9469 +AuRWLockFuncs(parent3, PARENT3);
9471 +#undef AuReadLockFunc
9472 +#undef AuWriteLockFunc
9473 +#undef AuRWLockFuncs
9475 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9476 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9477 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9479 +/* ---------------------------------------------------------------------- */
9481 +/* todo: memory barrier? */
9482 +static inline unsigned int au_digen(struct dentry *d)
9484 + return atomic_read(&au_di(d)->di_generation);
9487 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9489 + hdentry->hd_dentry = NULL;
9492 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9493 + aufs_bindex_t bindex)
9495 + return di->di_hdentry + bindex;
9498 +static inline void au_hdput(struct au_hdentry *hd)
9501 + dput(hd->hd_dentry);
9504 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9506 + DiMustAnyLock(dentry);
9507 + return au_di(dentry)->di_btop;
9510 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9512 + DiMustAnyLock(dentry);
9513 + return au_di(dentry)->di_bbot;
9516 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9518 + DiMustAnyLock(dentry);
9519 + return au_di(dentry)->di_bwh;
9522 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9524 + DiMustAnyLock(dentry);
9525 + return au_di(dentry)->di_bdiropq;
9528 +/* todo: hard/soft set? */
9529 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9531 + DiMustWriteLock(dentry);
9532 + au_di(dentry)->di_btop = bindex;
9535 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9537 + DiMustWriteLock(dentry);
9538 + au_di(dentry)->di_bbot = bindex;
9541 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9543 + DiMustWriteLock(dentry);
9544 + /* dbwh can be outside of btop - bbot range */
9545 + au_di(dentry)->di_bwh = bindex;
9548 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9550 + DiMustWriteLock(dentry);
9551 + au_di(dentry)->di_bdiropq = bindex;
9554 +/* ---------------------------------------------------------------------- */
9556 +#ifdef CONFIG_AUFS_HNOTIFY
9557 +static inline void au_digen_dec(struct dentry *d)
9559 + atomic_dec(&au_di(d)->di_generation);
9562 +static inline void au_hn_di_reinit(struct dentry *dentry)
9564 + dentry->d_fsdata = NULL;
9567 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9568 +#endif /* CONFIG_AUFS_HNOTIFY */
9570 +#endif /* __KERNEL__ */
9571 +#endif /* __AUFS_DENTRY_H__ */
9572 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9573 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9574 +++ linux/fs/aufs/dinfo.c 2019-01-28 14:36:12.219084659 +0100
9576 +// SPDX-License-Identifier: GPL-2.0
9578 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9580 + * This program, aufs is free software; you can redistribute it and/or modify
9581 + * it under the terms of the GNU General Public License as published by
9582 + * the Free Software Foundation; either version 2 of the License, or
9583 + * (at your option) any later version.
9585 + * This program is distributed in the hope that it will be useful,
9586 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9587 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9588 + * GNU General Public License for more details.
9590 + * You should have received a copy of the GNU General Public License
9591 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9595 + * dentry private data
9600 +void au_di_init_once(void *_dinfo)
9602 + struct au_dinfo *dinfo = _dinfo;
9604 + au_rw_init(&dinfo->di_rwsem);
9607 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9609 + struct au_dinfo *dinfo;
9612 + dinfo = au_cache_alloc_dinfo();
9613 + if (unlikely(!dinfo))
9616 + nbr = au_sbbot(sb) + 1;
9619 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9620 + if (dinfo->di_hdentry) {
9621 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9622 + dinfo->di_btop = -1;
9623 + dinfo->di_bbot = -1;
9624 + dinfo->di_bwh = -1;
9625 + dinfo->di_bdiropq = -1;
9626 + dinfo->di_tmpfile = 0;
9627 + for (i = 0; i < nbr; i++)
9628 + dinfo->di_hdentry[i].hd_id = -1;
9632 + au_cache_free_dinfo(dinfo);
9639 +void au_di_free(struct au_dinfo *dinfo)
9641 + struct au_hdentry *p;
9642 + aufs_bindex_t bbot, bindex;
9644 + /* dentry may not be revalidated */
9645 + bindex = dinfo->di_btop;
9646 + if (bindex >= 0) {
9647 + bbot = dinfo->di_bbot;
9648 + p = au_hdentry(dinfo, bindex);
9649 + while (bindex++ <= bbot)
9652 + au_kfree_try_rcu(dinfo->di_hdentry);
9653 + au_cache_free_dinfo(dinfo);
9656 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9658 + struct au_hdentry *p;
9661 + AuRwMustWriteLock(&a->di_rwsem);
9662 + AuRwMustWriteLock(&b->di_rwsem);
9664 +#define DiSwap(v, name) \
9666 + v = a->di_##name; \
9667 + a->di_##name = b->di_##name; \
9668 + b->di_##name = v; \
9671 + DiSwap(p, hdentry);
9675 + DiSwap(bi, bdiropq);
9681 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9683 + AuRwMustWriteLock(&dst->di_rwsem);
9684 + AuRwMustWriteLock(&src->di_rwsem);
9686 + dst->di_btop = src->di_btop;
9687 + dst->di_bbot = src->di_bbot;
9688 + dst->di_bwh = src->di_bwh;
9689 + dst->di_bdiropq = src->di_bdiropq;
9693 +int au_di_init(struct dentry *dentry)
9696 + struct super_block *sb;
9697 + struct au_dinfo *dinfo;
9700 + sb = dentry->d_sb;
9701 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9703 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9704 + /* smp_mb(); */ /* atomic_set */
9705 + dentry->d_fsdata = dinfo;
9712 +void au_di_fin(struct dentry *dentry)
9714 + struct au_dinfo *dinfo;
9716 + dinfo = au_di(dentry);
9717 + AuRwDestroy(&dinfo->di_rwsem);
9718 + au_di_free(dinfo);
9721 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9724 + struct au_hdentry *hdp;
9726 + AuRwMustWriteLock(&dinfo->di_rwsem);
9729 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9731 + sz = sizeof(*hdp);
9732 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9735 + dinfo->di_hdentry = hdp;
9742 +/* ---------------------------------------------------------------------- */
9744 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9747 + case AuLsc_DI_CHILD:
9748 + ii_write_lock_child(inode);
9750 + case AuLsc_DI_CHILD2:
9751 + ii_write_lock_child2(inode);
9753 + case AuLsc_DI_CHILD3:
9754 + ii_write_lock_child3(inode);
9756 + case AuLsc_DI_PARENT:
9757 + ii_write_lock_parent(inode);
9759 + case AuLsc_DI_PARENT2:
9760 + ii_write_lock_parent2(inode);
9762 + case AuLsc_DI_PARENT3:
9763 + ii_write_lock_parent3(inode);
9770 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9773 + case AuLsc_DI_CHILD:
9774 + ii_read_lock_child(inode);
9776 + case AuLsc_DI_CHILD2:
9777 + ii_read_lock_child2(inode);
9779 + case AuLsc_DI_CHILD3:
9780 + ii_read_lock_child3(inode);
9782 + case AuLsc_DI_PARENT:
9783 + ii_read_lock_parent(inode);
9785 + case AuLsc_DI_PARENT2:
9786 + ii_read_lock_parent2(inode);
9788 + case AuLsc_DI_PARENT3:
9789 + ii_read_lock_parent3(inode);
9796 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9798 + struct inode *inode;
9800 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9801 + if (d_really_is_positive(d)) {
9802 + inode = d_inode(d);
9803 + if (au_ftest_lock(flags, IW))
9804 + do_ii_write_lock(inode, lsc);
9805 + else if (au_ftest_lock(flags, IR))
9806 + do_ii_read_lock(inode, lsc);
9810 +void di_read_unlock(struct dentry *d, int flags)
9812 + struct inode *inode;
9814 + if (d_really_is_positive(d)) {
9815 + inode = d_inode(d);
9816 + if (au_ftest_lock(flags, IW)) {
9817 + au_dbg_verify_dinode(d);
9818 + ii_write_unlock(inode);
9819 + } else if (au_ftest_lock(flags, IR)) {
9820 + au_dbg_verify_dinode(d);
9821 + ii_read_unlock(inode);
9824 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9827 +void di_downgrade_lock(struct dentry *d, int flags)
9829 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9830 + ii_downgrade_lock(d_inode(d));
9831 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9834 +void di_write_lock(struct dentry *d, unsigned int lsc)
9836 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9837 + if (d_really_is_positive(d))
9838 + do_ii_write_lock(d_inode(d), lsc);
9841 +void di_write_unlock(struct dentry *d)
9843 + au_dbg_verify_dinode(d);
9844 + if (d_really_is_positive(d))
9845 + ii_write_unlock(d_inode(d));
9846 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9849 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9851 + AuDebugOn(d1 == d2
9852 + || d_inode(d1) == d_inode(d2)
9853 + || d1->d_sb != d2->d_sb);
9855 + if ((isdir && au_test_subdir(d1, d2))
9857 + di_write_lock_child(d1);
9858 + di_write_lock_child2(d2);
9860 + di_write_lock_child(d2);
9861 + di_write_lock_child2(d1);
9865 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9867 + AuDebugOn(d1 == d2
9868 + || d_inode(d1) == d_inode(d2)
9869 + || d1->d_sb != d2->d_sb);
9871 + if ((isdir && au_test_subdir(d1, d2))
9873 + di_write_lock_parent(d1);
9874 + di_write_lock_parent2(d2);
9876 + di_write_lock_parent(d2);
9877 + di_write_lock_parent2(d1);
9881 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9883 + di_write_unlock(d1);
9884 + if (d_inode(d1) == d_inode(d2))
9885 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9887 + di_write_unlock(d2);
9890 +/* ---------------------------------------------------------------------- */
9892 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9896 + DiMustAnyLock(dentry);
9898 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9900 + AuDebugOn(bindex < 0);
9901 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9902 + AuDebugOn(d && au_dcount(d) <= 0);
9907 + * extended version of au_h_dptr().
9908 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9911 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9913 + struct dentry *h_dentry;
9914 + struct inode *inode, *h_inode;
9916 + AuDebugOn(d_really_is_negative(dentry));
9919 + if (au_dbtop(dentry) <= bindex
9920 + && bindex <= au_dbbot(dentry))
9921 + h_dentry = au_h_dptr(dentry, bindex);
9922 + if (h_dentry && !au_d_linkable(h_dentry)) {
9924 + goto out; /* success */
9927 + inode = d_inode(dentry);
9928 + AuDebugOn(bindex < au_ibtop(inode));
9929 + AuDebugOn(au_ibbot(inode) < bindex);
9930 + h_inode = au_h_iptr(inode, bindex);
9931 + h_dentry = d_find_alias(h_inode);
9933 + if (!IS_ERR(h_dentry)) {
9934 + if (!au_d_linkable(h_dentry))
9935 + goto out; /* success */
9941 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9942 + h_dentry = au_plink_lkup(inode, bindex);
9943 + AuDebugOn(!h_dentry);
9944 + if (!IS_ERR(h_dentry)) {
9945 + if (!au_d_hashed_positive(h_dentry))
9946 + goto out; /* success */
9953 + AuDbgDentry(h_dentry);
9957 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9959 + aufs_bindex_t bbot, bwh;
9961 + bbot = au_dbbot(dentry);
9963 + bwh = au_dbwh(dentry);
9966 + if (0 < bwh && bwh < bbot)
9972 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9974 + aufs_bindex_t bbot, bopq;
9976 + bbot = au_dbtail(dentry);
9978 + bopq = au_dbdiropq(dentry);
9979 + if (0 <= bopq && bopq < bbot)
9985 +/* ---------------------------------------------------------------------- */
9987 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9988 + struct dentry *h_dentry)
9990 + struct au_dinfo *dinfo;
9991 + struct au_hdentry *hd;
9992 + struct au_branch *br;
9994 + DiMustWriteLock(dentry);
9996 + dinfo = au_di(dentry);
9997 + hd = au_hdentry(dinfo, bindex);
9999 + hd->hd_dentry = h_dentry;
10001 + br = au_sbr(dentry->d_sb, bindex);
10002 + hd->hd_id = br->br_id;
10006 +int au_dbrange_test(struct dentry *dentry)
10009 + aufs_bindex_t btop, bbot;
10012 + btop = au_dbtop(dentry);
10013 + bbot = au_dbbot(dentry);
10015 + AuDebugOn(bbot < 0 && btop > bbot);
10018 + AuDebugOn(bbot >= 0);
10024 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10029 + if (unlikely(au_digen(dentry) != sigen
10030 + || au_iigen_test(d_inode(dentry), sigen)))
10036 +void au_update_digen(struct dentry *dentry)
10038 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10039 + /* smp_mb(); */ /* atomic_set */
10042 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10044 + struct au_dinfo *dinfo;
10045 + struct dentry *h_d;
10046 + struct au_hdentry *hdp;
10047 + aufs_bindex_t bindex, bbot;
10049 + DiMustWriteLock(dentry);
10051 + dinfo = au_di(dentry);
10052 + if (!dinfo || dinfo->di_btop < 0)
10055 + if (do_put_zero) {
10056 + bbot = dinfo->di_bbot;
10057 + bindex = dinfo->di_btop;
10058 + hdp = au_hdentry(dinfo, bindex);
10059 + for (; bindex <= bbot; bindex++, hdp++) {
10060 + h_d = hdp->hd_dentry;
10061 + if (h_d && d_is_negative(h_d))
10062 + au_set_h_dptr(dentry, bindex, NULL);
10066 + dinfo->di_btop = 0;
10067 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10068 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10069 + if (hdp->hd_dentry)
10071 + if (dinfo->di_btop > dinfo->di_bbot) {
10072 + dinfo->di_btop = -1;
10073 + dinfo->di_bbot = -1;
10077 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10078 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10079 + if (hdp->hd_dentry)
10081 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10084 +void au_update_dbtop(struct dentry *dentry)
10086 + aufs_bindex_t bindex, bbot;
10087 + struct dentry *h_dentry;
10089 + bbot = au_dbbot(dentry);
10090 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10091 + h_dentry = au_h_dptr(dentry, bindex);
10094 + if (d_is_positive(h_dentry)) {
10095 + au_set_dbtop(dentry, bindex);
10098 + au_set_h_dptr(dentry, bindex, NULL);
10102 +void au_update_dbbot(struct dentry *dentry)
10104 + aufs_bindex_t bindex, btop;
10105 + struct dentry *h_dentry;
10107 + btop = au_dbtop(dentry);
10108 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10109 + h_dentry = au_h_dptr(dentry, bindex);
10112 + if (d_is_positive(h_dentry)) {
10113 + au_set_dbbot(dentry, bindex);
10116 + au_set_h_dptr(dentry, bindex, NULL);
10120 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10122 + aufs_bindex_t bindex, bbot;
10124 + bbot = au_dbbot(dentry);
10125 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10126 + if (au_h_dptr(dentry, bindex) == h_dentry)
10130 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10131 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10132 +++ linux/fs/aufs/dir.c 2019-01-28 14:36:12.219084659 +0100
10134 +// SPDX-License-Identifier: GPL-2.0
10136 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10138 + * This program, aufs is free software; you can redistribute it and/or modify
10139 + * it under the terms of the GNU General Public License as published by
10140 + * the Free Software Foundation; either version 2 of the License, or
10141 + * (at your option) any later version.
10143 + * This program is distributed in the hope that it will be useful,
10144 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10145 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10146 + * GNU General Public License for more details.
10148 + * You should have received a copy of the GNU General Public License
10149 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10153 + * directory operations
10156 +#include <linux/fs_stack.h>
10159 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10161 + unsigned int nlink;
10163 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10165 + nlink = dir->i_nlink;
10166 + nlink += h_dir->i_nlink - 2;
10167 + if (h_dir->i_nlink < 2)
10169 + smp_mb(); /* for i_nlink */
10170 + /* 0 can happen in revaliding */
10171 + set_nlink(dir, nlink);
10174 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10176 + unsigned int nlink;
10178 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10180 + nlink = dir->i_nlink;
10181 + nlink -= h_dir->i_nlink - 2;
10182 + if (h_dir->i_nlink < 2)
10184 + smp_mb(); /* for i_nlink */
10185 + /* nlink == 0 means the branch-fs is broken */
10186 + set_nlink(dir, nlink);
10189 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10192 + aufs_bindex_t bindex, bbot;
10193 + struct file *h_file;
10194 + struct dentry *h_dentry;
10198 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10200 + bbot = au_fbbot_dir(file);
10201 + for (bindex = au_fbtop(file);
10202 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10204 + h_file = au_hf_dir(file, bindex);
10205 + if (h_file && file_inode(h_file))
10206 + sz += vfsub_f_size_read(h_file);
10209 + AuDebugOn(!dentry);
10210 + AuDebugOn(!d_is_dir(dentry));
10212 + bbot = au_dbtaildir(dentry);
10213 + for (bindex = au_dbtop(dentry);
10214 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10216 + h_dentry = au_h_dptr(dentry, bindex);
10217 + if (h_dentry && d_is_positive(h_dentry))
10218 + sz += i_size_read(d_inode(h_dentry));
10221 + if (sz < KMALLOC_MAX_SIZE)
10222 + sz = roundup_pow_of_two(sz);
10223 + if (sz > KMALLOC_MAX_SIZE)
10224 + sz = KMALLOC_MAX_SIZE;
10225 + else if (sz < NAME_MAX) {
10226 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10227 + sz = AUFS_RDBLK_DEF;
10232 +struct au_dir_ts_arg {
10233 + struct dentry *dentry;
10234 + aufs_bindex_t brid;
10237 +static void au_do_dir_ts(void *arg)
10239 + struct au_dir_ts_arg *a = arg;
10240 + struct au_dtime dt;
10241 + struct path h_path;
10242 + struct inode *dir, *h_dir;
10243 + struct super_block *sb;
10244 + struct au_branch *br;
10245 + struct au_hinode *hdir;
10247 + aufs_bindex_t btop, bindex;
10249 + sb = a->dentry->d_sb;
10250 + if (d_really_is_negative(a->dentry))
10252 + /* no dir->i_mutex lock */
10253 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10255 + dir = d_inode(a->dentry);
10256 + btop = au_ibtop(dir);
10257 + bindex = au_br_index(sb, a->brid);
10258 + if (bindex < btop)
10261 + br = au_sbr(sb, bindex);
10262 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10263 + if (!h_path.dentry)
10265 + h_path.mnt = au_br_mnt(br);
10266 + au_dtime_store(&dt, a->dentry, &h_path);
10268 + br = au_sbr(sb, btop);
10269 + if (!au_br_writable(br->br_perm))
10271 + h_path.dentry = au_h_dptr(a->dentry, btop);
10272 + h_path.mnt = au_br_mnt(br);
10273 + err = vfsub_mnt_want_write(h_path.mnt);
10276 + hdir = au_hi(dir, btop);
10277 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10278 + h_dir = au_h_iptr(dir, btop);
10279 + if (h_dir->i_nlink
10280 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10281 + dt.dt_h_path = h_path;
10282 + au_dtime_revert(&dt);
10284 + au_hn_inode_unlock(hdir);
10285 + vfsub_mnt_drop_write(h_path.mnt);
10286 + au_cpup_attr_timesizes(dir);
10289 + aufs_read_unlock(a->dentry, AuLock_DW);
10292 + au_nwt_done(&au_sbi(sb)->si_nowait);
10293 + au_kfree_try_rcu(arg);
10296 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10298 + int perm, wkq_err;
10299 + aufs_bindex_t btop;
10300 + struct au_dir_ts_arg *arg;
10301 + struct dentry *dentry;
10302 + struct super_block *sb;
10306 + dentry = d_find_any_alias(dir);
10307 + AuDebugOn(!dentry);
10308 + sb = dentry->d_sb;
10309 + btop = au_ibtop(dir);
10310 + if (btop == bindex) {
10311 + au_cpup_attr_timesizes(dir);
10315 + perm = au_sbr_perm(sb, btop);
10316 + if (!au_br_writable(perm))
10319 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10323 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10324 + arg->brid = au_sbr_id(sb, bindex);
10325 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10326 + if (unlikely(wkq_err)) {
10327 + pr_err("wkq %d\n", wkq_err);
10329 + au_kfree_try_rcu(arg);
10336 +/* ---------------------------------------------------------------------- */
10338 +static int reopen_dir(struct file *file)
10341 + unsigned int flags;
10342 + aufs_bindex_t bindex, btail, btop;
10343 + struct dentry *dentry, *h_dentry;
10344 + struct file *h_file;
10346 + /* open all lower dirs */
10347 + dentry = file->f_path.dentry;
10348 + btop = au_dbtop(dentry);
10349 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10350 + au_set_h_fptr(file, bindex, NULL);
10351 + au_set_fbtop(file, btop);
10353 + btail = au_dbtaildir(dentry);
10354 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10355 + au_set_h_fptr(file, bindex, NULL);
10356 + au_set_fbbot_dir(file, btail);
10358 + flags = vfsub_file_flags(file);
10359 + for (bindex = btop; bindex <= btail; bindex++) {
10360 + h_dentry = au_h_dptr(dentry, bindex);
10363 + h_file = au_hf_dir(file, bindex);
10367 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10368 + err = PTR_ERR(h_file);
10369 + if (IS_ERR(h_file))
10370 + goto out; /* close all? */
10371 + au_set_h_fptr(file, bindex, h_file);
10373 + au_update_figen(file);
10374 + /* todo: necessary? */
10375 + /* file->f_ra = h_file->f_ra; */
10382 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10385 + aufs_bindex_t bindex, btail;
10386 + struct dentry *dentry, *h_dentry;
10387 + struct vfsmount *mnt;
10389 + FiMustWriteLock(file);
10390 + AuDebugOn(h_file);
10393 + mnt = file->f_path.mnt;
10394 + dentry = file->f_path.dentry;
10395 + file->f_version = inode_query_iversion(d_inode(dentry));
10396 + bindex = au_dbtop(dentry);
10397 + au_set_fbtop(file, bindex);
10398 + btail = au_dbtaildir(dentry);
10399 + au_set_fbbot_dir(file, btail);
10400 + for (; !err && bindex <= btail; bindex++) {
10401 + h_dentry = au_h_dptr(dentry, bindex);
10405 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10406 + if (unlikely(err))
10408 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10409 + if (IS_ERR(h_file)) {
10410 + err = PTR_ERR(h_file);
10413 + au_set_h_fptr(file, bindex, h_file);
10415 + au_update_figen(file);
10416 + /* todo: necessary? */
10417 + /* file->f_ra = h_file->f_ra; */
10419 + return 0; /* success */
10422 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10423 + au_set_h_fptr(file, bindex, NULL);
10424 + au_set_fbtop(file, -1);
10425 + au_set_fbbot_dir(file, -1);
10430 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10431 + struct file *file)
10434 + struct super_block *sb;
10435 + struct au_fidir *fidir;
10438 + sb = file->f_path.dentry->d_sb;
10439 + si_read_lock(sb, AuLock_FLUSH);
10440 + fidir = au_fidir_alloc(sb);
10442 + struct au_do_open_args args = {
10443 + .open = do_open_dir,
10446 + err = au_do_open(file, &args);
10447 + if (unlikely(err))
10448 + au_kfree_rcu(fidir);
10450 + si_read_unlock(sb);
10454 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10455 + struct file *file)
10457 + struct au_vdir *vdir_cache;
10458 + struct au_finfo *finfo;
10459 + struct au_fidir *fidir;
10460 + struct au_hfile *hf;
10461 + aufs_bindex_t bindex, bbot;
10463 + finfo = au_fi(file);
10464 + fidir = finfo->fi_hdir;
10466 + au_hbl_del(&finfo->fi_hlist,
10467 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10468 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10470 + au_vdir_free(vdir_cache);
10472 + bindex = finfo->fi_btop;
10473 + if (bindex >= 0) {
10474 + hf = fidir->fd_hfile + bindex;
10476 + * calls fput() instead of filp_close(),
10477 + * since no dnotify or lock for the lower file.
10479 + bbot = fidir->fd_bbot;
10480 + for (; bindex <= bbot; bindex++, hf++)
10482 + au_hfput(hf, /*execed*/0);
10484 + au_kfree_rcu(fidir);
10485 + finfo->fi_hdir = NULL;
10487 + au_finfo_fin(file);
10491 +/* ---------------------------------------------------------------------- */
10493 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10496 + aufs_bindex_t bindex, bbot;
10497 + struct file *h_file;
10500 + bbot = au_fbbot_dir(file);
10501 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10502 + h_file = au_hf_dir(file, bindex);
10504 + err = vfsub_flush(h_file, id);
10509 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10511 + return au_do_flush(file, id, au_do_flush_dir);
10514 +/* ---------------------------------------------------------------------- */
10516 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10519 + aufs_bindex_t bbot, bindex;
10520 + struct inode *inode;
10521 + struct super_block *sb;
10524 + sb = dentry->d_sb;
10525 + inode = d_inode(dentry);
10526 + IMustLock(inode);
10527 + bbot = au_dbbot(dentry);
10528 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10529 + struct path h_path;
10531 + if (au_test_ro(sb, bindex, inode))
10533 + h_path.dentry = au_h_dptr(dentry, bindex);
10534 + if (!h_path.dentry)
10537 + h_path.mnt = au_sbr_mnt(sb, bindex);
10538 + err = vfsub_fsync(NULL, &h_path, datasync);
10544 +static int au_do_fsync_dir(struct file *file, int datasync)
10547 + aufs_bindex_t bbot, bindex;
10548 + struct file *h_file;
10549 + struct super_block *sb;
10550 + struct inode *inode;
10552 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10553 + if (unlikely(err))
10556 + inode = file_inode(file);
10557 + sb = inode->i_sb;
10558 + bbot = au_fbbot_dir(file);
10559 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10560 + h_file = au_hf_dir(file, bindex);
10561 + if (!h_file || au_test_ro(sb, bindex, inode))
10564 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10572 + * @file may be NULL
10574 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10578 + struct dentry *dentry;
10579 + struct inode *inode;
10580 + struct super_block *sb;
10583 + dentry = file->f_path.dentry;
10584 + inode = d_inode(dentry);
10585 + inode_lock(inode);
10586 + sb = dentry->d_sb;
10587 + si_noflush_read_lock(sb);
10589 + err = au_do_fsync_dir(file, datasync);
10591 + di_write_lock_child(dentry);
10592 + err = au_do_fsync_dir_no_file(dentry, datasync);
10594 + au_cpup_attr_timesizes(inode);
10595 + di_write_unlock(dentry);
10597 + fi_write_unlock(file);
10599 + si_read_unlock(sb);
10600 + inode_unlock(inode);
10604 +/* ---------------------------------------------------------------------- */
10606 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10609 + struct dentry *dentry;
10610 + struct inode *inode, *h_inode;
10611 + struct super_block *sb;
10613 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10615 + dentry = file->f_path.dentry;
10616 + inode = d_inode(dentry);
10617 + IMustLock(inode);
10619 + sb = dentry->d_sb;
10620 + si_read_lock(sb, AuLock_FLUSH);
10621 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10622 + if (unlikely(err))
10624 + err = au_alive_dir(dentry);
10626 + err = au_vdir_init(file);
10627 + di_downgrade_lock(dentry, AuLock_IR);
10628 + if (unlikely(err))
10631 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10632 + if (!au_test_nfsd()) {
10633 + err = au_vdir_fill_de(file, ctx);
10634 + fsstack_copy_attr_atime(inode, h_inode);
10637 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10638 + * encode_fh() and others.
10640 + atomic_inc(&h_inode->i_count);
10641 + di_read_unlock(dentry, AuLock_IR);
10642 + si_read_unlock(sb);
10643 + err = au_vdir_fill_de(file, ctx);
10644 + fsstack_copy_attr_atime(inode, h_inode);
10645 + fi_write_unlock(file);
10653 + di_read_unlock(dentry, AuLock_IR);
10654 + fi_write_unlock(file);
10656 + si_read_unlock(sb);
10660 +/* ---------------------------------------------------------------------- */
10662 +#define AuTestEmpty_WHONLY 1
10663 +#define AuTestEmpty_CALLED (1 << 1)
10664 +#define AuTestEmpty_SHWH (1 << 2)
10665 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10666 +#define au_fset_testempty(flags, name) \
10667 + do { (flags) |= AuTestEmpty_##name; } while (0)
10668 +#define au_fclr_testempty(flags, name) \
10669 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10671 +#ifndef CONFIG_AUFS_SHWH
10672 +#undef AuTestEmpty_SHWH
10673 +#define AuTestEmpty_SHWH 0
10676 +struct test_empty_arg {
10677 + struct dir_context ctx;
10678 + struct au_nhash *whlist;
10679 + unsigned int flags;
10681 + aufs_bindex_t bindex;
10684 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10685 + int namelen, loff_t offset __maybe_unused, u64 ino,
10686 + unsigned int d_type)
10688 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10690 + char *name = (void *)__name;
10693 + au_fset_testempty(arg->flags, CALLED);
10695 + if (name[0] == '.'
10696 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10697 + goto out; /* success */
10699 + if (namelen <= AUFS_WH_PFX_LEN
10700 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10701 + if (au_ftest_testempty(arg->flags, WHONLY)
10702 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10703 + arg->err = -ENOTEMPTY;
10707 + name += AUFS_WH_PFX_LEN;
10708 + namelen -= AUFS_WH_PFX_LEN;
10709 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10710 + arg->err = au_nhash_append_wh
10711 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10712 + au_ftest_testempty(arg->flags, SHWH));
10716 + AuTraceErr(arg->err);
10720 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10723 + struct file *h_file;
10724 + struct au_branch *br;
10726 + h_file = au_h_open(dentry, arg->bindex,
10727 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10728 + /*file*/NULL, /*force_wr*/0);
10729 + err = PTR_ERR(h_file);
10730 + if (IS_ERR(h_file))
10734 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10735 + && !file_inode(h_file)->i_nlink)
10740 + au_fclr_testempty(arg->flags, CALLED);
10742 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10745 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10749 + br = au_sbr(dentry->d_sb, arg->bindex);
10750 + au_lcnt_dec(&br->br_nfiles);
10755 +struct do_test_empty_args {
10757 + struct dentry *dentry;
10758 + struct test_empty_arg *arg;
10761 +static void call_do_test_empty(void *args)
10763 + struct do_test_empty_args *a = args;
10764 + *a->errp = do_test_empty(a->dentry, a->arg);
10767 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10769 + int err, wkq_err;
10770 + struct dentry *h_dentry;
10771 + struct inode *h_inode;
10773 + h_dentry = au_h_dptr(dentry, arg->bindex);
10774 + h_inode = d_inode(h_dentry);
10775 + /* todo: i_mode changes anytime? */
10776 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10777 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10778 + inode_unlock_shared(h_inode);
10780 + err = do_test_empty(dentry, arg);
10782 + struct do_test_empty_args args = {
10784 + .dentry = dentry,
10787 + unsigned int flags = arg->flags;
10789 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10790 + if (unlikely(wkq_err))
10792 + arg->flags = flags;
10798 +int au_test_empty_lower(struct dentry *dentry)
10801 + unsigned int rdhash;
10802 + aufs_bindex_t bindex, btop, btail;
10803 + struct au_nhash whlist;
10804 + struct test_empty_arg arg = {
10806 + .actor = test_empty_cb
10809 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10811 + SiMustAnyLock(dentry->d_sb);
10813 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10815 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10816 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10817 + if (unlikely(err))
10821 + arg.whlist = &whlist;
10822 + btop = au_dbtop(dentry);
10823 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10824 + au_fset_testempty(arg.flags, SHWH);
10825 + test_empty = do_test_empty;
10826 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10827 + test_empty = sio_test_empty;
10828 + arg.bindex = btop;
10829 + err = test_empty(dentry, &arg);
10830 + if (unlikely(err))
10833 + au_fset_testempty(arg.flags, WHONLY);
10834 + btail = au_dbtaildir(dentry);
10835 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10836 + struct dentry *h_dentry;
10838 + h_dentry = au_h_dptr(dentry, bindex);
10839 + if (h_dentry && d_is_positive(h_dentry)) {
10840 + arg.bindex = bindex;
10841 + err = test_empty(dentry, &arg);
10846 + au_nhash_wh_free(&whlist);
10851 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10854 + struct test_empty_arg arg = {
10856 + .actor = test_empty_cb
10859 + aufs_bindex_t bindex, btail;
10862 + arg.whlist = whlist;
10863 + arg.flags = AuTestEmpty_WHONLY;
10864 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10865 + au_fset_testempty(arg.flags, SHWH);
10866 + btail = au_dbtaildir(dentry);
10867 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10868 + struct dentry *h_dentry;
10870 + h_dentry = au_h_dptr(dentry, bindex);
10871 + if (h_dentry && d_is_positive(h_dentry)) {
10872 + arg.bindex = bindex;
10873 + err = sio_test_empty(dentry, &arg);
10880 +/* ---------------------------------------------------------------------- */
10882 +const struct file_operations aufs_dir_fop = {
10883 + .owner = THIS_MODULE,
10884 + .llseek = default_llseek,
10885 + .read = generic_read_dir,
10886 + .iterate_shared = aufs_iterate_shared,
10887 + .unlocked_ioctl = aufs_ioctl_dir,
10888 +#ifdef CONFIG_COMPAT
10889 + .compat_ioctl = aufs_compat_ioctl_dir,
10891 + .open = aufs_open_dir,
10892 + .release = aufs_release_dir,
10893 + .flush = aufs_flush_dir,
10894 + .fsync = aufs_fsync_dir
10896 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10897 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10898 +++ linux/fs/aufs/dir.h 2019-01-28 14:36:12.219084659 +0100
10900 +/* SPDX-License-Identifier: GPL-2.0 */
10902 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10904 + * This program, aufs is free software; you can redistribute it and/or modify
10905 + * it under the terms of the GNU General Public License as published by
10906 + * the Free Software Foundation; either version 2 of the License, or
10907 + * (at your option) any later version.
10909 + * This program is distributed in the hope that it will be useful,
10910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10912 + * GNU General Public License for more details.
10914 + * You should have received a copy of the GNU General Public License
10915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10919 + * directory operations
10922 +#ifndef __AUFS_DIR_H__
10923 +#define __AUFS_DIR_H__
10927 +#include <linux/fs.h>
10929 +/* ---------------------------------------------------------------------- */
10931 +/* need to be faster and smaller */
10934 + unsigned int nh_num;
10935 + struct hlist_head *nh_head;
10938 +struct au_vdir_destr {
10939 + unsigned char len;
10940 + unsigned char name[0];
10943 +struct au_vdir_dehstr {
10944 + struct hlist_node hash;
10945 + struct au_vdir_destr *str;
10946 + struct rcu_head rcu;
10947 +} ____cacheline_aligned_in_smp;
10949 +struct au_vdir_de {
10951 + unsigned char de_type;
10952 + /* caution: packed */
10953 + struct au_vdir_destr de_str;
10956 +struct au_vdir_wh {
10957 + struct hlist_node wh_hash;
10958 +#ifdef CONFIG_AUFS_SHWH
10960 + aufs_bindex_t wh_bindex;
10961 + unsigned char wh_type;
10963 + aufs_bindex_t wh_bindex;
10965 + /* caution: packed */
10966 + struct au_vdir_destr wh_str;
10969 +union au_vdir_deblk_p {
10970 + unsigned char *deblk;
10971 + struct au_vdir_de *de;
10975 + unsigned char **vd_deblk;
10976 + unsigned long vd_nblk;
10978 + unsigned long ul;
10979 + union au_vdir_deblk_p p;
10983 + unsigned int vd_deblk_sz;
10984 + unsigned long vd_jiffy;
10985 + struct rcu_head rcu;
10986 +} ____cacheline_aligned_in_smp;
10988 +/* ---------------------------------------------------------------------- */
10991 +extern const struct file_operations aufs_dir_fop;
10992 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10993 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10994 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10995 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10996 +int au_test_empty_lower(struct dentry *dentry);
10997 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
11000 +unsigned int au_rdhash_est(loff_t sz);
11001 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
11002 +void au_nhash_wh_free(struct au_nhash *whlist);
11003 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
11005 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
11006 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
11007 + unsigned int d_type, aufs_bindex_t bindex,
11008 + unsigned char shwh);
11009 +void au_vdir_free(struct au_vdir *vdir);
11010 +int au_vdir_init(struct file *file);
11011 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
11014 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
11016 +#ifdef CONFIG_AUFS_RDU
11018 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
11019 +#ifdef CONFIG_COMPAT
11020 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
11021 + unsigned long arg);
11024 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11025 + unsigned int cmd, unsigned long arg)
11026 +#ifdef CONFIG_COMPAT
11027 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11028 + unsigned int cmd, unsigned long arg)
11032 +#endif /* __KERNEL__ */
11033 +#endif /* __AUFS_DIR_H__ */
11034 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11035 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11036 +++ linux/fs/aufs/dirren.c 2019-01-28 14:36:12.219084659 +0100
11038 +// SPDX-License-Identifier: GPL-2.0
11040 + * Copyright (C) 2017-2018 Junjiro R. Okajima
11042 + * This program, aufs is free software; you can redistribute it and/or modify
11043 + * it under the terms of the GNU General Public License as published by
11044 + * the Free Software Foundation; either version 2 of the License, or
11045 + * (at your option) any later version.
11047 + * This program is distributed in the hope that it will be useful,
11048 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11049 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11050 + * GNU General Public License for more details.
11052 + * You should have received a copy of the GNU General Public License
11053 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11057 + * special handling in renaming a directory
11058 + * in order to support looking-up the before-renamed name on the lower readonly
11062 +#include <linux/byteorder/generic.h>
11065 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11069 + idx = au_dr_ihash(ent->dr_h_ino);
11070 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11073 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11076 + struct hlist_bl_head *hbl;
11079 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11080 + hbl = dr->dr_h_ino + i;
11081 + hlist_bl_lock(hbl);
11082 + ret &= hlist_bl_empty(hbl);
11083 + hlist_bl_unlock(hbl);
11089 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11091 + struct au_dr_hino *found, *ent;
11092 + struct hlist_bl_head *hbl;
11093 + struct hlist_bl_node *pos;
11097 + idx = au_dr_ihash(ino);
11098 + hbl = dr->dr_h_ino + idx;
11099 + hlist_bl_lock(hbl);
11100 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11101 + if (ent->dr_h_ino == ino) {
11105 + hlist_bl_unlock(hbl);
11110 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11111 + struct au_dr_hino *add_ent)
11114 + struct hlist_bl_head *hbl;
11115 + struct hlist_bl_node *pos;
11116 + struct au_dr_hino *ent;
11119 + idx = au_dr_ihash(ino);
11120 + hbl = dr->dr_h_ino + idx;
11123 + struct hlist_bl_node *tmp;
11125 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11126 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11129 + hlist_bl_lock(hbl);
11130 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11131 + if (ent->dr_h_ino == ino) {
11135 + if (!found && add_ent)
11136 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11137 + hlist_bl_unlock(hbl);
11139 + if (!found && add_ent)
11140 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11145 +void au_dr_hino_free(struct au_dr_br *dr)
11148 + struct hlist_bl_head *hbl;
11149 + struct hlist_bl_node *pos, *tmp;
11150 + struct au_dr_hino *ent;
11152 + /* SiMustWriteLock(sb); */
11154 + for (i = 0; i < AuDirren_NHASH; i++) {
11155 + hbl = dr->dr_h_ino + i;
11156 + /* no spinlock since sbinfo must be write-locked */
11157 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11158 + au_kfree_rcu(ent);
11159 + INIT_HLIST_BL_HEAD(hbl);
11163 +/* returns the number of inodes or an error */
11164 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11165 + struct file *hinofile)
11169 + loff_t pos, oldsize;
11171 + struct inode *hinoinode;
11172 + struct hlist_bl_head *hbl;
11173 + struct hlist_bl_node *n1, *n2;
11174 + struct au_dr_hino *ent;
11176 + SiMustWriteLock(sb);
11177 + AuDebugOn(!au_br_writable(br->br_perm));
11179 + hinoinode = file_inode(hinofile);
11180 + oldsize = i_size_read(hinoinode);
11184 + hbl = br->br_dirren.dr_h_ino;
11185 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11186 + /* no bit-lock since sbinfo must be write-locked */
11187 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11188 + AuDbg("hi%llu, %pD2\n",
11189 + (unsigned long long)ent->dr_h_ino, hinofile);
11190 + u64 = cpu_to_be64(ent->dr_h_ino);
11191 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11192 + if (ssz == sizeof(u64))
11195 + /* write error */
11196 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11203 + /* regardless the error */
11204 + if (pos < oldsize) {
11205 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11213 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11220 + struct au_dr_hino *ent;
11221 + struct inode *hinoinode;
11222 + struct hlist_bl_head *hbl;
11226 + hbl = dr->dr_h_ino;
11227 + hinoinode = file_inode(hinofile);
11228 + sz = i_size_read(hinoinode);
11229 + AuDebugOn(sz % sizeof(u64));
11230 + n = sz / sizeof(u64);
11232 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11233 + if (unlikely(ssz != sizeof(u64))) {
11234 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11241 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11247 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11248 + AuDbg("hi%llu, %pD2\n",
11249 + (unsigned long long)ent->dr_h_ino, hinofile);
11250 + hidx = au_dr_ihash(ent->dr_h_ino);
11251 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11253 + goto out; /* success */
11256 + au_dr_hino_free(dr);
11263 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11264 + * @path is a switch to distinguish load and store.
11266 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11267 + struct au_branch *br, const struct path *path)
11270 + unsigned char load, suspend;
11271 + struct file *hinofile;
11272 + struct au_hinode *hdir;
11273 + struct inode *dir, *delegated;
11274 + struct path hinopath;
11275 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11276 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11278 + AuDebugOn(bindex < 0 && !br);
11279 + AuDebugOn(bindex >= 0 && br);
11284 + br = au_sbr(sb, bindex);
11287 + path = &br->br_path;
11288 + AuDebugOn(!au_br_writable(br->br_perm));
11289 + if (unlikely(!au_br_writable(br->br_perm)))
11295 + dir = d_inode(sb->s_root);
11296 + hdir = au_hinode(au_ii(dir), bindex);
11297 + dir = hdir->hi_inode;
11298 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11300 + dir = d_inode(path->dentry);
11301 + inode_lock_nested(dir, AuLsc_I_CHILD);
11303 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11304 + err = PTR_ERR(hinopath.dentry);
11305 + if (IS_ERR(hinopath.dentry))
11309 + flags = O_RDONLY;
11311 + if (d_is_negative(hinopath.dentry))
11312 + goto out_dput; /* success */
11314 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11315 + if (d_is_positive(hinopath.dentry)) {
11316 + delegated = NULL;
11317 + err = vfsub_unlink(dir, &hinopath, &delegated,
11320 + if (unlikely(err))
11321 + pr_err("ignored err %d, %pd2\n",
11322 + err, hinopath.dentry);
11323 + if (unlikely(err == -EWOULDBLOCK))
11328 + } else if (!d_is_positive(hinopath.dentry)) {
11329 + err = vfsub_create(dir, &hinopath, 0600,
11330 + /*want_excl*/false);
11332 + if (unlikely(err))
11335 + flags = O_WRONLY;
11337 + hinopath.mnt = path->mnt;
11338 + hinofile = vfsub_dentry_open(&hinopath, flags);
11340 + au_hn_inode_unlock(hdir);
11342 + inode_unlock(dir);
11343 + dput(hinopath.dentry);
11344 + AuTraceErrPtr(hinofile);
11345 + if (IS_ERR(hinofile)) {
11346 + err = PTR_ERR(hinofile);
11351 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11353 + err = au_dr_hino_store(sb, br, hinofile);
11358 + dput(hinopath.dentry);
11361 + au_hn_inode_unlock(hdir);
11363 + inode_unlock(dir);
11369 +/* ---------------------------------------------------------------------- */
11371 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11374 + struct kstatfs kstfs;
11376 + struct dentry *dentry;
11377 + struct super_block *sb;
11379 + err = vfs_statfs((void *)path, &kstfs);
11381 + if (unlikely(err))
11384 + /* todo: support for UUID */
11386 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11387 + brid->type = AuBrid_FSID;
11388 + brid->fsid = kstfs.f_fsid;
11390 + dentry = path->dentry;
11391 + sb = dentry->d_sb;
11394 + brid->type = AuBrid_DEV;
11403 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11404 + const struct path *path)
11407 + struct au_dr_br *dr;
11408 + struct hlist_bl_head *hbl;
11410 + dr = &br->br_dirren;
11411 + hbl = dr->dr_h_ino;
11412 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11413 + INIT_HLIST_BL_HEAD(hbl);
11415 + err = au_dr_brid_init(&dr->dr_brid, path);
11416 + if (unlikely(err))
11419 + if (au_opt_test(au_mntflags(sb), DIRREN))
11420 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11427 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11432 + if (au_br_writable(br->br_perm))
11433 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11435 + au_dr_hino_free(&br->br_dirren);
11440 +/* ---------------------------------------------------------------------- */
11442 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11443 + char *buf, size_t sz)
11446 + unsigned int major, minor;
11450 + err = snprintf(p, sz, "%d_", brid->type);
11451 + AuDebugOn(err > sz);
11454 + switch (brid->type) {
11455 + case AuBrid_Unset:
11457 + case AuBrid_UUID:
11458 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11460 + case AuBrid_FSID:
11461 + err = snprintf(p, sz, "%08x-%08x",
11462 + brid->fsid.val[0], brid->fsid.val[1]);
11465 + major = MAJOR(brid->dev);
11466 + minor = MINOR(brid->dev);
11467 + if (major <= 0xff && minor <= 0xff)
11468 + err = snprintf(p, sz, "%02x%02x", major, minor);
11470 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11473 + AuDebugOn(err > sz);
11476 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11477 + AuDebugOn(err > sz);
11484 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11487 + struct dentry *br_dentry;
11488 + struct inode *br_inode;
11490 + br_dentry = au_br_dentry(br);
11491 + br_inode = d_inode(br_dentry);
11492 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11493 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11494 + AuDebugOn(rlen > len);
11499 +/* ---------------------------------------------------------------------- */
11502 + * from the given @h_dentry, construct drinfo at @*fdata.
11503 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11506 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11507 + struct dentry *h_dentry,
11508 + unsigned char *allocated)
11511 + struct au_drinfo_fdata *f, *p;
11512 + struct au_drinfo *drinfo;
11513 + struct inode *h_inode;
11514 + struct qstr *qname;
11518 + h_inode = d_inode(h_dentry);
11519 + qname = &h_dentry->d_name;
11520 + drinfo = &f->drinfo;
11521 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11522 + drinfo->oldnamelen = qname->len;
11523 + if (*allocated < sizeof(*f) + qname->len) {
11524 + v = roundup_pow_of_two(*allocated + qname->len);
11525 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11526 + if (unlikely(!p)) {
11534 + drinfo = &f->drinfo;
11536 + memcpy(drinfo->oldname, qname->name, qname->len);
11537 + AuDbg("i%llu, %.*s\n",
11538 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11539 + drinfo->oldname);
11546 +/* callers have to free the return value */
11547 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11549 + struct au_drinfo *ret, *drinfo;
11550 + struct au_drinfo_fdata fdata;
11555 + ret = ERR_PTR(-EIO);
11557 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11558 + if (unlikely(ssz != sizeof(fdata))) {
11559 + AuIOErr("ssz %zd, %u, %pD2\n",
11560 + ssz, (unsigned int)sizeof(fdata), file);
11564 + fdata.magic = ntohl((__force __be32)fdata.magic);
11565 + switch (fdata.magic) {
11566 + case AUFS_DRINFO_MAGIC_V1:
11569 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11570 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11574 + drinfo = &fdata.drinfo;
11575 + len = drinfo->oldnamelen;
11577 + AuIOErr("broken drinfo %pD2\n", file);
11582 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11583 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11584 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11585 + (unsigned long long)drinfo->ino,
11586 + (unsigned long long)h_ino, file);
11587 + goto out; /* success */
11590 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11591 + if (unlikely(!ret)) {
11592 + ret = ERR_PTR(-ENOMEM);
11593 + AuTraceErrPtr(ret);
11598 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11599 + if (unlikely(ssz != len)) {
11600 + au_kfree_rcu(ret);
11601 + ret = ERR_PTR(-EIO);
11602 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11606 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11612 +/* ---------------------------------------------------------------------- */
11614 +/* in order to be revertible */
11615 +struct au_drinfo_rev_elm {
11617 + struct dentry *info_dentry;
11618 + struct au_drinfo *info_last;
11621 +struct au_drinfo_rev {
11622 + unsigned char already;
11623 + aufs_bindex_t nelm;
11624 + struct au_drinfo_rev_elm elm[0];
11627 +/* todo: isn't it too large? */
11628 +struct au_drinfo_store {
11629 + struct path h_ppath;
11630 + struct dentry *h_dentry;
11631 + struct au_drinfo_fdata *fdata;
11632 + char *infoname; /* inside of whname, just after PFX */
11633 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11634 + aufs_bindex_t btgt, btail;
11635 + unsigned char no_sio,
11636 + allocated, /* current size of *fdata */
11637 + infonamelen, /* room size for p */
11638 + whnamelen, /* length of the generated name */
11639 + renameback; /* renamed back */
11642 +/* on rename(2) error, the caller should revert it using @elm */
11643 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11644 + struct au_drinfo_rev_elm *elm)
11649 + struct path infopath = {
11650 + .mnt = w->h_ppath.mnt
11652 + struct inode *h_dir, *h_inode, *delegated;
11653 + struct file *infofile;
11654 + struct qstr *qname;
11657 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11659 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11661 + AuTraceErrPtr(infopath.dentry);
11662 + if (IS_ERR(infopath.dentry)) {
11663 + err = PTR_ERR(infopath.dentry);
11668 + h_dir = d_inode(w->h_ppath.dentry);
11669 + if (elm && d_is_negative(infopath.dentry)) {
11670 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11672 + if (unlikely(err))
11674 + elm->created = 1;
11675 + elm->info_dentry = dget(infopath.dentry);
11678 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11679 + AuTraceErrPtr(infofile);
11680 + if (IS_ERR(infofile)) {
11681 + err = PTR_ERR(infofile);
11685 + h_inode = d_inode(infopath.dentry);
11686 + if (elm && i_size_read(h_inode)) {
11687 + h_inode = d_inode(w->h_dentry);
11688 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11689 + AuTraceErrPtr(elm->info_last);
11690 + if (IS_ERR(elm->info_last)) {
11691 + err = PTR_ERR(elm->info_last);
11692 + elm->info_last = NULL;
11693 + AuDebugOn(elm->info_dentry);
11698 + if (elm && w->renameback) {
11699 + delegated = NULL;
11700 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11702 + if (unlikely(err == -EWOULDBLOCK))
11708 + qname = &w->h_dentry->d_name;
11709 + len = sizeof(*w->fdata) + qname->len;
11711 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11712 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11713 + if (ssz == len) {
11714 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11715 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11716 + goto out_fput; /* success */
11721 + /* the caller should revert it using @elm */
11727 + dput(infopath.dentry);
11733 +struct au_call_drinfo_do_store_args {
11735 + struct au_drinfo_store *w;
11736 + struct au_drinfo_rev_elm *elm;
11739 +static void au_call_drinfo_do_store(void *args)
11741 + struct au_call_drinfo_do_store_args *a = args;
11743 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11746 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11747 + struct au_drinfo_rev_elm *elm)
11749 + int err, wkq_err;
11752 + err = au_drinfo_do_store(w, elm);
11754 + struct au_call_drinfo_do_store_args a = {
11759 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11760 + if (unlikely(wkq_err))
11768 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11769 + aufs_bindex_t btgt)
11773 + memset(w, 0, sizeof(*w));
11774 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11775 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11776 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11777 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11779 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11782 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11783 + if (unlikely(!w->fdata)) {
11787 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11794 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11796 + au_kfree_rcu(w->fdata);
11799 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11800 + struct au_drinfo_store *w)
11802 + struct au_drinfo_rev_elm *elm;
11803 + struct inode *h_dir, *delegated;
11805 + struct path infopath = {
11806 + .mnt = w->h_ppath.mnt
11809 + h_dir = d_inode(w->h_ppath.dentry);
11810 + IMustLock(h_dir);
11814 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11815 + AuDebugOn(elm->created && elm->info_last);
11816 + if (elm->created) {
11818 + delegated = NULL;
11819 + infopath.dentry = elm->info_dentry;
11820 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11823 + if (unlikely(err == -EWOULDBLOCK))
11825 + dput(elm->info_dentry);
11826 + } else if (elm->info_last) {
11828 + w->fdata->drinfo = *elm->info_last;
11829 + memcpy(w->fdata->drinfo.oldname,
11830 + elm->info_last->oldname,
11831 + elm->info_last->oldnamelen);
11832 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11833 + au_kfree_rcu(elm->info_last);
11835 + if (unlikely(err))
11836 + AuIOErr("%d, %s\n", err, w->whname);
11837 + /* go on even if err */
11841 +/* caller has to call au_dr_rename_fin() later */
11842 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11843 + struct qstr *dst_name, void *_rev)
11845 + int err, sz, nelm;
11846 + aufs_bindex_t bindex, btail;
11847 + struct au_drinfo_store work;
11848 + struct au_drinfo_rev *rev, **p;
11849 + struct au_drinfo_rev_elm *elm;
11850 + struct super_block *sb;
11851 + struct au_branch *br;
11852 + struct au_hinode *hdir;
11854 + err = au_drinfo_store_work_init(&work, btgt);
11856 + if (unlikely(err))
11860 + btail = au_dbtaildir(dentry);
11861 + nelm = btail - btgt;
11862 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11863 + rev = kcalloc(1, sz, GFP_NOFS);
11864 + if (unlikely(!rev)) {
11868 + rev->nelm = nelm;
11874 + sb = dentry->d_sb;
11875 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11876 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11877 + hdir = au_hi(d_inode(dentry), btgt);
11878 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11879 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11880 + work.h_dentry = au_h_dptr(dentry, bindex);
11881 + if (!work.h_dentry)
11884 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11885 + &work.allocated);
11887 + if (unlikely(err))
11890 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11891 + br = au_sbr(sb, bindex);
11892 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11893 + work.whnamelen += au_drinfo_name(br, work.infoname,
11894 + work.infonamelen);
11895 + AuDbg("whname %.*s, i%llu, %.*s\n",
11896 + work.whnamelen, work.whname,
11897 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11898 + work.fdata->drinfo.oldnamelen,
11899 + work.fdata->drinfo.oldname);
11901 + err = au_drinfo_store_sio(&work, elm);
11903 + if (unlikely(err))
11906 + if (unlikely(err)) {
11907 + /* revert all drinfo */
11908 + au_drinfo_store_rev(rev, &work);
11909 + au_kfree_try_rcu(rev);
11912 + au_hn_inode_unlock(hdir);
11915 + au_drinfo_store_work_fin(&work);
11920 +/* ---------------------------------------------------------------------- */
11922 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11923 + struct qstr *dst_name, void *_rev)
11925 + int err, already;
11927 + struct super_block *sb;
11928 + struct au_branch *br;
11929 + struct au_dr_br *dr;
11930 + struct dentry *h_dentry;
11931 + struct inode *h_inode;
11932 + struct au_dr_hino *ent;
11933 + struct au_drinfo_rev *rev, **p;
11935 + AuDbg("bindex %d\n", bindex);
11938 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11939 + if (unlikely(!ent))
11943 + br = au_sbr(sb, bindex);
11944 + dr = &br->br_dirren;
11945 + h_dentry = au_h_dptr(src, bindex);
11946 + h_inode = d_inode(h_dentry);
11947 + ino = h_inode->i_ino;
11948 + ent->dr_h_ino = ino;
11949 + already = au_dr_hino_test_add(dr, ino, ent);
11950 + AuDbg("b%d, hi%llu, already %d\n",
11951 + bindex, (unsigned long long)ino, already);
11953 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11958 + rev->already = already;
11959 + goto out; /* success */
11964 + au_dr_hino_del(dr, ent);
11965 + au_kfree_rcu(ent);
11972 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11974 + struct au_drinfo_rev *rev;
11975 + struct au_drinfo_rev_elm *elm;
11980 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11981 + dput(elm->info_dentry);
11982 + au_kfree_rcu(elm->info_last);
11984 + au_kfree_try_rcu(rev);
11987 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11990 + struct au_drinfo_store work;
11991 + struct au_drinfo_rev *rev = _rev;
11992 + struct super_block *sb;
11993 + struct au_branch *br;
11994 + struct inode *h_inode;
11995 + struct au_dr_br *dr;
11996 + struct au_dr_hino *ent;
11998 + err = au_drinfo_store_work_init(&work, btgt);
11999 + if (unlikely(err))
12003 + br = au_sbr(sb, btgt);
12004 + work.h_ppath.dentry = au_h_dptr(src, btgt);
12005 + work.h_ppath.mnt = au_br_mnt(br);
12006 + au_drinfo_store_rev(rev, &work);
12007 + au_drinfo_store_work_fin(&work);
12008 + if (rev->already)
12011 + dr = &br->br_dirren;
12012 + h_inode = d_inode(work.h_ppath.dentry);
12013 + ent = au_dr_hino_find(dr, h_inode->i_ino);
12015 + au_dr_hino_del(dr, ent);
12016 + au_kfree_rcu(ent);
12019 + au_kfree_try_rcu(rev);
12020 + if (unlikely(err))
12021 + pr_err("failed to remove dirren info\n");
12024 +/* ---------------------------------------------------------------------- */
12026 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12027 + char *whname, int whnamelen,
12028 + struct dentry **info_dentry)
12030 + struct au_drinfo *drinfo;
12032 + struct inode *h_dir;
12033 + struct path infopath;
12036 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12038 + *info_dentry = NULL;
12041 + h_dir = d_inode(h_ppath->dentry);
12042 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12043 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12045 + if (IS_ERR(infopath.dentry)) {
12046 + drinfo = (void *)infopath.dentry;
12050 + if (d_is_negative(infopath.dentry))
12051 + goto out_dput; /* success */
12053 + infopath.mnt = h_ppath->mnt;
12054 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12055 + inode_unlock_shared(h_dir);
12058 + drinfo = (void *)f;
12062 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12063 + if (IS_ERR_OR_NULL(drinfo))
12066 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12067 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12072 + dput(infopath.dentry);
12075 + inode_unlock_shared(h_dir);
12076 + AuTraceErrPtr(drinfo);
12080 +struct au_drinfo_do_load_args {
12081 + struct au_drinfo **drinfop;
12082 + struct path *h_ppath;
12085 + struct dentry **info_dentry;
12088 +static void au_call_drinfo_do_load(void *args)
12090 + struct au_drinfo_do_load_args *a = args;
12092 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12096 +struct au_drinfo_load {
12097 + struct path h_ppath;
12098 + struct qstr *qname;
12099 + unsigned char no_sio;
12101 + aufs_bindex_t ninfo;
12102 + struct au_drinfo **drinfo;
12105 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12106 + struct au_branch *br)
12108 + int err, wkq_err, whnamelen, e;
12109 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12110 + = AUFS_WH_DR_INFO_PFX;
12111 + struct au_drinfo *drinfo;
12112 + struct qstr oldname;
12113 + struct inode *h_dir, *delegated;
12114 + struct dentry *info_dentry;
12115 + struct path infopath;
12117 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12118 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12119 + sizeof(whname) - whnamelen);
12121 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12124 + struct au_drinfo_do_load_args args = {
12125 + .drinfop = &drinfo,
12126 + .h_ppath = &w->h_ppath,
12127 + .whname = whname,
12128 + .whnamelen = whnamelen,
12129 + .info_dentry = &info_dentry
12131 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12132 + if (unlikely(wkq_err))
12133 + drinfo = ERR_PTR(wkq_err);
12135 + err = PTR_ERR(drinfo);
12136 + if (IS_ERR_OR_NULL(drinfo))
12140 + oldname.len = drinfo->oldnamelen;
12141 + oldname.name = drinfo->oldname;
12142 + if (au_qstreq(w->qname, &oldname)) {
12143 + /* the name is renamed back */
12144 + au_kfree_rcu(drinfo);
12147 + infopath.dentry = info_dentry;
12148 + infopath.mnt = w->h_ppath.mnt;
12149 + h_dir = d_inode(w->h_ppath.dentry);
12150 + delegated = NULL;
12151 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12152 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12153 + inode_unlock(h_dir);
12155 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12156 + if (unlikely(e == -EWOULDBLOCK))
12159 + au_kfree_rcu(w->drinfo[bindex]);
12160 + w->drinfo[bindex] = drinfo;
12161 + dput(info_dentry);
12168 +/* ---------------------------------------------------------------------- */
12170 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12172 + struct au_drinfo **p = drinfo;
12175 + au_kfree_rcu(*drinfo++);
12176 + au_kfree_try_rcu(p);
12179 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12180 + aufs_bindex_t btgt)
12183 + struct au_drinfo_load w;
12184 + aufs_bindex_t bindex, bbot;
12185 + struct au_branch *br;
12186 + struct inode *h_dir;
12187 + struct au_dr_hino *ent;
12188 + struct super_block *sb;
12190 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12191 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12192 + AuLNPair(&lkup->whname), btgt);
12194 + sb = dentry->d_sb;
12195 + bbot = au_sbbot(sb);
12196 + w.ninfo = bbot + 1;
12197 + if (!lkup->dirren.drinfo) {
12198 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12199 + sizeof(*lkup->dirren.drinfo),
12201 + if (unlikely(!lkup->dirren.drinfo)) {
12205 + lkup->dirren.ninfo = w.ninfo;
12207 + w.drinfo = lkup->dirren.drinfo;
12208 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12209 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12210 + AuDebugOn(!w.h_ppath.dentry);
12211 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12212 + w.qname = &dentry->d_name;
12215 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12216 + br = au_sbr(sb, bindex);
12217 + err = au_drinfo_load(&w, bindex, br);
12218 + if (unlikely(err))
12220 + if (w.drinfo[bindex])
12224 + br = au_sbr(sb, btgt);
12225 + h_dir = d_inode(w.h_ppath.dentry);
12226 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12228 + au_dr_hino_del(&br->br_dirren, ent);
12229 + au_kfree_rcu(ent);
12231 + goto out; /* success */
12234 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12235 + lkup->dirren.ninfo = 0;
12236 + lkup->dirren.drinfo = NULL;
12242 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12244 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12247 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12250 + struct au_drinfo *drinfo;
12253 + if (!lkup->dirren.drinfo)
12255 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12256 + drinfo = lkup->dirren.drinfo[btgt + 1];
12260 + au_kfree_try_rcu(lkup->whname.name);
12261 + lkup->whname.name = NULL;
12262 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12263 + lkup->dirren.dr_name.name = drinfo->oldname;
12264 + lkup->name = &lkup->dirren.dr_name;
12265 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12267 + AuDbg("name %.*s, whname %.*s, b%d\n",
12268 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12276 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12280 + struct au_drinfo *drinfo;
12283 + if (!lkup->dirren.drinfo)
12285 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12286 + drinfo = lkup->dirren.drinfo[bindex + 1];
12290 + match = (drinfo->ino == h_ino);
12291 + AuDbg("match %d\n", match);
12297 +/* ---------------------------------------------------------------------- */
12299 +int au_dr_opt_set(struct super_block *sb)
12302 + aufs_bindex_t bindex, bbot;
12303 + struct au_branch *br;
12306 + bbot = au_sbbot(sb);
12307 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12308 + br = au_sbr(sb, bindex);
12309 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12315 +int au_dr_opt_flush(struct super_block *sb)
12318 + aufs_bindex_t bindex, bbot;
12319 + struct au_branch *br;
12322 + bbot = au_sbbot(sb);
12323 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12324 + br = au_sbr(sb, bindex);
12325 + if (au_br_writable(br->br_perm))
12326 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12332 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12335 + aufs_bindex_t bindex, bbot;
12336 + struct au_branch *br;
12340 + err = au_dr_opt_flush(sb);
12341 + if (unlikely(err))
12345 + bbot = au_sbbot(sb);
12346 + for (bindex = 0; bindex <= bbot; bindex++) {
12347 + br = au_sbr(sb, bindex);
12348 + au_dr_hino_free(&br->br_dirren);
12354 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12355 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12356 +++ linux/fs/aufs/dirren.h 2019-01-28 14:36:12.219084659 +0100
12358 +/* SPDX-License-Identifier: GPL-2.0 */
12360 + * Copyright (C) 2017-2018 Junjiro R. Okajima
12362 + * This program, aufs is free software; you can redistribute it and/or modify
12363 + * it under the terms of the GNU General Public License as published by
12364 + * the Free Software Foundation; either version 2 of the License, or
12365 + * (at your option) any later version.
12367 + * This program is distributed in the hope that it will be useful,
12368 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12369 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12370 + * GNU General Public License for more details.
12372 + * You should have received a copy of the GNU General Public License
12373 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12377 + * renamed dir info
12380 +#ifndef __AUFS_DIRREN_H__
12381 +#define __AUFS_DIRREN_H__
12385 +#include <linux/dcache.h>
12386 +#include <linux/statfs.h>
12387 +#include <linux/uuid.h>
12390 +#define AuDirren_NHASH 100
12392 +#ifdef CONFIG_AUFS_DIRREN
12393 +enum au_brid_type {
12400 +struct au_dr_brid {
12401 + enum au_brid_type type;
12403 + uuid_t uuid; /* unimplemented yet */
12409 +/* 20 is the max digits length of ulong 64 */
12410 +/* brid-type "_" uuid "_" inum */
12411 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12412 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12414 +struct au_dr_hino {
12415 + struct hlist_bl_node dr_hnode;
12420 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12421 + struct au_dr_brid dr_brid;
12424 +struct au_dr_lookup {
12425 + /* dr_name is pointed by struct au_do_lookup_args.name */
12426 + struct qstr dr_name; /* subset of dr_info */
12427 + aufs_bindex_t ninfo;
12428 + struct au_drinfo **drinfo;
12431 +struct au_dr_hino;
12433 +struct au_dr_br { };
12434 +struct au_dr_lookup { };
12437 +/* ---------------------------------------------------------------------- */
12440 +struct au_do_lookup_args;
12442 +#ifdef CONFIG_AUFS_DIRREN
12443 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12444 + struct au_dr_hino *add_ent);
12445 +void au_dr_hino_free(struct au_dr_br *dr);
12446 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12447 + const struct path *path);
12448 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12449 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12450 + struct qstr *dst_name, void *_rev);
12451 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12452 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12453 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12454 + aufs_bindex_t bindex);
12455 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12456 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12458 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12459 +int au_dr_opt_set(struct super_block *sb);
12460 +int au_dr_opt_flush(struct super_block *sb);
12461 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12463 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12464 + struct au_dr_hino *add_ent);
12465 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12466 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12467 + const struct path *path);
12468 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12469 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12470 + struct qstr *dst_name, void *_rev);
12471 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12472 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12474 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12475 + aufs_bindex_t bindex);
12476 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12477 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12478 + aufs_bindex_t bindex, ino_t h_ino);
12479 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12480 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12481 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12482 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12485 +/* ---------------------------------------------------------------------- */
12487 +#ifdef CONFIG_AUFS_DIRREN
12488 +static inline int au_dr_ihash(ino_t h_ino)
12490 + return h_ino % AuDirren_NHASH;
12493 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12496 +#endif /* __KERNEL__ */
12497 +#endif /* __AUFS_DIRREN_H__ */
12498 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12499 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12500 +++ linux/fs/aufs/dynop.c 2019-01-28 14:36:12.219084659 +0100
12502 +// SPDX-License-Identifier: GPL-2.0
12504 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12506 + * This program, aufs is free software; you can redistribute it and/or modify
12507 + * it under the terms of the GNU General Public License as published by
12508 + * the Free Software Foundation; either version 2 of the License, or
12509 + * (at your option) any later version.
12511 + * This program is distributed in the hope that it will be useful,
12512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12514 + * GNU General Public License for more details.
12516 + * You should have received a copy of the GNU General Public License
12517 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12521 + * dynamically customizable operations for regular files
12526 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12529 + * How large will these lists be?
12530 + * Usually just a few elements, 20-30 at most for each, I guess.
12532 +static struct hlist_bl_head dynop[AuDyLast];
12534 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12535 + const void *h_op)
12537 + struct au_dykey *key, *tmp;
12538 + struct hlist_bl_node *pos;
12541 + hlist_bl_lock(hbl);
12542 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12543 + if (tmp->dk_op.dy_hop == h_op) {
12545 + kref_get(&key->dk_kref);
12548 + hlist_bl_unlock(hbl);
12553 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12555 + struct au_dykey **k, *found;
12556 + const void *h_op = key->dk_op.dy_hop;
12560 + k = br->br_dykey;
12561 + for (i = 0; i < AuBrDynOp; i++)
12563 + if (k[i]->dk_op.dy_hop == h_op) {
12570 + spin_lock(&br->br_dykey_lock);
12571 + for (; i < AuBrDynOp; i++)
12573 + if (k[i]->dk_op.dy_hop == h_op) {
12581 + spin_unlock(&br->br_dykey_lock);
12582 + BUG_ON(i == AuBrDynOp); /* expand the array */
12588 +/* kref_get() if @key is already added */
12589 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12591 + struct au_dykey *tmp, *found;
12592 + struct hlist_bl_node *pos;
12593 + const void *h_op = key->dk_op.dy_hop;
12596 + hlist_bl_lock(hbl);
12597 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12598 + if (tmp->dk_op.dy_hop == h_op) {
12599 + kref_get(&tmp->dk_kref);
12604 + hlist_bl_add_head(&key->dk_hnode, hbl);
12605 + hlist_bl_unlock(hbl);
12612 +static void dy_free_rcu(struct rcu_head *rcu)
12614 + struct au_dykey *key;
12616 + key = container_of(rcu, struct au_dykey, dk_rcu);
12618 + au_kfree_rcu(key);
12621 +static void dy_free(struct kref *kref)
12623 + struct au_dykey *key;
12624 + struct hlist_bl_head *hbl;
12626 + key = container_of(kref, struct au_dykey, dk_kref);
12627 + hbl = dynop + key->dk_op.dy_type;
12628 + au_hbl_del(&key->dk_hnode, hbl);
12629 + call_rcu(&key->dk_rcu, dy_free_rcu);
12632 +void au_dy_put(struct au_dykey *key)
12634 + kref_put(&key->dk_kref, dy_free);
12637 +/* ---------------------------------------------------------------------- */
12639 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12641 +#ifdef CONFIG_AUFS_DEBUG
12642 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12643 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12645 +#define DyDbgDeclare(cnt) do {} while (0)
12646 +#define DyDbgInc(cnt) do {} while (0)
12649 +#define DySet(func, dst, src, h_op, h_sb) do { \
12651 + if (h_op->func) { \
12653 + dst.func = src.func; \
12655 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12659 +#define DySetForce(func, dst, src) do { \
12660 + AuDebugOn(!src.func); \
12662 + dst.func = src.func; \
12665 +#define DySetAop(func) \
12666 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12667 +#define DySetAopForce(func) \
12668 + DySetForce(func, dyaop->da_op, aufs_aop)
12670 +static void dy_aop(struct au_dykey *key, const void *h_op,
12671 + struct super_block *h_sb __maybe_unused)
12673 + struct au_dyaop *dyaop = (void *)key;
12674 + const struct address_space_operations *h_aop = h_op;
12675 + DyDbgDeclare(cnt);
12677 + AuDbg("%s\n", au_sbtype(h_sb));
12679 + DySetAop(writepage);
12680 + DySetAopForce(readpage); /* force */
12681 + DySetAop(writepages);
12682 + DySetAop(set_page_dirty);
12683 + DySetAop(readpages);
12684 + DySetAop(write_begin);
12685 + DySetAop(write_end);
12687 + DySetAop(invalidatepage);
12688 + DySetAop(releasepage);
12689 + DySetAop(freepage);
12690 + /* this one will be changed according to an aufs mount option */
12691 + DySetAop(direct_IO);
12692 + DySetAop(migratepage);
12693 + DySetAop(isolate_page);
12694 + DySetAop(putback_page);
12695 + DySetAop(launder_page);
12696 + DySetAop(is_partially_uptodate);
12697 + DySetAop(is_dirty_writeback);
12698 + DySetAop(error_remove_page);
12699 + DySetAop(swap_activate);
12700 + DySetAop(swap_deactivate);
12702 + DyDbgSize(cnt, *h_aop);
12705 +/* ---------------------------------------------------------------------- */
12707 +static void dy_bug(struct kref *kref)
12712 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12714 + struct au_dykey *key, *old;
12715 + struct hlist_bl_head *hbl;
12718 + void (*set)(struct au_dykey *key, const void *h_op,
12719 + struct super_block *h_sb __maybe_unused);
12721 + static const struct op a[] = {
12723 + .sz = sizeof(struct au_dyaop),
12727 + const struct op *p;
12729 + hbl = dynop + op->dy_type;
12730 + key = dy_gfind_get(hbl, op->dy_hop);
12732 + goto out_add; /* success */
12734 + p = a + op->dy_type;
12735 + key = kzalloc(p->sz, GFP_NOFS);
12736 + if (unlikely(!key)) {
12737 + key = ERR_PTR(-ENOMEM);
12741 + key->dk_op.dy_hop = op->dy_hop;
12742 + kref_init(&key->dk_kref);
12743 + p->set(key, op->dy_hop, au_br_sb(br));
12744 + old = dy_gadd(hbl, key);
12746 + au_kfree_rcu(key);
12751 + old = dy_bradd(br, key);
12753 + /* its ref-count should never be zero here */
12754 + kref_put(&key->dk_kref, dy_bug);
12759 +/* ---------------------------------------------------------------------- */
12761 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12762 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12763 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12764 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12765 + * See the aufs manual in detail.
12767 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12770 + dyaop->da_op.direct_IO = NULL;
12772 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12775 +static struct au_dyaop *dy_aget(struct au_branch *br,
12776 + const struct address_space_operations *h_aop,
12779 + struct au_dyaop *dyaop;
12780 + struct au_dynop op;
12782 + op.dy_type = AuDy_AOP;
12783 + op.dy_haop = h_aop;
12784 + dyaop = (void *)dy_get(&op, br);
12785 + if (IS_ERR(dyaop))
12787 + dy_adx(dyaop, do_dx);
12793 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12794 + struct inode *h_inode)
12797 + struct super_block *sb;
12798 + struct au_branch *br;
12799 + struct au_dyaop *dyaop;
12801 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12802 + IiMustWriteLock(inode);
12804 + sb = inode->i_sb;
12805 + br = au_sbr(sb, bindex);
12806 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12807 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12808 + err = PTR_ERR(dyaop);
12809 + if (IS_ERR(dyaop))
12810 + /* unnecessary to call dy_fput() */
12814 + inode->i_mapping->a_ops = &dyaop->da_op;
12821 + * Is it safe to replace a_ops during the inode/file is in operation?
12822 + * Yes, I hope so.
12824 +int au_dy_irefresh(struct inode *inode)
12827 + aufs_bindex_t btop;
12828 + struct inode *h_inode;
12831 + if (S_ISREG(inode->i_mode)) {
12832 + btop = au_ibtop(inode);
12833 + h_inode = au_h_iptr(inode, btop);
12834 + err = au_dy_iaop(inode, btop, h_inode);
12839 +void au_dy_arefresh(int do_dx)
12841 + struct hlist_bl_head *hbl;
12842 + struct hlist_bl_node *pos;
12843 + struct au_dykey *key;
12845 + hbl = dynop + AuDy_AOP;
12846 + hlist_bl_lock(hbl);
12847 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12848 + dy_adx((void *)key, do_dx);
12849 + hlist_bl_unlock(hbl);
12852 +/* ---------------------------------------------------------------------- */
12854 +void __init au_dy_init(void)
12858 + /* make sure that 'struct au_dykey *' can be any type */
12859 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12861 + for (i = 0; i < AuDyLast; i++)
12862 + INIT_HLIST_BL_HEAD(dynop + i);
12865 +void au_dy_fin(void)
12869 + for (i = 0; i < AuDyLast; i++)
12870 + WARN_ON(!hlist_bl_empty(dynop + i));
12872 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12873 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12874 +++ linux/fs/aufs/dynop.h 2019-01-28 14:36:12.219084659 +0100
12876 +/* SPDX-License-Identifier: GPL-2.0 */
12878 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12880 + * This program, aufs is free software; you can redistribute it and/or modify
12881 + * it under the terms of the GNU General Public License as published by
12882 + * the Free Software Foundation; either version 2 of the License, or
12883 + * (at your option) any later version.
12885 + * This program is distributed in the hope that it will be useful,
12886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12888 + * GNU General Public License for more details.
12890 + * You should have received a copy of the GNU General Public License
12891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12895 + * dynamically customizable operations (for regular files only)
12898 +#ifndef __AUFS_DYNOP_H__
12899 +#define __AUFS_DYNOP_H__
12903 +#include <linux/fs.h>
12904 +#include <linux/kref.h>
12906 +enum {AuDy_AOP, AuDyLast};
12911 + const void *dy_hop;
12912 + const struct address_space_operations *dy_haop;
12918 + struct hlist_bl_node dk_hnode;
12919 + struct rcu_head dk_rcu;
12921 + struct au_dynop dk_op;
12924 + * during I am in the branch local array, kref is gotten. when the
12925 + * branch is removed, kref is put.
12927 + struct kref dk_kref;
12930 +/* stop unioning since their sizes are very different from each other */
12932 + struct au_dykey da_key;
12933 + struct address_space_operations da_op; /* not const */
12936 +/* ---------------------------------------------------------------------- */
12940 +void au_dy_put(struct au_dykey *key);
12941 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12942 + struct inode *h_inode);
12943 +int au_dy_irefresh(struct inode *inode);
12944 +void au_dy_arefresh(int do_dio);
12946 +void __init au_dy_init(void);
12947 +void au_dy_fin(void);
12949 +#endif /* __KERNEL__ */
12950 +#endif /* __AUFS_DYNOP_H__ */
12951 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12952 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12953 +++ linux/fs/aufs/export.c 2019-01-28 14:36:12.219084659 +0100
12955 +// SPDX-License-Identifier: GPL-2.0
12957 + * Copyright (C) 2005-2018 Junjiro R. Okajima
12959 + * This program, aufs is free software; you can redistribute it and/or modify
12960 + * it under the terms of the GNU General Public License as published by
12961 + * the Free Software Foundation; either version 2 of the License, or
12962 + * (at your option) any later version.
12964 + * This program is distributed in the hope that it will be useful,
12965 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12966 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12967 + * GNU General Public License for more details.
12969 + * You should have received a copy of the GNU General Public License
12970 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12977 +#include <linux/exportfs.h>
12978 +#include <linux/fs_struct.h>
12979 +#include <linux/namei.h>
12980 +#include <linux/nsproxy.h>
12981 +#include <linux/random.h>
12982 +#include <linux/writeback.h>
12986 +#ifdef CONFIG_AUFS_INO_T_64
12994 +static ino_t decode_ino(__u32 *a)
12998 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
13000 +#ifdef CONFIG_AUFS_INO_T_64
13006 +static void encode_ino(__u32 *a, ino_t ino)
13012 +#ifdef CONFIG_AUFS_INO_T_64
13017 +/* NFS file handle */
13021 +#ifdef CONFIG_AUFS_INO_T_64
13022 + /* support 64bit inode number */
13035 + Fh_ino = Fh_ino1,
13036 + Fh_dir_ino = Fh_dir_ino1
13039 +static int au_test_anon(struct dentry *dentry)
13041 + /* note: read d_flags without d_lock */
13042 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13045 +int au_test_nfsd(void)
13048 + struct task_struct *tsk = current;
13049 + char comm[sizeof(tsk->comm)];
13052 + if (tsk->flags & PF_KTHREAD) {
13053 + get_task_comm(comm, tsk);
13054 + ret = !strcmp(comm, "nfsd");
13060 +/* ---------------------------------------------------------------------- */
13061 +/* inode generation external table */
13063 +void au_xigen_inc(struct inode *inode)
13068 + struct super_block *sb;
13069 + struct au_sbinfo *sbinfo;
13071 + sb = inode->i_sb;
13072 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13074 + sbinfo = au_sbi(sb);
13075 + pos = inode->i_ino;
13076 + pos *= sizeof(igen);
13077 + igen = inode->i_generation + 1;
13078 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13079 + sizeof(igen), &pos);
13080 + if (sz == sizeof(igen))
13081 + return; /* success */
13083 + if (unlikely(sz >= 0))
13084 + AuIOErr("xigen error (%zd)\n", sz);
13087 +int au_xigen_new(struct inode *inode)
13092 + struct super_block *sb;
13093 + struct au_sbinfo *sbinfo;
13094 + struct file *file;
13097 + /* todo: dirty, at mount time */
13098 + if (inode->i_ino == AUFS_ROOT_INO)
13100 + sb = inode->i_sb;
13101 + SiMustAnyLock(sb);
13102 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13106 + pos = inode->i_ino;
13107 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13108 + AuIOErr1("too large i%lld\n", pos);
13111 + pos *= sizeof(inode->i_generation);
13114 + sbinfo = au_sbi(sb);
13115 + file = sbinfo->si_xigen;
13118 + if (vfsub_f_size_read(file)
13119 + < pos + sizeof(inode->i_generation)) {
13120 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13121 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13122 + sizeof(inode->i_generation), &pos);
13124 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13125 + sizeof(inode->i_generation), &pos);
13126 + if (sz == sizeof(inode->i_generation))
13127 + goto out; /* success */
13130 + if (unlikely(sz >= 0)) {
13132 + AuIOErr("xigen error (%zd)\n", sz);
13139 +int au_xigen_set(struct super_block *sb, struct path *path)
13142 + struct au_sbinfo *sbinfo;
13143 + struct file *file;
13145 + SiMustWriteLock(sb);
13147 + sbinfo = au_sbi(sb);
13148 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13149 + err = PTR_ERR(file);
13150 + if (IS_ERR(file))
13153 + if (sbinfo->si_xigen)
13154 + fput(sbinfo->si_xigen);
13155 + sbinfo->si_xigen = file;
13162 +void au_xigen_clr(struct super_block *sb)
13164 + struct au_sbinfo *sbinfo;
13166 + SiMustWriteLock(sb);
13168 + sbinfo = au_sbi(sb);
13169 + if (sbinfo->si_xigen) {
13170 + fput(sbinfo->si_xigen);
13171 + sbinfo->si_xigen = NULL;
13175 +/* ---------------------------------------------------------------------- */
13177 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13180 + struct dentry *dentry, *d;
13181 + struct inode *inode;
13182 + unsigned int sigen;
13185 + inode = ilookup(sb, ino);
13189 + dentry = ERR_PTR(-ESTALE);
13190 + sigen = au_sigen(sb);
13191 + if (unlikely(au_is_bad_inode(inode)
13192 + || IS_DEADDIR(inode)
13193 + || sigen != au_iigen(inode, NULL)))
13197 + if (!dir_ino || S_ISDIR(inode->i_mode))
13198 + dentry = d_find_alias(inode);
13200 + spin_lock(&inode->i_lock);
13201 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13202 + spin_lock(&d->d_lock);
13203 + if (!au_test_anon(d)
13204 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13205 + dentry = dget_dlock(d);
13206 + spin_unlock(&d->d_lock);
13209 + spin_unlock(&d->d_lock);
13211 + spin_unlock(&inode->i_lock);
13213 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13214 + /* need to refresh */
13222 + AuTraceErrPtr(dentry);
13226 +/* ---------------------------------------------------------------------- */
13228 +/* todo: dirty? */
13229 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13231 +struct au_compare_mnt_args {
13233 + struct super_block *sb;
13236 + struct vfsmount *mnt;
13239 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13241 + struct au_compare_mnt_args *a = arg;
13243 + if (mnt->mnt_sb != a->sb)
13245 + a->mnt = mntget(mnt);
13249 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13252 + struct path root;
13253 + struct au_compare_mnt_args args = {
13257 + get_fs_root(current->fs, &root);
13259 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13260 + rcu_read_unlock();
13263 + AuDebugOn(!args.mnt);
13267 +struct au_nfsd_si_lock {
13268 + unsigned int sigen;
13269 + aufs_bindex_t bindex, br_id;
13270 + unsigned char force_lock;
13273 +static int si_nfsd_read_lock(struct super_block *sb,
13274 + struct au_nfsd_si_lock *nsi_lock)
13277 + aufs_bindex_t bindex;
13279 + si_read_lock(sb, AuLock_FLUSH);
13281 + /* branch id may be wrapped around */
13283 + bindex = au_br_index(sb, nsi_lock->br_id);
13284 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13285 + goto out; /* success */
13289 + if (!nsi_lock->force_lock)
13290 + si_read_unlock(sb);
13293 + nsi_lock->bindex = bindex;
13297 +struct find_name_by_ino {
13298 + struct dir_context ctx;
13299 + int called, found;
13306 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13307 + loff_t offset, u64 ino, unsigned int d_type)
13309 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13313 + if (a->ino != ino)
13316 + memcpy(a->name, name, namelen);
13317 + a->namelen = namelen;
13322 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13323 + struct au_nfsd_si_lock *nsi_lock)
13325 + struct dentry *dentry, *parent;
13326 + struct file *file;
13327 + struct inode *dir;
13328 + struct find_name_by_ino arg = {
13330 + .actor = find_name_by_ino
13335 + parent = path->dentry;
13337 + si_read_unlock(parent->d_sb);
13338 + file = vfsub_dentry_open(path, au_dir_roflags);
13339 + dentry = (void *)file;
13340 + if (IS_ERR(file))
13343 + dentry = ERR_PTR(-ENOMEM);
13344 + arg.name = (void *)__get_free_page(GFP_NOFS);
13345 + if (unlikely(!arg.name))
13352 + err = vfsub_iterate_dir(file, &arg.ctx);
13353 + } while (!err && !arg.found && arg.called);
13354 + dentry = ERR_PTR(err);
13355 + if (unlikely(err))
13357 + /* instead of ENOENT */
13358 + dentry = ERR_PTR(-ESTALE);
13362 + /* do not call vfsub_lkup_one() */
13363 + dir = d_inode(parent);
13364 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13365 + AuTraceErrPtr(dentry);
13366 + if (IS_ERR(dentry))
13368 + AuDebugOn(au_test_anon(dentry));
13369 + if (unlikely(d_really_is_negative(dentry))) {
13371 + dentry = ERR_PTR(-ENOENT);
13375 + free_page((unsigned long)arg.name);
13379 + if (unlikely(nsi_lock
13380 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13381 + if (!IS_ERR(dentry)) {
13383 + dentry = ERR_PTR(-ESTALE);
13385 + AuTraceErrPtr(dentry);
13389 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13391 + struct au_nfsd_si_lock *nsi_lock)
13393 + struct dentry *dentry;
13394 + struct path path;
13396 + if (dir_ino != AUFS_ROOT_INO) {
13397 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13398 + dentry = path.dentry;
13399 + if (!path.dentry || IS_ERR(path.dentry))
13401 + AuDebugOn(au_test_anon(path.dentry));
13403 + path.dentry = dget(sb->s_root);
13405 + path.mnt = au_mnt_get(sb);
13406 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13410 + AuTraceErrPtr(dentry);
13414 +/* ---------------------------------------------------------------------- */
13416 +static int h_acceptable(void *expv, struct dentry *dentry)
13421 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13422 + char *buf, int len, struct super_block *sb)
13426 + struct path path;
13428 + p = d_path(h_rootpath, buf, len);
13433 + path.mnt = h_rootpath->mnt;
13434 + path.dentry = h_parent;
13435 + p = d_path(&path, buf, len);
13441 + path.mnt = au_mnt_get(sb);
13442 + path.dentry = sb->s_root;
13443 + p = d_path(&path, buf, len - strlen(p));
13444 + mntput(path.mnt);
13448 + p[strlen(p)] = '/';
13451 + AuTraceErrPtr(p);
13456 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13457 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13459 + struct dentry *dentry, *h_parent, *root;
13460 + struct super_block *h_sb;
13461 + char *pathname, *p;
13462 + struct vfsmount *h_mnt;
13463 + struct au_branch *br;
13465 + struct path path;
13467 + br = au_sbr(sb, nsi_lock->bindex);
13468 + h_mnt = au_br_mnt(br);
13469 + h_sb = h_mnt->mnt_sb;
13470 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13472 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13473 + fh_len - Fh_tail, fh[Fh_h_type],
13474 + h_acceptable, /*context*/NULL);
13476 + dentry = h_parent;
13477 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13478 + AuWarn1("%s decode_fh failed, %ld\n",
13479 + au_sbtype(h_sb), PTR_ERR(h_parent));
13483 + if (unlikely(au_test_anon(h_parent))) {
13484 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13485 + au_sbtype(h_sb));
13486 + goto out_h_parent;
13489 + dentry = ERR_PTR(-ENOMEM);
13490 + pathname = (void *)__get_free_page(GFP_NOFS);
13491 + if (unlikely(!pathname))
13492 + goto out_h_parent;
13494 + root = sb->s_root;
13495 + path.mnt = h_mnt;
13496 + di_read_lock_parent(root, !AuLock_IR);
13497 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13498 + di_read_unlock(root, !AuLock_IR);
13499 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13500 + dentry = (void *)p;
13502 + goto out_pathname;
13504 + si_read_unlock(sb);
13505 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13506 + dentry = ERR_PTR(err);
13507 + if (unlikely(err))
13510 + dentry = ERR_PTR(-ENOENT);
13511 + AuDebugOn(au_test_anon(path.dentry));
13512 + if (unlikely(d_really_is_negative(path.dentry)))
13515 + if (ino != d_inode(path.dentry)->i_ino)
13516 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13518 + dentry = dget(path.dentry);
13523 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13524 + if (!IS_ERR(dentry)) {
13526 + dentry = ERR_PTR(-ESTALE);
13529 + free_page((unsigned long)pathname);
13533 + AuTraceErrPtr(dentry);
13537 +/* ---------------------------------------------------------------------- */
13539 +static struct dentry *
13540 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13543 + struct dentry *dentry;
13544 + __u32 *fh = fid->raw;
13545 + struct au_branch *br;
13546 + ino_t ino, dir_ino;
13547 + struct au_nfsd_si_lock nsi_lock = {
13551 + dentry = ERR_PTR(-ESTALE);
13552 + /* it should never happen, but the file handle is unreliable */
13553 + if (unlikely(fh_len < Fh_tail))
13555 + nsi_lock.sigen = fh[Fh_sigen];
13556 + nsi_lock.br_id = fh[Fh_br_id];
13558 + /* branch id may be wrapped around */
13560 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13562 + nsi_lock.force_lock = 1;
13564 + /* is this inode still cached? */
13565 + ino = decode_ino(fh + Fh_ino);
13566 + /* it should never happen */
13567 + if (unlikely(ino == AUFS_ROOT_INO))
13570 + dir_ino = decode_ino(fh + Fh_dir_ino);
13571 + dentry = decode_by_ino(sb, ino, dir_ino);
13572 + if (IS_ERR(dentry))
13577 + /* is the parent dir cached? */
13578 + br = au_sbr(sb, nsi_lock.bindex);
13579 + au_lcnt_inc(&br->br_nfiles);
13580 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13581 + if (IS_ERR(dentry))
13586 + /* lookup path */
13587 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13588 + if (IS_ERR(dentry))
13590 + if (unlikely(!dentry))
13591 + /* todo?: make it ESTALE */
13595 + if (!au_digen_test(dentry, au_sigen(sb))
13596 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13597 + goto out_unlock; /* success */
13600 + dentry = ERR_PTR(-ESTALE);
13603 + au_lcnt_dec(&br->br_nfiles);
13604 + si_read_unlock(sb);
13606 + AuTraceErrPtr(dentry);
13610 +#if 0 /* reserved for future use */
13611 +/* support subtreecheck option */
13612 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13613 + int fh_len, int fh_type)
13615 + struct dentry *parent;
13616 + __u32 *fh = fid->raw;
13619 + dir_ino = decode_ino(fh + Fh_dir_ino);
13620 + parent = decode_by_ino(sb, dir_ino, 0);
13621 + if (IS_ERR(parent))
13624 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13625 + dir_ino, fh, fh_len);
13628 + AuTraceErrPtr(parent);
13633 +/* ---------------------------------------------------------------------- */
13635 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13636 + struct inode *dir)
13639 + aufs_bindex_t bindex;
13640 + struct super_block *sb, *h_sb;
13641 + struct dentry *dentry, *parent, *h_parent;
13642 + struct inode *h_dir;
13643 + struct au_branch *br;
13646 + if (unlikely(*max_len <= Fh_tail)) {
13647 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13651 + err = FILEID_ROOT;
13652 + if (inode->i_ino == AUFS_ROOT_INO) {
13653 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13658 + sb = inode->i_sb;
13659 + err = si_read_lock(sb, AuLock_FLUSH);
13660 + if (unlikely(err))
13663 +#ifdef CONFIG_AUFS_DEBUG
13664 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13665 + AuWarn1("NFS-exporting requires xino\n");
13669 + ii_read_lock_child(inode);
13670 + bindex = au_ibtop(inode);
13672 + dentry = d_find_any_alias(inode);
13673 + if (unlikely(!dentry))
13675 + AuDebugOn(au_test_anon(dentry));
13676 + parent = dget_parent(dentry);
13678 + if (unlikely(!parent))
13680 + if (d_really_is_positive(parent))
13681 + dir = d_inode(parent);
13684 + ii_read_lock_parent(dir);
13685 + h_dir = au_h_iptr(dir, bindex);
13686 + ii_read_unlock(dir);
13687 + if (unlikely(!h_dir))
13689 + h_parent = d_find_any_alias(h_dir);
13690 + if (unlikely(!h_parent))
13691 + goto out_hparent;
13694 + br = au_sbr(sb, bindex);
13695 + h_sb = au_br_sb(br);
13696 + if (unlikely(!h_sb->s_export_op)) {
13697 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13698 + goto out_hparent;
13701 + fh[Fh_br_id] = br->br_id;
13702 + fh[Fh_sigen] = au_sigen(sb);
13703 + encode_ino(fh + Fh_ino, inode->i_ino);
13704 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13705 + fh[Fh_igen] = inode->i_generation;
13707 + *max_len -= Fh_tail;
13708 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13710 + /*connectable or subtreecheck*/0);
13711 + err = fh[Fh_h_type];
13712 + *max_len += Fh_tail;
13713 + /* todo: macros? */
13714 + if (err != FILEID_INVALID)
13717 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13724 + ii_read_unlock(inode);
13725 + si_read_unlock(sb);
13727 + if (unlikely(err < 0))
13728 + err = FILEID_INVALID;
13732 +/* ---------------------------------------------------------------------- */
13734 +static int aufs_commit_metadata(struct inode *inode)
13737 + aufs_bindex_t bindex;
13738 + struct super_block *sb;
13739 + struct inode *h_inode;
13740 + int (*f)(struct inode *inode);
13742 + sb = inode->i_sb;
13743 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13744 + ii_write_lock_child(inode);
13745 + bindex = au_ibtop(inode);
13746 + AuDebugOn(bindex < 0);
13747 + h_inode = au_h_iptr(inode, bindex);
13749 + f = h_inode->i_sb->s_export_op->commit_metadata;
13751 + err = f(h_inode);
13753 + struct writeback_control wbc = {
13754 + .sync_mode = WB_SYNC_ALL,
13755 + .nr_to_write = 0 /* metadata only */
13758 + err = sync_inode(h_inode, &wbc);
13761 + au_cpup_attr_timesizes(inode);
13762 + ii_write_unlock(inode);
13763 + si_read_unlock(sb);
13767 +/* ---------------------------------------------------------------------- */
13769 +static struct export_operations aufs_export_op = {
13770 + .fh_to_dentry = aufs_fh_to_dentry,
13771 + /* .fh_to_parent = aufs_fh_to_parent, */
13772 + .encode_fh = aufs_encode_fh,
13773 + .commit_metadata = aufs_commit_metadata
13776 +void au_export_init(struct super_block *sb)
13778 + struct au_sbinfo *sbinfo;
13781 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13782 + && IS_MODULE(CONFIG_EXPORTFS),
13783 + AUFS_NAME ": unsupported configuration "
13784 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13786 + sb->s_export_op = &aufs_export_op;
13787 + sbinfo = au_sbi(sb);
13788 + sbinfo->si_xigen = NULL;
13789 + get_random_bytes(&u, sizeof(u));
13790 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13791 + atomic_set(&sbinfo->si_xigen_next, u);
13793 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13794 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13795 +++ linux/fs/aufs/fhsm.c 2019-01-28 14:36:12.219084659 +0100
13797 +// SPDX-License-Identifier: GPL-2.0
13799 + * Copyright (C) 2011-2018 Junjiro R. Okajima
13801 + * This program, aufs is free software; you can redistribute it and/or modify
13802 + * it under the terms of the GNU General Public License as published by
13803 + * the Free Software Foundation; either version 2 of the License, or
13804 + * (at your option) any later version.
13806 + * This program is distributed in the hope that it will be useful,
13807 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13808 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13809 + * GNU General Public License for more details.
13811 + * You should have received a copy of the GNU General Public License
13812 + * along with this program; if not, write to the Free Software
13813 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13817 + * File-based Hierarchy Storage Management
13820 +#include <linux/anon_inodes.h>
13821 +#include <linux/poll.h>
13822 +#include <linux/seq_file.h>
13823 +#include <linux/statfs.h>
13826 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13828 + struct au_sbinfo *sbinfo;
13829 + struct au_fhsm *fhsm;
13831 + SiMustAnyLock(sb);
13833 + sbinfo = au_sbi(sb);
13834 + fhsm = &sbinfo->si_fhsm;
13835 + AuDebugOn(!fhsm);
13836 + return fhsm->fhsm_bottom;
13839 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13841 + struct au_sbinfo *sbinfo;
13842 + struct au_fhsm *fhsm;
13844 + SiMustWriteLock(sb);
13846 + sbinfo = au_sbi(sb);
13847 + fhsm = &sbinfo->si_fhsm;
13848 + AuDebugOn(!fhsm);
13849 + fhsm->fhsm_bottom = bindex;
13852 +/* ---------------------------------------------------------------------- */
13854 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13856 + struct au_br_fhsm *bf;
13858 + bf = br->br_fhsm;
13859 + MtxMustLock(&bf->bf_lock);
13861 + return !bf->bf_readable
13862 + || time_after(jiffies,
13863 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13866 +/* ---------------------------------------------------------------------- */
13868 +static void au_fhsm_notify(struct super_block *sb, int val)
13870 + struct au_sbinfo *sbinfo;
13871 + struct au_fhsm *fhsm;
13873 + SiMustAnyLock(sb);
13875 + sbinfo = au_sbi(sb);
13876 + fhsm = &sbinfo->si_fhsm;
13877 + if (au_fhsm_pid(fhsm)
13878 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13879 + atomic_set(&fhsm->fhsm_readable, val);
13881 + wake_up(&fhsm->fhsm_wqh);
13885 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13886 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13889 + struct au_branch *br;
13890 + struct au_br_fhsm *bf;
13892 + br = au_sbr(sb, bindex);
13893 + AuDebugOn(au_br_rdonly(br));
13894 + bf = br->br_fhsm;
13898 + mutex_lock(&bf->bf_lock);
13900 + MtxMustLock(&bf->bf_lock);
13902 + /* sb->s_root for NFS is unreliable */
13903 + err = au_br_stfs(br, &bf->bf_stfs);
13904 + if (unlikely(err)) {
13905 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13909 + bf->bf_jiffy = jiffies;
13910 + bf->bf_readable = 1;
13912 + au_fhsm_notify(sb, /*val*/1);
13914 + *rstfs = bf->bf_stfs;
13918 + mutex_unlock(&bf->bf_lock);
13919 + au_fhsm_notify(sb, /*val*/1);
13924 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13927 + struct au_sbinfo *sbinfo;
13928 + struct au_fhsm *fhsm;
13929 + struct au_branch *br;
13930 + struct au_br_fhsm *bf;
13932 + AuDbg("b%d, force %d\n", bindex, force);
13933 + SiMustAnyLock(sb);
13935 + sbinfo = au_sbi(sb);
13936 + fhsm = &sbinfo->si_fhsm;
13937 + if (!au_ftest_si(sbinfo, FHSM)
13938 + || fhsm->fhsm_bottom == bindex)
13941 + br = au_sbr(sb, bindex);
13942 + bf = br->br_fhsm;
13944 + mutex_lock(&bf->bf_lock);
13946 + || au_fhsm_pid(fhsm)
13947 + || au_fhsm_test_jiffy(sbinfo, br))
13948 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13950 + mutex_unlock(&bf->bf_lock);
13953 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13955 + aufs_bindex_t bindex, bbot;
13956 + struct au_branch *br;
13958 + /* exclude the bottom */
13959 + bbot = au_fhsm_bottom(sb);
13960 + for (bindex = 0; bindex < bbot; bindex++) {
13961 + br = au_sbr(sb, bindex);
13962 + if (au_br_fhsm(br->br_perm))
13963 + au_fhsm_wrote(sb, bindex, force);
13967 +/* ---------------------------------------------------------------------- */
13969 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13972 + struct au_sbinfo *sbinfo;
13973 + struct au_fhsm *fhsm;
13976 + sbinfo = file->private_data;
13977 + fhsm = &sbinfo->si_fhsm;
13978 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13979 + if (atomic_read(&fhsm->fhsm_readable))
13980 + mask = EPOLLIN /* | EPOLLRDNORM */;
13983 + AuDbg("mask 0x%x\n", mask);
13987 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13988 + struct aufs_stfs *stfs, __s16 brid)
13992 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13994 + err = __put_user(brid, &stbr->brid);
13995 + if (unlikely(err))
14001 +static ssize_t au_fhsm_do_read(struct super_block *sb,
14002 + struct aufs_stbr __user *stbr, size_t count)
14006 + aufs_bindex_t bindex, bbot;
14007 + struct au_branch *br;
14008 + struct au_br_fhsm *bf;
14010 + /* except the bottom branch */
14013 + bbot = au_fhsm_bottom(sb);
14014 + for (bindex = 0; !err && bindex < bbot; bindex++) {
14015 + br = au_sbr(sb, bindex);
14016 + if (!au_br_fhsm(br->br_perm))
14019 + bf = br->br_fhsm;
14020 + mutex_lock(&bf->bf_lock);
14021 + if (bf->bf_readable) {
14023 + if (count >= sizeof(*stbr))
14024 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14027 + bf->bf_readable = 0;
14028 + count -= sizeof(*stbr);
14032 + mutex_unlock(&bf->bf_lock);
14035 + err = sizeof(*stbr) * nstbr;
14040 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14045 + aufs_bindex_t nfhsm, bindex, bbot;
14046 + struct au_sbinfo *sbinfo;
14047 + struct au_fhsm *fhsm;
14048 + struct au_branch *br;
14049 + struct super_block *sb;
14052 + sbinfo = file->private_data;
14053 + fhsm = &sbinfo->si_fhsm;
14055 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14056 + if (!atomic_read(&fhsm->fhsm_readable)) {
14057 + if (vfsub_file_flags(file) & O_NONBLOCK)
14060 + err = wait_event_interruptible_locked_irq
14062 + atomic_read(&fhsm->fhsm_readable));
14064 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14065 + if (unlikely(err))
14068 + /* sb may already be dead */
14069 + au_rw_read_lock(&sbinfo->si_rwsem);
14070 + readable = atomic_read(&fhsm->fhsm_readable);
14071 + if (readable > 0) {
14072 + sb = sbinfo->si_sb;
14074 + /* exclude the bottom branch */
14076 + bbot = au_fhsm_bottom(sb);
14077 + for (bindex = 0; bindex < bbot; bindex++) {
14078 + br = au_sbr(sb, bindex);
14079 + if (au_br_fhsm(br->br_perm))
14083 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14084 + atomic_set(&fhsm->fhsm_readable, 0);
14085 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14089 + au_rw_read_unlock(&sbinfo->si_rwsem);
14097 +static int au_fhsm_release(struct inode *inode, struct file *file)
14099 + struct au_sbinfo *sbinfo;
14100 + struct au_fhsm *fhsm;
14102 + /* sb may already be dead */
14103 + sbinfo = file->private_data;
14104 + fhsm = &sbinfo->si_fhsm;
14105 + spin_lock(&fhsm->fhsm_spin);
14106 + fhsm->fhsm_pid = 0;
14107 + spin_unlock(&fhsm->fhsm_spin);
14108 + kobject_put(&sbinfo->si_kobj);
14113 +static const struct file_operations au_fhsm_fops = {
14114 + .owner = THIS_MODULE,
14115 + .llseek = noop_llseek,
14116 + .read = au_fhsm_read,
14117 + .poll = au_fhsm_poll,
14118 + .release = au_fhsm_release
14121 +int au_fhsm_fd(struct super_block *sb, int oflags)
14124 + struct au_sbinfo *sbinfo;
14125 + struct au_fhsm *fhsm;
14128 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14132 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14136 + sbinfo = au_sbi(sb);
14137 + fhsm = &sbinfo->si_fhsm;
14138 + spin_lock(&fhsm->fhsm_spin);
14139 + if (!fhsm->fhsm_pid)
14140 + fhsm->fhsm_pid = current->pid;
14143 + spin_unlock(&fhsm->fhsm_spin);
14144 + if (unlikely(err))
14147 + oflags |= O_RDONLY;
14148 + /* oflags |= FMODE_NONOTIFY; */
14149 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14151 + if (unlikely(fd < 0))
14154 + /* succeed regardless 'fhsm' status */
14155 + kobject_get(&sbinfo->si_kobj);
14156 + si_noflush_read_lock(sb);
14157 + if (au_ftest_si(sbinfo, FHSM))
14158 + au_fhsm_wrote_all(sb, /*force*/0);
14159 + si_read_unlock(sb);
14160 + goto out; /* success */
14163 + spin_lock(&fhsm->fhsm_spin);
14164 + fhsm->fhsm_pid = 0;
14165 + spin_unlock(&fhsm->fhsm_spin);
14171 +/* ---------------------------------------------------------------------- */
14173 +int au_fhsm_br_alloc(struct au_branch *br)
14178 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14180 + au_br_fhsm_init(br->br_fhsm);
14187 +/* ---------------------------------------------------------------------- */
14189 +void au_fhsm_fin(struct super_block *sb)
14191 + au_fhsm_notify(sb, /*val*/-1);
14194 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14196 + struct au_fhsm *fhsm;
14198 + fhsm = &sbinfo->si_fhsm;
14199 + spin_lock_init(&fhsm->fhsm_spin);
14200 + init_waitqueue_head(&fhsm->fhsm_wqh);
14201 + atomic_set(&fhsm->fhsm_readable, 0);
14202 + fhsm->fhsm_expire
14203 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14204 + fhsm->fhsm_bottom = -1;
14207 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14209 + sbinfo->si_fhsm.fhsm_expire
14210 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14213 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14217 + if (!au_ftest_si(sbinfo, FHSM))
14220 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14221 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14222 + seq_printf(seq, ",fhsm_sec=%u", u);
14224 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14225 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14226 +++ linux/fs/aufs/file.c 2019-01-28 14:36:12.219084659 +0100
14228 +// SPDX-License-Identifier: GPL-2.0
14230 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14232 + * This program, aufs is free software; you can redistribute it and/or modify
14233 + * it under the terms of the GNU General Public License as published by
14234 + * the Free Software Foundation; either version 2 of the License, or
14235 + * (at your option) any later version.
14237 + * This program is distributed in the hope that it will be useful,
14238 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14240 + * GNU General Public License for more details.
14242 + * You should have received a copy of the GNU General Public License
14243 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14247 + * handling file/dir, and address_space operation
14250 +#ifdef CONFIG_AUFS_DEBUG
14251 +#include <linux/migrate.h>
14253 +#include <linux/pagemap.h>
14256 +/* drop flags for writing */
14257 +unsigned int au_file_roflags(unsigned int flags)
14259 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14260 + flags |= O_RDONLY | O_NOATIME;
14264 +/* common functions to regular file and dir */
14265 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14266 + struct file *file, int force_wr)
14268 + struct file *h_file;
14269 + struct dentry *h_dentry;
14270 + struct inode *h_inode;
14271 + struct super_block *sb;
14272 + struct au_branch *br;
14273 + struct path h_path;
14276 + /* a race condition can happen between open and unlink/rmdir */
14277 + h_file = ERR_PTR(-ENOENT);
14278 + h_dentry = au_h_dptr(dentry, bindex);
14279 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14281 + h_inode = d_inode(h_dentry);
14282 + spin_lock(&h_dentry->d_lock);
14283 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14284 + /* || !d_inode(dentry)->i_nlink */
14286 + spin_unlock(&h_dentry->d_lock);
14287 + if (unlikely(err))
14290 + sb = dentry->d_sb;
14291 + br = au_sbr(sb, bindex);
14292 + err = au_br_test_oflag(flags, br);
14293 + h_file = ERR_PTR(err);
14294 + if (unlikely(err))
14297 + /* drop flags for writing */
14298 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14299 + if (force_wr && !(flags & O_WRONLY))
14301 + flags = au_file_roflags(flags);
14303 + h_file = ERR_PTR(-EROFS);
14304 + flags = au_file_roflags(flags);
14305 + if (unlikely(vfsub_native_ro(h_inode)
14306 + || IS_APPEND(h_inode)))
14308 + flags &= ~O_ACCMODE;
14309 + flags |= O_WRONLY;
14312 + flags &= ~O_CREAT;
14313 + au_lcnt_inc(&br->br_nfiles);
14314 + h_path.dentry = h_dentry;
14315 + h_path.mnt = au_br_mnt(br);
14316 + h_file = vfsub_dentry_open(&h_path, flags);
14317 + if (IS_ERR(h_file))
14320 + if (flags & __FMODE_EXEC) {
14321 + err = deny_write_access(h_file);
14322 + if (unlikely(err)) {
14324 + h_file = ERR_PTR(err);
14328 + fsnotify_open(h_file);
14329 + goto out; /* success */
14332 + au_lcnt_dec(&br->br_nfiles);
14337 +static int au_cmoo(struct dentry *dentry)
14339 + int err, cmoo, matched;
14340 + unsigned int udba;
14341 + struct path h_path;
14342 + struct au_pin pin;
14343 + struct au_cp_generic cpg = {
14344 + .dentry = dentry,
14349 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14351 + struct inode *delegated;
14352 + struct super_block *sb;
14353 + struct au_sbinfo *sbinfo;
14354 + struct au_fhsm *fhsm;
14356 + struct au_branch *br;
14357 + struct dentry *parent;
14358 + struct au_hinode *hdir;
14360 + DiMustWriteLock(dentry);
14361 + IiMustWriteLock(d_inode(dentry));
14364 + if (IS_ROOT(dentry))
14366 + cpg.bsrc = au_dbtop(dentry);
14370 + sb = dentry->d_sb;
14371 + sbinfo = au_sbi(sb);
14372 + fhsm = &sbinfo->si_fhsm;
14373 + pid = au_fhsm_pid(fhsm);
14376 + && (current->pid == pid
14377 + || rcu_dereference(current->real_parent)->pid == pid));
14378 + rcu_read_unlock();
14382 + br = au_sbr(sb, cpg.bsrc);
14383 + cmoo = au_br_cmoo(br->br_perm);
14386 + if (!d_is_reg(dentry))
14387 + cmoo &= AuBrAttr_COO_ALL;
14391 + parent = dget_parent(dentry);
14392 + di_write_lock_parent(parent);
14393 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14395 + if (unlikely(err < 0)) {
14396 + err = 0; /* there is no upper writable branch */
14399 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14401 + /* do not respect the coo attrib for the target branch */
14402 + err = au_cpup_dirs(dentry, cpg.bdst);
14403 + if (unlikely(err))
14406 + di_downgrade_lock(parent, AuLock_IR);
14407 + udba = au_opt_udba(sb);
14408 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14409 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14410 + if (unlikely(err))
14413 + err = au_sio_cpup_simple(&cpg);
14415 + if (unlikely(err))
14417 + if (!(cmoo & AuBrWAttr_MOO))
14418 + goto out_parent; /* success */
14420 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14421 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14422 + if (unlikely(err))
14425 + h_path.mnt = au_br_mnt(br);
14426 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14427 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14428 + delegated = NULL;
14429 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14431 + /* todo: keep h_dentry or not? */
14432 + if (unlikely(err == -EWOULDBLOCK)) {
14433 + pr_warn("cannot retry for NFSv4 delegation"
14434 + " for an internal unlink\n");
14437 + if (unlikely(err)) {
14438 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14442 + goto out_parent; /* success */
14445 + di_downgrade_lock(parent, AuLock_IR);
14447 + di_read_unlock(parent, AuLock_IR);
14454 +int au_do_open(struct file *file, struct au_do_open_args *args)
14456 + int err, aopen = args->aopen;
14457 + struct dentry *dentry;
14458 + struct au_finfo *finfo;
14461 + err = au_finfo_init(file, args->fidir);
14464 + err = au_finfo_init(file, args->fidir);
14467 + if (unlikely(err))
14470 + dentry = file->f_path.dentry;
14471 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14472 + di_write_lock_child(dentry);
14473 + err = au_cmoo(dentry);
14474 + di_downgrade_lock(dentry, AuLock_IR);
14477 + err = args->open(file, vfsub_file_flags(file), NULL);
14480 + err = args->open(file, vfsub_file_flags(file),
14485 + di_read_unlock(dentry, AuLock_IR);
14487 + finfo = au_fi(file);
14489 + finfo->fi_file = file;
14490 + au_hbl_add(&finfo->fi_hlist,
14491 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14494 + fi_write_unlock(file);
14497 + fi_write_unlock(file);
14500 + if (unlikely(err)) {
14501 + finfo->fi_hdir = NULL;
14502 + au_finfo_fin(file);
14510 +int au_reopen_nondir(struct file *file)
14513 + aufs_bindex_t btop;
14514 + struct dentry *dentry;
14515 + struct au_branch *br;
14516 + struct file *h_file, *h_file_tmp;
14518 + dentry = file->f_path.dentry;
14519 + btop = au_dbtop(dentry);
14520 + br = au_sbr(dentry->d_sb, btop);
14521 + h_file_tmp = NULL;
14522 + if (au_fbtop(file) == btop) {
14523 + h_file = au_hf_top(file);
14524 + if (file->f_mode == h_file->f_mode)
14525 + return 0; /* success */
14526 + h_file_tmp = h_file;
14527 + get_file(h_file_tmp);
14528 + au_lcnt_inc(&br->br_nfiles);
14529 + au_set_h_fptr(file, btop, NULL);
14531 + AuDebugOn(au_fi(file)->fi_hdir);
14534 + * file exists on both of rw and ro
14535 + * open --> dbtop and fbtop are both 0
14536 + * prepend a branch as rw, "rw" become ro
14538 + * delete the top branch, "rw" becomes rw again
14539 + * --> dbtop is 1, fbtop is still 0
14540 + * write --> fbtop is 0 but dbtop is 1
14542 + /* AuDebugOn(au_fbtop(file) < btop); */
14544 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14545 + file, /*force_wr*/0);
14546 + err = PTR_ERR(h_file);
14547 + if (IS_ERR(h_file)) {
14548 + if (h_file_tmp) {
14550 + au_set_h_fptr(file, btop, h_file_tmp);
14551 + h_file_tmp = NULL;
14553 + goto out; /* todo: close all? */
14557 + au_set_fbtop(file, btop);
14558 + au_set_h_fptr(file, btop, h_file);
14559 + au_update_figen(file);
14560 + /* todo: necessary? */
14561 + /* file->f_ra = h_file->f_ra; */
14564 + if (h_file_tmp) {
14565 + fput(h_file_tmp);
14566 + au_lcnt_dec(&br->br_nfiles);
14571 +/* ---------------------------------------------------------------------- */
14573 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14574 + struct dentry *hi_wh)
14577 + aufs_bindex_t btop;
14578 + struct au_dinfo *dinfo;
14579 + struct dentry *h_dentry;
14580 + struct au_hdentry *hdp;
14582 + dinfo = au_di(file->f_path.dentry);
14583 + AuRwMustWriteLock(&dinfo->di_rwsem);
14585 + btop = dinfo->di_btop;
14586 + dinfo->di_btop = btgt;
14587 + hdp = au_hdentry(dinfo, btgt);
14588 + h_dentry = hdp->hd_dentry;
14589 + hdp->hd_dentry = hi_wh;
14590 + err = au_reopen_nondir(file);
14591 + hdp->hd_dentry = h_dentry;
14592 + dinfo->di_btop = btop;
14597 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14598 + aufs_bindex_t bcpup, struct au_pin *pin)
14601 + struct inode *inode, *h_inode;
14602 + struct dentry *h_dentry, *hi_wh;
14603 + struct au_cp_generic cpg = {
14604 + .dentry = file->f_path.dentry,
14611 + au_update_dbtop(cpg.dentry);
14612 + inode = d_inode(cpg.dentry);
14614 + if (au_dbtop(cpg.dentry) <= bcpup
14615 + && au_dbbot(cpg.dentry) >= bcpup) {
14616 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14617 + if (h_dentry && d_is_positive(h_dentry))
14618 + h_inode = d_inode(h_dentry);
14620 + hi_wh = au_hi_wh(inode, bcpup);
14621 + if (!hi_wh && !h_inode)
14622 + err = au_sio_cpup_wh(&cpg, file);
14624 + /* already copied-up after unlink */
14625 + err = au_reopen_wh(file, bcpup, hi_wh);
14628 + && (inode->i_nlink > 1
14629 + || (inode->i_state & I_LINKABLE))
14630 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14631 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14637 + * prepare the @file for writing.
14639 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14642 + aufs_bindex_t dbtop;
14643 + struct dentry *parent;
14644 + struct inode *inode;
14645 + struct super_block *sb;
14646 + struct file *h_file;
14647 + struct au_cp_generic cpg = {
14648 + .dentry = file->f_path.dentry,
14653 + .flags = AuCpup_DTIME
14656 + sb = cpg.dentry->d_sb;
14657 + inode = d_inode(cpg.dentry);
14658 + cpg.bsrc = au_fbtop(file);
14659 + err = au_test_ro(sb, cpg.bsrc, inode);
14660 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14661 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14666 + /* need to cpup or reopen */
14667 + parent = dget_parent(cpg.dentry);
14668 + di_write_lock_parent(parent);
14669 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14671 + if (unlikely(err < 0))
14675 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14676 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14677 + if (unlikely(err))
14681 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14682 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14683 + if (unlikely(err))
14686 + dbtop = au_dbtop(cpg.dentry);
14687 + if (dbtop <= cpg.bdst)
14688 + cpg.bsrc = cpg.bdst;
14690 + if (dbtop <= cpg.bdst /* just reopen */
14691 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14693 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14694 + if (IS_ERR(h_file))
14695 + err = PTR_ERR(h_file);
14697 + di_downgrade_lock(parent, AuLock_IR);
14698 + if (dbtop > cpg.bdst)
14699 + err = au_sio_cpup_simple(&cpg);
14701 + err = au_reopen_nondir(file);
14702 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14704 + } else { /* copyup as wh and reopen */
14706 + * since writable hfsplus branch is not supported,
14707 + * h_open_pre/post() are unnecessary.
14709 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14710 + di_downgrade_lock(parent, AuLock_IR);
14714 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14715 + goto out_dput; /* success */
14721 + di_downgrade_lock(parent, AuLock_IR);
14723 + di_read_unlock(parent, AuLock_IR);
14730 +/* ---------------------------------------------------------------------- */
14732 +int au_do_flush(struct file *file, fl_owner_t id,
14733 + int (*flush)(struct file *file, fl_owner_t id))
14736 + struct super_block *sb;
14737 + struct inode *inode;
14739 + inode = file_inode(file);
14740 + sb = inode->i_sb;
14741 + si_noflush_read_lock(sb);
14742 + fi_read_lock(file);
14743 + ii_read_lock_child(inode);
14745 + err = flush(file, id);
14746 + au_cpup_attr_timesizes(inode);
14748 + ii_read_unlock(inode);
14749 + fi_read_unlock(file);
14750 + si_read_unlock(sb);
14754 +/* ---------------------------------------------------------------------- */
14756 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14759 + struct au_pin pin;
14760 + struct au_finfo *finfo;
14761 + struct dentry *parent, *hi_wh;
14762 + struct inode *inode;
14763 + struct super_block *sb;
14764 + struct au_cp_generic cpg = {
14765 + .dentry = file->f_path.dentry,
14770 + .flags = AuCpup_DTIME
14773 + FiMustWriteLock(file);
14776 + finfo = au_fi(file);
14777 + sb = cpg.dentry->d_sb;
14778 + inode = d_inode(cpg.dentry);
14779 + cpg.bdst = au_ibtop(inode);
14780 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14783 + parent = dget_parent(cpg.dentry);
14784 + if (au_test_ro(sb, cpg.bdst, inode)) {
14785 + di_read_lock_parent(parent, !AuLock_IR);
14786 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14788 + di_read_unlock(parent, !AuLock_IR);
14789 + if (unlikely(err < 0))
14794 + di_read_lock_parent(parent, AuLock_IR);
14795 + hi_wh = au_hi_wh(inode, cpg.bdst);
14796 + if (!S_ISDIR(inode->i_mode)
14797 + && au_opt_test(au_mntflags(sb), PLINK)
14798 + && au_plink_test(inode)
14799 + && !d_unhashed(cpg.dentry)
14800 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14801 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14802 + if (unlikely(err))
14805 + /* always superio. */
14806 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14807 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14809 + err = au_sio_cpup_simple(&cpg);
14812 + } else if (hi_wh) {
14813 + /* already copied-up after unlink */
14814 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14815 + *need_reopen = 0;
14819 + di_read_unlock(parent, AuLock_IR);
14826 +static void au_do_refresh_dir(struct file *file)
14828 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14829 + struct au_hfile *p, tmp, *q;
14830 + struct au_finfo *finfo;
14831 + struct super_block *sb;
14832 + struct au_fidir *fidir;
14834 + FiMustWriteLock(file);
14836 + sb = file->f_path.dentry->d_sb;
14837 + finfo = au_fi(file);
14838 + fidir = finfo->fi_hdir;
14839 + AuDebugOn(!fidir);
14840 + p = fidir->fd_hfile + finfo->fi_btop;
14841 + brid = p->hf_br->br_id;
14842 + bbot = fidir->fd_bbot;
14843 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14847 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14848 + if (new_bindex == bindex)
14850 + if (new_bindex < 0) {
14851 + au_set_h_fptr(file, bindex, NULL);
14855 + /* swap two lower inode, and loop again */
14856 + q = fidir->fd_hfile + new_bindex;
14860 + if (tmp.hf_file) {
14866 + p = fidir->fd_hfile;
14867 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14868 + bbot = au_sbbot(sb);
14869 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14870 + finfo->fi_btop++, p++)
14871 + if (p->hf_file) {
14872 + if (file_inode(p->hf_file))
14874 + au_hfput(p, /*execed*/0);
14877 + bbot = au_br_index(sb, brid);
14878 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14879 + finfo->fi_btop++, p++)
14881 + au_hfput(p, /*execed*/0);
14882 + bbot = au_sbbot(sb);
14885 + p = fidir->fd_hfile + bbot;
14886 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14887 + fidir->fd_bbot--, p--)
14888 + if (p->hf_file) {
14889 + if (file_inode(p->hf_file))
14891 + au_hfput(p, /*execed*/0);
14893 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14897 + * after branch manipulating, refresh the file.
14899 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14901 + int err, need_reopen, nbr;
14902 + aufs_bindex_t bbot, bindex;
14903 + struct dentry *dentry;
14904 + struct super_block *sb;
14905 + struct au_finfo *finfo;
14906 + struct au_hfile *hfile;
14908 + dentry = file->f_path.dentry;
14909 + sb = dentry->d_sb;
14910 + nbr = au_sbbot(sb) + 1;
14911 + finfo = au_fi(file);
14912 + if (!finfo->fi_hdir) {
14913 + hfile = &finfo->fi_htop;
14914 + AuDebugOn(!hfile->hf_file);
14915 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14916 + AuDebugOn(bindex < 0);
14917 + if (bindex != finfo->fi_btop)
14918 + au_set_fbtop(file, bindex);
14920 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14921 + if (unlikely(err))
14923 + au_do_refresh_dir(file);
14928 + if (!au_test_mmapped(file))
14929 + err = au_file_refresh_by_inode(file, &need_reopen);
14930 + if (finfo->fi_hdir)
14931 + /* harmless if err */
14932 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14933 + if (!err && need_reopen && !d_unlinked(dentry))
14934 + err = reopen(file);
14936 + au_update_figen(file);
14937 + goto out; /* success */
14940 + /* error, close all lower files */
14941 + if (finfo->fi_hdir) {
14942 + bbot = au_fbbot_dir(file);
14943 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14944 + au_set_h_fptr(file, bindex, NULL);
14951 +/* common function to regular file and dir */
14952 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14953 + int wlock, unsigned int fi_lsc)
14956 + unsigned int sigen, figen;
14957 + aufs_bindex_t btop;
14958 + unsigned char pseudo_link;
14959 + struct dentry *dentry;
14960 + struct inode *inode;
14963 + dentry = file->f_path.dentry;
14964 + inode = d_inode(dentry);
14965 + sigen = au_sigen(dentry->d_sb);
14966 + fi_write_lock_nested(file, fi_lsc);
14967 + figen = au_figen(file);
14969 + di_write_lock_child(dentry);
14971 + di_write_lock_child2(dentry);
14972 + btop = au_dbtop(dentry);
14973 + pseudo_link = (btop != au_ibtop(inode));
14974 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14976 + di_downgrade_lock(dentry, AuLock_IR);
14977 + fi_downgrade_lock(file);
14979 + goto out; /* success */
14982 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14983 + if (au_digen_test(dentry, sigen)) {
14984 + err = au_reval_dpath(dentry, sigen);
14985 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14989 + err = refresh_file(file, reopen);
14992 + di_downgrade_lock(dentry, AuLock_IR);
14993 + fi_downgrade_lock(file);
14996 + di_write_unlock(dentry);
14997 + fi_write_unlock(file);
15004 +/* ---------------------------------------------------------------------- */
15006 +/* cf. aufs_nopage() */
15007 +/* for madvise(2) */
15008 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
15010 + unlock_page(page);
15014 +/* it will never be called, but necessary to support O_DIRECT */
15015 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
15016 +{ BUG(); return 0; }
15018 +/* they will never be called. */
15019 +#ifdef CONFIG_AUFS_DEBUG
15020 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
15021 + loff_t pos, unsigned len, unsigned flags,
15022 + struct page **pagep, void **fsdata)
15023 +{ AuUnsupport(); return 0; }
15024 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15025 + loff_t pos, unsigned len, unsigned copied,
15026 + struct page *page, void *fsdata)
15027 +{ AuUnsupport(); return 0; }
15028 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15029 +{ AuUnsupport(); return 0; }
15031 +static int aufs_set_page_dirty(struct page *page)
15032 +{ AuUnsupport(); return 0; }
15033 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15034 + unsigned int length)
15035 +{ AuUnsupport(); }
15036 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15037 +{ AuUnsupport(); return 0; }
15038 +#if 0 /* called by memory compaction regardless file */
15039 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15040 + struct page *page, enum migrate_mode mode)
15041 +{ AuUnsupport(); return 0; }
15043 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15044 +{ AuUnsupport(); return true; }
15045 +static void aufs_putback_page(struct page *page)
15046 +{ AuUnsupport(); }
15047 +static int aufs_launder_page(struct page *page)
15048 +{ AuUnsupport(); return 0; }
15049 +static int aufs_is_partially_uptodate(struct page *page,
15050 + unsigned long from,
15051 + unsigned long count)
15052 +{ AuUnsupport(); return 0; }
15053 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15055 +{ AuUnsupport(); }
15056 +static int aufs_error_remove_page(struct address_space *mapping,
15057 + struct page *page)
15058 +{ AuUnsupport(); return 0; }
15059 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15061 +{ AuUnsupport(); return 0; }
15062 +static void aufs_swap_deactivate(struct file *file)
15063 +{ AuUnsupport(); }
15064 +#endif /* CONFIG_AUFS_DEBUG */
15066 +const struct address_space_operations aufs_aop = {
15067 + .readpage = aufs_readpage,
15068 + .direct_IO = aufs_direct_IO,
15069 +#ifdef CONFIG_AUFS_DEBUG
15070 + .writepage = aufs_writepage,
15071 + /* no writepages, because of writepage */
15072 + .set_page_dirty = aufs_set_page_dirty,
15073 + /* no readpages, because of readpage */
15074 + .write_begin = aufs_write_begin,
15075 + .write_end = aufs_write_end,
15076 + /* no bmap, no block device */
15077 + .invalidatepage = aufs_invalidatepage,
15078 + .releasepage = aufs_releasepage,
15079 + /* is fallback_migrate_page ok? */
15080 + /* .migratepage = aufs_migratepage, */
15081 + .isolate_page = aufs_isolate_page,
15082 + .putback_page = aufs_putback_page,
15083 + .launder_page = aufs_launder_page,
15084 + .is_partially_uptodate = aufs_is_partially_uptodate,
15085 + .is_dirty_writeback = aufs_is_dirty_writeback,
15086 + .error_remove_page = aufs_error_remove_page,
15087 + .swap_activate = aufs_swap_activate,
15088 + .swap_deactivate = aufs_swap_deactivate
15089 +#endif /* CONFIG_AUFS_DEBUG */
15091 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15092 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15093 +++ linux/fs/aufs/file.h 2019-01-28 14:36:12.219084659 +0100
15095 +/* SPDX-License-Identifier: GPL-2.0 */
15097 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15099 + * This program, aufs is free software; you can redistribute it and/or modify
15100 + * it under the terms of the GNU General Public License as published by
15101 + * the Free Software Foundation; either version 2 of the License, or
15102 + * (at your option) any later version.
15104 + * This program is distributed in the hope that it will be useful,
15105 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15106 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15107 + * GNU General Public License for more details.
15109 + * You should have received a copy of the GNU General Public License
15110 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15114 + * file operations
15117 +#ifndef __AUFS_FILE_H__
15118 +#define __AUFS_FILE_H__
15122 +#include <linux/file.h>
15123 +#include <linux/fs.h>
15124 +#include <linux/mm_types.h>
15125 +#include <linux/poll.h>
15126 +#include "rwsem.h"
15130 + struct file *hf_file;
15131 + struct au_branch *hf_br;
15136 + aufs_bindex_t fd_bbot;
15137 + aufs_bindex_t fd_nent;
15138 + struct au_vdir *fd_vdir_cache;
15139 + struct au_hfile fd_hfile[];
15142 +static inline int au_fidir_sz(int nent)
15144 + AuDebugOn(nent < 0);
15145 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15149 + atomic_t fi_generation;
15151 + struct au_rwsem fi_rwsem;
15152 + aufs_bindex_t fi_btop;
15154 + /* do not union them */
15155 + struct { /* for non-dir */
15156 + struct au_hfile fi_htop;
15157 + atomic_t fi_mmapped;
15159 + struct au_fidir *fi_hdir; /* for dir only */
15161 + struct hlist_bl_node fi_hlist;
15162 + struct file *fi_file; /* very ugly */
15163 + struct rcu_head rcu;
15164 +} ____cacheline_aligned_in_smp;
15166 +/* ---------------------------------------------------------------------- */
15169 +extern const struct address_space_operations aufs_aop;
15170 +unsigned int au_file_roflags(unsigned int flags);
15171 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15172 + struct file *file, int force_wr);
15173 +struct au_do_open_args {
15175 + int (*open)(struct file *file, int flags,
15176 + struct file *h_file);
15177 + struct au_fidir *fidir;
15178 + struct file *h_file;
15180 +int au_do_open(struct file *file, struct au_do_open_args *args);
15181 +int au_reopen_nondir(struct file *file);
15183 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15184 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15185 + int wlock, unsigned int fi_lsc);
15186 +int au_do_flush(struct file *file, fl_owner_t id,
15187 + int (*flush)(struct file *file, fl_owner_t id));
15190 +#ifdef CONFIG_AUFS_POLL
15191 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15194 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15196 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15198 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15199 + struct file *h_file);
15201 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15202 + aufs_bindex_t bindex, int force_wr)
15203 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15204 + struct file *h_file);
15208 +extern const struct file_operations aufs_file_fop;
15209 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15210 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15211 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15214 +void au_hfput(struct au_hfile *hf, int execed);
15215 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15216 + struct file *h_file);
15218 +void au_update_figen(struct file *file);
15219 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15220 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15222 +void au_fi_init_once(void *_fi);
15223 +void au_finfo_fin(struct file *file);
15224 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15227 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15228 +#ifdef CONFIG_COMPAT
15229 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15230 + unsigned long arg);
15231 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15232 + unsigned long arg);
15235 +/* ---------------------------------------------------------------------- */
15237 +static inline struct au_finfo *au_fi(struct file *file)
15239 + return file->private_data;
15242 +/* ---------------------------------------------------------------------- */
15244 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15245 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15246 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15247 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15249 +#define fi_read_trylock_nested(f) \
15250 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15251 +#define fi_write_trylock_nested(f) \
15252 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15255 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15256 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15257 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15259 +/* lock subclass for finfo */
15265 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15267 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15270 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15272 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15276 + * fi_read_lock_1, fi_write_lock_1,
15277 + * fi_read_lock_2, fi_write_lock_2
15279 +#define AuReadLockFunc(name) \
15280 +static inline void fi_read_lock_##name(struct file *f) \
15281 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15283 +#define AuWriteLockFunc(name) \
15284 +static inline void fi_write_lock_##name(struct file *f) \
15285 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15287 +#define AuRWLockFuncs(name) \
15288 + AuReadLockFunc(name) \
15289 + AuWriteLockFunc(name)
15294 +#undef AuReadLockFunc
15295 +#undef AuWriteLockFunc
15296 +#undef AuRWLockFuncs
15298 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15299 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15300 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15302 +/* ---------------------------------------------------------------------- */
15304 +/* todo: hard/soft set? */
15305 +static inline aufs_bindex_t au_fbtop(struct file *file)
15307 + FiMustAnyLock(file);
15308 + return au_fi(file)->fi_btop;
15311 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15313 + FiMustAnyLock(file);
15314 + AuDebugOn(!au_fi(file)->fi_hdir);
15315 + return au_fi(file)->fi_hdir->fd_bbot;
15318 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15320 + FiMustAnyLock(file);
15321 + AuDebugOn(!au_fi(file)->fi_hdir);
15322 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15325 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15327 + FiMustWriteLock(file);
15328 + au_fi(file)->fi_btop = bindex;
15331 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15333 + FiMustWriteLock(file);
15334 + AuDebugOn(!au_fi(file)->fi_hdir);
15335 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15338 +static inline void au_set_fvdir_cache(struct file *file,
15339 + struct au_vdir *vdir_cache)
15341 + FiMustWriteLock(file);
15342 + AuDebugOn(!au_fi(file)->fi_hdir);
15343 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15346 +static inline struct file *au_hf_top(struct file *file)
15348 + FiMustAnyLock(file);
15349 + AuDebugOn(au_fi(file)->fi_hdir);
15350 + return au_fi(file)->fi_htop.hf_file;
15353 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15355 + FiMustAnyLock(file);
15356 + AuDebugOn(!au_fi(file)->fi_hdir);
15357 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15360 +/* todo: memory barrier? */
15361 +static inline unsigned int au_figen(struct file *f)
15363 + return atomic_read(&au_fi(f)->fi_generation);
15366 +static inline void au_set_mmapped(struct file *f)
15368 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15370 + pr_warn("fi_mmapped wrapped around\n");
15371 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15375 +static inline void au_unset_mmapped(struct file *f)
15377 + atomic_dec(&au_fi(f)->fi_mmapped);
15380 +static inline int au_test_mmapped(struct file *f)
15382 + return atomic_read(&au_fi(f)->fi_mmapped);
15385 +/* customize vma->vm_file */
15387 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15388 + struct file *file)
15392 + f = vma->vm_file;
15394 + vma->vm_file = file;
15399 +#define AuDbgVmRegion(file, vma) do {} while (0)
15401 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15402 + struct file *file)
15404 + au_do_vm_file_reset(vma, file);
15407 +#define AuDbgVmRegion(file, vma) \
15408 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15410 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15411 + struct file *file)
15415 + au_do_vm_file_reset(vma, file);
15416 + f = vma->vm_region->vm_file;
15418 + vma->vm_region->vm_file = file;
15421 +#endif /* CONFIG_MMU */
15423 +/* handle vma->vm_prfile */
15424 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15425 + struct file *file)
15428 + vma->vm_prfile = file;
15429 +#ifndef CONFIG_MMU
15431 + vma->vm_region->vm_prfile = file;
15435 +#endif /* __KERNEL__ */
15436 +#endif /* __AUFS_FILE_H__ */
15437 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15438 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15439 +++ linux/fs/aufs/finfo.c 2019-01-28 14:36:12.219084659 +0100
15441 +// SPDX-License-Identifier: GPL-2.0
15443 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15445 + * This program, aufs is free software; you can redistribute it and/or modify
15446 + * it under the terms of the GNU General Public License as published by
15447 + * the Free Software Foundation; either version 2 of the License, or
15448 + * (at your option) any later version.
15450 + * This program is distributed in the hope that it will be useful,
15451 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15452 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15453 + * GNU General Public License for more details.
15455 + * You should have received a copy of the GNU General Public License
15456 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15460 + * file private data
15465 +void au_hfput(struct au_hfile *hf, int execed)
15468 + allow_write_access(hf->hf_file);
15469 + fput(hf->hf_file);
15470 + hf->hf_file = NULL;
15471 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15472 + hf->hf_br = NULL;
15475 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15477 + struct au_finfo *finfo = au_fi(file);
15478 + struct au_hfile *hf;
15479 + struct au_fidir *fidir;
15481 + fidir = finfo->fi_hdir;
15483 + AuDebugOn(finfo->fi_btop != bindex);
15484 + hf = &finfo->fi_htop;
15486 + hf = fidir->fd_hfile + bindex;
15488 + if (hf && hf->hf_file)
15489 + au_hfput(hf, vfsub_file_execed(file));
15491 + FiMustWriteLock(file);
15492 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15493 + hf->hf_file = val;
15494 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15498 +void au_update_figen(struct file *file)
15500 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15501 + /* smp_mb(); */ /* atomic_set */
15504 +/* ---------------------------------------------------------------------- */
15506 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15508 + struct au_fidir *fidir;
15511 + nbr = au_sbbot(sb) + 1;
15513 + nbr = 2; /* initial allocate for 2 branches */
15514 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15516 + fidir->fd_bbot = -1;
15517 + fidir->fd_nent = nbr;
15523 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15526 + struct au_fidir *fidir, *p;
15528 + AuRwMustWriteLock(&finfo->fi_rwsem);
15529 + fidir = finfo->fi_hdir;
15530 + AuDebugOn(!fidir);
15533 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15534 + GFP_NOFS, may_shrink);
15536 + p->fd_nent = nbr;
15537 + finfo->fi_hdir = p;
15544 +/* ---------------------------------------------------------------------- */
15546 +void au_finfo_fin(struct file *file)
15548 + struct au_finfo *finfo;
15550 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15552 + finfo = au_fi(file);
15553 + AuDebugOn(finfo->fi_hdir);
15554 + AuRwDestroy(&finfo->fi_rwsem);
15555 + au_cache_free_finfo(finfo);
15558 +void au_fi_init_once(void *_finfo)
15560 + struct au_finfo *finfo = _finfo;
15562 + au_rw_init(&finfo->fi_rwsem);
15565 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15568 + struct au_finfo *finfo;
15569 + struct dentry *dentry;
15572 + dentry = file->f_path.dentry;
15573 + finfo = au_cache_alloc_finfo();
15574 + if (unlikely(!finfo))
15578 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15579 + au_rw_write_lock(&finfo->fi_rwsem);
15580 + finfo->fi_btop = -1;
15581 + finfo->fi_hdir = fidir;
15582 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15583 + /* smp_mb(); */ /* atomic_set */
15585 + file->private_data = finfo;
15590 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15591 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15592 +++ linux/fs/aufs/f_op.c 2019-01-28 14:36:12.219084659 +0100
15594 +// SPDX-License-Identifier: GPL-2.0
15596 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15598 + * This program, aufs is free software; you can redistribute it and/or modify
15599 + * it under the terms of the GNU General Public License as published by
15600 + * the Free Software Foundation; either version 2 of the License, or
15601 + * (at your option) any later version.
15603 + * This program is distributed in the hope that it will be useful,
15604 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15605 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15606 + * GNU General Public License for more details.
15608 + * You should have received a copy of the GNU General Public License
15609 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15613 + * file and vm operations
15616 +#include <linux/aio.h>
15617 +#include <linux/fs_stack.h>
15618 +#include <linux/mman.h>
15619 +#include <linux/security.h>
15622 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15625 + aufs_bindex_t bindex;
15626 + struct dentry *dentry, *h_dentry;
15627 + struct au_finfo *finfo;
15628 + struct inode *h_inode;
15630 + FiMustWriteLock(file);
15633 + dentry = file->f_path.dentry;
15634 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15635 + finfo = au_fi(file);
15636 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15637 + atomic_set(&finfo->fi_mmapped, 0);
15638 + bindex = au_dbtop(dentry);
15640 + h_dentry = au_h_dptr(dentry, bindex);
15641 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15642 + if (unlikely(err))
15644 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15645 + if (IS_ERR(h_file)) {
15646 + err = PTR_ERR(h_file);
15650 + h_dentry = h_file->f_path.dentry;
15651 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15652 + if (unlikely(err))
15654 + /* br ref is already inc-ed */
15657 + if ((flags & __O_TMPFILE)
15658 + && !(flags & O_EXCL)) {
15659 + h_inode = file_inode(h_file);
15660 + spin_lock(&h_inode->i_lock);
15661 + h_inode->i_state |= I_LINKABLE;
15662 + spin_unlock(&h_inode->i_lock);
15664 + au_set_fbtop(file, bindex);
15665 + au_set_h_fptr(file, bindex, h_file);
15666 + au_update_figen(file);
15667 + /* todo: necessary? */
15668 + /* file->f_ra = h_file->f_ra; */
15674 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15675 + struct file *file)
15678 + struct super_block *sb;
15679 + struct au_do_open_args args = {
15680 + .open = au_do_open_nondir
15683 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15684 + file, vfsub_file_flags(file), file->f_mode);
15686 + sb = file->f_path.dentry->d_sb;
15687 + si_read_lock(sb, AuLock_FLUSH);
15688 + err = au_do_open(file, &args);
15689 + si_read_unlock(sb);
15693 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15695 + struct au_finfo *finfo;
15696 + aufs_bindex_t bindex;
15698 + finfo = au_fi(file);
15699 + au_hbl_del(&finfo->fi_hlist,
15700 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15701 + bindex = finfo->fi_btop;
15703 + au_set_h_fptr(file, bindex, NULL);
15705 + au_finfo_fin(file);
15709 +/* ---------------------------------------------------------------------- */
15711 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15714 + struct file *h_file;
15717 + h_file = au_hf_top(file);
15719 + err = vfsub_flush(h_file, id);
15723 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15725 + return au_do_flush(file, id, au_do_flush_nondir);
15728 +/* ---------------------------------------------------------------------- */
15730 + * read and write functions acquire [fdi]_rwsem once, but release before
15731 + * mmap_sem. This is because to stop a race condition between mmap(2).
15732 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15733 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15734 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15737 +/* Callers should call au_read_post() or fput() in the end */
15738 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15740 + struct file *h_file;
15743 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15745 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15746 + h_file = au_hf_top(file);
15747 + get_file(h_file);
15749 + fi_read_unlock(file);
15751 + h_file = ERR_PTR(err);
15756 +static void au_read_post(struct inode *inode, struct file *h_file)
15758 + /* update without lock, I don't think it a problem */
15759 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15763 +struct au_write_pre {
15765 + unsigned int lsc;
15769 + aufs_bindex_t btop;
15773 + * return with iinfo is write-locked
15774 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15777 +static struct file *au_write_pre(struct file *file, int do_ready,
15778 + struct au_write_pre *wpre)
15780 + struct file *h_file;
15781 + struct dentry *dentry;
15783 + unsigned int lsc;
15784 + struct au_pin pin;
15789 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15790 + h_file = ERR_PTR(err);
15791 + if (unlikely(err))
15794 + dentry = file->f_path.dentry;
15796 + err = au_ready_to_write(file, -1, &pin);
15797 + if (unlikely(err)) {
15798 + h_file = ERR_PTR(err);
15799 + di_write_unlock(dentry);
15804 + di_downgrade_lock(dentry, /*flags*/0);
15806 + wpre->btop = au_fbtop(file);
15807 + h_file = au_hf_top(file);
15808 + get_file(h_file);
15810 + wpre->blks = file_inode(h_file)->i_blocks;
15813 + di_read_unlock(dentry, /*flags*/0);
15816 + fi_write_unlock(file);
15821 +static void au_write_post(struct inode *inode, struct file *h_file,
15822 + struct au_write_pre *wpre, ssize_t written)
15824 + struct inode *h_inode;
15826 + au_cpup_attr_timesizes(inode);
15827 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15828 + h_inode = file_inode(h_file);
15829 + inode->i_mode = h_inode->i_mode;
15830 + ii_write_unlock(inode);
15831 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15833 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15834 + /*force*/h_inode->i_blocks > wpre->blks);
15838 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15842 + struct inode *inode;
15843 + struct file *h_file;
15844 + struct super_block *sb;
15846 + inode = file_inode(file);
15847 + sb = inode->i_sb;
15848 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15850 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15851 + err = PTR_ERR(h_file);
15852 + if (IS_ERR(h_file))
15855 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15856 + err = vfsub_read_u(h_file, buf, count, ppos);
15857 + /* todo: necessary? */
15858 + /* file->f_ra = h_file->f_ra; */
15859 + au_read_post(inode, h_file);
15862 + si_read_unlock(sb);
15867 + * todo: very ugly
15868 + * it locks both of i_mutex and si_rwsem for read in safe.
15869 + * if the plink maintenance mode continues forever (that is the problem),
15870 + * may loop forever.
15872 +static void au_mtx_and_read_lock(struct inode *inode)
15875 + struct super_block *sb = inode->i_sb;
15878 + inode_lock(inode);
15879 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15882 + inode_unlock(inode);
15883 + si_read_lock(sb, AuLock_NOPLMW);
15884 + si_read_unlock(sb);
15888 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15889 + size_t count, loff_t *ppos)
15892 + struct au_write_pre wpre;
15893 + struct inode *inode;
15894 + struct file *h_file;
15895 + char __user *buf = (char __user *)ubuf;
15897 + inode = file_inode(file);
15898 + au_mtx_and_read_lock(inode);
15901 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15902 + err = PTR_ERR(h_file);
15903 + if (IS_ERR(h_file))
15906 + err = vfsub_write_u(h_file, buf, count, ppos);
15907 + au_write_post(inode, h_file, &wpre, err);
15910 + si_read_unlock(inode->i_sb);
15911 + inode_unlock(inode);
15915 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15916 + struct iov_iter *iov_iter)
15919 + struct file *file;
15920 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15922 + err = security_file_permission(h_file, rw);
15923 + if (unlikely(err))
15928 + if (rw == MAY_READ)
15929 + iter = h_file->f_op->read_iter;
15930 + else if (rw == MAY_WRITE)
15931 + iter = h_file->f_op->write_iter;
15933 + file = kio->ki_filp;
15934 + kio->ki_filp = h_file;
15937 + err = iter(kio, iov_iter);
15940 + /* currently there is no such fs */
15942 + kio->ki_filp = file;
15948 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15951 + struct file *file, *h_file;
15952 + struct inode *inode;
15953 + struct super_block *sb;
15955 + file = kio->ki_filp;
15956 + inode = file_inode(file);
15957 + sb = inode->i_sb;
15958 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15960 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15961 + err = PTR_ERR(h_file);
15962 + if (IS_ERR(h_file))
15965 + if (au_test_loopback_kthread()) {
15966 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15967 + if (file->f_mapping != h_file->f_mapping) {
15968 + file->f_mapping = h_file->f_mapping;
15969 + smp_mb(); /* unnecessary? */
15972 + fi_read_unlock(file);
15974 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15975 + /* todo: necessary? */
15976 + /* file->f_ra = h_file->f_ra; */
15977 + au_read_post(inode, h_file);
15980 + si_read_unlock(sb);
15984 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15987 + struct au_write_pre wpre;
15988 + struct inode *inode;
15989 + struct file *file, *h_file;
15991 + file = kio->ki_filp;
15992 + inode = file_inode(file);
15993 + au_mtx_and_read_lock(inode);
15996 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15997 + err = PTR_ERR(h_file);
15998 + if (IS_ERR(h_file))
16001 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
16002 + au_write_post(inode, h_file, &wpre, err);
16005 + si_read_unlock(inode->i_sb);
16006 + inode_unlock(inode);
16010 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
16011 + struct pipe_inode_info *pipe, size_t len,
16012 + unsigned int flags)
16015 + struct file *h_file;
16016 + struct inode *inode;
16017 + struct super_block *sb;
16019 + inode = file_inode(file);
16020 + sb = inode->i_sb;
16021 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16023 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16024 + err = PTR_ERR(h_file);
16025 + if (IS_ERR(h_file))
16028 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16029 + /* todo: necessary? */
16030 + /* file->f_ra = h_file->f_ra; */
16031 + au_read_post(inode, h_file);
16034 + si_read_unlock(sb);
16039 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16040 + size_t len, unsigned int flags)
16043 + struct au_write_pre wpre;
16044 + struct inode *inode;
16045 + struct file *h_file;
16047 + inode = file_inode(file);
16048 + au_mtx_and_read_lock(inode);
16051 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16052 + err = PTR_ERR(h_file);
16053 + if (IS_ERR(h_file))
16056 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16057 + au_write_post(inode, h_file, &wpre, err);
16060 + si_read_unlock(inode->i_sb);
16061 + inode_unlock(inode);
16065 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16069 + struct au_write_pre wpre;
16070 + struct inode *inode;
16071 + struct file *h_file;
16073 + inode = file_inode(file);
16074 + au_mtx_and_read_lock(inode);
16077 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16078 + err = PTR_ERR(h_file);
16079 + if (IS_ERR(h_file))
16083 + err = vfs_fallocate(h_file, mode, offset, len);
16085 + au_write_post(inode, h_file, &wpre, /*written*/1);
16088 + si_read_unlock(inode->i_sb);
16089 + inode_unlock(inode);
16093 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16094 + struct file *dst, loff_t dst_pos,
16095 + size_t len, unsigned int flags)
16098 + struct au_write_pre wpre;
16099 + enum { SRC, DST };
16101 + struct inode *inode;
16102 + struct file *h_file;
16103 + struct super_block *h_sb;
16105 +#define a_src a[SRC]
16106 +#define a_dst a[DST]
16109 + a_src.inode = file_inode(src);
16110 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16112 + a_dst.inode = file_inode(dst);
16113 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16116 + au_mtx_and_read_lock(a_dst.inode);
16118 + * in order to match the order in di_write_lock2_{child,parent}(),
16119 + * use f_path.dentry for this comparison.
16121 + if (src->f_path.dentry < dst->f_path.dentry) {
16122 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16123 + err = PTR_ERR(a_src.h_file);
16124 + if (IS_ERR(a_src.h_file))
16127 + wpre.lsc = AuLsc_FI_2;
16128 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16129 + err = PTR_ERR(a_dst.h_file);
16130 + if (IS_ERR(a_dst.h_file)) {
16131 + au_read_post(a_src.inode, a_src.h_file);
16135 + wpre.lsc = AuLsc_FI_1;
16136 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16137 + err = PTR_ERR(a_dst.h_file);
16138 + if (IS_ERR(a_dst.h_file))
16141 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16142 + err = PTR_ERR(a_src.h_file);
16143 + if (IS_ERR(a_src.h_file)) {
16144 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16151 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16152 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16153 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16159 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16160 + dst_pos, len, flags);
16163 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16164 + fi_read_unlock(src);
16165 + au_read_post(a_src.inode, a_src.h_file);
16167 + si_read_unlock(a_dst.inode->i_sb);
16168 + inode_unlock(a_dst.inode);
16175 +/* ---------------------------------------------------------------------- */
16178 + * The locking order around current->mmap_sem.
16179 + * - in most and regular cases
16180 + * file I/O syscall -- aufs_read() or something
16181 + * -- si_rwsem for read -- mmap_sem
16182 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16184 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16185 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16186 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16187 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16188 + * It means that when aufs acquires si_rwsem for write, the process should never
16189 + * acquire mmap_sem.
16191 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16192 + * problem either since any directory is not able to be mmap-ed.
16193 + * The similar scenario is applied to aufs_readlink() too.
16196 +#if 0 /* stop calling security_file_mmap() */
16197 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16198 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16200 +static unsigned long au_arch_prot_conv(unsigned long flags)
16202 + /* currently ppc64 only */
16203 +#ifdef CONFIG_PPC64
16204 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16205 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16206 + return AuConv_VM_PROT(flags, SAO);
16208 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16213 +static unsigned long au_prot_conv(unsigned long flags)
16215 + return AuConv_VM_PROT(flags, READ)
16216 + | AuConv_VM_PROT(flags, WRITE)
16217 + | AuConv_VM_PROT(flags, EXEC)
16218 + | au_arch_prot_conv(flags);
16221 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16222 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16224 +static unsigned long au_flag_conv(unsigned long flags)
16226 + return AuConv_VM_MAP(flags, GROWSDOWN)
16227 + | AuConv_VM_MAP(flags, DENYWRITE)
16228 + | AuConv_VM_MAP(flags, LOCKED);
16232 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16235 + const unsigned char wlock
16236 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16237 + struct super_block *sb;
16238 + struct file *h_file;
16239 + struct inode *inode;
16241 + AuDbgVmRegion(file, vma);
16243 + inode = file_inode(file);
16244 + sb = inode->i_sb;
16246 + si_read_lock(sb, AuLock_NOPLMW);
16248 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16250 + err = PTR_ERR(h_file);
16251 + if (IS_ERR(h_file))
16255 + au_set_mmapped(file);
16256 + au_vm_file_reset(vma, h_file);
16258 + * we cannot call security_mmap_file() here since it may acquire
16259 + * mmap_sem or i_mutex.
16261 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16262 + * au_flag_conv(vma->vm_flags));
16265 + err = call_mmap(h_file, vma);
16267 + au_vm_prfile_set(vma, file);
16268 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16269 + goto out_fput; /* success */
16271 + au_unset_mmapped(file);
16272 + au_vm_file_reset(vma, file);
16276 + ii_write_unlock(inode);
16281 + si_read_unlock(sb);
16287 +/* ---------------------------------------------------------------------- */
16289 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16293 + struct au_write_pre wpre;
16294 + struct inode *inode;
16295 + struct file *h_file;
16297 + err = 0; /* -EBADF; */ /* posix? */
16298 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16301 + inode = file_inode(file);
16302 + au_mtx_and_read_lock(inode);
16305 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16306 + err = PTR_ERR(h_file);
16307 + if (IS_ERR(h_file))
16310 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16311 + au_write_post(inode, h_file, &wpre, /*written*/0);
16314 + si_read_unlock(inode->i_sb);
16315 + inode_unlock(inode);
16320 +static int aufs_fasync(int fd, struct file *file, int flag)
16323 + struct file *h_file;
16324 + struct super_block *sb;
16326 + sb = file->f_path.dentry->d_sb;
16327 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16329 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16330 + err = PTR_ERR(h_file);
16331 + if (IS_ERR(h_file))
16334 + if (h_file->f_op->fasync)
16335 + err = h_file->f_op->fasync(fd, h_file, flag);
16336 + fput(h_file); /* instead of au_read_post() */
16339 + si_read_unlock(sb);
16343 +static int aufs_setfl(struct file *file, unsigned long arg)
16346 + struct file *h_file;
16347 + struct super_block *sb;
16349 + sb = file->f_path.dentry->d_sb;
16350 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16352 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16353 + err = PTR_ERR(h_file);
16354 + if (IS_ERR(h_file))
16357 + /* stop calling h_file->fasync */
16358 + arg |= vfsub_file_flags(file) & FASYNC;
16359 + err = setfl(/*unused fd*/-1, h_file, arg);
16360 + fput(h_file); /* instead of au_read_post() */
16363 + si_read_unlock(sb);
16367 +/* ---------------------------------------------------------------------- */
16369 +/* no one supports this operation, currently */
16371 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16372 + size_t len, loff_t *pos, int more)
16377 +/* ---------------------------------------------------------------------- */
16379 +const struct file_operations aufs_file_fop = {
16380 + .owner = THIS_MODULE,
16382 + .llseek = default_llseek,
16384 + .read = aufs_read,
16385 + .write = aufs_write,
16386 + .read_iter = aufs_read_iter,
16387 + .write_iter = aufs_write_iter,
16389 +#ifdef CONFIG_AUFS_POLL
16390 + .poll = aufs_poll,
16392 + .unlocked_ioctl = aufs_ioctl_nondir,
16393 +#ifdef CONFIG_COMPAT
16394 + .compat_ioctl = aufs_compat_ioctl_nondir,
16396 + .mmap = aufs_mmap,
16397 + .open = aufs_open_nondir,
16398 + .flush = aufs_flush_nondir,
16399 + .release = aufs_release_nondir,
16400 + .fsync = aufs_fsync_nondir,
16401 + .fasync = aufs_fasync,
16402 + /* .sendpage = aufs_sendpage, */
16403 + .setfl = aufs_setfl,
16404 + .splice_write = aufs_splice_write,
16405 + .splice_read = aufs_splice_read,
16407 + .aio_splice_write = aufs_aio_splice_write,
16408 + .aio_splice_read = aufs_aio_splice_read,
16410 + .fallocate = aufs_fallocate,
16411 + .copy_file_range = aufs_copy_file_range
16413 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16414 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16415 +++ linux/fs/aufs/fstype.h 2019-01-28 14:36:12.219084659 +0100
16417 +/* SPDX-License-Identifier: GPL-2.0 */
16419 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16421 + * This program, aufs is free software; you can redistribute it and/or modify
16422 + * it under the terms of the GNU General Public License as published by
16423 + * the Free Software Foundation; either version 2 of the License, or
16424 + * (at your option) any later version.
16426 + * This program is distributed in the hope that it will be useful,
16427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16429 + * GNU General Public License for more details.
16431 + * You should have received a copy of the GNU General Public License
16432 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16436 + * judging filesystem type
16439 +#ifndef __AUFS_FSTYPE_H__
16440 +#define __AUFS_FSTYPE_H__
16444 +#include <linux/fs.h>
16445 +#include <linux/magic.h>
16446 +#include <linux/nfs_fs.h>
16447 +#include <linux/romfs_fs.h>
16449 +static inline int au_test_aufs(struct super_block *sb)
16451 + return sb->s_magic == AUFS_SUPER_MAGIC;
16454 +static inline const char *au_sbtype(struct super_block *sb)
16456 + return sb->s_type->name;
16459 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16461 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16462 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16468 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16470 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16471 + return sb->s_magic == ROMFS_MAGIC;
16477 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16479 +#if IS_ENABLED(CONFIG_CRAMFS)
16480 + return sb->s_magic == CRAMFS_MAGIC;
16485 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16487 +#if IS_ENABLED(CONFIG_NFS_FS)
16488 + return sb->s_magic == NFS_SUPER_MAGIC;
16494 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16496 +#if IS_ENABLED(CONFIG_FUSE_FS)
16497 + return sb->s_magic == FUSE_SUPER_MAGIC;
16503 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16505 +#if IS_ENABLED(CONFIG_XFS_FS)
16506 + return sb->s_magic == XFS_SB_MAGIC;
16512 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16514 +#ifdef CONFIG_TMPFS
16515 + return sb->s_magic == TMPFS_MAGIC;
16521 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16523 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16524 + return !strcmp(au_sbtype(sb), "ecryptfs");
16530 +static inline int au_test_ramfs(struct super_block *sb)
16532 + return sb->s_magic == RAMFS_MAGIC;
16535 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16537 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16538 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16544 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16546 +#ifdef CONFIG_PROC_FS
16547 + return sb->s_magic == PROC_SUPER_MAGIC;
16553 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16555 +#ifdef CONFIG_SYSFS
16556 + return sb->s_magic == SYSFS_MAGIC;
16562 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16564 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16565 + return sb->s_magic == CONFIGFS_MAGIC;
16571 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16573 +#if IS_ENABLED(CONFIG_MINIX_FS)
16574 + return sb->s_magic == MINIX3_SUPER_MAGIC
16575 + || sb->s_magic == MINIX2_SUPER_MAGIC
16576 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16577 + || sb->s_magic == MINIX_SUPER_MAGIC
16578 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16584 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16586 +#if IS_ENABLED(CONFIG_FAT_FS)
16587 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16593 +static inline int au_test_msdos(struct super_block *sb)
16595 + return au_test_fat(sb);
16598 +static inline int au_test_vfat(struct super_block *sb)
16600 + return au_test_fat(sb);
16603 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16605 +#ifdef CONFIG_SECURITYFS
16606 + return sb->s_magic == SECURITYFS_MAGIC;
16612 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16614 +#if IS_ENABLED(CONFIG_SQUASHFS)
16615 + return sb->s_magic == SQUASHFS_MAGIC;
16621 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16623 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16624 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16630 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16632 +#if IS_ENABLED(CONFIG_XENFS)
16633 + return sb->s_magic == XENFS_SUPER_MAGIC;
16639 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16641 +#ifdef CONFIG_DEBUG_FS
16642 + return sb->s_magic == DEBUGFS_MAGIC;
16648 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16650 +#if IS_ENABLED(CONFIG_NILFS)
16651 + return sb->s_magic == NILFS_SUPER_MAGIC;
16657 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16659 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16660 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16666 +/* ---------------------------------------------------------------------- */
16668 + * they can't be an aufs branch.
16670 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16673 +#ifndef CONFIG_AUFS_BR_RAMFS
16674 + au_test_ramfs(sb) ||
16676 + au_test_procfs(sb)
16677 + || au_test_sysfs(sb)
16678 + || au_test_configfs(sb)
16679 + || au_test_debugfs(sb)
16680 + || au_test_securityfs(sb)
16681 + || au_test_xenfs(sb)
16682 + || au_test_ecryptfs(sb)
16683 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16684 + || au_test_aufs(sb); /* will be supported in next version */
16687 +static inline int au_test_fs_remote(struct super_block *sb)
16689 + return !au_test_tmpfs(sb)
16690 +#ifdef CONFIG_AUFS_BR_RAMFS
16691 + && !au_test_ramfs(sb)
16693 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16696 +/* ---------------------------------------------------------------------- */
16699 + * Note: these functions (below) are created after reading ->getattr() in all
16700 + * filesystems under linux/fs. it means we have to do so in every update...
16704 + * some filesystems require getattr to refresh the inode attributes before
16706 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16707 + * and leave the work for d_revalidate()
16709 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16711 + return au_test_nfs(sb)
16712 + || au_test_fuse(sb)
16713 + /* || au_test_btrfs(sb) */ /* untested */
16718 + * filesystems which don't maintain i_size or i_blocks.
16720 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16722 + return au_test_xfs(sb)
16723 + || au_test_btrfs(sb)
16724 + || au_test_ubifs(sb)
16725 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16726 + /* || au_test_minix(sb) */ /* untested */
16731 + * filesystems which don't store the correct value in some of their inode
16734 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16736 + return au_test_fs_bad_iattr_size(sb)
16737 + || au_test_fat(sb)
16738 + || au_test_msdos(sb)
16739 + || au_test_vfat(sb);
16742 +/* they don't check i_nlink in link(2) */
16743 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16745 + return au_test_tmpfs(sb)
16746 +#ifdef CONFIG_AUFS_BR_RAMFS
16747 + || au_test_ramfs(sb)
16749 + || au_test_ubifs(sb)
16750 + || au_test_hfsplus(sb);
16754 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16756 +static inline int au_test_fs_notime(struct super_block *sb)
16758 + return au_test_nfs(sb)
16759 + || au_test_fuse(sb)
16760 + || au_test_ubifs(sb)
16764 +/* temporary support for i#1 in cramfs */
16765 +static inline int au_test_fs_unique_ino(struct inode *inode)
16767 + if (au_test_cramfs(inode->i_sb))
16768 + return inode->i_ino != 1;
16772 +/* ---------------------------------------------------------------------- */
16775 + * the filesystem where the xino files placed must support i/o after unlink and
16776 + * maintain i_size and i_blocks.
16778 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16780 + return au_test_fs_remote(sb)
16781 + || au_test_fs_bad_iattr_size(sb)
16782 + /* don't want unnecessary work for xino */
16783 + || au_test_aufs(sb)
16784 + || au_test_ecryptfs(sb)
16785 + || au_test_nilfs(sb);
16788 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16790 + return au_test_tmpfs(sb)
16791 + || au_test_ramfs(sb);
16795 + * test if the @sb is real-readonly.
16797 +static inline int au_test_fs_rr(struct super_block *sb)
16799 + return au_test_squashfs(sb)
16800 + || au_test_iso9660(sb)
16801 + || au_test_cramfs(sb)
16802 + || au_test_romfs(sb);
16806 + * test if the @inode is nfs with 'noacl' option
16807 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16809 +static inline int au_test_nfs_noacl(struct inode *inode)
16811 + return au_test_nfs(inode->i_sb)
16812 + /* && IS_POSIXACL(inode) */
16813 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16816 +#endif /* __KERNEL__ */
16817 +#endif /* __AUFS_FSTYPE_H__ */
16818 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16819 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16820 +++ linux/fs/aufs/hbl.h 2019-01-28 14:36:12.219084659 +0100
16822 +/* SPDX-License-Identifier: GPL-2.0 */
16824 + * Copyright (C) 2017-2018 Junjiro R. Okajima
16826 + * This program, aufs is free software; you can redistribute it and/or modify
16827 + * it under the terms of the GNU General Public License as published by
16828 + * the Free Software Foundation; either version 2 of the License, or
16829 + * (at your option) any later version.
16831 + * This program is distributed in the hope that it will be useful,
16832 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16833 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16834 + * GNU General Public License for more details.
16836 + * You should have received a copy of the GNU General Public License
16837 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16841 + * helpers for hlist_bl.h
16844 +#ifndef __AUFS_HBL_H__
16845 +#define __AUFS_HBL_H__
16849 +#include <linux/list_bl.h>
16851 +static inline void au_hbl_add(struct hlist_bl_node *node,
16852 + struct hlist_bl_head *hbl)
16854 + hlist_bl_lock(hbl);
16855 + hlist_bl_add_head(node, hbl);
16856 + hlist_bl_unlock(hbl);
16859 +static inline void au_hbl_del(struct hlist_bl_node *node,
16860 + struct hlist_bl_head *hbl)
16862 + hlist_bl_lock(hbl);
16863 + hlist_bl_del(node);
16864 + hlist_bl_unlock(hbl);
16867 +#define au_hbl_for_each(pos, head) \
16868 + for (pos = hlist_bl_first(head); \
16872 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16874 + unsigned long cnt;
16875 + struct hlist_bl_node *pos;
16878 + hlist_bl_lock(hbl);
16879 + au_hbl_for_each(pos, hbl)
16881 + hlist_bl_unlock(hbl);
16885 +#endif /* __KERNEL__ */
16886 +#endif /* __AUFS_HBL_H__ */
16887 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16888 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16889 +++ linux/fs/aufs/hfsnotify.c 2019-01-28 14:36:12.219084659 +0100
16891 +// SPDX-License-Identifier: GPL-2.0
16893 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16895 + * This program, aufs is free software; you can redistribute it and/or modify
16896 + * it under the terms of the GNU General Public License as published by
16897 + * the Free Software Foundation; either version 2 of the License, or
16898 + * (at your option) any later version.
16900 + * This program is distributed in the hope that it will be useful,
16901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16903 + * GNU General Public License for more details.
16905 + * You should have received a copy of the GNU General Public License
16906 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16910 + * fsnotify for the lower directories
16915 +/* FS_IN_IGNORED is unnecessary */
16916 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16917 + | FS_CREATE | FS_EVENT_ON_CHILD);
16918 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16919 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16921 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16923 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16925 + /* AuDbg("here\n"); */
16926 + au_cache_free_hnotify(hn);
16927 + smp_mb__before_atomic(); /* for atomic64_dec */
16928 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16929 + wake_up(&au_hfsn_wq);
16932 +static int au_hfsn_alloc(struct au_hinode *hinode)
16935 + struct au_hnotify *hn;
16936 + struct super_block *sb;
16937 + struct au_branch *br;
16938 + struct fsnotify_mark *mark;
16939 + aufs_bindex_t bindex;
16941 + hn = hinode->hi_notify;
16942 + sb = hn->hn_aufs_inode->i_sb;
16943 + bindex = au_br_index(sb, hinode->hi_id);
16944 + br = au_sbr(sb, bindex);
16945 + AuDebugOn(!br->br_hfsn);
16947 + mark = &hn->hn_mark;
16948 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16949 + mark->mask = AuHfsnMask;
16951 + * by udba rename or rmdir, aufs assign a new inode to the known
16952 + * h_inode, so specify 1 to allow dups.
16955 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16961 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16963 + struct fsnotify_mark *mark;
16964 + unsigned long long ull;
16965 + struct fsnotify_group *group;
16967 + ull = atomic64_inc_return(&au_hfsn_ifree);
16970 + mark = &hn->hn_mark;
16971 + spin_lock(&mark->lock);
16972 + group = mark->group;
16973 + fsnotify_get_group(group);
16974 + spin_unlock(&mark->lock);
16976 + fsnotify_destroy_mark(mark, group);
16977 + fsnotify_put_mark(mark);
16978 + fsnotify_put_group(group);
16981 + /* free hn by myself */
16985 +/* ---------------------------------------------------------------------- */
16987 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16989 + struct fsnotify_mark *mark;
16991 + mark = &hinode->hi_notify->hn_mark;
16992 + spin_lock(&mark->lock);
16994 + AuDebugOn(mark->mask & AuHfsnMask);
16995 + mark->mask |= AuHfsnMask;
16997 + AuDebugOn(!(mark->mask & AuHfsnMask));
16998 + mark->mask &= ~AuHfsnMask;
17000 + spin_unlock(&mark->lock);
17001 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
17004 +/* ---------------------------------------------------------------------- */
17006 +/* #define AuDbgHnotify */
17007 +#ifdef AuDbgHnotify
17008 +static char *au_hfsn_name(u32 mask)
17010 +#ifdef CONFIG_AUFS_DEBUG
17011 +#define test_ret(flag) \
17013 + if (mask & flag) \
17016 + test_ret(FS_ACCESS);
17017 + test_ret(FS_MODIFY);
17018 + test_ret(FS_ATTRIB);
17019 + test_ret(FS_CLOSE_WRITE);
17020 + test_ret(FS_CLOSE_NOWRITE);
17021 + test_ret(FS_OPEN);
17022 + test_ret(FS_MOVED_FROM);
17023 + test_ret(FS_MOVED_TO);
17024 + test_ret(FS_CREATE);
17025 + test_ret(FS_DELETE);
17026 + test_ret(FS_DELETE_SELF);
17027 + test_ret(FS_MOVE_SELF);
17028 + test_ret(FS_UNMOUNT);
17029 + test_ret(FS_Q_OVERFLOW);
17030 + test_ret(FS_IN_IGNORED);
17031 + test_ret(FS_ISDIR);
17032 + test_ret(FS_IN_ONESHOT);
17033 + test_ret(FS_EVENT_ON_CHILD);
17042 +/* ---------------------------------------------------------------------- */
17044 +static void au_hfsn_free_group(struct fsnotify_group *group)
17046 + struct au_br_hfsnotify *hfsn = group->private;
17048 + /* AuDbg("here\n"); */
17049 + au_kfree_try_rcu(hfsn);
17052 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17053 + struct inode *inode,
17054 + u32 mask, const void *data, int data_type,
17055 + const unsigned char *file_name, u32 cookie,
17056 + struct fsnotify_iter_info *iter_info)
17059 + struct au_hnotify *hnotify;
17060 + struct inode *h_dir, *h_inode;
17061 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17062 + struct fsnotify_mark *inode_mark;
17064 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17067 + /* if FS_UNMOUNT happens, there must be another bug */
17068 + AuDebugOn(mask & FS_UNMOUNT);
17069 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17074 +#ifdef AuDbgHnotify
17076 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17077 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17078 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17079 + h_dir->i_ino, mask, au_hfsn_name(mask),
17080 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17081 + /* WARN_ON(1); */
17086 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17087 + AuDebugOn(!inode_mark);
17088 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17089 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17095 +static struct fsnotify_ops au_hfsn_ops = {
17096 + .handle_event = au_hfsn_handle_event,
17097 + .free_group_priv = au_hfsn_free_group,
17098 + .free_mark = au_hfsn_free_mark
17101 +/* ---------------------------------------------------------------------- */
17103 +static void au_hfsn_fin_br(struct au_branch *br)
17105 + struct au_br_hfsnotify *hfsn;
17107 + hfsn = br->br_hfsn;
17110 + fsnotify_put_group(hfsn->hfsn_group);
17115 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17118 + struct fsnotify_group *group;
17119 + struct au_br_hfsnotify *hfsn;
17122 + br->br_hfsn = NULL;
17123 + if (!au_br_hnotifyable(perm))
17127 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17128 + if (unlikely(!hfsn))
17132 + group = fsnotify_alloc_group(&au_hfsn_ops);
17133 + if (IS_ERR(group)) {
17134 + err = PTR_ERR(group);
17135 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17139 + group->private = hfsn;
17140 + hfsn->hfsn_group = group;
17141 + br->br_hfsn = hfsn;
17142 + goto out; /* success */
17145 + au_kfree_try_rcu(hfsn);
17150 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17155 + if (!br->br_hfsn)
17156 + err = au_hfsn_init_br(br, perm);
17161 +/* ---------------------------------------------------------------------- */
17163 +static void au_hfsn_fin(void)
17165 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17166 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17169 +const struct au_hnotify_op au_hnotify_op = {
17170 + .ctl = au_hfsn_ctl,
17171 + .alloc = au_hfsn_alloc,
17172 + .free = au_hfsn_free,
17174 + .fin = au_hfsn_fin,
17176 + .reset_br = au_hfsn_reset_br,
17177 + .fin_br = au_hfsn_fin_br,
17178 + .init_br = au_hfsn_init_br
17180 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17181 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17182 +++ linux/fs/aufs/hfsplus.c 2019-01-28 14:36:12.219084659 +0100
17184 +// SPDX-License-Identifier: GPL-2.0
17186 + * Copyright (C) 2010-2018 Junjiro R. Okajima
17188 + * This program, aufs is free software; you can redistribute it and/or modify
17189 + * it under the terms of the GNU General Public License as published by
17190 + * the Free Software Foundation; either version 2 of the License, or
17191 + * (at your option) any later version.
17193 + * This program is distributed in the hope that it will be useful,
17194 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17195 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17196 + * GNU General Public License for more details.
17198 + * You should have received a copy of the GNU General Public License
17199 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17203 + * special support for filesystems which acquires an inode mutex
17204 + * at final closing a file, eg, hfsplus.
17206 + * This trick is very simple and stupid, just to open the file before really
17207 + * necessary open to tell hfsplus that this is not the final closing.
17208 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17209 + * and au_h_open_post() after releasing it.
17214 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17217 + struct file *h_file;
17218 + struct dentry *h_dentry;
17220 + h_dentry = au_h_dptr(dentry, bindex);
17221 + AuDebugOn(!h_dentry);
17222 + AuDebugOn(d_is_negative(h_dentry));
17225 + if (au_test_hfsplus(h_dentry->d_sb)
17226 + && d_is_reg(h_dentry))
17227 + h_file = au_h_open(dentry, bindex,
17228 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17229 + /*file*/NULL, force_wr);
17233 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17234 + struct file *h_file)
17236 + struct au_branch *br;
17240 + br = au_sbr(dentry->d_sb, bindex);
17241 + au_lcnt_dec(&br->br_nfiles);
17244 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17245 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17246 +++ linux/fs/aufs/hnotify.c 2019-01-28 14:36:12.219084659 +0100
17248 +// SPDX-License-Identifier: GPL-2.0
17250 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17252 + * This program, aufs is free software; you can redistribute it and/or modify
17253 + * it under the terms of the GNU General Public License as published by
17254 + * the Free Software Foundation; either version 2 of the License, or
17255 + * (at your option) any later version.
17257 + * This program is distributed in the hope that it will be useful,
17258 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17259 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17260 + * GNU General Public License for more details.
17262 + * You should have received a copy of the GNU General Public License
17263 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17267 + * abstraction to notify the direct changes on lower directories
17272 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17275 + struct au_hnotify *hn;
17278 + hn = au_cache_alloc_hnotify();
17280 + hn->hn_aufs_inode = inode;
17281 + hinode->hi_notify = hn;
17282 + err = au_hnotify_op.alloc(hinode);
17284 + if (unlikely(err)) {
17285 + hinode->hi_notify = NULL;
17286 + au_cache_free_hnotify(hn);
17288 + * The upper dir was removed by udba, but the same named
17289 + * dir left. In this case, aufs assigns a new inode
17290 + * number and set the monitor again.
17291 + * For the lower dir, the old monitor is still left.
17293 + if (err == -EEXIST)
17302 +void au_hn_free(struct au_hinode *hinode)
17304 + struct au_hnotify *hn;
17306 + hn = hinode->hi_notify;
17308 + hinode->hi_notify = NULL;
17309 + if (au_hnotify_op.free(hinode, hn))
17310 + au_cache_free_hnotify(hn);
17314 +/* ---------------------------------------------------------------------- */
17316 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17318 + if (hinode->hi_notify)
17319 + au_hnotify_op.ctl(hinode, do_set);
17322 +void au_hn_reset(struct inode *inode, unsigned int flags)
17324 + aufs_bindex_t bindex, bbot;
17325 + struct inode *hi;
17326 + struct dentry *iwhdentry;
17328 + bbot = au_ibbot(inode);
17329 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17330 + hi = au_h_iptr(inode, bindex);
17334 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17335 + iwhdentry = au_hi_wh(inode, bindex);
17339 + au_set_h_iptr(inode, bindex, NULL, 0);
17340 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17341 + flags & ~AuHi_XINO);
17344 + /* inode_unlock(hi); */
17348 +/* ---------------------------------------------------------------------- */
17350 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17353 + aufs_bindex_t bindex, bbot, bfound, btop;
17354 + struct inode *h_i;
17357 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17358 + pr_warn("branch root dir was changed\n");
17363 + bbot = au_ibbot(inode);
17364 + btop = au_ibtop(inode);
17365 +#if 0 /* reserved for future use */
17366 + if (bindex == bbot) {
17367 + /* keep this ino in rename case */
17371 + for (bindex = btop; bindex <= bbot; bindex++)
17372 + if (au_h_iptr(inode, bindex) == h_inode) {
17379 + for (bindex = btop; bindex <= bbot; bindex++) {
17380 + h_i = au_h_iptr(inode, bindex);
17384 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17385 + /* ignore this error */
17386 + /* bad action? */
17389 + /* children inode number will be broken */
17396 +static int hn_gen_tree(struct dentry *dentry)
17398 + int err, i, j, ndentry;
17399 + struct au_dcsub_pages dpages;
17400 + struct au_dpage *dpage;
17401 + struct dentry **dentries;
17403 + err = au_dpages_init(&dpages, GFP_NOFS);
17404 + if (unlikely(err))
17406 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17407 + if (unlikely(err))
17410 + for (i = 0; i < dpages.ndpage; i++) {
17411 + dpage = dpages.dpages + i;
17412 + dentries = dpage->dentries;
17413 + ndentry = dpage->ndentry;
17414 + for (j = 0; j < ndentry; j++) {
17415 + struct dentry *d;
17422 + if (d_really_is_positive(d))
17423 + /* todo: reset children xino?
17424 + cached children only? */
17425 + au_iigen_dec(d_inode(d));
17430 + au_dpages_free(&dpages);
17433 + /* discard children */
17434 + dentry_unhash(dentry);
17442 + * return 0 if processed.
17444 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17445 + const unsigned int isdir)
17448 + struct dentry *d;
17449 + struct qstr *dname;
17452 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17453 + pr_warn("branch root dir was changed\n");
17459 + AuDebugOn(!name);
17460 + au_iigen_dec(inode);
17461 + spin_lock(&inode->i_lock);
17462 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17463 + spin_lock(&d->d_lock);
17464 + dname = &d->d_name;
17465 + if (dname->len != nlen
17466 + && memcmp(dname->name, name, nlen)) {
17467 + spin_unlock(&d->d_lock);
17472 + spin_unlock(&d->d_lock);
17475 + spin_unlock(&inode->i_lock);
17477 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17478 + d = d_find_any_alias(inode);
17480 + au_iigen_dec(inode);
17484 + spin_lock(&d->d_lock);
17485 + dname = &d->d_name;
17486 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17487 + spin_unlock(&d->d_lock);
17488 + err = hn_gen_tree(d);
17489 + spin_lock(&d->d_lock);
17491 + spin_unlock(&d->d_lock);
17500 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17504 + if (IS_ROOT(dentry)) {
17505 + pr_warn("branch root dir was changed\n");
17511 + au_digen_dec(dentry);
17512 + if (d_really_is_positive(dentry))
17513 + au_iigen_dec(d_inode(dentry));
17515 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17516 + if (d_really_is_positive(dentry))
17517 + err = hn_gen_tree(dentry);
17524 +/* ---------------------------------------------------------------------- */
17526 +/* hnotify job flags */
17527 +#define AuHnJob_XINO0 1
17528 +#define AuHnJob_GEN (1 << 1)
17529 +#define AuHnJob_DIRENT (1 << 2)
17530 +#define AuHnJob_ISDIR (1 << 3)
17531 +#define AuHnJob_TRYXINO0 (1 << 4)
17532 +#define AuHnJob_MNTPNT (1 << 5)
17533 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17534 +#define au_fset_hnjob(flags, name) \
17535 + do { (flags) |= AuHnJob_##name; } while (0)
17536 +#define au_fclr_hnjob(flags, name) \
17537 + do { (flags) &= ~AuHnJob_##name; } while (0)
17545 +struct au_hnotify_args {
17546 + struct inode *h_dir, *dir, *h_child_inode;
17548 + unsigned int flags[AuHnLast];
17549 + unsigned int h_child_nlen;
17550 + char h_child_name[];
17553 +struct hn_job_args {
17554 + unsigned int flags;
17555 + struct inode *inode, *h_inode, *dir, *h_dir;
17556 + struct dentry *dentry;
17561 +static int hn_job(struct hn_job_args *a)
17563 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17567 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17568 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17570 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17573 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17574 + if (!a->h_inode->i_nlink
17575 + && !(a->h_inode->i_state & I_LINKABLE))
17576 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17577 + inode_unlock_shared(a->h_inode);
17580 + /* make the generation obsolete */
17581 + if (au_ftest_hnjob(a->flags, GEN)) {
17584 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17586 + if (e && a->dentry)
17587 + hn_gen_by_name(a->dentry, isdir);
17588 + /* ignore this error */
17591 + /* make dir entries obsolete */
17592 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17593 + struct au_vdir *vdir;
17595 + vdir = au_ivdir(a->inode);
17597 + vdir->vd_jiffy = 0;
17598 + /* IMustLock(a->inode); */
17599 + /* inode_inc_iversion(a->inode); */
17602 + /* can do nothing but warn */
17603 + if (au_ftest_hnjob(a->flags, MNTPNT)
17605 + && d_mountpoint(a->dentry))
17606 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17611 +/* ---------------------------------------------------------------------- */
17613 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17614 + struct inode *dir)
17616 + struct dentry *dentry, *d, *parent;
17617 + struct qstr *dname;
17619 + parent = d_find_any_alias(dir);
17624 + spin_lock(&parent->d_lock);
17625 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17626 + /* AuDbg("%pd\n", d); */
17627 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17628 + dname = &d->d_name;
17629 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17630 + goto cont_unlock;
17634 + goto cont_unlock;
17635 + if (au_dcount(d) > 0) {
17636 + dentry = dget_dlock(d);
17637 + spin_unlock(&d->d_lock);
17642 + spin_unlock(&d->d_lock);
17644 + spin_unlock(&parent->d_lock);
17648 + di_write_lock_child(dentry);
17653 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17654 + aufs_bindex_t bindex, ino_t h_ino)
17656 + struct inode *inode;
17661 + err = au_xino_read(sb, bindex, h_ino, &ino);
17663 + inode = ilookup(sb, ino);
17667 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17668 + pr_warn("wrong root branch\n");
17674 + ii_write_lock_child(inode);
17680 +static void au_hn_bh(void *_args)
17682 + struct au_hnotify_args *a = _args;
17683 + struct super_block *sb;
17684 + aufs_bindex_t bindex, bbot, bfound;
17685 + unsigned char xino, try_iput;
17687 + struct inode *inode;
17689 + struct hn_job_args args;
17690 + struct dentry *dentry;
17691 + struct au_sbinfo *sbinfo;
17693 + AuDebugOn(!_args);
17694 + AuDebugOn(!a->h_dir);
17695 + AuDebugOn(!a->dir);
17696 + AuDebugOn(!a->mask);
17697 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17698 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17699 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17704 + * do not lock a->dir->i_mutex here
17705 + * because of d_revalidate() may cause a deadlock.
17707 + sb = a->dir->i_sb;
17709 + sbinfo = au_sbi(sb);
17710 + AuDebugOn(!sbinfo);
17711 + si_write_lock(sb, AuLock_NOPLMW);
17713 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17714 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17715 + case FS_MOVED_FROM:
17716 + case FS_MOVED_TO:
17717 + AuWarn1("DIRREN with UDBA may not work correctly "
17718 + "for the direct rename(2)\n");
17721 + ii_read_lock_parent(a->dir);
17723 + bbot = au_ibbot(a->dir);
17724 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17725 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17729 + ii_read_unlock(a->dir);
17730 + if (unlikely(bfound < 0))
17733 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17735 + if (a->h_child_inode)
17736 + h_ino = a->h_child_inode->i_ino;
17738 + if (a->h_child_nlen
17739 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17740 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17741 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17744 + if (dentry && d_really_is_positive(dentry))
17745 + inode = d_inode(dentry);
17746 + if (xino && !inode && h_ino
17747 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17748 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17749 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17750 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17754 + args.flags = a->flags[AuHn_CHILD];
17755 + args.dentry = dentry;
17756 + args.inode = inode;
17757 + args.h_inode = a->h_child_inode;
17758 + args.dir = a->dir;
17759 + args.h_dir = a->h_dir;
17760 + args.h_name = a->h_child_name;
17761 + args.h_nlen = a->h_child_nlen;
17762 + err = hn_job(&args);
17764 + if (au_di(dentry))
17765 + di_write_unlock(dentry);
17768 + if (inode && try_iput) {
17769 + ii_write_unlock(inode);
17773 + ii_write_lock_parent(a->dir);
17774 + args.flags = a->flags[AuHn_PARENT];
17775 + args.dentry = NULL;
17776 + args.inode = a->dir;
17777 + args.h_inode = a->h_dir;
17779 + args.h_dir = NULL;
17780 + args.h_name = NULL;
17782 + err = hn_job(&args);
17783 + ii_write_unlock(a->dir);
17786 + iput(a->h_child_inode);
17789 + si_write_unlock(sb);
17790 + au_nwt_done(&sbinfo->si_nowait);
17794 +/* ---------------------------------------------------------------------- */
17796 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17797 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17800 + unsigned int flags[AuHnLast], f;
17801 + unsigned char isdir, isroot, wh;
17802 + struct inode *dir;
17803 + struct au_hnotify_args *args;
17804 + char *p, *h_child_name;
17807 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17808 + dir = igrab(hnotify->hn_aufs_inode);
17812 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17814 + h_child_name = (void *)h_child_qstr->name;
17815 + len = h_child_qstr->len;
17816 + if (h_child_name) {
17817 + if (len > AUFS_WH_PFX_LEN
17818 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17819 + h_child_name += AUFS_WH_PFX_LEN;
17820 + len -= AUFS_WH_PFX_LEN;
17826 + if (h_child_inode)
17827 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17828 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17829 + flags[AuHn_CHILD] = 0;
17831 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17832 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17833 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17834 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17835 + case FS_MOVED_FROM:
17836 + case FS_MOVED_TO:
17837 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17838 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17841 + AuDebugOn(!h_child_name);
17846 + * aufs never be able to get this child inode.
17847 + * revalidation should be in d_revalidate()
17848 + * by checking i_nlink, i_generation or d_unhashed().
17850 + AuDebugOn(!h_child_name);
17851 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17852 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17860 + h_child_inode = NULL;
17863 + /* iput() and kfree() will be called in au_hnotify() */
17864 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17865 + if (unlikely(!args)) {
17866 + AuErr1("no memory\n");
17870 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17871 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17872 + args->mask = mask;
17874 + args->h_dir = igrab(h_dir);
17875 + if (h_child_inode)
17876 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17877 + args->h_child_inode = h_child_inode;
17878 + args->h_child_nlen = len;
17880 + p = (void *)args;
17881 + p += sizeof(*args);
17882 + memcpy(p, h_child_name, len);
17886 + /* NFS fires the event for silly-renamed one from kworker */
17888 + if (!dir->i_nlink
17889 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17891 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17892 + if (unlikely(err)) {
17893 + pr_err("wkq %d\n", err);
17894 + iput(args->h_child_inode);
17895 + iput(args->h_dir);
17897 + au_kfree_rcu(args);
17904 +/* ---------------------------------------------------------------------- */
17906 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17910 + AuDebugOn(!(udba & AuOptMask_UDBA));
17913 + if (au_hnotify_op.reset_br)
17914 + err = au_hnotify_op.reset_br(udba, br, perm);
17919 +int au_hnotify_init_br(struct au_branch *br, int perm)
17924 + if (au_hnotify_op.init_br)
17925 + err = au_hnotify_op.init_br(br, perm);
17930 +void au_hnotify_fin_br(struct au_branch *br)
17932 + if (au_hnotify_op.fin_br)
17933 + au_hnotify_op.fin_br(br);
17936 +static void au_hn_destroy_cache(void)
17938 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17939 + au_cache[AuCache_HNOTIFY] = NULL;
17942 +int __init au_hnotify_init(void)
17947 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17948 + if (au_cache[AuCache_HNOTIFY]) {
17950 + if (au_hnotify_op.init)
17951 + err = au_hnotify_op.init();
17952 + if (unlikely(err))
17953 + au_hn_destroy_cache();
17959 +void au_hnotify_fin(void)
17961 + if (au_hnotify_op.fin)
17962 + au_hnotify_op.fin();
17964 + /* cf. au_cache_fin() */
17965 + if (au_cache[AuCache_HNOTIFY])
17966 + au_hn_destroy_cache();
17968 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17969 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17970 +++ linux/fs/aufs/iinfo.c 2019-01-28 14:36:12.222418047 +0100
17972 +// SPDX-License-Identifier: GPL-2.0
17974 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17976 + * This program, aufs is free software; you can redistribute it and/or modify
17977 + * it under the terms of the GNU General Public License as published by
17978 + * the Free Software Foundation; either version 2 of the License, or
17979 + * (at your option) any later version.
17981 + * This program is distributed in the hope that it will be useful,
17982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17984 + * GNU General Public License for more details.
17986 + * You should have received a copy of the GNU General Public License
17987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17991 + * inode private data
17996 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17998 + struct inode *h_inode;
17999 + struct au_hinode *hinode;
18001 + IiMustAnyLock(inode);
18003 + hinode = au_hinode(au_ii(inode), bindex);
18004 + h_inode = hinode->hi_inode;
18005 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18009 +/* todo: hard/soft set? */
18010 +void au_hiput(struct au_hinode *hinode)
18012 + au_hn_free(hinode);
18013 + dput(hinode->hi_whdentry);
18014 + iput(hinode->hi_inode);
18017 +unsigned int au_hi_flags(struct inode *inode, int isdir)
18019 + unsigned int flags;
18020 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
18023 + if (au_opt_test(mnt_flags, XINO))
18024 + au_fset_hi(flags, XINO);
18025 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
18026 + au_fset_hi(flags, HNOTIFY);
18030 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18031 + struct inode *h_inode, unsigned int flags)
18033 + struct au_hinode *hinode;
18034 + struct inode *hi;
18035 + struct au_iinfo *iinfo = au_ii(inode);
18037 + IiMustWriteLock(inode);
18039 + hinode = au_hinode(iinfo, bindex);
18040 + hi = hinode->hi_inode;
18041 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18044 + au_hiput(hinode);
18045 + hinode->hi_inode = h_inode;
18048 + struct super_block *sb = inode->i_sb;
18049 + struct au_branch *br;
18051 + AuDebugOn(inode->i_mode
18052 + && (h_inode->i_mode & S_IFMT)
18053 + != (inode->i_mode & S_IFMT));
18054 + if (bindex == iinfo->ii_btop)
18055 + au_cpup_igen(inode, h_inode);
18056 + br = au_sbr(sb, bindex);
18057 + hinode->hi_id = br->br_id;
18058 + if (au_ftest_hi(flags, XINO)) {
18059 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18061 + if (unlikely(err))
18062 + AuIOErr1("failed au_xino_write() %d\n", err);
18065 + if (au_ftest_hi(flags, HNOTIFY)
18066 + && au_br_hnotifyable(br->br_perm)) {
18067 + err = au_hn_alloc(hinode, inode);
18068 + if (unlikely(err))
18069 + AuIOErr1("au_hn_alloc() %d\n", err);
18074 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18075 + struct dentry *h_wh)
18077 + struct au_hinode *hinode;
18079 + IiMustWriteLock(inode);
18081 + hinode = au_hinode(au_ii(inode), bindex);
18082 + AuDebugOn(hinode->hi_whdentry);
18083 + hinode->hi_whdentry = h_wh;
18086 +void au_update_iigen(struct inode *inode, int half)
18088 + struct au_iinfo *iinfo;
18089 + struct au_iigen *iigen;
18090 + unsigned int sigen;
18092 + sigen = au_sigen(inode->i_sb);
18093 + iinfo = au_ii(inode);
18094 + iigen = &iinfo->ii_generation;
18095 + spin_lock(&iigen->ig_spin);
18096 + iigen->ig_generation = sigen;
18098 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18100 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18101 + spin_unlock(&iigen->ig_spin);
18104 +/* it may be called at remount time, too */
18105 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18107 + struct au_iinfo *iinfo;
18108 + aufs_bindex_t bindex, bbot;
18110 + AuDebugOn(au_is_bad_inode(inode));
18111 + IiMustWriteLock(inode);
18113 + iinfo = au_ii(inode);
18114 + if (do_put_zero && iinfo->ii_btop >= 0) {
18115 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18117 + struct inode *h_i;
18119 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18122 + && !(h_i->i_state & I_LINKABLE))
18123 + au_set_h_iptr(inode, bindex, NULL, 0);
18127 + iinfo->ii_btop = -1;
18128 + iinfo->ii_bbot = -1;
18129 + bbot = au_sbbot(inode->i_sb);
18130 + for (bindex = 0; bindex <= bbot; bindex++)
18131 + if (au_hinode(iinfo, bindex)->hi_inode) {
18132 + iinfo->ii_btop = bindex;
18135 + if (iinfo->ii_btop >= 0)
18136 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18137 + if (au_hinode(iinfo, bindex)->hi_inode) {
18138 + iinfo->ii_bbot = bindex;
18141 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18144 +/* ---------------------------------------------------------------------- */
18146 +void au_icntnr_init_once(void *_c)
18148 + struct au_icntnr *c = _c;
18149 + struct au_iinfo *iinfo = &c->iinfo;
18151 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18152 + au_rw_init(&iinfo->ii_rwsem);
18153 + inode_init_once(&c->vfs_inode);
18156 +void au_hinode_init(struct au_hinode *hinode)
18158 + hinode->hi_inode = NULL;
18159 + hinode->hi_id = -1;
18160 + au_hn_init(hinode);
18161 + hinode->hi_whdentry = NULL;
18164 +int au_iinfo_init(struct inode *inode)
18166 + struct au_iinfo *iinfo;
18167 + struct super_block *sb;
18168 + struct au_hinode *hi;
18171 + sb = inode->i_sb;
18172 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18173 + nbr = au_sbbot(sb) + 1;
18174 + if (unlikely(nbr <= 0))
18176 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18178 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18180 + iinfo->ii_hinode = hi;
18181 + for (i = 0; i < nbr; i++, hi++)
18182 + au_hinode_init(hi);
18184 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18185 + iinfo->ii_btop = -1;
18186 + iinfo->ii_bbot = -1;
18187 + iinfo->ii_vdir = NULL;
18193 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18196 + struct au_hinode *hip;
18198 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18201 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18204 + iinfo->ii_hinode = hip;
18205 + i = iinfo->ii_bbot + 1;
18207 + for (; i < nbr; i++, hip++)
18208 + au_hinode_init(hip);
18215 +void au_iinfo_fin(struct inode *inode)
18217 + struct au_iinfo *iinfo;
18218 + struct au_hinode *hi;
18219 + struct super_block *sb;
18220 + aufs_bindex_t bindex, bbot;
18221 + const unsigned char unlinked = !inode->i_nlink;
18223 + AuDebugOn(au_is_bad_inode(inode));
18225 + sb = inode->i_sb;
18226 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18227 + if (si_pid_test(sb))
18228 + au_xino_delete_inode(inode, unlinked);
18231 + * it is safe to hide the dependency between sbinfo and
18235 + si_noflush_read_lock(sb);
18236 + au_xino_delete_inode(inode, unlinked);
18237 + si_read_unlock(sb);
18241 + iinfo = au_ii(inode);
18242 + if (iinfo->ii_vdir)
18243 + au_vdir_free(iinfo->ii_vdir);
18245 + bindex = iinfo->ii_btop;
18246 + if (bindex >= 0) {
18247 + hi = au_hinode(iinfo, bindex);
18248 + bbot = iinfo->ii_bbot;
18249 + while (bindex++ <= bbot) {
18250 + if (hi->hi_inode)
18255 + au_kfree_rcu(iinfo->ii_hinode);
18256 + AuRwDestroy(&iinfo->ii_rwsem);
18258 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18259 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18260 +++ linux/fs/aufs/inode.c 2019-01-28 14:36:12.222418047 +0100
18262 +// SPDX-License-Identifier: GPL-2.0
18264 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18266 + * This program, aufs is free software; you can redistribute it and/or modify
18267 + * it under the terms of the GNU General Public License as published by
18268 + * the Free Software Foundation; either version 2 of the License, or
18269 + * (at your option) any later version.
18271 + * This program is distributed in the hope that it will be useful,
18272 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18273 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18274 + * GNU General Public License for more details.
18276 + * You should have received a copy of the GNU General Public License
18277 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18281 + * inode functions
18286 +struct inode *au_igrab(struct inode *inode)
18289 + AuDebugOn(!atomic_read(&inode->i_count));
18295 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18297 + au_cpup_attr_all(inode, /*force*/0);
18298 + au_update_iigen(inode, /*half*/1);
18300 + inode_inc_iversion(inode);
18303 +static int au_ii_refresh(struct inode *inode, int *update)
18307 + aufs_bindex_t bindex, new_bindex;
18308 + struct super_block *sb;
18309 + struct au_iinfo *iinfo;
18310 + struct au_hinode *p, *q, tmp;
18312 + AuDebugOn(au_is_bad_inode(inode));
18313 + IiMustWriteLock(inode);
18316 + sb = inode->i_sb;
18317 + nbr = au_sbbot(sb) + 1;
18318 + type = inode->i_mode & S_IFMT;
18319 + iinfo = au_ii(inode);
18320 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18321 + if (unlikely(err))
18324 + AuDebugOn(iinfo->ii_btop < 0);
18325 + p = au_hinode(iinfo, iinfo->ii_btop);
18326 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18328 + if (!p->hi_inode)
18331 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18332 + new_bindex = au_br_index(sb, p->hi_id);
18333 + if (new_bindex == bindex)
18336 + if (new_bindex < 0) {
18339 + p->hi_inode = NULL;
18343 + if (new_bindex < iinfo->ii_btop)
18344 + iinfo->ii_btop = new_bindex;
18345 + if (iinfo->ii_bbot < new_bindex)
18346 + iinfo->ii_bbot = new_bindex;
18347 + /* swap two lower inode, and loop again */
18348 + q = au_hinode(iinfo, new_bindex);
18352 + if (tmp.hi_inode) {
18357 + au_update_ibrange(inode, /*do_put_zero*/0);
18358 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18359 + e = au_dy_irefresh(inode);
18360 + if (unlikely(e && !err))
18368 +void au_refresh_iop(struct inode *inode, int force_getattr)
18371 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18372 + const struct inode_operations *iop
18373 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18375 + if (inode->i_op == iop)
18378 + switch (inode->i_mode & S_IFMT) {
18380 + type = AuIop_DIR;
18383 + type = AuIop_SYMLINK;
18386 + type = AuIop_OTHER;
18390 + inode->i_op = iop + type;
18391 + /* unnecessary smp_wmb() */
18394 +int au_refresh_hinode_self(struct inode *inode)
18398 + err = au_ii_refresh(inode, &update);
18400 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18406 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18408 + int err, e, update;
18409 + unsigned int flags;
18411 + aufs_bindex_t bindex, bbot;
18412 + unsigned char isdir;
18413 + struct au_hinode *p;
18414 + struct au_iinfo *iinfo;
18416 + err = au_ii_refresh(inode, &update);
18417 + if (unlikely(err))
18421 + iinfo = au_ii(inode);
18422 + p = au_hinode(iinfo, iinfo->ii_btop);
18423 + mode = (inode->i_mode & S_IFMT);
18424 + isdir = S_ISDIR(mode);
18425 + flags = au_hi_flags(inode, isdir);
18426 + bbot = au_dbbot(dentry);
18427 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18428 + struct inode *h_i, *h_inode;
18429 + struct dentry *h_d;
18431 + h_d = au_h_dptr(dentry, bindex);
18432 + if (!h_d || d_is_negative(h_d))
18435 + h_inode = d_inode(h_d);
18436 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18437 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18438 + h_i = au_h_iptr(inode, bindex);
18440 + if (h_i == h_inode)
18446 + if (bindex < iinfo->ii_btop)
18447 + iinfo->ii_btop = bindex;
18448 + if (iinfo->ii_bbot < bindex)
18449 + iinfo->ii_bbot = bindex;
18450 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18453 + au_update_ibrange(inode, /*do_put_zero*/0);
18454 + e = au_dy_irefresh(inode);
18455 + if (unlikely(e && !err))
18458 + au_refresh_hinode_attr(inode, update && isdir);
18465 +static int set_inode(struct inode *inode, struct dentry *dentry)
18468 + unsigned int flags;
18470 + aufs_bindex_t bindex, btop, btail;
18471 + unsigned char isdir;
18472 + struct dentry *h_dentry;
18473 + struct inode *h_inode;
18474 + struct au_iinfo *iinfo;
18475 + struct inode_operations *iop;
18477 + IiMustWriteLock(inode);
18481 + iop = au_sbi(inode->i_sb)->si_iop_array;
18482 + btop = au_dbtop(dentry);
18483 + h_dentry = au_h_dptr(dentry, btop);
18484 + h_inode = d_inode(h_dentry);
18485 + mode = h_inode->i_mode;
18486 + switch (mode & S_IFMT) {
18488 + btail = au_dbtail(dentry);
18489 + inode->i_op = iop + AuIop_OTHER;
18490 + inode->i_fop = &aufs_file_fop;
18491 + err = au_dy_iaop(inode, btop, h_inode);
18492 + if (unlikely(err))
18497 + btail = au_dbtaildir(dentry);
18498 + inode->i_op = iop + AuIop_DIR;
18499 + inode->i_fop = &aufs_dir_fop;
18502 + btail = au_dbtail(dentry);
18503 + inode->i_op = iop + AuIop_SYMLINK;
18509 + btail = au_dbtail(dentry);
18510 + inode->i_op = iop + AuIop_OTHER;
18511 + init_special_inode(inode, mode, h_inode->i_rdev);
18514 + AuIOErr("Unknown file type 0%o\n", mode);
18519 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18520 + flags = au_hi_flags(inode, isdir);
18521 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18522 + && au_ftest_hi(flags, HNOTIFY)
18523 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18524 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18525 + au_fclr_hi(flags, HNOTIFY);
18526 + iinfo = au_ii(inode);
18527 + iinfo->ii_btop = btop;
18528 + iinfo->ii_bbot = btail;
18529 + for (bindex = btop; bindex <= btail; bindex++) {
18530 + h_dentry = au_h_dptr(dentry, bindex);
18532 + au_set_h_iptr(inode, bindex,
18533 + au_igrab(d_inode(h_dentry)), flags);
18535 + au_cpup_attr_all(inode, /*force*/1);
18537 + * to force calling aufs_get_acl() every time,
18538 + * do not call cache_no_acl() for aufs inode.
18546 + * successful returns with iinfo write_locked
18548 + * zero: success, matched
18549 + * plus: no error, but unmatched
18551 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18554 + unsigned int gen, igflags;
18555 + aufs_bindex_t bindex, bbot;
18556 + struct inode *h_inode, *h_dinode;
18557 + struct dentry *h_dentry;
18560 + * before this function, if aufs got any iinfo lock, it must be only
18561 + * one, the parent dir.
18562 + * it can happen by UDBA and the obsoleted inode number.
18565 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18569 + ii_write_lock_new_child(inode);
18570 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18571 + h_dinode = d_inode(h_dentry);
18572 + bbot = au_ibbot(inode);
18573 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18574 + h_inode = au_h_iptr(inode, bindex);
18575 + if (!h_inode || h_inode != h_dinode)
18579 + gen = au_iigen(inode, &igflags);
18580 + if (gen == au_digen(dentry)
18581 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18584 + /* fully refresh inode using dentry */
18585 + err = au_refresh_hinode(inode, dentry);
18587 + au_update_iigen(inode, /*half*/0);
18591 + if (unlikely(err))
18592 + ii_write_unlock(inode);
18597 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18598 + unsigned int d_type, ino_t *ino)
18601 + const int isnondir = d_type != DT_DIR;
18603 + /* prevent hardlinked inode number from race condition */
18605 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18606 + if (unlikely(err))
18610 + err = au_xino_read(sb, bindex, h_ino, ino);
18611 + if (unlikely(err))
18612 + goto out_xinondir;
18616 + *ino = au_xino_new_ino(sb);
18617 + if (unlikely(!*ino))
18618 + goto out_xinondir;
18619 + err = au_xino_write(sb, bindex, h_ino, *ino);
18620 + if (unlikely(err))
18621 + goto out_xinondir;
18625 + if (isnondir && idx >= 0)
18626 + au_xinondir_leave(sb, bindex, h_ino, idx);
18631 +/* successful returns with iinfo write_locked */
18632 +/* todo: return with unlocked? */
18633 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18635 + struct inode *inode, *h_inode;
18636 + struct dentry *h_dentry;
18637 + struct super_block *sb;
18638 + ino_t h_ino, ino;
18639 + int err, idx, hlinked;
18640 + aufs_bindex_t btop;
18642 + sb = dentry->d_sb;
18643 + btop = au_dbtop(dentry);
18644 + h_dentry = au_h_dptr(dentry, btop);
18645 + h_inode = d_inode(h_dentry);
18646 + h_ino = h_inode->i_ino;
18647 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18651 + * stop 'race'-ing between hardlinks under different
18655 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18656 + inode = ERR_PTR(err);
18657 + if (unlikely(err))
18661 + err = au_xino_read(sb, btop, h_ino, &ino);
18662 + inode = ERR_PTR(err);
18663 + if (unlikely(err))
18664 + goto out_xinondir;
18667 + ino = au_xino_new_ino(sb);
18668 + if (unlikely(!ino)) {
18669 + inode = ERR_PTR(-EIO);
18670 + goto out_xinondir;
18674 + AuDbg("i%lu\n", (unsigned long)ino);
18675 + inode = au_iget_locked(sb, ino);
18676 + err = PTR_ERR(inode);
18677 + if (IS_ERR(inode))
18678 + goto out_xinondir;
18680 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18681 + if (inode->i_state & I_NEW) {
18682 + ii_write_lock_new_child(inode);
18683 + err = set_inode(inode, dentry);
18685 + unlock_new_inode(inode);
18686 + goto out_xinondir; /* success */
18690 + * iget_failed() calls iput(), but we need to call
18691 + * ii_write_unlock() after iget_failed(). so dirty hack for
18694 + atomic_inc(&inode->i_count);
18695 + iget_failed(inode);
18696 + ii_write_unlock(inode);
18697 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18698 + /* ignore this error */
18700 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18702 + * horrible race condition between lookup, readdir and copyup
18703 + * (or something).
18705 + if (hlinked && idx >= 0)
18706 + au_xinondir_leave(sb, btop, h_ino, idx);
18707 + err = reval_inode(inode, dentry);
18708 + if (unlikely(err < 0)) {
18713 + goto out; /* success */
18714 + else if (hlinked && idx >= 0) {
18715 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18716 + if (unlikely(err)) {
18718 + inode = ERR_PTR(err);
18724 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18725 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18726 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18727 + btop, au_sbtype(h_dentry->d_sb), dentry,
18728 + (unsigned long)h_ino, (unsigned long)ino);
18730 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18733 + if (hlinked && idx >= 0)
18734 + au_xinondir_leave(sb, btop, h_ino, idx);
18740 + inode = ERR_PTR(err);
18742 + if (hlinked && idx >= 0)
18743 + au_xinondir_leave(sb, btop, h_ino, idx);
18748 +/* ---------------------------------------------------------------------- */
18750 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18751 + struct inode *inode)
18754 + struct inode *hi;
18756 + err = au_br_rdonly(au_sbr(sb, bindex));
18758 + /* pseudo-link after flushed may happen out of bounds */
18761 + && au_ibtop(inode) <= bindex
18762 + && bindex <= au_ibbot(inode)) {
18764 + * permission check is unnecessary since vfsub routine
18765 + * will be called later
18767 + hi = au_h_iptr(inode, bindex);
18769 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18775 +int au_test_h_perm(struct inode *h_inode, int mask)
18777 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18779 + return inode_permission(h_inode, mask);
18782 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18784 + if (au_test_nfs(h_inode->i_sb)
18785 + && (mask & MAY_WRITE)
18786 + && S_ISDIR(h_inode->i_mode))
18787 + mask |= MAY_READ; /* force permission check */
18788 + return au_test_h_perm(h_inode, mask);
18790 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18791 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18792 +++ linux/fs/aufs/inode.h 2019-01-28 14:36:12.222418047 +0100
18794 +/* SPDX-License-Identifier: GPL-2.0 */
18796 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18798 + * This program, aufs is free software; you can redistribute it and/or modify
18799 + * it under the terms of the GNU General Public License as published by
18800 + * the Free Software Foundation; either version 2 of the License, or
18801 + * (at your option) any later version.
18803 + * This program is distributed in the hope that it will be useful,
18804 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18805 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18806 + * GNU General Public License for more details.
18808 + * You should have received a copy of the GNU General Public License
18809 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18813 + * inode operations
18816 +#ifndef __AUFS_INODE_H__
18817 +#define __AUFS_INODE_H__
18821 +#include <linux/fsnotify.h>
18822 +#include "rwsem.h"
18826 +struct au_hnotify {
18827 +#ifdef CONFIG_AUFS_HNOTIFY
18828 +#ifdef CONFIG_AUFS_HFSNOTIFY
18829 + /* never use fsnotify_add_vfsmount_mark() */
18830 + struct fsnotify_mark hn_mark;
18832 + struct inode *hn_aufs_inode; /* no get/put */
18833 + struct rcu_head rcu;
18835 +} ____cacheline_aligned_in_smp;
18837 +struct au_hinode {
18838 + struct inode *hi_inode;
18839 + aufs_bindex_t hi_id;
18840 +#ifdef CONFIG_AUFS_HNOTIFY
18841 + struct au_hnotify *hi_notify;
18844 + /* reference to the copied-up whiteout with get/put */
18845 + struct dentry *hi_whdentry;
18849 +#define AuIG_HALF_REFRESHED 1
18850 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18851 +#define au_ig_fset(flags, name) \
18852 + do { (flags) |= AuIG_##name; } while (0)
18853 +#define au_ig_fclr(flags, name) \
18854 + do { (flags) &= ~AuIG_##name; } while (0)
18857 + spinlock_t ig_spin;
18858 + __u32 ig_generation, ig_flags;
18863 + struct au_iigen ii_generation;
18864 + struct super_block *ii_hsb1; /* no get/put */
18866 + struct au_rwsem ii_rwsem;
18867 + aufs_bindex_t ii_btop, ii_bbot;
18869 + struct au_hinode *ii_hinode;
18870 + struct au_vdir *ii_vdir;
18873 +struct au_icntnr {
18874 + struct au_iinfo iinfo;
18875 + struct inode vfs_inode;
18876 + struct hlist_bl_node plink;
18877 + struct rcu_head rcu;
18878 +} ____cacheline_aligned_in_smp;
18880 +/* au_pin flags */
18881 +#define AuPin_DI_LOCKED 1
18882 +#define AuPin_MNT_WRITE (1 << 1)
18883 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18884 +#define au_fset_pin(flags, name) \
18885 + do { (flags) |= AuPin_##name; } while (0)
18886 +#define au_fclr_pin(flags, name) \
18887 + do { (flags) &= ~AuPin_##name; } while (0)
18891 + struct dentry *dentry;
18892 + unsigned int udba;
18893 + unsigned char lsc_di, lsc_hi, flags;
18894 + aufs_bindex_t bindex;
18897 + struct dentry *parent;
18898 + struct au_hinode *hdir;
18899 + struct vfsmount *h_mnt;
18901 + /* temporary unlock/relock for copyup */
18902 + struct dentry *h_dentry, *h_parent;
18903 + struct au_branch *br;
18904 + struct task_struct *task;
18907 +void au_pin_hdir_unlock(struct au_pin *p);
18908 +int au_pin_hdir_lock(struct au_pin *p);
18909 +int au_pin_hdir_relock(struct au_pin *p);
18910 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18911 +void au_pin_hdir_release(struct au_pin *p);
18913 +/* ---------------------------------------------------------------------- */
18915 +static inline struct au_iinfo *au_ii(struct inode *inode)
18917 + BUG_ON(is_bad_inode(inode));
18918 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18921 +/* ---------------------------------------------------------------------- */
18924 +struct inode *au_igrab(struct inode *inode);
18925 +void au_refresh_iop(struct inode *inode, int force_getattr);
18926 +int au_refresh_hinode_self(struct inode *inode);
18927 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18928 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18929 + unsigned int d_type, ino_t *ino);
18930 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18931 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18932 + struct inode *inode);
18933 +int au_test_h_perm(struct inode *h_inode, int mask);
18934 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18936 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18937 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18939 +#ifdef CONFIG_AUFS_SHWH
18940 + return au_ino(sb, bindex, h_ino, d_type, ino);
18953 +extern struct inode_operations aufs_iop[AuIop_Last],
18954 + aufs_iop_nogetattr[AuIop_Last];
18956 +/* au_wr_dir flags */
18957 +#define AuWrDir_ADD_ENTRY 1
18958 +#define AuWrDir_ISDIR (1 << 1)
18959 +#define AuWrDir_TMPFILE (1 << 2)
18960 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18961 +#define au_fset_wrdir(flags, name) \
18962 + do { (flags) |= AuWrDir_##name; } while (0)
18963 +#define au_fclr_wrdir(flags, name) \
18964 + do { (flags) &= ~AuWrDir_##name; } while (0)
18966 +struct au_wr_dir_args {
18967 + aufs_bindex_t force_btgt;
18968 + unsigned char flags;
18970 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18971 + struct au_wr_dir_args *args);
18973 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18974 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18975 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18976 + unsigned int udba, unsigned char flags);
18977 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18978 + unsigned int udba, unsigned char flags) __must_check;
18979 +int au_do_pin(struct au_pin *pin) __must_check;
18980 +void au_unpin(struct au_pin *pin);
18981 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18983 +#define AuIcpup_DID_CPUP 1
18984 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18985 +#define au_fset_icpup(flags, name) \
18986 + do { (flags) |= AuIcpup_##name; } while (0)
18987 +#define au_fclr_icpup(flags, name) \
18988 + do { (flags) &= ~AuIcpup_##name; } while (0)
18990 +struct au_icpup_args {
18991 + unsigned char flags;
18992 + unsigned char pin_flags;
18993 + aufs_bindex_t btgt;
18994 + unsigned int udba;
18995 + struct au_pin pin;
18996 + struct path h_path;
18997 + struct inode *h_inode;
19000 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19001 + struct au_icpup_args *a);
19003 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19007 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19008 + struct dentry *h_parent, int isdir);
19009 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19011 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
19012 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19014 +struct vfsub_aopen_args;
19015 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19016 + struct vfsub_aopen_args *args);
19017 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
19018 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
19019 + struct dentry *dentry);
19020 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
19023 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
19024 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19025 + struct dentry *h_parent, int isdir);
19026 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
19027 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19030 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19031 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19032 + struct inode *dir, struct dentry *dentry,
19033 + unsigned int flags);
19036 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19037 +void au_hiput(struct au_hinode *hinode);
19038 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19039 + struct dentry *h_wh);
19040 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19042 +/* hinode flags */
19043 +#define AuHi_XINO 1
19044 +#define AuHi_HNOTIFY (1 << 1)
19045 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19046 +#define au_fset_hi(flags, name) \
19047 + do { (flags) |= AuHi_##name; } while (0)
19048 +#define au_fclr_hi(flags, name) \
19049 + do { (flags) &= ~AuHi_##name; } while (0)
19051 +#ifndef CONFIG_AUFS_HNOTIFY
19052 +#undef AuHi_HNOTIFY
19053 +#define AuHi_HNOTIFY 0
19056 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19057 + struct inode *h_inode, unsigned int flags);
19059 +void au_update_iigen(struct inode *inode, int half);
19060 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19062 +void au_icntnr_init_once(void *_c);
19063 +void au_hinode_init(struct au_hinode *hinode);
19064 +int au_iinfo_init(struct inode *inode);
19065 +void au_iinfo_fin(struct inode *inode);
19066 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19068 +#ifdef CONFIG_PROC_FS
19070 +int au_plink_maint(struct super_block *sb, int flags);
19072 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19073 +int au_plink_maint_enter(struct super_block *sb);
19074 +#ifdef CONFIG_AUFS_DEBUG
19075 +void au_plink_list(struct super_block *sb);
19077 +AuStubVoid(au_plink_list, struct super_block *sb)
19079 +int au_plink_test(struct inode *inode);
19080 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19081 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19082 + struct dentry *h_dentry);
19083 +void au_plink_put(struct super_block *sb, int verbose);
19084 +void au_plink_clean(struct super_block *sb, int verbose);
19085 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19087 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19088 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19089 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19090 +AuStubVoid(au_plink_list, struct super_block *sb);
19091 +AuStubInt0(au_plink_test, struct inode *inode);
19092 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19093 + struct inode *inode, aufs_bindex_t bindex);
19094 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19095 + struct dentry *h_dentry);
19096 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19097 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19098 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19099 +#endif /* CONFIG_PROC_FS */
19101 +#ifdef CONFIG_AUFS_XATTR
19103 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19104 + unsigned int verbose);
19105 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19106 +void au_xattr_init(struct super_block *sb);
19108 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19109 + int ignore_flags, unsigned int verbose);
19110 +AuStubVoid(au_xattr_init, struct super_block *sb);
19113 +#ifdef CONFIG_FS_POSIX_ACL
19114 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19115 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19118 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19124 +struct au_sxattr {
19128 + const char *name;
19129 + const void *value;
19134 + struct posix_acl *acl;
19139 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19140 + struct au_sxattr *arg);
19143 +/* ---------------------------------------------------------------------- */
19145 +/* lock subclass for iinfo */
19147 + AuLsc_II_CHILD, /* child first */
19148 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19149 + AuLsc_II_CHILD3, /* copyup dirs */
19150 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19151 + AuLsc_II_PARENT2,
19152 + AuLsc_II_PARENT3, /* copyup dirs */
19153 + AuLsc_II_NEW_CHILD
19157 + * ii_read_lock_child, ii_write_lock_child,
19158 + * ii_read_lock_child2, ii_write_lock_child2,
19159 + * ii_read_lock_child3, ii_write_lock_child3,
19160 + * ii_read_lock_parent, ii_write_lock_parent,
19161 + * ii_read_lock_parent2, ii_write_lock_parent2,
19162 + * ii_read_lock_parent3, ii_write_lock_parent3,
19163 + * ii_read_lock_new_child, ii_write_lock_new_child,
19165 +#define AuReadLockFunc(name, lsc) \
19166 +static inline void ii_read_lock_##name(struct inode *i) \
19168 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19171 +#define AuWriteLockFunc(name, lsc) \
19172 +static inline void ii_write_lock_##name(struct inode *i) \
19174 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19177 +#define AuRWLockFuncs(name, lsc) \
19178 + AuReadLockFunc(name, lsc) \
19179 + AuWriteLockFunc(name, lsc)
19181 +AuRWLockFuncs(child, CHILD);
19182 +AuRWLockFuncs(child2, CHILD2);
19183 +AuRWLockFuncs(child3, CHILD3);
19184 +AuRWLockFuncs(parent, PARENT);
19185 +AuRWLockFuncs(parent2, PARENT2);
19186 +AuRWLockFuncs(parent3, PARENT3);
19187 +AuRWLockFuncs(new_child, NEW_CHILD);
19189 +#undef AuReadLockFunc
19190 +#undef AuWriteLockFunc
19191 +#undef AuRWLockFuncs
19193 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19194 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19195 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19197 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19198 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19199 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19201 +/* ---------------------------------------------------------------------- */
19203 +static inline void au_icntnr_init(struct au_icntnr *c)
19205 +#ifdef CONFIG_AUFS_DEBUG
19206 + c->vfs_inode.i_mode = 0;
19210 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19212 + unsigned int gen;
19213 + struct au_iinfo *iinfo;
19214 + struct au_iigen *iigen;
19216 + iinfo = au_ii(inode);
19217 + iigen = &iinfo->ii_generation;
19218 + spin_lock(&iigen->ig_spin);
19220 + *igflags = iigen->ig_flags;
19221 + gen = iigen->ig_generation;
19222 + spin_unlock(&iigen->ig_spin);
19227 +/* tiny test for inode number */
19228 +/* tmpfs generation is too rough */
19229 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19231 + struct au_iinfo *iinfo;
19233 + iinfo = au_ii(inode);
19234 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19235 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19236 + && iinfo->ii_higen == h_inode->i_generation);
19239 +static inline void au_iigen_dec(struct inode *inode)
19241 + struct au_iinfo *iinfo;
19242 + struct au_iigen *iigen;
19244 + iinfo = au_ii(inode);
19245 + iigen = &iinfo->ii_generation;
19246 + spin_lock(&iigen->ig_spin);
19247 + iigen->ig_generation--;
19248 + spin_unlock(&iigen->ig_spin);
19251 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19256 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19262 +/* ---------------------------------------------------------------------- */
19264 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19265 + aufs_bindex_t bindex)
19267 + return iinfo->ii_hinode + bindex;
19270 +static inline int au_is_bad_inode(struct inode *inode)
19272 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19275 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19276 + aufs_bindex_t bindex)
19278 + IiMustAnyLock(inode);
19279 + return au_hinode(au_ii(inode), bindex)->hi_id;
19282 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19284 + IiMustAnyLock(inode);
19285 + return au_ii(inode)->ii_btop;
19288 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19290 + IiMustAnyLock(inode);
19291 + return au_ii(inode)->ii_bbot;
19294 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19296 + IiMustAnyLock(inode);
19297 + return au_ii(inode)->ii_vdir;
19300 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19302 + IiMustAnyLock(inode);
19303 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19306 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19308 + IiMustWriteLock(inode);
19309 + au_ii(inode)->ii_btop = bindex;
19312 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19314 + IiMustWriteLock(inode);
19315 + au_ii(inode)->ii_bbot = bindex;
19318 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19320 + IiMustWriteLock(inode);
19321 + au_ii(inode)->ii_vdir = vdir;
19324 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19326 + IiMustAnyLock(inode);
19327 + return au_hinode(au_ii(inode), bindex);
19330 +/* ---------------------------------------------------------------------- */
19332 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19335 + return pin->parent;
19339 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19341 + if (pin && pin->hdir)
19342 + return pin->hdir->hi_inode;
19346 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19349 + return pin->hdir;
19353 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19356 + pin->dentry = dentry;
19359 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19360 + unsigned char lflag)
19364 + au_fset_pin(pin->flags, DI_LOCKED);
19366 + au_fclr_pin(pin->flags, DI_LOCKED);
19370 +#if 0 /* reserved */
19371 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19374 + dput(pin->parent);
19375 + pin->parent = dget(parent);
19380 +/* ---------------------------------------------------------------------- */
19383 +#ifdef CONFIG_AUFS_HNOTIFY
19384 +struct au_hnotify_op {
19385 + void (*ctl)(struct au_hinode *hinode, int do_set);
19386 + int (*alloc)(struct au_hinode *hinode);
19389 + * if it returns true, the the caller should free hinode->hi_notify,
19390 + * otherwise ->free() frees it.
19392 + int (*free)(struct au_hinode *hinode,
19393 + struct au_hnotify *hn) __must_check;
19395 + void (*fin)(void);
19396 + int (*init)(void);
19398 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19399 + void (*fin_br)(struct au_branch *br);
19400 + int (*init_br)(struct au_branch *br, int perm);
19404 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19405 +void au_hn_free(struct au_hinode *hinode);
19406 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19407 +void au_hn_reset(struct inode *inode, unsigned int flags);
19408 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19409 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19410 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19411 +int au_hnotify_init_br(struct au_branch *br, int perm);
19412 +void au_hnotify_fin_br(struct au_branch *br);
19413 +int __init au_hnotify_init(void);
19414 +void au_hnotify_fin(void);
19417 +extern const struct au_hnotify_op au_hnotify_op;
19420 +void au_hn_init(struct au_hinode *hinode)
19422 + hinode->hi_notify = NULL;
19425 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19427 + return hinode->hi_notify;
19431 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19432 + struct au_hinode *hinode __maybe_unused,
19433 + struct inode *inode __maybe_unused)
19434 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19435 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19436 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19437 + int do_set __maybe_unused)
19438 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19439 + unsigned int flags __maybe_unused)
19440 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19441 + struct au_branch *br __maybe_unused,
19442 + int perm __maybe_unused)
19443 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19444 + int perm __maybe_unused)
19445 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19446 +AuStubInt0(__init au_hnotify_init, void)
19447 +AuStubVoid(au_hnotify_fin, void)
19448 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19449 +#endif /* CONFIG_AUFS_HNOTIFY */
19451 +static inline void au_hn_suspend(struct au_hinode *hdir)
19453 + au_hn_ctl(hdir, /*do_set*/0);
19456 +static inline void au_hn_resume(struct au_hinode *hdir)
19458 + au_hn_ctl(hdir, /*do_set*/1);
19461 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19463 + inode_lock(hdir->hi_inode);
19464 + au_hn_suspend(hdir);
19467 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19468 + unsigned int sc __maybe_unused)
19470 + inode_lock_nested(hdir->hi_inode, sc);
19471 + au_hn_suspend(hdir);
19474 +#if 0 /* unused */
19475 +#include "vfsub.h"
19476 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19479 + inode_lock_shared_nested(hdir->hi_inode, sc);
19480 + au_hn_suspend(hdir);
19484 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19486 + au_hn_resume(hdir);
19487 + inode_unlock(hdir->hi_inode);
19490 +#endif /* __KERNEL__ */
19491 +#endif /* __AUFS_INODE_H__ */
19492 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19493 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19494 +++ linux/fs/aufs/ioctl.c 2019-01-28 14:36:12.222418047 +0100
19496 +// SPDX-License-Identifier: GPL-2.0
19498 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19500 + * This program, aufs is free software; you can redistribute it and/or modify
19501 + * it under the terms of the GNU General Public License as published by
19502 + * the Free Software Foundation; either version 2 of the License, or
19503 + * (at your option) any later version.
19505 + * This program is distributed in the hope that it will be useful,
19506 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19508 + * GNU General Public License for more details.
19510 + * You should have received a copy of the GNU General Public License
19511 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19516 + * plink-management and readdir in userspace.
19517 + * assist the pathconf(3) wrapper library.
19519 + * File-based Hierarchical Storage Management.
19522 +#include <linux/compat.h>
19523 +#include <linux/file.h>
19526 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19529 + aufs_bindex_t wbi, bindex, bbot;
19530 + struct file *h_file;
19531 + struct super_block *sb;
19532 + struct dentry *root;
19533 + struct au_branch *br;
19534 + struct aufs_wbr_fd wbrfd = {
19535 + .oflags = au_dir_roflags,
19538 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19539 + | O_NOATIME | O_CLOEXEC;
19541 + AuDebugOn(wbrfd.oflags & ~valid);
19544 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19545 + if (unlikely(err)) {
19551 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19552 + wbrfd.oflags |= au_dir_roflags;
19553 + AuDbg("0%o\n", wbrfd.oflags);
19554 + if (unlikely(wbrfd.oflags & ~valid))
19558 + fd = get_unused_fd_flags(0);
19560 + if (unlikely(fd < 0))
19563 + h_file = ERR_PTR(-EINVAL);
19566 + sb = path->dentry->d_sb;
19567 + root = sb->s_root;
19568 + aufs_read_lock(root, AuLock_IR);
19569 + bbot = au_sbbot(sb);
19570 + if (wbrfd.brid >= 0) {
19571 + wbi = au_br_index(sb, wbrfd.brid);
19572 + if (unlikely(wbi < 0 || wbi > bbot))
19576 + h_file = ERR_PTR(-ENOENT);
19577 + br = au_sbr(sb, wbi);
19578 + if (!au_br_writable(br->br_perm)) {
19582 + bindex = wbi + 1;
19584 + for (; bindex <= bbot; bindex++) {
19585 + br = au_sbr(sb, bindex);
19586 + if (au_br_writable(br->br_perm)) {
19588 + br = au_sbr(sb, wbi);
19593 + AuDbg("wbi %d\n", wbi);
19595 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19599 + aufs_read_unlock(root, AuLock_IR);
19600 + err = PTR_ERR(h_file);
19601 + if (IS_ERR(h_file))
19604 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19605 + fd_install(fd, h_file);
19607 + goto out; /* success */
19610 + put_unused_fd(fd);
19616 +/* ---------------------------------------------------------------------- */
19618 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19621 + struct dentry *dentry;
19624 + case AUFS_CTL_RDU:
19625 + case AUFS_CTL_RDU_INO:
19626 + err = au_rdu_ioctl(file, cmd, arg);
19629 + case AUFS_CTL_WBR_FD:
19630 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19633 + case AUFS_CTL_IBUSY:
19634 + err = au_ibusy_ioctl(file, arg);
19637 + case AUFS_CTL_BRINFO:
19638 + err = au_brinfo_ioctl(file, arg);
19641 + case AUFS_CTL_FHSM_FD:
19642 + dentry = file->f_path.dentry;
19643 + if (IS_ROOT(dentry))
19644 + err = au_fhsm_fd(dentry->d_sb, arg);
19650 + /* do not call the lower */
19651 + AuDbg("0x%x\n", cmd);
19659 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19664 + case AUFS_CTL_MVDOWN:
19665 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19668 + case AUFS_CTL_WBR_FD:
19669 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19673 + /* do not call the lower */
19674 + AuDbg("0x%x\n", cmd);
19682 +#ifdef CONFIG_COMPAT
19683 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19684 + unsigned long arg)
19689 + case AUFS_CTL_RDU:
19690 + case AUFS_CTL_RDU_INO:
19691 + err = au_rdu_compat_ioctl(file, cmd, arg);
19694 + case AUFS_CTL_IBUSY:
19695 + err = au_ibusy_compat_ioctl(file, arg);
19698 + case AUFS_CTL_BRINFO:
19699 + err = au_brinfo_compat_ioctl(file, arg);
19703 + err = aufs_ioctl_dir(file, cmd, arg);
19710 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19711 + unsigned long arg)
19713 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19716 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19717 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19718 +++ linux/fs/aufs/i_op_add.c 2019-01-28 14:36:12.222418047 +0100
19720 +// SPDX-License-Identifier: GPL-2.0
19722 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19724 + * This program, aufs is free software; you can redistribute it and/or modify
19725 + * it under the terms of the GNU General Public License as published by
19726 + * the Free Software Foundation; either version 2 of the License, or
19727 + * (at your option) any later version.
19729 + * This program is distributed in the hope that it will be useful,
19730 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19731 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19732 + * GNU General Public License for more details.
19734 + * You should have received a copy of the GNU General Public License
19735 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19739 + * inode operations (add entry)
19745 + * final procedure of adding a new entry, except link(2).
19746 + * remove whiteout, instantiate, copyup the parent dir's times and size
19747 + * and update version.
19748 + * if it failed, re-create the removed whiteout.
19750 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19751 + struct dentry *wh_dentry, struct dentry *dentry)
19754 + aufs_bindex_t bwh;
19755 + struct path h_path;
19756 + struct super_block *sb;
19757 + struct inode *inode, *h_dir;
19758 + struct dentry *wh;
19763 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19764 + IMustLock(h_dir);
19765 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19766 + bwh = au_dbwh(dentry);
19767 + h_path.dentry = wh_dentry;
19768 + h_path.mnt = au_sbr_mnt(sb, bindex);
19769 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19771 + if (unlikely(err))
19775 + inode = au_new_inode(dentry, /*must_new*/1);
19776 + if (!IS_ERR(inode)) {
19777 + d_instantiate(dentry, inode);
19778 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19780 + au_dir_ts(dir, bindex);
19781 + inode_inc_iversion(dir);
19782 + au_fhsm_wrote(sb, bindex, /*force*/0);
19783 + return 0; /* success */
19786 + err = PTR_ERR(inode);
19791 + /* dir inode is locked */
19792 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19793 + rerr = PTR_ERR(wh);
19794 + if (IS_ERR(wh)) {
19795 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19796 + dentry, err, rerr);
19805 +static int au_d_may_add(struct dentry *dentry)
19810 + if (unlikely(d_unhashed(dentry)))
19812 + if (unlikely(d_really_is_positive(dentry)))
19818 + * simple tests for the adding inode operations.
19819 + * following the checks in vfs, plus the parent-child relationship.
19821 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19822 + struct dentry *h_parent, int isdir)
19826 + struct dentry *h_dentry;
19827 + struct inode *h_inode;
19829 + err = -ENAMETOOLONG;
19830 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19833 + h_dentry = au_h_dptr(dentry, bindex);
19834 + if (d_really_is_negative(dentry)) {
19836 + if (unlikely(d_is_positive(h_dentry)))
19839 + /* rename(2) case */
19841 + if (unlikely(d_is_negative(h_dentry)))
19843 + h_inode = d_inode(h_dentry);
19844 + if (unlikely(!h_inode->i_nlink))
19847 + h_mode = h_inode->i_mode;
19850 + if (unlikely(S_ISDIR(h_mode)))
19852 + } else if (unlikely(!S_ISDIR(h_mode))) {
19859 + /* expected parent dir is locked */
19860 + if (unlikely(h_parent != h_dentry->d_parent))
19869 + * initial procedure of adding a new entry.
19870 + * prepare writable branch and the parent dir, lock it,
19871 + * and lookup whiteout for the new entry.
19873 +static struct dentry*
19874 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19875 + struct dentry *src_dentry, struct au_pin *pin,
19876 + struct au_wr_dir_args *wr_dir_args)
19878 + struct dentry *wh_dentry, *h_parent;
19879 + struct super_block *sb;
19880 + struct au_branch *br;
19882 + unsigned int udba;
19883 + aufs_bindex_t bcpup;
19885 + AuDbg("%pd\n", dentry);
19887 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19889 + wh_dentry = ERR_PTR(err);
19890 + if (unlikely(err < 0))
19893 + sb = dentry->d_sb;
19894 + udba = au_opt_udba(sb);
19895 + err = au_pin(pin, dentry, bcpup, udba,
19896 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19897 + wh_dentry = ERR_PTR(err);
19898 + if (unlikely(err))
19901 + h_parent = au_pinned_h_parent(pin);
19902 + if (udba != AuOpt_UDBA_NONE
19903 + && au_dbtop(dentry) == bcpup)
19904 + err = au_may_add(dentry, bcpup, h_parent,
19905 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19906 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19907 + err = -ENAMETOOLONG;
19908 + wh_dentry = ERR_PTR(err);
19909 + if (unlikely(err))
19912 + br = au_sbr(sb, bcpup);
19914 + struct path tmp = {
19915 + .dentry = h_parent,
19916 + .mnt = au_br_mnt(br)
19918 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19921 + wh_dentry = NULL;
19922 + if (bcpup != au_dbwh(dentry))
19923 + goto out; /* success */
19926 + * ENAMETOOLONG here means that if we allowed create such name, then it
19927 + * would not be able to removed in the future. So we don't allow such
19928 + * name here and we don't handle ENAMETOOLONG differently here.
19930 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19933 + if (IS_ERR(wh_dentry))
19936 + return wh_dentry;
19939 +/* ---------------------------------------------------------------------- */
19941 +enum { Mknod, Symlink, Creat };
19942 +struct simple_arg {
19949 + struct vfsub_aopen_args *aopen;
19952 + const char *symname;
19961 +static int add_simple(struct inode *dir, struct dentry *dentry,
19962 + struct simple_arg *arg)
19965 + aufs_bindex_t btop;
19966 + unsigned char created;
19967 + const unsigned char try_aopen
19968 + = (arg->type == Creat && arg->u.c.try_aopen);
19969 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19970 + struct dentry *wh_dentry, *parent;
19971 + struct inode *h_dir;
19972 + struct super_block *sb;
19973 + struct au_branch *br;
19974 + /* to reduce stack size */
19976 + struct au_dtime dt;
19977 + struct au_pin pin;
19978 + struct path h_path;
19979 + struct au_wr_dir_args wr_dir_args;
19982 + AuDbg("%pd\n", dentry);
19986 + a = kmalloc(sizeof(*a), GFP_NOFS);
19987 + if (unlikely(!a))
19989 + a->wr_dir_args.force_btgt = -1;
19990 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19992 + parent = dentry->d_parent; /* dir inode is locked */
19993 + if (!try_aopen) {
19994 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19995 + if (unlikely(err))
19998 + err = au_d_may_add(dentry);
19999 + if (unlikely(err))
20002 + di_write_lock_parent(parent);
20003 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20004 + &a->pin, &a->wr_dir_args);
20005 + err = PTR_ERR(wh_dentry);
20006 + if (IS_ERR(wh_dentry))
20009 + btop = au_dbtop(dentry);
20010 + sb = dentry->d_sb;
20011 + br = au_sbr(sb, btop);
20012 + a->h_path.dentry = au_h_dptr(dentry, btop);
20013 + a->h_path.mnt = au_br_mnt(br);
20014 + h_dir = au_pinned_h_dir(&a->pin);
20015 + switch (arg->type) {
20017 + if (!try_aopen || !h_dir->i_op->atomic_open) {
20018 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
20019 + arg->u.c.want_excl);
20021 + if (!err && try_aopen)
20022 + aopen->file->f_mode |= FMODE_CREATED;
20025 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
20026 + AuDbg("err %d\n", err);
20027 + AuDbgFile(aopen->file);
20028 + created = err >= 0
20029 + && !!(aopen->file->f_mode & FMODE_CREATED);
20033 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20037 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20044 + if (unlikely(err < 0))
20047 + err = epilog(dir, btop, wh_dentry, dentry);
20049 + goto out_unpin; /* success */
20052 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20053 + /* no delegation since it is just created */
20054 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20057 + AuIOErr("%pd revert failure(%d, %d)\n",
20058 + dentry, err, rerr);
20061 + au_dtime_revert(&a->dt);
20063 + if (try_aopen && h_dir->i_op->atomic_open
20064 + && (aopen->file->f_mode & FMODE_OPENED))
20065 + /* aopen->file is still opened */
20066 + au_lcnt_dec(&aopen->br->br_nfiles);
20069 + au_unpin(&a->pin);
20073 + di_write_unlock(parent);
20075 + if (unlikely(err)) {
20076 + au_update_dbtop(dentry);
20080 + aufs_read_unlock(dentry, AuLock_DW);
20087 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20090 + struct simple_arg arg = {
20097 + return add_simple(dir, dentry, &arg);
20100 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20102 + struct simple_arg arg = {
20104 + .u.s.symname = symname
20106 + return add_simple(dir, dentry, &arg);
20109 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20112 + struct simple_arg arg = {
20116 + .want_excl = want_excl
20119 + return add_simple(dir, dentry, &arg);
20122 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20123 + struct vfsub_aopen_args *aopen_args)
20125 + struct simple_arg arg = {
20128 + .mode = aopen_args->create_mode,
20129 + .want_excl = aopen_args->open_flag & O_EXCL,
20130 + .try_aopen = true,
20131 + .aopen = aopen_args
20134 + return add_simple(dir, dentry, &arg);
20137 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20140 + aufs_bindex_t bindex;
20141 + struct super_block *sb;
20142 + struct dentry *parent, *h_parent, *h_dentry;
20143 + struct inode *h_dir, *inode;
20144 + struct vfsmount *h_mnt;
20145 + struct au_wr_dir_args wr_dir_args = {
20146 + .force_btgt = -1,
20147 + .flags = AuWrDir_TMPFILE
20150 + /* copy-up may happen */
20154 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20155 + if (unlikely(err))
20158 + err = au_di_init(dentry);
20159 + if (unlikely(err))
20163 + parent = d_find_any_alias(dir);
20164 + AuDebugOn(!parent);
20165 + di_write_lock_parent(parent);
20166 + if (unlikely(d_inode(parent) != dir))
20169 + err = au_digen_test(parent, au_sigen(sb));
20170 + if (unlikely(err))
20173 + bindex = au_dbtop(parent);
20174 + au_set_dbtop(dentry, bindex);
20175 + au_set_dbbot(dentry, bindex);
20176 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20178 + if (unlikely(err < 0))
20181 + err = -EOPNOTSUPP;
20182 + h_dir = au_h_iptr(dir, bindex);
20183 + if (unlikely(!h_dir->i_op->tmpfile))
20186 + h_mnt = au_sbr_mnt(sb, bindex);
20187 + err = vfsub_mnt_want_write(h_mnt);
20188 + if (unlikely(err))
20191 + h_parent = au_h_dptr(parent, bindex);
20192 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20193 + if (IS_ERR(h_dentry)) {
20194 + err = PTR_ERR(h_dentry);
20198 + au_set_dbtop(dentry, bindex);
20199 + au_set_dbbot(dentry, bindex);
20200 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20201 + inode = au_new_inode(dentry, /*must_new*/1);
20202 + if (IS_ERR(inode)) {
20203 + err = PTR_ERR(inode);
20204 + au_set_h_dptr(dentry, bindex, NULL);
20205 + au_set_dbtop(dentry, -1);
20206 + au_set_dbbot(dentry, -1);
20208 + if (!inode->i_nlink)
20209 + set_nlink(inode, 1);
20210 + d_tmpfile(dentry, inode);
20211 + au_di(dentry)->di_tmpfile = 1;
20213 + /* update without i_mutex */
20214 + if (au_ibtop(dir) == au_dbtop(dentry))
20215 + au_cpup_attr_timesizes(dir);
20220 + vfsub_mnt_drop_write(h_mnt);
20222 + di_write_unlock(parent);
20224 + di_write_unlock(dentry);
20225 + if (unlikely(err)) {
20226 + au_di_fin(dentry);
20227 + dentry->d_fsdata = NULL;
20230 + si_read_unlock(sb);
20232 + inode_unlock(dir);
20236 +/* ---------------------------------------------------------------------- */
20238 +struct au_link_args {
20239 + aufs_bindex_t bdst, bsrc;
20240 + struct au_pin pin;
20241 + struct path h_path;
20242 + struct dentry *src_parent, *parent;
20245 +static int au_cpup_before_link(struct dentry *src_dentry,
20246 + struct au_link_args *a)
20249 + struct dentry *h_src_dentry;
20250 + struct au_cp_generic cpg = {
20251 + .dentry = src_dentry,
20256 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20259 + di_read_lock_parent(a->src_parent, AuLock_IR);
20260 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20261 + if (unlikely(err))
20264 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20265 + err = au_pin(&a->pin, src_dentry, a->bdst,
20266 + au_opt_udba(src_dentry->d_sb),
20267 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20268 + if (unlikely(err))
20271 + err = au_sio_cpup_simple(&cpg);
20272 + au_unpin(&a->pin);
20275 + di_read_unlock(a->src_parent, AuLock_IR);
20279 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20280 + struct au_link_args *a)
20283 + unsigned char plink;
20284 + aufs_bindex_t bbot;
20285 + struct dentry *h_src_dentry;
20286 + struct inode *h_inode, *inode, *delegated;
20287 + struct super_block *sb;
20288 + struct file *h_file;
20292 + sb = src_dentry->d_sb;
20293 + inode = d_inode(src_dentry);
20294 + if (au_ibtop(inode) <= a->bdst)
20295 + h_inode = au_h_iptr(inode, a->bdst);
20296 + if (!h_inode || !h_inode->i_nlink) {
20297 + /* copyup src_dentry as the name of dentry. */
20298 + bbot = au_dbbot(dentry);
20299 + if (bbot < a->bsrc)
20300 + au_set_dbbot(dentry, a->bsrc);
20301 + au_set_h_dptr(dentry, a->bsrc,
20302 + dget(au_h_dptr(src_dentry, a->bsrc)));
20303 + dget(a->h_path.dentry);
20304 + au_set_h_dptr(dentry, a->bdst, NULL);
20305 + AuDbg("temporary d_inode...\n");
20306 + spin_lock(&dentry->d_lock);
20307 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20308 + spin_unlock(&dentry->d_lock);
20309 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20310 + if (IS_ERR(h_file))
20311 + err = PTR_ERR(h_file);
20313 + struct au_cp_generic cpg = {
20314 + .dentry = dentry,
20319 + .flags = AuCpup_KEEPLINO
20321 + err = au_sio_cpup_simple(&cpg);
20322 + au_h_open_post(dentry, a->bsrc, h_file);
20324 + dput(a->h_path.dentry);
20325 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20327 + au_set_h_dptr(dentry, a->bdst,
20328 + a->h_path.dentry);
20330 + spin_lock(&dentry->d_lock);
20331 + dentry->d_inode = NULL; /* restore */
20332 + spin_unlock(&dentry->d_lock);
20333 + AuDbg("temporary d_inode...done\n");
20334 + au_set_h_dptr(dentry, a->bsrc, NULL);
20335 + au_set_dbbot(dentry, bbot);
20337 + /* the inode of src_dentry already exists on a.bdst branch */
20338 + h_src_dentry = d_find_alias(h_inode);
20339 + if (!h_src_dentry && au_plink_test(inode)) {
20341 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20342 + err = PTR_ERR(h_src_dentry);
20343 + if (IS_ERR(h_src_dentry))
20346 + if (unlikely(d_is_negative(h_src_dentry))) {
20347 + dput(h_src_dentry);
20348 + h_src_dentry = NULL;
20352 + if (h_src_dentry) {
20353 + delegated = NULL;
20354 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20355 + &a->h_path, &delegated);
20356 + if (unlikely(err == -EWOULDBLOCK)) {
20357 + pr_warn("cannot retry for NFSv4 delegation"
20358 + " for an internal link\n");
20361 + dput(h_src_dentry);
20363 + AuIOErr("no dentry found for hi%lu on b%d\n",
20364 + h_inode->i_ino, a->bdst);
20369 + if (!err && !plink)
20370 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20377 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20378 + struct dentry *dentry)
20381 + struct au_dtime dt;
20382 + struct au_link_args *a;
20383 + struct dentry *wh_dentry, *h_src_dentry;
20384 + struct inode *inode, *delegated;
20385 + struct super_block *sb;
20386 + struct au_wr_dir_args wr_dir_args = {
20387 + /* .force_btgt = -1, */
20388 + .flags = AuWrDir_ADD_ENTRY
20392 + inode = d_inode(src_dentry);
20393 + IMustLock(inode);
20396 + a = kzalloc(sizeof(*a), GFP_NOFS);
20397 + if (unlikely(!a))
20400 + a->parent = dentry->d_parent; /* dir inode is locked */
20401 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20402 + AuLock_NOPLM | AuLock_GEN);
20403 + if (unlikely(err))
20405 + err = au_d_linkable(src_dentry);
20406 + if (unlikely(err))
20408 + err = au_d_may_add(dentry);
20409 + if (unlikely(err))
20412 + a->src_parent = dget_parent(src_dentry);
20413 + wr_dir_args.force_btgt = au_ibtop(inode);
20415 + di_write_lock_parent(a->parent);
20416 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20417 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20419 + err = PTR_ERR(wh_dentry);
20420 + if (IS_ERR(wh_dentry))
20424 + sb = dentry->d_sb;
20425 + a->bdst = au_dbtop(dentry);
20426 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20427 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20428 + a->bsrc = au_ibtop(inode);
20429 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20430 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20431 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20432 + if (!h_src_dentry) {
20433 + a->bsrc = au_dbtop(src_dentry);
20434 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20435 + AuDebugOn(!h_src_dentry);
20436 + } else if (IS_ERR(h_src_dentry)) {
20437 + err = PTR_ERR(h_src_dentry);
20442 + * aufs doesn't touch the credential so
20443 + * security_dentry_create_files_as() is unnecessary.
20445 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20446 + if (a->bdst < a->bsrc
20447 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20448 + err = au_cpup_or_link(src_dentry, dentry, a);
20450 + delegated = NULL;
20451 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20452 + &a->h_path, &delegated);
20453 + if (unlikely(err == -EWOULDBLOCK)) {
20454 + pr_warn("cannot retry for NFSv4 delegation"
20455 + " for an internal link\n");
20459 + dput(h_src_dentry);
20462 + * copyup src_dentry to the branch we process,
20463 + * and then link(2) to it.
20465 + dput(h_src_dentry);
20466 + if (a->bdst < a->bsrc
20467 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20468 + au_unpin(&a->pin);
20469 + di_write_unlock(a->parent);
20470 + err = au_cpup_before_link(src_dentry, a);
20471 + di_write_lock_parent(a->parent);
20473 + err = au_pin(&a->pin, dentry, a->bdst,
20475 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20476 + if (unlikely(err))
20480 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20482 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20483 + delegated = NULL;
20484 + err = vfsub_link(h_src_dentry,
20485 + au_pinned_h_dir(&a->pin),
20486 + &a->h_path, &delegated);
20487 + if (unlikely(err == -EWOULDBLOCK)) {
20488 + pr_warn("cannot retry"
20489 + " for NFSv4 delegation"
20490 + " for an internal link\n");
20496 + if (unlikely(err))
20500 + a->h_path.dentry = wh_dentry;
20501 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20503 + if (unlikely(err))
20507 + au_dir_ts(dir, a->bdst);
20508 + inode_inc_iversion(dir);
20509 + inc_nlink(inode);
20510 + inode->i_ctime = dir->i_ctime;
20511 + d_instantiate(dentry, au_igrab(inode));
20512 + if (d_unhashed(a->h_path.dentry))
20513 + /* some filesystem calls d_drop() */
20515 + /* some filesystems consume an inode even hardlink */
20516 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20517 + goto out_unpin; /* success */
20520 + /* no delegation since it is just created */
20521 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20522 + /*delegated*/NULL, /*force*/0);
20523 + if (unlikely(rerr)) {
20524 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20527 + au_dtime_revert(&dt);
20529 + au_unpin(&a->pin);
20533 + di_write_unlock(a->parent);
20534 + dput(a->src_parent);
20536 + if (unlikely(err)) {
20537 + au_update_dbtop(dentry);
20540 + aufs_read_and_write_unlock2(dentry, src_dentry);
20548 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20551 + aufs_bindex_t bindex;
20552 + unsigned char diropq;
20553 + struct path h_path;
20554 + struct dentry *wh_dentry, *parent, *opq_dentry;
20555 + struct inode *h_inode;
20556 + struct super_block *sb;
20558 + struct au_pin pin;
20559 + struct au_dtime dt;
20560 + } *a; /* reduce the stack usage */
20561 + struct au_wr_dir_args wr_dir_args = {
20562 + .force_btgt = -1,
20563 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20569 + a = kmalloc(sizeof(*a), GFP_NOFS);
20570 + if (unlikely(!a))
20573 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20574 + if (unlikely(err))
20576 + err = au_d_may_add(dentry);
20577 + if (unlikely(err))
20580 + parent = dentry->d_parent; /* dir inode is locked */
20581 + di_write_lock_parent(parent);
20582 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20583 + &a->pin, &wr_dir_args);
20584 + err = PTR_ERR(wh_dentry);
20585 + if (IS_ERR(wh_dentry))
20588 + sb = dentry->d_sb;
20589 + bindex = au_dbtop(dentry);
20590 + h_path.dentry = au_h_dptr(dentry, bindex);
20591 + h_path.mnt = au_sbr_mnt(sb, bindex);
20592 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20593 + if (unlikely(err))
20596 + /* make the dir opaque */
20598 + h_inode = d_inode(h_path.dentry);
20600 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20601 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20602 + opq_dentry = au_diropq_create(dentry, bindex);
20603 + inode_unlock(h_inode);
20604 + err = PTR_ERR(opq_dentry);
20605 + if (IS_ERR(opq_dentry))
20607 + dput(opq_dentry);
20611 + err = epilog(dir, bindex, wh_dentry, dentry);
20614 + goto out_unpin; /* success */
20619 + AuLabel(revert opq);
20620 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20621 + rerr = au_diropq_remove(dentry, bindex);
20622 + inode_unlock(h_inode);
20624 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20625 + dentry, err, rerr);
20631 + AuLabel(revert dir);
20632 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20634 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20635 + dentry, err, rerr);
20638 + au_dtime_revert(&a->dt);
20640 + au_unpin(&a->pin);
20643 + di_write_unlock(parent);
20645 + if (unlikely(err)) {
20646 + au_update_dbtop(dentry);
20649 + aufs_read_unlock(dentry, AuLock_DW);
20655 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20656 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20657 +++ linux/fs/aufs/i_op.c 2019-01-28 14:36:12.222418047 +0100
20659 +// SPDX-License-Identifier: GPL-2.0
20661 + * Copyright (C) 2005-2018 Junjiro R. Okajima
20663 + * This program, aufs is free software; you can redistribute it and/or modify
20664 + * it under the terms of the GNU General Public License as published by
20665 + * the Free Software Foundation; either version 2 of the License, or
20666 + * (at your option) any later version.
20668 + * This program is distributed in the hope that it will be useful,
20669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20671 + * GNU General Public License for more details.
20673 + * You should have received a copy of the GNU General Public License
20674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20678 + * inode operations (except add/del/rename)
20681 +#include <linux/device_cgroup.h>
20682 +#include <linux/fs_stack.h>
20683 +#include <linux/namei.h>
20684 +#include <linux/security.h>
20687 +static int h_permission(struct inode *h_inode, int mask,
20688 + struct path *h_path, int brperm)
20691 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20694 + if (write_mask && IS_IMMUTABLE(h_inode))
20698 + if (((mask & MAY_EXEC)
20699 + && S_ISREG(h_inode->i_mode)
20700 + && (path_noexec(h_path)
20701 + || !(h_inode->i_mode & 0111))))
20705 + * - skip the lower fs test in the case of write to ro branch.
20706 + * - nfs dir permission write check is optimized, but a policy for
20707 + * link/rename requires a real check.
20708 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20709 + * in this case, generic_permission() returns -EOPNOTSUPP.
20711 + if ((write_mask && !au_br_writable(brperm))
20712 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20713 + && write_mask && !(mask & MAY_READ))
20714 + || !h_inode->i_op->permission) {
20715 + /* AuLabel(generic_permission); */
20716 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20717 + err = generic_permission(h_inode, mask);
20718 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20719 + err = h_inode->i_op->permission(h_inode, mask);
20722 + /* AuLabel(h_inode->permission); */
20723 + err = h_inode->i_op->permission(h_inode, mask);
20728 + err = devcgroup_inode_permission(h_inode, mask);
20730 + err = security_inode_permission(h_inode, mask);
20734 + /* todo: do we need to call ima_path_check()? */
20735 + struct path h_path = {
20739 + err = ima_path_check(&h_path,
20740 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20741 + IMA_COUNT_LEAVE);
20749 +static int aufs_permission(struct inode *inode, int mask)
20752 + aufs_bindex_t bindex, bbot;
20753 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20754 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20755 + struct inode *h_inode;
20756 + struct super_block *sb;
20757 + struct au_branch *br;
20759 + /* todo: support rcu-walk? */
20760 + if (mask & MAY_NOT_BLOCK)
20763 + sb = inode->i_sb;
20764 + si_read_lock(sb, AuLock_FLUSH);
20765 + ii_read_lock_child(inode);
20767 + err = au_iigen_test(inode, au_sigen(sb));
20768 + if (unlikely(err))
20774 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20775 + err = au_busy_or_stale();
20776 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20777 + if (unlikely(!h_inode
20778 + || (h_inode->i_mode & S_IFMT)
20779 + != (inode->i_mode & S_IFMT)))
20783 + bindex = au_ibtop(inode);
20784 + br = au_sbr(sb, bindex);
20785 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20788 + && !special_file(h_inode->i_mode)) {
20789 + /* test whether the upper writable branch exists */
20791 + for (; bindex >= 0; bindex--)
20792 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20800 + /* non-write to dir */
20802 + bbot = au_ibbot(inode);
20803 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20804 + h_inode = au_h_iptr(inode, bindex);
20806 + err = au_busy_or_stale();
20807 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20810 + br = au_sbr(sb, bindex);
20811 + err = h_permission(h_inode, mask, &br->br_path,
20817 + ii_read_unlock(inode);
20818 + si_read_unlock(sb);
20822 +/* ---------------------------------------------------------------------- */
20824 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20825 + unsigned int flags)
20827 + struct dentry *ret, *parent;
20828 + struct inode *inode;
20829 + struct super_block *sb;
20830 + int err, npositive;
20834 + /* todo: support rcu-walk? */
20835 + ret = ERR_PTR(-ECHILD);
20836 + if (flags & LOOKUP_RCU)
20839 + ret = ERR_PTR(-ENAMETOOLONG);
20840 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20844 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20845 + ret = ERR_PTR(err);
20846 + if (unlikely(err))
20849 + err = au_di_init(dentry);
20850 + ret = ERR_PTR(err);
20851 + if (unlikely(err))
20855 + npositive = 0; /* suppress a warning */
20856 + parent = dentry->d_parent; /* dir inode is locked */
20857 + di_read_lock_parent(parent, AuLock_IR);
20858 + err = au_alive_dir(parent);
20860 + err = au_digen_test(parent, au_sigen(sb));
20862 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20863 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20864 + AuLkup_ALLOW_NEG);
20867 + di_read_unlock(parent, AuLock_IR);
20868 + ret = ERR_PTR(err);
20869 + if (unlikely(err < 0))
20873 + inode = au_new_inode(dentry, /*must_new*/0);
20874 + if (IS_ERR(inode)) {
20875 + ret = (void *)inode;
20882 + atomic_inc(&inode->i_count);
20883 + ret = d_splice_alias(inode, dentry);
20885 + if (unlikely(d_need_lookup(dentry))) {
20886 + spin_lock(&dentry->d_lock);
20887 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20888 + spin_unlock(&dentry->d_lock);
20892 + if (!IS_ERR(ret)) {
20894 + if (ret && ret != dentry)
20895 + ii_write_unlock(inode);
20897 + ii_write_unlock(inode);
20904 + di_write_unlock(dentry);
20906 + si_read_unlock(sb);
20911 +/* ---------------------------------------------------------------------- */
20914 + * very dirty and complicated aufs ->atomic_open().
20915 + * aufs_atomic_open()
20916 + * + au_aopen_or_create()
20918 + * + vfsub_atomic_open()
20919 + * + branch fs ->atomic_open()
20920 + * may call the actual 'open' for h_file
20921 + * + inc br_nfiles only if opened
20922 + * + au_aopen_no_open() or au_aopen_do_open()
20924 + * au_aopen_do_open()
20925 + * + finish_open()
20926 + * + au_do_aopen()
20927 + * + au_do_open() the body of all 'open'
20928 + * + au_do_open_nondir()
20929 + * set the passed h_file
20931 + * au_aopen_no_open()
20932 + * + finish_no_open()
20935 +struct aopen_node {
20936 + struct hlist_bl_node hblist;
20937 + struct file *file, *h_file;
20940 +static int au_do_aopen(struct inode *inode, struct file *file)
20942 + struct hlist_bl_head *aopen;
20943 + struct hlist_bl_node *pos;
20944 + struct aopen_node *node;
20945 + struct au_do_open_args args = {
20947 + .open = au_do_open_nondir
20950 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20951 + hlist_bl_lock(aopen);
20952 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20953 + if (node->file == file) {
20954 + args.h_file = node->h_file;
20957 + hlist_bl_unlock(aopen);
20958 + /* AuDebugOn(!args.h_file); */
20960 + return au_do_open(file, &args);
20963 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20964 + struct aopen_node *aopen_node)
20967 + struct hlist_bl_head *aopen;
20970 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20971 + au_hbl_add(&aopen_node->hblist, aopen);
20972 + err = finish_open(file, dentry, au_do_aopen);
20973 + au_hbl_del(&aopen_node->hblist, aopen);
20974 + /* AuDbgFile(file); */
20975 + AuDbg("%pd%s%s\n", dentry,
20976 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20977 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20983 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20989 + err = finish_no_open(file, dentry);
20995 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20996 + struct file *file, unsigned int open_flag,
20997 + umode_t create_mode)
20999 + int err, did_open;
21000 + unsigned int lkup_flags;
21001 + aufs_bindex_t bindex;
21002 + struct super_block *sb;
21003 + struct dentry *parent, *d;
21004 + struct vfsub_aopen_args args = {
21005 + .open_flag = open_flag,
21006 + .create_mode = create_mode
21008 + struct aopen_node aopen_node = {
21013 + AuDbg("open_flag 0%o\n", open_flag);
21014 + AuDbgDentry(dentry);
21017 + if (!au_di(dentry)) {
21018 + lkup_flags = LOOKUP_OPEN;
21019 + if (open_flag & O_CREAT)
21020 + lkup_flags |= LOOKUP_CREATE;
21021 + d = aufs_lookup(dir, dentry, lkup_flags);
21023 + err = PTR_ERR(d);
21028 + * obsoleted dentry found.
21029 + * another error will be returned later.
21035 + AuDbgDentry(dentry);
21038 + if (d_is_positive(dentry)
21039 + || d_unhashed(dentry)
21040 + || d_unlinked(dentry)
21041 + || !(open_flag & O_CREAT)) {
21042 + err = au_aopen_no_open(file, dentry);
21043 + goto out; /* success */
21046 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21047 + if (unlikely(err))
21050 + sb = dentry->d_sb;
21051 + parent = dentry->d_parent; /* dir is locked */
21052 + di_write_lock_parent(parent);
21053 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21054 + if (unlikely(err < 0))
21057 + AuDbgDentry(dentry);
21058 + if (d_is_positive(dentry)) {
21059 + err = au_aopen_no_open(file, dentry);
21060 + goto out_parent; /* success */
21063 + args.file = alloc_empty_file(file->f_flags, current_cred());
21064 + err = PTR_ERR(args.file);
21065 + if (IS_ERR(args.file))
21068 + bindex = au_dbtop(dentry);
21069 + err = au_aopen_or_create(dir, dentry, &args);
21071 + AuDbgFile(args.file);
21072 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21073 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21076 + args.file = NULL;
21078 + di_write_unlock(parent);
21079 + di_write_unlock(dentry);
21080 + if (unlikely(err < 0)) {
21087 + err = au_aopen_no_open(file, dentry);
21089 + aopen_node.h_file = args.file;
21090 + err = au_aopen_do_open(file, dentry, &aopen_node);
21092 + if (unlikely(err < 0)) {
21096 + au_lcnt_dec(&args.br->br_nfiles);
21098 + goto out_sb; /* success */
21101 + di_write_unlock(parent);
21102 + di_write_unlock(dentry);
21104 + si_read_unlock(sb);
21112 +/* ---------------------------------------------------------------------- */
21114 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21115 + const unsigned char add_entry, aufs_bindex_t bcpup,
21116 + aufs_bindex_t btop)
21119 + struct dentry *h_parent;
21120 + struct inode *h_dir;
21123 + IMustLock(d_inode(parent));
21125 + di_write_lock_parent(parent);
21128 + if (!au_h_dptr(parent, bcpup)) {
21129 + if (btop > bcpup)
21130 + err = au_cpup_dirs(dentry, bcpup);
21131 + else if (btop < bcpup)
21132 + err = au_cpdown_dirs(dentry, bcpup);
21136 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21137 + h_parent = au_h_dptr(parent, bcpup);
21138 + h_dir = d_inode(h_parent);
21139 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21140 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21141 + /* todo: no unlock here */
21142 + inode_unlock_shared(h_dir);
21144 + AuDbg("bcpup %d\n", bcpup);
21146 + if (d_really_is_negative(dentry))
21147 + au_set_h_dptr(dentry, btop, NULL);
21148 + au_update_dbrange(dentry, /*do_put_zero*/0);
21153 + di_write_unlock(parent);
21155 + err = bcpup; /* success */
21162 + * decide the branch and the parent dir where we will create a new entry.
21163 + * returns new bindex or an error.
21164 + * copyup the parent dir if needed.
21166 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21167 + struct au_wr_dir_args *args)
21170 + unsigned int flags;
21171 + aufs_bindex_t bcpup, btop, src_btop;
21172 + const unsigned char add_entry
21173 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21174 + | au_ftest_wrdir(args->flags, TMPFILE);
21175 + struct super_block *sb;
21176 + struct dentry *parent;
21177 + struct au_sbinfo *sbinfo;
21179 + sb = dentry->d_sb;
21180 + sbinfo = au_sbi(sb);
21181 + parent = dget_parent(dentry);
21182 + btop = au_dbtop(dentry);
21184 + if (args->force_btgt < 0) {
21185 + if (src_dentry) {
21186 + src_btop = au_dbtop(src_dentry);
21187 + if (src_btop < btop)
21188 + bcpup = src_btop;
21189 + } else if (add_entry) {
21191 + if (au_ftest_wrdir(args->flags, ISDIR))
21192 + au_fset_wbr(flags, DIR);
21193 + err = AuWbrCreate(sbinfo, dentry, flags);
21197 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21199 + err = AuWbrCopyup(sbinfo, dentry);
21201 + if (!IS_ROOT(dentry)) {
21202 + di_read_lock_parent(parent, !AuLock_IR);
21203 + err = AuWbrCopyup(sbinfo, dentry);
21204 + di_read_unlock(parent, !AuLock_IR);
21206 + err = AuWbrCopyup(sbinfo, dentry);
21209 + if (unlikely(err < 0))
21213 + bcpup = args->force_btgt;
21214 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21217 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21219 + if (bcpup == btop)
21220 + goto out; /* success */
21222 + /* copyup the new parent into the branch we process */
21223 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21225 + if (d_really_is_negative(dentry)) {
21226 + au_set_h_dptr(dentry, btop, NULL);
21227 + au_set_dbtop(dentry, bcpup);
21228 + au_set_dbbot(dentry, bcpup);
21230 + AuDebugOn(add_entry
21231 + && !au_ftest_wrdir(args->flags, TMPFILE)
21232 + && !au_h_dptr(dentry, bcpup));
21240 +/* ---------------------------------------------------------------------- */
21242 +void au_pin_hdir_unlock(struct au_pin *p)
21245 + au_hn_inode_unlock(p->hdir);
21248 +int au_pin_hdir_lock(struct au_pin *p)
21256 + /* even if an error happens later, keep this lock */
21257 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21260 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21265 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21266 + p->h_parent, p->br);
21272 +int au_pin_hdir_relock(struct au_pin *p)
21275 + struct inode *h_i;
21276 + struct dentry *h_d[] = {
21281 + err = au_pin_hdir_lock(p);
21282 + if (unlikely(err))
21285 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21288 + if (d_is_positive(h_d[i])) {
21289 + h_i = d_inode(h_d[i]);
21290 + err = !h_i->i_nlink;
21298 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21300 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21301 + p->hdir->hi_inode->i_rwsem.owner = task;
21305 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21308 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21309 + p->lsc_hi, 0, NULL, _RET_IP_);
21310 + au_pin_hdir_set_owner(p, current);
21314 +void au_pin_hdir_release(struct au_pin *p)
21317 + au_pin_hdir_set_owner(p, p->task);
21318 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21322 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21324 + if (pin && pin->parent)
21325 + return au_h_dptr(pin->parent, pin->bindex);
21329 +void au_unpin(struct au_pin *p)
21332 + au_pin_hdir_unlock(p);
21333 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21334 + vfsub_mnt_drop_write(p->h_mnt);
21338 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21339 + di_read_unlock(p->parent, AuLock_IR);
21340 + iput(p->hdir->hi_inode);
21342 + p->parent = NULL;
21345 + /* do not clear p->task */
21348 +int au_do_pin(struct au_pin *p)
21351 + struct super_block *sb;
21352 + struct inode *h_dir;
21355 + sb = p->dentry->d_sb;
21356 + p->br = au_sbr(sb, p->bindex);
21357 + if (IS_ROOT(p->dentry)) {
21358 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21359 + p->h_mnt = au_br_mnt(p->br);
21360 + err = vfsub_mnt_want_write(p->h_mnt);
21361 + if (unlikely(err)) {
21362 + au_fclr_pin(p->flags, MNT_WRITE);
21369 + p->h_dentry = NULL;
21370 + if (p->bindex <= au_dbbot(p->dentry))
21371 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21373 + p->parent = dget_parent(p->dentry);
21374 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21375 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21378 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21379 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21381 + h_dir = p->hdir->hi_inode;
21385 + * if DI_LOCKED is not set, then p->parent may be different
21386 + * and h_parent can be NULL.
21388 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21390 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21391 + di_read_unlock(p->parent, AuLock_IR);
21393 + p->parent = NULL;
21397 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21398 + p->h_mnt = au_br_mnt(p->br);
21399 + err = vfsub_mnt_want_write(p->h_mnt);
21400 + if (unlikely(err)) {
21401 + au_fclr_pin(p->flags, MNT_WRITE);
21402 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21403 + di_read_unlock(p->parent, AuLock_IR);
21405 + p->parent = NULL;
21411 + err = au_pin_hdir_lock(p);
21413 + goto out; /* success */
21418 + pr_err("err %d\n", err);
21419 + err = au_busy_or_stale();
21424 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21425 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21426 + unsigned int udba, unsigned char flags)
21428 + p->dentry = dentry;
21430 + p->lsc_di = lsc_di;
21431 + p->lsc_hi = lsc_hi;
21432 + p->flags = flags;
21433 + p->bindex = bindex;
21435 + p->parent = NULL;
21439 + p->h_dentry = NULL;
21440 + p->h_parent = NULL;
21442 + p->task = current;
21445 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21446 + unsigned int udba, unsigned char flags)
21448 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21450 + return au_do_pin(pin);
21453 +/* ---------------------------------------------------------------------- */
21456 + * ->setattr() and ->getattr() are called in various cases.
21457 + * chmod, stat: dentry is revalidated.
21458 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21460 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21462 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21463 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21466 + struct dentry *parent;
21469 + if (au_digen_test(dentry, sigen)) {
21470 + parent = dget_parent(dentry);
21471 + di_read_lock_parent(parent, AuLock_IR);
21472 + err = au_refresh_dentry(dentry, parent);
21473 + di_read_unlock(parent, AuLock_IR);
21481 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21482 + struct au_icpup_args *a)
21486 + aufs_bindex_t btop, ibtop;
21487 + struct dentry *hi_wh, *parent;
21488 + struct inode *inode;
21489 + struct au_wr_dir_args wr_dir_args = {
21490 + .force_btgt = -1,
21494 + if (d_is_dir(dentry))
21495 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21496 + /* plink or hi_wh() case */
21497 + btop = au_dbtop(dentry);
21498 + inode = d_inode(dentry);
21499 + ibtop = au_ibtop(inode);
21500 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21501 + wr_dir_args.force_btgt = ibtop;
21502 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21503 + if (unlikely(err < 0))
21507 + au_fset_icpup(a->flags, DID_CPUP);
21510 + a->pin_flags = AuPin_MNT_WRITE;
21512 + if (!IS_ROOT(dentry)) {
21513 + au_fset_pin(a->pin_flags, DI_LOCKED);
21514 + parent = dget_parent(dentry);
21515 + di_write_lock_parent(parent);
21518 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21519 + if (unlikely(err))
21523 + a->h_path.dentry = au_h_dptr(dentry, btop);
21524 + a->h_inode = d_inode(a->h_path.dentry);
21525 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21526 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21527 + if (ia->ia_size < i_size_read(a->h_inode))
21528 + sz = ia->ia_size;
21529 + inode_unlock_shared(a->h_inode);
21533 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21534 + hi_wh = au_hi_wh(inode, a->btgt);
21536 + struct au_cp_generic cpg = {
21537 + .dentry = dentry,
21543 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21544 + if (unlikely(err))
21546 + hi_wh = au_hi_wh(inode, a->btgt);
21547 + /* todo: revalidate hi_wh? */
21552 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21553 + di_downgrade_lock(parent, AuLock_IR);
21557 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21558 + goto out; /* success */
21560 + if (!d_unhashed(dentry)) {
21561 + struct au_cp_generic cpg = {
21562 + .dentry = dentry,
21567 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21569 + err = au_sio_cpup_simple(&cpg);
21571 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21572 + } else if (!hi_wh)
21573 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21575 + a->h_path.dentry = hi_wh; /* do not dget here */
21578 + a->h_inode = d_inode(a->h_path.dentry);
21580 + goto out; /* success */
21581 + au_unpin(&a->pin);
21584 + di_write_unlock(parent);
21589 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21593 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21596 + struct inode *inode, *delegated;
21597 + struct super_block *sb;
21598 + struct file *file;
21599 + struct au_icpup_args *a;
21601 + inode = d_inode(dentry);
21602 + IMustLock(inode);
21604 + err = setattr_prepare(dentry, ia);
21605 + if (unlikely(err))
21609 + a = kzalloc(sizeof(*a), GFP_NOFS);
21610 + if (unlikely(!a))
21613 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21614 + ia->ia_valid &= ~ATTR_MODE;
21617 + sb = dentry->d_sb;
21618 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21619 + if (unlikely(err))
21622 + if (ia->ia_valid & ATTR_FILE) {
21623 + /* currently ftruncate(2) only */
21624 + AuDebugOn(!d_is_reg(dentry));
21625 + file = ia->ia_file;
21626 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21628 + if (unlikely(err))
21630 + ia->ia_file = au_hf_top(file);
21631 + a->udba = AuOpt_UDBA_NONE;
21633 + /* fchmod() doesn't pass ia_file */
21634 + a->udba = au_opt_udba(sb);
21635 + di_write_lock_child(dentry);
21636 + /* no d_unlinked(), to set UDBA_NONE for root */
21637 + if (d_unhashed(dentry))
21638 + a->udba = AuOpt_UDBA_NONE;
21639 + if (a->udba != AuOpt_UDBA_NONE) {
21640 + AuDebugOn(IS_ROOT(dentry));
21641 + err = au_reval_for_attr(dentry, au_sigen(sb));
21642 + if (unlikely(err))
21647 + err = au_pin_and_icpup(dentry, ia, a);
21648 + if (unlikely(err < 0))
21650 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21651 + ia->ia_file = NULL;
21652 + ia->ia_valid &= ~ATTR_FILE;
21655 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21656 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21657 + == (ATTR_MODE | ATTR_CTIME)) {
21658 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21659 + if (unlikely(err))
21661 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21662 + && (ia->ia_valid & ATTR_CTIME)) {
21663 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21664 + if (unlikely(err))
21668 + if (ia->ia_valid & ATTR_SIZE) {
21671 + if (ia->ia_size < i_size_read(inode))
21673 + truncate_setsize(inode, ia->ia_size);
21676 + if (ia->ia_valid & ATTR_FILE)
21678 + inode_unlock(a->h_inode);
21679 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21680 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21682 + delegated = NULL;
21684 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21686 + err = break_deleg_wait(&delegated);
21694 + * regardless aufs 'acl' option setting.
21695 + * why don't all acl-aware fs call this func from their ->setattr()?
21697 + if (!err && (ia->ia_valid & ATTR_MODE))
21698 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21700 + au_cpup_attr_changeable(inode);
21703 + inode_unlock(a->h_inode);
21704 + au_unpin(&a->pin);
21705 + if (unlikely(err))
21706 + au_update_dbtop(dentry);
21708 + di_write_unlock(dentry);
21710 + fi_write_unlock(file);
21711 + ia->ia_file = file;
21712 + ia->ia_valid |= ATTR_FILE;
21715 + si_read_unlock(sb);
21723 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21724 +static int au_h_path_to_set_attr(struct dentry *dentry,
21725 + struct au_icpup_args *a, struct path *h_path)
21728 + struct super_block *sb;
21730 + sb = dentry->d_sb;
21731 + a->udba = au_opt_udba(sb);
21732 + /* no d_unlinked(), to set UDBA_NONE for root */
21733 + if (d_unhashed(dentry))
21734 + a->udba = AuOpt_UDBA_NONE;
21735 + if (a->udba != AuOpt_UDBA_NONE) {
21736 + AuDebugOn(IS_ROOT(dentry));
21737 + err = au_reval_for_attr(dentry, au_sigen(sb));
21738 + if (unlikely(err))
21741 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21742 + if (unlikely(err < 0))
21745 + h_path->dentry = a->h_path.dentry;
21746 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21752 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21753 + struct au_sxattr *arg)
21756 + struct path h_path;
21757 + struct super_block *sb;
21758 + struct au_icpup_args *a;
21759 + struct inode *h_inode;
21761 + IMustLock(inode);
21764 + a = kzalloc(sizeof(*a), GFP_NOFS);
21765 + if (unlikely(!a))
21768 + sb = dentry->d_sb;
21769 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21770 + if (unlikely(err))
21773 + h_path.dentry = NULL; /* silence gcc */
21774 + di_write_lock_child(dentry);
21775 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21776 + if (unlikely(err))
21779 + inode_unlock(a->h_inode);
21780 + switch (arg->type) {
21781 + case AU_XATTR_SET:
21782 + AuDebugOn(d_is_negative(h_path.dentry));
21783 + err = vfsub_setxattr(h_path.dentry,
21784 + arg->u.set.name, arg->u.set.value,
21785 + arg->u.set.size, arg->u.set.flags);
21788 + err = -EOPNOTSUPP;
21789 + h_inode = d_inode(h_path.dentry);
21790 + if (h_inode->i_op->set_acl)
21791 + /* this will call posix_acl_update_mode */
21792 + err = h_inode->i_op->set_acl(h_inode,
21793 + arg->u.acl_set.acl,
21794 + arg->u.acl_set.type);
21798 + au_cpup_attr_timesizes(inode);
21800 + au_unpin(&a->pin);
21801 + if (unlikely(err))
21802 + au_update_dbtop(dentry);
21805 + di_write_unlock(dentry);
21806 + si_read_unlock(sb);
21815 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21816 + unsigned int nlink)
21820 + inode->i_mode = st->mode;
21821 + /* don't i_[ug]id_write() here */
21822 + inode->i_uid = st->uid;
21823 + inode->i_gid = st->gid;
21824 + inode->i_atime = st->atime;
21825 + inode->i_mtime = st->mtime;
21826 + inode->i_ctime = st->ctime;
21828 + au_cpup_attr_nlink(inode, /*force*/0);
21829 + if (S_ISDIR(inode->i_mode)) {
21830 + n = inode->i_nlink;
21833 + smp_mb(); /* for i_nlink */
21834 + /* 0 can happen */
21835 + set_nlink(inode, n);
21838 + spin_lock(&inode->i_lock);
21839 + inode->i_blocks = st->blocks;
21840 + i_size_write(inode, st->size);
21841 + spin_unlock(&inode->i_lock);
21845 + * common routine for aufs_getattr() and au_getxattr().
21846 + * returns zero or negative (an error).
21847 + * @dentry will be read-locked in success.
21849 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21853 + unsigned int mnt_flags, sigen;
21854 + unsigned char udba_none;
21855 + aufs_bindex_t bindex;
21856 + struct super_block *sb, *h_sb;
21857 + struct inode *inode;
21859 + h_path->mnt = NULL;
21860 + h_path->dentry = NULL;
21863 + sb = dentry->d_sb;
21864 + mnt_flags = au_mntflags(sb);
21865 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21867 + if (unlikely(locked))
21868 + goto body; /* skip locking dinfo */
21870 + /* support fstat(2) */
21871 + if (!d_unlinked(dentry) && !udba_none) {
21872 + sigen = au_sigen(sb);
21873 + err = au_digen_test(dentry, sigen);
21875 + di_read_lock_child(dentry, AuLock_IR);
21876 + err = au_dbrange_test(dentry);
21877 + if (unlikely(err)) {
21878 + di_read_unlock(dentry, AuLock_IR);
21882 + AuDebugOn(IS_ROOT(dentry));
21883 + di_write_lock_child(dentry);
21884 + err = au_dbrange_test(dentry);
21886 + err = au_reval_for_attr(dentry, sigen);
21888 + di_downgrade_lock(dentry, AuLock_IR);
21890 + di_write_unlock(dentry);
21895 + di_read_lock_child(dentry, AuLock_IR);
21898 + inode = d_inode(dentry);
21899 + bindex = au_ibtop(inode);
21900 + h_path->mnt = au_sbr_mnt(sb, bindex);
21901 + h_sb = h_path->mnt->mnt_sb;
21903 + && !au_test_fs_bad_iattr(h_sb)
21905 + goto out; /* success */
21907 + if (au_dbtop(dentry) == bindex)
21908 + h_path->dentry = au_h_dptr(dentry, bindex);
21909 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21910 + h_path->dentry = au_plink_lkup(inode, bindex);
21911 + if (IS_ERR(h_path->dentry))
21912 + /* pretending success */
21913 + h_path->dentry = NULL;
21915 + dput(h_path->dentry);
21922 +static int aufs_getattr(const struct path *path, struct kstat *st,
21923 + u32 request, unsigned int query)
21926 + unsigned char positive;
21927 + struct path h_path;
21928 + struct dentry *dentry;
21929 + struct inode *inode;
21930 + struct super_block *sb;
21932 + dentry = path->dentry;
21933 + inode = d_inode(dentry);
21934 + sb = dentry->d_sb;
21935 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21936 + if (unlikely(err))
21938 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21939 + if (unlikely(err))
21941 + if (unlikely(!h_path.dentry))
21942 + /* illegally overlapped or something */
21943 + goto out_fill; /* pretending success */
21945 + positive = d_is_positive(h_path.dentry);
21947 + /* no vfsub version */
21948 + err = vfs_getattr(&h_path, st, request, query);
21951 + au_refresh_iattr(inode, st,
21952 + d_inode(h_path.dentry)->i_nlink);
21953 + goto out_fill; /* success */
21959 + generic_fillattr(inode, st);
21961 + di_read_unlock(dentry, AuLock_IR);
21963 + si_read_unlock(sb);
21969 +/* ---------------------------------------------------------------------- */
21971 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21972 + struct delayed_call *done)
21975 + struct dentry *h_dentry;
21976 + struct inode *h_inode;
21978 + aufs_bindex_t bindex;
21980 + ret = NULL; /* suppress a warning */
21985 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21986 + if (unlikely(err))
21989 + err = au_d_hashed_positive(dentry);
21990 + if (unlikely(err))
21994 + inode = d_inode(dentry);
21995 + bindex = au_ibtop(inode);
21996 + h_inode = au_h_iptr(inode, bindex);
21997 + if (unlikely(!h_inode->i_op->get_link))
22002 + if (au_dbtop(dentry) <= bindex) {
22003 + h_dentry = au_h_dptr(dentry, bindex);
22008 + h_dentry = d_find_any_alias(h_inode);
22009 + if (IS_ERR(h_dentry)) {
22010 + err = PTR_ERR(h_dentry);
22014 + if (unlikely(!h_dentry))
22018 + AuDbg("%ps\n", h_inode->i_op->get_link);
22019 + AuDbgDentry(h_dentry);
22020 + ret = vfs_get_link(h_dentry, done);
22023 + err = PTR_ERR(ret);
22026 + aufs_read_unlock(dentry, AuLock_IR);
22028 + if (unlikely(err))
22029 + ret = ERR_PTR(err);
22030 + AuTraceErrPtr(ret);
22034 +/* ---------------------------------------------------------------------- */
22036 +static int au_is_special(struct inode *inode)
22038 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
22041 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
22045 + aufs_bindex_t bindex;
22046 + struct super_block *sb;
22047 + struct inode *h_inode;
22048 + struct vfsmount *h_mnt;
22050 + sb = inode->i_sb;
22051 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
22052 + "unexpected s_flags 0x%lx", sb->s_flags);
22054 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
22056 + si_read_lock(sb, AuLock_FLUSH);
22057 + ii_write_lock_child(inode);
22060 + bindex = au_ibtop(inode);
22061 + h_inode = au_h_iptr(inode, bindex);
22062 + if (!au_test_ro(sb, bindex, inode)) {
22063 + h_mnt = au_sbr_mnt(sb, bindex);
22064 + err = vfsub_mnt_want_write(h_mnt);
22066 + err = vfsub_update_time(h_inode, ts, flags);
22067 + vfsub_mnt_drop_write(h_mnt);
22069 + } else if (au_is_special(h_inode)) {
22071 + * Never copy-up here.
22072 + * These special files may already be opened and used for
22073 + * communicating. If we copied it up, then the communication
22074 + * would be corrupted.
22076 + AuWarn1("timestamps for i%lu are ignored "
22077 + "since it is on readonly branch (hi%lu).\n",
22078 + inode->i_ino, h_inode->i_ino);
22079 + } else if (flags & ~S_ATIME) {
22081 + AuIOErr1("unexpected flags 0x%x\n", flags);
22086 + au_cpup_attr_timesizes(inode);
22087 + ii_write_unlock(inode);
22088 + si_read_unlock(sb);
22091 + if (!err && (flags & S_VERSION))
22092 + inode_inc_iversion(inode);
22097 +/* ---------------------------------------------------------------------- */
22099 +/* no getattr version will be set by module.c:aufs_init() */
22100 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22102 + [AuIop_SYMLINK] = {
22103 + .permission = aufs_permission,
22104 +#ifdef CONFIG_FS_POSIX_ACL
22105 + .get_acl = aufs_get_acl,
22106 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22109 + .setattr = aufs_setattr,
22110 + .getattr = aufs_getattr,
22112 +#ifdef CONFIG_AUFS_XATTR
22113 + .listxattr = aufs_listxattr,
22116 + .get_link = aufs_get_link,
22118 + /* .update_time = aufs_update_time */
22121 + .create = aufs_create,
22122 + .lookup = aufs_lookup,
22123 + .link = aufs_link,
22124 + .unlink = aufs_unlink,
22125 + .symlink = aufs_symlink,
22126 + .mkdir = aufs_mkdir,
22127 + .rmdir = aufs_rmdir,
22128 + .mknod = aufs_mknod,
22129 + .rename = aufs_rename,
22131 + .permission = aufs_permission,
22132 +#ifdef CONFIG_FS_POSIX_ACL
22133 + .get_acl = aufs_get_acl,
22134 + .set_acl = aufs_set_acl,
22137 + .setattr = aufs_setattr,
22138 + .getattr = aufs_getattr,
22140 +#ifdef CONFIG_AUFS_XATTR
22141 + .listxattr = aufs_listxattr,
22144 + .update_time = aufs_update_time,
22145 + .atomic_open = aufs_atomic_open,
22146 + .tmpfile = aufs_tmpfile
22148 + [AuIop_OTHER] = {
22149 + .permission = aufs_permission,
22150 +#ifdef CONFIG_FS_POSIX_ACL
22151 + .get_acl = aufs_get_acl,
22152 + .set_acl = aufs_set_acl,
22155 + .setattr = aufs_setattr,
22156 + .getattr = aufs_getattr,
22158 +#ifdef CONFIG_AUFS_XATTR
22159 + .listxattr = aufs_listxattr,
22162 + .update_time = aufs_update_time
22165 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22166 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22167 +++ linux/fs/aufs/i_op_del.c 2019-01-28 14:36:12.222418047 +0100
22169 +// SPDX-License-Identifier: GPL-2.0
22171 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22173 + * This program, aufs is free software; you can redistribute it and/or modify
22174 + * it under the terms of the GNU General Public License as published by
22175 + * the Free Software Foundation; either version 2 of the License, or
22176 + * (at your option) any later version.
22178 + * This program is distributed in the hope that it will be useful,
22179 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22180 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22181 + * GNU General Public License for more details.
22183 + * You should have received a copy of the GNU General Public License
22184 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22188 + * inode operations (del entry)
22194 + * decide if a new whiteout for @dentry is necessary or not.
22195 + * when it is necessary, prepare the parent dir for the upper branch whose
22196 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22197 + * be done by caller.
22199 + * 0: wh is unnecessary
22200 + * plus: wh is necessary
22203 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22205 + int need_wh, err;
22206 + aufs_bindex_t btop;
22207 + struct super_block *sb;
22209 + sb = dentry->d_sb;
22210 + btop = au_dbtop(dentry);
22211 + if (*bcpup < 0) {
22213 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22214 + err = AuWbrCopyup(au_sbi(sb), dentry);
22216 + if (unlikely(err < 0))
22220 + AuDebugOn(btop < *bcpup
22221 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22222 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22224 + if (*bcpup != btop) {
22225 + err = au_cpup_dirs(dentry, *bcpup);
22226 + if (unlikely(err))
22230 + struct au_dinfo *dinfo, *tmp;
22232 + need_wh = -ENOMEM;
22233 + dinfo = au_di(dentry);
22234 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22236 + au_di_cp(tmp, dinfo);
22237 + au_di_swap(tmp, dinfo);
22238 + /* returns the number of positive dentries */
22239 + need_wh = au_lkup_dentry(dentry, btop + 1,
22240 + /* AuLkup_IGNORE_PERM */ 0);
22241 + au_di_swap(tmp, dinfo);
22242 + au_rw_write_unlock(&tmp->di_rwsem);
22246 + AuDbg("need_wh %d\n", need_wh);
22254 + * simple tests for the del-entry operations.
22255 + * following the checks in vfs, plus the parent-child relationship.
22257 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22258 + struct dentry *h_parent, int isdir)
22262 + struct dentry *h_dentry, *h_latest;
22263 + struct inode *h_inode;
22265 + h_dentry = au_h_dptr(dentry, bindex);
22266 + if (d_really_is_positive(dentry)) {
22268 + if (unlikely(d_is_negative(h_dentry)))
22270 + h_inode = d_inode(h_dentry);
22271 + if (unlikely(!h_inode->i_nlink))
22274 + h_mode = h_inode->i_mode;
22277 + if (unlikely(S_ISDIR(h_mode)))
22279 + } else if (unlikely(!S_ISDIR(h_mode))) {
22284 + /* rename(2) case */
22286 + if (unlikely(d_is_positive(h_dentry)))
22291 + /* expected parent dir is locked */
22292 + if (unlikely(h_parent != h_dentry->d_parent))
22297 + * rmdir a dir may break the consistency on some filesystem.
22298 + * let's try heavy test.
22301 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22302 + && au_test_h_perm(d_inode(h_parent),
22303 + MAY_EXEC | MAY_WRITE)))
22306 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22308 + if (IS_ERR(h_latest))
22310 + if (h_latest == h_dentry)
22319 + * decide the branch where we operate for @dentry. the branch index will be set
22320 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22321 + * dir for reverting.
22322 + * when a new whiteout is necessary, create it.
22324 +static struct dentry*
22325 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22326 + struct au_dtime *dt, struct au_pin *pin)
22328 + struct dentry *wh_dentry;
22329 + struct super_block *sb;
22330 + struct path h_path;
22331 + int err, need_wh;
22332 + unsigned int udba;
22333 + aufs_bindex_t bcpup;
22335 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22336 + wh_dentry = ERR_PTR(need_wh);
22337 + if (unlikely(need_wh < 0))
22340 + sb = dentry->d_sb;
22341 + udba = au_opt_udba(sb);
22343 + err = au_pin(pin, dentry, bcpup, udba,
22344 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22345 + wh_dentry = ERR_PTR(err);
22346 + if (unlikely(err))
22349 + h_path.dentry = au_pinned_h_parent(pin);
22350 + if (udba != AuOpt_UDBA_NONE
22351 + && au_dbtop(dentry) == bcpup) {
22352 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22353 + wh_dentry = ERR_PTR(err);
22354 + if (unlikely(err))
22358 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22359 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22360 + wh_dentry = NULL;
22362 + goto out; /* success, no need to create whiteout */
22364 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22365 + if (IS_ERR(wh_dentry))
22368 + /* returns with the parent is locked and wh_dentry is dget-ed */
22369 + goto out; /* success */
22374 + return wh_dentry;
22378 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22379 + * in order to be revertible and save time for removing many child whiteouts
22381 + * returns 1 when there are too many child whiteout and caller should remove
22382 + * them asynchronously. returns 0 when the number of children is enough small to
22383 + * remove now or the branch fs is a remote fs.
22384 + * otherwise return an error.
22386 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22387 + struct au_nhash *whlist, struct inode *dir)
22389 + int rmdir_later, err, dirwh;
22390 + struct dentry *h_dentry;
22391 + struct super_block *sb;
22392 + struct inode *inode;
22394 + sb = dentry->d_sb;
22395 + SiMustAnyLock(sb);
22396 + h_dentry = au_h_dptr(dentry, bindex);
22397 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22398 + if (unlikely(err))
22401 + /* stop monitoring */
22402 + inode = d_inode(dentry);
22403 + au_hn_free(au_hi(inode, bindex));
22405 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22406 + dirwh = au_sbi(sb)->si_dirwh;
22407 + rmdir_later = (dirwh <= 1);
22408 + if (!rmdir_later)
22409 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22412 + return rmdir_later;
22415 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22416 + if (unlikely(err)) {
22417 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22418 + h_dentry, bindex, err);
22428 + * final procedure for deleting a entry.
22429 + * maintain dentry and iattr.
22431 +static void epilog(struct inode *dir, struct dentry *dentry,
22432 + aufs_bindex_t bindex)
22434 + struct inode *inode;
22436 + inode = d_inode(dentry);
22438 + inode->i_ctime = dir->i_ctime;
22440 + au_dir_ts(dir, bindex);
22441 + inode_inc_iversion(dir);
22445 + * when an error happened, remove the created whiteout and revert everything.
22447 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22448 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22449 + struct dentry *dentry, struct au_dtime *dt)
22452 + struct path h_path = {
22453 + .dentry = wh_dentry,
22454 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22457 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22459 + au_set_dbwh(dentry, bwh);
22460 + au_dtime_revert(dt);
22464 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22468 +/* ---------------------------------------------------------------------- */
22470 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22473 + aufs_bindex_t bwh, bindex, btop;
22474 + struct inode *inode, *h_dir, *delegated;
22475 + struct dentry *parent, *wh_dentry;
22476 + /* to reduce stack size */
22478 + struct au_dtime dt;
22479 + struct au_pin pin;
22480 + struct path h_path;
22486 + a = kmalloc(sizeof(*a), GFP_NOFS);
22487 + if (unlikely(!a))
22490 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22491 + if (unlikely(err))
22493 + err = au_d_hashed_positive(dentry);
22494 + if (unlikely(err))
22496 + inode = d_inode(dentry);
22497 + IMustLock(inode);
22499 + if (unlikely(d_is_dir(dentry)))
22500 + goto out_unlock; /* possible? */
22502 + btop = au_dbtop(dentry);
22503 + bwh = au_dbwh(dentry);
22505 + parent = dentry->d_parent; /* dir inode is locked */
22506 + di_write_lock_parent(parent);
22507 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22509 + err = PTR_ERR(wh_dentry);
22510 + if (IS_ERR(wh_dentry))
22513 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22514 + a->h_path.dentry = au_h_dptr(dentry, btop);
22515 + dget(a->h_path.dentry);
22516 + if (bindex == btop) {
22517 + h_dir = au_pinned_h_dir(&a->pin);
22518 + delegated = NULL;
22519 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22520 + if (unlikely(err == -EWOULDBLOCK)) {
22521 + pr_warn("cannot retry for NFSv4 delegation"
22522 + " for an internal unlink\n");
22526 + /* dir inode is locked */
22527 + h_dir = d_inode(wh_dentry->d_parent);
22528 + IMustLock(h_dir);
22533 + vfsub_drop_nlink(inode);
22534 + epilog(dir, dentry, bindex);
22536 + /* update target timestamps */
22537 + if (bindex == btop) {
22538 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22540 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22542 + /* todo: this timestamp may be reverted later */
22543 + inode->i_ctime = h_dir->i_ctime;
22544 + goto out_unpin; /* success */
22551 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22558 + au_unpin(&a->pin);
22560 + dput(a->h_path.dentry);
22562 + di_write_unlock(parent);
22564 + aufs_read_unlock(dentry, AuLock_DW);
22571 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22573 + int err, rmdir_later;
22574 + aufs_bindex_t bwh, bindex, btop;
22575 + struct inode *inode;
22576 + struct dentry *parent, *wh_dentry, *h_dentry;
22577 + struct au_whtmp_rmdir *args;
22578 + /* to reduce stack size */
22580 + struct au_dtime dt;
22581 + struct au_pin pin;
22587 + a = kmalloc(sizeof(*a), GFP_NOFS);
22588 + if (unlikely(!a))
22591 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22592 + if (unlikely(err))
22594 + err = au_alive_dir(dentry);
22595 + if (unlikely(err))
22597 + inode = d_inode(dentry);
22598 + IMustLock(inode);
22600 + if (unlikely(!d_is_dir(dentry)))
22601 + goto out_unlock; /* possible? */
22604 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22605 + if (unlikely(!args))
22608 + parent = dentry->d_parent; /* dir inode is locked */
22609 + di_write_lock_parent(parent);
22610 + err = au_test_empty(dentry, &args->whlist);
22611 + if (unlikely(err))
22614 + btop = au_dbtop(dentry);
22615 + bwh = au_dbwh(dentry);
22617 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22619 + err = PTR_ERR(wh_dentry);
22620 + if (IS_ERR(wh_dentry))
22623 + h_dentry = au_h_dptr(dentry, btop);
22626 + if (bindex == btop) {
22627 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22629 + rmdir_later = err;
22633 + /* stop monitoring */
22634 + au_hn_free(au_hi(inode, btop));
22636 + /* dir inode is locked */
22637 + IMustLock(d_inode(wh_dentry->d_parent));
22642 + vfsub_dead_dir(inode);
22643 + au_set_dbdiropq(dentry, -1);
22644 + epilog(dir, dentry, bindex);
22646 + if (rmdir_later) {
22647 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22651 + goto out_unpin; /* success */
22659 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22666 + au_unpin(&a->pin);
22670 + di_write_unlock(parent);
22672 + au_whtmp_rmdir_free(args);
22674 + aufs_read_unlock(dentry, AuLock_DW);
22681 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22682 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22683 +++ linux/fs/aufs/i_op_ren.c 2019-01-28 14:36:12.222418047 +0100
22685 +// SPDX-License-Identifier: GPL-2.0
22687 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22689 + * This program, aufs is free software; you can redistribute it and/or modify
22690 + * it under the terms of the GNU General Public License as published by
22691 + * the Free Software Foundation; either version 2 of the License, or
22692 + * (at your option) any later version.
22694 + * This program is distributed in the hope that it will be useful,
22695 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22696 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22697 + * GNU General Public License for more details.
22699 + * You should have received a copy of the GNU General Public License
22700 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22704 + * inode operation (rename entry)
22705 + * todo: this is crazy monster
22710 +enum { AuSRC, AuDST, AuSrcDst };
22711 +enum { AuPARENT, AuCHILD, AuParentChild };
22713 +#define AuRen_ISDIR_SRC 1
22714 +#define AuRen_ISDIR_DST (1 << 1)
22715 +#define AuRen_ISSAMEDIR (1 << 2)
22716 +#define AuRen_WHSRC (1 << 3)
22717 +#define AuRen_WHDST (1 << 4)
22718 +#define AuRen_MNT_WRITE (1 << 5)
22719 +#define AuRen_DT_DSTDIR (1 << 6)
22720 +#define AuRen_DIROPQ_SRC (1 << 7)
22721 +#define AuRen_DIROPQ_DST (1 << 8)
22722 +#define AuRen_DIRREN (1 << 9)
22723 +#define AuRen_DROPPED_SRC (1 << 10)
22724 +#define AuRen_DROPPED_DST (1 << 11)
22725 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22726 +#define au_fset_ren(flags, name) \
22727 + do { (flags) |= AuRen_##name; } while (0)
22728 +#define au_fclr_ren(flags, name) \
22729 + do { (flags) &= ~AuRen_##name; } while (0)
22731 +#ifndef CONFIG_AUFS_DIRREN
22732 +#undef AuRen_DIRREN
22733 +#define AuRen_DIRREN 0
22736 +struct au_ren_args {
22738 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22740 + struct inode *dir, *inode;
22741 + struct au_hinode *hdir, *hinode;
22742 + struct au_dtime dt[AuParentChild];
22743 + aufs_bindex_t btop, bdiropq;
22746 +#define src_dentry sd[AuSRC].dentry
22747 +#define src_dir sd[AuSRC].dir
22748 +#define src_inode sd[AuSRC].inode
22749 +#define src_h_dentry sd[AuSRC].h_dentry
22750 +#define src_parent sd[AuSRC].parent
22751 +#define src_h_parent sd[AuSRC].h_parent
22752 +#define src_wh_dentry sd[AuSRC].wh_dentry
22753 +#define src_hdir sd[AuSRC].hdir
22754 +#define src_hinode sd[AuSRC].hinode
22755 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22756 +#define src_dt sd[AuSRC].dt
22757 +#define src_btop sd[AuSRC].btop
22758 +#define src_bdiropq sd[AuSRC].bdiropq
22760 +#define dst_dentry sd[AuDST].dentry
22761 +#define dst_dir sd[AuDST].dir
22762 +#define dst_inode sd[AuDST].inode
22763 +#define dst_h_dentry sd[AuDST].h_dentry
22764 +#define dst_parent sd[AuDST].parent
22765 +#define dst_h_parent sd[AuDST].h_parent
22766 +#define dst_wh_dentry sd[AuDST].wh_dentry
22767 +#define dst_hdir sd[AuDST].hdir
22768 +#define dst_hinode sd[AuDST].hinode
22769 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22770 +#define dst_dt sd[AuDST].dt
22771 +#define dst_btop sd[AuDST].btop
22772 +#define dst_bdiropq sd[AuDST].bdiropq
22774 + struct dentry *h_trap;
22775 + struct au_branch *br;
22776 + struct path h_path;
22777 + struct au_nhash whlist;
22778 + aufs_bindex_t btgt, src_bwh;
22781 + unsigned short auren_flags;
22782 + unsigned char flags; /* syscall parameter */
22783 + unsigned char exchange;
22786 + struct au_whtmp_rmdir *thargs;
22787 + struct dentry *h_dst;
22788 + struct au_hinode *h_root;
22791 +/* ---------------------------------------------------------------------- */
22794 + * functions for reverting.
22795 + * when an error happened in a single rename systemcall, we should revert
22796 + * everything as if nothing happened.
22797 + * we don't need to revert the copied-up/down the parent dir since they are
22801 +#define RevertFailure(fmt, ...) do { \
22802 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22803 + ##__VA_ARGS__, err, rerr); \
22807 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22810 + struct dentry *d;
22811 +#define src_or_dst(member) a->sd[idx].member
22813 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22814 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22815 + rerr = au_diropq_remove(d, a->btgt);
22816 + au_hn_inode_unlock(src_or_dst(hinode));
22817 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22819 + RevertFailure("remove diropq %pd", d);
22821 +#undef src_or_dst_
22824 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22826 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22827 + au_ren_do_rev_diropq(err, a, AuSRC);
22828 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22829 + au_ren_do_rev_diropq(err, a, AuDST);
22832 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22835 + struct inode *delegated;
22837 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22838 + a->src_h_parent);
22839 + rerr = PTR_ERR(a->h_path.dentry);
22840 + if (IS_ERR(a->h_path.dentry)) {
22841 + RevertFailure("lkup one %pd", a->src_dentry);
22845 + delegated = NULL;
22846 + rerr = vfsub_rename(a->dst_h_dir,
22847 + au_h_dptr(a->src_dentry, a->btgt),
22848 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22849 + if (unlikely(rerr == -EWOULDBLOCK)) {
22850 + pr_warn("cannot retry for NFSv4 delegation"
22851 + " for an internal rename\n");
22854 + d_drop(a->h_path.dentry);
22855 + dput(a->h_path.dentry);
22856 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22858 + RevertFailure("rename %pd", a->src_dentry);
22861 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22864 + struct inode *delegated;
22866 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22867 + a->dst_h_parent);
22868 + rerr = PTR_ERR(a->h_path.dentry);
22869 + if (IS_ERR(a->h_path.dentry)) {
22870 + RevertFailure("lkup one %pd", a->dst_dentry);
22873 + if (d_is_positive(a->h_path.dentry)) {
22874 + d_drop(a->h_path.dentry);
22875 + dput(a->h_path.dentry);
22879 + delegated = NULL;
22880 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22881 + &delegated, a->flags);
22882 + if (unlikely(rerr == -EWOULDBLOCK)) {
22883 + pr_warn("cannot retry for NFSv4 delegation"
22884 + " for an internal rename\n");
22887 + d_drop(a->h_path.dentry);
22888 + dput(a->h_path.dentry);
22890 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22892 + RevertFailure("rename %pd", a->h_dst);
22895 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22899 + a->h_path.dentry = a->src_wh_dentry;
22900 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22901 + au_set_dbwh(a->src_dentry, a->src_bwh);
22903 + RevertFailure("unlink %pd", a->src_wh_dentry);
22905 +#undef RevertFailure
22907 +/* ---------------------------------------------------------------------- */
22910 + * when we have to copyup the renaming entry, do it with the rename-target name
22911 + * in order to minimize the cost (the later actual rename is unnecessary).
22912 + * otherwise rename it on the target branch.
22914 +static int au_ren_or_cpup(struct au_ren_args *a)
22917 + struct dentry *d;
22918 + struct inode *delegated;
22920 + d = a->src_dentry;
22921 + if (au_dbtop(d) == a->btgt) {
22922 + a->h_path.dentry = a->dst_h_dentry;
22923 + AuDebugOn(au_dbtop(d) != a->btgt);
22924 + delegated = NULL;
22925 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22926 + a->dst_h_dir, &a->h_path, &delegated,
22928 + if (unlikely(err == -EWOULDBLOCK)) {
22929 + pr_warn("cannot retry for NFSv4 delegation"
22930 + " for an internal rename\n");
22936 + if (!err && a->h_dst)
22937 + /* it will be set to dinfo later */
22943 +/* cf. aufs_rmdir() */
22944 +static int au_ren_del_whtmp(struct au_ren_args *a)
22947 + struct inode *dir;
22949 + dir = a->dst_dir;
22950 + SiMustAnyLock(dir->i_sb);
22951 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22952 + au_sbi(dir->i_sb)->si_dirwh)
22953 + || au_test_fs_remote(a->h_dst->d_sb)) {
22954 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22955 + if (unlikely(err))
22956 + pr_warn("failed removing whtmp dir %pd (%d), "
22957 + "ignored.\n", a->h_dst, err);
22959 + au_nhash_wh_free(&a->thargs->whlist);
22960 + a->thargs->whlist = a->whlist;
22961 + a->whlist.nh_num = 0;
22962 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22964 + a->thargs = NULL;
22970 +/* make it 'opaque' dir. */
22971 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22974 + struct dentry *d, *diropq;
22975 +#define src_or_dst(member) a->sd[idx].member
22978 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22979 + src_or_dst(bdiropq) = au_dbdiropq(d);
22980 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22981 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22982 + diropq = au_diropq_create(d, a->btgt);
22983 + au_hn_inode_unlock(src_or_dst(hinode));
22984 + if (IS_ERR(diropq))
22985 + err = PTR_ERR(diropq);
22989 +#undef src_or_dst_
22993 +static int au_ren_diropq(struct au_ren_args *a)
22996 + unsigned char always;
22997 + struct dentry *d;
23000 + d = a->dst_dentry; /* already renamed on the branch */
23001 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
23002 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23003 + && !au_ftest_ren(a->auren_flags, DIRREN)
23004 + && a->btgt != au_dbdiropq(a->src_dentry)
23005 + && (a->dst_wh_dentry
23006 + || a->btgt <= au_dbdiropq(d)
23007 + /* hide the lower to keep xino */
23008 + /* the lowers may not be a dir, but we hide them anyway */
23009 + || a->btgt < au_dbbot(d)
23012 + err = au_ren_do_diropq(a, AuSRC);
23013 + if (unlikely(err))
23015 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
23017 + if (!a->exchange)
23018 + goto out; /* success */
23020 + d = a->src_dentry; /* already renamed on the branch */
23021 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23022 + && a->btgt != au_dbdiropq(a->dst_dentry)
23023 + && (a->btgt < au_dbdiropq(d)
23024 + || a->btgt < au_dbbot(d)
23026 + AuDbgDentry(a->src_dentry);
23027 + AuDbgDentry(a->dst_dentry);
23028 + err = au_ren_do_diropq(a, AuDST);
23029 + if (unlikely(err))
23030 + goto out_rev_src;
23031 + au_fset_ren(a->auren_flags, DIROPQ_DST);
23033 + goto out; /* success */
23036 + AuDbg("err %d, reverting src\n", err);
23037 + au_ren_rev_diropq(err, a);
23042 +static int do_rename(struct au_ren_args *a)
23045 + struct dentry *d, *h_d;
23047 + if (!a->exchange) {
23048 + /* prepare workqueue args for asynchronous rmdir */
23049 + h_d = a->dst_h_dentry;
23050 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23051 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
23052 + && d_is_positive(h_d)) {
23054 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
23056 + if (unlikely(!a->thargs))
23058 + a->h_dst = dget(h_d);
23061 + /* create whiteout for src_dentry */
23062 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
23063 + a->src_bwh = au_dbwh(a->src_dentry);
23064 + AuDebugOn(a->src_bwh >= 0);
23065 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
23066 + a->src_h_parent);
23067 + err = PTR_ERR(a->src_wh_dentry);
23068 + if (IS_ERR(a->src_wh_dentry))
23072 + /* lookup whiteout for dentry */
23073 + if (au_ftest_ren(a->auren_flags, WHDST)) {
23074 + h_d = au_wh_lkup(a->dst_h_parent,
23075 + &a->dst_dentry->d_name, a->br);
23076 + err = PTR_ERR(h_d);
23079 + if (d_is_negative(h_d))
23082 + a->dst_wh_dentry = h_d;
23085 + /* rename dentry to tmpwh */
23087 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23088 + if (unlikely(err))
23091 + d = a->dst_dentry;
23092 + au_set_h_dptr(d, a->btgt, NULL);
23093 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23094 + if (unlikely(err))
23096 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23100 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23102 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23103 + && d_is_positive(a->dst_h_dentry)
23104 + && a->src_btop != a->btgt);
23107 + /* rename by vfs_rename or cpup */
23108 + err = au_ren_or_cpup(a);
23109 + if (unlikely(err))
23110 + /* leave the copied-up one */
23113 + /* make dir opaque */
23114 + err = au_ren_diropq(a);
23115 + if (unlikely(err))
23118 + /* update target timestamps */
23119 + if (a->exchange) {
23120 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23121 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23122 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23123 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23125 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23126 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23127 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23128 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23130 + if (!a->exchange) {
23131 + /* remove whiteout for dentry */
23132 + if (a->dst_wh_dentry) {
23133 + a->h_path.dentry = a->dst_wh_dentry;
23134 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23136 + if (unlikely(err))
23140 + /* remove whtmp */
23142 + au_ren_del_whtmp(a); /* ignore this error */
23144 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23147 + goto out_success;
23150 + au_ren_rev_diropq(err, a);
23152 + au_ren_rev_rename(err, a);
23156 + au_ren_rev_whtmp(err, a);
23158 + dput(a->dst_wh_dentry);
23159 + a->dst_wh_dentry = NULL;
23161 + if (a->src_wh_dentry)
23162 + au_ren_rev_whsrc(err, a);
23164 + dput(a->src_wh_dentry);
23165 + dput(a->dst_wh_dentry);
23169 + au_whtmp_rmdir_free(a->thargs);
23170 + a->thargs = NULL;
23176 +/* ---------------------------------------------------------------------- */
23179 + * test if @dentry dir can be rename destination or not.
23180 + * success means, it is a logically empty dir.
23182 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23184 + return au_test_empty(dentry, whlist);
23188 + * test if @a->src_dentry dir can be rename source or not.
23189 + * if it can, return 0.
23191 + * - it is a logically empty dir.
23192 + * - or, it exists on writable branch and has no children including whiteouts
23193 + * on the lower branch unless DIRREN is on.
23195 +static int may_rename_srcdir(struct au_ren_args *a)
23198 + unsigned int rdhash;
23199 + aufs_bindex_t btop, btgt;
23200 + struct dentry *dentry;
23201 + struct super_block *sb;
23202 + struct au_sbinfo *sbinfo;
23204 + dentry = a->src_dentry;
23205 + sb = dentry->d_sb;
23206 + sbinfo = au_sbi(sb);
23207 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23208 + au_fset_ren(a->auren_flags, DIRREN);
23211 + btop = au_dbtop(dentry);
23212 + if (btop != btgt) {
23213 + struct au_nhash whlist;
23215 + SiMustAnyLock(sb);
23216 + rdhash = sbinfo->si_rdhash;
23218 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23220 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23221 + if (unlikely(err))
23223 + err = au_test_empty(dentry, &whlist);
23224 + au_nhash_wh_free(&whlist);
23228 + if (btop == au_dbtaildir(dentry))
23229 + return 0; /* success */
23231 + err = au_test_empty_lower(dentry);
23234 + if (err == -ENOTEMPTY) {
23235 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23238 + AuWarn1("renaming dir who has child(ren) on multiple "
23239 + "branches, is not supported\n");
23246 +/* side effect: sets whlist and h_dentry */
23247 +static int au_ren_may_dir(struct au_ren_args *a)
23250 + unsigned int rdhash;
23251 + struct dentry *d;
23253 + d = a->dst_dentry;
23254 + SiMustAnyLock(d->d_sb);
23257 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23258 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23260 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23261 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23262 + if (unlikely(err))
23265 + if (!a->exchange) {
23266 + au_set_dbtop(d, a->dst_btop);
23267 + err = may_rename_dstdir(d, &a->whlist);
23268 + au_set_dbtop(d, a->btgt);
23270 + err = may_rename_srcdir(a);
23272 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23273 + if (unlikely(err))
23276 + d = a->src_dentry;
23277 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23278 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23279 + err = may_rename_srcdir(a);
23280 + if (unlikely(err)) {
23281 + au_nhash_wh_free(&a->whlist);
23282 + a->whlist.nh_num = 0;
23289 +/* ---------------------------------------------------------------------- */
23292 + * simple tests for rename.
23293 + * following the checks in vfs, plus the parent-child relationship.
23295 +static int au_may_ren(struct au_ren_args *a)
23298 + struct inode *h_inode;
23300 + if (a->src_btop == a->btgt) {
23301 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23302 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23303 + if (unlikely(err))
23306 + if (unlikely(a->src_h_dentry == a->h_trap))
23311 + if (a->dst_btop != a->btgt)
23314 + err = -ENOTEMPTY;
23315 + if (unlikely(a->dst_h_dentry == a->h_trap))
23319 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23320 + if (d_really_is_negative(a->dst_dentry)) {
23321 + if (d_is_negative(a->dst_h_dentry))
23322 + err = au_may_add(a->dst_dentry, a->btgt,
23323 + a->dst_h_parent, isdir);
23325 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23327 + h_inode = d_inode(a->dst_h_dentry);
23328 + if (h_inode->i_nlink)
23329 + err = au_may_del(a->dst_dentry, a->btgt,
23330 + a->dst_h_parent, isdir);
23334 + if (unlikely(err == -ENOENT || err == -EEXIST))
23340 +/* ---------------------------------------------------------------------- */
23345 + * - src_dir and dir by lock_rename()
23346 + * - inode if exists
23349 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23351 + * + di_write_lock2_child()
23352 + * + di_write_lock_child()
23353 + * + ii_write_lock_child()
23354 + * + di_write_lock_child2()
23355 + * + ii_write_lock_child2()
23356 + * + src_parent and parent
23357 + * + di_write_lock_parent()
23358 + * + ii_write_lock_parent()
23359 + * + di_write_lock_parent2()
23360 + * + ii_write_lock_parent2()
23361 + * + lower src_dir and dir by vfsub_lock_rename()
23362 + * + verify the every relationships between child and parent. if any
23363 + * of them failed, unlock all and return -EBUSY.
23365 +static void au_ren_unlock(struct au_ren_args *a)
23367 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23368 + a->dst_h_parent, a->dst_hdir);
23369 + if (au_ftest_ren(a->auren_flags, DIRREN)
23371 + au_hn_inode_unlock(a->h_root);
23372 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23373 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23376 +static int au_ren_lock(struct au_ren_args *a)
23379 + unsigned int udba;
23382 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23383 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23384 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23385 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23387 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23388 + if (unlikely(err))
23390 + au_fset_ren(a->auren_flags, MNT_WRITE);
23391 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23392 + struct dentry *root;
23393 + struct inode *dir;
23396 + * sbinfo is already locked, so this ii_read_lock is
23397 + * unnecessary. but our debugging feature checks it.
23399 + root = a->src_inode->i_sb->s_root;
23400 + if (root != a->src_parent && root != a->dst_parent) {
23401 + dir = d_inode(root);
23402 + ii_read_lock_parent3(dir);
23403 + a->h_root = au_hi(dir, a->btgt);
23404 + ii_read_unlock(dir);
23405 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23408 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23409 + a->dst_h_parent, a->dst_hdir);
23410 + udba = au_opt_udba(a->src_dentry->d_sb);
23411 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23412 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23413 + err = au_busy_or_stale();
23414 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23415 + err = au_h_verify(a->src_h_dentry, udba,
23416 + d_inode(a->src_h_parent), a->src_h_parent,
23418 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23419 + err = au_h_verify(a->dst_h_dentry, udba,
23420 + d_inode(a->dst_h_parent), a->dst_h_parent,
23423 + goto out; /* success */
23425 + err = au_busy_or_stale();
23426 + au_ren_unlock(a);
23432 +/* ---------------------------------------------------------------------- */
23434 +static void au_ren_refresh_dir(struct au_ren_args *a)
23436 + struct inode *dir;
23438 + dir = a->dst_dir;
23439 + inode_inc_iversion(dir);
23440 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23441 + /* is this updating defined in POSIX? */
23442 + au_cpup_attr_timesizes(a->src_inode);
23443 + au_cpup_attr_nlink(dir, /*force*/1);
23445 + au_dir_ts(dir, a->btgt);
23447 + if (a->exchange) {
23448 + dir = a->src_dir;
23449 + inode_inc_iversion(dir);
23450 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23451 + /* is this updating defined in POSIX? */
23452 + au_cpup_attr_timesizes(a->dst_inode);
23453 + au_cpup_attr_nlink(dir, /*force*/1);
23455 + au_dir_ts(dir, a->btgt);
23458 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23461 + dir = a->src_dir;
23462 + inode_inc_iversion(dir);
23463 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23464 + au_cpup_attr_nlink(dir, /*force*/1);
23465 + au_dir_ts(dir, a->btgt);
23468 +static void au_ren_refresh(struct au_ren_args *a)
23470 + aufs_bindex_t bbot, bindex;
23471 + struct dentry *d, *h_d;
23472 + struct inode *i, *h_i;
23473 + struct super_block *sb;
23475 + d = a->dst_dentry;
23478 + /* already dget-ed by au_ren_or_cpup() */
23479 + au_set_h_dptr(d, a->btgt, a->h_dst);
23481 + i = a->dst_inode;
23483 + if (!a->exchange) {
23484 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23485 + vfsub_drop_nlink(i);
23487 + vfsub_dead_dir(i);
23488 + au_cpup_attr_timesizes(i);
23490 + au_update_dbrange(d, /*do_put_zero*/1);
23492 + au_cpup_attr_nlink(i, /*force*/1);
23495 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23496 + au_set_h_dptr(d, bindex, NULL);
23497 + bbot = au_dbbot(d);
23498 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23499 + au_set_h_dptr(d, bindex, NULL);
23500 + au_update_dbrange(d, /*do_put_zero*/0);
23504 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23505 + d_drop(a->src_dentry);
23506 + if (au_ftest_ren(a->auren_flags, DIRREN))
23507 + au_set_dbwh(a->src_dentry, -1);
23511 + d = a->src_dentry;
23512 + au_set_dbwh(d, -1);
23513 + bbot = au_dbbot(d);
23514 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23515 + h_d = au_h_dptr(d, bindex);
23517 + au_set_h_dptr(d, bindex, NULL);
23519 + au_set_dbbot(d, a->btgt);
23522 + i = a->src_inode;
23523 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23524 + return; /* success */
23526 + bbot = au_ibbot(i);
23527 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23528 + h_i = au_h_iptr(i, bindex);
23530 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23531 + /* ignore this error */
23532 + au_set_h_iptr(i, bindex, NULL, 0);
23535 + au_set_ibbot(i, a->btgt);
23538 +/* ---------------------------------------------------------------------- */
23540 +/* mainly for link(2) and rename(2) */
23541 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23543 + aufs_bindex_t bdiropq, bwh;
23544 + struct dentry *parent;
23545 + struct au_branch *br;
23547 + parent = dentry->d_parent;
23548 + IMustLock(d_inode(parent)); /* dir is locked */
23550 + bdiropq = au_dbdiropq(parent);
23551 + bwh = au_dbwh(dentry);
23552 + br = au_sbr(dentry->d_sb, btgt);
23553 + if (au_br_rdonly(br)
23554 + || (0 <= bdiropq && bdiropq < btgt)
23555 + || (0 <= bwh && bwh < btgt))
23558 + AuDbg("btgt %d\n", btgt);
23562 +/* sets src_btop, dst_btop and btgt */
23563 +static int au_ren_wbr(struct au_ren_args *a)
23566 + struct au_wr_dir_args wr_dir_args = {
23567 + /* .force_btgt = -1, */
23568 + .flags = AuWrDir_ADD_ENTRY
23571 + a->src_btop = au_dbtop(a->src_dentry);
23572 + a->dst_btop = au_dbtop(a->dst_dentry);
23573 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23574 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23575 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23576 + wr_dir_args.force_btgt = a->src_btop;
23577 + if (a->dst_inode && a->dst_btop < a->src_btop)
23578 + wr_dir_args.force_btgt = a->dst_btop;
23579 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23580 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23583 + au_update_dbtop(a->dst_dentry);
23588 +static void au_ren_dt(struct au_ren_args *a)
23590 + a->h_path.dentry = a->src_h_parent;
23591 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23592 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23593 + a->h_path.dentry = a->dst_h_parent;
23594 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23597 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23598 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23602 + a->h_path.dentry = a->src_h_dentry;
23603 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23604 + if (d_is_positive(a->dst_h_dentry)) {
23605 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23606 + a->h_path.dentry = a->dst_h_dentry;
23607 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23611 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23613 + struct dentry *h_d;
23614 + struct inode *h_inode;
23616 + au_dtime_revert(a->src_dt + AuPARENT);
23617 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23618 + au_dtime_revert(a->dst_dt + AuPARENT);
23620 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23621 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23622 + h_inode = d_inode(h_d);
23623 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23624 + au_dtime_revert(a->src_dt + AuCHILD);
23625 + inode_unlock(h_inode);
23627 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23628 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23629 + h_inode = d_inode(h_d);
23630 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23631 + au_dtime_revert(a->dst_dt + AuCHILD);
23632 + inode_unlock(h_inode);
23637 +/* ---------------------------------------------------------------------- */
23639 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23640 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23641 + unsigned int _flags)
23643 + int err, lock_flags;
23645 + /* reduce stack space */
23646 + struct au_ren_args *a;
23647 + struct au_pin pin;
23649 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23650 + IMustLock(_src_dir);
23651 + IMustLock(_dst_dir);
23654 + if (unlikely(_flags & RENAME_WHITEOUT))
23658 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23659 + a = kzalloc(sizeof(*a), GFP_NOFS);
23660 + if (unlikely(!a))
23663 + a->flags = _flags;
23664 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23665 + && RENAME_EXCHANGE > U8_MAX);
23666 + a->exchange = _flags & RENAME_EXCHANGE;
23667 + a->src_dir = _src_dir;
23668 + a->src_dentry = _src_dentry;
23669 + a->src_inode = NULL;
23670 + if (d_really_is_positive(a->src_dentry))
23671 + a->src_inode = d_inode(a->src_dentry);
23672 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23673 + a->dst_dir = _dst_dir;
23674 + a->dst_dentry = _dst_dentry;
23675 + a->dst_inode = NULL;
23676 + if (d_really_is_positive(a->dst_dentry))
23677 + a->dst_inode = d_inode(a->dst_dentry);
23678 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23679 + if (a->dst_inode) {
23681 + * if EXCHANGE && src is non-dir && dst is dir,
23682 + * dst is not locked.
23684 + /* IMustLock(a->dst_inode); */
23685 + au_igrab(a->dst_inode);
23689 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23690 + if (d_is_dir(a->src_dentry)) {
23691 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23692 + if (unlikely(!a->exchange
23693 + && d_really_is_positive(a->dst_dentry)
23694 + && !d_is_dir(a->dst_dentry)))
23696 + lock_flags |= AuLock_DIRS;
23698 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23699 + au_fset_ren(a->auren_flags, ISDIR_DST);
23700 + if (unlikely(!a->exchange
23701 + && d_really_is_positive(a->src_dentry)
23702 + && !d_is_dir(a->src_dentry)))
23704 + lock_flags |= AuLock_DIRS;
23706 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23708 + if (unlikely(err))
23711 + err = au_d_hashed_positive(a->src_dentry);
23712 + if (unlikely(err))
23715 + if (a->dst_inode) {
23717 + * If it is a dir, VFS unhash it before this
23718 + * function. It means we cannot rely upon d_unhashed().
23720 + if (unlikely(!a->dst_inode->i_nlink))
23722 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23723 + err = au_d_hashed_positive(a->dst_dentry);
23724 + if (unlikely(err && !a->exchange))
23726 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23728 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23732 + * is it possible?
23733 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23734 + * there may exist a problem somewhere else.
23737 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23740 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23741 + di_write_lock_parent(a->dst_parent);
23743 + /* which branch we process */
23744 + err = au_ren_wbr(a);
23745 + if (unlikely(err < 0))
23747 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23748 + a->h_path.mnt = au_br_mnt(a->br);
23750 + /* are they available to be renamed */
23751 + err = au_ren_may_dir(a);
23752 + if (unlikely(err))
23753 + goto out_children;
23755 + /* prepare the writable parent dir on the same branch */
23756 + if (a->dst_btop == a->btgt) {
23757 + au_fset_ren(a->auren_flags, WHDST);
23759 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23760 + if (unlikely(err))
23761 + goto out_children;
23765 + if (!a->exchange) {
23766 + if (a->src_dir != a->dst_dir) {
23768 + * this temporary unlock is safe,
23769 + * because both dir->i_mutex are locked.
23771 + di_write_unlock(a->dst_parent);
23772 + di_write_lock_parent(a->src_parent);
23773 + err = au_wr_dir_need_wh(a->src_dentry,
23774 + au_ftest_ren(a->auren_flags,
23777 + di_write_unlock(a->src_parent);
23778 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23780 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23782 + err = au_wr_dir_need_wh(a->src_dentry,
23783 + au_ftest_ren(a->auren_flags,
23787 + if (unlikely(err < 0))
23788 + goto out_children;
23790 + au_fset_ren(a->auren_flags, WHSRC);
23793 + if (a->src_btop != a->btgt) {
23794 + err = au_pin(&pin, a->src_dentry, a->btgt,
23795 + au_opt_udba(a->src_dentry->d_sb),
23796 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23798 + struct au_cp_generic cpg = {
23799 + .dentry = a->src_dentry,
23801 + .bsrc = a->src_btop,
23804 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23806 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23807 + err = au_sio_cpup_simple(&cpg);
23810 + if (unlikely(err))
23811 + goto out_children;
23812 + a->src_btop = a->btgt;
23813 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23814 + if (!a->exchange)
23815 + au_fset_ren(a->auren_flags, WHSRC);
23819 + if (a->exchange && a->dst_inode
23820 + && a->dst_btop != a->btgt) {
23821 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23822 + au_opt_udba(a->dst_dentry->d_sb),
23823 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23825 + struct au_cp_generic cpg = {
23826 + .dentry = a->dst_dentry,
23828 + .bsrc = a->dst_btop,
23831 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23833 + err = au_sio_cpup_simple(&cpg);
23836 + if (unlikely(err))
23837 + goto out_children;
23838 + a->dst_btop = a->btgt;
23839 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23842 + /* lock them all */
23843 + err = au_ren_lock(a);
23844 + if (unlikely(err))
23845 + /* leave the copied-up one */
23846 + goto out_children;
23848 + if (!a->exchange) {
23849 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23850 + err = au_may_ren(a);
23851 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23852 + err = -ENAMETOOLONG;
23853 + if (unlikely(err))
23857 + /* store timestamps to be revertible */
23860 + /* store dirren info */
23861 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23862 + err = au_dr_rename(a->src_dentry, a->btgt,
23863 + &a->dst_dentry->d_name, &rev);
23865 + if (unlikely(err))
23870 + err = do_rename(a);
23871 + if (unlikely(err))
23874 + if (au_ftest_ren(a->auren_flags, DIRREN))
23875 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23877 + /* update dir attributes */
23878 + au_ren_refresh_dir(a);
23880 + /* dput/iput all lower dentries */
23881 + au_ren_refresh(a);
23883 + goto out_hdir; /* success */
23886 + if (au_ftest_ren(a->auren_flags, DIRREN))
23887 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23889 + au_ren_rev_dt(err, a);
23891 + au_ren_unlock(a);
23893 + au_nhash_wh_free(&a->whlist);
23894 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23895 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23896 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23897 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23901 + if (d_unhashed(a->src_dentry))
23902 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23903 + if (d_unhashed(a->dst_dentry))
23904 + au_fset_ren(a->auren_flags, DROPPED_DST);
23905 + if (!a->exchange)
23906 + d_move(a->src_dentry, a->dst_dentry);
23908 + d_exchange(a->src_dentry, a->dst_dentry);
23909 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23910 + d_drop(a->dst_dentry);
23912 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23913 + d_drop(a->src_dentry);
23915 + au_update_dbtop(a->dst_dentry);
23916 + if (!a->dst_inode)
23917 + d_drop(a->dst_dentry);
23919 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23920 + di_write_unlock(a->dst_parent);
23922 + di_write_unlock2(a->src_parent, a->dst_parent);
23924 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23926 + iput(a->dst_inode);
23928 + au_whtmp_rmdir_free(a->thargs);
23934 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23935 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23936 +++ linux/fs/aufs/Kconfig 2019-01-28 14:36:12.219084659 +0100
23938 +# SPDX-License-Identifier: GPL-2.0
23940 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23942 + Aufs is a stackable unification filesystem such as Unionfs,
23943 + which unifies several directories and provides a merged single
23945 + In the early days, aufs was entirely re-designed and
23946 + re-implemented Unionfs Version 1.x series. Introducing many
23947 + original ideas, approaches and improvements, it becomes totally
23948 + different from Unionfs while keeping the basic features.
23952 + prompt "Maximum number of branches"
23953 + default AUFS_BRANCH_MAX_127
23955 + Specifies the maximum number of branches (or member directories)
23956 + in a single aufs. The larger value consumes more system
23957 + resources and has a minor impact to performance.
23958 +config AUFS_BRANCH_MAX_127
23961 + Specifies the maximum number of branches (or member directories)
23962 + in a single aufs. The larger value consumes more system
23963 + resources and has a minor impact to performance.
23964 +config AUFS_BRANCH_MAX_511
23967 + Specifies the maximum number of branches (or member directories)
23968 + in a single aufs. The larger value consumes more system
23969 + resources and has a minor impact to performance.
23970 +config AUFS_BRANCH_MAX_1023
23973 + Specifies the maximum number of branches (or member directories)
23974 + in a single aufs. The larger value consumes more system
23975 + resources and has a minor impact to performance.
23976 +config AUFS_BRANCH_MAX_32767
23979 + Specifies the maximum number of branches (or member directories)
23980 + in a single aufs. The larger value consumes more system
23981 + resources and has a minor impact to performance.
23984 +config AUFS_SBILIST
23986 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23989 + Automatic configuration for internal use.
23990 + When aufs supports Magic SysRq or /proc, enabled automatically.
23992 +config AUFS_HNOTIFY
23993 + bool "Detect direct branch access (bypassing aufs)"
23995 + If you want to modify files on branches directly, eg. bypassing aufs,
23996 + and want aufs to detect the changes of them fully, then enable this
23997 + option and use 'udba=notify' mount option.
23998 + Currently there is only one available configuration, "fsnotify".
23999 + It will have a negative impact to the performance.
24000 + See detail in aufs.5.
24003 + prompt "method" if AUFS_HNOTIFY
24004 + default AUFS_HFSNOTIFY
24005 +config AUFS_HFSNOTIFY
24010 +config AUFS_EXPORT
24011 + bool "NFS-exportable aufs"
24012 + depends on EXPORTFS
24014 + If you want to export your mounted aufs via NFS, then enable this
24015 + option. There are several requirements for this configuration.
24016 + See detail in aufs.5.
24018 +config AUFS_INO_T_64
24020 + depends on AUFS_EXPORT
24021 + depends on 64BIT && !(ALPHA || S390)
24024 + Automatic configuration for internal use.
24025 + /* typedef unsigned long/int __kernel_ino_t */
24026 + /* alpha and s390x are int */
24029 + bool "support for XATTR/EA (including Security Labels)"
24031 + If your branch fs supports XATTR/EA and you want to make them
24032 + available in aufs too, then enable this opsion and specify the
24033 + branch attributes for EA.
24034 + See detail in aufs.5.
24037 + bool "File-based Hierarchical Storage Management"
24039 + Hierarchical Storage Management (or HSM) is a well-known feature
24040 + in the storage world. Aufs provides this feature as file-based.
24041 + with multiple branches.
24042 + These multiple branches are prioritized, ie. the topmost one
24043 + should be the fastest drive and be used heavily.
24046 + bool "Readdir in userspace"
24048 + Aufs has two methods to provide a merged view for a directory,
24049 + by a user-space library and by kernel-space natively. The latter
24050 + is always enabled but sometimes large and slow.
24051 + If you enable this option, install the library in aufs2-util
24052 + package, and set some environment variables for your readdir(3),
24053 + then the work will be handled in user-space which generally
24054 + shows better performance in most cases.
24055 + See detail in aufs.5.
24057 +config AUFS_DIRREN
24058 + bool "Workaround for rename(2)-ing a directory"
24060 + By default, aufs returns EXDEV error in renameing a dir who has
24061 + his child on the lower branch, since it is a bad idea to issue
24062 + rename(2) internally for every lower branch. But user may not
24063 + accept this behaviour. So here is a workaround to allow such
24064 + rename(2) and store some extra infromation on the writable
24065 + branch. Obviously this costs high (and I don't like it).
24066 + To use this feature, you need to enable this configuration AND
24067 + to specify the mount option `dirren.'
24068 + See details in aufs.5 and the design documents.
24071 + bool "Show whiteouts"
24073 + If you want to make the whiteouts in aufs visible, then enable
24074 + this option and specify 'shwh' mount option. Although it may
24075 + sounds like philosophy or something, but in technically it
24076 + simply shows the name of whiteout with keeping its behaviour.
24078 +config AUFS_BR_RAMFS
24079 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
24081 + If you want to use ramfs as an aufs branch fs, then enable this
24082 + option. Generally tmpfs is recommended.
24083 + Aufs prohibited them to be a branch fs by default, because
24084 + initramfs becomes unusable after switch_root or something
24085 + generally. If you sets initramfs as an aufs branch and boot your
24086 + system by switch_root, you will meet a problem easily since the
24087 + files in initramfs may be inaccessible.
24088 + Unless you are going to use ramfs as an aufs branch fs without
24089 + switch_root or something, leave it N.
24091 +config AUFS_BR_FUSE
24092 + bool "Fuse fs as an aufs branch"
24093 + depends on FUSE_FS
24096 + If you want to use fuse-based userspace filesystem as an aufs
24097 + branch fs, then enable this option.
24098 + It implements the internal poll(2) operation which is
24099 + implemented by fuse only (curretnly).
24104 + Automatic configuration for internal use.
24106 +config AUFS_BR_HFSPLUS
24107 + bool "Hfsplus as an aufs branch"
24108 + depends on HFSPLUS_FS
24111 + If you want to use hfsplus fs as an aufs branch fs, then enable
24112 + this option. This option introduces a small overhead at
24113 + copying-up a file on hfsplus.
24115 +config AUFS_BDEV_LOOP
24117 + depends on BLK_DEV_LOOP
24120 + Automatic configuration for internal use.
24121 + Convert =[ym] into =y.
24124 + bool "Debug aufs"
24126 + Enable this to compile aufs internal debug code.
24127 + It will have a negative impact to the performance.
24129 +config AUFS_MAGIC_SYSRQ
24131 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24134 + Automatic configuration for internal use.
24135 + When aufs supports Magic SysRq, enabled automatically.
24137 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24138 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24139 +++ linux/fs/aufs/lcnt.h 2019-01-28 14:36:12.222418047 +0100
24141 +/* SPDX-License-Identifier: GPL-2.0 */
24143 + * Copyright (C) 2018 Junjiro R. Okajima
24145 + * This program, aufs is free software; you can redistribute it and/or modify
24146 + * it under the terms of the GNU General Public License as published by
24147 + * the Free Software Foundation; either version 2 of the License, or
24148 + * (at your option) any later version.
24150 + * This program is distributed in the hope that it will be useful,
24151 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24152 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24153 + * GNU General Public License for more details.
24155 + * You should have received a copy of the GNU General Public License
24156 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24160 + * simple long counter wrapper
24163 +#ifndef __AUFS_LCNT_H__
24164 +#define __AUFS_LCNT_H__
24168 +#include "debug.h"
24170 +#define AuLCntATOMIC 1
24171 +#define AuLCntPCPUCNT 2
24173 + * why does percpu_refcount require extra synchronize_rcu()s in
24174 + * au_br_do_free()
24176 +#define AuLCntPCPUREF 3
24178 +/* #define AuLCntChosen AuLCntATOMIC */
24179 +#define AuLCntChosen AuLCntPCPUCNT
24180 +/* #define AuLCntChosen AuLCntPCPUREF */
24182 +#if AuLCntChosen == AuLCntATOMIC
24183 +#include <linux/atomic.h>
24185 +typedef atomic_long_t au_lcnt_t;
24187 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24189 + atomic_long_set(cnt, 0);
24193 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24198 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24199 + int do_sync __maybe_unused)
24204 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24206 + atomic_long_inc(cnt);
24209 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24211 + atomic_long_dec(cnt);
24214 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24216 + return atomic_long_read(cnt);
24220 +#if AuLCntChosen == AuLCntPCPUCNT
24221 +#include <linux/percpu_counter.h>
24223 +typedef struct percpu_counter au_lcnt_t;
24225 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24227 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24230 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24235 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24237 + percpu_counter_destroy(cnt);
24240 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24242 + percpu_counter_inc(cnt);
24245 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24247 + percpu_counter_dec(cnt);
24250 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24254 + n = percpu_counter_sum(cnt);
24256 + if (LONG_MAX != LLONG_MAX
24258 + AuWarn1("%s\n", "wrap-around");
24264 +#if AuLCntChosen == AuLCntPCPUREF
24265 +#include <linux/percpu-refcount.h>
24267 +typedef struct percpu_ref au_lcnt_t;
24269 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24272 + release = percpu_ref_exit;
24273 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24276 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24278 + synchronize_rcu();
24281 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24283 + percpu_ref_kill(cnt);
24285 + au_lcnt_wait_for_fin(cnt);
24288 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24290 + percpu_ref_get(cnt);
24293 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24295 + percpu_ref_put(cnt);
24299 + * avoid calling this func as possible.
24301 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24305 + percpu_ref_switch_to_atomic_sync(cnt);
24306 + l = atomic_long_read(&cnt->count);
24308 + percpu_ref_switch_to_percpu(cnt);
24310 + /* percpu_ref is initialized by 1 instead of 0 */
24315 +#ifdef CONFIG_AUFS_DEBUG
24316 +#define AuLCntZero(val) do { \
24319 + AuDbg("%s = %ld\n", #val, l); \
24322 +#define AuLCntZero(val) do {} while (0)
24325 +#endif /* __KERNEL__ */
24326 +#endif /* __AUFS_LCNT_H__ */
24327 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24328 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24329 +++ linux/fs/aufs/loop.c 2019-01-28 14:36:12.222418047 +0100
24331 +// SPDX-License-Identifier: GPL-2.0
24333 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24335 + * This program, aufs is free software; you can redistribute it and/or modify
24336 + * it under the terms of the GNU General Public License as published by
24337 + * the Free Software Foundation; either version 2 of the License, or
24338 + * (at your option) any later version.
24340 + * This program is distributed in the hope that it will be useful,
24341 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24342 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24343 + * GNU General Public License for more details.
24345 + * You should have received a copy of the GNU General Public License
24346 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24350 + * support for loopback block device as a branch
24355 +/* added into drivers/block/loop.c */
24356 +static struct file *(*backing_file_func)(struct super_block *sb);
24359 + * test if two lower dentries have overlapping branches.
24361 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24363 + struct super_block *h_sb;
24364 + struct file *backing_file;
24366 + if (unlikely(!backing_file_func)) {
24367 + /* don't load "loop" module here */
24368 + backing_file_func = symbol_get(loop_backing_file);
24369 + if (unlikely(!backing_file_func))
24370 + /* "loop" module is not loaded */
24374 + h_sb = h_adding->d_sb;
24375 + backing_file = backing_file_func(h_sb);
24376 + if (!backing_file)
24379 + h_adding = backing_file->f_path.dentry;
24381 + * h_adding can be local NFS.
24382 + * in this case aufs cannot detect the loop.
24384 + if (unlikely(h_adding->d_sb == sb))
24386 + return !!au_test_subdir(h_adding, sb->s_root);
24389 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24390 +int au_test_loopback_kthread(void)
24393 + struct task_struct *tsk = current;
24394 + char c, comm[sizeof(tsk->comm)];
24397 + if (tsk->flags & PF_KTHREAD) {
24398 + get_task_comm(comm, tsk);
24400 + ret = ('0' <= c && c <= '9'
24401 + && !strncmp(comm, "loop", 4));
24407 +/* ---------------------------------------------------------------------- */
24409 +#define au_warn_loopback_step 16
24410 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24411 +static unsigned long *au_warn_loopback_array;
24413 +void au_warn_loopback(struct super_block *h_sb)
24415 + int i, new_nelem;
24416 + unsigned long *a, magic;
24417 + static DEFINE_SPINLOCK(spin);
24419 + magic = h_sb->s_magic;
24420 + spin_lock(&spin);
24421 + a = au_warn_loopback_array;
24422 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24423 + if (a[i] == magic) {
24424 + spin_unlock(&spin);
24428 + /* h_sb is new to us, print it */
24429 + if (i < au_warn_loopback_nelem) {
24434 + /* expand the array */
24435 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24436 + a = au_kzrealloc(au_warn_loopback_array,
24437 + au_warn_loopback_nelem * sizeof(unsigned long),
24438 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24439 + /*may_shrink*/0);
24441 + au_warn_loopback_nelem = new_nelem;
24442 + au_warn_loopback_array = a;
24447 + spin_unlock(&spin);
24448 + AuWarn1("realloc failed, ignored\n");
24452 + spin_unlock(&spin);
24453 + pr_warn("you may want to try another patch for loopback file "
24454 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24457 +int au_loopback_init(void)
24460 + struct super_block *sb __maybe_unused;
24462 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24465 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24466 + sizeof(unsigned long), GFP_NOFS);
24467 + if (unlikely(!au_warn_loopback_array))
24473 +void au_loopback_fin(void)
24475 + if (backing_file_func)
24476 + symbol_put(loop_backing_file);
24477 + au_kfree_try_rcu(au_warn_loopback_array);
24479 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24480 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24481 +++ linux/fs/aufs/loop.h 2019-01-28 14:36:12.222418047 +0100
24483 +/* SPDX-License-Identifier: GPL-2.0 */
24485 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24487 + * This program, aufs is free software; you can redistribute it and/or modify
24488 + * it under the terms of the GNU General Public License as published by
24489 + * the Free Software Foundation; either version 2 of the License, or
24490 + * (at your option) any later version.
24492 + * This program is distributed in the hope that it will be useful,
24493 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24494 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24495 + * GNU General Public License for more details.
24497 + * You should have received a copy of the GNU General Public License
24498 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24502 + * support for loopback mount as a branch
24505 +#ifndef __AUFS_LOOP_H__
24506 +#define __AUFS_LOOP_H__
24511 +struct super_block;
24513 +#ifdef CONFIG_AUFS_BDEV_LOOP
24514 +/* drivers/block/loop.c */
24515 +struct file *loop_backing_file(struct super_block *sb);
24518 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24519 +int au_test_loopback_kthread(void);
24520 +void au_warn_loopback(struct super_block *h_sb);
24522 +int au_loopback_init(void);
24523 +void au_loopback_fin(void);
24525 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24526 + struct dentry *h_adding)
24527 +AuStubInt0(au_test_loopback_kthread, void)
24528 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24530 +AuStubInt0(au_loopback_init, void)
24531 +AuStubVoid(au_loopback_fin, void)
24532 +#endif /* BLK_DEV_LOOP */
24534 +#endif /* __KERNEL__ */
24535 +#endif /* __AUFS_LOOP_H__ */
24536 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24537 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24538 +++ linux/fs/aufs/magic.mk 2019-01-28 14:36:12.222418047 +0100
24540 +# SPDX-License-Identifier: GPL-2.0
24542 +# defined in ${srctree}/fs/fuse/inode.c
24544 +ifdef CONFIG_FUSE_FS
24545 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24548 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24550 +ifdef CONFIG_XFS_FS
24551 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24554 +# defined in ${srctree}/fs/configfs/mount.c
24556 +ifdef CONFIG_CONFIGFS_FS
24557 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24560 +# defined in ${srctree}/fs/ubifs/ubifs.h
24562 +ifdef CONFIG_UBIFS_FS
24563 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24566 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24568 +ifdef CONFIG_HFSPLUS_FS
24569 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24571 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24572 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24573 +++ linux/fs/aufs/Makefile 2019-01-28 14:36:12.219084659 +0100
24575 +# SPDX-License-Identifier: GPL-2.0
24577 +include ${src}/magic.mk
24578 +ifeq (${CONFIG_AUFS_FS},m)
24579 +include ${src}/conf.mk
24581 +-include ${src}/priv_def.mk
24583 +# cf. include/linux/kernel.h
24585 +ccflags-y += -DDEBUG
24586 +# sparse requires the full pathname
24588 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24590 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24593 +obj-$(CONFIG_AUFS_FS) += aufs.o
24594 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24595 + wkq.o vfsub.o dcsub.o \
24596 + cpup.o whout.o wbr_policy.o \
24597 + dinfo.o dentry.o \
24599 + finfo.o file.o f_op.o \
24601 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24605 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24606 +aufs-$(CONFIG_SYSFS) += sysfs.o
24607 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24608 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24609 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24610 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24611 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24612 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24613 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24614 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24615 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24616 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24617 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24618 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24619 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24620 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24621 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24622 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24623 +++ linux/fs/aufs/module.c 2019-01-28 14:36:12.222418047 +0100
24625 +// SPDX-License-Identifier: GPL-2.0
24627 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24629 + * This program, aufs is free software; you can redistribute it and/or modify
24630 + * it under the terms of the GNU General Public License as published by
24631 + * the Free Software Foundation; either version 2 of the License, or
24632 + * (at your option) any later version.
24634 + * This program is distributed in the hope that it will be useful,
24635 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24636 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24637 + * GNU General Public License for more details.
24639 + * You should have received a copy of the GNU General Public License
24640 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24644 + * module global variables and operations
24647 +#include <linux/module.h>
24648 +#include <linux/seq_file.h>
24651 +/* shrinkable realloc */
24652 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24660 +#if 0 /* unused */
24667 + AuDebugOn(!new_sz);
24670 + diff = au_kmidx_sub(sz, new_sz);
24676 + /* expand or SLOB */
24677 + p = krealloc(p, new_sz, gfp);
24678 + else if (new_sz < sz && may_shrink) {
24682 + q = kmalloc(new_sz, gfp);
24685 + memcpy(q, p, new_sz);
24686 + au_kfree_try_rcu(p);
24697 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24700 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24701 + if (p && new_sz > nused)
24702 + memset(p + nused, 0, new_sz - nused);
24706 +/* ---------------------------------------------------------------------- */
24710 +struct kmem_cache *au_cache[AuCache_Last];
24712 +static void au_cache_fin(void)
24717 + * Make sure all delayed rcu free inodes are flushed before we
24722 + /* excluding AuCache_HNOTIFY */
24723 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24724 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24725 + kmem_cache_destroy(au_cache[i]);
24726 + au_cache[i] = NULL;
24730 +static int __init au_cache_init(void)
24732 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24733 + if (au_cache[AuCache_DINFO])
24734 + /* SLAB_DESTROY_BY_RCU */
24735 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24736 + au_icntnr_init_once);
24737 + if (au_cache[AuCache_ICNTNR])
24738 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24739 + au_fi_init_once);
24740 + if (au_cache[AuCache_FINFO])
24741 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24742 + if (au_cache[AuCache_VDIR])
24743 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24744 + if (au_cache[AuCache_DEHSTR])
24751 +/* ---------------------------------------------------------------------- */
24753 +int au_dir_roflags;
24755 +#ifdef CONFIG_AUFS_SBILIST
24757 + * iterate_supers_type() doesn't protect us from
24758 + * remounting (branch management)
24760 +struct hlist_bl_head au_sbilist;
24764 + * functions for module interface.
24766 +MODULE_LICENSE("GPL");
24767 +/* MODULE_LICENSE("GPL v2"); */
24768 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24769 +MODULE_DESCRIPTION(AUFS_NAME
24770 + " -- Advanced multi layered unification filesystem");
24771 +MODULE_VERSION(AUFS_VERSION);
24772 +MODULE_ALIAS_FS(AUFS_NAME);
24774 +/* this module parameter has no meaning when SYSFS is disabled */
24775 +int sysaufs_brs = 1;
24776 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24777 +module_param_named(brs, sysaufs_brs, int, 0444);
24779 +/* this module parameter has no meaning when USER_NS is disabled */
24781 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24782 +module_param_named(allow_userns, au_userns, bool, 0444);
24784 +/* ---------------------------------------------------------------------- */
24786 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24788 +int au_seq_path(struct seq_file *seq, struct path *path)
24792 + err = seq_path(seq, path, au_esc_chars);
24801 +/* ---------------------------------------------------------------------- */
24803 +static int __init aufs_init(void)
24808 + p = au_esc_chars;
24809 + for (i = 1; i <= ' '; i++)
24815 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24817 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24818 + for (i = 0; i < AuIop_Last; i++)
24819 + aufs_iop_nogetattr[i].getattr = NULL;
24821 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24823 + au_sbilist_init();
24824 + sysaufs_brs_init();
24827 + err = sysaufs_init();
24828 + if (unlikely(err))
24830 + err = dbgaufs_init();
24831 + if (unlikely(err))
24832 + goto out_sysaufs;
24833 + err = au_procfs_init();
24834 + if (unlikely(err))
24835 + goto out_dbgaufs;
24836 + err = au_wkq_init();
24837 + if (unlikely(err))
24839 + err = au_loopback_init();
24840 + if (unlikely(err))
24842 + err = au_hnotify_init();
24843 + if (unlikely(err))
24844 + goto out_loopback;
24845 + err = au_sysrq_init();
24846 + if (unlikely(err))
24848 + err = au_cache_init();
24849 + if (unlikely(err))
24852 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24853 + err = register_filesystem(&aufs_fs_type);
24854 + if (unlikely(err))
24857 + /* since we define pr_fmt, call printk directly */
24858 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24859 + goto out; /* success */
24866 + au_hnotify_fin();
24868 + au_loopback_fin();
24882 +static void __exit aufs_exit(void)
24884 + unregister_filesystem(&aufs_fs_type);
24887 + au_hnotify_fin();
24888 + au_loopback_fin();
24896 +module_init(aufs_init);
24897 +module_exit(aufs_exit);
24898 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24899 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24900 +++ linux/fs/aufs/module.h 2019-01-28 14:36:12.222418047 +0100
24902 +/* SPDX-License-Identifier: GPL-2.0 */
24904 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24906 + * This program, aufs is free software; you can redistribute it and/or modify
24907 + * it under the terms of the GNU General Public License as published by
24908 + * the Free Software Foundation; either version 2 of the License, or
24909 + * (at your option) any later version.
24911 + * This program is distributed in the hope that it will be useful,
24912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24914 + * GNU General Public License for more details.
24916 + * You should have received a copy of the GNU General Public License
24917 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24921 + * module initialization and module-global
24924 +#ifndef __AUFS_MODULE_H__
24925 +#define __AUFS_MODULE_H__
24929 +#include <linux/slab.h>
24930 +#include "debug.h"
24931 +#include "dentry.h"
24934 +#include "inode.h"
24939 +/* module parameters */
24940 +extern int sysaufs_brs;
24941 +extern bool au_userns;
24943 +/* ---------------------------------------------------------------------- */
24945 +extern int au_dir_roflags;
24947 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24948 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24952 + * Comparing the size of the object with sizeof(struct rcu_head)
24953 + * case 1: object is always larger
24954 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24955 + * case 2: object is always smaller
24956 + * --> au_kfree_small()
24957 + * case 3: object can be any size
24958 + * --> au_kfree_try_rcu()
24961 +static inline void au_kfree_do_rcu(const void *p)
24964 + struct rcu_head rcu;
24965 + } *a = (void *)p;
24967 + kfree_rcu(a, rcu);
24970 +#define au_kfree_rcu(_p) do { \
24971 + typeof(_p) p = (_p); \
24972 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24974 + au_kfree_do_rcu(p); \
24977 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24978 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24980 +static inline void au_kfree_try_rcu(const void *p)
24984 + if (au_kfree_sz_test(p))
24985 + au_kfree_do_rcu(p);
24990 +static inline void au_kfree_small(const void *p)
24994 + AuDebugOn(au_kfree_sz_test(p));
24998 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
25000 +#ifndef CONFIG_SLOB
25001 + return kmalloc_index(sz) - kmalloc_index(new_sz);
25003 + return -1; /* SLOB is untested */
25007 +int au_seq_path(struct seq_file *seq, struct path *path);
25009 +#ifdef CONFIG_PROC_FS
25011 +int __init au_procfs_init(void);
25012 +void au_procfs_fin(void);
25014 +AuStubInt0(au_procfs_init, void);
25015 +AuStubVoid(au_procfs_fin, void);
25018 +/* ---------------------------------------------------------------------- */
25027 + AuCache_HNOTIFY, /* must be last */
25031 +extern struct kmem_cache *au_cache[AuCache_Last];
25033 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
25034 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
25035 +#define AuCacheCtor(type, ctor) \
25036 + kmem_cache_create(#type, sizeof(struct type), \
25037 + __alignof__(struct type), AuCacheFlags, ctor)
25039 +#define AuCacheFuncs(name, index) \
25040 + static inline struct au_##name *au_cache_alloc_##name(void) \
25041 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
25042 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
25043 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
25045 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
25046 + { void *p = rcu; \
25047 + p -= offsetof(struct au_##name, rcu); \
25048 + kmem_cache_free(au_cache[AuCache_##index], p); } \
25049 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
25050 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
25051 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
25053 + static inline void au_cache_free_##name(struct au_##name *p) \
25054 + { /* au_cache_free_##name##_norcu(p); */ \
25055 + au_cache_free_##name##_rcu(p); }
25057 +AuCacheFuncs(dinfo, DINFO);
25058 +AuCacheFuncs(icntnr, ICNTNR);
25059 +AuCacheFuncs(finfo, FINFO);
25060 +AuCacheFuncs(vdir, VDIR);
25061 +AuCacheFuncs(vdir_dehstr, DEHSTR);
25062 +#ifdef CONFIG_AUFS_HNOTIFY
25063 +AuCacheFuncs(hnotify, HNOTIFY);
25066 +#endif /* __KERNEL__ */
25067 +#endif /* __AUFS_MODULE_H__ */
25068 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
25069 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
25070 +++ linux/fs/aufs/mvdown.c 2019-01-28 14:36:12.222418047 +0100
25072 +// SPDX-License-Identifier: GPL-2.0
25074 + * Copyright (C) 2011-2018 Junjiro R. Okajima
25076 + * This program, aufs is free software; you can redistribute it and/or modify
25077 + * it under the terms of the GNU General Public License as published by
25078 + * the Free Software Foundation; either version 2 of the License, or
25079 + * (at your option) any later version.
25081 + * This program is distributed in the hope that it will be useful,
25082 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25083 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25084 + * GNU General Public License for more details.
25086 + * You should have received a copy of the GNU General Public License
25087 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25091 + * move-down, opposite of copy-up
25096 +struct au_mvd_args {
25098 + struct super_block *h_sb;
25099 + struct dentry *h_parent;
25100 + struct au_hinode *hdir;
25101 + struct inode *h_dir, *h_inode;
25102 + struct au_pin pin;
25103 + } info[AUFS_MVDOWN_NARRAY];
25105 + struct aufs_mvdown mvdown;
25106 + struct dentry *dentry, *parent;
25107 + struct inode *inode, *dir;
25108 + struct super_block *sb;
25109 + aufs_bindex_t bopq, bwh, bfound;
25110 + unsigned char rename_lock;
25113 +#define mvd_errno mvdown.au_errno
25114 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25115 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25116 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25117 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25119 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25120 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25121 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25122 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25123 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25124 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25126 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25127 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25128 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25129 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25130 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25131 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25133 +#define AU_MVD_PR(flag, ...) do { \
25135 + pr_err(__VA_ARGS__); \
25138 +static int find_lower_writable(struct au_mvd_args *a)
25140 + struct super_block *sb;
25141 + aufs_bindex_t bindex, bbot;
25142 + struct au_branch *br;
25145 + bindex = a->mvd_bsrc;
25146 + bbot = au_sbbot(sb);
25147 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25148 + for (bindex++; bindex <= bbot; bindex++) {
25149 + br = au_sbr(sb, bindex);
25150 + if (au_br_fhsm(br->br_perm)
25151 + && !sb_rdonly(au_br_sb(br)))
25154 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25155 + for (bindex++; bindex <= bbot; bindex++) {
25156 + br = au_sbr(sb, bindex);
25157 + if (!au_br_rdonly(br))
25161 + for (bindex++; bindex <= bbot; bindex++) {
25162 + br = au_sbr(sb, bindex);
25163 + if (!sb_rdonly(au_br_sb(br))) {
25164 + if (au_br_rdonly(br))
25166 + |= AUFS_MVDOWN_ROLOWER_R;
25174 +/* make the parent dir on bdst */
25175 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25180 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25181 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25182 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25183 + a->mvd_h_dst_parent = NULL;
25184 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25185 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25186 + if (!a->mvd_h_dst_parent) {
25187 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25188 + if (unlikely(err)) {
25189 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25192 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25200 +/* lock them all */
25201 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25204 + struct dentry *h_trap;
25206 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25207 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25208 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25209 + au_opt_udba(a->sb),
25210 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25212 + if (unlikely(err)) {
25213 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25217 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25218 + a->rename_lock = 0;
25219 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25220 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25221 + au_opt_udba(a->sb),
25222 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25223 + err = au_do_pin(&a->mvd_pin_src);
25225 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25226 + if (unlikely(err)) {
25227 + AU_MVD_PR(dmsg, "pin_src failed\n");
25230 + goto out; /* success */
25233 + a->rename_lock = 1;
25234 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25235 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25236 + au_opt_udba(a->sb),
25237 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25239 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25240 + if (unlikely(err)) {
25241 + AU_MVD_PR(dmsg, "pin_src failed\n");
25242 + au_pin_hdir_lock(&a->mvd_pin_dst);
25245 + au_pin_hdir_unlock(&a->mvd_pin_src);
25246 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25247 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25249 + err = (h_trap != a->mvd_h_src_parent);
25251 + err = (h_trap != a->mvd_h_dst_parent);
25253 + BUG_ON(err); /* it should never happen */
25254 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25257 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25258 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25259 + au_pin_hdir_lock(&a->mvd_pin_src);
25260 + au_unpin(&a->mvd_pin_src);
25261 + au_pin_hdir_lock(&a->mvd_pin_dst);
25264 + goto out; /* success */
25267 + au_unpin(&a->mvd_pin_dst);
25273 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25275 + if (!a->rename_lock)
25276 + au_unpin(&a->mvd_pin_src);
25278 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25279 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25280 + au_pin_hdir_lock(&a->mvd_pin_src);
25281 + au_unpin(&a->mvd_pin_src);
25282 + au_pin_hdir_lock(&a->mvd_pin_dst);
25284 + au_unpin(&a->mvd_pin_dst);
25287 +/* copy-down the file */
25288 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25291 + struct au_cp_generic cpg = {
25292 + .dentry = a->dentry,
25293 + .bdst = a->mvd_bdst,
25294 + .bsrc = a->mvd_bsrc,
25296 + .pin = &a->mvd_pin_dst,
25297 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25300 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25301 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25302 + au_fset_cpup(cpg.flags, OVERWRITE);
25303 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25304 + au_fset_cpup(cpg.flags, RWDST);
25305 + err = au_sio_cpdown_simple(&cpg);
25306 + if (unlikely(err))
25307 + AU_MVD_PR(dmsg, "cpdown failed\n");
25314 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25317 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25320 + struct path h_path;
25321 + struct au_branch *br;
25322 + struct inode *delegated;
25324 + br = au_sbr(a->sb, a->mvd_bdst);
25325 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25326 + err = PTR_ERR(h_path.dentry);
25327 + if (IS_ERR(h_path.dentry)) {
25328 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25333 + if (d_is_positive(h_path.dentry)) {
25334 + h_path.mnt = au_br_mnt(br);
25335 + delegated = NULL;
25336 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25337 + &delegated, /*force*/0);
25338 + if (unlikely(err == -EWOULDBLOCK)) {
25339 + pr_warn("cannot retry for NFSv4 delegation"
25340 + " for an internal unlink\n");
25343 + if (unlikely(err))
25344 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25346 + dput(h_path.dentry);
25354 + * unlink the topmost h_dentry
25356 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25359 + struct path h_path;
25360 + struct inode *delegated;
25362 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25363 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25364 + delegated = NULL;
25365 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25366 + if (unlikely(err == -EWOULDBLOCK)) {
25367 + pr_warn("cannot retry for NFSv4 delegation"
25368 + " for an internal unlink\n");
25371 + if (unlikely(err))
25372 + AU_MVD_PR(dmsg, "unlink failed\n");
25378 +/* Since mvdown succeeded, we ignore an error of this function */
25379 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25382 + struct au_branch *br;
25384 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25385 + br = au_sbr(a->sb, a->mvd_bsrc);
25386 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25388 + br = au_sbr(a->sb, a->mvd_bdst);
25389 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25390 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25393 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25395 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25399 + * copy-down the file and unlink the bsrc file.
25400 + * - unlink the bdst whout if exist
25401 + * - copy-down the file (with whtmp name and rename)
25402 + * - unlink the bsrc file
25404 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25408 + err = au_do_mkdir(dmsg, a);
25410 + err = au_do_lock(dmsg, a);
25411 + if (unlikely(err))
25415 + * do not revert the activities we made on bdst since they should be
25416 + * harmless in aufs.
25419 + err = au_do_cpdown(dmsg, a);
25421 + err = au_do_unlink_wh(dmsg, a);
25422 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25423 + err = au_do_unlink(dmsg, a);
25424 + if (unlikely(err))
25427 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25428 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25429 + if (find_lower_writable(a) < 0)
25430 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25432 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25433 + au_do_stfs(dmsg, a);
25435 + /* maintain internal array */
25436 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25437 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25438 + au_set_dbtop(a->dentry, a->mvd_bdst);
25439 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25440 + au_set_ibtop(a->inode, a->mvd_bdst);
25442 + /* hide the lower */
25443 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25444 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25445 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25446 + au_set_ibbot(a->inode, a->mvd_bsrc);
25448 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25449 + au_set_dbbot(a->dentry, a->mvd_bdst);
25450 + if (au_ibbot(a->inode) < a->mvd_bdst)
25451 + au_set_ibbot(a->inode, a->mvd_bdst);
25454 + au_do_unlock(dmsg, a);
25460 +/* ---------------------------------------------------------------------- */
25462 +/* make sure the file is idle */
25463 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25465 + int err, plinked;
25468 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25469 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25470 + && au_dcount(a->dentry) == 1
25471 + && atomic_read(&a->inode->i_count) == 1
25472 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25473 + && (!plinked || !au_plink_test(a->inode))
25474 + && a->inode->i_nlink == 1)
25479 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25480 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25481 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25482 + a->mvd_h_src_inode->i_nlink,
25483 + plinked, plinked ? au_plink_test(a->inode) : 0);
25490 +/* make sure the parent dir is fine */
25491 +static int au_mvd_args_parent(const unsigned char dmsg,
25492 + struct au_mvd_args *a)
25495 + aufs_bindex_t bindex;
25498 + if (unlikely(au_alive_dir(a->parent))) {
25500 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25504 + a->bopq = au_dbdiropq(a->parent);
25505 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25506 + AuDbg("b%d\n", bindex);
25507 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25508 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25510 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25511 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25512 + a->bopq, a->mvd_bdst);
25520 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25521 + struct au_mvd_args *a)
25524 + struct au_dinfo *dinfo, *tmp;
25526 + /* lookup the next lower positive entry */
25528 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25529 + if (unlikely(!tmp))
25534 + dinfo = au_di(a->dentry);
25535 + au_di_cp(tmp, dinfo);
25536 + au_di_swap(tmp, dinfo);
25538 + /* returns the number of positive dentries */
25539 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25540 + /* AuLkup_IGNORE_PERM */ 0);
25542 + a->bwh = au_dbwh(a->dentry);
25543 + else if (err > 0)
25544 + a->bfound = au_dbtop(a->dentry);
25546 + au_di_swap(tmp, dinfo);
25547 + au_rw_write_unlock(&tmp->di_rwsem);
25549 + if (unlikely(err < 0))
25550 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25553 + * here, we have these cases.
25555 + * no positive dentry under bsrc. there are more sub-cases.
25557 + * there no whiteout, we can safely move-down.
25560 + * bsrc < bwh && bwh < bdst
25561 + * there is a whiteout on RO branch. cannot proceed.
25563 + * there is a whiteout on the RW target branch. it should
25566 + * there is a whiteout somewhere unrelated branch.
25567 + * -1 < bfound && bfound <= bsrc
25570 + * found, but it is on RO branch between bsrc and bdst. cannot
25573 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25576 + * found, after we create the file on bdst, it will be hidden.
25579 + AuDebugOn(a->bfound == -1
25581 + && a->bwh <= a->mvd_bsrc);
25582 + AuDebugOn(-1 < a->bfound
25583 + && a->bfound <= a->mvd_bsrc);
25586 + if (a->bfound == -1
25587 + && a->mvd_bsrc < a->bwh
25589 + && a->bwh < a->mvd_bdst) {
25590 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25591 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25592 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25594 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25595 + a->mvd_errno = EAU_MVDOWN_UPPER;
25596 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25597 + a->mvd_bdst, a->bfound);
25601 + err = 0; /* success */
25608 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25613 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25614 + && a->bfound == a->mvd_bdst)
25620 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25623 + struct au_branch *br;
25626 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25630 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25631 + a->mvd_bsrc = au_ibtop(a->inode);
25633 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25634 + if (unlikely(a->mvd_bsrc < 0
25635 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25636 + || au_dbbot(a->dentry) < a->mvd_bsrc
25637 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25638 + || (a->mvd_bsrc < au_ibtop(a->inode)
25639 + || au_ibbot(a->inode) < a->mvd_bsrc
25640 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25641 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25642 + AU_MVD_PR(dmsg, "no upper\n");
25646 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25647 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25648 + AU_MVD_PR(dmsg, "on the bottom\n");
25651 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25652 + br = au_sbr(a->sb, a->mvd_bsrc);
25653 + err = au_br_rdonly(br);
25654 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25655 + if (unlikely(err))
25657 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25658 + || IS_APPEND(a->mvd_h_src_inode))) {
25660 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25666 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25667 + a->mvd_bdst = find_lower_writable(a);
25668 + if (unlikely(a->mvd_bdst < 0)) {
25669 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25670 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25674 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25675 + if (unlikely(a->mvd_bdst < 0
25676 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25677 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25678 + AU_MVD_PR(dmsg, "no lower brid\n");
25683 + err = au_mvd_args_busy(dmsg, a);
25685 + err = au_mvd_args_parent(dmsg, a);
25687 + err = au_mvd_args_intermediate(dmsg, a);
25689 + err = au_mvd_args_exist(dmsg, a);
25691 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25698 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25701 + unsigned char dmsg;
25702 + struct au_mvd_args *args;
25703 + struct inode *inode;
25705 + inode = d_inode(dentry);
25707 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25711 + args = kmalloc(sizeof(*args), GFP_NOFS);
25712 + if (unlikely(!args))
25715 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25717 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25718 + if (unlikely(err)) {
25723 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25724 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25725 + args->mvdown.au_errno = 0;
25726 + args->dentry = dentry;
25727 + args->inode = inode;
25728 + args->sb = dentry->d_sb;
25731 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25732 + args->parent = dget_parent(dentry);
25733 + args->dir = d_inode(args->parent);
25734 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25735 + dput(args->parent);
25736 + if (unlikely(args->parent != dentry->d_parent)) {
25737 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25741 + inode_lock_nested(inode, I_MUTEX_CHILD);
25742 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25743 + if (unlikely(err))
25746 + di_write_lock_parent(args->parent);
25747 + err = au_mvd_args(dmsg, args);
25748 + if (unlikely(err))
25751 + err = au_do_mvdown(dmsg, args);
25752 + if (unlikely(err))
25755 + au_cpup_attr_timesizes(args->dir);
25756 + au_cpup_attr_timesizes(inode);
25757 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25758 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25759 + /* au_digen_dec(dentry); */
25762 + di_write_unlock(args->parent);
25763 + aufs_read_unlock(dentry, AuLock_DW);
25765 + inode_unlock(inode);
25767 + inode_unlock(args->dir);
25769 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25772 + au_kfree_rcu(args);
25777 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25778 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25779 +++ linux/fs/aufs/opts.c 2019-01-28 14:36:12.222418047 +0100
25781 +// SPDX-License-Identifier: GPL-2.0
25783 + * Copyright (C) 2005-2018 Junjiro R. Okajima
25785 + * This program, aufs is free software; you can redistribute it and/or modify
25786 + * it under the terms of the GNU General Public License as published by
25787 + * the Free Software Foundation; either version 2 of the License, or
25788 + * (at your option) any later version.
25790 + * This program is distributed in the hope that it will be useful,
25791 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25792 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25793 + * GNU General Public License for more details.
25795 + * You should have received a copy of the GNU General Public License
25796 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25800 + * mount options/flags
25803 +#include <linux/namei.h>
25804 +#include <linux/types.h> /* a distribution requires */
25805 +#include <linux/parser.h>
25808 +/* ---------------------------------------------------------------------- */
25812 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25813 + Opt_idel, Opt_imod,
25814 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25815 + Opt_rdblk_def, Opt_rdhash_def,
25816 + Opt_xino, Opt_noxino,
25817 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25818 + Opt_trunc_xino_path, Opt_itrunc_xino,
25819 + Opt_trunc_xib, Opt_notrunc_xib,
25820 + Opt_shwh, Opt_noshwh,
25821 + Opt_plink, Opt_noplink, Opt_list_plink,
25823 + Opt_dio, Opt_nodio,
25824 + Opt_diropq_a, Opt_diropq_w,
25825 + Opt_warn_perm, Opt_nowarn_perm,
25826 + Opt_wbr_copyup, Opt_wbr_create,
25828 + Opt_verbose, Opt_noverbose,
25829 + Opt_sum, Opt_nosum, Opt_wsum,
25830 + Opt_dirperm1, Opt_nodirperm1,
25831 + Opt_dirren, Opt_nodirren,
25832 + Opt_acl, Opt_noacl,
25833 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25836 +static match_table_t options = {
25837 + {Opt_br, "br=%s"},
25838 + {Opt_br, "br:%s"},
25840 + {Opt_add, "add=%d:%s"},
25841 + {Opt_add, "add:%d:%s"},
25842 + {Opt_add, "ins=%d:%s"},
25843 + {Opt_add, "ins:%d:%s"},
25844 + {Opt_append, "append=%s"},
25845 + {Opt_append, "append:%s"},
25846 + {Opt_prepend, "prepend=%s"},
25847 + {Opt_prepend, "prepend:%s"},
25849 + {Opt_del, "del=%s"},
25850 + {Opt_del, "del:%s"},
25851 + /* {Opt_idel, "idel:%d"}, */
25852 + {Opt_mod, "mod=%s"},
25853 + {Opt_mod, "mod:%s"},
25854 + /* {Opt_imod, "imod:%d:%s"}, */
25856 + {Opt_dirwh, "dirwh=%d"},
25858 + {Opt_xino, "xino=%s"},
25859 + {Opt_noxino, "noxino"},
25860 + {Opt_trunc_xino, "trunc_xino"},
25861 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25862 + {Opt_notrunc_xino, "notrunc_xino"},
25863 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25864 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25865 + /* {Opt_zxino, "zxino=%s"}, */
25866 + {Opt_trunc_xib, "trunc_xib"},
25867 + {Opt_notrunc_xib, "notrunc_xib"},
25869 +#ifdef CONFIG_PROC_FS
25870 + {Opt_plink, "plink"},
25872 + {Opt_ignore_silent, "plink"},
25875 + {Opt_noplink, "noplink"},
25877 +#ifdef CONFIG_AUFS_DEBUG
25878 + {Opt_list_plink, "list_plink"},
25881 + {Opt_udba, "udba=%s"},
25883 + {Opt_dio, "dio"},
25884 + {Opt_nodio, "nodio"},
25886 +#ifdef CONFIG_AUFS_DIRREN
25887 + {Opt_dirren, "dirren"},
25888 + {Opt_nodirren, "nodirren"},
25890 + {Opt_ignore, "dirren"},
25891 + {Opt_ignore_silent, "nodirren"},
25894 +#ifdef CONFIG_AUFS_FHSM
25895 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25897 + {Opt_ignore, "fhsm_sec=%d"},
25900 + {Opt_diropq_a, "diropq=always"},
25901 + {Opt_diropq_a, "diropq=a"},
25902 + {Opt_diropq_w, "diropq=whiteouted"},
25903 + {Opt_diropq_w, "diropq=w"},
25905 + {Opt_warn_perm, "warn_perm"},
25906 + {Opt_nowarn_perm, "nowarn_perm"},
25908 + /* keep them temporary */
25909 + {Opt_ignore_silent, "nodlgt"},
25910 + {Opt_ignore, "clean_plink"},
25912 +#ifdef CONFIG_AUFS_SHWH
25913 + {Opt_shwh, "shwh"},
25915 + {Opt_noshwh, "noshwh"},
25917 + {Opt_dirperm1, "dirperm1"},
25918 + {Opt_nodirperm1, "nodirperm1"},
25920 + {Opt_verbose, "verbose"},
25921 + {Opt_verbose, "v"},
25922 + {Opt_noverbose, "noverbose"},
25923 + {Opt_noverbose, "quiet"},
25924 + {Opt_noverbose, "q"},
25925 + {Opt_noverbose, "silent"},
25927 + {Opt_sum, "sum"},
25928 + {Opt_nosum, "nosum"},
25929 + {Opt_wsum, "wsum"},
25931 + {Opt_rdcache, "rdcache=%d"},
25932 + {Opt_rdblk, "rdblk=%d"},
25933 + {Opt_rdblk_def, "rdblk=def"},
25934 + {Opt_rdhash, "rdhash=%d"},
25935 + {Opt_rdhash_def, "rdhash=def"},
25937 + {Opt_wbr_create, "create=%s"},
25938 + {Opt_wbr_create, "create_policy=%s"},
25939 + {Opt_wbr_copyup, "cpup=%s"},
25940 + {Opt_wbr_copyup, "copyup=%s"},
25941 + {Opt_wbr_copyup, "copyup_policy=%s"},
25943 + /* generic VFS flag */
25944 +#ifdef CONFIG_FS_POSIX_ACL
25945 + {Opt_acl, "acl"},
25946 + {Opt_noacl, "noacl"},
25948 + {Opt_ignore, "acl"},
25949 + {Opt_ignore_silent, "noacl"},
25952 + /* internal use for the scripts */
25953 + {Opt_ignore_silent, "si=%s"},
25955 + {Opt_br, "dirs=%s"},
25956 + {Opt_ignore, "debug=%d"},
25957 + {Opt_ignore, "delete=whiteout"},
25958 + {Opt_ignore, "delete=all"},
25959 + {Opt_ignore, "imap=%s"},
25961 + /* temporary workaround, due to old mount(8)? */
25962 + {Opt_ignore_silent, "relatime"},
25967 +/* ---------------------------------------------------------------------- */
25969 +static const char *au_parser_pattern(int val, match_table_t tbl)
25971 + struct match_token *p;
25974 + while (p->pattern) {
25975 + if (p->token == val)
25976 + return p->pattern;
25983 +static const char *au_optstr(int *val, match_table_t tbl)
25985 + struct match_token *p;
25992 + while (p->pattern) {
25994 + && (v & p->token) == p->token) {
25995 + *val &= ~p->token;
25996 + return p->pattern;
26005 +/* ---------------------------------------------------------------------- */
26007 +static match_table_t brperm = {
26008 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26009 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26010 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26014 +static match_table_t brattr = {
26016 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26017 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26018 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26019 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26020 +#ifdef CONFIG_AUFS_FHSM
26021 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26023 +#ifdef CONFIG_AUFS_XATTR
26024 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26025 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26026 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26027 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26028 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26029 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26032 + /* ro/rr branch */
26033 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26036 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26037 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26042 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26049 + p = strchr(str, '+');
26052 + v = match_token(str, table, args);
26054 + if (v & AuBrAttr_CMOO_Mask)
26055 + attr &= ~AuBrAttr_CMOO_Mask;
26060 + pr_warn("ignored branch attribute %s\n", str);
26070 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26078 + p = au_optstr(&perm, brattr);
26081 + memcpy(q, p, sz + 1);
26087 + p = au_optstr(&perm, brattr);
26091 + memcpy(q, p, sz + 1);
26097 + return q - str->a;
26100 +static int noinline_for_stack br_perm_val(char *perm)
26102 + int val, bad, sz;
26104 + substring_t args[MAX_OPT_ARGS];
26105 + au_br_perm_str_t attr;
26107 + p = strchr(perm, '+');
26110 + val = match_token(perm, brperm, args);
26114 + pr_warn("ignored branch permission %s\n", perm);
26115 + val = AuBrPerm_RO;
26121 + val |= br_attr_val(p + 1, brattr, args);
26124 + switch (val & AuBrPerm_Mask) {
26125 + case AuBrPerm_RO:
26126 + case AuBrPerm_RR:
26127 + bad = val & AuBrWAttr_Mask;
26128 + val &= ~AuBrWAttr_Mask;
26130 + case AuBrPerm_RW:
26131 + bad = val & AuBrRAttr_Mask;
26132 + val &= ~AuBrRAttr_Mask;
26137 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26138 + * does not treat it as an error, just warning.
26139 + * this is a tiny guard for the user operation.
26141 + if (val & AuBrAttr_UNPIN) {
26142 + bad |= AuBrAttr_UNPIN;
26143 + val &= ~AuBrAttr_UNPIN;
26146 + if (unlikely(bad)) {
26147 + sz = au_do_optstr_br_attr(&attr, bad);
26149 + pr_warn("ignored branch attribute %s\n", attr.a);
26156 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26158 + au_br_perm_str_t attr;
26164 + p = au_optstr(&perm, brperm);
26165 + AuDebugOn(!p || !*p);
26167 + memcpy(q, p, sz + 1);
26170 + sz = au_do_optstr_br_attr(&attr, perm);
26173 + memcpy(q, attr.a, sz + 1);
26176 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26179 +/* ---------------------------------------------------------------------- */
26181 +static match_table_t udbalevel = {
26182 + {AuOpt_UDBA_REVAL, "reval"},
26183 + {AuOpt_UDBA_NONE, "none"},
26184 +#ifdef CONFIG_AUFS_HNOTIFY
26185 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26186 +#ifdef CONFIG_AUFS_HFSNOTIFY
26187 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26193 +static int noinline_for_stack udba_val(char *str)
26195 + substring_t args[MAX_OPT_ARGS];
26197 + return match_token(str, udbalevel, args);
26200 +const char *au_optstr_udba(int udba)
26202 + return au_parser_pattern(udba, udbalevel);
26205 +/* ---------------------------------------------------------------------- */
26207 +static match_table_t au_wbr_create_policy = {
26208 + {AuWbrCreate_TDP, "tdp"},
26209 + {AuWbrCreate_TDP, "top-down-parent"},
26210 + {AuWbrCreate_RR, "rr"},
26211 + {AuWbrCreate_RR, "round-robin"},
26212 + {AuWbrCreate_MFS, "mfs"},
26213 + {AuWbrCreate_MFS, "most-free-space"},
26214 + {AuWbrCreate_MFSV, "mfs:%d"},
26215 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26217 + /* top-down regardless the parent, and then mfs */
26218 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26219 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26221 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26222 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26223 + {AuWbrCreate_PMFS, "pmfs"},
26224 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26225 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26226 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26231 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26232 + struct au_opt_wbr_create *create)
26235 + unsigned long long ull;
26238 + if (!match_u64(arg, &ull))
26239 + create->mfsrr_watermark = ull;
26241 + pr_err("bad integer in %s\n", str);
26248 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26249 + struct au_opt_wbr_create *create)
26254 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26255 + create->mfs_second = n;
26257 + pr_err("bad integer in %s\n", str);
26264 +static int noinline_for_stack
26265 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26268 + substring_t args[MAX_OPT_ARGS];
26270 + err = match_token(str, au_wbr_create_policy, args);
26271 + create->wbr_create = err;
26273 + case AuWbrCreate_MFSRRV:
26274 + case AuWbrCreate_TDMFSV:
26275 + case AuWbrCreate_PMFSRRV:
26276 + e = au_wbr_mfs_wmark(&args[0], str, create);
26278 + e = au_wbr_mfs_sec(&args[1], str, create);
26282 + case AuWbrCreate_MFSRR:
26283 + case AuWbrCreate_TDMFS:
26284 + case AuWbrCreate_PMFSRR:
26285 + e = au_wbr_mfs_wmark(&args[0], str, create);
26286 + if (unlikely(e)) {
26291 + case AuWbrCreate_MFS:
26292 + case AuWbrCreate_PMFS:
26293 + create->mfs_second = AUFS_MFS_DEF_SEC;
26295 + case AuWbrCreate_MFSV:
26296 + case AuWbrCreate_PMFSV:
26297 + e = au_wbr_mfs_sec(&args[0], str, create);
26306 +const char *au_optstr_wbr_create(int wbr_create)
26308 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26311 +static match_table_t au_wbr_copyup_policy = {
26312 + {AuWbrCopyup_TDP, "tdp"},
26313 + {AuWbrCopyup_TDP, "top-down-parent"},
26314 + {AuWbrCopyup_BUP, "bup"},
26315 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26316 + {AuWbrCopyup_BU, "bu"},
26317 + {AuWbrCopyup_BU, "bottom-up"},
26321 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26323 + substring_t args[MAX_OPT_ARGS];
26325 + return match_token(str, au_wbr_copyup_policy, args);
26328 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26330 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26333 +/* ---------------------------------------------------------------------- */
26335 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26337 +static void dump_opts(struct au_opts *opts)
26339 +#ifdef CONFIG_AUFS_DEBUG
26340 + /* reduce stack space */
26342 + struct au_opt_add *add;
26343 + struct au_opt_del *del;
26344 + struct au_opt_mod *mod;
26345 + struct au_opt_xino *xino;
26346 + struct au_opt_xino_itrunc *xino_itrunc;
26347 + struct au_opt_wbr_create *create;
26349 + struct au_opt *opt;
26352 + while (opt->type != Opt_tail) {
26353 + switch (opt->type) {
26355 + u.add = &opt->add;
26356 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26357 + u.add->bindex, u.add->pathname, u.add->perm,
26358 + u.add->path.dentry);
26362 + u.del = &opt->del;
26363 + AuDbg("del {%s, %p}\n",
26364 + u.del->pathname, u.del->h_path.dentry);
26368 + u.mod = &opt->mod;
26369 + AuDbg("mod {%s, 0x%x, %p}\n",
26370 + u.mod->path, u.mod->perm, u.mod->h_root);
26373 + u.add = &opt->add;
26374 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26375 + u.add->bindex, u.add->pathname, u.add->perm,
26376 + u.add->path.dentry);
26378 + case Opt_prepend:
26379 + u.add = &opt->add;
26380 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26381 + u.add->bindex, u.add->pathname, u.add->perm,
26382 + u.add->path.dentry);
26385 + AuDbg("dirwh %d\n", opt->dirwh);
26387 + case Opt_rdcache:
26388 + AuDbg("rdcache %d\n", opt->rdcache);
26391 + AuDbg("rdblk %u\n", opt->rdblk);
26393 + case Opt_rdblk_def:
26394 + AuDbg("rdblk_def\n");
26397 + AuDbg("rdhash %u\n", opt->rdhash);
26399 + case Opt_rdhash_def:
26400 + AuDbg("rdhash_def\n");
26403 + u.xino = &opt->xino;
26404 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26406 + case Opt_trunc_xino:
26407 + AuLabel(trunc_xino);
26409 + case Opt_notrunc_xino:
26410 + AuLabel(notrunc_xino);
26412 + case Opt_trunc_xino_path:
26413 + case Opt_itrunc_xino:
26414 + u.xino_itrunc = &opt->xino_itrunc;
26415 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26420 + case Opt_trunc_xib:
26421 + AuLabel(trunc_xib);
26423 + case Opt_notrunc_xib:
26424 + AuLabel(notrunc_xib);
26432 + case Opt_dirperm1:
26433 + AuLabel(dirperm1);
26435 + case Opt_nodirperm1:
26436 + AuLabel(nodirperm1);
26441 + case Opt_noplink:
26442 + AuLabel(noplink);
26444 + case Opt_list_plink:
26445 + AuLabel(list_plink);
26448 + AuDbg("udba %d, %s\n",
26449 + opt->udba, au_optstr_udba(opt->udba));
26457 + case Opt_diropq_a:
26458 + AuLabel(diropq_a);
26460 + case Opt_diropq_w:
26461 + AuLabel(diropq_w);
26463 + case Opt_warn_perm:
26464 + AuLabel(warn_perm);
26466 + case Opt_nowarn_perm:
26467 + AuLabel(nowarn_perm);
26469 + case Opt_verbose:
26470 + AuLabel(verbose);
26472 + case Opt_noverbose:
26473 + AuLabel(noverbose);
26484 + case Opt_wbr_create:
26485 + u.create = &opt->wbr_create;
26486 + AuDbg("create %d, %s\n", u.create->wbr_create,
26487 + au_optstr_wbr_create(u.create->wbr_create));
26488 + switch (u.create->wbr_create) {
26489 + case AuWbrCreate_MFSV:
26490 + case AuWbrCreate_PMFSV:
26491 + AuDbg("%d sec\n", u.create->mfs_second);
26493 + case AuWbrCreate_MFSRR:
26494 + case AuWbrCreate_TDMFS:
26495 + AuDbg("%llu watermark\n",
26496 + u.create->mfsrr_watermark);
26498 + case AuWbrCreate_MFSRRV:
26499 + case AuWbrCreate_TDMFSV:
26500 + case AuWbrCreate_PMFSRRV:
26501 + AuDbg("%llu watermark, %d sec\n",
26502 + u.create->mfsrr_watermark,
26503 + u.create->mfs_second);
26507 + case Opt_wbr_copyup:
26508 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26509 + au_optstr_wbr_copyup(opt->wbr_copyup));
26511 + case Opt_fhsm_sec:
26512 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26517 + case Opt_nodirren:
26518 + AuLabel(nodirren);
26534 +void au_opts_free(struct au_opts *opts)
26536 + struct au_opt *opt;
26539 + while (opt->type != Opt_tail) {
26540 + switch (opt->type) {
26543 + case Opt_prepend:
26544 + path_put(&opt->add.path);
26548 + path_put(&opt->del.h_path);
26552 + dput(opt->mod.h_root);
26555 + fput(opt->xino.file);
26562 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26563 + aufs_bindex_t bindex)
26566 + struct au_opt_add *add = &opt->add;
26569 + add->bindex = bindex;
26570 + add->perm = AuBrPerm_RO;
26571 + add->pathname = opt_str;
26572 + p = strchr(opt_str, '=');
26576 + add->perm = br_perm_val(p);
26579 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26582 + add->perm = AuBrPerm_RO;
26583 + if (au_test_fs_rr(add->path.dentry->d_sb))
26584 + add->perm = AuBrPerm_RR;
26585 + else if (!bindex && !(sb_flags & SB_RDONLY))
26586 + add->perm = AuBrPerm_RW;
26588 + opt->type = Opt_add;
26591 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26598 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26602 + del->pathname = args[0].from;
26603 + AuDbg("del path %s\n", del->pathname);
26605 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26606 + if (unlikely(err))
26607 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26612 +#if 0 /* reserved for future use */
26613 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26614 + struct au_opt_del *del, substring_t args[])
26617 + struct dentry *root;
26620 + root = sb->s_root;
26621 + aufs_read_lock(root, AuLock_FLUSH);
26622 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26623 + pr_err("out of bounds, %d\n", bindex);
26628 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26629 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26632 + aufs_read_unlock(root, !AuLock_IR);
26637 +static int noinline_for_stack
26638 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26641 + struct path path;
26645 + mod->path = args[0].from;
26646 + p = strchr(mod->path, '=');
26647 + if (unlikely(!p)) {
26648 + pr_err("no permission %s\n", args[0].from);
26653 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26654 + if (unlikely(err)) {
26655 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26659 + mod->perm = br_perm_val(p);
26660 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26661 + mod->h_root = dget(path.dentry);
26668 +#if 0 /* reserved for future use */
26669 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26670 + struct au_opt_mod *mod, substring_t args[])
26673 + struct dentry *root;
26676 + root = sb->s_root;
26677 + aufs_read_lock(root, AuLock_FLUSH);
26678 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26679 + pr_err("out of bounds, %d\n", bindex);
26684 + mod->perm = br_perm_val(args[1].from);
26685 + AuDbg("mod path %s, perm 0x%x, %s\n",
26686 + mod->path, mod->perm, args[1].from);
26687 + mod->h_root = dget(au_h_dptr(root, bindex));
26690 + aufs_read_unlock(root, !AuLock_IR);
26695 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26696 + substring_t args[])
26699 + struct file *file;
26701 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26702 + err = PTR_ERR(file);
26703 + if (IS_ERR(file))
26707 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26709 + pr_err("%s must be outside\n", args[0].from);
26714 + xino->file = file;
26715 + xino->path = args[0].from;
26721 +static int noinline_for_stack
26722 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26723 + struct au_opt_xino_itrunc *xino_itrunc,
26724 + substring_t args[])
26727 + aufs_bindex_t bbot, bindex;
26728 + struct path path;
26729 + struct dentry *root;
26731 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26732 + if (unlikely(err)) {
26733 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26737 + xino_itrunc->bindex = -1;
26738 + root = sb->s_root;
26739 + aufs_read_lock(root, AuLock_FLUSH);
26740 + bbot = au_sbbot(sb);
26741 + for (bindex = 0; bindex <= bbot; bindex++) {
26742 + if (au_h_dptr(root, bindex) == path.dentry) {
26743 + xino_itrunc->bindex = bindex;
26747 + aufs_read_unlock(root, !AuLock_IR);
26750 + if (unlikely(xino_itrunc->bindex < 0)) {
26751 + pr_err("no such branch %s\n", args[0].from);
26759 +/* called without aufs lock */
26760 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26762 + int err, n, token;
26763 + aufs_bindex_t bindex;
26764 + unsigned char skipped;
26765 + struct dentry *root;
26766 + struct au_opt *opt, *opt_tail;
26768 + /* reduce the stack space */
26770 + struct au_opt_xino_itrunc *xino_itrunc;
26771 + struct au_opt_wbr_create *create;
26774 + substring_t args[MAX_OPT_ARGS];
26778 + a = kmalloc(sizeof(*a), GFP_NOFS);
26779 + if (unlikely(!a))
26782 + root = sb->s_root;
26786 + opt_tail = opt + opts->max_opt - 1;
26787 + opt->type = Opt_tail;
26788 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26791 + token = match_token(opt_str, options, a->args);
26795 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26797 + err = opt_add(opt, opt_str, opts->sb_flags,
26799 + if (unlikely(!err && ++opt > opt_tail)) {
26803 + opt->type = Opt_tail;
26808 + if (unlikely(match_int(&a->args[0], &n))) {
26809 + pr_err("bad integer in %s\n", opt_str);
26813 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26816 + opt->type = token;
26819 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26820 + /*dummy bindex*/1);
26822 + opt->type = token;
26824 + case Opt_prepend:
26825 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26828 + opt->type = token;
26831 + err = au_opts_parse_del(&opt->del, a->args);
26833 + opt->type = token;
26835 +#if 0 /* reserved for future use */
26837 + del->pathname = "(indexed)";
26838 + if (unlikely(match_int(&args[0], &n))) {
26839 + pr_err("bad integer in %s\n", opt_str);
26842 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26844 + opt->type = token;
26848 + err = au_opts_parse_mod(&opt->mod, a->args);
26850 + opt->type = token;
26852 +#ifdef IMOD /* reserved for future use */
26854 + u.mod->path = "(indexed)";
26855 + if (unlikely(match_int(&a->args[0], &n))) {
26856 + pr_err("bad integer in %s\n", opt_str);
26859 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26861 + opt->type = token;
26865 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26867 + opt->type = token;
26870 + case Opt_trunc_xino_path:
26871 + err = au_opts_parse_xino_itrunc_path
26872 + (sb, &opt->xino_itrunc, a->args);
26874 + opt->type = token;
26877 + case Opt_itrunc_xino:
26878 + u.xino_itrunc = &opt->xino_itrunc;
26879 + if (unlikely(match_int(&a->args[0], &n))) {
26880 + pr_err("bad integer in %s\n", opt_str);
26883 + u.xino_itrunc->bindex = n;
26884 + aufs_read_lock(root, AuLock_FLUSH);
26885 + if (n < 0 || au_sbbot(sb) < n) {
26886 + pr_err("out of bounds, %d\n", n);
26887 + aufs_read_unlock(root, !AuLock_IR);
26890 + aufs_read_unlock(root, !AuLock_IR);
26892 + opt->type = token;
26896 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26899 + opt->type = token;
26902 + case Opt_rdcache:
26903 + if (unlikely(match_int(&a->args[0], &n))) {
26904 + pr_err("bad integer in %s\n", opt_str);
26907 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26908 + pr_err("rdcache must be smaller than %d\n",
26909 + AUFS_RDCACHE_MAX);
26912 + opt->rdcache = n;
26914 + opt->type = token;
26917 + if (unlikely(match_int(&a->args[0], &n)
26919 + || n > KMALLOC_MAX_SIZE)) {
26920 + pr_err("bad integer in %s\n", opt_str);
26923 + if (unlikely(n && n < NAME_MAX)) {
26924 + pr_err("rdblk must be larger than %d\n",
26930 + opt->type = token;
26933 + if (unlikely(match_int(&a->args[0], &n)
26935 + || n * sizeof(struct hlist_head)
26936 + > KMALLOC_MAX_SIZE)) {
26937 + pr_err("bad integer in %s\n", opt_str);
26942 + opt->type = token;
26945 + case Opt_trunc_xino:
26946 + case Opt_notrunc_xino:
26948 + case Opt_trunc_xib:
26949 + case Opt_notrunc_xib:
26952 + case Opt_dirperm1:
26953 + case Opt_nodirperm1:
26955 + case Opt_noplink:
26956 + case Opt_list_plink:
26959 + case Opt_diropq_a:
26960 + case Opt_diropq_w:
26961 + case Opt_warn_perm:
26962 + case Opt_nowarn_perm:
26963 + case Opt_verbose:
26964 + case Opt_noverbose:
26968 + case Opt_rdblk_def:
26969 + case Opt_rdhash_def:
26971 + case Opt_nodirren:
26975 + opt->type = token;
26979 + opt->udba = udba_val(a->args[0].from);
26980 + if (opt->udba >= 0) {
26982 + opt->type = token;
26984 + pr_err("wrong value, %s\n", opt_str);
26987 + case Opt_wbr_create:
26988 + u.create = &opt->wbr_create;
26989 + u.create->wbr_create
26990 + = au_wbr_create_val(a->args[0].from, u.create);
26991 + if (u.create->wbr_create >= 0) {
26993 + opt->type = token;
26995 + pr_err("wrong value, %s\n", opt_str);
26997 + case Opt_wbr_copyup:
26998 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26999 + if (opt->wbr_copyup >= 0) {
27001 + opt->type = token;
27003 + pr_err("wrong value, %s\n", opt_str);
27006 + case Opt_fhsm_sec:
27007 + if (unlikely(match_int(&a->args[0], &n)
27009 + pr_err("bad integer in %s\n", opt_str);
27012 + if (sysaufs_brs) {
27013 + opt->fhsm_second = n;
27014 + opt->type = token;
27016 + pr_warn("ignored %s\n", opt_str);
27021 + pr_warn("ignored %s\n", opt_str);
27023 + case Opt_ignore_silent:
27028 + pr_err("unknown option %s\n", opt_str);
27032 + if (!err && !skipped) {
27033 + if (unlikely(++opt > opt_tail)) {
27036 + opt->type = Opt_tail;
27039 + opt->type = Opt_tail;
27045 + if (unlikely(err))
27046 + au_opts_free(opts);
27052 +static int au_opt_wbr_create(struct super_block *sb,
27053 + struct au_opt_wbr_create *create)
27056 + struct au_sbinfo *sbinfo;
27058 + SiMustWriteLock(sb);
27060 + err = 1; /* handled */
27061 + sbinfo = au_sbi(sb);
27062 + if (sbinfo->si_wbr_create_ops->fin) {
27063 + err = sbinfo->si_wbr_create_ops->fin(sb);
27068 + sbinfo->si_wbr_create = create->wbr_create;
27069 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27070 + switch (create->wbr_create) {
27071 + case AuWbrCreate_MFSRRV:
27072 + case AuWbrCreate_MFSRR:
27073 + case AuWbrCreate_TDMFS:
27074 + case AuWbrCreate_TDMFSV:
27075 + case AuWbrCreate_PMFSRR:
27076 + case AuWbrCreate_PMFSRRV:
27077 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27079 + case AuWbrCreate_MFS:
27080 + case AuWbrCreate_MFSV:
27081 + case AuWbrCreate_PMFS:
27082 + case AuWbrCreate_PMFSV:
27083 + sbinfo->si_wbr_mfs.mfs_expire
27084 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27088 + if (sbinfo->si_wbr_create_ops->init)
27089 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27096 + * plus: processed without an error
27097 + * zero: unprocessed
27099 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27100 + struct au_opts *opts)
27103 + struct au_sbinfo *sbinfo;
27105 + SiMustWriteLock(sb);
27107 + err = 1; /* handled */
27108 + sbinfo = au_sbi(sb);
27109 + switch (opt->type) {
27111 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27112 + sbinfo->si_mntflags |= opt->udba;
27113 + opts->given_udba |= opt->udba;
27117 + au_opt_set(sbinfo->si_mntflags, PLINK);
27119 + case Opt_noplink:
27120 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27121 + au_plink_put(sb, /*verbose*/1);
27122 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27124 + case Opt_list_plink:
27125 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27126 + au_plink_list(sb);
27130 + au_opt_set(sbinfo->si_mntflags, DIO);
27131 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27134 + au_opt_clr(sbinfo->si_mntflags, DIO);
27135 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27138 + case Opt_fhsm_sec:
27139 + au_fhsm_set(sbinfo, opt->fhsm_second);
27142 + case Opt_diropq_a:
27143 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27145 + case Opt_diropq_w:
27146 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27149 + case Opt_warn_perm:
27150 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27152 + case Opt_nowarn_perm:
27153 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27156 + case Opt_verbose:
27157 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27159 + case Opt_noverbose:
27160 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27164 + au_opt_set(sbinfo->si_mntflags, SUM);
27167 + au_opt_clr(sbinfo->si_mntflags, SUM);
27168 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27170 + au_opt_clr(sbinfo->si_mntflags, SUM);
27171 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27174 + case Opt_wbr_create:
27175 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27177 + case Opt_wbr_copyup:
27178 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27179 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27183 + sbinfo->si_dirwh = opt->dirwh;
27186 + case Opt_rdcache:
27187 + sbinfo->si_rdcache
27188 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27191 + sbinfo->si_rdblk = opt->rdblk;
27193 + case Opt_rdblk_def:
27194 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27197 + sbinfo->si_rdhash = opt->rdhash;
27199 + case Opt_rdhash_def:
27200 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27204 + au_opt_set(sbinfo->si_mntflags, SHWH);
27207 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27210 + case Opt_dirperm1:
27211 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27213 + case Opt_nodirperm1:
27214 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27217 + case Opt_trunc_xino:
27218 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27220 + case Opt_notrunc_xino:
27221 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27224 + case Opt_trunc_xino_path:
27225 + case Opt_itrunc_xino:
27226 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27232 + case Opt_trunc_xib:
27233 + au_fset_opts(opts->flags, TRUNC_XIB);
27235 + case Opt_notrunc_xib:
27236 + au_fclr_opts(opts->flags, TRUNC_XIB);
27241 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27242 + err = au_dr_opt_set(sb);
27247 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27249 + case Opt_nodirren:
27251 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27252 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27258 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27262 + sb->s_flags |= SB_POSIXACL;
27265 + sb->s_flags &= ~SB_POSIXACL;
27277 + * returns tri-state.
27278 + * plus: processed without an error
27279 + * zero: unprocessed
27282 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27283 + struct au_opts *opts)
27285 + int err, do_refresh;
27288 + switch (opt->type) {
27290 + opt->add.bindex = au_sbbot(sb) + 1;
27291 + if (opt->add.bindex < 0)
27292 + opt->add.bindex = 0;
27294 + case Opt_prepend:
27295 + opt->add.bindex = 0;
27296 + add: /* indented label */
27298 + err = au_br_add(sb, &opt->add,
27299 + au_ftest_opts(opts->flags, REMOUNT));
27302 + au_fset_opts(opts->flags, REFRESH);
27308 + err = au_br_del(sb, &opt->del,
27309 + au_ftest_opts(opts->flags, REMOUNT));
27312 + au_fset_opts(opts->flags, TRUNC_XIB);
27313 + au_fset_opts(opts->flags, REFRESH);
27319 + err = au_br_mod(sb, &opt->mod,
27320 + au_ftest_opts(opts->flags, REMOUNT),
27325 + au_fset_opts(opts->flags, REFRESH);
27332 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27333 + struct au_opt_xino **opt_xino,
27334 + struct au_opts *opts)
27339 + switch (opt->type) {
27341 + err = au_xino_set(sb, &opt->xino,
27342 + !!au_ftest_opts(opts->flags, REMOUNT));
27343 + if (unlikely(err))
27346 + *opt_xino = &opt->xino;
27351 + *opt_xino = (void *)-1;
27358 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27359 + unsigned int pending)
27362 + aufs_bindex_t bindex, bbot;
27363 + unsigned char do_plink, skip, do_free, can_no_dreval;
27364 + struct au_branch *br;
27365 + struct au_wbr *wbr;
27366 + struct dentry *root, *dentry;
27367 + struct inode *dir, *h_dir;
27368 + struct au_sbinfo *sbinfo;
27369 + struct au_hinode *hdir;
27371 + SiMustAnyLock(sb);
27373 + sbinfo = au_sbi(sb);
27374 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27376 + if (!(sb_flags & SB_RDONLY)) {
27377 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27378 + pr_warn("first branch should be rw\n");
27379 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27380 + pr_warn_once("shwh should be used with ro\n");
27383 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27384 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27385 + pr_warn_once("udba=*notify requires xino\n");
27387 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27388 + pr_warn_once("dirperm1 breaks the protection"
27389 + " by the permission bits on the lower branch\n");
27393 + root = sb->s_root;
27394 + dir = d_inode(root);
27395 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27396 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27398 + bbot = au_sbbot(sb);
27399 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27401 + h_dir = au_h_iptr(dir, bindex);
27402 + br = au_sbr(sb, bindex);
27404 + if ((br->br_perm & AuBrAttr_ICEX)
27405 + && !h_dir->i_op->listxattr)
27406 + br->br_perm &= ~AuBrAttr_ICEX;
27408 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27409 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27410 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27414 + wbr = br->br_wbr;
27416 + wbr_wh_read_lock(wbr);
27418 + if (!au_br_writable(br->br_perm)) {
27421 + || (!wbr->wbr_whbase
27422 + && !wbr->wbr_plink
27423 + && !wbr->wbr_orph));
27424 + } else if (!au_br_wh_linkable(br->br_perm)) {
27425 + /* skip = (!br->br_whbase && !br->br_orph); */
27426 + skip = (!wbr || !wbr->wbr_whbase);
27427 + if (skip && wbr) {
27429 + skip = !!wbr->wbr_plink;
27431 + skip = !wbr->wbr_plink;
27434 + /* skip = (br->br_whbase && br->br_ohph); */
27435 + skip = (wbr && wbr->wbr_whbase);
27438 + skip = !!wbr->wbr_plink;
27440 + skip = !wbr->wbr_plink;
27444 + wbr_wh_read_unlock(wbr);
27446 + if (can_no_dreval) {
27447 + dentry = br->br_path.dentry;
27448 + spin_lock(&dentry->d_lock);
27449 + if (dentry->d_flags &
27450 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27451 + can_no_dreval = 0;
27452 + spin_unlock(&dentry->d_lock);
27455 + if (au_br_fhsm(br->br_perm)) {
27457 + AuDebugOn(!br->br_fhsm);
27463 + hdir = au_hi(dir, bindex);
27464 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27466 + wbr_wh_write_lock(wbr);
27467 + err = au_wh_init(br, sb);
27469 + wbr_wh_write_unlock(wbr);
27470 + au_hn_inode_unlock(hdir);
27472 + if (!err && do_free) {
27473 + au_kfree_rcu(wbr);
27474 + br->br_wbr = NULL;
27478 + if (can_no_dreval)
27479 + au_fset_si(sbinfo, NO_DREVAL);
27481 + au_fclr_si(sbinfo, NO_DREVAL);
27484 + au_fset_si(sbinfo, FHSM);
27485 + for (bindex = bbot; bindex >= 0; bindex--) {
27486 + br = au_sbr(sb, bindex);
27487 + if (au_br_fhsm(br->br_perm)) {
27488 + au_fhsm_set_bottom(sb, bindex);
27493 + au_fclr_si(sbinfo, FHSM);
27494 + au_fhsm_set_bottom(sb, -1);
27500 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27503 + unsigned int tmp;
27504 + aufs_bindex_t bindex, bbot;
27505 + struct au_opt *opt;
27506 + struct au_opt_xino *opt_xino, xino;
27507 + struct au_sbinfo *sbinfo;
27508 + struct au_branch *br;
27509 + struct inode *dir;
27511 + SiMustWriteLock(sb);
27516 + while (err >= 0 && opt->type != Opt_tail)
27517 + err = au_opt_simple(sb, opt++, opts);
27520 + else if (unlikely(err < 0))
27523 + /* disable xino and udba temporary */
27524 + sbinfo = au_sbi(sb);
27525 + tmp = sbinfo->si_mntflags;
27526 + au_opt_clr(sbinfo->si_mntflags, XINO);
27527 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27530 + while (err >= 0 && opt->type != Opt_tail)
27531 + err = au_opt_br(sb, opt++, opts);
27534 + else if (unlikely(err < 0))
27537 + bbot = au_sbbot(sb);
27538 + if (unlikely(bbot < 0)) {
27540 + pr_err("no branches\n");
27544 + if (au_opt_test(tmp, XINO))
27545 + au_opt_set(sbinfo->si_mntflags, XINO);
27547 + while (!err && opt->type != Opt_tail)
27548 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27549 + if (unlikely(err))
27552 + err = au_opts_verify(sb, sb->s_flags, tmp);
27553 + if (unlikely(err))
27556 + /* restore xino */
27557 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27558 + xino.file = au_xino_def(sb);
27559 + err = PTR_ERR(xino.file);
27560 + if (IS_ERR(xino.file))
27563 + err = au_xino_set(sb, &xino, /*remount*/0);
27565 + if (unlikely(err))
27569 + /* restore udba */
27570 + tmp &= AuOptMask_UDBA;
27571 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27572 + sbinfo->si_mntflags |= tmp;
27573 + bbot = au_sbbot(sb);
27574 + for (bindex = 0; bindex <= bbot; bindex++) {
27575 + br = au_sbr(sb, bindex);
27576 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27577 + if (unlikely(err))
27578 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27580 + /* go on even if err */
27582 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27583 + dir = d_inode(sb->s_root);
27584 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27591 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27594 + unsigned char no_dreval;
27595 + struct inode *dir;
27596 + struct au_opt_xino *opt_xino;
27597 + struct au_opt *opt;
27598 + struct au_sbinfo *sbinfo;
27600 + SiMustWriteLock(sb);
27602 + err = au_dr_opt_flush(sb);
27603 + if (unlikely(err))
27605 + au_fset_opts(opts->flags, DR_FLUSHED);
27607 + dir = d_inode(sb->s_root);
27608 + sbinfo = au_sbi(sb);
27611 + while (err >= 0 && opt->type != Opt_tail) {
27612 + err = au_opt_simple(sb, opt, opts);
27614 + err = au_opt_br(sb, opt, opts);
27616 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27622 + /* go on even err */
27624 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27625 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27626 + if (unlikely(rerr && !err))
27629 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27630 + au_fset_opts(opts->flags, REFRESH_IDOP);
27632 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27633 + rerr = au_xib_trunc(sb);
27634 + if (unlikely(rerr && !err))
27638 + /* will be handled by the caller */
27639 + if (!au_ftest_opts(opts->flags, REFRESH)
27640 + && (opts->given_udba
27641 + || au_opt_test(sbinfo->si_mntflags, XINO)
27642 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27644 + au_fset_opts(opts->flags, REFRESH);
27646 + AuDbg("status 0x%x\n", opts->flags);
27652 +/* ---------------------------------------------------------------------- */
27654 +unsigned int au_opt_udba(struct super_block *sb)
27656 + return au_mntflags(sb) & AuOptMask_UDBA;
27658 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27659 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27660 +++ linux/fs/aufs/opts.h 2019-01-28 14:36:12.222418047 +0100
27662 +/* SPDX-License-Identifier: GPL-2.0 */
27664 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27666 + * This program, aufs is free software; you can redistribute it and/or modify
27667 + * it under the terms of the GNU General Public License as published by
27668 + * the Free Software Foundation; either version 2 of the License, or
27669 + * (at your option) any later version.
27671 + * This program is distributed in the hope that it will be useful,
27672 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27673 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27674 + * GNU General Public License for more details.
27676 + * You should have received a copy of the GNU General Public License
27677 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27681 + * mount options/flags
27684 +#ifndef __AUFS_OPTS_H__
27685 +#define __AUFS_OPTS_H__
27689 +#include <linux/path.h>
27693 +/* ---------------------------------------------------------------------- */
27696 +#define AuOpt_XINO 1 /* external inode number bitmap
27697 + and translation table */
27698 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27699 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27700 +#define AuOpt_UDBA_REVAL (1 << 3)
27701 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27702 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27703 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27704 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27706 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27707 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27708 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27709 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27710 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27711 +#define AuOpt_DIO (1 << 14) /* direct io */
27712 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27714 +#ifndef CONFIG_AUFS_HNOTIFY
27715 +#undef AuOpt_UDBA_HNOTIFY
27716 +#define AuOpt_UDBA_HNOTIFY 0
27718 +#ifndef CONFIG_AUFS_DIRREN
27719 +#undef AuOpt_DIRREN
27720 +#define AuOpt_DIRREN 0
27722 +#ifndef CONFIG_AUFS_SHWH
27724 +#define AuOpt_SHWH 0
27727 +#define AuOpt_Def (AuOpt_XINO \
27728 + | AuOpt_UDBA_REVAL \
27730 + /* | AuOpt_DIRPERM1 */ \
27731 + | AuOpt_WARN_PERM)
27732 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27733 + | AuOpt_UDBA_REVAL \
27734 + | AuOpt_UDBA_HNOTIFY)
27736 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27737 +#define au_opt_set(flags, name) do { \
27738 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27739 + ((flags) |= AuOpt_##name); \
27741 +#define au_opt_set_udba(flags, name) do { \
27742 + (flags) &= ~AuOptMask_UDBA; \
27743 + ((flags) |= AuOpt_##name); \
27745 +#define au_opt_clr(flags, name) do { \
27746 + ((flags) &= ~AuOpt_##name); \
27749 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27751 +#ifdef CONFIG_PROC_FS
27754 + return mntflags & ~AuOpt_PLINK;
27758 +/* ---------------------------------------------------------------------- */
27760 +/* policies to select one among multiple writable branches */
27762 + AuWbrCreate_TDP, /* top down parent */
27763 + AuWbrCreate_RR, /* round robin */
27764 + AuWbrCreate_MFS, /* most free space */
27765 + AuWbrCreate_MFSV, /* mfs with seconds */
27766 + AuWbrCreate_MFSRR, /* mfs then rr */
27767 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27768 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27769 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27770 + AuWbrCreate_PMFS, /* parent and mfs */
27771 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27772 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27773 + AuWbrCreate_PMFSRRV, /* plus seconds */
27775 + AuWbrCreate_Def = AuWbrCreate_TDP
27779 + AuWbrCopyup_TDP, /* top down parent */
27780 + AuWbrCopyup_BUP, /* bottom up parent */
27781 + AuWbrCopyup_BU, /* bottom up */
27783 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27786 +/* ---------------------------------------------------------------------- */
27788 +struct au_opt_add {
27789 + aufs_bindex_t bindex;
27792 + struct path path;
27795 +struct au_opt_del {
27797 + struct path h_path;
27800 +struct au_opt_mod {
27803 + struct dentry *h_root;
27806 +struct au_opt_xino {
27808 + struct file *file;
27811 +struct au_opt_xino_itrunc {
27812 + aufs_bindex_t bindex;
27815 +struct au_opt_wbr_create {
27818 + unsigned long long mfsrr_watermark;
27824 + struct au_opt_xino xino;
27825 + struct au_opt_xino_itrunc xino_itrunc;
27826 + struct au_opt_add add;
27827 + struct au_opt_del del;
27828 + struct au_opt_mod mod;
27831 + unsigned int rdblk;
27832 + unsigned int rdhash;
27834 + struct au_opt_wbr_create wbr_create;
27836 + unsigned int fhsm_second;
27841 +#define AuOpts_REMOUNT 1
27842 +#define AuOpts_REFRESH (1 << 1)
27843 +#define AuOpts_TRUNC_XIB (1 << 2)
27844 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27845 +#define AuOpts_REFRESH_IDOP (1 << 4)
27846 +#define AuOpts_DR_FLUSHED (1 << 5)
27847 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27848 +#define au_fset_opts(flags, name) \
27849 + do { (flags) |= AuOpts_##name; } while (0)
27850 +#define au_fclr_opts(flags, name) \
27851 + do { (flags) &= ~AuOpts_##name; } while (0)
27853 +#ifndef CONFIG_AUFS_DIRREN
27854 +#undef AuOpts_DR_FLUSHED
27855 +#define AuOpts_DR_FLUSHED 0
27859 + struct au_opt *opt;
27862 + unsigned int given_udba;
27863 + unsigned int flags;
27864 + unsigned long sb_flags;
27867 +/* ---------------------------------------------------------------------- */
27870 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27871 +const char *au_optstr_udba(int udba);
27872 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27873 +const char *au_optstr_wbr_create(int wbr_create);
27875 +void au_opts_free(struct au_opts *opts);
27876 +struct super_block;
27877 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27878 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27879 + unsigned int pending);
27880 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27881 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27883 +unsigned int au_opt_udba(struct super_block *sb);
27885 +#endif /* __KERNEL__ */
27886 +#endif /* __AUFS_OPTS_H__ */
27887 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27888 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27889 +++ linux/fs/aufs/plink.c 2019-01-28 14:36:12.222418047 +0100
27891 +// SPDX-License-Identifier: GPL-2.0
27893 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27895 + * This program, aufs is free software; you can redistribute it and/or modify
27896 + * it under the terms of the GNU General Public License as published by
27897 + * the Free Software Foundation; either version 2 of the License, or
27898 + * (at your option) any later version.
27900 + * This program is distributed in the hope that it will be useful,
27901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27903 + * GNU General Public License for more details.
27905 + * You should have received a copy of the GNU General Public License
27906 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27916 + * the pseudo-link maintenance mode.
27917 + * during a user process maintains the pseudo-links,
27918 + * prohibit adding a new plink and branch manipulation.
27922 + * For entry functions which will handle plink, and i_mutex is already held
27924 + * They cannot wait and should return an error at once.
27925 + * Callers has to check the error.
27927 + * For entry functions which will handle plink, but i_mutex is not held
27929 + * They can wait the plink maintenance mode to finish.
27931 + * They behave like F_SETLK and F_SETLKW.
27932 + * If the caller never handle plink, then both flags are unnecessary.
27935 +int au_plink_maint(struct super_block *sb, int flags)
27939 + struct task_struct *parent, *prev;
27940 + struct au_sbinfo *sbi;
27942 + SiMustAnyLock(sb);
27945 + if (!au_opt_test(au_mntflags(sb), PLINK))
27948 + sbi = au_sbi(sb);
27949 + pid = sbi->si_plink_maint_pid;
27950 + if (!pid || pid == current->pid)
27953 + /* todo: it highly depends upon /sbin/mount.aufs */
27955 + parent = current;
27959 + parent = rcu_dereference(parent->real_parent);
27960 + if (parent == prev)
27962 + ppid = task_pid_vnr(parent);
27963 + if (pid == ppid) {
27964 + rcu_read_unlock();
27969 + rcu_read_unlock();
27971 + if (au_ftest_lock(flags, NOPLMW)) {
27972 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27973 + /* AuDebugOn(!lockdep_depth(current)); */
27974 + while (sbi->si_plink_maint_pid) {
27975 + si_read_unlock(sb);
27976 + /* gave up wake_up_bit() */
27977 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27979 + if (au_ftest_lock(flags, FLUSH))
27980 + au_nwt_flush(&sbi->si_nowait);
27981 + si_noflush_read_lock(sb);
27983 + } else if (au_ftest_lock(flags, NOPLM)) {
27984 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27992 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27994 + spin_lock(&sbinfo->si_plink_maint_lock);
27995 + sbinfo->si_plink_maint_pid = 0;
27996 + spin_unlock(&sbinfo->si_plink_maint_lock);
27997 + wake_up_all(&sbinfo->si_plink_wq);
28000 +int au_plink_maint_enter(struct super_block *sb)
28003 + struct au_sbinfo *sbinfo;
28006 + sbinfo = au_sbi(sb);
28007 + /* make sure i am the only one in this fs */
28008 + si_write_lock(sb, AuLock_FLUSH);
28009 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28010 + spin_lock(&sbinfo->si_plink_maint_lock);
28011 + if (!sbinfo->si_plink_maint_pid)
28012 + sbinfo->si_plink_maint_pid = current->pid;
28015 + spin_unlock(&sbinfo->si_plink_maint_lock);
28017 + si_write_unlock(sb);
28022 +/* ---------------------------------------------------------------------- */
28024 +#ifdef CONFIG_AUFS_DEBUG
28025 +void au_plink_list(struct super_block *sb)
28028 + struct au_sbinfo *sbinfo;
28029 + struct hlist_bl_head *hbl;
28030 + struct hlist_bl_node *pos;
28031 + struct au_icntnr *icntnr;
28033 + SiMustAnyLock(sb);
28035 + sbinfo = au_sbi(sb);
28036 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28037 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28039 + for (i = 0; i < AuPlink_NHASH; i++) {
28040 + hbl = sbinfo->si_plink + i;
28041 + hlist_bl_lock(hbl);
28042 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28043 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28044 + hlist_bl_unlock(hbl);
28049 +/* is the inode pseudo-linked? */
28050 +int au_plink_test(struct inode *inode)
28053 + struct au_sbinfo *sbinfo;
28054 + struct hlist_bl_head *hbl;
28055 + struct hlist_bl_node *pos;
28056 + struct au_icntnr *icntnr;
28058 + sbinfo = au_sbi(inode->i_sb);
28059 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28060 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28061 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28064 + i = au_plink_hash(inode->i_ino);
28065 + hbl = sbinfo->si_plink + i;
28066 + hlist_bl_lock(hbl);
28067 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28068 + if (&icntnr->vfs_inode == inode) {
28072 + hlist_bl_unlock(hbl);
28076 +/* ---------------------------------------------------------------------- */
28079 + * generate a name for plink.
28080 + * the file will be stored under AUFS_WH_PLINKDIR.
28082 +/* 20 is max digits length of ulong 64 */
28083 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28085 +static int plink_name(char *name, int len, struct inode *inode,
28086 + aufs_bindex_t bindex)
28089 + struct inode *h_inode;
28091 + h_inode = au_h_iptr(inode, bindex);
28092 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28096 +struct au_do_plink_lkup_args {
28097 + struct dentry **errp;
28098 + struct qstr *tgtname;
28099 + struct dentry *h_parent;
28100 + struct au_branch *br;
28103 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28104 + struct dentry *h_parent,
28105 + struct au_branch *br)
28107 + struct dentry *h_dentry;
28108 + struct inode *h_inode;
28110 + h_inode = d_inode(h_parent);
28111 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28112 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28113 + inode_unlock_shared(h_inode);
28117 +static void au_call_do_plink_lkup(void *args)
28119 + struct au_do_plink_lkup_args *a = args;
28120 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28123 +/* lookup the plink-ed @inode under the branch at @bindex */
28124 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28126 + struct dentry *h_dentry, *h_parent;
28127 + struct au_branch *br;
28129 + char a[PLINK_NAME_LEN];
28130 + struct qstr tgtname = QSTR_INIT(a, 0);
28132 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28134 + br = au_sbr(inode->i_sb, bindex);
28135 + h_parent = br->br_wbr->wbr_plink;
28136 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28138 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28139 + struct au_do_plink_lkup_args args = {
28140 + .errp = &h_dentry,
28141 + .tgtname = &tgtname,
28142 + .h_parent = h_parent,
28146 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28147 + if (unlikely(wkq_err))
28148 + h_dentry = ERR_PTR(wkq_err);
28150 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28155 +/* create a pseudo-link */
28156 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28157 + struct dentry *h_dentry, struct au_branch *br)
28160 + struct path h_path = {
28161 + .mnt = au_br_mnt(br)
28163 + struct inode *h_dir, *delegated;
28165 + h_dir = d_inode(h_parent);
28166 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28168 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28169 + err = PTR_ERR(h_path.dentry);
28170 + if (IS_ERR(h_path.dentry))
28174 + /* wh.plink dir is not monitored */
28175 + /* todo: is it really safe? */
28176 + if (d_is_positive(h_path.dentry)
28177 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28178 + delegated = NULL;
28179 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28180 + if (unlikely(err == -EWOULDBLOCK)) {
28181 + pr_warn("cannot retry for NFSv4 delegation"
28182 + " for an internal unlink\n");
28185 + dput(h_path.dentry);
28186 + h_path.dentry = NULL;
28190 + if (!err && d_is_negative(h_path.dentry)) {
28191 + delegated = NULL;
28192 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28193 + if (unlikely(err == -EWOULDBLOCK)) {
28194 + pr_warn("cannot retry for NFSv4 delegation"
28195 + " for an internal link\n");
28199 + dput(h_path.dentry);
28202 + inode_unlock(h_dir);
28206 +struct do_whplink_args {
28208 + struct qstr *tgt;
28209 + struct dentry *h_parent;
28210 + struct dentry *h_dentry;
28211 + struct au_branch *br;
28214 +static void call_do_whplink(void *args)
28216 + struct do_whplink_args *a = args;
28217 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28220 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28221 + aufs_bindex_t bindex, struct au_branch *br)
28223 + int err, wkq_err;
28224 + struct au_wbr *wbr;
28225 + struct dentry *h_parent;
28226 + char a[PLINK_NAME_LEN];
28227 + struct qstr tgtname = QSTR_INIT(a, 0);
28229 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28230 + h_parent = wbr->wbr_plink;
28231 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28233 + /* always superio. */
28234 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28235 + struct do_whplink_args args = {
28238 + .h_parent = h_parent,
28239 + .h_dentry = h_dentry,
28242 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28243 + if (unlikely(wkq_err))
28246 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28252 + * create a new pseudo-link for @h_dentry on @bindex.
28253 + * the linked inode is held in aufs @inode.
28255 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28256 + struct dentry *h_dentry)
28258 + struct super_block *sb;
28259 + struct au_sbinfo *sbinfo;
28260 + struct hlist_bl_head *hbl;
28261 + struct hlist_bl_node *pos;
28262 + struct au_icntnr *icntnr;
28263 + int found, err, cnt, i;
28265 + sb = inode->i_sb;
28266 + sbinfo = au_sbi(sb);
28267 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28268 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28270 + found = au_plink_test(inode);
28274 + i = au_plink_hash(inode->i_ino);
28275 + hbl = sbinfo->si_plink + i;
28278 + hlist_bl_lock(hbl);
28279 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28280 + if (&icntnr->vfs_inode == inode) {
28286 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28287 + hlist_bl_add_head(&icntnr->plink, hbl);
28289 + hlist_bl_unlock(hbl);
28291 + cnt = au_hbl_count(hbl);
28292 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28293 + if (cnt > AUFS_PLINK_WARN)
28294 + AuWarn1(msg ", %d\n", cnt);
28296 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28297 + if (unlikely(err)) {
28298 + pr_warn("err %d, damaged pseudo link.\n", err);
28299 + au_hbl_del(&icntnr->plink, hbl);
28300 + iput(&icntnr->vfs_inode);
28303 + iput(&icntnr->vfs_inode);
28306 +/* free all plinks */
28307 +void au_plink_put(struct super_block *sb, int verbose)
28310 + struct au_sbinfo *sbinfo;
28311 + struct hlist_bl_head *hbl;
28312 + struct hlist_bl_node *pos, *tmp;
28313 + struct au_icntnr *icntnr;
28315 + SiMustWriteLock(sb);
28317 + sbinfo = au_sbi(sb);
28318 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28319 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28321 + /* no spin_lock since sbinfo is write-locked */
28323 + for (i = 0; i < AuPlink_NHASH; i++) {
28324 + hbl = sbinfo->si_plink + i;
28325 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28326 + pr_warn("pseudo-link is not flushed");
28329 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28330 + iput(&icntnr->vfs_inode);
28331 + INIT_HLIST_BL_HEAD(hbl);
28335 +void au_plink_clean(struct super_block *sb, int verbose)
28337 + struct dentry *root;
28339 + root = sb->s_root;
28340 + aufs_write_lock(root);
28341 + if (au_opt_test(au_mntflags(sb), PLINK))
28342 + au_plink_put(sb, verbose);
28343 + aufs_write_unlock(root);
28346 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28349 + aufs_bindex_t btop, bbot, bindex;
28352 + btop = au_ibtop(inode);
28353 + bbot = au_ibbot(inode);
28355 + for (bindex = btop; bindex <= bbot; bindex++) {
28356 + if (!au_h_iptr(inode, bindex)
28357 + || au_ii_br_id(inode, bindex) != br_id)
28359 + au_set_h_iptr(inode, bindex, NULL, 0);
28364 + for (bindex = btop; bindex <= bbot; bindex++)
28365 + if (au_h_iptr(inode, bindex)) {
28375 +/* free the plinks on a branch specified by @br_id */
28376 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28378 + struct au_sbinfo *sbinfo;
28379 + struct hlist_bl_head *hbl;
28380 + struct hlist_bl_node *pos, *tmp;
28381 + struct au_icntnr *icntnr;
28382 + struct inode *inode;
28385 + SiMustWriteLock(sb);
28387 + sbinfo = au_sbi(sb);
28388 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28389 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28391 + /* no bit_lock since sbinfo is write-locked */
28392 + for (i = 0; i < AuPlink_NHASH; i++) {
28393 + hbl = sbinfo->si_plink + i;
28394 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28395 + inode = au_igrab(&icntnr->vfs_inode);
28396 + ii_write_lock_child(inode);
28397 + do_put = au_plink_do_half_refresh(inode, br_id);
28399 + hlist_bl_del(&icntnr->plink);
28402 + ii_write_unlock(inode);
28407 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28408 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28409 +++ linux/fs/aufs/poll.c 2019-01-28 14:36:12.222418047 +0100
28411 +// SPDX-License-Identifier: GPL-2.0
28413 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28415 + * This program, aufs is free software; you can redistribute it and/or modify
28416 + * it under the terms of the GNU General Public License as published by
28417 + * the Free Software Foundation; either version 2 of the License, or
28418 + * (at your option) any later version.
28420 + * This program is distributed in the hope that it will be useful,
28421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28423 + * GNU General Public License for more details.
28425 + * You should have received a copy of the GNU General Public License
28426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28431 + * There is only one filesystem which implements ->poll operation, currently.
28436 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28439 + struct file *h_file;
28440 + struct super_block *sb;
28442 + /* We should pretend an error happened. */
28443 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28444 + sb = file->f_path.dentry->d_sb;
28445 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28447 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28448 + if (IS_ERR(h_file)) {
28449 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28453 + mask = vfs_poll(h_file, pt);
28454 + fput(h_file); /* instead of au_read_post() */
28457 + si_read_unlock(sb);
28458 + if (mask & EPOLLERR)
28459 + AuDbg("mask 0x%x\n", mask);
28462 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28463 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28464 +++ linux/fs/aufs/posix_acl.c 2019-01-28 14:36:12.222418047 +0100
28466 +// SPDX-License-Identifier: GPL-2.0
28468 + * Copyright (C) 2014-2018 Junjiro R. Okajima
28470 + * This program, aufs is free software; you can redistribute it and/or modify
28471 + * it under the terms of the GNU General Public License as published by
28472 + * the Free Software Foundation; either version 2 of the License, or
28473 + * (at your option) any later version.
28475 + * This program is distributed in the hope that it will be useful,
28476 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28477 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28478 + * GNU General Public License for more details.
28480 + * You should have received a copy of the GNU General Public License
28481 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28485 + * posix acl operations
28488 +#include <linux/fs.h>
28491 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28493 + struct posix_acl *acl;
28495 + aufs_bindex_t bindex;
28496 + struct inode *h_inode;
28497 + struct super_block *sb;
28500 + sb = inode->i_sb;
28501 + si_read_lock(sb, AuLock_FLUSH);
28502 + ii_read_lock_child(inode);
28503 + if (!(sb->s_flags & SB_POSIXACL))
28506 + bindex = au_ibtop(inode);
28507 + h_inode = au_h_iptr(inode, bindex);
28508 + if (unlikely(!h_inode
28509 + || ((h_inode->i_mode & S_IFMT)
28510 + != (inode->i_mode & S_IFMT)))) {
28511 + err = au_busy_or_stale();
28512 + acl = ERR_PTR(err);
28516 + /* always topmost only */
28517 + acl = get_acl(h_inode, type);
28518 + if (!IS_ERR_OR_NULL(acl))
28519 + set_cached_acl(inode, type, acl);
28522 + ii_read_unlock(inode);
28523 + si_read_unlock(sb);
28525 + AuTraceErrPtr(acl);
28529 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28533 + struct dentry *dentry;
28534 + struct au_sxattr arg = {
28535 + .type = AU_ACL_SET,
28542 + IMustLock(inode);
28544 + if (inode->i_ino == AUFS_ROOT_INO)
28545 + dentry = dget(inode->i_sb->s_root);
28547 + dentry = d_find_alias(inode);
28549 + dentry = d_find_any_alias(inode);
28551 + pr_warn("cannot handle this inode, "
28552 + "please report to aufs-users ML\n");
28558 + ssz = au_sxattr(dentry, inode, &arg);
28563 + set_cached_acl(inode, type, acl);
28569 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28570 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28571 +++ linux/fs/aufs/procfs.c 2019-01-28 14:36:12.222418047 +0100
28573 +// SPDX-License-Identifier: GPL-2.0
28575 + * Copyright (C) 2010-2018 Junjiro R. Okajima
28577 + * This program, aufs is free software; you can redistribute it and/or modify
28578 + * it under the terms of the GNU General Public License as published by
28579 + * the Free Software Foundation; either version 2 of the License, or
28580 + * (at your option) any later version.
28582 + * This program is distributed in the hope that it will be useful,
28583 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28584 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28585 + * GNU General Public License for more details.
28587 + * You should have received a copy of the GNU General Public License
28588 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28592 + * procfs interfaces
28595 +#include <linux/proc_fs.h>
28598 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28600 + struct au_sbinfo *sbinfo;
28602 + sbinfo = file->private_data;
28604 + au_plink_maint_leave(sbinfo);
28605 + kobject_put(&sbinfo->si_kobj);
28611 +static void au_procfs_plm_write_clean(struct file *file)
28613 + struct au_sbinfo *sbinfo;
28615 + sbinfo = file->private_data;
28617 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28620 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28623 + struct super_block *sb;
28624 + struct au_sbinfo *sbinfo;
28625 + struct hlist_bl_node *pos;
28628 + if (unlikely(file->private_data))
28632 + /* don't use au_sbilist_lock() here */
28633 + hlist_bl_lock(&au_sbilist);
28634 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28635 + if (id == sysaufs_si_id(sbinfo)) {
28636 + kobject_get(&sbinfo->si_kobj);
28637 + sb = sbinfo->si_sb;
28640 + hlist_bl_unlock(&au_sbilist);
28643 + if (unlikely(!sb))
28646 + err = au_plink_maint_enter(sb);
28648 + /* keep kobject_get() */
28649 + file->private_data = sbinfo;
28651 + kobject_put(&sbinfo->si_kobj);
28657 + * Accept a valid "si=xxxx" only.
28658 + * Once it is accepted successfully, accept "clean" too.
28660 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28661 + size_t count, loff_t *ppos)
28664 + unsigned long id;
28665 + /* last newline is allowed */
28666 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28669 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28673 + if (unlikely(count > sizeof(buf)))
28676 + err = copy_from_user(buf, ubuf, count);
28677 + if (unlikely(err)) {
28684 + if (!strcmp("clean", buf)) {
28685 + au_procfs_plm_write_clean(file);
28686 + goto out_success;
28687 + } else if (unlikely(strncmp("si=", buf, 3)))
28690 + err = kstrtoul(buf + 3, 16, &id);
28691 + if (unlikely(err))
28694 + err = au_procfs_plm_write_si(file, id);
28695 + if (unlikely(err))
28699 + err = count; /* success */
28704 +static const struct file_operations au_procfs_plm_fop = {
28705 + .write = au_procfs_plm_write,
28706 + .release = au_procfs_plm_release,
28707 + .owner = THIS_MODULE
28710 +/* ---------------------------------------------------------------------- */
28712 +static struct proc_dir_entry *au_procfs_dir;
28714 +void au_procfs_fin(void)
28716 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28717 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28720 +int __init au_procfs_init(void)
28723 + struct proc_dir_entry *entry;
28726 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28727 + if (unlikely(!au_procfs_dir))
28730 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28731 + au_procfs_dir, &au_procfs_plm_fop);
28732 + if (unlikely(!entry))
28736 + goto out; /* success */
28740 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28744 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28745 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28746 +++ linux/fs/aufs/rdu.c 2019-01-28 14:36:12.222418047 +0100
28748 +// SPDX-License-Identifier: GPL-2.0
28750 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28752 + * This program, aufs is free software; you can redistribute it and/or modify
28753 + * it under the terms of the GNU General Public License as published by
28754 + * the Free Software Foundation; either version 2 of the License, or
28755 + * (at your option) any later version.
28757 + * This program is distributed in the hope that it will be useful,
28758 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28759 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28760 + * GNU General Public License for more details.
28762 + * You should have received a copy of the GNU General Public License
28763 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28767 + * readdir in userspace.
28770 +#include <linux/compat.h>
28771 +#include <linux/fs_stack.h>
28772 +#include <linux/security.h>
28775 +/* bits for struct aufs_rdu.flags */
28776 +#define AuRdu_CALLED 1
28777 +#define AuRdu_CONT (1 << 1)
28778 +#define AuRdu_FULL (1 << 2)
28779 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28780 +#define au_fset_rdu(flags, name) \
28781 + do { (flags) |= AuRdu_##name; } while (0)
28782 +#define au_fclr_rdu(flags, name) \
28783 + do { (flags) &= ~AuRdu_##name; } while (0)
28785 +struct au_rdu_arg {
28786 + struct dir_context ctx;
28787 + struct aufs_rdu *rdu;
28788 + union au_rdu_ent_ul ent;
28789 + unsigned long end;
28791 + struct super_block *sb;
28795 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28796 + loff_t offset, u64 h_ino, unsigned int d_type)
28799 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28800 + struct aufs_rdu *rdu = arg->rdu;
28801 + struct au_rdu_ent ent;
28805 + au_fset_rdu(rdu->cookie.flags, CALLED);
28806 + len = au_rdu_len(nlen);
28807 + if (arg->ent.ul + len < arg->end) {
28809 + ent.bindex = rdu->cookie.bindex;
28810 + ent.type = d_type;
28812 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28813 + ent.type = DT_UNKNOWN;
28815 + /* unnecessary to support mmap_sem since this is a dir */
28817 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28819 + if (copy_to_user(arg->ent.e->name, name, nlen))
28821 + /* the terminating NULL */
28822 + if (__put_user(0, arg->ent.e->name + nlen))
28825 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28826 + arg->ent.ul += len;
28830 + au_fset_rdu(rdu->cookie.flags, FULL);
28832 + rdu->tail = arg->ent;
28836 + /* AuTraceErr(err); */
28840 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28844 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28846 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28847 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28849 + if (unlikely(offset != cookie->h_pos))
28855 + au_fclr_rdu(cookie->flags, CALLED);
28857 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28861 + && au_ftest_rdu(cookie->flags, CALLED)
28862 + && !au_ftest_rdu(cookie->flags, FULL));
28863 + cookie->h_pos = h_file->f_pos;
28870 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28873 + aufs_bindex_t bbot;
28874 + struct au_rdu_arg arg = {
28876 + .actor = au_rdu_fill
28879 + struct dentry *dentry;
28880 + struct inode *inode;
28881 + struct file *h_file;
28882 + struct au_rdu_cookie *cookie = &rdu->cookie;
28884 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28885 + if (unlikely(err)) {
28891 + rdu->tail = rdu->ent;
28894 + arg.ent = rdu->ent;
28895 + arg.end = arg.ent.ul;
28896 + arg.end += rdu->sz;
28899 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28902 + err = security_file_permission(file, MAY_READ);
28904 + if (unlikely(err))
28907 + dentry = file->f_path.dentry;
28908 + inode = d_inode(dentry);
28909 + inode_lock_shared(inode);
28911 + arg.sb = inode->i_sb;
28912 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28913 + if (unlikely(err))
28915 + err = au_alive_dir(dentry);
28916 + if (unlikely(err))
28918 + /* todo: reval? */
28919 + fi_read_lock(file);
28922 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28923 + && cookie->generation != au_figen(file)))
28928 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28930 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28932 + bbot = au_fbtop(file);
28933 + if (cookie->bindex < bbot)
28934 + cookie->bindex = bbot;
28935 + bbot = au_fbbot_dir(file);
28936 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28937 + for (; !err && cookie->bindex <= bbot;
28938 + cookie->bindex++, cookie->h_pos = 0) {
28939 + h_file = au_hf_dir(file, cookie->bindex);
28943 + au_fclr_rdu(cookie->flags, FULL);
28944 + err = au_rdu_do(h_file, &arg);
28946 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28949 + AuDbg("rent %llu\n", rdu->rent);
28951 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28952 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28953 + au_fset_rdu(cookie->flags, CONT);
28954 + cookie->generation = au_figen(file);
28957 + ii_read_lock_child(inode);
28958 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28959 + ii_read_unlock(inode);
28962 + fi_read_unlock(file);
28964 + si_read_unlock(arg.sb);
28966 + inode_unlock_shared(inode);
28972 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28976 + unsigned long long nent;
28977 + union au_rdu_ent_ul *u;
28978 + struct au_rdu_ent ent;
28979 + struct super_block *sb;
28982 + nent = rdu->nent;
28984 + sb = file->f_path.dentry->d_sb;
28985 + si_read_lock(sb, AuLock_FLUSH);
28986 + while (nent-- > 0) {
28987 + /* unnecessary to support mmap_sem since this is a dir */
28988 + err = copy_from_user(&ent, u->e, sizeof(ent));
28990 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28991 + if (unlikely(err)) {
28997 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28999 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29001 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29003 + if (unlikely(err)) {
29008 + err = __put_user(ino, &u->e->ino);
29009 + if (unlikely(err)) {
29014 + u->ul += au_rdu_len(ent.nlen);
29016 + si_read_unlock(sb);
29021 +/* ---------------------------------------------------------------------- */
29023 +static int au_rdu_verify(struct aufs_rdu *rdu)
29025 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29026 + "%llu, b%d, 0x%x, g%u}\n",
29027 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29029 + rdu->rent, rdu->shwh, rdu->full,
29030 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29031 + rdu->cookie.generation);
29033 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29037 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29041 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29044 + struct aufs_rdu rdu;
29045 + void __user *p = (void __user *)arg;
29047 + err = copy_from_user(&rdu, p, sizeof(rdu));
29048 + if (unlikely(err)) {
29053 + err = au_rdu_verify(&rdu);
29054 + if (unlikely(err))
29058 + case AUFS_CTL_RDU:
29059 + err = au_rdu(file, &rdu);
29060 + if (unlikely(err))
29063 + e = copy_to_user(p, &rdu, sizeof(rdu));
29064 + if (unlikely(e)) {
29069 + case AUFS_CTL_RDU_INO:
29070 + err = au_rdu_ino(file, &rdu);
29074 + /* err = -ENOTTY; */
29083 +#ifdef CONFIG_COMPAT
29084 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29087 + struct aufs_rdu rdu;
29088 + void __user *p = compat_ptr(arg);
29090 + /* todo: get_user()? */
29091 + err = copy_from_user(&rdu, p, sizeof(rdu));
29092 + if (unlikely(err)) {
29097 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29098 + err = au_rdu_verify(&rdu);
29099 + if (unlikely(err))
29103 + case AUFS_CTL_RDU:
29104 + err = au_rdu(file, &rdu);
29105 + if (unlikely(err))
29108 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29109 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29110 + e = copy_to_user(p, &rdu, sizeof(rdu));
29111 + if (unlikely(e)) {
29116 + case AUFS_CTL_RDU_INO:
29117 + err = au_rdu_ino(file, &rdu);
29121 + /* err = -ENOTTY; */
29130 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29131 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29132 +++ linux/fs/aufs/rwsem.h 2019-01-28 14:36:12.222418047 +0100
29134 +/* SPDX-License-Identifier: GPL-2.0 */
29136 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29138 + * This program, aufs is free software; you can redistribute it and/or modify
29139 + * it under the terms of the GNU General Public License as published by
29140 + * the Free Software Foundation; either version 2 of the License, or
29141 + * (at your option) any later version.
29143 + * This program is distributed in the hope that it will be useful,
29144 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29145 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29146 + * GNU General Public License for more details.
29148 + * You should have received a copy of the GNU General Public License
29149 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29153 + * simple read-write semaphore wrappers
29156 +#ifndef __AUFS_RWSEM_H__
29157 +#define __AUFS_RWSEM_H__
29161 +#include "debug.h"
29163 +/* in the future, the name 'au_rwsem' will be totally gone */
29164 +#define au_rwsem rw_semaphore
29166 +/* to debug easier, do not make them inlined functions */
29167 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29168 +/* rwsem_is_locked() is unusable */
29169 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29171 + && !lockdep_is_held_type(rw, 1))
29172 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29174 + && !lockdep_is_held_type(rw, 0))
29175 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29177 + && !lockdep_is_held(rw))
29178 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29180 + && lockdep_is_held(rw))
29182 +#define au_rw_init(rw) init_rwsem(rw)
29184 +#define au_rw_init_wlock(rw) do { \
29185 + au_rw_init(rw); \
29186 + down_write(rw); \
29189 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29190 + au_rw_init(rw); \
29191 + down_write_nested(rw, lsc); \
29194 +#define au_rw_read_lock(rw) down_read(rw)
29195 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29196 +#define au_rw_read_unlock(rw) up_read(rw)
29197 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29198 +#define au_rw_write_lock(rw) down_write(rw)
29199 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29200 +#define au_rw_write_unlock(rw) up_write(rw)
29201 +/* why is not _nested version defined? */
29202 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29203 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29205 +#endif /* __KERNEL__ */
29206 +#endif /* __AUFS_RWSEM_H__ */
29207 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29208 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29209 +++ linux/fs/aufs/sbinfo.c 2019-01-28 14:36:12.222418047 +0100
29211 +// SPDX-License-Identifier: GPL-2.0
29213 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29215 + * This program, aufs is free software; you can redistribute it and/or modify
29216 + * it under the terms of the GNU General Public License as published by
29217 + * the Free Software Foundation; either version 2 of the License, or
29218 + * (at your option) any later version.
29220 + * This program is distributed in the hope that it will be useful,
29221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29223 + * GNU General Public License for more details.
29225 + * You should have received a copy of the GNU General Public License
29226 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29230 + * superblock private data
29236 + * they are necessary regardless sysfs is disabled.
29238 +void au_si_free(struct kobject *kobj)
29241 + struct au_sbinfo *sbinfo;
29242 + char *locked __maybe_unused; /* debug only */
29244 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29245 + for (i = 0; i < AuPlink_NHASH; i++)
29246 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29247 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29249 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29250 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29251 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29252 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29254 + dbgaufs_si_fin(sbinfo);
29255 + au_rw_write_lock(&sbinfo->si_rwsem);
29256 + au_br_free(sbinfo);
29257 + au_rw_write_unlock(&sbinfo->si_rwsem);
29259 + au_kfree_try_rcu(sbinfo->si_branch);
29260 + mutex_destroy(&sbinfo->si_xib_mtx);
29261 + AuRwDestroy(&sbinfo->si_rwsem);
29263 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29264 + /* si_nfiles is waited too */
29265 + au_kfree_rcu(sbinfo);
29268 +int au_si_alloc(struct super_block *sb)
29271 + struct au_sbinfo *sbinfo;
29274 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29275 + if (unlikely(!sbinfo))
29278 + /* will be reallocated separately */
29279 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29280 + if (unlikely(!sbinfo->si_branch))
29283 + err = sysaufs_si_init(sbinfo);
29285 + dbgaufs_si_null(sbinfo);
29286 + err = dbgaufs_si_init(sbinfo);
29287 + if (unlikely(err))
29288 + kobject_put(&sbinfo->si_kobj);
29290 + if (unlikely(err))
29293 + au_nwt_init(&sbinfo->si_nowait);
29294 + au_rw_init_wlock(&sbinfo->si_rwsem);
29296 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29297 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29299 + sbinfo->si_bbot = -1;
29300 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29302 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29303 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29304 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29305 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29307 + au_fhsm_init(sbinfo);
29309 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29311 + sbinfo->si_xino_jiffy = jiffies;
29312 + sbinfo->si_xino_expire
29313 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29314 + mutex_init(&sbinfo->si_xib_mtx);
29315 + /* leave si_xib_last_pindex and si_xib_next_bit */
29317 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29319 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29320 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29321 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29322 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29324 + for (i = 0; i < AuPlink_NHASH; i++)
29325 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29326 + init_waitqueue_head(&sbinfo->si_plink_wq);
29327 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29329 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29331 + /* with getattr by default */
29332 + sbinfo->si_iop_array = aufs_iop;
29334 + /* leave other members for sysaufs and si_mnt. */
29335 + sbinfo->si_sb = sb;
29336 + sb->s_fs_info = sbinfo;
29338 + return 0; /* success */
29341 + au_kfree_try_rcu(sbinfo->si_branch);
29343 + au_kfree_rcu(sbinfo);
29348 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29351 + struct au_branch **brp;
29353 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29356 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29357 + if (unlikely(!sz))
29358 + sz = sizeof(*brp);
29359 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29362 + sbinfo->si_branch = brp;
29369 +/* ---------------------------------------------------------------------- */
29371 +unsigned int au_sigen_inc(struct super_block *sb)
29373 + unsigned int gen;
29374 + struct inode *inode;
29376 + SiMustWriteLock(sb);
29378 + gen = ++au_sbi(sb)->si_generation;
29379 + au_update_digen(sb->s_root);
29380 + inode = d_inode(sb->s_root);
29381 + au_update_iigen(inode, /*half*/0);
29382 + inode_inc_iversion(inode);
29386 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29388 + aufs_bindex_t br_id;
29390 + struct au_sbinfo *sbinfo;
29392 + SiMustWriteLock(sb);
29394 + sbinfo = au_sbi(sb);
29395 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29396 + br_id = ++sbinfo->si_last_br_id;
29397 + AuDebugOn(br_id < 0);
29398 + if (br_id && au_br_index(sb, br_id) < 0)
29405 +/* ---------------------------------------------------------------------- */
29407 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29408 +int si_read_lock(struct super_block *sb, int flags)
29413 + if (au_ftest_lock(flags, FLUSH))
29414 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29416 + si_noflush_read_lock(sb);
29417 + err = au_plink_maint(sb, flags);
29418 + if (unlikely(err))
29419 + si_read_unlock(sb);
29424 +int si_write_lock(struct super_block *sb, int flags)
29428 + if (au_ftest_lock(flags, FLUSH))
29429 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29431 + si_noflush_write_lock(sb);
29432 + err = au_plink_maint(sb, flags);
29433 + if (unlikely(err))
29434 + si_write_unlock(sb);
29439 +/* dentry and super_block lock. call at entry point */
29440 +int aufs_read_lock(struct dentry *dentry, int flags)
29443 + struct super_block *sb;
29445 + sb = dentry->d_sb;
29446 + err = si_read_lock(sb, flags);
29447 + if (unlikely(err))
29450 + if (au_ftest_lock(flags, DW))
29451 + di_write_lock_child(dentry);
29453 + di_read_lock_child(dentry, flags);
29455 + if (au_ftest_lock(flags, GEN)) {
29456 + err = au_digen_test(dentry, au_sigen(sb));
29457 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29458 + AuDebugOn(!err && au_dbrange_test(dentry));
29460 + err = au_dbrange_test(dentry);
29461 + if (unlikely(err))
29462 + aufs_read_unlock(dentry, flags);
29469 +void aufs_read_unlock(struct dentry *dentry, int flags)
29471 + if (au_ftest_lock(flags, DW))
29472 + di_write_unlock(dentry);
29474 + di_read_unlock(dentry, flags);
29475 + si_read_unlock(dentry->d_sb);
29478 +void aufs_write_lock(struct dentry *dentry)
29480 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29481 + di_write_lock_child(dentry);
29484 +void aufs_write_unlock(struct dentry *dentry)
29486 + di_write_unlock(dentry);
29487 + si_write_unlock(dentry->d_sb);
29490 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29493 + unsigned int sigen;
29494 + struct super_block *sb;
29497 + err = si_read_lock(sb, flags);
29498 + if (unlikely(err))
29501 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29503 + if (au_ftest_lock(flags, GEN)) {
29504 + sigen = au_sigen(sb);
29505 + err = au_digen_test(d1, sigen);
29506 + AuDebugOn(!err && au_dbrange_test(d1));
29508 + err = au_digen_test(d2, sigen);
29509 + AuDebugOn(!err && au_dbrange_test(d2));
29511 + if (unlikely(err))
29512 + aufs_read_and_write_unlock2(d1, d2);
29519 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29521 + di_write_unlock2(d1, d2);
29522 + si_read_unlock(d1->d_sb);
29524 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29525 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29526 +++ linux/fs/aufs/super.c 2019-01-28 14:36:12.222418047 +0100
29528 +// SPDX-License-Identifier: GPL-2.0
29530 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29532 + * This program, aufs is free software; you can redistribute it and/or modify
29533 + * it under the terms of the GNU General Public License as published by
29534 + * the Free Software Foundation; either version 2 of the License, or
29535 + * (at your option) any later version.
29537 + * This program is distributed in the hope that it will be useful,
29538 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29539 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29540 + * GNU General Public License for more details.
29542 + * You should have received a copy of the GNU General Public License
29543 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29547 + * mount and super_block operations
29550 +#include <linux/mm.h>
29551 +#include <linux/seq_file.h>
29552 +#include <linux/statfs.h>
29553 +#include <linux/vmalloc.h>
29557 + * super_operations
29559 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29561 + struct au_icntnr *c;
29563 + c = au_cache_alloc_icntnr();
29565 + au_icntnr_init(c);
29566 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29567 + c->iinfo.ii_hinode = NULL;
29568 + return &c->vfs_inode;
29573 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29575 + struct inode *inode = container_of(head, struct inode, i_rcu);
29577 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29580 +static void aufs_destroy_inode(struct inode *inode)
29582 + if (!au_is_bad_inode(inode))
29583 + au_iinfo_fin(inode);
29584 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29587 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29589 + struct inode *inode;
29592 + inode = iget_locked(sb, ino);
29593 + if (unlikely(!inode)) {
29594 + inode = ERR_PTR(-ENOMEM);
29597 + if (!(inode->i_state & I_NEW))
29600 + err = au_xigen_new(inode);
29602 + err = au_iinfo_init(inode);
29604 + inode_inc_iversion(inode);
29606 + iget_failed(inode);
29607 + inode = ERR_PTR(err);
29611 + /* never return NULL */
29612 + AuDebugOn(!inode);
29613 + AuTraceErrPtr(inode);
29617 +/* lock free root dinfo */
29618 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29621 + aufs_bindex_t bindex, bbot;
29622 + struct path path;
29623 + struct au_hdentry *hdp;
29624 + struct au_branch *br;
29625 + au_br_perm_str_t perm;
29628 + bbot = au_sbbot(sb);
29630 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29631 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29632 + br = au_sbr(sb, bindex);
29633 + path.mnt = au_br_mnt(br);
29634 + path.dentry = hdp->hd_dentry;
29635 + err = au_seq_path(seq, &path);
29637 + au_optstr_br_perm(&perm, br->br_perm);
29638 + seq_printf(seq, "=%s", perm.a);
29639 + if (bindex != bbot)
29640 + seq_putc(seq, ':');
29643 + if (unlikely(err || seq_has_overflowed(seq)))
29649 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29650 + const char *append)
29655 + while (*pat != ':')
29658 + strcpy(p, append);
29659 + AuDebugOn(strlen(fmt) >= len);
29662 +static void au_show_wbr_create(struct seq_file *m, int v,
29663 + struct au_sbinfo *sbinfo)
29667 + struct au_wbr_mfs *mfs;
29669 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29671 + seq_puts(m, ",create=");
29672 + pat = au_optstr_wbr_create(v);
29673 + mfs = &sbinfo->si_wbr_mfs;
29675 + case AuWbrCreate_TDP:
29676 + case AuWbrCreate_RR:
29677 + case AuWbrCreate_MFS:
29678 + case AuWbrCreate_PMFS:
29679 + seq_puts(m, pat);
29681 + case AuWbrCreate_MFSRR:
29682 + case AuWbrCreate_TDMFS:
29683 + case AuWbrCreate_PMFSRR:
29684 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29685 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29687 + case AuWbrCreate_MFSV:
29688 + case AuWbrCreate_PMFSV:
29689 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29690 + seq_printf(m, fmt,
29691 + jiffies_to_msecs(mfs->mfs_expire)
29694 + case AuWbrCreate_MFSRRV:
29695 + case AuWbrCreate_TDMFSV:
29696 + case AuWbrCreate_PMFSRRV:
29697 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29698 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29699 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29706 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29708 +#ifdef CONFIG_SYSFS
29712 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29713 + aufs_bindex_t bindex, brid;
29714 + struct qstr *name;
29716 + struct dentry *d, *h_root;
29717 + struct au_branch *br;
29719 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29722 + f = au_sbi(sb)->si_xib;
29726 + /* stop printing the default xino path on the first writable branch */
29728 + bindex = au_xi_root(sb, f->f_path.dentry);
29729 + if (bindex >= 0) {
29730 + br = au_sbr_sb(sb, bindex);
29731 + h_root = au_br_dentry(br);
29734 + d = f->f_path.dentry;
29735 + name = &d->d_name;
29736 + /* safe ->d_parent because the file is unlinked */
29737 + if (d->d_parent == h_root
29738 + && name->len == len
29739 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29742 + seq_puts(seq, ",xino=");
29743 + err = au_xino_path(seq, f);
29750 +/* seq_file will re-call me in case of too long string */
29751 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29754 + unsigned int mnt_flags, v;
29755 + struct super_block *sb;
29756 + struct au_sbinfo *sbinfo;
29758 +#define AuBool(name, str) do { \
29759 + v = au_opt_test(mnt_flags, name); \
29760 + if (v != au_opt_test(AuOpt_Def, name)) \
29761 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29764 +#define AuStr(name, str) do { \
29765 + v = mnt_flags & AuOptMask_##name; \
29766 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29767 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29770 +#define AuUInt(name, str, val) do { \
29771 + if (val != AUFS_##name##_DEF) \
29772 + seq_printf(m, "," #str "=%u", val); \
29775 + sb = dentry->d_sb;
29776 + if (sb->s_flags & SB_POSIXACL)
29777 + seq_puts(m, ",acl");
29779 + if (sb->s_flags & SB_I_VERSION)
29780 + seq_puts(m, ",i_version");
29783 + /* lock free root dinfo */
29784 + si_noflush_read_lock(sb);
29785 + sbinfo = au_sbi(sb);
29786 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29788 + mnt_flags = au_mntflags(sb);
29789 + if (au_opt_test(mnt_flags, XINO)) {
29790 + err = au_show_xino(m, sb);
29791 + if (unlikely(err))
29794 + seq_puts(m, ",noxino");
29796 + AuBool(TRUNC_XINO, trunc_xino);
29797 + AuStr(UDBA, udba);
29798 + AuBool(SHWH, shwh);
29799 + AuBool(PLINK, plink);
29800 + AuBool(DIO, dio);
29801 + AuBool(DIRPERM1, dirperm1);
29803 + v = sbinfo->si_wbr_create;
29804 + if (v != AuWbrCreate_Def)
29805 + au_show_wbr_create(m, v, sbinfo);
29807 + v = sbinfo->si_wbr_copyup;
29808 + if (v != AuWbrCopyup_Def)
29809 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29811 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29812 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29813 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29815 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29817 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29818 + AuUInt(RDCACHE, rdcache, v);
29820 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29821 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29823 + au_fhsm_show(m, sbinfo);
29825 + AuBool(DIRREN, dirren);
29826 + AuBool(SUM, sum);
29827 + /* AuBool(SUM_W, wsum); */
29828 + AuBool(WARN_PERM, warn_perm);
29829 + AuBool(VERBOSE, verbose);
29832 + /* be sure to print "br:" last */
29833 + if (!sysaufs_brs) {
29834 + seq_puts(m, ",br:");
29835 + au_show_brs(m, sb);
29837 + si_read_unlock(sb);
29845 +/* ---------------------------------------------------------------------- */
29847 +/* sum mode which returns the summation for statfs(2) */
29849 +static u64 au_add_till_max(u64 a, u64 b)
29857 + return ULLONG_MAX;
29860 +static u64 au_mul_till_max(u64 a, long mul)
29868 + return ULLONG_MAX;
29871 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29874 + long bsize, factor;
29875 + u64 blocks, bfree, bavail, files, ffree;
29876 + aufs_bindex_t bbot, bindex, i;
29877 + unsigned char shared;
29878 + struct path h_path;
29879 + struct super_block *h_sb;
29882 + bsize = LONG_MAX;
29888 + bbot = au_sbbot(sb);
29889 + for (bindex = 0; bindex <= bbot; bindex++) {
29890 + h_path.mnt = au_sbr_mnt(sb, bindex);
29891 + h_sb = h_path.mnt->mnt_sb;
29893 + for (i = 0; !shared && i < bindex; i++)
29894 + shared = (au_sbr_sb(sb, i) == h_sb);
29898 + /* sb->s_root for NFS is unreliable */
29899 + h_path.dentry = h_path.mnt->mnt_root;
29900 + err = vfs_statfs(&h_path, buf);
29901 + if (unlikely(err))
29904 + if (bsize > buf->f_bsize) {
29906 + * we will reduce bsize, so we have to expand blocks
29907 + * etc. to match them again
29909 + factor = (bsize / buf->f_bsize);
29910 + blocks = au_mul_till_max(blocks, factor);
29911 + bfree = au_mul_till_max(bfree, factor);
29912 + bavail = au_mul_till_max(bavail, factor);
29913 + bsize = buf->f_bsize;
29916 + factor = (buf->f_bsize / bsize);
29917 + blocks = au_add_till_max(blocks,
29918 + au_mul_till_max(buf->f_blocks, factor));
29919 + bfree = au_add_till_max(bfree,
29920 + au_mul_till_max(buf->f_bfree, factor));
29921 + bavail = au_add_till_max(bavail,
29922 + au_mul_till_max(buf->f_bavail, factor));
29923 + files = au_add_till_max(files, buf->f_files);
29924 + ffree = au_add_till_max(ffree, buf->f_ffree);
29927 + buf->f_bsize = bsize;
29928 + buf->f_blocks = blocks;
29929 + buf->f_bfree = bfree;
29930 + buf->f_bavail = bavail;
29931 + buf->f_files = files;
29932 + buf->f_ffree = ffree;
29933 + buf->f_frsize = 0;
29939 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29942 + struct path h_path;
29943 + struct super_block *sb;
29945 + /* lock free root dinfo */
29946 + sb = dentry->d_sb;
29947 + si_noflush_read_lock(sb);
29948 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29949 + /* sb->s_root for NFS is unreliable */
29950 + h_path.mnt = au_sbr_mnt(sb, 0);
29951 + h_path.dentry = h_path.mnt->mnt_root;
29952 + err = vfs_statfs(&h_path, buf);
29954 + err = au_statfs_sum(sb, buf);
29955 + si_read_unlock(sb);
29958 + buf->f_type = AUFS_SUPER_MAGIC;
29959 + buf->f_namelen = AUFS_MAX_NAMELEN;
29960 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29962 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29967 +/* ---------------------------------------------------------------------- */
29969 +static int aufs_sync_fs(struct super_block *sb, int wait)
29972 + aufs_bindex_t bbot, bindex;
29973 + struct au_branch *br;
29974 + struct super_block *h_sb;
29977 + si_noflush_read_lock(sb);
29978 + bbot = au_sbbot(sb);
29979 + for (bindex = 0; bindex <= bbot; bindex++) {
29980 + br = au_sbr(sb, bindex);
29981 + if (!au_br_writable(br->br_perm))
29984 + h_sb = au_sbr_sb(sb, bindex);
29985 + e = vfsub_sync_filesystem(h_sb, wait);
29986 + if (unlikely(e && !err))
29988 + /* go on even if an error happens */
29990 + si_read_unlock(sb);
29995 +/* ---------------------------------------------------------------------- */
29997 +/* final actions when unmounting a file system */
29998 +static void aufs_put_super(struct super_block *sb)
30000 + struct au_sbinfo *sbinfo;
30002 + sbinfo = au_sbi(sb);
30004 + kobject_put(&sbinfo->si_kobj);
30007 +/* ---------------------------------------------------------------------- */
30009 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30010 + struct super_block *sb, void *arg)
30013 + unsigned long long n, sz;
30020 + if (*hint > ULLONG_MAX / sizeof(array)) {
30021 + array = ERR_PTR(-EMFILE);
30022 + pr_err("hint %llu\n", *hint);
30026 + sz = sizeof(array) * *hint;
30027 + array = kzalloc(sz, GFP_NOFS);
30028 + if (unlikely(!array))
30029 + array = vzalloc(sz);
30030 + if (unlikely(!array)) {
30031 + array = ERR_PTR(-ENOMEM);
30035 + n = cb(sb, array, *hint, arg);
30036 + AuDebugOn(n > *hint);
30043 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30044 + unsigned long long max __maybe_unused,
30047 + unsigned long long n;
30048 + struct inode **p, *inode;
30049 + struct list_head *head;
30054 + spin_lock(&sb->s_inode_list_lock);
30055 + list_for_each_entry(inode, head, i_sb_list) {
30056 + if (!au_is_bad_inode(inode)
30057 + && au_ii(inode)->ii_btop >= 0) {
30058 + spin_lock(&inode->i_lock);
30059 + if (atomic_read(&inode->i_count)) {
30063 + AuDebugOn(n > max);
30065 + spin_unlock(&inode->i_lock);
30068 + spin_unlock(&sb->s_inode_list_lock);
30073 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30075 + struct au_sbinfo *sbi;
30077 + sbi = au_sbi(sb);
30078 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30079 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30082 +void au_iarray_free(struct inode **a, unsigned long long max)
30084 + unsigned long long ull;
30086 + for (ull = 0; ull < max; ull++)
30091 +/* ---------------------------------------------------------------------- */
30094 + * refresh dentry and inode at remount time.
30096 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30097 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30098 + struct dentry *parent)
30102 + di_write_lock_child(dentry);
30103 + di_read_lock_parent(parent, AuLock_IR);
30104 + err = au_refresh_dentry(dentry, parent);
30105 + if (!err && dir_flags)
30106 + au_hn_reset(d_inode(dentry), dir_flags);
30107 + di_read_unlock(parent, AuLock_IR);
30108 + di_write_unlock(dentry);
30113 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30114 + struct au_sbinfo *sbinfo,
30115 + const unsigned int dir_flags, unsigned int do_idop)
30118 + struct dentry *parent;
30121 + parent = dget_parent(dentry);
30122 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30123 + if (d_really_is_positive(dentry)) {
30124 + if (!d_is_dir(dentry))
30125 + err = au_do_refresh(dentry, /*dir_flags*/0,
30128 + err = au_do_refresh(dentry, dir_flags, parent);
30129 + if (unlikely(err))
30130 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30133 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30134 + AuDbgDentry(dentry);
30140 + au_refresh_dop(dentry, /*force_reval*/0);
30142 + au_refresh_dop(dentry, /*force_reval*/1);
30148 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30150 + int err, i, j, ndentry, e;
30151 + unsigned int sigen;
30152 + struct au_dcsub_pages dpages;
30153 + struct au_dpage *dpage;
30154 + struct dentry **dentries, *d;
30155 + struct au_sbinfo *sbinfo;
30156 + struct dentry *root = sb->s_root;
30157 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30160 + au_refresh_dop(root, /*force_reval*/0);
30162 + err = au_dpages_init(&dpages, GFP_NOFS);
30163 + if (unlikely(err))
30165 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30166 + if (unlikely(err))
30169 + sigen = au_sigen(sb);
30170 + sbinfo = au_sbi(sb);
30171 + for (i = 0; i < dpages.ndpage; i++) {
30172 + dpage = dpages.dpages + i;
30173 + dentries = dpage->dentries;
30174 + ndentry = dpage->ndentry;
30175 + for (j = 0; j < ndentry; j++) {
30177 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30179 + if (unlikely(e && !err))
30181 + /* go on even err */
30186 + au_dpages_free(&dpages);
30191 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30194 + unsigned int sigen;
30195 + unsigned long long max, ull;
30196 + struct inode *inode, **array;
30198 + array = au_iarray_alloc(sb, &max);
30199 + err = PTR_ERR(array);
30200 + if (IS_ERR(array))
30204 + sigen = au_sigen(sb);
30205 + for (ull = 0; ull < max; ull++) {
30206 + inode = array[ull];
30207 + if (unlikely(!inode))
30211 + ii_write_lock_child(inode);
30212 + if (au_iigen(inode, NULL) != sigen) {
30213 + e = au_refresh_hinode_self(inode);
30214 + if (unlikely(e)) {
30215 + au_refresh_iop(inode, /*force_getattr*/1);
30216 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30219 + /* go on even if err */
30222 + if (!e && do_idop)
30223 + au_refresh_iop(inode, /*force_getattr*/0);
30224 + ii_write_unlock(inode);
30227 + au_iarray_free(array, max);
30233 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30236 + unsigned int udba;
30237 + aufs_bindex_t bindex, bbot;
30238 + struct dentry *root;
30239 + struct inode *inode;
30240 + struct au_branch *br;
30241 + struct au_sbinfo *sbi;
30243 + au_sigen_inc(sb);
30244 + sbi = au_sbi(sb);
30245 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30247 + root = sb->s_root;
30248 + DiMustNoWaiters(root);
30249 + inode = d_inode(root);
30250 + IiMustNoWaiters(inode);
30252 + udba = au_opt_udba(sb);
30253 + bbot = au_sbbot(sb);
30254 + for (bindex = 0; bindex <= bbot; bindex++) {
30255 + br = au_sbr(sb, bindex);
30256 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30257 + if (unlikely(err))
30258 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30260 + /* go on even if err */
30262 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30265 + if (au_ftest_si(sbi, NO_DREVAL)) {
30266 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30267 + sb->s_d_op = &aufs_dop_noreval;
30268 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30269 + sbi->si_iop_array = aufs_iop_nogetattr;
30271 + AuDebugOn(sb->s_d_op == &aufs_dop);
30272 + sb->s_d_op = &aufs_dop;
30273 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30274 + sbi->si_iop_array = aufs_iop;
30276 + pr_info("reset to %ps and %ps\n",
30277 + sb->s_d_op, sbi->si_iop_array);
30280 + di_write_unlock(root);
30281 + err = au_refresh_d(sb, do_idop);
30282 + e = au_refresh_i(sb, do_idop);
30283 + if (unlikely(e && !err))
30285 + /* aufs_write_lock() calls ..._child() */
30286 + di_write_lock_child(root);
30288 + au_cpup_attr_all(inode, /*force*/1);
30290 + if (unlikely(err))
30291 + AuIOErr("refresh failed, ignored, %d\n", err);
30294 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30295 +static int cvt_err(int err)
30309 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30312 + unsigned int mntflags;
30313 + struct au_opts opts = {
30316 + struct dentry *root;
30317 + struct inode *inode;
30318 + struct au_sbinfo *sbinfo;
30321 + root = sb->s_root;
30322 + if (!data || !*data) {
30323 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30325 + di_write_lock_child(root);
30326 + err = au_opts_verify(sb, *flags, /*pending*/0);
30327 + aufs_write_unlock(root);
30333 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30334 + if (unlikely(!opts.opt))
30336 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30337 + opts.flags = AuOpts_REMOUNT;
30338 + opts.sb_flags = *flags;
30340 + /* parse it before aufs lock */
30341 + err = au_opts_parse(sb, data, &opts);
30342 + if (unlikely(err))
30345 + sbinfo = au_sbi(sb);
30346 + inode = d_inode(root);
30347 + inode_lock(inode);
30348 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30349 + if (unlikely(err))
30351 + di_write_lock_child(root);
30353 + /* au_opts_remount() may return an error */
30354 + err = au_opts_remount(sb, &opts);
30355 + au_opts_free(&opts);
30357 + if (au_ftest_opts(opts.flags, REFRESH))
30358 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30360 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30361 + mntflags = au_mntflags(sb);
30362 + do_dx = !!au_opt_test(mntflags, DIO);
30363 + au_dy_arefresh(do_dx);
30366 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30367 + aufs_write_unlock(root);
30370 + inode_unlock(inode);
30372 + free_page((unsigned long)opts.opt);
30374 + err = cvt_err(err);
30379 +static const struct super_operations aufs_sop = {
30380 + .alloc_inode = aufs_alloc_inode,
30381 + .destroy_inode = aufs_destroy_inode,
30382 + /* always deleting, no clearing */
30383 + .drop_inode = generic_delete_inode,
30384 + .show_options = aufs_show_options,
30385 + .statfs = aufs_statfs,
30386 + .put_super = aufs_put_super,
30387 + .sync_fs = aufs_sync_fs,
30388 + .remount_fs = aufs_remount_fs
30391 +/* ---------------------------------------------------------------------- */
30393 +static int alloc_root(struct super_block *sb)
30396 + struct inode *inode;
30397 + struct dentry *root;
30400 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30401 + err = PTR_ERR(inode);
30402 + if (IS_ERR(inode))
30405 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30406 + inode->i_fop = &aufs_dir_fop;
30407 + inode->i_mode = S_IFDIR;
30408 + set_nlink(inode, 2);
30409 + unlock_new_inode(inode);
30411 + root = d_make_root(inode);
30412 + if (unlikely(!root))
30414 + err = PTR_ERR(root);
30415 + if (IS_ERR(root))
30418 + err = au_di_init(root);
30420 + sb->s_root = root;
30421 + return 0; /* success */
30429 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30430 + int silent __maybe_unused)
30433 + struct au_opts opts = {
30436 + struct au_sbinfo *sbinfo;
30437 + struct dentry *root;
30438 + struct inode *inode;
30439 + char *arg = raw_data;
30441 + if (unlikely(!arg || !*arg)) {
30443 + pr_err("no arg\n");
30448 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30449 + if (unlikely(!opts.opt))
30451 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30452 + opts.sb_flags = sb->s_flags;
30454 + err = au_si_alloc(sb);
30455 + if (unlikely(err))
30457 + sbinfo = au_sbi(sb);
30459 + /* all timestamps always follow the ones on the branch */
30460 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30461 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30462 + sb->s_op = &aufs_sop;
30463 + sb->s_d_op = &aufs_dop;
30464 + sb->s_magic = AUFS_SUPER_MAGIC;
30465 + sb->s_maxbytes = 0;
30466 + sb->s_stack_depth = 1;
30467 + au_export_init(sb);
30468 + au_xattr_init(sb);
30470 + err = alloc_root(sb);
30471 + if (unlikely(err)) {
30472 + si_write_unlock(sb);
30475 + root = sb->s_root;
30476 + inode = d_inode(root);
30479 + * actually we can parse options regardless aufs lock here.
30480 + * but at remount time, parsing must be done before aufs lock.
30481 + * so we follow the same rule.
30483 + ii_write_lock_parent(inode);
30484 + aufs_write_unlock(root);
30485 + err = au_opts_parse(sb, arg, &opts);
30486 + if (unlikely(err))
30489 + /* lock vfs_inode first, then aufs. */
30490 + inode_lock(inode);
30491 + aufs_write_lock(root);
30492 + err = au_opts_mount(sb, &opts);
30493 + au_opts_free(&opts);
30494 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30495 + sb->s_d_op = &aufs_dop_noreval;
30496 + pr_info("%ps\n", sb->s_d_op);
30497 + au_refresh_dop(root, /*force_reval*/0);
30498 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30499 + au_refresh_iop(inode, /*force_getattr*/0);
30501 + aufs_write_unlock(root);
30502 + inode_unlock(inode);
30504 + goto out_opts; /* success */
30508 + sb->s_root = NULL;
30510 + kobject_put(&sbinfo->si_kobj);
30511 + sb->s_fs_info = NULL;
30513 + free_page((unsigned long)opts.opt);
30516 + err = cvt_err(err);
30521 +/* ---------------------------------------------------------------------- */
30523 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30524 + const char *dev_name __maybe_unused,
30527 + struct dentry *root;
30529 + /* all timestamps always follow the ones on the branch */
30530 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30531 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30532 + if (IS_ERR(root))
30535 + au_sbilist_add(root->d_sb);
30541 +static void aufs_kill_sb(struct super_block *sb)
30543 + struct au_sbinfo *sbinfo;
30545 + sbinfo = au_sbi(sb);
30547 + au_sbilist_del(sb);
30548 + aufs_write_lock(sb->s_root);
30550 + if (sbinfo->si_wbr_create_ops->fin)
30551 + sbinfo->si_wbr_create_ops->fin(sb);
30552 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30553 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30554 + au_remount_refresh(sb, /*do_idop*/0);
30556 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30557 + au_plink_put(sb, /*verbose*/1);
30559 + au_dr_opt_flush(sb);
30560 + sbinfo->si_sb = NULL;
30561 + aufs_write_unlock(sb->s_root);
30562 + au_nwt_flush(&sbinfo->si_nowait);
30564 + kill_anon_super(sb);
30567 +struct file_system_type aufs_fs_type = {
30568 + .name = AUFS_FSTYPE,
30569 + /* a race between rename and others */
30570 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30571 + .mount = aufs_mount,
30572 + .kill_sb = aufs_kill_sb,
30573 + /* no need to __module_get() and module_put(). */
30574 + .owner = THIS_MODULE,
30576 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30577 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30578 +++ linux/fs/aufs/super.h 2019-01-28 14:36:12.222418047 +0100
30580 +/* SPDX-License-Identifier: GPL-2.0 */
30582 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30584 + * This program, aufs is free software; you can redistribute it and/or modify
30585 + * it under the terms of the GNU General Public License as published by
30586 + * the Free Software Foundation; either version 2 of the License, or
30587 + * (at your option) any later version.
30589 + * This program is distributed in the hope that it will be useful,
30590 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30591 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30592 + * GNU General Public License for more details.
30594 + * You should have received a copy of the GNU General Public License
30595 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30599 + * super_block operations
30602 +#ifndef __AUFS_SUPER_H__
30603 +#define __AUFS_SUPER_H__
30607 +#include <linux/fs.h>
30608 +#include <linux/kobject.h>
30611 +#include "rwsem.h"
30614 +/* policies to select one among multiple writable branches */
30615 +struct au_wbr_copyup_operations {
30616 + int (*copyup)(struct dentry *dentry);
30619 +#define AuWbr_DIR 1 /* target is a dir */
30620 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30622 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30623 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30624 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30626 +struct au_wbr_create_operations {
30627 + int (*create)(struct dentry *dentry, unsigned int flags);
30628 + int (*init)(struct super_block *sb);
30629 + int (*fin)(struct super_block *sb);
30632 +struct au_wbr_mfs {
30633 + struct mutex mfs_lock; /* protect this structure */
30634 + unsigned long mfs_jiffy;
30635 + unsigned long mfs_expire;
30636 + aufs_bindex_t mfs_bindex;
30638 + unsigned long long mfsrr_bytes;
30639 + unsigned long long mfsrr_watermark;
30642 +#define AuPlink_NHASH 100
30643 +static inline int au_plink_hash(ino_t ino)
30645 + return ino % AuPlink_NHASH;
30648 +/* File-based Hierarchical Storage Management */
30650 +#ifdef CONFIG_AUFS_FHSM
30651 + /* allow only one process who can receive the notification */
30652 + spinlock_t fhsm_spin;
30654 + wait_queue_head_t fhsm_wqh;
30655 + atomic_t fhsm_readable;
30657 + /* these are protected by si_rwsem */
30658 + unsigned long fhsm_expire;
30659 + aufs_bindex_t fhsm_bottom;
30664 +struct au_sbinfo {
30665 + /* nowait tasks in the system-wide workqueue */
30666 + struct au_nowait_tasks si_nowait;
30669 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30670 + * rwsem for au_sbinfo is necessary.
30672 + struct au_rwsem si_rwsem;
30675 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30678 + au_lcnt_t si_ninodes, si_nfiles;
30680 + /* branch management */
30681 + unsigned int si_generation;
30683 + /* see AuSi_ flags */
30684 + unsigned char au_si_status;
30686 + aufs_bindex_t si_bbot;
30688 + /* dirty trick to keep br_id plus */
30689 + unsigned int si_last_br_id :
30690 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30691 + struct au_branch **si_branch;
30693 + /* policy to select a writable branch */
30694 + unsigned char si_wbr_copyup;
30695 + unsigned char si_wbr_create;
30696 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30697 + struct au_wbr_create_operations *si_wbr_create_ops;
30699 + /* round robin */
30700 + atomic_t si_wbr_rr_next;
30702 + /* most free space */
30703 + struct au_wbr_mfs si_wbr_mfs;
30705 + /* File-based Hierarchical Storage Management */
30706 + struct au_fhsm si_fhsm;
30708 + /* mount flags */
30709 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30710 + unsigned int si_mntflags;
30712 + /* external inode number (bitmap and translation table) */
30713 + vfs_readf_t si_xread;
30714 + vfs_writef_t si_xwrite;
30715 + loff_t si_ximaxent; /* max entries in a xino */
30717 + struct file *si_xib;
30718 + struct mutex si_xib_mtx; /* protect xib members */
30719 + unsigned long *si_xib_buf;
30720 + unsigned long si_xib_last_pindex;
30721 + int si_xib_next_bit;
30723 + unsigned long si_xino_jiffy;
30724 + unsigned long si_xino_expire;
30725 + /* reserved for future use */
30726 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30728 +#ifdef CONFIG_AUFS_EXPORT
30729 + /* i_generation */
30730 + /* todo: make xigen file an array to support many inode numbers */
30731 + struct file *si_xigen;
30732 + atomic_t si_xigen_next;
30735 + /* dirty trick to support atomic_open */
30736 + struct hlist_bl_head si_aopen;
30738 + /* vdir parameters */
30739 + unsigned long si_rdcache; /* max cache time in jiffies */
30740 + unsigned int si_rdblk; /* deblk size */
30741 + unsigned int si_rdhash; /* hash size */
30744 + * If the number of whiteouts are larger than si_dirwh, leave all of
30745 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30746 + * future fsck.aufs or kernel thread will remove them later.
30747 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30749 + unsigned int si_dirwh;
30751 + /* pseudo_link list */
30752 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30753 + wait_queue_head_t si_plink_wq;
30754 + spinlock_t si_plink_maint_lock;
30755 + pid_t si_plink_maint_pid;
30758 + struct hlist_bl_head si_files;
30760 + /* with/without getattr, brother of sb->s_d_op */
30761 + struct inode_operations *si_iop_array;
30764 + * sysfs and lifetime management.
30765 + * this is not a small structure and it may be a waste of memory in case
30766 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30767 + * but using sysfs is majority.
30769 + struct kobject si_kobj;
30770 +#ifdef CONFIG_DEBUG_FS
30771 + struct dentry *si_dbgaufs;
30772 + struct dentry *si_dbgaufs_plink;
30773 + struct dentry *si_dbgaufs_xib;
30774 +#ifdef CONFIG_AUFS_EXPORT
30775 + struct dentry *si_dbgaufs_xigen;
30779 +#ifdef CONFIG_AUFS_SBILIST
30780 + struct hlist_bl_node si_list;
30783 + /* dirty, necessary for unmounting, sysfs and sysrq */
30784 + struct super_block *si_sb;
30787 +/* sbinfo status flags */
30789 + * set true when refresh_dirs() failed at remount time.
30790 + * then try refreshing dirs at access time again.
30791 + * if it is false, refreshing dirs at access time is unnecessary
30793 +#define AuSi_FAILED_REFRESH_DIR 1
30794 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30795 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30797 +#ifndef CONFIG_AUFS_FHSM
30799 +#define AuSi_FHSM 0
30802 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30803 + unsigned int flag)
30805 + AuRwMustAnyLock(&sbi->si_rwsem);
30806 + return sbi->au_si_status & flag;
30808 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30809 +#define au_fset_si(sbinfo, name) do { \
30810 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30811 + (sbinfo)->au_si_status |= AuSi_##name; \
30813 +#define au_fclr_si(sbinfo, name) do { \
30814 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30815 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30818 +/* ---------------------------------------------------------------------- */
30820 +/* policy to select one among writable branches */
30821 +#define AuWbrCopyup(sbinfo, ...) \
30822 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30823 +#define AuWbrCreate(sbinfo, ...) \
30824 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30826 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30827 +#define AuLock_DW 1 /* write-lock dentry */
30828 +#define AuLock_IR (1 << 1) /* read-lock inode */
30829 +#define AuLock_IW (1 << 2) /* write-lock inode */
30830 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30831 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30832 + /* except RENAME_EXCHANGE */
30833 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30834 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30835 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30836 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30837 +#define au_fset_lock(flags, name) \
30838 + do { (flags) |= AuLock_##name; } while (0)
30839 +#define au_fclr_lock(flags, name) \
30840 + do { (flags) &= ~AuLock_##name; } while (0)
30842 +/* ---------------------------------------------------------------------- */
30845 +extern struct file_system_type aufs_fs_type;
30846 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30847 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30848 + unsigned long long max, void *arg);
30849 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30850 + struct super_block *sb, void *arg);
30851 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30852 +void au_iarray_free(struct inode **a, unsigned long long max);
30855 +void au_si_free(struct kobject *kobj);
30856 +int au_si_alloc(struct super_block *sb);
30857 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30859 +unsigned int au_sigen_inc(struct super_block *sb);
30860 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30862 +int si_read_lock(struct super_block *sb, int flags);
30863 +int si_write_lock(struct super_block *sb, int flags);
30864 +int aufs_read_lock(struct dentry *dentry, int flags);
30865 +void aufs_read_unlock(struct dentry *dentry, int flags);
30866 +void aufs_write_lock(struct dentry *dentry);
30867 +void aufs_write_unlock(struct dentry *dentry);
30868 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30869 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30871 +/* wbr_policy.c */
30872 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30873 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30874 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30875 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30876 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30879 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30881 +#ifdef CONFIG_AUFS_FHSM
30884 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30888 + spin_lock(&fhsm->fhsm_spin);
30889 + pid = fhsm->fhsm_pid;
30890 + spin_unlock(&fhsm->fhsm_spin);
30895 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30896 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30897 +int au_fhsm_fd(struct super_block *sb, int oflags);
30898 +int au_fhsm_br_alloc(struct au_branch *br);
30899 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30900 +void au_fhsm_fin(struct super_block *sb);
30901 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30902 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30903 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30905 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30907 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30908 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30909 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30910 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30911 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30912 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30913 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30914 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30915 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30918 +/* ---------------------------------------------------------------------- */
30920 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30922 + return sb->s_fs_info;
30925 +/* ---------------------------------------------------------------------- */
30927 +#ifdef CONFIG_AUFS_EXPORT
30928 +int au_test_nfsd(void);
30929 +void au_export_init(struct super_block *sb);
30930 +void au_xigen_inc(struct inode *inode);
30931 +int au_xigen_new(struct inode *inode);
30932 +int au_xigen_set(struct super_block *sb, struct path *path);
30933 +void au_xigen_clr(struct super_block *sb);
30935 +static inline int au_busy_or_stale(void)
30937 + if (!au_test_nfsd())
30942 +AuStubInt0(au_test_nfsd, void)
30943 +AuStubVoid(au_export_init, struct super_block *sb)
30944 +AuStubVoid(au_xigen_inc, struct inode *inode)
30945 +AuStubInt0(au_xigen_new, struct inode *inode)
30946 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30947 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30948 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30949 +#endif /* CONFIG_AUFS_EXPORT */
30951 +/* ---------------------------------------------------------------------- */
30953 +#ifdef CONFIG_AUFS_SBILIST
30955 +extern struct hlist_bl_head au_sbilist;
30957 +static inline void au_sbilist_init(void)
30959 + INIT_HLIST_BL_HEAD(&au_sbilist);
30962 +static inline void au_sbilist_add(struct super_block *sb)
30964 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30967 +static inline void au_sbilist_del(struct super_block *sb)
30969 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30972 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30973 +static inline void au_sbilist_lock(void)
30975 + hlist_bl_lock(&au_sbilist);
30978 +static inline void au_sbilist_unlock(void)
30980 + hlist_bl_unlock(&au_sbilist);
30982 +#define AuGFP_SBILIST GFP_ATOMIC
30984 +AuStubVoid(au_sbilist_lock, void)
30985 +AuStubVoid(au_sbilist_unlock, void)
30986 +#define AuGFP_SBILIST GFP_NOFS
30987 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30989 +AuStubVoid(au_sbilist_init, void)
30990 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30991 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30992 +AuStubVoid(au_sbilist_lock, void)
30993 +AuStubVoid(au_sbilist_unlock, void)
30994 +#define AuGFP_SBILIST GFP_NOFS
30997 +/* ---------------------------------------------------------------------- */
30999 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31002 + * This function is a dynamic '__init' function actually,
31003 + * so the tiny check for si_rwsem is unnecessary.
31005 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31006 +#ifdef CONFIG_DEBUG_FS
31007 + sbinfo->si_dbgaufs = NULL;
31008 + sbinfo->si_dbgaufs_plink = NULL;
31009 + sbinfo->si_dbgaufs_xib = NULL;
31010 +#ifdef CONFIG_AUFS_EXPORT
31011 + sbinfo->si_dbgaufs_xigen = NULL;
31016 +/* ---------------------------------------------------------------------- */
31018 +/* current->atomic_flags */
31019 +/* this value should never corrupt the ones defined in linux/sched.h */
31020 +#define PFA_AUFS 7
31022 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31023 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31024 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31026 +static inline int si_pid_test(struct super_block *sb)
31028 + return !!task_test_aufs(current);
31031 +static inline void si_pid_clr(struct super_block *sb)
31033 + AuDebugOn(!task_test_aufs(current));
31034 + task_clear_aufs(current);
31037 +static inline void si_pid_set(struct super_block *sb)
31039 + AuDebugOn(task_test_aufs(current));
31040 + task_set_aufs(current);
31043 +/* ---------------------------------------------------------------------- */
31045 +/* lock superblock. mainly for entry point functions */
31046 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31047 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31048 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31049 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31051 +#define __si_read_trylock_nested(sb) \
31052 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31053 +#define __si_write_trylock_nested(sb) \
31054 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31057 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31058 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31059 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31061 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31062 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31063 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31065 +static inline void si_noflush_read_lock(struct super_block *sb)
31067 + __si_read_lock(sb);
31071 +static inline int si_noflush_read_trylock(struct super_block *sb)
31075 + locked = __si_read_trylock(sb);
31081 +static inline void si_noflush_write_lock(struct super_block *sb)
31083 + __si_write_lock(sb);
31087 +static inline int si_noflush_write_trylock(struct super_block *sb)
31091 + locked = __si_write_trylock(sb);
31097 +#if 0 /* reserved */
31098 +static inline int si_read_trylock(struct super_block *sb, int flags)
31100 + if (au_ftest_lock(flags, FLUSH))
31101 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31102 + return si_noflush_read_trylock(sb);
31106 +static inline void si_read_unlock(struct super_block *sb)
31109 + __si_read_unlock(sb);
31112 +#if 0 /* reserved */
31113 +static inline int si_write_trylock(struct super_block *sb, int flags)
31115 + if (au_ftest_lock(flags, FLUSH))
31116 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31117 + return si_noflush_write_trylock(sb);
31121 +static inline void si_write_unlock(struct super_block *sb)
31124 + __si_write_unlock(sb);
31127 +#if 0 /* reserved */
31128 +static inline void si_downgrade_lock(struct super_block *sb)
31130 + __si_downgrade_lock(sb);
31134 +/* ---------------------------------------------------------------------- */
31136 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31138 + SiMustAnyLock(sb);
31139 + return au_sbi(sb)->si_bbot;
31142 +static inline unsigned int au_mntflags(struct super_block *sb)
31144 + SiMustAnyLock(sb);
31145 + return au_sbi(sb)->si_mntflags;
31148 +static inline unsigned int au_sigen(struct super_block *sb)
31150 + SiMustAnyLock(sb);
31151 + return au_sbi(sb)->si_generation;
31154 +static inline struct au_branch *au_sbr(struct super_block *sb,
31155 + aufs_bindex_t bindex)
31157 + SiMustAnyLock(sb);
31158 + return au_sbi(sb)->si_branch[0 + bindex];
31161 +static inline loff_t au_xi_maxent(struct super_block *sb)
31163 + SiMustAnyLock(sb);
31164 + return au_sbi(sb)->si_ximaxent;
31167 +#endif /* __KERNEL__ */
31168 +#endif /* __AUFS_SUPER_H__ */
31169 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31170 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31171 +++ linux/fs/aufs/sysaufs.c 2019-01-28 14:36:12.222418047 +0100
31173 +// SPDX-License-Identifier: GPL-2.0
31175 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31177 + * This program, aufs is free software; you can redistribute it and/or modify
31178 + * it under the terms of the GNU General Public License as published by
31179 + * the Free Software Foundation; either version 2 of the License, or
31180 + * (at your option) any later version.
31182 + * This program is distributed in the hope that it will be useful,
31183 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31184 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31185 + * GNU General Public License for more details.
31187 + * You should have received a copy of the GNU General Public License
31188 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31192 + * sysfs interface and lifetime management
31193 + * they are necessary regardless sysfs is disabled.
31196 +#include <linux/random.h>
31199 +unsigned long sysaufs_si_mask;
31200 +struct kset *sysaufs_kset;
31202 +#define AuSiAttr(_name) { \
31203 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31204 + .show = sysaufs_si_##_name, \
31207 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31208 +struct attribute *sysaufs_si_attrs[] = {
31209 + &sysaufs_si_attr_xi_path.attr,
31213 +static const struct sysfs_ops au_sbi_ops = {
31214 + .show = sysaufs_si_show
31217 +static struct kobj_type au_sbi_ktype = {
31218 + .release = au_si_free,
31219 + .sysfs_ops = &au_sbi_ops,
31220 + .default_attrs = sysaufs_si_attrs
31223 +/* ---------------------------------------------------------------------- */
31225 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31229 + sbinfo->si_kobj.kset = sysaufs_kset;
31230 + /* cf. sysaufs_name() */
31231 + err = kobject_init_and_add
31232 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31233 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31238 +void sysaufs_fin(void)
31240 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31241 + kset_unregister(sysaufs_kset);
31244 +int __init sysaufs_init(void)
31249 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31250 + } while (!sysaufs_si_mask);
31253 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31254 + if (unlikely(!sysaufs_kset))
31256 + err = PTR_ERR(sysaufs_kset);
31257 + if (IS_ERR(sysaufs_kset))
31259 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31260 + if (unlikely(err))
31261 + kset_unregister(sysaufs_kset);
31266 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31267 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31268 +++ linux/fs/aufs/sysaufs.h 2019-01-28 14:36:12.222418047 +0100
31270 +/* SPDX-License-Identifier: GPL-2.0 */
31272 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31274 + * This program, aufs is free software; you can redistribute it and/or modify
31275 + * it under the terms of the GNU General Public License as published by
31276 + * the Free Software Foundation; either version 2 of the License, or
31277 + * (at your option) any later version.
31279 + * This program is distributed in the hope that it will be useful,
31280 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31281 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31282 + * GNU General Public License for more details.
31284 + * You should have received a copy of the GNU General Public License
31285 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31289 + * sysfs interface and mount lifetime management
31292 +#ifndef __SYSAUFS_H__
31293 +#define __SYSAUFS_H__
31297 +#include <linux/sysfs.h>
31298 +#include "module.h"
31300 +struct super_block;
31303 +struct sysaufs_si_attr {
31304 + struct attribute attr;
31305 + int (*show)(struct seq_file *seq, struct super_block *sb);
31308 +/* ---------------------------------------------------------------------- */
31311 +extern unsigned long sysaufs_si_mask;
31312 +extern struct kset *sysaufs_kset;
31313 +extern struct attribute *sysaufs_si_attrs[];
31314 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31315 +int __init sysaufs_init(void);
31316 +void sysaufs_fin(void);
31318 +/* ---------------------------------------------------------------------- */
31320 +/* some people doesn't like to show a pointer in kernel */
31321 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31323 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31326 +#define SysaufsSiNamePrefix "si_"
31327 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31328 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31330 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31331 + sysaufs_si_id(sbinfo));
31335 +#ifdef CONFIG_SYSFS
31337 +extern struct attribute_group *sysaufs_attr_group;
31339 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31340 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31342 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31343 +#ifdef CONFIG_COMPAT
31344 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31347 +void sysaufs_br_init(struct au_branch *br);
31348 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31349 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31351 +#define sysaufs_brs_init() do {} while (0)
31354 +#define sysaufs_attr_group NULL
31356 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31357 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31358 + struct attribute *attr, char *buf)
31359 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31360 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31361 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31363 +static inline void sysaufs_brs_init(void)
31368 +#endif /* CONFIG_SYSFS */
31370 +#endif /* __KERNEL__ */
31371 +#endif /* __SYSAUFS_H__ */
31372 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31373 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31374 +++ linux/fs/aufs/sysfs.c 2019-01-28 14:36:12.222418047 +0100
31376 +// SPDX-License-Identifier: GPL-2.0
31378 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31380 + * This program, aufs is free software; you can redistribute it and/or modify
31381 + * it under the terms of the GNU General Public License as published by
31382 + * the Free Software Foundation; either version 2 of the License, or
31383 + * (at your option) any later version.
31385 + * This program is distributed in the hope that it will be useful,
31386 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31387 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31388 + * GNU General Public License for more details.
31390 + * You should have received a copy of the GNU General Public License
31391 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31395 + * sysfs interface
31398 +#include <linux/compat.h>
31399 +#include <linux/seq_file.h>
31402 +#ifdef CONFIG_AUFS_FS_MODULE
31403 +/* this entry violates the "one line per file" policy of sysfs */
31404 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31408 + static char *conf =
31409 +/* this file is generated at compiling */
31410 +#include "conf.str"
31413 + err = snprintf(buf, PAGE_SIZE, conf);
31414 + if (unlikely(err >= PAGE_SIZE))
31419 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31422 +static struct attribute *au_attr[] = {
31423 +#ifdef CONFIG_AUFS_FS_MODULE
31424 + &au_config_attr.attr,
31426 + NULL, /* need to NULL terminate the list of attributes */
31429 +static struct attribute_group sysaufs_attr_group_body = {
31433 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31435 +/* ---------------------------------------------------------------------- */
31437 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31441 + SiMustAnyLock(sb);
31444 + if (au_opt_test(au_mntflags(sb), XINO)) {
31445 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31446 + seq_putc(seq, '\n');
31452 + * the lifetime of branch is independent from the entry under sysfs.
31453 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31456 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31457 + aufs_bindex_t bindex, int idx)
31460 + struct path path;
31461 + struct dentry *root;
31462 + struct au_branch *br;
31463 + au_br_perm_str_t perm;
31465 + AuDbg("b%d\n", bindex);
31468 + root = sb->s_root;
31469 + di_read_lock_parent(root, !AuLock_IR);
31470 + br = au_sbr(sb, bindex);
31473 + case AuBrSysfs_BR:
31474 + path.mnt = au_br_mnt(br);
31475 + path.dentry = au_h_dptr(root, bindex);
31476 + err = au_seq_path(seq, &path);
31478 + au_optstr_br_perm(&perm, br->br_perm);
31479 + seq_printf(seq, "=%s\n", perm.a);
31482 + case AuBrSysfs_BRID:
31483 + seq_printf(seq, "%d\n", br->br_id);
31486 + di_read_unlock(root, !AuLock_IR);
31487 + if (unlikely(err || seq_has_overflowed(seq)))
31493 +/* ---------------------------------------------------------------------- */
31495 +static struct seq_file *au_seq(char *p, ssize_t len)
31497 + struct seq_file *seq;
31499 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31501 + /* mutex_init(&seq.lock); */
31504 + return seq; /* success */
31507 + seq = ERR_PTR(-ENOMEM);
31511 +#define SysaufsBr_PREFIX "br"
31512 +#define SysaufsBrid_PREFIX "brid"
31514 +/* todo: file size may exceed PAGE_SIZE */
31515 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31521 + aufs_bindex_t bbot;
31522 + struct au_sbinfo *sbinfo;
31523 + struct super_block *sb;
31524 + struct seq_file *seq;
31526 + struct attribute **cattr;
31528 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31529 + sb = sbinfo->si_sb;
31532 + * prevent a race condition between sysfs and aufs.
31533 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31534 + * prohibits maintaining the sysfs entries.
31535 + * hew we acquire read lock after sysfs_get_active_two().
31536 + * on the other hand, the remount process may maintain the sysfs/aufs
31537 + * entries after acquiring write lock.
31538 + * it can cause a deadlock.
31539 + * simply we gave up processing read here.
31542 + if (unlikely(!si_noflush_read_trylock(sb)))
31545 + seq = au_seq(buf, PAGE_SIZE);
31546 + err = PTR_ERR(seq);
31550 + name = (void *)attr->name;
31551 + cattr = sysaufs_si_attrs;
31553 + if (!strcmp(name, (*cattr)->name)) {
31554 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31561 + if (!strncmp(name, SysaufsBrid_PREFIX,
31562 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31563 + idx = AuBrSysfs_BRID;
31564 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31565 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31566 + sizeof(SysaufsBr_PREFIX) - 1)) {
31567 + idx = AuBrSysfs_BR;
31568 + name += sizeof(SysaufsBr_PREFIX) - 1;
31572 + err = kstrtol(name, 10, &l);
31574 + bbot = au_sbbot(sb);
31576 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31583 + err = seq->count;
31584 + /* sysfs limit */
31585 + if (unlikely(err == PAGE_SIZE))
31588 + au_kfree_rcu(seq);
31590 + si_read_unlock(sb);
31595 +/* ---------------------------------------------------------------------- */
31597 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31601 + aufs_bindex_t bindex, bbot;
31604 + struct seq_file *seq;
31605 + struct au_branch *br;
31607 + si_read_lock(sb, AuLock_FLUSH);
31608 + bbot = au_sbbot(sb);
31614 + buf = (void *)__get_free_page(GFP_NOFS);
31615 + if (unlikely(!buf))
31618 + seq = au_seq(buf, PAGE_SIZE);
31619 + err = PTR_ERR(seq);
31623 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31624 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31625 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31626 + if (unlikely(err))
31629 + br = au_sbr(sb, bindex);
31630 + brid = br->br_id;
31631 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31632 + err = __put_user(brid, &arg->id);
31633 + if (unlikely(err))
31636 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31637 + err = __put_user(br->br_perm, &arg->perm);
31638 + if (unlikely(err))
31641 + err = au_seq_path(seq, &br->br_path);
31642 + if (unlikely(err))
31644 + seq_putc(seq, '\0');
31645 + if (!seq_has_overflowed(seq)) {
31646 + err = copy_to_user(arg->path, seq->buf, seq->count);
31648 + if (unlikely(err))
31655 + if (unlikely(err))
31659 + au_kfree_rcu(seq);
31661 + free_page((unsigned long)buf);
31663 + si_read_unlock(sb);
31667 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31669 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31672 +#ifdef CONFIG_COMPAT
31673 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31675 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31679 +/* ---------------------------------------------------------------------- */
31681 +void sysaufs_br_init(struct au_branch *br)
31684 + struct au_brsysfs *br_sysfs;
31685 + struct attribute *attr;
31687 + br_sysfs = br->br_sysfs;
31688 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31689 + attr = &br_sysfs->attr;
31690 + sysfs_attr_init(attr);
31691 + attr->name = br_sysfs->name;
31692 + attr->mode = 0444;
31697 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31699 + struct au_branch *br;
31700 + struct kobject *kobj;
31701 + struct au_brsysfs *br_sysfs;
31703 + aufs_bindex_t bbot;
31705 + if (!sysaufs_brs)
31708 + kobj = &au_sbi(sb)->si_kobj;
31709 + bbot = au_sbbot(sb);
31710 + for (; bindex <= bbot; bindex++) {
31711 + br = au_sbr(sb, bindex);
31712 + br_sysfs = br->br_sysfs;
31713 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31714 + sysfs_remove_file(kobj, &br_sysfs->attr);
31720 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31723 + aufs_bindex_t bbot;
31724 + struct kobject *kobj;
31725 + struct au_branch *br;
31726 + struct au_brsysfs *br_sysfs;
31728 + if (!sysaufs_brs)
31731 + kobj = &au_sbi(sb)->si_kobj;
31732 + bbot = au_sbbot(sb);
31733 + for (; bindex <= bbot; bindex++) {
31734 + br = au_sbr(sb, bindex);
31735 + br_sysfs = br->br_sysfs;
31736 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31737 + SysaufsBr_PREFIX "%d", bindex);
31738 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31739 + SysaufsBrid_PREFIX "%d", bindex);
31740 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31741 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31742 + if (unlikely(err))
31743 + pr_warn("failed %s under sysfs(%d)\n",
31744 + br_sysfs->name, err);
31749 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31750 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31751 +++ linux/fs/aufs/sysrq.c 2019-01-28 14:36:12.222418047 +0100
31753 +// SPDX-License-Identifier: GPL-2.0
31755 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31757 + * This program, aufs is free software; you can redistribute it and/or modify
31758 + * it under the terms of the GNU General Public License as published by
31759 + * the Free Software Foundation; either version 2 of the License, or
31760 + * (at your option) any later version.
31762 + * This program is distributed in the hope that it will be useful,
31763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31765 + * GNU General Public License for more details.
31767 + * You should have received a copy of the GNU General Public License
31768 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31772 + * magic sysrq handler
31775 +/* #include <linux/sysrq.h> */
31776 +#include <linux/writeback.h>
31779 +/* ---------------------------------------------------------------------- */
31781 +static void sysrq_sb(struct super_block *sb)
31784 + struct au_sbinfo *sbinfo;
31785 + struct file *file;
31786 + struct hlist_bl_head *files;
31787 + struct hlist_bl_node *pos;
31788 + struct au_finfo *finfo;
31790 + plevel = au_plevel;
31791 + au_plevel = KERN_WARNING;
31793 + /* since we define pr_fmt, call printk directly */
31794 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31796 + sbinfo = au_sbi(sb);
31797 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31798 + pr("superblock\n");
31802 + pr("root dentry\n");
31803 + au_dpri_dentry(sb->s_root);
31804 + pr("root inode\n");
31805 + au_dpri_inode(d_inode(sb->s_root));
31810 + int err, i, j, ndentry;
31811 + struct au_dcsub_pages dpages;
31812 + struct au_dpage *dpage;
31814 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31815 + if (unlikely(err))
31817 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31819 + for (i = 0; i < dpages.ndpage; i++) {
31820 + dpage = dpages.dpages + i;
31821 + ndentry = dpage->ndentry;
31822 + for (j = 0; j < ndentry; j++)
31823 + au_dpri_dentry(dpage->dentries[j]);
31825 + au_dpages_free(&dpages);
31833 + pr("isolated inode\n");
31834 + spin_lock(&sb->s_inode_list_lock);
31835 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31836 + spin_lock(&i->i_lock);
31837 + if (1 || hlist_empty(&i->i_dentry))
31838 + au_dpri_inode(i);
31839 + spin_unlock(&i->i_lock);
31841 + spin_unlock(&sb->s_inode_list_lock);
31845 + files = &au_sbi(sb)->si_files;
31846 + hlist_bl_lock(files);
31847 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31850 + file = finfo->fi_file;
31851 + mode = file_inode(file)->i_mode;
31852 + if (!special_file(mode))
31853 + au_dpri_file(file);
31855 + hlist_bl_unlock(files);
31859 + au_plevel = plevel;
31862 +/* ---------------------------------------------------------------------- */
31864 +/* module parameter */
31865 +static char *aufs_sysrq_key = "a";
31866 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31867 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31869 +static void au_sysrq(int key __maybe_unused)
31871 + struct au_sbinfo *sbinfo;
31872 + struct hlist_bl_node *pos;
31875 + au_sbilist_lock();
31876 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31877 + sysrq_sb(sbinfo->si_sb);
31878 + au_sbilist_unlock();
31882 +static struct sysrq_key_op au_sysrq_op = {
31883 + .handler = au_sysrq,
31884 + .help_msg = "Aufs",
31885 + .action_msg = "Aufs",
31886 + .enable_mask = SYSRQ_ENABLE_DUMP
31889 +/* ---------------------------------------------------------------------- */
31891 +int __init au_sysrq_init(void)
31897 + key = *aufs_sysrq_key;
31898 + if ('a' <= key && key <= 'z')
31899 + err = register_sysrq_key(key, &au_sysrq_op);
31900 + if (unlikely(err))
31901 + pr_err("err %d, sysrq=%c\n", err, key);
31905 +void au_sysrq_fin(void)
31909 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31910 + if (unlikely(err))
31911 + pr_err("err %d (ignored)\n", err);
31913 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31914 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31915 +++ linux/fs/aufs/vdir.c 2019-01-28 14:36:12.222418047 +0100
31917 +// SPDX-License-Identifier: GPL-2.0
31919 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31921 + * This program, aufs is free software; you can redistribute it and/or modify
31922 + * it under the terms of the GNU General Public License as published by
31923 + * the Free Software Foundation; either version 2 of the License, or
31924 + * (at your option) any later version.
31926 + * This program is distributed in the hope that it will be useful,
31927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31929 + * GNU General Public License for more details.
31931 + * You should have received a copy of the GNU General Public License
31932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31936 + * virtual or vertical directory
31941 +static unsigned int calc_size(int nlen)
31943 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31946 +static int set_deblk_end(union au_vdir_deblk_p *p,
31947 + union au_vdir_deblk_p *deblk_end)
31949 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31950 + p->de->de_str.len = 0;
31954 + return -1; /* error */
31957 +/* returns true or false */
31958 +static int is_deblk_end(union au_vdir_deblk_p *p,
31959 + union au_vdir_deblk_p *deblk_end)
31961 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31962 + return !p->de->de_str.len;
31966 +static unsigned char *last_deblk(struct au_vdir *vdir)
31968 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31971 +/* ---------------------------------------------------------------------- */
31973 +/* estimate the appropriate size for name hash table */
31974 +unsigned int au_rdhash_est(loff_t sz)
31982 + if (sz < AUFS_RDHASH_DEF)
31983 + n = AUFS_RDHASH_DEF;
31984 + /* pr_info("n %u\n", n); */
31989 + * the allocated memory has to be freed by
31990 + * au_nhash_wh_free() or au_nhash_de_free().
31992 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31994 + struct hlist_head *head;
31998 + sz = sizeof(*nhash->nh_head) * num_hash;
31999 + head = kmalloc(sz, gfp);
32001 + nhash->nh_num = num_hash;
32002 + nhash->nh_head = head;
32003 + for (u = 0; u < num_hash; u++)
32004 + INIT_HLIST_HEAD(head++);
32005 + return 0; /* success */
32011 +static void nhash_count(struct hlist_head *head)
32015 + struct hlist_node *pos;
32018 + hlist_for_each(pos, head)
32020 + pr_info("%lu\n", n);
32024 +static void au_nhash_wh_do_free(struct hlist_head *head)
32026 + struct au_vdir_wh *pos;
32027 + struct hlist_node *node;
32029 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32030 + au_kfree_rcu(pos);
32033 +static void au_nhash_de_do_free(struct hlist_head *head)
32035 + struct au_vdir_dehstr *pos;
32036 + struct hlist_node *node;
32038 + hlist_for_each_entry_safe(pos, node, head, hash)
32039 + au_cache_free_vdir_dehstr(pos);
32042 +static void au_nhash_do_free(struct au_nhash *nhash,
32043 + void (*free)(struct hlist_head *head))
32046 + struct hlist_head *head;
32048 + n = nhash->nh_num;
32052 + head = nhash->nh_head;
32053 + while (n-- > 0) {
32054 + nhash_count(head);
32057 + au_kfree_try_rcu(nhash->nh_head);
32060 +void au_nhash_wh_free(struct au_nhash *whlist)
32062 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32065 +static void au_nhash_de_free(struct au_nhash *delist)
32067 + au_nhash_do_free(delist, au_nhash_de_do_free);
32070 +/* ---------------------------------------------------------------------- */
32072 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32076 + unsigned int u, n;
32077 + struct hlist_head *head;
32078 + struct au_vdir_wh *pos;
32081 + n = whlist->nh_num;
32082 + head = whlist->nh_head;
32083 + for (u = 0; u < n; u++, head++)
32084 + hlist_for_each_entry(pos, head, wh_hash)
32085 + if (pos->wh_bindex == btgt && ++num > limit)
32090 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32091 + unsigned char *name,
32092 + unsigned int len)
32095 + /* const unsigned int magic_bit = 12; */
32097 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32104 + /* v = hash_long(v, magic_bit); */
32105 + v %= nhash->nh_num;
32106 + return nhash->nh_head + v;
32109 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32112 + return str->len == nlen && !memcmp(str->name, name, nlen);
32115 +/* returns found or not */
32116 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32118 + struct hlist_head *head;
32119 + struct au_vdir_wh *pos;
32120 + struct au_vdir_destr *str;
32122 + head = au_name_hash(whlist, name, nlen);
32123 + hlist_for_each_entry(pos, head, wh_hash) {
32124 + str = &pos->wh_str;
32125 + AuDbg("%.*s\n", str->len, str->name);
32126 + if (au_nhash_test_name(str, name, nlen))
32132 +/* returns found(true) or not */
32133 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32135 + struct hlist_head *head;
32136 + struct au_vdir_dehstr *pos;
32137 + struct au_vdir_destr *str;
32139 + head = au_name_hash(delist, name, nlen);
32140 + hlist_for_each_entry(pos, head, hash) {
32142 + AuDbg("%.*s\n", str->len, str->name);
32143 + if (au_nhash_test_name(str, name, nlen))
32149 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32150 + unsigned char d_type)
32152 +#ifdef CONFIG_AUFS_SHWH
32153 + wh->wh_ino = ino;
32154 + wh->wh_type = d_type;
32158 +/* ---------------------------------------------------------------------- */
32160 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32161 + unsigned int d_type, aufs_bindex_t bindex,
32162 + unsigned char shwh)
32165 + struct au_vdir_destr *str;
32166 + struct au_vdir_wh *wh;
32168 + AuDbg("%.*s\n", nlen, name);
32169 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32172 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32173 + if (unlikely(!wh))
32177 + wh->wh_bindex = bindex;
32179 + au_shwh_init_wh(wh, ino, d_type);
32180 + str = &wh->wh_str;
32182 + memcpy(str->name, name, nlen);
32183 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32190 +static int append_deblk(struct au_vdir *vdir)
32193 + unsigned long ul;
32194 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32195 + union au_vdir_deblk_p p, deblk_end;
32196 + unsigned char **o;
32199 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32200 + GFP_NOFS, /*may_shrink*/0);
32201 + if (unlikely(!o))
32204 + vdir->vd_deblk = o;
32205 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32207 + ul = vdir->vd_nblk++;
32208 + vdir->vd_deblk[ul] = p.deblk;
32209 + vdir->vd_last.ul = ul;
32210 + vdir->vd_last.p.deblk = p.deblk;
32211 + deblk_end.deblk = p.deblk + deblk_sz;
32212 + err = set_deblk_end(&p, &deblk_end);
32219 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32220 + unsigned int d_type, struct au_nhash *delist)
32224 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32225 + union au_vdir_deblk_p p, *room, deblk_end;
32226 + struct au_vdir_dehstr *dehstr;
32228 + p.deblk = last_deblk(vdir);
32229 + deblk_end.deblk = p.deblk + deblk_sz;
32230 + room = &vdir->vd_last.p;
32231 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32232 + || !is_deblk_end(room, &deblk_end));
32234 + sz = calc_size(nlen);
32235 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32236 + err = append_deblk(vdir);
32237 + if (unlikely(err))
32240 + p.deblk = last_deblk(vdir);
32241 + deblk_end.deblk = p.deblk + deblk_sz;
32243 + AuDebugOn(room->deblk != p.deblk);
32247 + dehstr = au_cache_alloc_vdir_dehstr();
32248 + if (unlikely(!dehstr))
32251 + dehstr->str = &room->de->de_str;
32252 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32253 + room->de->de_ino = ino;
32254 + room->de->de_type = d_type;
32255 + room->de->de_str.len = nlen;
32256 + memcpy(room->de->de_str.name, name, nlen);
32259 + room->deblk += sz;
32260 + if (unlikely(set_deblk_end(room, &deblk_end)))
32261 + err = append_deblk(vdir);
32268 +/* ---------------------------------------------------------------------- */
32270 +void au_vdir_free(struct au_vdir *vdir)
32272 + unsigned char **deblk;
32274 + deblk = vdir->vd_deblk;
32275 + while (vdir->vd_nblk--)
32276 + au_kfree_try_rcu(*deblk++);
32277 + au_kfree_try_rcu(vdir->vd_deblk);
32278 + au_cache_free_vdir(vdir);
32281 +static struct au_vdir *alloc_vdir(struct file *file)
32283 + struct au_vdir *vdir;
32284 + struct super_block *sb;
32287 + sb = file->f_path.dentry->d_sb;
32288 + SiMustAnyLock(sb);
32291 + vdir = au_cache_alloc_vdir();
32292 + if (unlikely(!vdir))
32295 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32296 + if (unlikely(!vdir->vd_deblk))
32299 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32300 + if (!vdir->vd_deblk_sz) {
32301 + /* estimate the appropriate size for deblk */
32302 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32303 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32305 + vdir->vd_nblk = 0;
32306 + vdir->vd_version = 0;
32307 + vdir->vd_jiffy = 0;
32308 + err = append_deblk(vdir);
32310 + return vdir; /* success */
32312 + au_kfree_try_rcu(vdir->vd_deblk);
32315 + au_cache_free_vdir(vdir);
32317 + vdir = ERR_PTR(err);
32321 +static int reinit_vdir(struct au_vdir *vdir)
32324 + union au_vdir_deblk_p p, deblk_end;
32326 + while (vdir->vd_nblk > 1) {
32327 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32328 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32331 + p.deblk = vdir->vd_deblk[0];
32332 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32333 + err = set_deblk_end(&p, &deblk_end);
32334 + /* keep vd_dblk_sz */
32335 + vdir->vd_last.ul = 0;
32336 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32337 + vdir->vd_version = 0;
32338 + vdir->vd_jiffy = 0;
32343 +/* ---------------------------------------------------------------------- */
32345 +#define AuFillVdir_CALLED 1
32346 +#define AuFillVdir_WHABLE (1 << 1)
32347 +#define AuFillVdir_SHWH (1 << 2)
32348 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32349 +#define au_fset_fillvdir(flags, name) \
32350 + do { (flags) |= AuFillVdir_##name; } while (0)
32351 +#define au_fclr_fillvdir(flags, name) \
32352 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32354 +#ifndef CONFIG_AUFS_SHWH
32355 +#undef AuFillVdir_SHWH
32356 +#define AuFillVdir_SHWH 0
32359 +struct fillvdir_arg {
32360 + struct dir_context ctx;
32361 + struct file *file;
32362 + struct au_vdir *vdir;
32363 + struct au_nhash delist;
32364 + struct au_nhash whlist;
32365 + aufs_bindex_t bindex;
32366 + unsigned int flags;
32370 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32371 + loff_t offset __maybe_unused, u64 h_ino,
32372 + unsigned int d_type)
32374 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32375 + char *name = (void *)__name;
32376 + struct super_block *sb;
32378 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32381 + sb = arg->file->f_path.dentry->d_sb;
32382 + au_fset_fillvdir(arg->flags, CALLED);
32384 + if (nlen <= AUFS_WH_PFX_LEN
32385 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32386 + if (test_known(&arg->delist, name, nlen)
32387 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32388 + goto out; /* already exists or whiteouted */
32390 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32392 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32393 + d_type = DT_UNKNOWN;
32394 + arg->err = append_de(arg->vdir, name, nlen, ino,
32395 + d_type, &arg->delist);
32397 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32398 + name += AUFS_WH_PFX_LEN;
32399 + nlen -= AUFS_WH_PFX_LEN;
32400 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32401 + goto out; /* already whiteouted */
32403 + ino = 0; /* just to suppress a warning */
32405 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32408 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32409 + d_type = DT_UNKNOWN;
32410 + arg->err = au_nhash_append_wh
32411 + (&arg->whlist, name, nlen, ino, d_type,
32412 + arg->bindex, shwh);
32418 + arg->vdir->vd_jiffy = jiffies;
32420 + AuTraceErr(arg->err);
32424 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32425 + struct au_nhash *whlist, struct au_nhash *delist)
32427 +#ifdef CONFIG_AUFS_SHWH
32429 + unsigned int nh, u;
32430 + struct hlist_head *head;
32431 + struct au_vdir_wh *pos;
32432 + struct hlist_node *n;
32434 + struct au_vdir_destr *destr;
32436 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32439 + o = p = (void *)__get_free_page(GFP_NOFS);
32440 + if (unlikely(!p))
32444 + nh = whlist->nh_num;
32445 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32446 + p += AUFS_WH_PFX_LEN;
32447 + for (u = 0; u < nh; u++) {
32448 + head = whlist->nh_head + u;
32449 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32450 + destr = &pos->wh_str;
32451 + memcpy(p, destr->name, destr->len);
32452 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32453 + pos->wh_ino, pos->wh_type, delist);
32454 + if (unlikely(err))
32459 + free_page((unsigned long)o);
32469 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32472 + unsigned int rdhash;
32474 + aufs_bindex_t bbot, bindex, btop;
32475 + unsigned char shwh;
32476 + struct file *hf, *file;
32477 + struct super_block *sb;
32479 + file = arg->file;
32480 + sb = file->f_path.dentry->d_sb;
32481 + SiMustAnyLock(sb);
32483 + rdhash = au_sbi(sb)->si_rdhash;
32485 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32486 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32487 + if (unlikely(err))
32489 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32490 + if (unlikely(err))
32496 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32498 + au_fset_fillvdir(arg->flags, SHWH);
32500 + btop = au_fbtop(file);
32501 + bbot = au_fbbot_dir(file);
32502 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32503 + hf = au_hf_dir(file, bindex);
32507 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32509 + if (unlikely(offset))
32512 + arg->bindex = bindex;
32513 + au_fclr_fillvdir(arg->flags, WHABLE);
32515 + || (bindex != bbot
32516 + && au_br_whable(au_sbr_perm(sb, bindex))))
32517 + au_fset_fillvdir(arg->flags, WHABLE);
32520 + au_fclr_fillvdir(arg->flags, CALLED);
32522 + err = vfsub_iterate_dir(hf, &arg->ctx);
32525 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32528 + * dir_relax() may be good for concurrency, but aufs should not
32529 + * use it since it will cause a lockdep problem.
32533 + if (!err && shwh)
32534 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32536 + au_nhash_wh_free(&arg->whlist);
32539 + au_nhash_de_free(&arg->delist);
32544 +static int read_vdir(struct file *file, int may_read)
32547 + unsigned long expire;
32548 + unsigned char do_read;
32549 + struct fillvdir_arg arg = {
32551 + .actor = fillvdir
32554 + struct inode *inode;
32555 + struct au_vdir *vdir, *allocated;
32558 + inode = file_inode(file);
32559 + IMustLock(inode);
32560 + IiMustWriteLock(inode);
32561 + SiMustAnyLock(inode->i_sb);
32563 + allocated = NULL;
32565 + expire = au_sbi(inode->i_sb)->si_rdcache;
32566 + vdir = au_ivdir(inode);
32569 + vdir = alloc_vdir(file);
32570 + err = PTR_ERR(vdir);
32571 + if (IS_ERR(vdir))
32574 + allocated = vdir;
32575 + } else if (may_read
32576 + && (!inode_eq_iversion(inode, vdir->vd_version)
32577 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32579 + err = reinit_vdir(vdir);
32580 + if (unlikely(err))
32585 + return 0; /* success */
32589 + err = au_do_read_vdir(&arg);
32591 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32592 + vdir->vd_version = inode_query_iversion(inode);
32593 + vdir->vd_last.ul = 0;
32594 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32596 + au_set_ivdir(inode, allocated);
32597 + } else if (allocated)
32598 + au_vdir_free(allocated);
32604 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32607 + unsigned long ul, n;
32608 + const unsigned int deblk_sz = src->vd_deblk_sz;
32610 + AuDebugOn(tgt->vd_nblk != 1);
32613 + if (tgt->vd_nblk < src->vd_nblk) {
32614 + unsigned char **p;
32616 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32617 + GFP_NOFS, /*may_shrink*/0);
32618 + if (unlikely(!p))
32620 + tgt->vd_deblk = p;
32623 + if (tgt->vd_deblk_sz != deblk_sz) {
32624 + unsigned char *p;
32626 + tgt->vd_deblk_sz = deblk_sz;
32627 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32628 + /*may_shrink*/1);
32629 + if (unlikely(!p))
32631 + tgt->vd_deblk[0] = p;
32633 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32634 + tgt->vd_version = src->vd_version;
32635 + tgt->vd_jiffy = src->vd_jiffy;
32637 + n = src->vd_nblk;
32638 + for (ul = 1; ul < n; ul++) {
32639 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32641 + if (unlikely(!tgt->vd_deblk[ul]))
32645 + tgt->vd_nblk = n;
32646 + tgt->vd_last.ul = tgt->vd_last.ul;
32647 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32648 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32649 + - src->vd_deblk[src->vd_last.ul];
32651 + return 0; /* success */
32654 + rerr = reinit_vdir(tgt);
32659 +int au_vdir_init(struct file *file)
32662 + struct inode *inode;
32663 + struct au_vdir *vdir_cache, *allocated;
32665 + /* test file->f_pos here instead of ctx->pos */
32666 + err = read_vdir(file, !file->f_pos);
32667 + if (unlikely(err))
32670 + allocated = NULL;
32671 + vdir_cache = au_fvdir_cache(file);
32672 + if (!vdir_cache) {
32673 + vdir_cache = alloc_vdir(file);
32674 + err = PTR_ERR(vdir_cache);
32675 + if (IS_ERR(vdir_cache))
32677 + allocated = vdir_cache;
32678 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32679 + /* test file->f_pos here instead of ctx->pos */
32680 + err = reinit_vdir(vdir_cache);
32681 + if (unlikely(err))
32684 + return 0; /* success */
32686 + inode = file_inode(file);
32687 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32689 + file->f_version = inode_query_iversion(inode);
32691 + au_set_fvdir_cache(file, allocated);
32692 + } else if (allocated)
32693 + au_vdir_free(allocated);
32699 +static loff_t calc_offset(struct au_vdir *vdir)
32702 + union au_vdir_deblk_p p;
32704 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32705 + offset = vdir->vd_last.p.deblk - p.deblk;
32706 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32710 +/* returns true or false */
32711 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32714 + unsigned int deblk_sz;
32715 + unsigned long ul, n;
32717 + union au_vdir_deblk_p p, deblk_end;
32718 + struct au_vdir *vdir_cache;
32721 + vdir_cache = au_fvdir_cache(file);
32722 + offset = calc_offset(vdir_cache);
32723 + AuDbg("offset %lld\n", offset);
32724 + if (ctx->pos == offset)
32727 + vdir_cache->vd_last.ul = 0;
32728 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32733 + deblk_sz = vdir_cache->vd_deblk_sz;
32734 + ul = div64_u64(ctx->pos, deblk_sz);
32735 + AuDbg("ul %lu\n", ul);
32736 + if (ul >= vdir_cache->vd_nblk)
32739 + n = vdir_cache->vd_nblk;
32740 + for (; ul < n; ul++) {
32741 + p.deblk = vdir_cache->vd_deblk[ul];
32742 + deblk_end.deblk = p.deblk + deblk_sz;
32744 + offset *= deblk_sz;
32745 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32748 + l = calc_size(p.de->de_str.len);
32752 + if (!is_deblk_end(&p, &deblk_end)) {
32754 + vdir_cache->vd_last.ul = ul;
32755 + vdir_cache->vd_last.p = p;
32763 + AuDbg("valid %d\n", !valid);
32767 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32769 + unsigned int l, deblk_sz;
32770 + union au_vdir_deblk_p deblk_end;
32771 + struct au_vdir *vdir_cache;
32772 + struct au_vdir_de *de;
32774 + if (!seek_vdir(file, ctx))
32777 + vdir_cache = au_fvdir_cache(file);
32778 + deblk_sz = vdir_cache->vd_deblk_sz;
32780 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32781 + deblk_end.deblk += deblk_sz;
32782 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32783 + de = vdir_cache->vd_last.p.de;
32784 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32785 + de->de_str.len, de->de_str.name, ctx->pos,
32786 + (unsigned long)de->de_ino, de->de_type);
32787 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32788 + de->de_str.len, de->de_ino,
32790 + /* todo: ignore the error caused by udba? */
32791 + /* return err; */
32795 + l = calc_size(de->de_str.len);
32796 + vdir_cache->vd_last.p.deblk += l;
32799 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32800 + vdir_cache->vd_last.ul++;
32801 + vdir_cache->vd_last.p.deblk
32802 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32803 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32812 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32813 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32814 +++ linux/fs/aufs/vfsub.c 2019-01-28 14:36:12.222418047 +0100
32816 +// SPDX-License-Identifier: GPL-2.0
32818 + * Copyright (C) 2005-2018 Junjiro R. Okajima
32820 + * This program, aufs is free software; you can redistribute it and/or modify
32821 + * it under the terms of the GNU General Public License as published by
32822 + * the Free Software Foundation; either version 2 of the License, or
32823 + * (at your option) any later version.
32825 + * This program is distributed in the hope that it will be useful,
32826 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32827 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32828 + * GNU General Public License for more details.
32830 + * You should have received a copy of the GNU General Public License
32831 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32835 + * sub-routines for VFS
32838 +#include <linux/mnt_namespace.h>
32839 +#include <linux/namei.h>
32840 +#include <linux/nsproxy.h>
32841 +#include <linux/security.h>
32842 +#include <linux/splice.h>
32845 +#ifdef CONFIG_AUFS_BR_FUSE
32846 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32848 + if (!au_test_fuse(h_sb) || !au_userns)
32851 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32855 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32860 + down_read(&h_sb->s_umount);
32861 + err = __sync_filesystem(h_sb, wait);
32862 + up_read(&h_sb->s_umount);
32868 +/* ---------------------------------------------------------------------- */
32870 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32874 + struct super_block *h_sb;
32876 + /* for remote fs, leave work for its getattr or d_revalidate */
32877 + /* for bad i_attr fs, handle them in aufs_getattr() */
32878 + /* still some fs may acquire i_mutex. we need to skip them */
32882 + h_sb = h_path->dentry->d_sb;
32883 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32885 + err = vfsub_getattr(h_path, &st);
32890 +/* ---------------------------------------------------------------------- */
32892 +struct file *vfsub_dentry_open(struct path *path, int flags)
32894 + struct file *file;
32896 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32898 + if (!IS_ERR_OR_NULL(file)
32899 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32900 + i_readcount_inc(d_inode(path->dentry));
32905 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32907 + struct file *file;
32910 + file = filp_open(path,
32911 + oflags /* | __FMODE_NONOTIFY */,
32914 + if (IS_ERR(file))
32916 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32923 + * Ideally this function should call VFS:do_last() in order to keep all its
32924 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32925 + * structure such as nameidata. This is a second (or third) best approach.
32926 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32928 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32929 + struct vfsub_aopen_args *args)
32932 + struct au_branch *br = args->br;
32933 + struct file *file = args->file;
32934 + /* copied from linux/fs/namei.c:atomic_open() */
32935 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32938 + AuDebugOn(!dir->i_op->atomic_open);
32940 + err = au_br_test_oflag(args->open_flag, br);
32941 + if (unlikely(err))
32944 + au_lcnt_inc(&br->br_nfiles);
32945 + file->f_path.dentry = DENTRY_NOT_SET;
32946 + file->f_path.mnt = au_br_mnt(br);
32947 + AuDbg("%ps\n", dir->i_op->atomic_open);
32948 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32949 + args->create_mode);
32950 + if (unlikely(err < 0)) {
32951 + au_lcnt_dec(&br->br_nfiles);
32955 + /* temporary workaround for nfsv4 branch */
32956 + if (au_test_nfs(dir->i_sb))
32957 + nfs_mark_for_revalidate(dir);
32959 + if (file->f_mode & FMODE_CREATED)
32960 + fsnotify_create(dir, dentry);
32961 + if (!(file->f_mode & FMODE_OPENED)) {
32962 + au_lcnt_dec(&br->br_nfiles);
32966 + /* todo: call VFS:may_open() here */
32967 + /* todo: ima_file_check() too? */
32968 + if (!err && (args->open_flag & __FMODE_EXEC))
32969 + err = deny_write_access(file);
32971 + fsnotify_open(file);
32973 + au_lcnt_dec(&br->br_nfiles);
32974 + /* note that the file is created and still opened */
32980 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32984 + err = kern_path(name, flags, path);
32985 + if (!err && d_is_positive(path->dentry))
32986 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32990 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32991 + struct dentry *parent, int len)
32993 + struct path path = {
32997 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32998 + if (IS_ERR(path.dentry))
33000 + if (d_is_positive(path.dentry))
33001 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33004 + AuTraceErrPtr(path.dentry);
33005 + return path.dentry;
33008 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33011 + struct path path = {
33015 + /* VFS checks it too, but by WARN_ON_ONCE() */
33016 + IMustLock(d_inode(parent));
33018 + path.dentry = lookup_one_len(name, parent, len);
33019 + if (IS_ERR(path.dentry))
33021 + if (d_is_positive(path.dentry))
33022 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33025 + AuTraceErrPtr(path.dentry);
33026 + return path.dentry;
33029 +void vfsub_call_lkup_one(void *args)
33031 + struct vfsub_lkup_one_args *a = args;
33032 + *a->errp = vfsub_lkup_one(a->name, a->parent);
33035 +/* ---------------------------------------------------------------------- */
33037 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33038 + struct dentry *d2, struct au_hinode *hdir2)
33040 + struct dentry *d;
33043 + d = lock_rename(d1, d2);
33045 + au_hn_suspend(hdir1);
33046 + if (hdir1 != hdir2)
33047 + au_hn_suspend(hdir2);
33052 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33053 + struct dentry *d2, struct au_hinode *hdir2)
33055 + au_hn_resume(hdir1);
33056 + if (hdir1 != hdir2)
33057 + au_hn_resume(hdir2);
33059 + unlock_rename(d1, d2);
33063 +/* ---------------------------------------------------------------------- */
33065 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33068 + struct dentry *d;
33072 + d = path->dentry;
33073 + path->dentry = d->d_parent;
33074 + err = security_path_mknod(path, d, mode, 0);
33075 + path->dentry = d;
33076 + if (unlikely(err))
33080 + err = vfs_create(dir, path->dentry, mode, want_excl);
33083 + struct path tmp = *path;
33086 + vfsub_update_h_iattr(&tmp, &did);
33088 + tmp.dentry = path->dentry->d_parent;
33089 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33098 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33101 + struct dentry *d;
33105 + d = path->dentry;
33106 + path->dentry = d->d_parent;
33107 + err = security_path_symlink(path, d, symname);
33108 + path->dentry = d;
33109 + if (unlikely(err))
33113 + err = vfs_symlink(dir, path->dentry, symname);
33116 + struct path tmp = *path;
33119 + vfsub_update_h_iattr(&tmp, &did);
33121 + tmp.dentry = path->dentry->d_parent;
33122 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33131 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33134 + struct dentry *d;
33138 + d = path->dentry;
33139 + path->dentry = d->d_parent;
33140 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33141 + path->dentry = d;
33142 + if (unlikely(err))
33146 + err = vfs_mknod(dir, path->dentry, mode, dev);
33149 + struct path tmp = *path;
33152 + vfsub_update_h_iattr(&tmp, &did);
33154 + tmp.dentry = path->dentry->d_parent;
33155 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33164 +static int au_test_nlink(struct inode *inode)
33166 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33168 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33169 + || inode->i_nlink < link_max)
33174 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33175 + struct inode **delegated_inode)
33178 + struct dentry *d;
33182 + err = au_test_nlink(d_inode(src_dentry));
33183 + if (unlikely(err))
33186 + /* we don't call may_linkat() */
33187 + d = path->dentry;
33188 + path->dentry = d->d_parent;
33189 + err = security_path_link(src_dentry, path, d);
33190 + path->dentry = d;
33191 + if (unlikely(err))
33195 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33198 + struct path tmp = *path;
33201 + /* fuse has different memory inode for the same inumber */
33202 + vfsub_update_h_iattr(&tmp, &did);
33204 + tmp.dentry = path->dentry->d_parent;
33205 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33206 + tmp.dentry = src_dentry;
33207 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33216 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33217 + struct inode *dir, struct path *path,
33218 + struct inode **delegated_inode, unsigned int flags)
33221 + struct path tmp = {
33224 + struct dentry *d;
33227 + IMustLock(src_dir);
33229 + d = path->dentry;
33230 + path->dentry = d->d_parent;
33231 + tmp.dentry = src_dentry->d_parent;
33232 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33233 + path->dentry = d;
33234 + if (unlikely(err))
33238 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33239 + delegated_inode, flags);
33244 + tmp.dentry = d->d_parent;
33245 + vfsub_update_h_iattr(&tmp, &did);
33247 + tmp.dentry = src_dentry;
33248 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33249 + tmp.dentry = src_dentry->d_parent;
33250 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33259 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33262 + struct dentry *d;
33266 + d = path->dentry;
33267 + path->dentry = d->d_parent;
33268 + err = security_path_mkdir(path, d, mode);
33269 + path->dentry = d;
33270 + if (unlikely(err))
33274 + err = vfs_mkdir(dir, path->dentry, mode);
33277 + struct path tmp = *path;
33280 + vfsub_update_h_iattr(&tmp, &did);
33282 + tmp.dentry = path->dentry->d_parent;
33283 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33292 +int vfsub_rmdir(struct inode *dir, struct path *path)
33295 + struct dentry *d;
33299 + d = path->dentry;
33300 + path->dentry = d->d_parent;
33301 + err = security_path_rmdir(path, d);
33302 + path->dentry = d;
33303 + if (unlikely(err))
33307 + err = vfs_rmdir(dir, path->dentry);
33310 + struct path tmp = {
33311 + .dentry = path->dentry->d_parent,
33315 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33322 +/* ---------------------------------------------------------------------- */
33324 +/* todo: support mmap_sem? */
33325 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33331 + err = vfs_read(file, ubuf, count, ppos);
33334 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33338 +/* todo: kernel_read()? */
33339 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33343 + mm_segment_t oldfs;
33350 + oldfs = get_fs();
33351 + set_fs(KERNEL_DS);
33352 + err = vfsub_read_u(file, buf.u, count, ppos);
33357 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33363 + err = vfs_write(file, ubuf, count, ppos);
33366 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33370 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33373 + mm_segment_t oldfs;
33376 + const char __user *u;
33380 + oldfs = get_fs();
33381 + set_fs(KERNEL_DS);
33382 + err = vfsub_write_u(file, buf.u, count, ppos);
33387 +int vfsub_flush(struct file *file, fl_owner_t id)
33392 + if (file->f_op->flush) {
33393 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33394 + err = file->f_op->flush(file, id);
33397 + err = file->f_op->flush(file, id);
33401 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33407 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33411 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33414 + err = iterate_dir(file, ctx);
33417 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33422 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33423 + struct pipe_inode_info *pipe, size_t len,
33424 + unsigned int flags)
33429 + err = do_splice_to(in, ppos, pipe, len, flags);
33431 + file_accessed(in);
33433 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33437 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33438 + loff_t *ppos, size_t len, unsigned int flags)
33443 + err = do_splice_from(pipe, out, ppos, len, flags);
33446 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33450 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33454 + /* file can be NULL */
33456 + err = vfs_fsync(file, datasync);
33460 + AuDebugOn(!file);
33461 + path = &file->f_path;
33463 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33468 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33469 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33470 + struct file *h_file)
33473 + struct inode *h_inode;
33474 + struct super_block *h_sb;
33477 + err = vfsub_truncate(h_path, length);
33481 + h_inode = d_inode(h_path->dentry);
33482 + h_sb = h_inode->i_sb;
33484 + sb_start_write(h_sb);
33486 + err = locks_verify_truncate(h_inode, h_file, length);
33488 + err = security_path_truncate(h_path);
33491 + err = do_truncate(h_path->dentry, length, attr, h_file);
33495 + sb_end_write(h_sb);
33502 +/* ---------------------------------------------------------------------- */
33504 +struct au_vfsub_mkdir_args {
33506 + struct inode *dir;
33507 + struct path *path;
33511 +static void au_call_vfsub_mkdir(void *args)
33513 + struct au_vfsub_mkdir_args *a = args;
33514 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33517 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33519 + int err, do_sio, wkq_err;
33521 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33524 + err = vfsub_mkdir(dir, path, mode);
33527 + struct au_vfsub_mkdir_args args = {
33533 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33534 + if (unlikely(wkq_err))
33541 +struct au_vfsub_rmdir_args {
33543 + struct inode *dir;
33544 + struct path *path;
33547 +static void au_call_vfsub_rmdir(void *args)
33549 + struct au_vfsub_rmdir_args *a = args;
33550 + *a->errp = vfsub_rmdir(a->dir, a->path);
33553 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33555 + int err, do_sio, wkq_err;
33557 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33560 + err = vfsub_rmdir(dir, path);
33563 + struct au_vfsub_rmdir_args args = {
33568 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33569 + if (unlikely(wkq_err))
33576 +/* ---------------------------------------------------------------------- */
33578 +struct notify_change_args {
33580 + struct path *path;
33581 + struct iattr *ia;
33582 + struct inode **delegated_inode;
33585 +static void call_notify_change(void *args)
33587 + struct notify_change_args *a = args;
33588 + struct inode *h_inode;
33590 + h_inode = d_inode(a->path->dentry);
33591 + IMustLock(h_inode);
33593 + *a->errp = -EPERM;
33594 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33596 + *a->errp = notify_change(a->path->dentry, a->ia,
33597 + a->delegated_inode);
33600 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33602 + AuTraceErr(*a->errp);
33605 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33606 + struct inode **delegated_inode)
33609 + struct notify_change_args args = {
33613 + .delegated_inode = delegated_inode
33616 + call_notify_change(&args);
33621 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33622 + struct inode **delegated_inode)
33624 + int err, wkq_err;
33625 + struct notify_change_args args = {
33629 + .delegated_inode = delegated_inode
33632 + wkq_err = au_wkq_wait(call_notify_change, &args);
33633 + if (unlikely(wkq_err))
33639 +/* ---------------------------------------------------------------------- */
33641 +struct unlink_args {
33643 + struct inode *dir;
33644 + struct path *path;
33645 + struct inode **delegated_inode;
33648 +static void call_unlink(void *args)
33650 + struct unlink_args *a = args;
33651 + struct dentry *d = a->path->dentry;
33652 + struct inode *h_inode;
33653 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33654 + && au_dcount(d) == 1);
33656 + IMustLock(a->dir);
33658 + a->path->dentry = d->d_parent;
33659 + *a->errp = security_path_unlink(a->path, d);
33660 + a->path->dentry = d;
33661 + if (unlikely(*a->errp))
33664 + if (!stop_sillyrename)
33667 + if (d_is_positive(d)) {
33668 + h_inode = d_inode(d);
33673 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33676 + struct path tmp = {
33677 + .dentry = d->d_parent,
33678 + .mnt = a->path->mnt
33680 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33683 + if (!stop_sillyrename)
33688 + AuTraceErr(*a->errp);
33692 + * @dir: must be locked.
33693 + * @dentry: target dentry.
33695 +int vfsub_unlink(struct inode *dir, struct path *path,
33696 + struct inode **delegated_inode, int force)
33699 + struct unlink_args args = {
33703 + .delegated_inode = delegated_inode
33707 + call_unlink(&args);
33711 + wkq_err = au_wkq_wait(call_unlink, &args);
33712 + if (unlikely(wkq_err))
33718 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33719 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33720 +++ linux/fs/aufs/vfsub.h 2019-01-28 14:36:12.222418047 +0100
33722 +/* SPDX-License-Identifier: GPL-2.0 */
33724 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33726 + * This program, aufs is free software; you can redistribute it and/or modify
33727 + * it under the terms of the GNU General Public License as published by
33728 + * the Free Software Foundation; either version 2 of the License, or
33729 + * (at your option) any later version.
33731 + * This program is distributed in the hope that it will be useful,
33732 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33733 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33734 + * GNU General Public License for more details.
33736 + * You should have received a copy of the GNU General Public License
33737 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33741 + * sub-routines for VFS
33744 +#ifndef __AUFS_VFSUB_H__
33745 +#define __AUFS_VFSUB_H__
33749 +#include <linux/fs.h>
33750 +#include <linux/iversion.h>
33751 +#include <linux/mount.h>
33752 +#include <linux/posix_acl.h>
33753 +#include <linux/xattr.h>
33754 +#include "debug.h"
33756 +/* copied from linux/fs/internal.h */
33757 +/* todo: BAD approach!! */
33758 +extern void __mnt_drop_write(struct vfsmount *);
33759 +extern struct file *alloc_empty_file(int, const struct cred *);
33761 +/* ---------------------------------------------------------------------- */
33763 +/* lock subclass for lower inode */
33764 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33765 +/* reduce? gave up. */
33767 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33768 + AuLsc_I_PARENT, /* lower inode, parent first */
33769 + AuLsc_I_PARENT2, /* copyup dirs */
33770 + AuLsc_I_PARENT3, /* copyup wh */
33776 +/* to debug easier, do not make them inlined functions */
33777 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33778 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33780 +/* ---------------------------------------------------------------------- */
33782 +static inline void vfsub_drop_nlink(struct inode *inode)
33784 + AuDebugOn(!inode->i_nlink);
33785 + drop_nlink(inode);
33788 +static inline void vfsub_dead_dir(struct inode *inode)
33790 + AuDebugOn(!S_ISDIR(inode->i_mode));
33791 + inode->i_flags |= S_DEAD;
33792 + clear_nlink(inode);
33795 +static inline int vfsub_native_ro(struct inode *inode)
33797 + return sb_rdonly(inode->i_sb)
33798 + || IS_RDONLY(inode)
33799 + /* || IS_APPEND(inode) */
33800 + || IS_IMMUTABLE(inode);
33803 +#ifdef CONFIG_AUFS_BR_FUSE
33804 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33806 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33809 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33811 +/* ---------------------------------------------------------------------- */
33813 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33814 +struct file *vfsub_dentry_open(struct path *path, int flags);
33815 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33817 +struct vfsub_aopen_args {
33818 + struct file *file;
33819 + unsigned int open_flag;
33820 + umode_t create_mode;
33821 + struct au_branch *br;
33823 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33824 + struct vfsub_aopen_args *args);
33825 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33827 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33828 + struct dentry *parent, int len);
33829 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33832 +struct vfsub_lkup_one_args {
33833 + struct dentry **errp;
33834 + struct qstr *name;
33835 + struct dentry *parent;
33838 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33839 + struct dentry *parent)
33841 + return vfsub_lookup_one_len(name->name, parent, name->len);
33844 +void vfsub_call_lkup_one(void *args);
33846 +/* ---------------------------------------------------------------------- */
33848 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33853 + err = mnt_want_write(mnt);
33858 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33861 + mnt_drop_write(mnt);
33865 +#if 0 /* reserved */
33866 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33869 + mnt_drop_write_file(file);
33874 +/* ---------------------------------------------------------------------- */
33877 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33878 + struct dentry *d2, struct au_hinode *hdir2);
33879 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33880 + struct dentry *d2, struct au_hinode *hdir2);
33882 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33884 +int vfsub_symlink(struct inode *dir, struct path *path,
33885 + const char *symname);
33886 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33887 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33888 + struct path *path, struct inode **delegated_inode);
33889 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33890 + struct inode *hdir, struct path *path,
33891 + struct inode **delegated_inode, unsigned int flags);
33892 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33893 +int vfsub_rmdir(struct inode *dir, struct path *path);
33895 +/* ---------------------------------------------------------------------- */
33897 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33899 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33901 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33903 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33905 +int vfsub_flush(struct file *file, fl_owner_t id);
33906 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33908 +static inline loff_t vfsub_f_size_read(struct file *file)
33910 + return i_size_read(file_inode(file));
33913 +static inline unsigned int vfsub_file_flags(struct file *file)
33915 + unsigned int flags;
33917 + spin_lock(&file->f_lock);
33918 + flags = file->f_flags;
33919 + spin_unlock(&file->f_lock);
33924 +static inline int vfsub_file_execed(struct file *file)
33926 + /* todo: direct access f_flags */
33927 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33930 +#if 0 /* reserved */
33931 +static inline void vfsub_file_accessed(struct file *h_file)
33933 + file_accessed(h_file);
33934 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33938 +#if 0 /* reserved */
33939 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33940 + struct dentry *h_dentry)
33942 + struct path h_path = {
33943 + .dentry = h_dentry,
33946 + touch_atime(&h_path);
33947 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33951 +static inline int vfsub_update_time(struct inode *h_inode,
33952 + struct timespec64 *ts, int flags)
33954 + return update_time(h_inode, ts, flags);
33955 + /* no vfsub_update_h_iattr() since we don't have struct path */
33958 +#ifdef CONFIG_FS_POSIX_ACL
33959 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33963 + err = posix_acl_chmod(h_inode, h_mode);
33964 + if (err == -EOPNOTSUPP)
33969 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33972 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33973 + struct pipe_inode_info *pipe, size_t len,
33974 + unsigned int flags);
33975 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33976 + loff_t *ppos, size_t len, unsigned int flags);
33978 +static inline long vfsub_truncate(struct path *path, loff_t length)
33983 + err = vfs_truncate(path, length);
33988 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33989 + struct file *h_file);
33990 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33993 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33996 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
34002 + err = vfs_clone_file_range(src, 0, dst, 0, len);
34008 +/* copy_file_range(2) is a systemcall */
34009 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34010 + struct file *dst, loff_t dst_pos,
34011 + size_t len, unsigned int flags)
34016 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34022 +/* ---------------------------------------------------------------------- */
34024 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34029 + err = vfs_llseek(file, offset, origin);
34034 +/* ---------------------------------------------------------------------- */
34036 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34037 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34038 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34039 + struct inode **delegated_inode);
34040 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34041 + struct inode **delegated_inode);
34042 +int vfsub_unlink(struct inode *dir, struct path *path,
34043 + struct inode **delegated_inode, int force);
34045 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34047 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34050 +/* ---------------------------------------------------------------------- */
34052 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
34053 + const void *value, size_t size, int flags)
34058 + err = vfs_setxattr(dentry, name, value, size, flags);
34064 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
34069 + err = vfs_removexattr(dentry, name);
34075 +#endif /* __KERNEL__ */
34076 +#endif /* __AUFS_VFSUB_H__ */
34077 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34078 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34079 +++ linux/fs/aufs/wbr_policy.c 2019-01-28 14:36:12.222418047 +0100
34081 +// SPDX-License-Identifier: GPL-2.0
34083 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34085 + * This program, aufs is free software; you can redistribute it and/or modify
34086 + * it under the terms of the GNU General Public License as published by
34087 + * the Free Software Foundation; either version 2 of the License, or
34088 + * (at your option) any later version.
34090 + * This program is distributed in the hope that it will be useful,
34091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34093 + * GNU General Public License for more details.
34095 + * You should have received a copy of the GNU General Public License
34096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34100 + * policies for selecting one among multiple writable branches
34103 +#include <linux/statfs.h>
34106 +/* subset of cpup_attr() */
34107 +static noinline_for_stack
34108 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34112 + struct inode *h_isrc;
34114 + h_isrc = d_inode(h_src);
34115 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34116 + ia.ia_mode = h_isrc->i_mode;
34117 + ia.ia_uid = h_isrc->i_uid;
34118 + ia.ia_gid = h_isrc->i_gid;
34119 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34120 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34121 + /* no delegation since it is just created */
34122 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34124 + /* is this nfs only? */
34125 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34126 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34127 + ia.ia_mode = h_isrc->i_mode;
34128 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34134 +#define AuCpdown_PARENT_OPQ 1
34135 +#define AuCpdown_WHED (1 << 1)
34136 +#define AuCpdown_MADE_DIR (1 << 2)
34137 +#define AuCpdown_DIROPQ (1 << 3)
34138 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34139 +#define au_fset_cpdown(flags, name) \
34140 + do { (flags) |= AuCpdown_##name; } while (0)
34141 +#define au_fclr_cpdown(flags, name) \
34142 + do { (flags) &= ~AuCpdown_##name; } while (0)
34144 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34145 + unsigned int *flags)
34148 + struct dentry *opq_dentry;
34150 + opq_dentry = au_diropq_create(dentry, bdst);
34151 + err = PTR_ERR(opq_dentry);
34152 + if (IS_ERR(opq_dentry))
34154 + dput(opq_dentry);
34155 + au_fset_cpdown(*flags, DIROPQ);
34161 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34162 + struct inode *dir, aufs_bindex_t bdst)
34165 + struct path h_path;
34166 + struct au_branch *br;
34168 + br = au_sbr(dentry->d_sb, bdst);
34169 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34170 + err = PTR_ERR(h_path.dentry);
34171 + if (IS_ERR(h_path.dentry))
34175 + if (d_is_positive(h_path.dentry)) {
34176 + h_path.mnt = au_br_mnt(br);
34177 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34180 + dput(h_path.dentry);
34186 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34187 + struct au_pin *pin,
34188 + struct dentry *h_parent, void *arg)
34191 + aufs_bindex_t bopq, btop;
34192 + struct path h_path;
34193 + struct dentry *parent;
34194 + struct inode *h_dir, *h_inode, *inode, *dir;
34195 + unsigned int *flags = arg;
34197 + btop = au_dbtop(dentry);
34198 + /* dentry is di-locked */
34199 + parent = dget_parent(dentry);
34200 + dir = d_inode(parent);
34201 + h_dir = d_inode(h_parent);
34202 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34203 + IMustLock(h_dir);
34205 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34206 + if (unlikely(err < 0))
34208 + h_path.dentry = au_h_dptr(dentry, bdst);
34209 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34210 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34211 + if (unlikely(err))
34213 + au_fset_cpdown(*flags, MADE_DIR);
34215 + bopq = au_dbdiropq(dentry);
34216 + au_fclr_cpdown(*flags, WHED);
34217 + au_fclr_cpdown(*flags, DIROPQ);
34218 + if (au_dbwh(dentry) == bdst)
34219 + au_fset_cpdown(*flags, WHED);
34220 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34221 + au_fset_cpdown(*flags, PARENT_OPQ);
34222 + h_inode = d_inode(h_path.dentry);
34223 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34224 + if (au_ftest_cpdown(*flags, WHED)) {
34225 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34226 + if (unlikely(err)) {
34227 + inode_unlock(h_inode);
34232 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34233 + inode_unlock(h_inode);
34234 + if (unlikely(err))
34237 + if (au_ftest_cpdown(*flags, WHED)) {
34238 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34239 + if (unlikely(err))
34243 + inode = d_inode(dentry);
34244 + if (au_ibbot(inode) < bdst)
34245 + au_set_ibbot(inode, bdst);
34246 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34247 + au_hi_flags(inode, /*isdir*/1));
34248 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34249 + goto out; /* success */
34253 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34254 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34255 + rerr = au_diropq_remove(dentry, bdst);
34256 + inode_unlock(h_inode);
34257 + if (unlikely(rerr)) {
34258 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34259 + dentry, bdst, rerr);
34265 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34266 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34267 + if (unlikely(rerr)) {
34268 + AuIOErr("failed removing %pd b%d (%d)\n",
34269 + dentry, bdst, rerr);
34274 + au_set_h_dptr(dentry, bdst, NULL);
34275 + if (au_dbbot(dentry) == bdst)
34276 + au_update_dbbot(dentry);
34282 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34285 + unsigned int flags;
34288 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34293 +/* ---------------------------------------------------------------------- */
34295 +/* policies for create */
34297 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34299 + int err, i, j, ndentry;
34300 + aufs_bindex_t bopq;
34301 + struct au_dcsub_pages dpages;
34302 + struct au_dpage *dpage;
34303 + struct dentry **dentries, *parent, *d;
34305 + err = au_dpages_init(&dpages, GFP_NOFS);
34306 + if (unlikely(err))
34308 + parent = dget_parent(dentry);
34309 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34310 + if (unlikely(err))
34314 + for (i = 0; i < dpages.ndpage; i++) {
34315 + dpage = dpages.dpages + i;
34316 + dentries = dpage->dentries;
34317 + ndentry = dpage->ndentry;
34318 + for (j = 0; j < ndentry; j++) {
34320 + di_read_lock_parent2(d, !AuLock_IR);
34321 + bopq = au_dbdiropq(d);
34322 + di_read_unlock(d, !AuLock_IR);
34323 + if (bopq >= 0 && bopq < err)
34330 + au_dpages_free(&dpages);
34335 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34337 + for (; bindex >= 0; bindex--)
34338 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34343 +/* top down parent */
34344 +static int au_wbr_create_tdp(struct dentry *dentry,
34345 + unsigned int flags __maybe_unused)
34348 + aufs_bindex_t btop, bindex;
34349 + struct super_block *sb;
34350 + struct dentry *parent, *h_parent;
34352 + sb = dentry->d_sb;
34353 + btop = au_dbtop(dentry);
34355 + if (!au_br_rdonly(au_sbr(sb, btop)))
34359 + parent = dget_parent(dentry);
34360 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34361 + h_parent = au_h_dptr(parent, bindex);
34362 + if (!h_parent || d_is_negative(h_parent))
34365 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34372 + /* bottom up here */
34373 + if (unlikely(err < 0)) {
34374 + err = au_wbr_bu(sb, btop - 1);
34376 + err = au_wbr_nonopq(dentry, err);
34380 + AuDbg("b%d\n", err);
34384 +/* ---------------------------------------------------------------------- */
34386 +/* an exception for the policy other than tdp */
34387 +static int au_wbr_create_exp(struct dentry *dentry)
34390 + aufs_bindex_t bwh, bdiropq;
34391 + struct dentry *parent;
34394 + bwh = au_dbwh(dentry);
34395 + parent = dget_parent(dentry);
34396 + bdiropq = au_dbdiropq(parent);
34398 + if (bdiropq >= 0)
34399 + err = min(bdiropq, bwh);
34402 + AuDbg("%d\n", err);
34403 + } else if (bdiropq >= 0) {
34405 + AuDbg("%d\n", err);
34410 + err = au_wbr_nonopq(dentry, err);
34412 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34415 + AuDbg("%d\n", err);
34419 +/* ---------------------------------------------------------------------- */
34422 +static int au_wbr_create_init_rr(struct super_block *sb)
34426 + err = au_wbr_bu(sb, au_sbbot(sb));
34427 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34430 + AuDbg("b%d\n", err);
34434 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34438 + aufs_bindex_t bindex, bbot;
34439 + struct super_block *sb;
34442 + err = au_wbr_create_exp(dentry);
34446 + sb = dentry->d_sb;
34447 + next = &au_sbi(sb)->si_wbr_rr_next;
34448 + bbot = au_sbbot(sb);
34450 + for (bindex = 0; bindex <= bbot; bindex++) {
34451 + if (!au_ftest_wbr(flags, DIR)) {
34452 + err = atomic_dec_return(next) + 1;
34453 + /* modulo for 0 is meaningless */
34454 + if (unlikely(!err))
34455 + err = atomic_dec_return(next) + 1;
34457 + err = atomic_read(next);
34458 + AuDbg("%d\n", err);
34461 + AuDbg("%d\n", err);
34462 + if (!au_br_rdonly(au_sbr(sb, err)))
34468 + err = au_wbr_nonopq(dentry, err);
34471 + AuDbg("%d\n", err);
34475 +/* ---------------------------------------------------------------------- */
34477 +/* most free space */
34478 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34480 + struct super_block *sb;
34481 + struct au_branch *br;
34482 + struct au_wbr_mfs *mfs;
34483 + struct dentry *h_parent;
34484 + aufs_bindex_t bindex, bbot;
34486 + unsigned long long b, bavail;
34487 + struct path h_path;
34488 + /* reduce the stack usage */
34489 + struct kstatfs *st;
34491 + st = kmalloc(sizeof(*st), GFP_NOFS);
34492 + if (unlikely(!st)) {
34493 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34498 + sb = dentry->d_sb;
34499 + mfs = &au_sbi(sb)->si_wbr_mfs;
34500 + MtxMustLock(&mfs->mfs_lock);
34501 + mfs->mfs_bindex = -EROFS;
34502 + mfs->mfsrr_bytes = 0;
34505 + bbot = au_sbbot(sb);
34507 + bindex = au_dbtop(parent);
34508 + bbot = au_dbtaildir(parent);
34511 + for (; bindex <= bbot; bindex++) {
34513 + h_parent = au_h_dptr(parent, bindex);
34514 + if (!h_parent || d_is_negative(h_parent))
34517 + br = au_sbr(sb, bindex);
34518 + if (au_br_rdonly(br))
34521 + /* sb->s_root for NFS is unreliable */
34522 + h_path.mnt = au_br_mnt(br);
34523 + h_path.dentry = h_path.mnt->mnt_root;
34524 + err = vfs_statfs(&h_path, st);
34525 + if (unlikely(err)) {
34526 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34530 + /* when the available size is equal, select the lower one */
34531 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34532 + || sizeof(b) < sizeof(st->f_bsize));
34533 + b = st->f_bavail * st->f_bsize;
34534 + br->br_wbr->wbr_bytes = b;
34535 + if (b >= bavail) {
34537 + mfs->mfs_bindex = bindex;
34538 + mfs->mfs_jiffy = jiffies;
34542 + mfs->mfsrr_bytes = bavail;
34543 + AuDbg("b%d\n", mfs->mfs_bindex);
34544 + au_kfree_rcu(st);
34547 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34550 + struct dentry *parent;
34551 + struct super_block *sb;
34552 + struct au_wbr_mfs *mfs;
34554 + err = au_wbr_create_exp(dentry);
34558 + sb = dentry->d_sb;
34560 + if (au_ftest_wbr(flags, PARENT))
34561 + parent = dget_parent(dentry);
34562 + mfs = &au_sbi(sb)->si_wbr_mfs;
34563 + mutex_lock(&mfs->mfs_lock);
34564 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34565 + || mfs->mfs_bindex < 0
34566 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34567 + au_mfs(dentry, parent);
34568 + mutex_unlock(&mfs->mfs_lock);
34569 + err = mfs->mfs_bindex;
34573 + err = au_wbr_nonopq(dentry, err);
34576 + AuDbg("b%d\n", err);
34580 +static int au_wbr_create_init_mfs(struct super_block *sb)
34582 + struct au_wbr_mfs *mfs;
34584 + mfs = &au_sbi(sb)->si_wbr_mfs;
34585 + mutex_init(&mfs->mfs_lock);
34586 + mfs->mfs_jiffy = 0;
34587 + mfs->mfs_bindex = -EROFS;
34592 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34594 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34598 +/* ---------------------------------------------------------------------- */
34600 +/* top down regardless parent, and then mfs */
34601 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34602 + unsigned int flags __maybe_unused)
34605 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34606 + unsigned long long watermark;
34607 + struct super_block *sb;
34608 + struct au_wbr_mfs *mfs;
34609 + struct au_branch *br;
34610 + struct dentry *parent;
34612 + sb = dentry->d_sb;
34613 + mfs = &au_sbi(sb)->si_wbr_mfs;
34614 + mutex_lock(&mfs->mfs_lock);
34615 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34616 + || mfs->mfs_bindex < 0)
34617 + au_mfs(dentry, /*parent*/NULL);
34618 + watermark = mfs->mfsrr_watermark;
34619 + bmfs = mfs->mfs_bindex;
34620 + mutex_unlock(&mfs->mfs_lock);
34622 + /* another style of au_wbr_create_exp() */
34623 + bwh = au_dbwh(dentry);
34624 + parent = dget_parent(dentry);
34625 + btail = au_dbtaildir(parent);
34626 + if (bwh >= 0 && bwh < btail)
34629 + err = au_wbr_nonopq(dentry, btail);
34630 + if (unlikely(err < 0))
34634 + for (bindex = 0; bindex <= btail; bindex++) {
34635 + br = au_sbr(sb, bindex);
34636 + if (au_br_rdonly(br))
34638 + if (br->br_wbr->wbr_bytes > watermark) {
34649 + AuDbg("b%d\n", err);
34653 +/* ---------------------------------------------------------------------- */
34655 +/* most free space and then round robin */
34656 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34659 + struct au_wbr_mfs *mfs;
34661 + err = au_wbr_create_mfs(dentry, flags);
34663 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34664 + mutex_lock(&mfs->mfs_lock);
34665 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34666 + err = au_wbr_create_rr(dentry, flags);
34667 + mutex_unlock(&mfs->mfs_lock);
34670 + AuDbg("b%d\n", err);
34674 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34678 + au_wbr_create_init_mfs(sb); /* ignore */
34679 + err = au_wbr_create_init_rr(sb);
34684 +/* ---------------------------------------------------------------------- */
34686 +/* top down parent and most free space */
34687 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34690 + unsigned long long b;
34691 + aufs_bindex_t bindex, btop, bbot;
34692 + struct super_block *sb;
34693 + struct dentry *parent, *h_parent;
34694 + struct au_branch *br;
34696 + err = au_wbr_create_tdp(dentry, flags);
34697 + if (unlikely(err < 0))
34699 + parent = dget_parent(dentry);
34700 + btop = au_dbtop(parent);
34701 + bbot = au_dbtaildir(parent);
34702 + if (btop == bbot)
34703 + goto out_parent; /* success */
34705 + e2 = au_wbr_create_mfs(dentry, flags);
34707 + goto out_parent; /* success */
34709 + /* when the available size is equal, select upper one */
34710 + sb = dentry->d_sb;
34711 + br = au_sbr(sb, err);
34712 + b = br->br_wbr->wbr_bytes;
34713 + AuDbg("b%d, %llu\n", err, b);
34715 + for (bindex = btop; bindex <= bbot; bindex++) {
34716 + h_parent = au_h_dptr(parent, bindex);
34717 + if (!h_parent || d_is_negative(h_parent))
34720 + br = au_sbr(sb, bindex);
34721 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34722 + b = br->br_wbr->wbr_bytes;
34724 + AuDbg("b%d, %llu\n", err, b);
34729 + err = au_wbr_nonopq(dentry, err);
34734 + AuDbg("b%d\n", err);
34738 +/* ---------------------------------------------------------------------- */
34741 + * - top down parent
34742 + * - most free space with parent
34743 + * - most free space round-robin regardless parent
34745 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34748 + unsigned long long watermark;
34749 + struct super_block *sb;
34750 + struct au_branch *br;
34751 + struct au_wbr_mfs *mfs;
34753 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34754 + if (unlikely(err < 0))
34757 + sb = dentry->d_sb;
34758 + br = au_sbr(sb, err);
34759 + mfs = &au_sbi(sb)->si_wbr_mfs;
34760 + mutex_lock(&mfs->mfs_lock);
34761 + watermark = mfs->mfsrr_watermark;
34762 + mutex_unlock(&mfs->mfs_lock);
34763 + if (br->br_wbr->wbr_bytes < watermark)
34764 + /* regardless the parent dir */
34765 + err = au_wbr_create_mfsrr(dentry, flags);
34768 + AuDbg("b%d\n", err);
34772 +/* ---------------------------------------------------------------------- */
34774 +/* policies for copyup */
34776 +/* top down parent */
34777 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34779 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34782 +/* bottom up parent */
34783 +static int au_wbr_copyup_bup(struct dentry *dentry)
34786 + aufs_bindex_t bindex, btop;
34787 + struct dentry *parent, *h_parent;
34788 + struct super_block *sb;
34791 + sb = dentry->d_sb;
34792 + parent = dget_parent(dentry);
34793 + btop = au_dbtop(parent);
34794 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34795 + h_parent = au_h_dptr(parent, bindex);
34796 + if (!h_parent || d_is_negative(h_parent))
34799 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34806 + /* bottom up here */
34807 + if (unlikely(err < 0))
34808 + err = au_wbr_bu(sb, btop - 1);
34810 + AuDbg("b%d\n", err);
34815 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34819 + err = au_wbr_bu(dentry->d_sb, btop);
34820 + AuDbg("b%d\n", err);
34822 + err = au_wbr_nonopq(dentry, err);
34824 + AuDbg("b%d\n", err);
34828 +static int au_wbr_copyup_bu(struct dentry *dentry)
34831 + aufs_bindex_t btop;
34833 + btop = au_dbtop(dentry);
34834 + err = au_wbr_do_copyup_bu(dentry, btop);
34838 +/* ---------------------------------------------------------------------- */
34840 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34841 + [AuWbrCopyup_TDP] = {
34842 + .copyup = au_wbr_copyup_tdp
34844 + [AuWbrCopyup_BUP] = {
34845 + .copyup = au_wbr_copyup_bup
34847 + [AuWbrCopyup_BU] = {
34848 + .copyup = au_wbr_copyup_bu
34852 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34853 + [AuWbrCreate_TDP] = {
34854 + .create = au_wbr_create_tdp
34856 + [AuWbrCreate_RR] = {
34857 + .create = au_wbr_create_rr,
34858 + .init = au_wbr_create_init_rr
34860 + [AuWbrCreate_MFS] = {
34861 + .create = au_wbr_create_mfs,
34862 + .init = au_wbr_create_init_mfs,
34863 + .fin = au_wbr_create_fin_mfs
34865 + [AuWbrCreate_MFSV] = {
34866 + .create = au_wbr_create_mfs,
34867 + .init = au_wbr_create_init_mfs,
34868 + .fin = au_wbr_create_fin_mfs
34870 + [AuWbrCreate_MFSRR] = {
34871 + .create = au_wbr_create_mfsrr,
34872 + .init = au_wbr_create_init_mfsrr,
34873 + .fin = au_wbr_create_fin_mfs
34875 + [AuWbrCreate_MFSRRV] = {
34876 + .create = au_wbr_create_mfsrr,
34877 + .init = au_wbr_create_init_mfsrr,
34878 + .fin = au_wbr_create_fin_mfs
34880 + [AuWbrCreate_TDMFS] = {
34881 + .create = au_wbr_create_tdmfs,
34882 + .init = au_wbr_create_init_mfs,
34883 + .fin = au_wbr_create_fin_mfs
34885 + [AuWbrCreate_TDMFSV] = {
34886 + .create = au_wbr_create_tdmfs,
34887 + .init = au_wbr_create_init_mfs,
34888 + .fin = au_wbr_create_fin_mfs
34890 + [AuWbrCreate_PMFS] = {
34891 + .create = au_wbr_create_pmfs,
34892 + .init = au_wbr_create_init_mfs,
34893 + .fin = au_wbr_create_fin_mfs
34895 + [AuWbrCreate_PMFSV] = {
34896 + .create = au_wbr_create_pmfs,
34897 + .init = au_wbr_create_init_mfs,
34898 + .fin = au_wbr_create_fin_mfs
34900 + [AuWbrCreate_PMFSRR] = {
34901 + .create = au_wbr_create_pmfsrr,
34902 + .init = au_wbr_create_init_mfsrr,
34903 + .fin = au_wbr_create_fin_mfs
34905 + [AuWbrCreate_PMFSRRV] = {
34906 + .create = au_wbr_create_pmfsrr,
34907 + .init = au_wbr_create_init_mfsrr,
34908 + .fin = au_wbr_create_fin_mfs
34911 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34912 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34913 +++ linux/fs/aufs/whout.c 2019-01-28 14:36:12.222418047 +0100
34915 +// SPDX-License-Identifier: GPL-2.0
34917 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34919 + * This program, aufs is free software; you can redistribute it and/or modify
34920 + * it under the terms of the GNU General Public License as published by
34921 + * the Free Software Foundation; either version 2 of the License, or
34922 + * (at your option) any later version.
34924 + * This program is distributed in the hope that it will be useful,
34925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34927 + * GNU General Public License for more details.
34929 + * You should have received a copy of the GNU General Public License
34930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34934 + * whiteout for logical deletion and opaque directory
34939 +#define WH_MASK 0444
34942 + * If a directory contains this file, then it is opaque. We start with the
34943 + * .wh. flag so that it is blocked by lookup.
34945 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34946 + sizeof(AUFS_WH_DIROPQ) - 1);
34949 + * generate whiteout name, which is NOT terminated by NULL.
34950 + * @name: original d_name.name
34951 + * @len: original d_name.len
34952 + * @wh: whiteout qstr
34953 + * returns zero when succeeds, otherwise error.
34954 + * succeeded value as wh->name should be freed by kfree().
34956 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34960 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34961 + return -ENAMETOOLONG;
34963 + wh->len = name->len + AUFS_WH_PFX_LEN;
34964 + p = kmalloc(wh->len, GFP_NOFS);
34967 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34968 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34975 +/* ---------------------------------------------------------------------- */
34978 + * test if the @wh_name exists under @h_parent.
34979 + * @try_sio specifies the necessary of super-io.
34981 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34984 + struct dentry *wh_dentry;
34987 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34989 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34990 + err = PTR_ERR(wh_dentry);
34991 + if (IS_ERR(wh_dentry)) {
34992 + if (err == -ENAMETOOLONG)
34998 + if (d_is_negative(wh_dentry))
34999 + goto out_wh; /* success */
35002 + if (d_is_reg(wh_dentry))
35003 + goto out_wh; /* success */
35006 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35007 + wh_dentry, d_inode(wh_dentry)->i_mode);
35016 + * test if the @h_dentry sets opaque or not.
35018 +int au_diropq_test(struct dentry *h_dentry)
35021 + struct inode *h_dir;
35023 + h_dir = d_inode(h_dentry);
35024 + err = au_wh_test(h_dentry, &diropq_name,
35025 + au_test_h_perm_sio(h_dir, MAY_EXEC));
35030 + * returns a negative dentry whose name is unique and temporary.
35032 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35033 + struct qstr *prefix)
35035 + struct dentry *dentry;
35037 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35039 + /* strict atomic_t is unnecessary here */
35040 + static unsigned short cnt;
35043 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35046 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35047 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35048 + dentry = ERR_PTR(-ENAMETOOLONG);
35049 + if (unlikely(qs.len > NAME_MAX))
35051 + dentry = ERR_PTR(-ENOMEM);
35052 + name = kmalloc(qs.len + 1, GFP_NOFS);
35053 + if (unlikely(!name))
35057 + /* doubly whiteout-ed */
35058 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35059 + p = name + AUFS_WH_PFX_LEN * 2;
35060 + memcpy(p, prefix->name, prefix->len);
35061 + p += prefix->len;
35063 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35066 + for (i = 0; i < 3; i++) {
35067 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35068 + dentry = au_sio_lkup_one(&qs, h_parent);
35069 + if (IS_ERR(dentry) || d_is_negative(dentry))
35073 + /* pr_warn("could not get random name\n"); */
35074 + dentry = ERR_PTR(-EEXIST);
35075 + AuDbg("%.*s\n", AuLNPair(&qs));
35079 + if (name != defname)
35080 + au_kfree_try_rcu(name);
35082 + AuTraceErrPtr(dentry);
35087 + * rename the @h_dentry on @br to the whiteouted temporary name.
35089 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35092 + struct path h_path = {
35093 + .mnt = au_br_mnt(br)
35095 + struct inode *h_dir, *delegated;
35096 + struct dentry *h_parent;
35098 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35099 + h_dir = d_inode(h_parent);
35100 + IMustLock(h_dir);
35102 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35103 + err = PTR_ERR(h_path.dentry);
35104 + if (IS_ERR(h_path.dentry))
35107 + /* under the same dir, no need to lock_rename() */
35108 + delegated = NULL;
35109 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35112 + if (unlikely(err == -EWOULDBLOCK)) {
35113 + pr_warn("cannot retry for NFSv4 delegation"
35114 + " for an internal rename\n");
35117 + dput(h_path.dentry);
35124 +/* ---------------------------------------------------------------------- */
35126 + * functions for removing a whiteout
35129 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35132 + struct inode *delegated;
35135 + * forces superio when the dir has a sticky bit.
35136 + * this may be a violation of unix fs semantics.
35138 + force = (h_dir->i_mode & S_ISVTX)
35139 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35140 + delegated = NULL;
35141 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35142 + if (unlikely(err == -EWOULDBLOCK)) {
35143 + pr_warn("cannot retry for NFSv4 delegation"
35144 + " for an internal unlink\n");
35150 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35151 + struct dentry *dentry)
35155 + err = do_unlink_wh(h_dir, h_path);
35156 + if (!err && dentry)
35157 + au_set_dbwh(dentry, -1);
35162 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35163 + struct au_branch *br)
35166 + struct path h_path = {
35167 + .mnt = au_br_mnt(br)
35171 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35172 + if (IS_ERR(h_path.dentry))
35173 + err = PTR_ERR(h_path.dentry);
35175 + if (d_is_reg(h_path.dentry))
35176 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35177 + dput(h_path.dentry);
35183 +/* ---------------------------------------------------------------------- */
35185 + * initialize/clean whiteout for a branch
35188 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35192 + struct inode *delegated;
35194 + if (d_is_negative(whpath->dentry))
35198 + err = vfsub_rmdir(h_dir, whpath);
35200 + delegated = NULL;
35201 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35202 + if (unlikely(err == -EWOULDBLOCK)) {
35203 + pr_warn("cannot retry for NFSv4 delegation"
35204 + " for an internal unlink\n");
35208 + if (unlikely(err))
35209 + pr_warn("failed removing %pd (%d), ignored.\n",
35210 + whpath->dentry, err);
35213 +static int test_linkable(struct dentry *h_root)
35215 + struct inode *h_dir = d_inode(h_root);
35217 + if (h_dir->i_op->link)
35220 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35221 + h_root, au_sbtype(h_root->d_sb));
35225 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35226 +static int au_whdir(struct inode *h_dir, struct path *path)
35231 + if (d_is_negative(path->dentry)) {
35234 + if (au_test_nfs(path->dentry->d_sb))
35236 + err = vfsub_mkdir(h_dir, path, mode);
35237 + } else if (d_is_dir(path->dentry))
35240 + pr_err("unknown %pd exists\n", path->dentry);
35245 +struct au_wh_base {
35246 + const struct qstr *name;
35247 + struct dentry *dentry;
35250 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35251 + struct path *h_path)
35253 + h_path->dentry = base[AuBrWh_BASE].dentry;
35254 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35255 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35256 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35257 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35258 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35262 + * returns tri-state,
35263 + * minus: error, caller should print the message
35265 + * plus: error, caller should NOT print the message
35267 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35268 + int do_plink, struct au_wh_base base[],
35269 + struct path *h_path)
35272 + struct inode *h_dir;
35274 + h_dir = d_inode(h_root);
35275 + h_path->dentry = base[AuBrWh_BASE].dentry;
35276 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35277 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35279 + err = test_linkable(h_root);
35280 + if (unlikely(err)) {
35285 + err = au_whdir(h_dir, h_path);
35286 + if (unlikely(err))
35288 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35290 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35291 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35292 + err = au_whdir(h_dir, h_path);
35293 + if (unlikely(err))
35295 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35302 + * for the moment, aufs supports the branch filesystem which does not support
35303 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35304 + * copyup failed. finally, such filesystem will not be used as the writable
35307 + * returns tri-state, see above.
35309 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35310 + int do_plink, struct au_wh_base base[],
35311 + struct path *h_path)
35314 + struct inode *h_dir;
35316 + WbrWhMustWriteLock(wbr);
35318 + err = test_linkable(h_root);
35319 + if (unlikely(err)) {
35325 + * todo: should this create be done in /sbin/mount.aufs helper?
35328 + h_dir = d_inode(h_root);
35329 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35330 + h_path->dentry = base[AuBrWh_BASE].dentry;
35331 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35332 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35335 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35336 + if (unlikely(err))
35339 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35341 + err = au_whdir(h_dir, h_path);
35342 + if (unlikely(err))
35344 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35346 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35347 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35349 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35350 + err = au_whdir(h_dir, h_path);
35351 + if (unlikely(err))
35353 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35360 + * initialize the whiteout base file/dir for @br.
35362 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35365 + const unsigned char do_plink
35366 + = !!au_opt_test(au_mntflags(sb), PLINK);
35367 + struct inode *h_dir;
35368 + struct path path = br->br_path;
35369 + struct dentry *h_root = path.dentry;
35370 + struct au_wbr *wbr = br->br_wbr;
35371 + static const struct qstr base_name[] = {
35372 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35373 + sizeof(AUFS_BASE_NAME) - 1),
35374 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35375 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35376 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35377 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35379 + struct au_wh_base base[] = {
35380 + [AuBrWh_BASE] = {
35381 + .name = base_name + AuBrWh_BASE,
35384 + [AuBrWh_PLINK] = {
35385 + .name = base_name + AuBrWh_PLINK,
35388 + [AuBrWh_ORPH] = {
35389 + .name = base_name + AuBrWh_ORPH,
35395 + WbrWhMustWriteLock(wbr);
35397 + for (i = 0; i < AuBrWh_Last; i++) {
35398 + /* doubly whiteouted */
35399 + struct dentry *d;
35401 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35402 + err = PTR_ERR(d);
35406 + base[i].dentry = d;
35408 + && wbr->wbr_wh[i]
35409 + && wbr->wbr_wh[i] != base[i].dentry);
35413 + for (i = 0; i < AuBrWh_Last; i++) {
35414 + dput(wbr->wbr_wh[i]);
35415 + wbr->wbr_wh[i] = NULL;
35419 + if (!au_br_writable(br->br_perm)) {
35420 + h_dir = d_inode(h_root);
35421 + au_wh_init_ro(h_dir, base, &path);
35422 + } else if (!au_br_wh_linkable(br->br_perm)) {
35423 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35429 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35435 + goto out; /* success */
35438 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35439 + err, h_root, au_sbtype(h_root->d_sb));
35441 + for (i = 0; i < AuBrWh_Last; i++)
35442 + dput(base[i].dentry);
35446 +/* ---------------------------------------------------------------------- */
35448 + * whiteouts are all hard-linked usually.
35449 + * when its link count reaches a ceiling, we create a new whiteout base
35450 + * asynchronously.
35453 +struct reinit_br_wh {
35454 + struct super_block *sb;
35455 + struct au_branch *br;
35458 +static void reinit_br_wh(void *arg)
35461 + aufs_bindex_t bindex;
35462 + struct path h_path;
35463 + struct reinit_br_wh *a = arg;
35464 + struct au_wbr *wbr;
35465 + struct inode *dir, *delegated;
35466 + struct dentry *h_root;
35467 + struct au_hinode *hdir;
35470 + wbr = a->br->br_wbr;
35471 + /* big aufs lock */
35472 + si_noflush_write_lock(a->sb);
35473 + if (!au_br_writable(a->br->br_perm))
35475 + bindex = au_br_index(a->sb, a->br->br_id);
35476 + if (unlikely(bindex < 0))
35479 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35480 + dir = d_inode(a->sb->s_root);
35481 + hdir = au_hi(dir, bindex);
35482 + h_root = au_h_dptr(a->sb->s_root, bindex);
35483 + AuDebugOn(h_root != au_br_dentry(a->br));
35485 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35486 + wbr_wh_write_lock(wbr);
35487 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35490 + h_path.dentry = wbr->wbr_whbase;
35491 + h_path.mnt = au_br_mnt(a->br);
35492 + delegated = NULL;
35493 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35495 + if (unlikely(err == -EWOULDBLOCK)) {
35496 + pr_warn("cannot retry for NFSv4 delegation"
35497 + " for an internal unlink\n");
35501 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35504 + dput(wbr->wbr_whbase);
35505 + wbr->wbr_whbase = NULL;
35507 + err = au_wh_init(a->br, a->sb);
35508 + wbr_wh_write_unlock(wbr);
35509 + au_hn_inode_unlock(hdir);
35510 + di_read_unlock(a->sb->s_root, AuLock_IR);
35512 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35516 + atomic_dec(&wbr->wbr_wh_running);
35517 + au_lcnt_dec(&a->br->br_count);
35518 + si_write_unlock(a->sb);
35519 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35521 + if (unlikely(err))
35522 + AuIOErr("err %d\n", err);
35525 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35527 + int do_dec, wkq_err;
35528 + struct reinit_br_wh *arg;
35531 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35534 + /* ignore ENOMEM */
35535 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35538 + * dec(wh_running), kfree(arg) and dec(br_count)
35539 + * in reinit function
35543 + au_lcnt_inc(&br->br_count);
35544 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35545 + if (unlikely(wkq_err)) {
35546 + atomic_dec(&br->br_wbr->wbr_wh_running);
35547 + au_lcnt_dec(&br->br_count);
35548 + au_kfree_rcu(arg);
35555 + atomic_dec(&br->br_wbr->wbr_wh_running);
35558 +/* ---------------------------------------------------------------------- */
35561 + * create the whiteout @wh.
35563 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35564 + struct dentry *wh)
35567 + struct path h_path = {
35570 + struct au_branch *br;
35571 + struct au_wbr *wbr;
35572 + struct dentry *h_parent;
35573 + struct inode *h_dir, *delegated;
35575 + h_parent = wh->d_parent; /* dir inode is locked */
35576 + h_dir = d_inode(h_parent);
35577 + IMustLock(h_dir);
35579 + br = au_sbr(sb, bindex);
35580 + h_path.mnt = au_br_mnt(br);
35581 + wbr = br->br_wbr;
35582 + wbr_wh_read_lock(wbr);
35583 + if (wbr->wbr_whbase) {
35584 + delegated = NULL;
35585 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35586 + if (unlikely(err == -EWOULDBLOCK)) {
35587 + pr_warn("cannot retry for NFSv4 delegation"
35588 + " for an internal link\n");
35591 + if (!err || err != -EMLINK)
35594 + /* link count full. re-initialize br_whbase. */
35595 + kick_reinit_br_wh(sb, br);
35598 + /* return this error in this context */
35599 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35601 + au_fhsm_wrote(sb, bindex, /*force*/0);
35604 + wbr_wh_read_unlock(wbr);
35608 +/* ---------------------------------------------------------------------- */
35611 + * create or remove the diropq.
35613 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35614 + unsigned int flags)
35616 + struct dentry *opq_dentry, *h_dentry;
35617 + struct super_block *sb;
35618 + struct au_branch *br;
35621 + sb = dentry->d_sb;
35622 + br = au_sbr(sb, bindex);
35623 + h_dentry = au_h_dptr(dentry, bindex);
35624 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35625 + if (IS_ERR(opq_dentry))
35628 + if (au_ftest_diropq(flags, CREATE)) {
35629 + err = link_or_create_wh(sb, bindex, opq_dentry);
35631 + au_set_dbdiropq(dentry, bindex);
35632 + goto out; /* success */
35635 + struct path tmp = {
35636 + .dentry = opq_dentry,
35637 + .mnt = au_br_mnt(br)
35639 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35641 + au_set_dbdiropq(dentry, -1);
35643 + dput(opq_dentry);
35644 + opq_dentry = ERR_PTR(err);
35647 + return opq_dentry;
35650 +struct do_diropq_args {
35651 + struct dentry **errp;
35652 + struct dentry *dentry;
35653 + aufs_bindex_t bindex;
35654 + unsigned int flags;
35657 +static void call_do_diropq(void *args)
35659 + struct do_diropq_args *a = args;
35660 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35663 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35664 + unsigned int flags)
35666 + struct dentry *diropq, *h_dentry;
35668 + h_dentry = au_h_dptr(dentry, bindex);
35669 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35670 + diropq = do_diropq(dentry, bindex, flags);
35673 + struct do_diropq_args args = {
35675 + .dentry = dentry,
35676 + .bindex = bindex,
35680 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35681 + if (unlikely(wkq_err))
35682 + diropq = ERR_PTR(wkq_err);
35688 +/* ---------------------------------------------------------------------- */
35691 + * lookup whiteout dentry.
35692 + * @h_parent: lower parent dentry which must exist and be locked
35693 + * @base_name: name of dentry which will be whiteouted
35694 + * returns dentry for whiteout.
35696 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35697 + struct au_branch *br)
35700 + struct qstr wh_name;
35701 + struct dentry *wh_dentry;
35703 + err = au_wh_name_alloc(&wh_name, base_name);
35704 + wh_dentry = ERR_PTR(err);
35706 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35707 + au_kfree_try_rcu(wh_name.name);
35709 + return wh_dentry;
35713 + * link/create a whiteout for @dentry on @bindex.
35715 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35716 + struct dentry *h_parent)
35718 + struct dentry *wh_dentry;
35719 + struct super_block *sb;
35722 + sb = dentry->d_sb;
35723 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35724 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35725 + err = link_or_create_wh(sb, bindex, wh_dentry);
35727 + au_set_dbwh(dentry, bindex);
35728 + au_fhsm_wrote(sb, bindex, /*force*/0);
35731 + wh_dentry = ERR_PTR(err);
35735 + return wh_dentry;
35738 +/* ---------------------------------------------------------------------- */
35740 +/* Delete all whiteouts in this directory on branch bindex. */
35741 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35742 + aufs_bindex_t bindex, struct au_branch *br)
35745 + unsigned long ul, n;
35746 + struct qstr wh_name;
35748 + struct hlist_head *head;
35749 + struct au_vdir_wh *pos;
35750 + struct au_vdir_destr *str;
35753 + p = (void *)__get_free_page(GFP_NOFS);
35754 + wh_name.name = p;
35755 + if (unlikely(!wh_name.name))
35759 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35760 + p += AUFS_WH_PFX_LEN;
35761 + n = whlist->nh_num;
35762 + head = whlist->nh_head;
35763 + for (ul = 0; !err && ul < n; ul++, head++) {
35764 + hlist_for_each_entry(pos, head, wh_hash) {
35765 + if (pos->wh_bindex != bindex)
35768 + str = &pos->wh_str;
35769 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35770 + memcpy(p, str->name, str->len);
35771 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35772 + err = unlink_wh_name(h_dentry, &wh_name, br);
35777 + AuIOErr("whiteout name too long %.*s\n",
35778 + str->len, str->name);
35783 + free_page((unsigned long)wh_name.name);
35789 +struct del_wh_children_args {
35791 + struct dentry *h_dentry;
35792 + struct au_nhash *whlist;
35793 + aufs_bindex_t bindex;
35794 + struct au_branch *br;
35797 +static void call_del_wh_children(void *args)
35799 + struct del_wh_children_args *a = args;
35800 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35803 +/* ---------------------------------------------------------------------- */
35805 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35807 + struct au_whtmp_rmdir *whtmp;
35809 + unsigned int rdhash;
35811 + SiMustAnyLock(sb);
35813 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35814 + if (unlikely(!whtmp)) {
35815 + whtmp = ERR_PTR(-ENOMEM);
35819 + /* no estimation for dir size */
35820 + rdhash = au_sbi(sb)->si_rdhash;
35822 + rdhash = AUFS_RDHASH_DEF;
35823 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35824 + if (unlikely(err)) {
35825 + au_kfree_rcu(whtmp);
35826 + whtmp = ERR_PTR(err);
35833 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35836 + au_lcnt_dec(&whtmp->br->br_count);
35837 + dput(whtmp->wh_dentry);
35838 + iput(whtmp->dir);
35839 + au_nhash_wh_free(&whtmp->whlist);
35840 + au_kfree_rcu(whtmp);
35844 + * rmdir the whiteouted temporary named dir @h_dentry.
35845 + * @whlist: whiteouted children.
35847 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35848 + struct dentry *wh_dentry, struct au_nhash *whlist)
35851 + unsigned int h_nlink;
35852 + struct path h_tmp;
35853 + struct inode *wh_inode, *h_dir;
35854 + struct au_branch *br;
35856 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35857 + IMustLock(h_dir);
35859 + br = au_sbr(dir->i_sb, bindex);
35860 + wh_inode = d_inode(wh_dentry);
35861 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35864 + * someone else might change some whiteouts while we were sleeping.
35865 + * it means this whlist may have an obsoleted entry.
35867 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35868 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35871 + struct del_wh_children_args args = {
35873 + .h_dentry = wh_dentry,
35874 + .whlist = whlist,
35875 + .bindex = bindex,
35879 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35880 + if (unlikely(wkq_err))
35883 + inode_unlock(wh_inode);
35886 + h_tmp.dentry = wh_dentry;
35887 + h_tmp.mnt = au_br_mnt(br);
35888 + h_nlink = h_dir->i_nlink;
35889 + err = vfsub_rmdir(h_dir, &h_tmp);
35890 + /* some fs doesn't change the parent nlink in some cases */
35891 + h_nlink -= h_dir->i_nlink;
35895 + if (au_ibtop(dir) == bindex) {
35896 + /* todo: dir->i_mutex is necessary */
35897 + au_cpup_attr_timesizes(dir);
35899 + vfsub_drop_nlink(dir);
35901 + return 0; /* success */
35904 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35908 +static void call_rmdir_whtmp(void *args)
35911 + aufs_bindex_t bindex;
35912 + struct au_whtmp_rmdir *a = args;
35913 + struct super_block *sb;
35914 + struct dentry *h_parent;
35915 + struct inode *h_dir;
35916 + struct au_hinode *hdir;
35918 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35919 + /* inode_lock(a->dir); */
35921 + sb = a->dir->i_sb;
35922 + si_read_lock(sb, !AuLock_FLUSH);
35923 + if (!au_br_writable(a->br->br_perm))
35925 + bindex = au_br_index(sb, a->br->br_id);
35926 + if (unlikely(bindex < 0))
35930 + ii_write_lock_parent(a->dir);
35931 + h_parent = dget_parent(a->wh_dentry);
35932 + h_dir = d_inode(h_parent);
35933 + hdir = au_hi(a->dir, bindex);
35934 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35935 + if (unlikely(err))
35937 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35938 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35941 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35942 + au_hn_inode_unlock(hdir);
35943 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35947 + ii_write_unlock(a->dir);
35949 + /* inode_unlock(a->dir); */
35950 + au_whtmp_rmdir_free(a);
35951 + si_read_unlock(sb);
35952 + au_nwt_done(&au_sbi(sb)->si_nowait);
35953 + if (unlikely(err))
35954 + AuIOErr("err %d\n", err);
35957 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35958 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35961 + struct super_block *sb;
35965 + /* all post-process will be done in do_rmdir_whtmp(). */
35967 + args->dir = au_igrab(dir);
35968 + args->br = au_sbr(sb, bindex);
35969 + au_lcnt_inc(&args->br->br_count);
35970 + args->wh_dentry = dget(wh_dentry);
35971 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35972 + if (unlikely(wkq_err)) {
35973 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35974 + au_whtmp_rmdir_free(args);
35977 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35978 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35979 +++ linux/fs/aufs/whout.h 2019-01-28 14:36:12.222418047 +0100
35981 +/* SPDX-License-Identifier: GPL-2.0 */
35983 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35985 + * This program, aufs is free software; you can redistribute it and/or modify
35986 + * it under the terms of the GNU General Public License as published by
35987 + * the Free Software Foundation; either version 2 of the License, or
35988 + * (at your option) any later version.
35990 + * This program is distributed in the hope that it will be useful,
35991 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35992 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35993 + * GNU General Public License for more details.
35995 + * You should have received a copy of the GNU General Public License
35996 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36000 + * whiteout for logical deletion and opaque directory
36003 +#ifndef __AUFS_WHOUT_H__
36004 +#define __AUFS_WHOUT_H__
36011 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36012 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
36013 +int au_diropq_test(struct dentry *h_dentry);
36015 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36016 + struct qstr *prefix);
36017 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36018 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36019 + struct dentry *dentry);
36020 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36022 +/* diropq flags */
36023 +#define AuDiropq_CREATE 1
36024 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36025 +#define au_fset_diropq(flags, name) \
36026 + do { (flags) |= AuDiropq_##name; } while (0)
36027 +#define au_fclr_diropq(flags, name) \
36028 + do { (flags) &= ~AuDiropq_##name; } while (0)
36030 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36031 + unsigned int flags);
36032 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36033 + struct au_branch *br);
36034 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36035 + struct dentry *h_parent);
36037 +/* real rmdir for the whiteout-ed dir */
36038 +struct au_whtmp_rmdir {
36039 + struct inode *dir;
36040 + struct au_branch *br;
36041 + struct dentry *wh_dentry;
36042 + struct au_nhash whlist;
36045 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36046 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36047 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36048 + struct dentry *wh_dentry, struct au_nhash *whlist);
36049 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36050 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36052 +/* ---------------------------------------------------------------------- */
36054 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36055 + aufs_bindex_t bindex)
36057 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36060 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36062 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36065 +#endif /* __KERNEL__ */
36066 +#endif /* __AUFS_WHOUT_H__ */
36067 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36068 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36069 +++ linux/fs/aufs/wkq.c 2019-01-28 14:36:12.222418047 +0100
36071 +// SPDX-License-Identifier: GPL-2.0
36073 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36075 + * This program, aufs is free software; you can redistribute it and/or modify
36076 + * it under the terms of the GNU General Public License as published by
36077 + * the Free Software Foundation; either version 2 of the License, or
36078 + * (at your option) any later version.
36080 + * This program is distributed in the hope that it will be useful,
36081 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36082 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36083 + * GNU General Public License for more details.
36085 + * You should have received a copy of the GNU General Public License
36086 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36090 + * workqueue for asynchronous/super-io operations
36091 + * todo: try new credential scheme
36094 +#include <linux/module.h>
36097 +/* internal workqueue named AUFS_WKQ_NAME */
36099 +static struct workqueue_struct *au_wkq;
36101 +struct au_wkinfo {
36102 + struct work_struct wk;
36103 + struct kobject *kobj;
36105 + unsigned int flags; /* see wkq.h */
36107 + au_wkq_func_t func;
36110 +#ifdef CONFIG_LOCKDEP
36112 + struct held_lock **hlock;
36115 + struct completion *comp;
36118 +/* ---------------------------------------------------------------------- */
36120 + * Aufs passes some operations to the workqueue such as the internal copyup.
36121 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36122 + * job run by workqueue depends upon the locks acquired in the other task.
36123 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36124 + * information too. And the job in the workqueue restores the info in order to
36125 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36126 + * correctly and expectedly.
36129 +#ifndef CONFIG_LOCKDEP
36130 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36131 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36132 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36133 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36134 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36136 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36138 + wkinfo->hlock = NULL;
36139 + wkinfo->dont_check = 0;
36146 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36148 + static DEFINE_SPINLOCK(spin);
36151 + struct lock_class_key *key;
36153 + { .name = "&sbinfo->si_rwsem" },
36154 + { .name = "&finfo->fi_rwsem" },
36155 + { .name = "&dinfo->di_rwsem" },
36156 + { .name = "&iinfo->ii_rwsem" }
36161 + /* lockless read from 'set.' see below */
36162 + if (set == ARRAY_SIZE(a)) {
36163 + for (i = 0; i < ARRAY_SIZE(a); i++)
36164 + if (a[i].key == key)
36169 + spin_lock(&spin);
36171 + for (i = 0; i < ARRAY_SIZE(a); i++)
36172 + if (a[i].key == key) {
36173 + spin_unlock(&spin);
36176 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36178 + if (unlikely(a[i].key == key)) { /* rare but possible */
36179 + spin_unlock(&spin);
36184 + if (strstr(a[i].name, name)) {
36186 + * the order of these three lines is important for the
36187 + * lockless read above.
36190 + spin_unlock(&spin);
36192 + /* AuDbg("%d, %s\n", set, name); */
36196 + spin_unlock(&spin);
36205 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36208 + struct task_struct *curr;
36209 + struct held_lock **hl, *held_locks, *p;
36213 + wkinfo->dont_check = lockdep_recursing(curr);
36214 + if (wkinfo->dont_check)
36216 + n = curr->lockdep_depth;
36221 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36222 + if (unlikely(!wkinfo->hlock))
36227 + if (0 && au_debug_test()) /* left for debugging */
36228 + lockdep_print_held_locks(curr);
36230 + held_locks = curr->held_locks;
36231 + hl = wkinfo->hlock;
36233 + p = held_locks++;
36234 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36243 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36245 + au_kfree_try_rcu(wkinfo->hlock);
36248 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36250 + struct held_lock *p, **hl = wkinfo->hlock;
36253 + if (wkinfo->dont_check)
36257 + while ((p = *hl++)) { /* assignment */
36258 + subclass = lockdep_hlock_class(p)->subclass;
36259 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36261 + rwsem_acquire_read(p->instance, subclass, 0,
36262 + /*p->acquire_ip*/_RET_IP_);
36264 + rwsem_acquire(p->instance, subclass, 0,
36265 + /*p->acquire_ip*/_RET_IP_);
36269 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36271 + struct held_lock *p, **hl = wkinfo->hlock;
36273 + if (wkinfo->dont_check)
36277 + while ((p = *hl++)) /* assignment */
36278 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36282 +static void wkq_func(struct work_struct *wk)
36284 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36286 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36287 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36289 + au_wkq_lockdep_pre(wkinfo);
36290 + wkinfo->func(wkinfo->args);
36291 + au_wkq_lockdep_post(wkinfo);
36292 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36293 + complete(wkinfo->comp);
36295 + kobject_put(wkinfo->kobj);
36296 + module_put(THIS_MODULE); /* todo: ?? */
36297 + au_kfree_rcu(wkinfo);
36302 + * Since struct completion is large, try allocating it dynamically.
36304 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36305 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36307 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36309 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36311 + init_completion(*comp);
36312 + wkinfo->comp = *comp;
36318 +static void au_wkq_comp_free(struct completion *comp)
36320 + au_kfree_rcu(comp);
36326 +#define AuWkqCompDeclare(name) \
36327 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36328 + struct completion *comp = &_ ## name
36330 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36332 + wkinfo->comp = *comp;
36336 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36340 +#endif /* 4KSTACKS */
36342 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36344 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36345 + if (au_wkq_test()) {
36346 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36347 + " due to a dead dir by UDBA,"
36348 + " or async xino write?\n");
36349 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36352 + au_dbg_verify_kthread();
36354 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36355 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36356 + queue_work(au_wkq, &wkinfo->wk);
36358 + INIT_WORK(&wkinfo->wk, wkq_func);
36359 + schedule_work(&wkinfo->wk);
36364 + * Be careful. It is easy to make deadlock happen.
36365 + * processA: lock, wkq and wait
36366 + * processB: wkq and wait, lock in wkq
36369 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36372 + AuWkqCompDeclare(comp);
36373 + struct au_wkinfo wkinfo = {
36379 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36380 + if (unlikely(err))
36382 + err = au_wkq_lockdep_alloc(&wkinfo);
36383 + if (unlikely(err))
36386 + au_wkq_run(&wkinfo);
36387 + /* no timeout, no interrupt */
36388 + wait_for_completion(wkinfo.comp);
36390 + au_wkq_lockdep_free(&wkinfo);
36393 + au_wkq_comp_free(comp);
36395 + destroy_work_on_stack(&wkinfo.wk);
36400 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36401 + * problem in a concurrent umounting.
36403 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36404 + unsigned int flags)
36407 + struct au_wkinfo *wkinfo;
36409 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36412 + * wkq_func() must free this wkinfo.
36413 + * it highly depends upon the implementation of workqueue.
36416 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36418 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36419 + wkinfo->flags = flags & ~AuWkq_WAIT;
36420 + wkinfo->func = func;
36421 + wkinfo->args = args;
36422 + wkinfo->comp = NULL;
36423 + au_wkq_lockdep_init(wkinfo);
36424 + kobject_get(wkinfo->kobj);
36425 + __module_get(THIS_MODULE); /* todo: ?? */
36427 + au_wkq_run(wkinfo);
36430 + au_nwt_done(&au_sbi(sb)->si_nowait);
36436 +/* ---------------------------------------------------------------------- */
36438 +void au_nwt_init(struct au_nowait_tasks *nwt)
36440 + atomic_set(&nwt->nw_len, 0);
36441 + /* smp_mb(); */ /* atomic_set */
36442 + init_waitqueue_head(&nwt->nw_wq);
36445 +void au_wkq_fin(void)
36447 + destroy_workqueue(au_wkq);
36450 +int __init au_wkq_init(void)
36455 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36456 + if (IS_ERR(au_wkq))
36457 + err = PTR_ERR(au_wkq);
36458 + else if (!au_wkq)
36463 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36464 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36465 +++ linux/fs/aufs/wkq.h 2019-01-28 14:36:12.225751436 +0100
36467 +/* SPDX-License-Identifier: GPL-2.0 */
36469 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36471 + * This program, aufs is free software; you can redistribute it and/or modify
36472 + * it under the terms of the GNU General Public License as published by
36473 + * the Free Software Foundation; either version 2 of the License, or
36474 + * (at your option) any later version.
36476 + * This program is distributed in the hope that it will be useful,
36477 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36478 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36479 + * GNU General Public License for more details.
36481 + * You should have received a copy of the GNU General Public License
36482 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36486 + * workqueue for asynchronous/super-io operations
36487 + * todo: try new credentials management scheme
36490 +#ifndef __AUFS_WKQ_H__
36491 +#define __AUFS_WKQ_H__
36495 +#include <linux/wait.h>
36497 +struct super_block;
36499 +/* ---------------------------------------------------------------------- */
36502 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36504 +struct au_nowait_tasks {
36506 + wait_queue_head_t nw_wq;
36509 +/* ---------------------------------------------------------------------- */
36511 +typedef void (*au_wkq_func_t)(void *args);
36514 +#define AuWkq_WAIT 1
36515 +#define AuWkq_NEST (1 << 1)
36516 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36517 +#define au_fset_wkq(flags, name) \
36518 + do { (flags) |= AuWkq_##name; } while (0)
36519 +#define au_fclr_wkq(flags, name) \
36520 + do { (flags) &= ~AuWkq_##name; } while (0)
36523 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36524 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36525 + unsigned int flags);
36526 +void au_nwt_init(struct au_nowait_tasks *nwt);
36527 +int __init au_wkq_init(void);
36528 +void au_wkq_fin(void);
36530 +/* ---------------------------------------------------------------------- */
36532 +static inline int au_wkq_test(void)
36534 + return current->flags & PF_WQ_WORKER;
36537 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36539 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36542 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36544 + if (atomic_dec_and_test(&nwt->nw_len))
36545 + wake_up_all(&nwt->nw_wq);
36548 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36550 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36554 +#endif /* __KERNEL__ */
36555 +#endif /* __AUFS_WKQ_H__ */
36556 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36557 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36558 +++ linux/fs/aufs/xattr.c 2019-01-28 14:36:12.225751436 +0100
36560 +// SPDX-License-Identifier: GPL-2.0
36562 + * Copyright (C) 2014-2018 Junjiro R. Okajima
36564 + * This program, aufs is free software; you can redistribute it and/or modify
36565 + * it under the terms of the GNU General Public License as published by
36566 + * the Free Software Foundation; either version 2 of the License, or
36567 + * (at your option) any later version.
36569 + * This program is distributed in the hope that it will be useful,
36570 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36571 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36572 + * GNU General Public License for more details.
36574 + * You should have received a copy of the GNU General Public License
36575 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36579 + * handling xattr functions
36582 +#include <linux/fs.h>
36583 +#include <linux/posix_acl_xattr.h>
36584 +#include <linux/xattr.h>
36587 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36589 + if (!ignore_flags)
36597 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36602 +#define cmp(brattr, prefix) do { \
36603 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36604 + XATTR_##prefix##_PREFIX_LEN)) { \
36605 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36611 + cmp(SEC, SECURITY);
36612 + cmp(SYS, SYSTEM);
36613 + cmp(TR, TRUSTED);
36617 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36624 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36626 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36627 + char *name, char **buf, unsigned int ignore_flags,
36628 + unsigned int verbose)
36632 + struct inode *h_idst;
36634 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36636 + if (unlikely(err <= 0)) {
36637 + if (err == -ENODATA
36638 + || (err == -EOPNOTSUPP
36639 + && ((ignore_flags & au_xattr_out_of_list)
36640 + || (au_test_nfs_noacl(d_inode(h_src))
36641 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36643 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36646 + if (err && (verbose || au_debug_test()))
36647 + pr_err("%s, err %d\n", name, err);
36651 + /* unlock it temporary */
36652 + h_idst = d_inode(h_dst);
36653 + inode_unlock(h_idst);
36654 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36655 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36656 + if (unlikely(err)) {
36657 + if (verbose || au_debug_test())
36658 + pr_err("%s, err %d\n", name, err);
36659 + err = au_xattr_ignore(err, name, ignore_flags);
36666 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36667 + unsigned int verbose)
36669 + int err, unlocked, acl_access, acl_default;
36671 + struct inode *h_isrc, *h_idst;
36672 + char *value, *p, *o, *e;
36674 + /* try stopping to update the source inode while we are referencing */
36675 + /* there should not be the parent-child relationship between them */
36676 + h_isrc = d_inode(h_src);
36677 + h_idst = d_inode(h_dst);
36678 + inode_unlock(h_idst);
36679 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36680 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36683 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36684 + ssz = vfs_listxattr(h_src, NULL, 0);
36686 + if (unlikely(err < 0)) {
36688 + if (err == -ENODATA
36689 + || err == -EOPNOTSUPP)
36690 + err = 0; /* ignore */
36699 + p = kmalloc(ssz, GFP_NOFS);
36701 + if (unlikely(!p))
36703 + err = vfs_listxattr(h_src, p, ssz);
36705 + inode_unlock_shared(h_isrc);
36707 + AuDbg("err %d, ssz %zd\n", err, ssz);
36708 + if (unlikely(err < 0))
36716 + while (!err && p < e) {
36717 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36718 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36719 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36720 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36722 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36724 + p += strlen(p) + 1;
36727 + ignore_flags |= au_xattr_out_of_list;
36728 + if (!err && !acl_access) {
36729 + err = au_do_cpup_xattr(h_dst, h_src,
36730 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36731 + ignore_flags, verbose);
36734 + if (!err && !acl_default) {
36735 + err = au_do_cpup_xattr(h_dst, h_src,
36736 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36737 + ignore_flags, verbose);
36741 + au_kfree_try_rcu(value);
36744 + au_kfree_try_rcu(o);
36747 + inode_unlock_shared(h_isrc);
36752 +/* ---------------------------------------------------------------------- */
36754 +static int au_smack_reentering(struct super_block *sb)
36756 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36758 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36759 + * i_op->getxattr(). ouch.
36761 + return si_pid_test(sb);
36772 +struct au_lgxattr {
36780 + const char *name;
36787 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36791 + struct path h_path;
36792 + struct super_block *sb;
36794 + sb = dentry->d_sb;
36795 + reenter = au_smack_reentering(sb);
36797 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36798 + if (unlikely(err))
36801 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36802 + if (unlikely(err))
36804 + if (unlikely(!h_path.dentry))
36805 + /* illegally overlapped or something */
36806 + goto out_di; /* pretending success */
36808 + /* always topmost entry only */
36809 + switch (arg->type) {
36810 + case AU_XATTR_LIST:
36811 + err = vfs_listxattr(h_path.dentry,
36812 + arg->u.list.list, arg->u.list.size);
36814 + case AU_XATTR_GET:
36815 + AuDebugOn(d_is_negative(h_path.dentry));
36816 + err = vfs_getxattr(h_path.dentry,
36817 + arg->u.get.name, arg->u.get.value,
36818 + arg->u.get.size);
36824 + di_read_unlock(dentry, AuLock_IR);
36827 + si_read_unlock(sb);
36833 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36835 + struct au_lgxattr arg = {
36836 + .type = AU_XATTR_LIST,
36843 + return au_lgxattr(dentry, &arg);
36846 +static ssize_t au_getxattr(struct dentry *dentry,
36847 + struct inode *inode __maybe_unused,
36848 + const char *name, void *value, size_t size)
36850 + struct au_lgxattr arg = {
36851 + .type = AU_XATTR_GET,
36859 + return au_lgxattr(dentry, &arg);
36862 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36863 + const char *name, const void *value, size_t size,
36866 + struct au_sxattr arg = {
36867 + .type = AU_XATTR_SET,
36876 + return au_sxattr(dentry, inode, &arg);
36879 +/* ---------------------------------------------------------------------- */
36881 +static int au_xattr_get(const struct xattr_handler *handler,
36882 + struct dentry *dentry, struct inode *inode,
36883 + const char *name, void *buffer, size_t size)
36885 + return au_getxattr(dentry, inode, name, buffer, size);
36888 +static int au_xattr_set(const struct xattr_handler *handler,
36889 + struct dentry *dentry, struct inode *inode,
36890 + const char *name, const void *value, size_t size,
36893 + return au_setxattr(dentry, inode, name, value, size, flags);
36896 +static const struct xattr_handler au_xattr_handler = {
36899 + .get = au_xattr_get,
36900 + .set = au_xattr_set
36903 +static const struct xattr_handler *au_xattr_handlers[] = {
36904 +#ifdef CONFIG_FS_POSIX_ACL
36905 + &posix_acl_access_xattr_handler,
36906 + &posix_acl_default_xattr_handler,
36908 + &au_xattr_handler, /* must be last */
36912 +void au_xattr_init(struct super_block *sb)
36914 + sb->s_xattr = au_xattr_handlers;
36916 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36917 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36918 +++ linux/fs/aufs/xino.c 2019-01-28 14:36:12.225751436 +0100
36920 +// SPDX-License-Identifier: GPL-2.0
36922 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36924 + * This program, aufs is free software; you can redistribute it and/or modify
36925 + * it under the terms of the GNU General Public License as published by
36926 + * the Free Software Foundation; either version 2 of the License, or
36927 + * (at your option) any later version.
36929 + * This program is distributed in the hope that it will be useful,
36930 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36931 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36932 + * GNU General Public License for more details.
36934 + * You should have received a copy of the GNU General Public License
36935 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36939 + * external inode number translation table and bitmap
36941 + * things to consider
36943 + * + au_xino object
36944 + * + XINO files (xino, xib, xigen)
36945 + * + dynamic debugfs entries (xiN)
36946 + * + static debugfs entries (xib, xigen)
36947 + * + static sysfs entry (xi_path)
36948 + * - several entry points to handle them.
36949 + * + mount(2) without xino option (default)
36950 + * + mount(2) with xino option
36951 + * + mount(2) with noxino option
36953 + * + remount with add/del branches
36954 + * + remount with xino/noxino options
36957 +#include <linux/seq_file.h>
36958 +#include <linux/statfs.h>
36961 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36962 + aufs_bindex_t bbot,
36963 + struct super_block *h_sb)
36965 + /* todo: try binary-search if the branches are many */
36966 + for (; btop <= bbot; btop++)
36967 + if (h_sb == au_sbr_sb(sb, btop))
36973 + * find another branch who is on the same filesystem of the specified
36974 + * branch{@btgt}. search until @bbot.
36976 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36977 + aufs_bindex_t bbot)
36979 + aufs_bindex_t bindex;
36980 + struct super_block *tgt_sb;
36982 + tgt_sb = au_sbr_sb(sb, btgt);
36983 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36985 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36990 +/* ---------------------------------------------------------------------- */
36993 + * stop unnecessary notify events at creating xino files
36996 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36998 + aufs_bindex_t bfound, bindex, bbot;
36999 + struct dentry *parent;
37000 + struct au_branch *br;
37003 + parent = dentry->d_parent; /* safe d_parent access */
37004 + bbot = au_sbbot(sb);
37005 + for (bindex = 0; bindex <= bbot; bindex++) {
37006 + br = au_sbr(sb, bindex);
37007 + if (au_br_dentry(br) == parent) {
37013 + AuDbg("bfound b%d\n", bfound);
37017 +struct au_xino_lock_dir {
37018 + struct au_hinode *hdir;
37019 + struct dentry *parent;
37020 + struct inode *dir;
37023 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37024 + unsigned int lsc)
37026 + struct dentry *parent;
37027 + struct inode *dir;
37029 + parent = dget_parent(dentry);
37030 + dir = d_inode(parent);
37031 + inode_lock_nested(dir, lsc);
37032 +#if 0 /* it should not happen */
37033 + spin_lock(&dentry->d_lock);
37034 + if (unlikely(dentry->d_parent != parent)) {
37035 + spin_unlock(&dentry->d_lock);
37036 + inode_unlock(dir);
37041 + spin_unlock(&dentry->d_lock);
37048 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37049 + struct au_xino_lock_dir *ldir)
37051 + aufs_bindex_t bindex;
37053 + ldir->hdir = NULL;
37054 + bindex = au_xi_root(sb, xipath->dentry);
37055 + if (bindex >= 0) {
37056 + /* rw branch root */
37057 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37058 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37061 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37063 + ldir->dir = d_inode(ldir->parent);
37067 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37070 + au_hn_inode_unlock(ldir->hdir);
37072 + inode_unlock(ldir->dir);
37073 + dput(ldir->parent);
37077 +/* ---------------------------------------------------------------------- */
37080 + * create and set a new xino file
37082 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent)
37084 + struct file *file;
37085 + struct dentry *h_parent, *d;
37086 + struct inode *h_dir, *inode;
37090 + * at mount-time, and the xino file is the default path,
37091 + * hnotify is disabled so we have no notify events to ignore.
37092 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37094 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37095 + /* | __FMODE_NONOTIFY */,
37097 + if (IS_ERR(file)) {
37099 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37103 + /* keep file count */
37105 + d = file->f_path.dentry;
37106 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37107 + /* mnt_want_write() is unnecessary here */
37108 + h_dir = d_inode(h_parent);
37109 + inode = file_inode(file);
37110 + /* no delegation since it is just created */
37111 + if (inode->i_nlink)
37112 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37114 + inode_unlock(h_dir);
37116 + if (unlikely(err)) {
37118 + pr_err("unlink %s(%d)\n", fpath, err);
37123 + if (unlikely(sb == d->d_sb)) {
37125 + pr_err("%s must be outside\n", fpath);
37128 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37130 + pr_err("xino doesn't support %s(%s)\n",
37131 + fpath, au_sbtype(d->d_sb));
37134 + return file; /* success */
37138 + file = ERR_PTR(err);
37143 + * create a new xinofile at the same place/path as @base.
37145 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37146 + struct file *copy_src)
37148 + struct file *file;
37149 + struct dentry *dentry, *parent;
37150 + struct inode *dir, *delegated;
37151 + struct qstr *name;
37152 + struct path path;
37153 + int err, do_unlock;
37154 + struct au_xino_lock_dir ldir;
37157 + au_xino_lock_dir(sb, base, &ldir);
37158 + dentry = base->dentry;
37159 + parent = dentry->d_parent; /* dir inode is locked */
37160 + dir = d_inode(parent);
37163 + name = &dentry->d_name;
37164 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37165 + if (IS_ERR(path.dentry)) {
37166 + file = (void *)path.dentry;
37167 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37171 + /* no need to mnt_want_write() since we call dentry_open() later */
37172 + err = vfs_create(dir, path.dentry, 0666, NULL);
37173 + if (unlikely(err)) {
37174 + file = ERR_PTR(err);
37175 + pr_err("%pd create err %d\n", dentry, err);
37179 + path.mnt = base->mnt;
37180 + file = vfsub_dentry_open(&path,
37181 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37182 + /* | __FMODE_NONOTIFY */);
37183 + if (IS_ERR(file)) {
37184 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37188 + delegated = NULL;
37189 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37190 + au_xino_unlock_dir(&ldir);
37192 + if (unlikely(err == -EWOULDBLOCK)) {
37193 + pr_warn("cannot retry for NFSv4 delegation"
37194 + " for an internal unlink\n");
37197 + if (unlikely(err)) {
37198 + pr_err("%pd unlink err %d\n", dentry, err);
37203 + /* no one can touch copy_src xino */
37204 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37205 + if (unlikely(err)) {
37206 + pr_err("%pd copy err %d\n", dentry, err);
37210 + goto out_dput; /* success */
37214 + file = ERR_PTR(err);
37216 + dput(path.dentry);
37219 + au_xino_unlock_dir(&ldir);
37223 +struct file *au_xino_file1(struct au_xino *xi)
37225 + struct file *file;
37226 + unsigned int u, nfile;
37229 + nfile = xi->xi_nfile;
37230 + for (u = 0; u < nfile; u++) {
37231 + file = xi->xi_file[u];
37239 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37250 + if (idx < xi->xi_nfile) {
37251 + f = xi->xi_file[idx];
37255 + p = au_kzrealloc(xi->xi_file,
37256 + sizeof(*xi->xi_file) * xi->xi_nfile,
37257 + sizeof(*xi->xi_file) * (idx + 1),
37258 + GFP_NOFS, /*may_shrink*/0);
37260 + MtxMustLock(&xi->xi_mtx);
37262 + xi->xi_nfile = idx + 1;
37270 + xi->xi_file[idx] = file;
37277 + * if @xinew->xi is not set, then create new xigen file.
37279 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37281 + struct file *file;
37284 + SiMustAnyLock(sb);
37286 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37287 + if (IS_ERR(file)) {
37288 + err = PTR_ERR(file);
37289 + pr_err("%s[%d], err %d\n",
37290 + xinew->xi ? "xino" : "xigen",
37291 + xinew->idx, err);
37296 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37299 + /* todo: make xigen file an array */
37300 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37303 + if (unlikely(err))
37304 + file = ERR_PTR(err);
37310 +/* ---------------------------------------------------------------------- */
37313 + * truncate xino files
37315 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37316 + int idx, struct kstatfs *st)
37320 + struct file *file, *new_xino;
37321 + struct au_xi_new xinew = {
37326 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37327 + file = au_xino_file(xinew.xi, idx);
37331 + xinew.base = &file->f_path;
37332 + err = vfs_statfs(xinew.base, st);
37333 + if (unlikely(err)) {
37334 + AuErr1("statfs err %d, ignored\n", err);
37339 + blocks = file_inode(file)->i_blocks;
37340 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37341 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37343 + xinew.copy_src = file;
37344 + new_xino = au_xi_new(sb, &xinew);
37345 + if (IS_ERR(new_xino)) {
37346 + err = PTR_ERR(new_xino);
37347 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37351 + err = vfs_statfs(&new_xino->f_path, st);
37353 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37354 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37355 + st->f_bfree, st->f_blocks);
37357 + AuErr1("statfs err %d, ignored\n", err);
37365 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37368 + unsigned long jiffy;
37369 + aufs_bindex_t bbot;
37370 + struct kstatfs *st;
37371 + struct au_branch *br;
37372 + struct au_xino *xi;
37375 + st = kmalloc(sizeof(*st), GFP_NOFS);
37376 + if (unlikely(!st))
37380 + bbot = au_sbbot(sb);
37381 + if (unlikely(bindex < 0 || bbot < bindex))
37386 + br = au_sbr(sb, bindex);
37387 + xi = br->br_xino;
37388 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37389 + err = au_xino_do_trunc(sb, bindex, i, st);
37391 + au_sbi(sb)->si_xino_jiffy = jiffy;
37394 + au_kfree_rcu(st);
37399 +struct xino_do_trunc_args {
37400 + struct super_block *sb;
37401 + struct au_branch *br;
37405 +static void xino_do_trunc(void *_args)
37407 + struct xino_do_trunc_args *args = _args;
37408 + struct super_block *sb;
37409 + struct au_branch *br;
37410 + struct inode *dir;
37412 + aufs_bindex_t bindex;
37416 + dir = d_inode(sb->s_root);
37420 + si_noflush_write_lock(sb);
37421 + ii_read_lock_parent(dir);
37422 + bindex = au_br_index(sb, br->br_id);
37423 + err = au_xino_trunc(sb, bindex, idx);
37424 + ii_read_unlock(dir);
37425 + if (unlikely(err))
37426 + pr_warn("err b%d, (%d)\n", bindex, err);
37427 + atomic_dec(&br->br_xino->xi_truncating);
37428 + au_lcnt_dec(&br->br_count);
37429 + si_write_unlock(sb);
37430 + au_nwt_done(&au_sbi(sb)->si_nowait);
37431 + au_kfree_rcu(args);
37435 + * returns the index in the xi_file array whose corresponding file is necessary
37436 + * to truncate, or -1 which means no need to truncate.
37438 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37442 + struct kstatfs st;
37443 + struct au_sbinfo *sbinfo;
37444 + struct au_xino *xi;
37445 + struct file *file;
37447 + /* todo: si_xino_expire and the ratio should be customizable */
37448 + sbinfo = au_sbi(sb);
37449 + if (time_before(jiffies,
37450 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37453 + /* truncation border */
37454 + xi = br->br_xino;
37455 + for (u = 0; u < xi->xi_nfile; u++) {
37456 + file = au_xino_file(xi, u);
37460 + err = vfs_statfs(&file->f_path, &st);
37461 + if (unlikely(err)) {
37462 + AuErr1("statfs err %d, ignored\n", err);
37465 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37466 + >= AUFS_XINO_DEF_TRUNC)
37473 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37476 + struct xino_do_trunc_args *args;
37479 + idx = xino_trunc_test(sb, br);
37483 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37486 + /* lock and kfree() will be called in trunc_xino() */
37487 + args = kmalloc(sizeof(*args), GFP_NOFS);
37488 + if (unlikely(!args)) {
37489 + AuErr1("no memory\n");
37493 + au_lcnt_inc(&br->br_count);
37497 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37499 + return; /* success */
37501 + pr_err("wkq %d\n", wkq_err);
37502 + au_lcnt_dec(&br->br_count);
37503 + au_kfree_rcu(args);
37506 + atomic_dec(&br->br_xino->xi_truncating);
37509 +/* ---------------------------------------------------------------------- */
37511 +struct au_xi_calc {
37516 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37517 + struct au_xi_calc *calc)
37521 + maxent = au_xi_maxent(sb);
37522 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37523 + calc->pos *= sizeof(ino_t);
37526 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37527 + struct au_xi_calc *calc)
37530 + struct file *file;
37531 + struct au_xino *xi = br->br_xino;
37532 + struct au_xi_new xinew = {
37536 + SiMustAnyLock(sb);
37542 + mutex_lock(&xi->xi_mtx);
37543 + file = au_xino_file(xi, calc->idx);
37547 + file = au_xino_file(xi, /*idx*/-1);
37548 + AuDebugOn(!file);
37549 + xinew.idx = calc->idx;
37550 + xinew.base = &file->f_path;
37551 + /* xinew.copy_src = NULL; */
37552 + file = au_xi_new(sb, &xinew);
37553 + if (IS_ERR(file))
37554 + err = PTR_ERR(file);
37557 + mutex_unlock(&xi->xi_mtx);
37562 +struct au_xino_do_new_async_args {
37563 + struct super_block *sb;
37564 + struct au_branch *br;
37565 + struct au_xi_calc calc;
37569 +struct au_xi_writing {
37570 + struct hlist_bl_node node;
37571 + ino_t h_ino, ino;
37574 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37575 + struct au_xi_calc *calc, ino_t ino);
37577 +static void au_xino_call_do_new_async(void *args)
37579 + struct au_xino_do_new_async_args *a = args;
37580 + struct au_branch *br;
37581 + struct super_block *sb;
37582 + struct au_sbinfo *sbi;
37583 + struct inode *root;
37584 + struct file *file;
37585 + struct au_xi_writing *del, *p;
37586 + struct hlist_bl_head *hbl;
37587 + struct hlist_bl_node *pos;
37592 + sbi = au_sbi(sb);
37593 + si_noflush_read_lock(sb);
37594 + root = d_inode(sb->s_root);
37595 + ii_read_lock_child(root);
37596 + err = au_xino_do_new_async(sb, br, &a->calc);
37597 + if (unlikely(err)) {
37598 + AuIOErr("err %d\n", err);
37602 + file = au_xino_file(br->br_xino, a->calc.idx);
37603 + AuDebugOn(!file);
37604 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37605 + if (unlikely(err)) {
37606 + AuIOErr("err %d\n", err);
37611 + hbl = &br->br_xino->xi_writing;
37612 + hlist_bl_lock(hbl);
37613 + au_hbl_for_each(pos, hbl) {
37614 + p = container_of(pos, struct au_xi_writing, node);
37615 + if (p->ino == a->ino) {
37617 + hlist_bl_del(&p->node);
37621 + hlist_bl_unlock(hbl);
37622 + au_kfree_rcu(del);
37625 + au_lcnt_dec(&br->br_count);
37626 + ii_read_unlock(root);
37627 + si_read_unlock(sb);
37628 + au_nwt_done(&sbi->si_nowait);
37633 + * create a new xino file asynchronously
37635 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37636 + struct au_xi_calc *calc, ino_t ino)
37639 + struct au_xino_do_new_async_args *arg;
37642 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37643 + if (unlikely(!arg))
37648 + arg->calc = *calc;
37650 + au_lcnt_inc(&br->br_count);
37651 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37652 + if (unlikely(err)) {
37653 + pr_err("wkq %d\n", err);
37654 + au_lcnt_dec(&br->br_count);
37655 + au_kfree_rcu(arg);
37663 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37664 + * at the position of @h_ino.
37666 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37671 + struct au_xi_calc calc;
37672 + struct au_sbinfo *sbinfo;
37673 + struct file *file;
37674 + struct au_xino *xi;
37675 + struct hlist_bl_head *hbl;
37676 + struct hlist_bl_node *pos;
37677 + struct au_xi_writing *p;
37680 + if (!au_opt_test(au_mntflags(sb), XINO))
37681 + return 0; /* no xino */
37684 + au_xi_calc(sb, h_ino, &calc);
37685 + xi = au_sbr(sb, bindex)->br_xino;
37686 + file = au_xino_file(xi, calc.idx);
37688 + hbl = &xi->xi_writing;
37689 + hlist_bl_lock(hbl);
37690 + au_hbl_for_each(pos, hbl) {
37691 + p = container_of(pos, struct au_xi_writing, node);
37692 + if (p->h_ino == h_ino) {
37693 + AuDbg("hi%llu, i%llu, found\n",
37694 + (u64)p->h_ino, (u64)p->ino);
37699 + hlist_bl_unlock(hbl);
37701 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37702 + return 0; /* no xino */
37704 + sbinfo = au_sbi(sb);
37705 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37706 + if (sz == sizeof(*ino))
37707 + return 0; /* success */
37710 + if (unlikely(sz >= 0)) {
37712 + AuIOErr("xino read error (%zd)\n", sz);
37717 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37718 + struct au_xi_calc *calc, ino_t ino)
37722 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37723 + if (sz == sizeof(ino))
37724 + return 0; /* success */
37726 + AuIOErr("write failed (%zd)\n", sz);
37731 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37732 + * at the position of @h_ino.
37733 + * even if @ino is zero, it is written to the xinofile and means no entry.
37734 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37735 + * try truncating it.
37737 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37741 + unsigned int mnt_flags;
37742 + struct au_xi_calc calc;
37743 + struct file *file;
37744 + struct au_branch *br;
37745 + struct au_xino *xi;
37746 + struct au_xi_writing *p;
37748 + SiMustAnyLock(sb);
37750 + mnt_flags = au_mntflags(sb);
37751 + if (!au_opt_test(mnt_flags, XINO))
37754 + au_xi_calc(sb, h_ino, &calc);
37755 + br = au_sbr(sb, bindex);
37756 + xi = br->br_xino;
37757 + file = au_xino_file(xi, calc.idx);
37759 + /* store the inum pair into the list */
37760 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37761 + p->h_ino = h_ino;
37763 + au_hbl_add(&p->node, &xi->xi_writing);
37765 + /* create and write a new xino file asynchronously */
37766 + err = au_xino_new_async(sb, br, &calc, ino);
37768 + return 0; /* success */
37772 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37774 + br = au_sbr(sb, bindex);
37775 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37776 + && au_test_fs_trunc_xino(au_br_sb(br)))
37777 + xino_try_trunc(sb, br);
37778 + return 0; /* success */
37782 + AuIOErr("write failed (%d)\n", err);
37786 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37787 + size_t size, loff_t *pos);
37789 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37790 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37794 + mm_segment_t oldfs;
37800 + const int prevent_endless = 10;
37804 + oldfs = get_fs();
37805 + set_fs(KERNEL_DS);
37807 + err = func(file, buf.u, size, pos);
37808 + if (err == -EINTR
37809 + && !au_wkq_test()
37810 + && fatal_signal_pending(current)) {
37812 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37813 + BUG_ON(err == -EINTR);
37814 + oldfs = get_fs();
37815 + set_fs(KERNEL_DS);
37817 + } while (i++ < prevent_endless
37818 + && (err == -EAGAIN || err == -EINTR));
37821 +#if 0 /* reserved for future use */
37823 + fsnotify_access(file->f_path.dentry);
37829 +struct xino_fread_args {
37831 + vfs_readf_t func;
37832 + struct file *file;
37838 +static void call_xino_fread(void *args)
37840 + struct xino_fread_args *a = args;
37841 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37844 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37845 + size_t size, loff_t *pos)
37849 + struct xino_fread_args args = {
37858 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37859 + if (unlikely(wkq_err))
37865 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37866 + size_t size, loff_t *pos);
37868 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37869 + size_t size, loff_t *pos)
37872 + mm_segment_t oldfs;
37875 + const char __user *u;
37878 + const int prevent_endless = 10;
37882 + oldfs = get_fs();
37883 + set_fs(KERNEL_DS);
37885 + err = func(file, buf.u, size, pos);
37886 + if (err == -EINTR
37887 + && !au_wkq_test()
37888 + && fatal_signal_pending(current)) {
37890 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37891 + BUG_ON(err == -EINTR);
37892 + oldfs = get_fs();
37893 + set_fs(KERNEL_DS);
37895 + } while (i++ < prevent_endless
37896 + && (err == -EAGAIN || err == -EINTR));
37899 +#if 0 /* reserved for future use */
37901 + fsnotify_modify(file->f_path.dentry);
37907 +struct do_xino_fwrite_args {
37909 + vfs_writef_t func;
37910 + struct file *file;
37916 +static void call_do_xino_fwrite(void *args)
37918 + struct do_xino_fwrite_args *a = args;
37919 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37922 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37923 + size_t size, loff_t *pos)
37927 + struct do_xino_fwrite_args args = {
37937 + * it breaks RLIMIT_FSIZE and normal user's limit,
37938 + * users should care about quota and real 'filesystem full.'
37940 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37941 + if (unlikely(wkq_err))
37947 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37948 + size_t size, loff_t *pos)
37952 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37954 + err = do_xino_fwrite(func, file, buf, size, pos);
37958 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37965 +/* ---------------------------------------------------------------------- */
37968 + * inode number bitmap
37970 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37971 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37975 + AuDebugOn(bit < 0 || page_bits <= bit);
37976 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37980 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37982 + AuDebugOn(ino < AUFS_FIRST_INO);
37983 + ino -= AUFS_FIRST_INO;
37984 + *pindex = ino / page_bits;
37985 + *bit = ino % page_bits;
37988 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37993 + struct au_sbinfo *sbinfo;
37994 + struct file *xib;
37995 + unsigned long *p;
37997 + sbinfo = au_sbi(sb);
37998 + MtxMustLock(&sbinfo->si_xib_mtx);
37999 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38000 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38002 + if (pindex == sbinfo->si_xib_last_pindex)
38005 + xib = sbinfo->si_xib;
38006 + p = sbinfo->si_xib_buf;
38007 + pos = sbinfo->si_xib_last_pindex;
38008 + pos *= PAGE_SIZE;
38009 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38010 + if (unlikely(sz != PAGE_SIZE))
38014 + pos *= PAGE_SIZE;
38015 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38016 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
38018 + memset(p, 0, PAGE_SIZE);
38019 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38021 + if (sz == PAGE_SIZE) {
38022 + sbinfo->si_xib_last_pindex = pindex;
38023 + return 0; /* success */
38027 + AuIOErr1("write failed (%zd)\n", sz);
38034 +static void au_xib_clear_bit(struct inode *inode)
38037 + unsigned long pindex;
38038 + struct super_block *sb;
38039 + struct au_sbinfo *sbinfo;
38041 + AuDebugOn(inode->i_nlink);
38043 + sb = inode->i_sb;
38044 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38045 + AuDebugOn(page_bits <= bit);
38046 + sbinfo = au_sbi(sb);
38047 + mutex_lock(&sbinfo->si_xib_mtx);
38048 + err = xib_pindex(sb, pindex);
38050 + clear_bit(bit, sbinfo->si_xib_buf);
38051 + sbinfo->si_xib_next_bit = bit;
38053 + mutex_unlock(&sbinfo->si_xib_mtx);
38056 +/* ---------------------------------------------------------------------- */
38059 + * truncate a xino bitmap file
38063 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38067 + unsigned long pindex;
38068 + loff_t pos, pend;
38069 + struct au_sbinfo *sbinfo;
38070 + vfs_readf_t func;
38072 + unsigned long *p;
38075 + sbinfo = au_sbi(sb);
38076 + MtxMustLock(&sbinfo->si_xib_mtx);
38077 + p = sbinfo->si_xib_buf;
38078 + func = sbinfo->si_xread;
38079 + pend = vfsub_f_size_read(file);
38081 + while (pos < pend) {
38082 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38084 + if (unlikely(sz <= 0))
38088 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38089 + if (unlikely(*ino < AUFS_FIRST_INO))
38092 + xib_calc_bit(*ino, &pindex, &bit);
38093 + AuDebugOn(page_bits <= bit);
38094 + err = xib_pindex(sb, pindex);
38106 +static int xib_restore(struct super_block *sb)
38109 + unsigned int nfile;
38110 + aufs_bindex_t bindex, bbot;
38112 + struct au_branch *br;
38113 + struct au_xino *xi;
38114 + struct file *file;
38117 + page = (void *)__get_free_page(GFP_NOFS);
38118 + if (unlikely(!page))
38122 + bbot = au_sbbot(sb);
38123 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38124 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38125 + br = au_sbr(sb, bindex);
38126 + xi = br->br_xino;
38127 + nfile = xi->xi_nfile;
38128 + for (i = 0; i < nfile; i++) {
38129 + file = au_xino_file(xi, i);
38131 + err = do_xib_restore(sb, file, page);
38134 + AuDbg("skip shared b%d\n", bindex);
38135 + free_page((unsigned long)page);
38141 +int au_xib_trunc(struct super_block *sb)
38146 + struct au_sbinfo *sbinfo;
38147 + unsigned long *p;
38148 + struct file *file;
38150 + SiMustWriteLock(sb);
38153 + sbinfo = au_sbi(sb);
38154 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38157 + file = sbinfo->si_xib;
38158 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38161 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38162 + err = PTR_ERR(file);
38163 + if (IS_ERR(file))
38165 + fput(sbinfo->si_xib);
38166 + sbinfo->si_xib = file;
38168 + p = sbinfo->si_xib_buf;
38169 + memset(p, 0, PAGE_SIZE);
38171 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38172 + if (unlikely(sz != PAGE_SIZE)) {
38174 + AuIOErr("err %d\n", err);
38180 + mutex_lock(&sbinfo->si_xib_mtx);
38181 + /* mnt_want_write() is unnecessary here */
38182 + err = xib_restore(sb);
38183 + mutex_unlock(&sbinfo->si_xib_mtx);
38189 +/* ---------------------------------------------------------------------- */
38191 +struct au_xino *au_xino_alloc(unsigned int nfile)
38193 + struct au_xino *xi;
38195 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38196 + if (unlikely(!xi))
38198 + xi->xi_nfile = nfile;
38199 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38200 + if (unlikely(!xi->xi_file))
38203 + xi->xi_nondir.total = 8; /* initial size */
38204 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38206 + if (unlikely(!xi->xi_nondir.array))
38209 + spin_lock_init(&xi->xi_nondir.spin);
38210 + init_waitqueue_head(&xi->xi_nondir.wqh);
38211 + mutex_init(&xi->xi_mtx);
38212 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38213 + atomic_set(&xi->xi_truncating, 0);
38214 + kref_init(&xi->xi_kref);
38215 + goto out; /* success */
38218 + au_kfree_try_rcu(xi->xi_file);
38220 + au_kfree_rcu(xi);
38226 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38229 + struct au_xino *xi;
38232 + xi = au_xino_alloc(idx + 1);
38233 + if (unlikely(!xi)) {
38240 + xi->xi_file[idx] = file;
38241 + AuDebugOn(br->br_xino);
38242 + br->br_xino = xi;
38248 +static void au_xino_release(struct kref *kref)
38250 + struct au_xino *xi;
38252 + unsigned long ul;
38253 + struct hlist_bl_head *hbl;
38254 + struct hlist_bl_node *pos, *n;
38255 + struct au_xi_writing *p;
38257 + xi = container_of(kref, struct au_xino, xi_kref);
38258 + for (i = 0; i < xi->xi_nfile; i++)
38259 + if (xi->xi_file[i])
38260 + fput(xi->xi_file[i]);
38261 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38262 + AuDebugOn(xi->xi_nondir.array[i]);
38263 + mutex_destroy(&xi->xi_mtx);
38264 + hbl = &xi->xi_writing;
38265 + ul = au_hbl_count(hbl);
38266 + if (unlikely(ul)) {
38267 + pr_warn("xi_writing %lu\n", ul);
38268 + hlist_bl_lock(hbl);
38269 + hlist_bl_for_each_entry_safe (p, pos, n, hbl, node) {
38270 + hlist_bl_del(&p->node);
38273 + hlist_bl_unlock(hbl);
38275 + au_kfree_try_rcu(xi->xi_file);
38276 + au_kfree_try_rcu(xi->xi_nondir.array);
38277 + au_kfree_rcu(xi);
38280 +int au_xino_put(struct au_branch *br)
38283 + struct au_xino *xi;
38286 + xi = br->br_xino;
38288 + br->br_xino = NULL;
38289 + ret = kref_put(&xi->xi_kref, au_xino_release);
38295 +/* ---------------------------------------------------------------------- */
38298 + * xino mount option handlers
38302 +static void xino_clear_xib(struct super_block *sb)
38304 + struct au_sbinfo *sbinfo;
38306 + SiMustWriteLock(sb);
38308 + sbinfo = au_sbi(sb);
38309 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38310 + if (sbinfo->si_xib)
38311 + fput(sbinfo->si_xib);
38312 + sbinfo->si_xib = NULL;
38313 + if (sbinfo->si_xib_buf)
38314 + free_page((unsigned long)sbinfo->si_xib_buf);
38315 + sbinfo->si_xib_buf = NULL;
38318 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38322 + struct au_sbinfo *sbinfo;
38323 + struct file *file;
38324 + struct super_block *xi_sb;
38326 + SiMustWriteLock(sb);
38328 + sbinfo = au_sbi(sb);
38329 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38330 + err = PTR_ERR(file);
38331 + if (IS_ERR(file))
38333 + if (sbinfo->si_xib)
38334 + fput(sbinfo->si_xib);
38335 + sbinfo->si_xib = file;
38336 + sbinfo->si_xread = vfs_readf(file);
38337 + sbinfo->si_xwrite = vfs_writef(file);
38338 + xi_sb = file_inode(file)->i_sb;
38339 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38340 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38342 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38343 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38346 + sbinfo->si_ximaxent /= sizeof(ino_t);
38349 + if (!sbinfo->si_xib_buf)
38350 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38351 + if (unlikely(!sbinfo->si_xib_buf))
38354 + sbinfo->si_xib_last_pindex = 0;
38355 + sbinfo->si_xib_next_bit = 0;
38356 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38358 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38359 + PAGE_SIZE, &pos);
38360 + if (unlikely(err != PAGE_SIZE))
38364 + goto out; /* success */
38367 + if (sbinfo->si_xib_buf)
38368 + free_page((unsigned long)sbinfo->si_xib_buf);
38369 + sbinfo->si_xib_buf = NULL;
38373 + fput(sbinfo->si_xib);
38374 + sbinfo->si_xib = NULL;
38380 +/* xino for each branch */
38381 +static void xino_clear_br(struct super_block *sb)
38383 + aufs_bindex_t bindex, bbot;
38384 + struct au_branch *br;
38386 + bbot = au_sbbot(sb);
38387 + for (bindex = 0; bindex <= bbot; bindex++) {
38388 + br = au_sbr(sb, bindex);
38394 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38395 + aufs_bindex_t bshared)
38397 + struct au_branch *brshared;
38399 + brshared = au_sbr(sb, bshared);
38400 + AuDebugOn(!brshared->br_xino);
38401 + AuDebugOn(!brshared->br_xino->xi_file);
38402 + if (br->br_xino != brshared->br_xino) {
38403 + au_xino_get(brshared);
38405 + br->br_xino = brshared->br_xino;
38409 +struct au_xino_do_set_br {
38410 + vfs_writef_t writef;
38411 + struct au_branch *br;
38413 + aufs_bindex_t bshared;
38416 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38417 + struct au_xino_do_set_br *args)
38420 + struct au_xi_calc calc;
38421 + struct file *file;
38422 + struct au_branch *br;
38423 + struct au_xi_new xinew = {
38428 + xinew.xi = br->br_xino;
38429 + au_xi_calc(sb, args->h_ino, &calc);
38430 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38431 + if (args->bshared >= 0)
38432 + /* shared xino */
38433 + au_xino_set_br_shared(sb, br, args->bshared);
38434 + else if (!xinew.xi) {
38436 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38437 + if (unlikely(err))
38441 + /* force re-creating */
38442 + xinew.xi = br->br_xino;
38443 + xinew.idx = calc.idx;
38444 + mutex_lock(&xinew.xi->xi_mtx);
38445 + file = au_xi_new(sb, &xinew);
38446 + mutex_unlock(&xinew.xi->xi_mtx);
38447 + err = PTR_ERR(file);
38448 + if (IS_ERR(file))
38450 + AuDebugOn(!file);
38452 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38453 + if (unlikely(err))
38461 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38464 + aufs_bindex_t bindex, bbot;
38465 + struct au_xino_do_set_br args;
38466 + struct inode *inode;
38468 + SiMustWriteLock(sb);
38470 + bbot = au_sbbot(sb);
38471 + inode = d_inode(sb->s_root);
38472 + args.writef = au_sbi(sb)->si_xwrite;
38473 + for (bindex = 0; bindex <= bbot; bindex++) {
38474 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38475 + args.br = au_sbr(sb, bindex);
38476 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38477 + err = au_xino_do_set_br(sb, path, &args);
38478 + if (unlikely(err))
38486 +void au_xino_clr(struct super_block *sb)
38488 + struct au_sbinfo *sbinfo;
38490 + au_xigen_clr(sb);
38491 + xino_clear_xib(sb);
38492 + xino_clear_br(sb);
38493 + dbgaufs_brs_del(sb, 0);
38494 + sbinfo = au_sbi(sb);
38495 + /* lvalue, do not call au_mntflags() */
38496 + au_opt_clr(sbinfo->si_mntflags, XINO);
38499 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38502 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38503 + struct qstr *dname, *cur_name;
38504 + struct file *cur_xino;
38505 + struct au_sbinfo *sbinfo;
38506 + struct path *path, *cur_path;
38508 + SiMustWriteLock(sb);
38511 + sbinfo = au_sbi(sb);
38512 + path = &xiopt->file->f_path;
38513 + dentry = path->dentry;
38514 + parent = dget_parent(dentry);
38517 + cur_xino = sbinfo->si_xib;
38519 + cur_path = &cur_xino->f_path;
38520 + cur_dentry = cur_path->dentry;
38521 + cur_parent = dget_parent(cur_dentry);
38522 + cur_name = &cur_dentry->d_name;
38523 + dname = &dentry->d_name;
38524 + skip = (cur_parent == parent
38525 + && au_qstreq(dname, cur_name));
38526 + dput(cur_parent);
38532 + au_opt_set(sbinfo->si_mntflags, XINO);
38533 + err = au_xino_set_xib(sb, path);
38534 + /* si_x{read,write} are set */
38536 + err = au_xigen_set(sb, path);
38538 + err = au_xino_set_br(sb, path);
38540 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38541 + goto out; /* success */
38545 + AuIOErr("failed setting xino(%d).\n", err);
38554 + * create a xinofile at the default place/path.
38556 +struct file *au_xino_def(struct super_block *sb)
38558 + struct file *file;
38560 + struct au_branch *br;
38561 + struct super_block *h_sb;
38562 + struct path path;
38563 + aufs_bindex_t bbot, bindex, bwr;
38566 + bbot = au_sbbot(sb);
38568 + for (bindex = 0; bindex <= bbot; bindex++) {
38569 + br = au_sbr(sb, bindex);
38570 + if (au_br_writable(br->br_perm)
38571 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38578 + file = ERR_PTR(-ENOMEM);
38579 + page = (void *)__get_free_page(GFP_NOFS);
38580 + if (unlikely(!page))
38582 + path.mnt = au_br_mnt(br);
38583 + path.dentry = au_h_dptr(sb->s_root, bwr);
38584 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38585 + file = (void *)p;
38586 + if (!IS_ERR(p)) {
38587 + strcat(p, "/" AUFS_XINO_FNAME);
38588 + AuDbg("%s\n", p);
38589 + file = au_xino_create(sb, p, /*silent*/0);
38591 + free_page((unsigned long)page);
38593 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
38594 + if (IS_ERR(file))
38596 + h_sb = file->f_path.dentry->d_sb;
38597 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38598 + pr_err("xino doesn't support %s(%s)\n",
38599 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38601 + file = ERR_PTR(-EINVAL);
38609 +/* ---------------------------------------------------------------------- */
38612 + * initialize the xinofile for the specified branch @br
38613 + * at the place/path where @base_file indicates.
38614 + * test whether another branch is on the same filesystem or not,
38615 + * if found then share the xinofile with another branch.
38617 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38618 + struct path *base)
38621 + struct au_xino_do_set_br args = {
38626 + args.writef = au_sbi(sb)->si_xwrite;
38627 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38629 + err = au_xino_do_set_br(sb, base, &args);
38630 + if (unlikely(err))
38636 +/* ---------------------------------------------------------------------- */
38639 + * get an unused inode number from bitmap
38641 +ino_t au_xino_new_ino(struct super_block *sb)
38644 + unsigned long *p, pindex, ul, pend;
38645 + struct au_sbinfo *sbinfo;
38646 + struct file *file;
38647 + int free_bit, err;
38649 + if (!au_opt_test(au_mntflags(sb), XINO))
38650 + return iunique(sb, AUFS_FIRST_INO);
38652 + sbinfo = au_sbi(sb);
38653 + mutex_lock(&sbinfo->si_xib_mtx);
38654 + p = sbinfo->si_xib_buf;
38655 + free_bit = sbinfo->si_xib_next_bit;
38656 + if (free_bit < page_bits && !test_bit(free_bit, p))
38657 + goto out; /* success */
38658 + free_bit = find_first_zero_bit(p, page_bits);
38659 + if (free_bit < page_bits)
38660 + goto out; /* success */
38662 + pindex = sbinfo->si_xib_last_pindex;
38663 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38664 + err = xib_pindex(sb, ul);
38665 + if (unlikely(err))
38667 + free_bit = find_first_zero_bit(p, page_bits);
38668 + if (free_bit < page_bits)
38669 + goto out; /* success */
38672 + file = sbinfo->si_xib;
38673 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38674 + for (ul = pindex + 1; ul <= pend; ul++) {
38675 + err = xib_pindex(sb, ul);
38676 + if (unlikely(err))
38678 + free_bit = find_first_zero_bit(p, page_bits);
38679 + if (free_bit < page_bits)
38680 + goto out; /* success */
38685 + set_bit(free_bit, p);
38686 + sbinfo->si_xib_next_bit = free_bit + 1;
38687 + pindex = sbinfo->si_xib_last_pindex;
38688 + mutex_unlock(&sbinfo->si_xib_mtx);
38689 + ino = xib_calc_ino(pindex, free_bit);
38690 + AuDbg("i%lu\n", (unsigned long)ino);
38693 + mutex_unlock(&sbinfo->si_xib_mtx);
38698 +/* for s_op->delete_inode() */
38699 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38702 + unsigned int mnt_flags;
38703 + aufs_bindex_t bindex, bbot, bi;
38704 + unsigned char try_trunc;
38705 + struct au_iinfo *iinfo;
38706 + struct super_block *sb;
38707 + struct au_hinode *hi;
38708 + struct inode *h_inode;
38709 + struct au_branch *br;
38710 + vfs_writef_t xwrite;
38711 + struct au_xi_calc calc;
38712 + struct file *file;
38714 + AuDebugOn(au_is_bad_inode(inode));
38716 + sb = inode->i_sb;
38717 + mnt_flags = au_mntflags(sb);
38718 + if (!au_opt_test(mnt_flags, XINO)
38719 + || inode->i_ino == AUFS_ROOT_INO)
38723 + au_xigen_inc(inode);
38724 + au_xib_clear_bit(inode);
38727 + iinfo = au_ii(inode);
38728 + bindex = iinfo->ii_btop;
38732 + xwrite = au_sbi(sb)->si_xwrite;
38733 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38734 + hi = au_hinode(iinfo, bindex);
38735 + bbot = iinfo->ii_bbot;
38736 + for (; bindex <= bbot; bindex++, hi++) {
38737 + h_inode = hi->hi_inode;
38739 + || (!unlinked && h_inode->i_nlink))
38742 + /* inode may not be revalidated */
38743 + bi = au_br_index(sb, hi->hi_id);
38747 + br = au_sbr(sb, bi);
38748 + au_xi_calc(sb, h_inode->i_ino, &calc);
38749 + file = au_xino_file(br->br_xino, calc.idx);
38750 + if (IS_ERR_OR_NULL(file))
38753 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38754 + if (!err && try_trunc
38755 + && au_test_fs_trunc_xino(au_br_sb(br)))
38756 + xino_try_trunc(sb, br);
38760 +/* ---------------------------------------------------------------------- */
38762 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38764 + int found, total, i;
38767 + total = xi->xi_nondir.total;
38768 + for (i = 0; i < total; i++) {
38769 + if (xi->xi_nondir.array[i] != h_ino)
38778 +static int au_xinondir_expand(struct au_xino *xi)
38783 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38786 + sz = xi->xi_nondir.total * sizeof(ino_t);
38787 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38789 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38790 + /*may_shrink*/0);
38792 + xi->xi_nondir.array = p;
38793 + xi->xi_nondir.total <<= 1;
38794 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38802 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38803 + ino_t h_ino, int idx)
38805 + struct au_xino *xi;
38807 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38808 + xi = au_sbr(sb, bindex)->br_xino;
38809 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38811 + spin_lock(&xi->xi_nondir.spin);
38812 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38813 + xi->xi_nondir.array[idx] = 0;
38814 + spin_unlock(&xi->xi_nondir.spin);
38815 + wake_up_all(&xi->xi_nondir.wqh);
38818 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38821 + int err, found, empty;
38822 + struct au_xino *xi;
38826 + if (!au_opt_test(au_mntflags(sb), XINO))
38827 + goto out; /* no xino */
38829 + xi = au_sbr(sb, bindex)->br_xino;
38832 + spin_lock(&xi->xi_nondir.spin);
38833 + found = au_xinondir_find(xi, h_ino);
38834 + if (found == -1) {
38835 + empty = au_xinondir_find(xi, /*h_ino*/0);
38836 + if (empty == -1) {
38837 + empty = xi->xi_nondir.total;
38838 + err = au_xinondir_expand(xi);
38839 + if (unlikely(err))
38842 + xi->xi_nondir.array[empty] = h_ino;
38845 + spin_unlock(&xi->xi_nondir.spin);
38846 + wait_event(xi->xi_nondir.wqh,
38847 + xi->xi_nondir.array[found] != h_ino);
38852 + spin_unlock(&xi->xi_nondir.spin);
38857 +/* ---------------------------------------------------------------------- */
38859 +int au_xino_path(struct seq_file *seq, struct file *file)
38863 + err = au_seq_path(seq, &file->f_path);
38864 + if (unlikely(err))
38867 +#define Deleted "\\040(deleted)"
38868 + seq->count -= sizeof(Deleted) - 1;
38869 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38870 + sizeof(Deleted) - 1));
38876 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38877 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38878 +++ linux/include/uapi/linux/aufs_type.h 2019-01-28 14:36:12.225751436 +0100
38880 +/* SPDX-License-Identifier: GPL-2.0 */
38882 + * Copyright (C) 2005-2018 Junjiro R. Okajima
38884 + * This program, aufs is free software; you can redistribute it and/or modify
38885 + * it under the terms of the GNU General Public License as published by
38886 + * the Free Software Foundation; either version 2 of the License, or
38887 + * (at your option) any later version.
38889 + * This program is distributed in the hope that it will be useful,
38890 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38891 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38892 + * GNU General Public License for more details.
38894 + * You should have received a copy of the GNU General Public License
38895 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38898 +#ifndef __AUFS_TYPE_H__
38899 +#define __AUFS_TYPE_H__
38901 +#define AUFS_NAME "aufs"
38905 + * define it before including all other headers.
38906 + * sched.h may use pr_* macros before defining "current", so define the
38907 + * no-current version first, and re-define later.
38909 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38910 +#include <linux/sched.h>
38912 +#define pr_fmt(fmt) \
38913 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38914 + (int)sizeof(current->comm), current->comm, current->pid
38916 +#include <stdint.h>
38917 +#include <sys/types.h>
38918 +#endif /* __KERNEL__ */
38920 +#include <linux/limits.h>
38922 +#define AUFS_VERSION "4.19-20181217"
38924 +/* todo? move this to linux-2.6.19/include/magic.h */
38925 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38927 +/* ---------------------------------------------------------------------- */
38929 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38930 +typedef int8_t aufs_bindex_t;
38931 +#define AUFS_BRANCH_MAX 127
38933 +typedef int16_t aufs_bindex_t;
38934 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38935 +#define AUFS_BRANCH_MAX 511
38936 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38937 +#define AUFS_BRANCH_MAX 1023
38938 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38939 +#define AUFS_BRANCH_MAX 32767
38944 +#ifndef AUFS_BRANCH_MAX
38945 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38947 +#endif /* __KERNEL__ */
38949 +/* ---------------------------------------------------------------------- */
38951 +#define AUFS_FSTYPE AUFS_NAME
38953 +#define AUFS_ROOT_INO 2
38954 +#define AUFS_FIRST_INO 11
38956 +#define AUFS_WH_PFX ".wh."
38957 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38958 +#define AUFS_WH_TMP_LEN 4
38959 +/* a limit for rmdir/rename a dir and copyup */
38960 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38961 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38963 + - AUFS_WH_TMP_LEN) /* hex */
38964 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38965 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38966 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38967 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38968 +#define AUFS_DIRWH_DEF 3
38969 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38970 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38971 +#define AUFS_RDBLK_DEF 512 /* bytes */
38972 +#define AUFS_RDHASH_DEF 32
38973 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38974 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38975 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38976 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38977 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38979 +/* pseudo-link maintenace under /proc */
38980 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38981 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38982 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38984 +/* dirren, renamed dir */
38985 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38986 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38987 +/* whiteouted doubly */
38988 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38989 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38991 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38992 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38994 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38995 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38996 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38998 +/* doubly whiteouted */
38999 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39000 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39001 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39003 +/* branch permissions and attributes */
39004 +#define AUFS_BRPERM_RW "rw"
39005 +#define AUFS_BRPERM_RO "ro"
39006 +#define AUFS_BRPERM_RR "rr"
39007 +#define AUFS_BRATTR_COO_REG "coo_reg"
39008 +#define AUFS_BRATTR_COO_ALL "coo_all"
39009 +#define AUFS_BRATTR_FHSM "fhsm"
39010 +#define AUFS_BRATTR_UNPIN "unpin"
39011 +#define AUFS_BRATTR_ICEX "icex"
39012 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39013 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39014 +#define AUFS_BRATTR_ICEX_TR "icextr"
39015 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39016 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39017 +#define AUFS_BRRATTR_WH "wh"
39018 +#define AUFS_BRWATTR_NLWH "nolwh"
39019 +#define AUFS_BRWATTR_MOO "moo"
39021 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39022 +#define AuBrPerm_RO (1 << 1) /* readonly */
39023 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39024 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39026 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39027 +#define AuBrAttr_COO_ALL (1 << 4)
39028 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39030 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39031 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39032 + branch. meaningless since
39033 + linux-3.18-rc1 */
39035 +/* ignore error in copying XATTR */
39036 +#define AuBrAttr_ICEX_SEC (1 << 7)
39037 +#define AuBrAttr_ICEX_SYS (1 << 8)
39038 +#define AuBrAttr_ICEX_TR (1 << 9)
39039 +#define AuBrAttr_ICEX_USR (1 << 10)
39040 +#define AuBrAttr_ICEX_OTH (1 << 11)
39041 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39042 + | AuBrAttr_ICEX_SYS \
39043 + | AuBrAttr_ICEX_TR \
39044 + | AuBrAttr_ICEX_USR \
39045 + | AuBrAttr_ICEX_OTH)
39047 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39048 +#define AuBrRAttr_Mask AuBrRAttr_WH
39050 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39051 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39052 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39054 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39056 +/* #warning test userspace */
39058 +#ifndef CONFIG_AUFS_FHSM
39059 +#undef AuBrAttr_FHSM
39060 +#define AuBrAttr_FHSM 0
39062 +#ifndef CONFIG_AUFS_XATTR
39063 +#undef AuBrAttr_ICEX
39064 +#define AuBrAttr_ICEX 0
39065 +#undef AuBrAttr_ICEX_SEC
39066 +#define AuBrAttr_ICEX_SEC 0
39067 +#undef AuBrAttr_ICEX_SYS
39068 +#define AuBrAttr_ICEX_SYS 0
39069 +#undef AuBrAttr_ICEX_TR
39070 +#define AuBrAttr_ICEX_TR 0
39071 +#undef AuBrAttr_ICEX_USR
39072 +#define AuBrAttr_ICEX_USR 0
39073 +#undef AuBrAttr_ICEX_OTH
39074 +#define AuBrAttr_ICEX_OTH 0
39078 +/* the longest combination */
39079 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39080 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39081 + "+" AUFS_BRATTR_COO_REG \
39082 + "+" AUFS_BRATTR_FHSM \
39083 + "+" AUFS_BRATTR_UNPIN \
39084 + "+" AUFS_BRATTR_ICEX_SEC \
39085 + "+" AUFS_BRATTR_ICEX_SYS \
39086 + "+" AUFS_BRATTR_ICEX_USR \
39087 + "+" AUFS_BRATTR_ICEX_OTH \
39088 + "+" AUFS_BRWATTR_NLWH)
39091 + char a[AuBrPermStrSz];
39092 +} au_br_perm_str_t;
39094 +static inline int au_br_writable(int brperm)
39096 + return brperm & AuBrPerm_RW;
39099 +static inline int au_br_whable(int brperm)
39101 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39104 +static inline int au_br_wh_linkable(int brperm)
39106 + return !(brperm & AuBrWAttr_NoLinkWH);
39109 +static inline int au_br_cmoo(int brperm)
39111 + return brperm & AuBrAttr_CMOO_Mask;
39114 +static inline int au_br_fhsm(int brperm)
39116 + return brperm & AuBrAttr_FHSM;
39119 +/* ---------------------------------------------------------------------- */
39123 + /* readdir in userspace */
39127 + AuCtl_WBR_FD, /* pathconf wrapper */
39128 + AuCtl_IBUSY, /* busy inode */
39129 + AuCtl_MVDOWN, /* move-down */
39130 + AuCtl_BR, /* info about branches */
39131 + AuCtl_FHSM_FD /* connection for fhsm */
39134 +/* borrowed from linux/include/linux/kernel.h */
39136 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39137 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39140 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39142 +#define __aligned(x) __attribute__((aligned(x)))
39147 +#define __packed __attribute__((packed))
39151 +struct au_rdu_cookie {
39156 + uint32_t generation;
39159 +struct au_rdu_ent {
39168 +static inline int au_rdu_len(int nlen)
39170 + /* include the terminating NULL */
39171 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39172 + sizeof(uint64_t));
39175 +union au_rdu_ent_ul {
39176 + struct au_rdu_ent __user *e;
39188 + uint64_t sz; /* AuCtl_RDU */
39189 + uint64_t nent; /* AuCtl_RDU_INO */
39191 + union au_rdu_ent_ul ent;
39192 + uint16_t verify[AufsCtlRduV_End];
39194 + /* input/output */
39198 + union au_rdu_ent_ul tail;
39199 + /* number of entries which were added in a single call */
39204 + struct au_rdu_cookie cookie;
39207 +/* ---------------------------------------------------------------------- */
39209 +/* dirren. the branch is identified by the filename who contains this */
39210 +struct au_drinfo {
39213 + uint8_t oldnamelen;
39214 + uint64_t _padding;
39216 + uint8_t oldname[0];
39219 +struct au_drinfo_fdata {
39221 + struct au_drinfo drinfo;
39224 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39226 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39228 +/* ---------------------------------------------------------------------- */
39230 +struct aufs_wbr_fd {
39235 +/* ---------------------------------------------------------------------- */
39237 +struct aufs_ibusy {
39238 + uint64_t ino, h_ino;
39242 +/* ---------------------------------------------------------------------- */
39244 +/* error code for move-down */
39245 +/* the actual message strings are implemented in aufs-util.git */
39247 + EAU_MVDOWN_OPAQUE = 1,
39248 + EAU_MVDOWN_WHITEOUT,
39249 + EAU_MVDOWN_UPPER,
39250 + EAU_MVDOWN_BOTTOM,
39251 + EAU_MVDOWN_NOUPPER,
39252 + EAU_MVDOWN_NOLOWERBR,
39256 +/* flags for move-down */
39257 +#define AUFS_MVDOWN_DMSG 1
39258 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39259 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39260 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39261 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39262 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39263 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39264 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39265 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39266 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39267 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39268 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39269 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39271 +/* index for move-down */
39273 + AUFS_MVDOWN_UPPER,
39274 + AUFS_MVDOWN_LOWER,
39275 + AUFS_MVDOWN_NARRAY
39279 + * additional info of move-down
39280 + * number of free blocks and inodes.
39281 + * subset of struct kstatfs, but smaller and always 64bit.
39283 +struct aufs_stfs {
39284 + uint64_t f_blocks;
39285 + uint64_t f_bavail;
39286 + uint64_t f_files;
39287 + uint64_t f_ffree;
39290 +struct aufs_stbr {
39291 + int16_t brid; /* optional input */
39292 + int16_t bindex; /* output */
39293 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39296 +struct aufs_mvdown {
39297 + uint32_t flags; /* input/output */
39298 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39299 + int8_t au_errno; /* output */
39302 +/* ---------------------------------------------------------------------- */
39304 +union aufs_brinfo {
39305 + /* PATH_MAX may differ between kernel-space and user-space */
39306 + char _spacer[4096];
39314 +/* ---------------------------------------------------------------------- */
39316 +#define AuCtlType 'A'
39317 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39318 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39319 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39320 + struct aufs_wbr_fd)
39321 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39322 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39323 + struct aufs_mvdown)
39324 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39325 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39327 +#endif /* __AUFS_TYPE_H__ */
39328 SPDX-License-Identifier: GPL-2.0
39329 aufs4.19 loopback patch
39331 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39332 index 9e534a3..74cd74e 100644
39333 --- a/drivers/block/loop.c
39334 +++ b/drivers/block/loop.c
39335 @@ -626,6 +626,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39339 +static struct file *loop_real_file(struct file *file)
39341 + struct file *f = NULL;
39343 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39344 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39348 static void loop_reread_partitions(struct loop_device *lo,
39349 struct block_device *bdev)
39351 @@ -690,6 +699,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39354 struct file *file = NULL, *old_file;
39355 + struct file *f, *virt_file = NULL, *old_virt_file;
39359 @@ -705,12 +715,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39363 + f = loop_real_file(file);
39365 + virt_file = file;
39370 error = loop_validate_file(file, bdev);
39374 old_file = lo->lo_backing_file;
39375 + old_virt_file = lo->lo_backing_virt_file;
39379 @@ -722,6 +739,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39380 blk_mq_freeze_queue(lo->lo_queue);
39381 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39382 lo->lo_backing_file = file;
39383 + lo->lo_backing_virt_file = virt_file;
39384 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39385 mapping_set_gfp_mask(file->f_mapping,
39386 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39387 @@ -729,14 +747,18 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39391 + if (old_virt_file)
39392 + fput(old_virt_file);
39394 loop_reread_partitions(lo, bdev);
39398 mutex_unlock(&loop_ctl_mutex);
39406 @@ -922,7 +944,7 @@ static int loop_prepare_queue(struct loop_device *lo)
39407 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39408 struct block_device *bdev, unsigned int arg)
39410 - struct file *file;
39411 + struct file *file, *f, *virt_file = NULL;
39412 struct inode *inode;
39413 struct address_space *mapping;
39415 @@ -936,6 +958,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39419 + f = loop_real_file(file);
39421 + virt_file = file;
39427 if (lo->lo_state != Lo_unbound)
39428 @@ -968,6 +996,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39429 lo->lo_device = bdev;
39430 lo->lo_flags = lo_flags;
39431 lo->lo_backing_file = file;
39432 + lo->lo_backing_virt_file = virt_file;
39433 lo->transfer = NULL;
39435 lo->lo_sizelimit = 0;
39436 @@ -1001,6 +1030,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39437 mutex_unlock(&loop_ctl_mutex);
39443 /* This is safe: open() is still holding a reference. */
39444 module_put(THIS_MODULE);
39445 @@ -1047,6 +1078,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39446 static int __loop_clr_fd(struct loop_device *lo)
39448 struct file *filp = NULL;
39449 + struct file *virt_filp = lo->lo_backing_virt_file;
39450 gfp_t gfp = lo->old_gfp_mask;
39451 struct block_device *bdev = lo->lo_device;
39453 @@ -1078,6 +1110,7 @@ static int __loop_clr_fd(struct loop_device *lo)
39454 spin_lock_irq(&lo->lo_lock);
39455 lo->lo_state = Lo_rundown;
39456 lo->lo_backing_file = NULL;
39457 + lo->lo_backing_virt_file = NULL;
39458 spin_unlock_irq(&lo->lo_lock);
39460 loop_release_xfer(lo);
39461 @@ -1126,6 +1159,8 @@ static int __loop_clr_fd(struct loop_device *lo)
39470 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39471 index 4d42c7a..a4974ee 100644
39472 --- a/drivers/block/loop.h
39473 +++ b/drivers/block/loop.h
39474 @@ -46,7 +46,7 @@ struct loop_device {
39475 int (*ioctl)(struct loop_device *, int cmd,
39476 unsigned long arg);
39478 - struct file * lo_backing_file;
39479 + struct file * lo_backing_file, *lo_backing_virt_file;
39480 struct block_device *lo_device;
39483 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39484 index 5309874..1a334cf 100644
39485 --- a/fs/aufs/f_op.c
39486 +++ b/fs/aufs/f_op.c
39487 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39488 if (IS_ERR(h_file))
39491 - if (au_test_loopback_kthread()) {
39492 + if (0 && au_test_loopback_kthread()) {
39493 au_warn_loopback(h_file->f_path.dentry->d_sb);
39494 if (file->f_mapping != h_file->f_mapping) {
39495 file->f_mapping = h_file->f_mapping;
39496 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39497 index 3f3577d..3b44158 100644
39498 --- a/fs/aufs/loop.c
39499 +++ b/fs/aufs/loop.c
39500 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39501 symbol_put(loop_backing_file);
39502 au_kfree_try_rcu(au_warn_loopback_array);
39505 +/* ---------------------------------------------------------------------- */
39507 +/* support the loopback block device insude aufs */
39509 +struct file *aufs_real_loop(struct file *file)
39513 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39514 + fi_read_lock(file);
39515 + f = au_hf_top(file);
39516 + fi_read_unlock(file);
39520 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39521 index 05d703d..6bb23c8 100644
39522 --- a/fs/aufs/loop.h
39523 +++ b/fs/aufs/loop.h
39524 @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb);
39526 int au_loopback_init(void);
39527 void au_loopback_fin(void);
39529 +struct file *aufs_real_loop(struct file *file);
39531 +AuStub(struct file *, loop_backing_file, return NULL)
39533 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
39534 struct dentry *h_adding)
39535 AuStubInt0(au_test_loopback_kthread, void)
39536 @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39538 AuStubInt0(au_loopback_init, void)
39539 AuStubVoid(au_loopback_fin, void)
39541 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39542 #endif /* BLK_DEV_LOOP */
39544 #endif /* __KERNEL__ */
39545 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39546 index 777503e..7130061 100644
39547 --- a/fs/aufs/super.c
39548 +++ b/fs/aufs/super.c
39549 @@ -845,7 +845,10 @@ static const struct super_operations aufs_sop = {
39550 .statfs = aufs_statfs,
39551 .put_super = aufs_put_super,
39552 .sync_fs = aufs_sync_fs,
39553 - .remount_fs = aufs_remount_fs
39554 + .remount_fs = aufs_remount_fs,
39555 +#ifdef CONFIG_AUFS_BDEV_LOOP
39556 + .real_loop = aufs_real_loop
39560 /* ---------------------------------------------------------------------- */
39561 diff --git a/include/linux/fs.h b/include/linux/fs.h
39562 index 7fb92a9..cff3ca3 100644
39563 --- a/include/linux/fs.h
39564 +++ b/include/linux/fs.h
39565 @@ -1882,6 +1882,10 @@ struct super_operations {
39566 struct shrink_control *);
39567 long (*free_cached_objects)(struct super_block *,
39568 struct shrink_control *);
39569 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39571 + struct file *(*real_loop)(struct file *);