1 SPDX-License-Identifier: GPL-2.0
2 aufs4.x-rcN kbuild patch
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
26 aufs4.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 6ac000c..16404bb 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
346 aufs4.x-rcN mmap patch
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.x-rcN 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 2018-08-12 23:43:05.450124426 +0200
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 2017-07-29 12:14:25.893041746 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-04-15 08:49:13.394483860 +0200
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 2018-10-23 12:33:35.579375203 +0200
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).
3034 +Thank you very much.
3035 +Donations are always, including future donations, very important and
3036 +helpful for me to keep on developing aufs.
3040 +----------------------------------------
3041 +If you are an experienced user, no explanation is needed. Aufs is
3042 +just a linux filesystem.
3047 +# Local variables: ;
3050 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3051 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3052 +++ linux/fs/aufs/aufs.h 2018-10-23 12:33:35.592708932 +0200
3054 +/* SPDX-License-Identifier: GPL-2.0 */
3056 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3058 + * This program, aufs is free software; you can redistribute it and/or modify
3059 + * it under the terms of the GNU General Public License as published by
3060 + * the Free Software Foundation; either version 2 of the License, or
3061 + * (at your option) any later version.
3063 + * This program is distributed in the hope that it will be useful,
3064 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3065 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3066 + * GNU General Public License for more details.
3068 + * You should have received a copy of the GNU General Public License
3069 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3073 + * all header files
3081 +#define AuStub(type, name, body, ...) \
3082 + static inline type name(__VA_ARGS__) { body; }
3084 +#define AuStubVoid(name, ...) \
3085 + AuStub(void, name, , __VA_ARGS__)
3086 +#define AuStubInt0(name, ...) \
3087 + AuStub(int, name, return 0, __VA_ARGS__)
3091 +#include "branch.h"
3094 +#include "dbgaufs.h"
3095 +#include "dentry.h"
3097 +#include "dirren.h"
3100 +#include "fstype.h"
3105 +#include "module.h"
3109 +#include "sysaufs.h"
3114 +#endif /* __KERNEL__ */
3115 +#endif /* __AUFS_H__ */
3116 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3117 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3118 +++ linux/fs/aufs/branch.c 2018-10-23 12:33:35.592708932 +0200
3120 +// SPDX-License-Identifier: GPL-2.0
3122 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3124 + * This program, aufs is free software; you can redistribute it and/or modify
3125 + * it under the terms of the GNU General Public License as published by
3126 + * the Free Software Foundation; either version 2 of the License, or
3127 + * (at your option) any later version.
3129 + * This program is distributed in the hope that it will be useful,
3130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3132 + * GNU General Public License for more details.
3134 + * You should have received a copy of the GNU General Public License
3135 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3139 + * branch management
3142 +#include <linux/compat.h>
3143 +#include <linux/statfs.h>
3147 + * free a single branch
3149 +static void au_br_do_free(struct au_branch *br)
3152 + struct au_wbr *wbr;
3153 + struct au_dykey **key;
3155 + au_hnotify_fin_br(br);
3156 + /* always, regardless the mount option */
3157 + au_dr_hino_free(&br->br_dirren);
3160 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3161 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3162 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3163 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3167 + for (i = 0; i < AuBrWh_Last; i++)
3168 + dput(wbr->wbr_wh[i]);
3169 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3170 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3173 + if (br->br_fhsm) {
3174 + au_br_fhsm_fin(br->br_fhsm);
3175 + kfree(br->br_fhsm);
3178 + key = br->br_dykey;
3179 + for (i = 0; i < AuBrDynOp; i++, key++)
3185 + /* recursive lock, s_umount of branch's */
3186 + /* synchronize_rcu(); */ /* why? */
3188 + path_put(&br->br_path);
3191 + au_lcnt_wait_for_fin(&br->br_nfiles);
3192 + au_lcnt_wait_for_fin(&br->br_count);
3193 + /* I don't know why, but percpu_refcount requires this */
3194 + /* synchronize_rcu(); */
3199 + * frees all branches
3201 +void au_br_free(struct au_sbinfo *sbinfo)
3203 + aufs_bindex_t bmax;
3204 + struct au_branch **br;
3206 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3208 + bmax = sbinfo->si_bbot + 1;
3209 + br = sbinfo->si_branch;
3211 + au_br_do_free(*br++);
3215 + * find the index of a branch which is specified by @br_id.
3217 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3219 + aufs_bindex_t bindex, bbot;
3221 + bbot = au_sbbot(sb);
3222 + for (bindex = 0; bindex <= bbot; bindex++)
3223 + if (au_sbr_id(sb, bindex) == br_id)
3228 +/* ---------------------------------------------------------------------- */
3234 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3235 + struct dentry *h_root)
3237 + if (unlikely(h_adding == h_root
3238 + || au_test_loopback_overlap(sb, h_adding)))
3240 + if (h_adding->d_sb != h_root->d_sb)
3242 + return au_test_subdir(h_adding, h_root)
3243 + || au_test_subdir(h_root, h_adding);
3247 + * returns a newly allocated branch. @new_nbranch is a number of branches
3248 + * after adding a branch.
3250 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3253 + struct au_branch *add_branch;
3254 + struct dentry *root;
3255 + struct inode *inode;
3259 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3260 + if (unlikely(!add_branch))
3262 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3263 + if (unlikely(!add_branch->br_xino))
3265 + err = au_hnotify_init_br(add_branch, perm);
3266 + if (unlikely(err))
3269 + if (au_br_writable(perm)) {
3270 + /* may be freed separately at changing the branch permission */
3271 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3273 + if (unlikely(!add_branch->br_wbr))
3277 + if (au_br_fhsm(perm)) {
3278 + err = au_fhsm_br_alloc(add_branch);
3279 + if (unlikely(err))
3283 + root = sb->s_root;
3284 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3286 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3288 + inode = d_inode(root);
3289 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3293 + return add_branch; /* success */
3296 + kfree(add_branch->br_wbr);
3298 + au_hnotify_fin_br(add_branch);
3300 + au_xino_put(add_branch);
3302 + kfree(add_branch);
3304 + return ERR_PTR(err);
3308 + * test if the branch permission is legal or not.
3310 +static int test_br(struct inode *inode, int brperm, char *path)
3314 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3319 + pr_err("write permission for readonly mount or inode, %s\n", path);
3327 + * 0: success, the caller will add it
3328 + * plus: success, it is already unified, the caller should ignore it
3331 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3334 + aufs_bindex_t bbot, bindex;
3335 + struct dentry *root, *h_dentry;
3336 + struct inode *inode, *h_inode;
3338 + root = sb->s_root;
3339 + bbot = au_sbbot(sb);
3340 + if (unlikely(bbot >= 0
3341 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3345 + pr_err("%s duplicated\n", add->pathname);
3350 + err = -ENOSPC; /* -E2BIG; */
3351 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3352 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3353 + pr_err("number of branches exceeded %s\n", add->pathname);
3358 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3359 + pr_err("bad index %d\n", add->bindex);
3363 + inode = d_inode(add->path.dentry);
3365 + if (unlikely(!inode->i_nlink)) {
3366 + pr_err("no existence %s\n", add->pathname);
3371 + if (unlikely(inode->i_sb == sb)) {
3372 + pr_err("%s must be outside\n", add->pathname);
3376 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3377 + pr_err("unsupported filesystem, %s (%s)\n",
3378 + add->pathname, au_sbtype(inode->i_sb));
3382 + if (unlikely(inode->i_sb->s_stack_depth)) {
3383 + pr_err("already stacked, %s (%s)\n",
3384 + add->pathname, au_sbtype(inode->i_sb));
3388 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3389 + if (unlikely(err))
3393 + return 0; /* success */
3396 + for (bindex = 0; bindex <= bbot; bindex++)
3397 + if (unlikely(test_overlap(sb, add->path.dentry,
3398 + au_h_dptr(root, bindex)))) {
3399 + pr_err("%s is overlapped\n", add->pathname);
3404 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3405 + h_dentry = au_h_dptr(root, 0);
3406 + h_inode = d_inode(h_dentry);
3407 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3408 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3409 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3410 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3412 + i_uid_read(inode), i_gid_read(inode),
3413 + (inode->i_mode & S_IALLUGO),
3414 + i_uid_read(h_inode), i_gid_read(h_inode),
3415 + (h_inode->i_mode & S_IALLUGO));
3423 + * initialize or clean the whiteouts for an adding branch
3425 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3428 + int err, old_perm;
3429 + aufs_bindex_t bindex;
3430 + struct inode *h_inode;
3431 + struct au_wbr *wbr;
3432 + struct au_hinode *hdir;
3433 + struct dentry *h_dentry;
3435 + err = vfsub_mnt_want_write(au_br_mnt(br));
3436 + if (unlikely(err))
3440 + old_perm = br->br_perm;
3441 + br->br_perm = new_perm;
3444 + bindex = au_br_index(sb, br->br_id);
3445 + if (0 <= bindex) {
3446 + hdir = au_hi(d_inode(sb->s_root), bindex);
3447 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3449 + h_dentry = au_br_dentry(br);
3450 + h_inode = d_inode(h_dentry);
3451 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3454 + err = au_wh_init(br, sb);
3456 + wbr_wh_write_lock(wbr);
3457 + err = au_wh_init(br, sb);
3458 + wbr_wh_write_unlock(wbr);
3461 + au_hn_inode_unlock(hdir);
3463 + inode_unlock(h_inode);
3464 + vfsub_mnt_drop_write(au_br_mnt(br));
3465 + br->br_perm = old_perm;
3467 + if (!err && wbr && !au_br_writable(new_perm)) {
3469 + br->br_wbr = NULL;
3476 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3480 + struct kstatfs kst;
3481 + struct au_wbr *wbr;
3484 + au_rw_init(&wbr->wbr_wh_rwsem);
3485 + atomic_set(&wbr->wbr_wh_running, 0);
3488 + * a limit for rmdir/rename a dir
3489 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3491 + err = vfs_statfs(&br->br_path, &kst);
3492 + if (unlikely(err))
3495 + if (kst.f_namelen >= NAME_MAX)
3496 + err = au_br_init_wh(sb, br, perm);
3498 + pr_err("%pd(%s), unsupported namelen %ld\n",
3500 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3506 +/* initialize a new branch */
3507 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3508 + struct au_opt_add *add)
3511 + struct au_branch *brbase;
3513 + struct inode *h_inode;
3516 + br->br_perm = add->perm;
3517 + br->br_path = add->path; /* set first, path_get() later */
3518 + spin_lock_init(&br->br_dykey_lock);
3519 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3520 + au_lcnt_init(&br->br_count, /*release*/NULL);
3521 + br->br_id = au_new_br_id(sb);
3522 + AuDebugOn(br->br_id < 0);
3524 + /* always, regardless the given option */
3525 + err = au_dr_br_init(sb, br, &add->path);
3526 + if (unlikely(err))
3529 + if (au_br_writable(add->perm)) {
3530 + err = au_wbr_init(br, sb, add->perm);
3531 + if (unlikely(err))
3535 + if (au_opt_test(au_mntflags(sb), XINO)) {
3536 + brbase = au_sbr(sb, 0);
3537 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3539 + h_inode = d_inode(add->path.dentry);
3540 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3541 + if (unlikely(err)) {
3542 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3547 + sysaufs_br_init(br);
3548 + path_get(&br->br_path);
3549 + goto out; /* success */
3552 + memset(&br->br_path, 0, sizeof(br->br_path));
3557 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3558 + struct au_branch *br, aufs_bindex_t bbot,
3559 + aufs_bindex_t amount)
3561 + struct au_branch **brp;
3563 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3565 + brp = sbinfo->si_branch + bindex;
3566 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3568 + sbinfo->si_bbot++;
3569 + if (unlikely(bbot < 0))
3570 + sbinfo->si_bbot = 0;
3573 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3574 + aufs_bindex_t bbot, aufs_bindex_t amount)
3576 + struct au_hdentry *hdp;
3578 + AuRwMustWriteLock(&dinfo->di_rwsem);
3580 + hdp = au_hdentry(dinfo, bindex);
3581 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3582 + au_h_dentry_init(hdp);
3584 + if (unlikely(bbot < 0))
3585 + dinfo->di_btop = 0;
3588 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3589 + aufs_bindex_t bbot, aufs_bindex_t amount)
3591 + struct au_hinode *hip;
3593 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3595 + hip = au_hinode(iinfo, bindex);
3596 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3597 + au_hinode_init(hip);
3599 + if (unlikely(bbot < 0))
3600 + iinfo->ii_btop = 0;
3603 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3604 + aufs_bindex_t bindex)
3606 + struct dentry *root, *h_dentry;
3607 + struct inode *root_inode, *h_inode;
3608 + aufs_bindex_t bbot, amount;
3610 + root = sb->s_root;
3611 + root_inode = d_inode(root);
3612 + bbot = au_sbbot(sb);
3613 + amount = bbot + 1 - bindex;
3614 + h_dentry = au_br_dentry(br);
3615 + au_sbilist_lock();
3616 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3617 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3618 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3619 + au_set_h_dptr(root, bindex, dget(h_dentry));
3620 + h_inode = d_inode(h_dentry);
3621 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3622 + au_sbilist_unlock();
3625 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3628 + aufs_bindex_t bbot, add_bindex;
3629 + struct dentry *root, *h_dentry;
3630 + struct inode *root_inode;
3631 + struct au_branch *add_branch;
3633 + root = sb->s_root;
3634 + root_inode = d_inode(root);
3635 + IMustLock(root_inode);
3636 + IiMustWriteLock(root_inode);
3637 + err = test_add(sb, add, remount);
3638 + if (unlikely(err < 0))
3642 + goto out; /* success */
3645 + bbot = au_sbbot(sb);
3646 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3647 + err = PTR_ERR(add_branch);
3648 + if (IS_ERR(add_branch))
3651 + err = au_br_init(add_branch, sb, add);
3652 + if (unlikely(err)) {
3653 + au_br_do_free(add_branch);
3657 + add_bindex = add->bindex;
3658 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3659 + au_br_do_add(sb, add_branch, add_bindex);
3660 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3661 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3663 + h_dentry = add->path.dentry;
3664 + if (!add_bindex) {
3665 + au_cpup_attr_all(root_inode, /*force*/1);
3666 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3668 + au_add_nlink(root_inode, d_inode(h_dentry));
3674 +/* ---------------------------------------------------------------------- */
3676 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3677 + unsigned long long max __maybe_unused,
3680 + unsigned long long n;
3681 + struct file **p, *f;
3682 + struct hlist_bl_head *files;
3683 + struct hlist_bl_node *pos;
3684 + struct au_finfo *finfo;
3688 + files = &au_sbi(sb)->si_files;
3689 + hlist_bl_lock(files);
3690 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3691 + f = finfo->fi_file;
3693 + && !special_file(file_inode(f)->i_mode)) {
3697 + AuDebugOn(n > max);
3700 + hlist_bl_unlock(files);
3705 +static struct file **au_farray_alloc(struct super_block *sb,
3706 + unsigned long long *max)
3708 + struct au_sbinfo *sbi;
3711 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3712 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3715 +static void au_farray_free(struct file **a, unsigned long long max)
3717 + unsigned long long ull;
3719 + for (ull = 0; ull < max; ull++)
3725 +/* ---------------------------------------------------------------------- */
3731 +/* to show the line number, do not make it inlined function */
3732 +#define AuVerbose(do_info, fmt, ...) do { \
3734 + pr_info(fmt, ##__VA_ARGS__); \
3737 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3738 + aufs_bindex_t bbot)
3740 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3743 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3744 + aufs_bindex_t bbot)
3746 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3750 + * test if the branch is deletable or not.
3752 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3753 + unsigned int sigen, const unsigned int verbose)
3755 + int err, i, j, ndentry;
3756 + aufs_bindex_t btop, bbot;
3757 + struct au_dcsub_pages dpages;
3758 + struct au_dpage *dpage;
3761 + err = au_dpages_init(&dpages, GFP_NOFS);
3762 + if (unlikely(err))
3764 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3765 + if (unlikely(err))
3768 + for (i = 0; !err && i < dpages.ndpage; i++) {
3769 + dpage = dpages.dpages + i;
3770 + ndentry = dpage->ndentry;
3771 + for (j = 0; !err && j < ndentry; j++) {
3772 + d = dpage->dentries[j];
3773 + AuDebugOn(au_dcount(d) <= 0);
3774 + if (!au_digen_test(d, sigen)) {
3775 + di_read_lock_child(d, AuLock_IR);
3776 + if (unlikely(au_dbrange_test(d))) {
3777 + di_read_unlock(d, AuLock_IR);
3781 + di_write_lock_child(d);
3782 + if (unlikely(au_dbrange_test(d))) {
3783 + di_write_unlock(d);
3786 + err = au_reval_dpath(d, sigen);
3788 + di_downgrade_lock(d, AuLock_IR);
3790 + di_write_unlock(d);
3795 + /* AuDbgDentry(d); */
3796 + btop = au_dbtop(d);
3797 + bbot = au_dbbot(d);
3798 + if (btop <= bindex
3800 + && au_h_dptr(d, bindex)
3801 + && au_test_dbusy(d, btop, bbot)) {
3803 + AuVerbose(verbose, "busy %pd\n", d);
3806 + di_read_unlock(d, AuLock_IR);
3811 + au_dpages_free(&dpages);
3816 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3817 + unsigned int sigen, const unsigned int verbose)
3820 + unsigned long long max, ull;
3821 + struct inode *i, **array;
3822 + aufs_bindex_t btop, bbot;
3824 + array = au_iarray_alloc(sb, &max);
3825 + err = PTR_ERR(array);
3826 + if (IS_ERR(array))
3830 + AuDbg("b%d\n", bindex);
3831 + for (ull = 0; !err && ull < max; ull++) {
3835 + if (i->i_ino == AUFS_ROOT_INO)
3838 + /* AuDbgInode(i); */
3839 + if (au_iigen(i, NULL) == sigen)
3840 + ii_read_lock_child(i);
3842 + ii_write_lock_child(i);
3843 + err = au_refresh_hinode_self(i);
3846 + ii_downgrade_lock(i);
3848 + ii_write_unlock(i);
3853 + btop = au_ibtop(i);
3854 + bbot = au_ibbot(i);
3855 + if (btop <= bindex
3857 + && au_h_iptr(i, bindex)
3858 + && au_test_ibusy(i, btop, bbot)) {
3860 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3863 + ii_read_unlock(i);
3865 + au_iarray_free(array, max);
3871 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3872 + const unsigned int verbose)
3875 + unsigned int sigen;
3877 + sigen = au_sigen(root->d_sb);
3878 + DiMustNoWaiters(root);
3879 + IiMustNoWaiters(d_inode(root));
3880 + di_write_unlock(root);
3881 + err = test_dentry_busy(root, bindex, sigen, verbose);
3883 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3884 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3889 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3890 + struct file **to_free, int *idx)
3893 + unsigned char matched, root;
3894 + aufs_bindex_t bindex, bbot;
3895 + struct au_fidir *fidir;
3896 + struct au_hfile *hfile;
3899 + root = IS_ROOT(file->f_path.dentry);
3902 + to_free[*idx] = file;
3908 + fidir = au_fi(file)->fi_hdir;
3909 + AuDebugOn(!fidir);
3910 + bbot = au_fbbot_dir(file);
3911 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3912 + hfile = fidir->fd_hfile + bindex;
3913 + if (!hfile->hf_file)
3916 + if (hfile->hf_br->br_id == br_id) {
3928 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3929 + struct file **to_free, int opened)
3932 + unsigned long long ull, max;
3933 + aufs_bindex_t btop;
3934 + struct file *file, **array;
3935 + struct dentry *root;
3936 + struct au_hfile *hfile;
3938 + array = au_farray_alloc(sb, &max);
3939 + err = PTR_ERR(array);
3940 + if (IS_ERR(array))
3945 + root = sb->s_root;
3946 + di_write_unlock(root);
3947 + for (ull = 0; ull < max; ull++) {
3948 + file = array[ull];
3949 + if (unlikely(!file))
3952 + /* AuDbg("%pD\n", file); */
3953 + fi_read_lock(file);
3954 + btop = au_fbtop(file);
3955 + if (!d_is_dir(file->f_path.dentry)) {
3956 + hfile = &au_fi(file)->fi_htop;
3957 + if (hfile->hf_br->br_id == br_id)
3960 + err = test_dir_busy(file, br_id, to_free, &idx);
3961 + fi_read_unlock(file);
3962 + if (unlikely(err))
3965 + di_write_lock_child(root);
3966 + au_farray_free(array, max);
3967 + AuDebugOn(idx > opened);
3973 +static void br_del_file(struct file **to_free, unsigned long long opened,
3974 + aufs_bindex_t br_id)
3976 + unsigned long long ull;
3977 + aufs_bindex_t bindex, btop, bbot, bfound;
3978 + struct file *file;
3979 + struct au_fidir *fidir;
3980 + struct au_hfile *hfile;
3982 + for (ull = 0; ull < opened; ull++) {
3983 + file = to_free[ull];
3984 + if (unlikely(!file))
3987 + /* AuDbg("%pD\n", file); */
3988 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3990 + fidir = au_fi(file)->fi_hdir;
3991 + AuDebugOn(!fidir);
3992 + fi_write_lock(file);
3993 + btop = au_fbtop(file);
3994 + bbot = au_fbbot_dir(file);
3995 + for (bindex = btop; bindex <= bbot; bindex++) {
3996 + hfile = fidir->fd_hfile + bindex;
3997 + if (!hfile->hf_file)
4000 + if (hfile->hf_br->br_id == br_id) {
4005 + AuDebugOn(bfound < 0);
4006 + au_set_h_fptr(file, bfound, NULL);
4007 + if (bfound == btop) {
4008 + for (btop++; btop <= bbot; btop++)
4009 + if (au_hf_dir(file, btop)) {
4010 + au_set_fbtop(file, btop);
4014 + fi_write_unlock(file);
4018 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4019 + const aufs_bindex_t bindex,
4020 + const aufs_bindex_t bbot)
4022 + struct au_branch **brp, **p;
4024 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4026 + brp = sbinfo->si_branch + bindex;
4027 + if (bindex < bbot)
4028 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4029 + sbinfo->si_branch[0 + bbot] = NULL;
4030 + sbinfo->si_bbot--;
4032 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4035 + sbinfo->si_branch = p;
4036 + /* harmless error */
4039 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4040 + const aufs_bindex_t bbot)
4042 + struct au_hdentry *hdp, *p;
4044 + AuRwMustWriteLock(&dinfo->di_rwsem);
4046 + hdp = au_hdentry(dinfo, bindex);
4047 + if (bindex < bbot)
4048 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4049 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4052 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4055 + dinfo->di_hdentry = p;
4056 + /* harmless error */
4059 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4060 + const aufs_bindex_t bbot)
4062 + struct au_hinode *hip, *p;
4064 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4066 + hip = au_hinode(iinfo, bindex);
4067 + if (bindex < bbot)
4068 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4069 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4072 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4075 + iinfo->ii_hinode = p;
4076 + /* harmless error */
4079 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4080 + struct au_branch *br)
4082 + aufs_bindex_t bbot;
4083 + struct au_sbinfo *sbinfo;
4084 + struct dentry *root, *h_root;
4085 + struct inode *inode, *h_inode;
4086 + struct au_hinode *hinode;
4088 + SiMustWriteLock(sb);
4090 + root = sb->s_root;
4091 + inode = d_inode(root);
4092 + sbinfo = au_sbi(sb);
4093 + bbot = sbinfo->si_bbot;
4095 + h_root = au_h_dptr(root, bindex);
4096 + hinode = au_hi(inode, bindex);
4097 + h_inode = au_igrab(hinode->hi_inode);
4100 + au_sbilist_lock();
4101 + au_br_do_del_brp(sbinfo, bindex, bbot);
4102 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4103 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4104 + au_sbilist_unlock();
4106 + /* ignore an error */
4107 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4111 + au_br_do_free(br);
4114 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4115 + unsigned long long max, void *arg)
4120 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4123 + unsigned long long opened;
4124 + unsigned int mnt_flags;
4125 + aufs_bindex_t bindex, bbot, br_id;
4126 + unsigned char do_wh, verbose;
4127 + struct au_branch *br;
4128 + struct au_wbr *wbr;
4129 + struct dentry *root;
4130 + struct file **to_free;
4135 + root = sb->s_root;
4136 + bindex = au_find_dbindex(root, del->h_path.dentry);
4139 + goto out; /* success */
4141 + pr_err("%s no such branch\n", del->pathname);
4144 + AuDbg("bindex b%d\n", bindex);
4147 + mnt_flags = au_mntflags(sb);
4148 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4149 + bbot = au_sbbot(sb);
4150 + if (unlikely(!bbot)) {
4151 + AuVerbose(verbose, "no more branches left\n");
4155 + br = au_sbr(sb, bindex);
4156 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4157 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4158 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4162 + br_id = br->br_id;
4163 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4164 + if (unlikely(opened)) {
4165 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4166 + err = PTR_ERR(to_free);
4167 + if (IS_ERR(to_free))
4170 + err = test_file_busy(sb, br_id, to_free, opened);
4171 + if (unlikely(err)) {
4172 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4178 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4180 + /* instead of WbrWhMustWriteLock(wbr) */
4181 + SiMustWriteLock(sb);
4182 + for (i = 0; i < AuBrWh_Last; i++) {
4183 + dput(wbr->wbr_wh[i]);
4184 + wbr->wbr_wh[i] = NULL;
4188 + err = test_children_busy(root, bindex, verbose);
4189 + if (unlikely(err)) {
4198 + * now we confirmed the branch is deletable.
4199 + * let's free the remaining opened dirs on the branch.
4201 + di_write_unlock(root);
4202 + br_del_file(to_free, opened, br_id);
4203 + di_write_lock_child(root);
4206 + sysaufs_brs_del(sb, bindex); /* remove successors */
4207 + dbgaufs_xino_del(br); /* remove one */
4208 + au_br_do_del(sb, bindex, br);
4209 + sysaufs_brs_add(sb, bindex); /* append successors */
4210 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4213 + au_cpup_attr_all(d_inode(root), /*force*/1);
4214 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4216 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4217 + if (au_opt_test(mnt_flags, PLINK))
4218 + au_plink_half_refresh(sb, br_id);
4220 + goto out; /* success */
4224 + rerr = au_br_init_wh(sb, br, br->br_perm);
4226 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4227 + del->pathname, rerr);
4230 + au_farray_free(to_free, opened);
4234 +/* ---------------------------------------------------------------------- */
4236 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4239 + aufs_bindex_t btop, bbot;
4240 + struct aufs_ibusy ibusy;
4241 + struct inode *inode, *h_inode;
4244 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4247 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4249 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4250 + if (unlikely(err)) {
4257 + si_read_lock(sb, AuLock_FLUSH);
4258 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4262 + ibusy.h_ino = 0; /* invalid */
4263 + inode = ilookup(sb, ibusy.ino);
4265 + || inode->i_ino == AUFS_ROOT_INO
4266 + || au_is_bad_inode(inode))
4269 + ii_read_lock_child(inode);
4270 + btop = au_ibtop(inode);
4271 + bbot = au_ibbot(inode);
4272 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4273 + h_inode = au_h_iptr(inode, ibusy.bindex);
4274 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4275 + ibusy.h_ino = h_inode->i_ino;
4277 + ii_read_unlock(inode);
4281 + si_read_unlock(sb);
4283 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4284 + if (unlikely(err)) {
4293 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4295 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4298 +#ifdef CONFIG_COMPAT
4299 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4301 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4305 +/* ---------------------------------------------------------------------- */
4308 + * change a branch permission
4311 +static void au_warn_ima(void)
4314 + /* since it doesn't support mark_files_ro() */
4315 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4319 +static int do_need_sigen_inc(int a, int b)
4321 + return au_br_whable(a) && !au_br_whable(b);
4324 +static int need_sigen_inc(int old, int new)
4326 + return do_need_sigen_inc(old, new)
4327 + || do_need_sigen_inc(new, old);
4330 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4333 + unsigned int mnt_flags;
4334 + unsigned long long ull, max;
4335 + aufs_bindex_t br_id;
4336 + unsigned char verbose, writer;
4337 + struct file *file, *hf, **array;
4338 + struct au_hfile *hfile;
4340 + mnt_flags = au_mntflags(sb);
4341 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4343 + array = au_farray_alloc(sb, &max);
4344 + err = PTR_ERR(array);
4345 + if (IS_ERR(array))
4349 + br_id = au_sbr_id(sb, bindex);
4350 + for (ull = 0; ull < max; ull++) {
4351 + file = array[ull];
4352 + if (unlikely(!file))
4355 + /* AuDbg("%pD\n", file); */
4356 + fi_read_lock(file);
4357 + if (unlikely(au_test_mmapped(file))) {
4359 + AuVerbose(verbose, "mmapped %pD\n", file);
4361 + FiMustNoWaiters(file);
4362 + fi_read_unlock(file);
4366 + hfile = &au_fi(file)->fi_htop;
4367 + hf = hfile->hf_file;
4368 + if (!d_is_reg(file->f_path.dentry)
4369 + || !(file->f_mode & FMODE_WRITE)
4370 + || hfile->hf_br->br_id != br_id
4371 + || !(hf->f_mode & FMODE_WRITE))
4372 + array[ull] = NULL;
4378 + FiMustNoWaiters(file);
4379 + fi_read_unlock(file);
4387 + for (ull = 0; ull < max; ull++) {
4388 + file = array[ull];
4392 + /* todo: already flushed? */
4394 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4395 + * approach which resets f_mode and calls mnt_drop_write() and
4396 + * file_release_write() for each file, because the branch
4397 + * attribute in aufs world is totally different from the native
4400 + /* fi_read_lock(file); */
4401 + hfile = &au_fi(file)->fi_htop;
4402 + hf = hfile->hf_file;
4403 + /* fi_read_unlock(file); */
4404 + spin_lock(&hf->f_lock);
4405 + writer = !!(hf->f_mode & FMODE_WRITER);
4406 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4407 + spin_unlock(&hf->f_lock);
4409 + put_write_access(file_inode(hf));
4410 + __mnt_drop_write(hf->f_path.mnt);
4415 + au_farray_free(array, max);
4421 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4425 + aufs_bindex_t bindex;
4426 + struct dentry *root;
4427 + struct au_branch *br;
4428 + struct au_br_fhsm *bf;
4430 + root = sb->s_root;
4431 + bindex = au_find_dbindex(root, mod->h_root);
4434 + return 0; /* success */
4436 + pr_err("%s no such branch\n", mod->path);
4439 + AuDbg("bindex b%d\n", bindex);
4441 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4442 + if (unlikely(err))
4445 + br = au_sbr(sb, bindex);
4446 + AuDebugOn(mod->h_root != au_br_dentry(br));
4447 + if (br->br_perm == mod->perm)
4448 + return 0; /* success */
4450 + /* pre-allocate for non-fhsm --> fhsm */
4452 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4453 + err = au_fhsm_br_alloc(br);
4454 + if (unlikely(err))
4457 + br->br_fhsm = NULL;
4460 + if (au_br_writable(br->br_perm)) {
4461 + /* remove whiteout base */
4462 + err = au_br_init_wh(sb, br, mod->perm);
4463 + if (unlikely(err))
4466 + if (!au_br_writable(mod->perm)) {
4467 + /* rw --> ro, file might be mmapped */
4468 + DiMustNoWaiters(root);
4469 + IiMustNoWaiters(d_inode(root));
4470 + di_write_unlock(root);
4471 + err = au_br_mod_files_ro(sb, bindex);
4472 + /* aufs_write_lock() calls ..._child() */
4473 + di_write_lock_child(root);
4475 + if (unlikely(err)) {
4477 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4480 + rerr = au_wbr_init(br, sb, br->br_perm);
4481 + if (unlikely(rerr)) {
4482 + AuIOErr("nested error %d (%d)\n",
4484 + br->br_perm = mod->perm;
4488 + } else if (au_br_writable(mod->perm)) {
4491 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4493 + err = au_wbr_init(br, sb, mod->perm);
4494 + if (unlikely(err)) {
4495 + kfree(br->br_wbr);
4496 + br->br_wbr = NULL;
4500 + if (unlikely(err))
4503 + if (au_br_fhsm(br->br_perm)) {
4504 + if (!au_br_fhsm(mod->perm)) {
4505 + /* fhsm --> non-fhsm */
4506 + au_br_fhsm_fin(br->br_fhsm);
4507 + kfree(br->br_fhsm);
4508 + br->br_fhsm = NULL;
4510 + } else if (au_br_fhsm(mod->perm))
4511 + /* non-fhsm --> fhsm */
4514 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4515 + br->br_perm = mod->perm;
4516 + goto out; /* success */
4525 +/* ---------------------------------------------------------------------- */
4527 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4530 + struct kstatfs kstfs;
4532 + err = vfs_statfs(&br->br_path, &kstfs);
4534 + stfs->f_blocks = kstfs.f_blocks;
4535 + stfs->f_bavail = kstfs.f_bavail;
4536 + stfs->f_files = kstfs.f_files;
4537 + stfs->f_ffree = kstfs.f_ffree;
4542 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4543 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4544 +++ linux/fs/aufs/branch.h 2018-10-23 12:33:35.592708932 +0200
4546 +/* SPDX-License-Identifier: GPL-2.0 */
4548 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4550 + * This program, aufs is free software; you can redistribute it and/or modify
4551 + * it under the terms of the GNU General Public License as published by
4552 + * the Free Software Foundation; either version 2 of the License, or
4553 + * (at your option) any later version.
4555 + * This program is distributed in the hope that it will be useful,
4556 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4557 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4558 + * GNU General Public License for more details.
4560 + * You should have received a copy of the GNU General Public License
4561 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4565 + * branch filesystems and xino for them
4568 +#ifndef __AUFS_BRANCH_H__
4569 +#define __AUFS_BRANCH_H__
4573 +#include <linux/mount.h>
4574 +#include "dirren.h"
4580 +/* ---------------------------------------------------------------------- */
4584 + struct file **xi_file;
4585 + unsigned int xi_nfile;
4591 + /* reserved for future use */
4592 + /* unsigned long *bitmap; */
4593 + wait_queue_head_t wqh;
4596 + struct mutex xi_mtx; /* protects xi_file array */
4597 + /* reserved for future use */
4598 + /* wait_queue_head_t xi_wq; */
4599 + /* atomic_t xi_pending; */
4601 + atomic_t xi_truncating;
4603 + struct kref xi_kref;
4606 +/* File-based Hierarchical Storage Management */
4607 +struct au_br_fhsm {
4608 +#ifdef CONFIG_AUFS_FHSM
4609 + struct mutex bf_lock;
4610 + unsigned long bf_jiffy;
4611 + struct aufs_stfs bf_stfs;
4616 +/* members for writable branch only */
4617 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4619 + struct au_rwsem wbr_wh_rwsem;
4620 + struct dentry *wbr_wh[AuBrWh_Last];
4621 + atomic_t wbr_wh_running;
4622 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4623 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4624 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4627 + unsigned long long wbr_bytes;
4630 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4631 +#define AuBrDynOp (AuDyLast * 4)
4633 +#ifdef CONFIG_AUFS_HFSNOTIFY
4634 +/* support for asynchronous destruction */
4635 +struct au_br_hfsnotify {
4636 + struct fsnotify_group *hfsn_group;
4640 +/* sysfs entries */
4641 +struct au_brsysfs {
4643 + struct attribute attr;
4652 +/* protected by superblock rwsem */
4654 + struct au_xino *br_xino;
4656 + aufs_bindex_t br_id;
4659 + struct path br_path;
4660 + spinlock_t br_dykey_lock;
4661 + struct au_dykey *br_dykey[AuBrDynOp];
4662 + au_lcnt_t br_nfiles; /* opened files */
4663 + au_lcnt_t br_count; /* in-use for other */
4665 + struct au_wbr *br_wbr;
4666 + struct au_br_fhsm *br_fhsm;
4668 +#ifdef CONFIG_AUFS_HFSNOTIFY
4669 + struct au_br_hfsnotify *br_hfsn;
4672 +#ifdef CONFIG_SYSFS
4673 + /* entries under sysfs per mount-point */
4674 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4677 +#ifdef CONFIG_DEBUG_FS
4678 + struct dentry *br_dbgaufs; /* xino */
4681 + struct au_dr_br br_dirren;
4684 +/* ---------------------------------------------------------------------- */
4686 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4688 + return br->br_path.mnt;
4691 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4693 + return br->br_path.dentry;
4696 +static inline struct super_block *au_br_sb(struct au_branch *br)
4698 + return au_br_mnt(br)->mnt_sb;
4701 +static inline int au_br_rdonly(struct au_branch *br)
4703 + return (sb_rdonly(au_br_sb(br))
4704 + || !au_br_writable(br->br_perm))
4708 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4710 +#ifdef CONFIG_AUFS_HNOTIFY
4711 + return !(brperm & AuBrPerm_RR);
4717 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4719 + int err, exec_flag;
4722 + exec_flag = oflag & __FMODE_EXEC;
4723 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4729 +static inline void au_xino_get(struct au_branch *br)
4731 + struct au_xino *xi;
4735 + kref_get(&xi->xi_kref);
4738 +static inline int au_xino_count(struct au_branch *br)
4741 + struct au_xino *xi;
4746 + v = kref_read(&xi->xi_kref);
4751 +/* ---------------------------------------------------------------------- */
4755 +void au_br_free(struct au_sbinfo *sinfo);
4756 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4758 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4760 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4761 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4762 +#ifdef CONFIG_COMPAT
4763 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4766 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4769 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4772 +static const loff_t au_loff_max = LLONG_MAX;
4774 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4775 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent);
4776 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4777 + struct file *copy_src);
4779 + struct au_xino *xi; /* switch between xino and xigen */
4781 + struct path *base;
4782 + struct file *copy_src;
4784 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4786 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4788 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4790 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4792 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4793 + size_t size, loff_t *pos);
4795 +int au_xib_trunc(struct super_block *sb);
4796 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4798 +struct au_xino *au_xino_alloc(unsigned int nfile);
4799 +int au_xino_put(struct au_branch *br);
4800 +struct file *au_xino_file1(struct au_xino *xi);
4802 +struct au_opt_xino;
4803 +void au_xino_clr(struct super_block *sb);
4804 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4805 +struct file *au_xino_def(struct super_block *sb);
4806 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4807 + struct path *base);
4809 +ino_t au_xino_new_ino(struct super_block *sb);
4810 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4812 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4813 + ino_t h_ino, int idx);
4814 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4817 +int au_xino_path(struct seq_file *seq, struct file *file);
4819 +/* ---------------------------------------------------------------------- */
4821 +/* @idx is signed to accept -1 meaning the first file */
4822 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4824 + struct file *file;
4831 + if (idx < xi->xi_nfile)
4832 + file = xi->xi_file[idx];
4834 + file = au_xino_file1(xi);
4840 +/* ---------------------------------------------------------------------- */
4842 +/* Superblock to branch */
4844 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4846 + return au_sbr(sb, bindex)->br_id;
4850 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4852 + return au_br_mnt(au_sbr(sb, bindex));
4856 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4858 + return au_br_sb(au_sbr(sb, bindex));
4861 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4863 + return au_sbr(sb, bindex)->br_perm;
4866 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4868 + return au_br_whable(au_sbr_perm(sb, bindex));
4871 +/* ---------------------------------------------------------------------- */
4873 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4874 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4875 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4876 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4878 +#define wbr_wh_read_trylock_nested(wbr) \
4879 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4880 +#define wbr_wh_write_trylock_nested(wbr) \
4881 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4884 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4885 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4886 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4888 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4889 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4890 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4892 +/* ---------------------------------------------------------------------- */
4894 +#ifdef CONFIG_AUFS_FHSM
4895 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4897 + mutex_init(&brfhsm->bf_lock);
4898 + brfhsm->bf_jiffy = 0;
4899 + brfhsm->bf_readable = 0;
4902 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4904 + mutex_destroy(&brfhsm->bf_lock);
4907 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4908 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4911 +#endif /* __KERNEL__ */
4912 +#endif /* __AUFS_BRANCH_H__ */
4913 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4914 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4915 +++ linux/fs/aufs/conf.mk 2018-06-04 09:08:09.181412645 +0200
4917 +# SPDX-License-Identifier: GPL-2.0
4919 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4923 +AuConfStr += ${1}=${${1}}
4927 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4929 + HNOTIFY HFSNOTIFY \
4941 +$(foreach i, ${AuConfAll}, \
4942 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4944 +AuConfName = ${obj}/conf.str
4945 +${AuConfName}.tmp: FORCE
4946 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4947 +${AuConfName}: ${AuConfName}.tmp
4948 + @diff -q $< $@ > /dev/null 2>&1 || { \
4949 + echo ' GEN ' $@; \
4953 +clean-files += ${AuConfName} ${AuConfName}.tmp
4954 +${obj}/sysfs.o: ${AuConfName}
4956 +-include ${srctree}/${src}/conf_priv.mk
4957 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4958 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4959 +++ linux/fs/aufs/cpup.c 2018-10-23 12:33:35.596042364 +0200
4961 +// SPDX-License-Identifier: GPL-2.0
4963 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4965 + * This program, aufs is free software; you can redistribute it and/or modify
4966 + * it under the terms of the GNU General Public License as published by
4967 + * the Free Software Foundation; either version 2 of the License, or
4968 + * (at your option) any later version.
4970 + * This program is distributed in the hope that it will be useful,
4971 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4972 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4973 + * GNU General Public License for more details.
4975 + * You should have received a copy of the GNU General Public License
4976 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4980 + * copy-up functions, see wbr_policy.c for copy-down
4983 +#include <linux/fs_stack.h>
4984 +#include <linux/mm.h>
4985 +#include <linux/task_work.h>
4988 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4990 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4991 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4993 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4995 + dst->i_flags |= iflags & ~mask;
4996 + if (au_test_fs_notime(dst->i_sb))
4997 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
5000 +void au_cpup_attr_timesizes(struct inode *inode)
5002 + struct inode *h_inode;
5004 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5005 + fsstack_copy_attr_times(inode, h_inode);
5006 + fsstack_copy_inode_size(inode, h_inode);
5009 +void au_cpup_attr_nlink(struct inode *inode, int force)
5011 + struct inode *h_inode;
5012 + struct super_block *sb;
5013 + aufs_bindex_t bindex, bbot;
5016 + bindex = au_ibtop(inode);
5017 + h_inode = au_h_iptr(inode, bindex);
5019 + && !S_ISDIR(h_inode->i_mode)
5020 + && au_opt_test(au_mntflags(sb), PLINK)
5021 + && au_plink_test(inode))
5025 + * 0 can happen in revalidating.
5026 + * h_inode->i_mutex may not be held here, but it is harmless since once
5027 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5029 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5030 + * the incorrect link count.
5032 + set_nlink(inode, h_inode->i_nlink);
5035 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5036 + * it may includes whplink directory.
5038 + if (S_ISDIR(h_inode->i_mode)) {
5039 + bbot = au_ibbot(inode);
5040 + for (bindex++; bindex <= bbot; bindex++) {
5041 + h_inode = au_h_iptr(inode, bindex);
5043 + au_add_nlink(inode, h_inode);
5048 +void au_cpup_attr_changeable(struct inode *inode)
5050 + struct inode *h_inode;
5052 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5053 + inode->i_mode = h_inode->i_mode;
5054 + inode->i_uid = h_inode->i_uid;
5055 + inode->i_gid = h_inode->i_gid;
5056 + au_cpup_attr_timesizes(inode);
5057 + au_cpup_attr_flags(inode, h_inode->i_flags);
5060 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5062 + struct au_iinfo *iinfo = au_ii(inode);
5064 + IiMustWriteLock(inode);
5066 + iinfo->ii_higen = h_inode->i_generation;
5067 + iinfo->ii_hsb1 = h_inode->i_sb;
5070 +void au_cpup_attr_all(struct inode *inode, int force)
5072 + struct inode *h_inode;
5074 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5075 + au_cpup_attr_changeable(inode);
5076 + if (inode->i_nlink > 0)
5077 + au_cpup_attr_nlink(inode, force);
5078 + inode->i_rdev = h_inode->i_rdev;
5079 + inode->i_blkbits = h_inode->i_blkbits;
5080 + au_cpup_igen(inode, h_inode);
5083 +/* ---------------------------------------------------------------------- */
5085 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5087 +/* keep the timestamps of the parent dir when cpup */
5088 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5089 + struct path *h_path)
5091 + struct inode *h_inode;
5093 + dt->dt_dentry = dentry;
5094 + dt->dt_h_path = *h_path;
5095 + h_inode = d_inode(h_path->dentry);
5096 + dt->dt_atime = h_inode->i_atime;
5097 + dt->dt_mtime = h_inode->i_mtime;
5101 +void au_dtime_revert(struct au_dtime *dt)
5103 + struct iattr attr;
5106 + attr.ia_atime = dt->dt_atime;
5107 + attr.ia_mtime = dt->dt_mtime;
5108 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5109 + | ATTR_ATIME | ATTR_ATIME_SET;
5111 + /* no delegation since this is a directory */
5112 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5113 + if (unlikely(err))
5114 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5117 +/* ---------------------------------------------------------------------- */
5119 +/* internal use only */
5120 +struct au_cpup_reg_attr {
5123 + unsigned int iflags; /* inode->i_flags */
5126 +static noinline_for_stack
5127 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5128 + struct au_cpup_reg_attr *h_src_attr)
5130 + int err, sbits, icex;
5131 + unsigned int mnt_flags;
5132 + unsigned char verbose;
5134 + struct path h_path;
5135 + struct inode *h_isrc, *h_idst;
5136 + struct kstat *h_st;
5137 + struct au_branch *br;
5139 + h_path.dentry = au_h_dptr(dst, bindex);
5140 + h_idst = d_inode(h_path.dentry);
5141 + br = au_sbr(dst->d_sb, bindex);
5142 + h_path.mnt = au_br_mnt(br);
5143 + h_isrc = d_inode(h_src);
5144 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5145 + | ATTR_ATIME | ATTR_MTIME
5146 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5147 + if (h_src_attr && h_src_attr->valid) {
5148 + h_st = &h_src_attr->st;
5149 + ia.ia_uid = h_st->uid;
5150 + ia.ia_gid = h_st->gid;
5151 + ia.ia_atime = h_st->atime;
5152 + ia.ia_mtime = h_st->mtime;
5153 + if (h_idst->i_mode != h_st->mode
5154 + && !S_ISLNK(h_idst->i_mode)) {
5155 + ia.ia_valid |= ATTR_MODE;
5156 + ia.ia_mode = h_st->mode;
5158 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5159 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5161 + ia.ia_uid = h_isrc->i_uid;
5162 + ia.ia_gid = h_isrc->i_gid;
5163 + ia.ia_atime = h_isrc->i_atime;
5164 + ia.ia_mtime = h_isrc->i_mtime;
5165 + if (h_idst->i_mode != h_isrc->i_mode
5166 + && !S_ISLNK(h_idst->i_mode)) {
5167 + ia.ia_valid |= ATTR_MODE;
5168 + ia.ia_mode = h_isrc->i_mode;
5170 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5171 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5173 + /* no delegation since it is just created */
5174 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5176 + /* is this nfs only? */
5177 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5178 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5179 + ia.ia_mode = h_isrc->i_mode;
5180 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5183 + icex = br->br_perm & AuBrAttr_ICEX;
5185 + mnt_flags = au_mntflags(dst->d_sb);
5186 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5187 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5193 +/* ---------------------------------------------------------------------- */
5195 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5196 + char *buf, unsigned long blksize)
5199 + size_t sz, rbytes, wbytes;
5200 + unsigned char all_zero;
5202 + struct inode *h_inode;
5203 + /* reduce stack usage */
5206 + zp = page_address(ZERO_PAGE(0));
5207 + if (unlikely(!zp))
5208 + return -ENOMEM; /* possible? */
5213 + AuDbg("len %lld\n", len);
5215 + if (len < blksize)
5219 + /* todo: signal_pending? */
5220 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5221 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5224 + if (unlikely(err < 0))
5228 + if (len >= rbytes && rbytes == blksize)
5229 + all_zero = !memcmp(buf, zp, rbytes);
5236 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5238 + /* todo: signal_pending? */
5239 + if (unlikely(err == -EAGAIN || err == -EINTR))
5241 + if (unlikely(err < 0))
5246 + if (unlikely(err < 0))
5252 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5254 + if (unlikely(res < 0))
5261 + /* the last block may be a hole */
5262 + if (!err && all_zero) {
5263 + AuLabel(last hole);
5266 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5267 + /* nfs requires this step to make last hole */
5268 + /* is this only nfs? */
5270 + /* todo: signal_pending? */
5271 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5272 + } while (err == -EAGAIN || err == -EINTR);
5279 + ia->ia_size = dst->f_pos;
5280 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5281 + ia->ia_file = dst;
5282 + h_inode = file_inode(dst);
5283 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5284 + /* no delegation since it is just created */
5285 + err = vfsub_notify_change(&dst->f_path, ia,
5286 + /*delegated*/NULL);
5287 + inode_unlock(h_inode);
5294 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5297 + unsigned long blksize;
5298 + unsigned char do_kfree;
5302 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5303 + if (!blksize || PAGE_SIZE < blksize)
5304 + blksize = PAGE_SIZE;
5305 + AuDbg("blksize %lu\n", blksize);
5306 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5308 + buf = kmalloc(blksize, GFP_NOFS);
5310 + buf = (void *)__get_free_page(GFP_NOFS);
5311 + if (unlikely(!buf))
5314 + if (len > (1 << 22))
5315 + AuDbg("copying a large file %lld\n", (long long)len);
5319 + err = au_do_copy_file(dst, src, len, buf, blksize);
5323 + free_page((unsigned long)buf);
5329 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5332 + struct super_block *h_src_sb;
5333 + struct inode *h_src_inode;
5335 + h_src_inode = file_inode(src);
5336 + h_src_sb = h_src_inode->i_sb;
5338 + /* XFS acquires inode_lock */
5339 + if (!au_test_xfs(h_src_sb))
5340 + err = au_copy_file(dst, src, len);
5342 + inode_unlock_shared(h_src_inode);
5343 + err = au_copy_file(dst, src, len);
5344 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5350 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5353 + struct super_block *h_src_sb;
5354 + struct inode *h_src_inode;
5356 + h_src_inode = file_inode(src);
5357 + h_src_sb = h_src_inode->i_sb;
5358 + if (h_src_sb != file_inode(dst)->i_sb
5359 + || !dst->f_op->clone_file_range) {
5360 + err = au_do_copy(dst, src, len);
5364 + if (!au_test_nfs(h_src_sb)) {
5365 + inode_unlock_shared(h_src_inode);
5366 + err = vfsub_clone_file_range(src, dst, len);
5367 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5369 + err = vfsub_clone_file_range(src, dst, len);
5370 + /* older XFS has a condition in cloning */
5371 + if (unlikely(err != -EOPNOTSUPP))
5374 + /* the backend fs on NFS may not support cloning */
5375 + err = au_do_copy(dst, src, len);
5383 + * to support a sparse file which is opened with O_APPEND,
5384 + * we need to close the file.
5386 +static int au_cp_regular(struct au_cp_generic *cpg)
5389 + enum { SRC, DST };
5391 + aufs_bindex_t bindex;
5392 + unsigned int flags;
5393 + struct dentry *dentry;
5395 + struct file *file;
5399 + .bindex = cpg->bsrc,
5400 + .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),
5407 + .label = &&out_src
5410 + struct au_branch *br;
5411 + struct super_block *sb, *h_src_sb;
5412 + struct inode *h_src_inode;
5413 + struct task_struct *tsk = current;
5415 + /* bsrc branch can be ro/rw. */
5416 + sb = cpg->dentry->d_sb;
5418 + for (i = 0; i < 2; i++, f++) {
5419 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5420 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5421 + /*file*/NULL, f->force_wr);
5422 + err = PTR_ERR(f->file);
5423 + if (IS_ERR(f->file))
5427 + /* try stopping to update while we copyup */
5428 + h_src_inode = d_inode(file[SRC].dentry);
5429 + h_src_sb = h_src_inode->i_sb;
5430 + if (!au_test_nfs(h_src_sb))
5431 + IMustLock(h_src_inode);
5432 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5434 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5435 + if (tsk->flags & PF_KTHREAD)
5436 + __fput_sync(file[DST].file);
5438 + /* it happened actually */
5439 + fput(file[DST].file);
5442 + * we have to call both since we don't know which place the file
5446 + flush_delayed_fput();
5448 + br = au_sbr(sb, file[DST].bindex);
5449 + au_lcnt_dec(&br->br_nfiles);
5452 + fput(file[SRC].file);
5453 + br = au_sbr(sb, file[SRC].bindex);
5454 + au_lcnt_dec(&br->br_nfiles);
5459 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5460 + struct au_cpup_reg_attr *h_src_attr)
5464 + struct path h_path;
5465 + struct inode *h_src_inode, *h_dst_inode;
5468 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5469 + l = i_size_read(h_src_inode);
5470 + if (cpg->len == -1 || l < cpg->len)
5473 + /* try stopping to update while we are referencing */
5474 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5475 + au_pin_hdir_unlock(cpg->pin);
5477 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5478 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5479 + h_src_attr->iflags = h_src_inode->i_flags;
5480 + if (!au_test_nfs(h_src_inode->i_sb))
5481 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5483 + inode_unlock_shared(h_src_inode);
5484 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5485 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5487 + if (unlikely(err)) {
5488 + inode_unlock_shared(h_src_inode);
5491 + h_src_attr->valid = 1;
5492 + if (!au_test_nfs(h_src_inode->i_sb)) {
5493 + err = au_cp_regular(cpg);
5494 + inode_unlock_shared(h_src_inode);
5496 + inode_unlock_shared(h_src_inode);
5497 + err = au_cp_regular(cpg);
5499 + rerr = au_pin_hdir_relock(cpg->pin);
5503 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5504 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5505 + h_dst_inode = d_inode(h_path.dentry);
5506 + spin_lock(&h_dst_inode->i_lock);
5507 + h_dst_inode->i_state |= I_LINKABLE;
5508 + spin_unlock(&h_dst_inode->i_lock);
5515 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5516 + struct inode *h_dir)
5519 + mm_segment_t old_fs;
5526 + sym.k = (void *)__get_free_page(GFP_NOFS);
5527 + if (unlikely(!sym.k))
5530 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5531 + old_fs = get_fs();
5532 + set_fs(KERNEL_DS);
5533 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5538 + sym.k[symlen] = 0;
5539 + err = vfsub_symlink(h_dir, h_path, sym.k);
5541 + free_page((unsigned long)sym.k);
5548 + * regardless 'acl' option, reset all ACL.
5549 + * All ACL will be copied up later from the original entry on the lower branch.
5551 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5554 + struct dentry *h_dentry;
5555 + struct inode *h_inode;
5557 + h_dentry = h_path->dentry;
5558 + h_inode = d_inode(h_dentry);
5559 + /* forget_all_cached_acls(h_inode)); */
5560 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5562 + if (err == -EOPNOTSUPP)
5565 + err = vfsub_acl_chmod(h_inode, mode);
5571 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5572 + struct inode *h_dir, struct path *h_path)
5575 + struct inode *dir, *inode;
5577 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5579 + if (err == -EOPNOTSUPP)
5581 + if (unlikely(err))
5585 + * strange behaviour from the users view,
5586 + * particularly setattr case
5588 + dir = d_inode(dst_parent);
5589 + if (au_ibtop(dir) == cpg->bdst)
5590 + au_cpup_attr_nlink(dir, /*force*/1);
5591 + inode = d_inode(cpg->dentry);
5592 + au_cpup_attr_nlink(inode, /*force*/1);
5598 +static noinline_for_stack
5599 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5600 + struct au_cpup_reg_attr *h_src_attr)
5604 + unsigned int mnt_flags;
5605 + unsigned char isdir, isreg, force;
5606 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5607 + struct au_dtime dt;
5608 + struct path h_path;
5609 + struct dentry *h_src, *h_dst, *h_parent;
5610 + struct inode *h_inode, *h_dir;
5611 + struct super_block *sb;
5613 + /* bsrc branch can be ro/rw. */
5614 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5615 + h_inode = d_inode(h_src);
5616 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5618 + /* try stopping to be referenced while we are creating */
5619 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5620 + if (au_ftest_cpup(cpg->flags, RENAME))
5621 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5622 + AUFS_WH_PFX_LEN));
5623 + h_parent = h_dst->d_parent; /* dir inode is locked */
5624 + h_dir = d_inode(h_parent);
5626 + AuDebugOn(h_parent != h_dst->d_parent);
5628 + sb = cpg->dentry->d_sb;
5629 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5631 + h_path.dentry = h_parent;
5632 + au_dtime_store(&dt, dst_parent, &h_path);
5634 + h_path.dentry = h_dst;
5638 + mode = h_inode->i_mode;
5639 + switch (mode & S_IFMT) {
5642 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5644 + err = au_do_cpup_regular(cpg, h_src_attr);
5648 + err = vfsub_mkdir(h_dir, &h_path, mode);
5650 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5653 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5657 + AuDebugOn(!capable(CAP_MKNOD));
5661 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5664 + AuIOErr("Unknown inode type 0%o\n", mode);
5668 + err = au_reset_acl(h_dir, &h_path, mode);
5670 + mnt_flags = au_mntflags(sb);
5671 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5673 + && au_opt_test(mnt_flags, XINO)
5674 + && (h_inode->i_nlink == 1
5675 + || (h_inode->i_state & I_LINKABLE))
5676 + /* todo: unnecessary? */
5677 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5678 + && cpg->bdst < cpg->bsrc
5679 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5680 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5681 + /* ignore this error */
5686 + force = !!cpg->len;
5687 + if (cpg->len == -1)
5688 + force = !!i_size_read(h_inode);
5690 + au_fhsm_wrote(sb, cpg->bdst, force);
5694 + au_dtime_revert(&dt);
5698 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5701 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5702 + struct inode *h_dir;
5703 + aufs_bindex_t bdst;
5705 + dentry = cpg->dentry;
5707 + h_dentry = au_h_dptr(dentry, bdst);
5708 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5710 + au_set_h_dptr(dentry, bdst, NULL);
5711 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5713 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5714 + au_set_h_dptr(dentry, bdst, h_dentry);
5717 + parent = dget_parent(dentry);
5718 + h_parent = au_h_dptr(parent, bdst);
5720 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5721 + if (IS_ERR(h_path->dentry))
5722 + err = PTR_ERR(h_path->dentry);
5724 + if (unlikely(err))
5727 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5728 + h_dir = d_inode(h_parent);
5730 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5731 + /* no delegation since it is just created */
5732 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5734 + dput(h_path->dentry);
5741 + * copyup the @dentry from @bsrc to @bdst.
5742 + * the caller must set the both of lower dentries.
5743 + * @len is for truncating when it is -1 copyup the entire file.
5744 + * in link/rename cases, @dst_parent may be different from the real one.
5745 + * basic->bsrc can be larger than basic->bdst.
5746 + * aufs doesn't touch the credential so
5747 + * security_inode_copy_up{,_xattr}() are unnecessary.
5749 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5752 + aufs_bindex_t old_ibtop;
5753 + unsigned char isdir, plink;
5754 + struct dentry *h_src, *h_dst, *h_parent;
5755 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5756 + struct super_block *sb;
5757 + struct au_branch *br;
5758 + /* to reduce stack size */
5760 + struct au_dtime dt;
5761 + struct path h_path;
5762 + struct au_cpup_reg_attr h_src_attr;
5766 + a = kmalloc(sizeof(*a), GFP_NOFS);
5769 + a->h_src_attr.valid = 0;
5771 + sb = cpg->dentry->d_sb;
5772 + br = au_sbr(sb, cpg->bdst);
5773 + a->h_path.mnt = au_br_mnt(br);
5774 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5775 + h_parent = h_dst->d_parent; /* dir inode is locked */
5776 + h_dir = d_inode(h_parent);
5779 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5780 + inode = d_inode(cpg->dentry);
5783 + dst_parent = dget_parent(cpg->dentry);
5787 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5788 + dst_inode = au_h_iptr(inode, cpg->bdst);
5790 + if (unlikely(!plink)) {
5792 + AuIOErr("hi%lu(i%lu) exists on b%d "
5793 + "but plink is disabled\n",
5794 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5798 + if (dst_inode->i_nlink) {
5799 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5801 + h_src = au_plink_lkup(inode, cpg->bdst);
5802 + err = PTR_ERR(h_src);
5803 + if (IS_ERR(h_src))
5805 + if (unlikely(d_is_negative(h_src))) {
5807 + AuIOErr("i%lu exists on b%d "
5808 + "but not pseudo-linked\n",
5809 + inode->i_ino, cpg->bdst);
5815 + a->h_path.dentry = h_parent;
5816 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5819 + a->h_path.dentry = h_dst;
5821 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5822 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5823 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5825 + au_dtime_revert(&a->dt);
5826 + if (unlikely(err == -EWOULDBLOCK)) {
5827 + pr_warn("cannot retry for NFSv4 delegation"
5828 + " for an internal link\n");
5834 + /* todo: cpup_wh_file? */
5836 + au_update_ibrange(inode, /*do_put_zero*/1);
5839 + isdir = S_ISDIR(inode->i_mode);
5840 + old_ibtop = au_ibtop(inode);
5841 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5842 + if (unlikely(err))
5844 + dst_inode = d_inode(h_dst);
5845 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5846 + /* todo: necessary? */
5847 + /* au_pin_hdir_unlock(cpg->pin); */
5849 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5850 + if (unlikely(err)) {
5851 + /* todo: necessary? */
5852 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5853 + inode_unlock(dst_inode);
5857 + if (cpg->bdst < old_ibtop) {
5858 + if (S_ISREG(inode->i_mode)) {
5859 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5860 + if (unlikely(err)) {
5861 + /* ignore an error */
5862 + /* au_pin_hdir_relock(cpg->pin); */
5863 + inode_unlock(dst_inode);
5867 + au_set_ibtop(inode, cpg->bdst);
5869 + au_set_ibbot(inode, cpg->bdst);
5870 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5871 + au_hi_flags(inode, isdir));
5873 + /* todo: necessary? */
5874 + /* err = au_pin_hdir_relock(cpg->pin); */
5875 + inode_unlock(dst_inode);
5876 + if (unlikely(err))
5879 + src_inode = d_inode(h_src);
5881 + && (src_inode->i_nlink > 1
5882 + || src_inode->i_state & I_LINKABLE)
5884 + au_plink_append(inode, cpg->bdst, h_dst);
5886 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5887 + a->h_path.dentry = h_dst;
5888 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5891 + goto out_parent; /* success */
5895 + a->h_path.dentry = h_parent;
5896 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5897 + a->h_path.dentry = h_dst;
5899 + if (d_is_positive(h_dst)) {
5901 + /* no delegation since it is just created */
5902 + rerr = vfsub_unlink(h_dir, &a->h_path,
5903 + /*delegated*/NULL, /*force*/0);
5905 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5907 + au_dtime_revert(&a->dt);
5909 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5919 +#if 0 /* reserved */
5920 +struct au_cpup_single_args {
5922 + struct au_cp_generic *cpg;
5923 + struct dentry *dst_parent;
5926 +static void au_call_cpup_single(void *args)
5928 + struct au_cpup_single_args *a = args;
5930 + au_pin_hdir_acquire_nest(a->cpg->pin);
5931 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5932 + au_pin_hdir_release(a->cpg->pin);
5937 + * prevent SIGXFSZ in copy-up.
5938 + * testing CAP_MKNOD is for generic fs,
5939 + * but CAP_FSETID is for xfs only, currently.
5941 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5944 + struct super_block *sb;
5945 + struct inode *h_dir;
5948 + sb = au_pinned_parent(pin)->d_sb;
5949 + if (!au_wkq_test()
5950 + && (!au_sbi(sb)->si_plink_maint_pid
5951 + || au_plink_maint(sb, AuLock_NOPLM))) {
5952 + switch (mode & S_IFMT) {
5954 + /* no condition about RLIMIT_FSIZE and the file size */
5959 + do_sio = !capable(CAP_MKNOD);
5963 + do_sio = ((mode & (S_ISUID | S_ISGID))
5964 + && !capable(CAP_FSETID));
5965 + /* this workaround may be removed in the future */
5967 + h_dir = au_pinned_h_dir(pin);
5968 + do_sio = h_dir->i_mode & S_ISVTX;
5975 +#if 0 /* reserved */
5976 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5979 + struct dentry *h_dentry;
5981 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5982 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5983 + err = au_cpup_single(cpg, dst_parent);
5985 + struct au_cpup_single_args args = {
5988 + .dst_parent = dst_parent
5990 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5991 + if (unlikely(wkq_err))
6000 + * copyup the @dentry from the first active lower branch to @bdst,
6001 + * using au_cpup_single().
6003 +static int au_cpup_simple(struct au_cp_generic *cpg)
6006 + unsigned int flags_orig;
6007 + struct dentry *dentry;
6009 + AuDebugOn(cpg->bsrc < 0);
6011 + dentry = cpg->dentry;
6012 + DiMustWriteLock(dentry);
6014 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6016 + flags_orig = cpg->flags;
6017 + au_fset_cpup(cpg->flags, RENAME);
6018 + err = au_cpup_single(cpg, NULL);
6019 + cpg->flags = flags_orig;
6021 + return 0; /* success */
6024 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6025 + au_set_dbtop(dentry, cpg->bsrc);
6031 +struct au_cpup_simple_args {
6033 + struct au_cp_generic *cpg;
6036 +static void au_call_cpup_simple(void *args)
6038 + struct au_cpup_simple_args *a = args;
6040 + au_pin_hdir_acquire_nest(a->cpg->pin);
6041 + *a->errp = au_cpup_simple(a->cpg);
6042 + au_pin_hdir_release(a->cpg->pin);
6045 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6048 + struct dentry *dentry, *parent;
6049 + struct file *h_file;
6050 + struct inode *h_dir;
6052 + dentry = cpg->dentry;
6054 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6055 + AuDebugOn(cpg->bsrc < 0);
6056 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6057 + err = PTR_ERR(h_file);
6058 + if (IS_ERR(h_file))
6062 + parent = dget_parent(dentry);
6063 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6064 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6065 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6066 + err = au_cpup_simple(cpg);
6068 + struct au_cpup_simple_args args = {
6072 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6073 + if (unlikely(wkq_err))
6079 + au_h_open_post(dentry, cpg->bsrc, h_file);
6085 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6087 + aufs_bindex_t bsrc, bbot;
6088 + struct dentry *dentry, *h_dentry;
6090 + if (cpg->bsrc < 0) {
6091 + dentry = cpg->dentry;
6092 + bbot = au_dbbot(dentry);
6093 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6094 + h_dentry = au_h_dptr(dentry, bsrc);
6096 + AuDebugOn(d_is_negative(h_dentry));
6100 + AuDebugOn(bsrc > bbot);
6103 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6104 + return au_do_sio_cpup_simple(cpg);
6107 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6109 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6110 + return au_do_sio_cpup_simple(cpg);
6113 +/* ---------------------------------------------------------------------- */
6116 + * copyup the deleted file for writing.
6118 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6119 + struct file *file)
6122 + unsigned int flags_orig;
6123 + aufs_bindex_t bsrc_orig;
6124 + struct au_dinfo *dinfo;
6126 + struct au_hdentry *hd;
6127 + struct dentry *h_dentry;
6130 + dinfo = au_di(cpg->dentry);
6131 + AuRwMustWriteLock(&dinfo->di_rwsem);
6133 + bsrc_orig = cpg->bsrc;
6134 + cpg->bsrc = dinfo->di_btop;
6135 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6136 + hdst.h_dentry = hdst.hd->hd_dentry;
6137 + hdst.hd->hd_dentry = wh_dentry;
6138 + dinfo->di_btop = cpg->bdst;
6140 + hsrc.h_dentry = NULL;
6142 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6143 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6144 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6146 + flags_orig = cpg->flags;
6147 + cpg->flags = !AuCpup_DTIME;
6148 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6149 + cpg->flags = flags_orig;
6152 + err = au_reopen_nondir(file);
6153 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6155 + hdst.hd->hd_dentry = hdst.h_dentry;
6156 + dinfo->di_btop = cpg->bsrc;
6157 + cpg->bsrc = bsrc_orig;
6162 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6165 + aufs_bindex_t bdst;
6166 + struct au_dtime dt;
6167 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6168 + struct au_branch *br;
6169 + struct path h_path;
6171 + dentry = cpg->dentry;
6173 + br = au_sbr(dentry->d_sb, bdst);
6174 + parent = dget_parent(dentry);
6175 + h_parent = au_h_dptr(parent, bdst);
6176 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6177 + err = PTR_ERR(wh_dentry);
6178 + if (IS_ERR(wh_dentry))
6181 + h_path.dentry = h_parent;
6182 + h_path.mnt = au_br_mnt(br);
6183 + au_dtime_store(&dt, parent, &h_path);
6184 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6185 + if (unlikely(err))
6189 + h_path.dentry = wh_dentry;
6190 + if (!d_is_dir(wh_dentry)) {
6191 + /* no delegation since it is just created */
6192 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6193 + /*delegated*/NULL, /*force*/0);
6195 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6196 + if (unlikely(err)) {
6197 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6201 + au_dtime_revert(&dt);
6202 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6211 +struct au_cpup_wh_args {
6213 + struct au_cp_generic *cpg;
6214 + struct file *file;
6217 +static void au_call_cpup_wh(void *args)
6219 + struct au_cpup_wh_args *a = args;
6221 + au_pin_hdir_acquire_nest(a->cpg->pin);
6222 + *a->errp = au_cpup_wh(a->cpg, a->file);
6223 + au_pin_hdir_release(a->cpg->pin);
6226 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6229 + aufs_bindex_t bdst;
6230 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6231 + struct inode *dir, *h_dir, *h_tmpdir;
6232 + struct au_wbr *wbr;
6233 + struct au_pin wh_pin, *pin_orig;
6235 + dentry = cpg->dentry;
6237 + parent = dget_parent(dentry);
6238 + dir = d_inode(parent);
6241 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6244 + if (!h_dir->i_nlink) {
6245 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6246 + h_orph = wbr->wbr_orph;
6248 + h_parent = dget(au_h_dptr(parent, bdst));
6249 + au_set_h_dptr(parent, bdst, dget(h_orph));
6250 + h_tmpdir = d_inode(h_orph);
6251 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6253 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6254 + /* todo: au_h_open_pre()? */
6256 + pin_orig = cpg->pin;
6257 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6258 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6259 + cpg->pin = &wh_pin;
6262 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6263 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6264 + err = au_cpup_wh(cpg, file);
6266 + struct au_cpup_wh_args args = {
6271 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6272 + if (unlikely(wkq_err))
6277 + inode_unlock(h_tmpdir);
6278 + /* todo: au_h_open_post()? */
6279 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6280 + au_set_h_dptr(parent, bdst, h_parent);
6281 + AuDebugOn(!pin_orig);
6282 + cpg->pin = pin_orig;
6290 +/* ---------------------------------------------------------------------- */
6293 + * generic routine for both of copy-up and copy-down.
6295 +/* cf. revalidate function in file.c */
6296 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6297 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6298 + struct au_pin *pin,
6299 + struct dentry *h_parent, void *arg),
6303 + struct au_pin pin;
6304 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6307 + parent = dget_parent(dentry);
6308 + if (IS_ROOT(parent))
6311 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6312 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6314 + /* do not use au_dpage */
6315 + real_parent = parent;
6318 + parent = dget_parent(dentry);
6319 + h_parent = au_h_dptr(parent, bdst);
6321 + goto out; /* success */
6323 + /* find top dir which is necessary to cpup */
6327 + parent = dget_parent(d);
6328 + di_read_lock_parent3(parent, !AuLock_IR);
6329 + h_parent = au_h_dptr(parent, bdst);
6330 + di_read_unlock(parent, !AuLock_IR);
6331 + } while (!h_parent);
6333 + if (d != real_parent)
6334 + di_write_lock_child3(d);
6336 + /* somebody else might create while we were sleeping */
6337 + h_dentry = au_h_dptr(d, bdst);
6338 + if (!h_dentry || d_is_negative(h_dentry)) {
6340 + au_update_dbtop(d);
6342 + au_pin_set_dentry(&pin, d);
6343 + err = au_do_pin(&pin);
6345 + err = cp(d, bdst, &pin, h_parent, arg);
6350 + if (d != real_parent)
6351 + di_write_unlock(d);
6352 + if (unlikely(err))
6361 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6362 + struct au_pin *pin,
6363 + struct dentry *h_parent __maybe_unused,
6364 + void *arg __maybe_unused)
6366 + struct au_cp_generic cpg = {
6372 + .flags = AuCpup_DTIME
6374 + return au_sio_cpup_simple(&cpg);
6377 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6379 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6382 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6385 + struct dentry *parent;
6386 + struct inode *dir;
6388 + parent = dget_parent(dentry);
6389 + dir = d_inode(parent);
6391 + if (au_h_iptr(dir, bdst))
6394 + di_read_unlock(parent, AuLock_IR);
6395 + di_write_lock_parent(parent);
6396 + /* someone else might change our inode while we were sleeping */
6397 + if (!au_h_iptr(dir, bdst))
6398 + err = au_cpup_dirs(dentry, bdst);
6399 + di_downgrade_lock(parent, AuLock_IR);
6405 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6406 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6407 +++ linux/fs/aufs/cpup.h 2018-08-12 23:43:05.453457863 +0200
6409 +/* SPDX-License-Identifier: GPL-2.0 */
6411 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6413 + * This program, aufs is free software; you can redistribute it and/or modify
6414 + * it under the terms of the GNU General Public License as published by
6415 + * the Free Software Foundation; either version 2 of the License, or
6416 + * (at your option) any later version.
6418 + * This program is distributed in the hope that it will be useful,
6419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6421 + * GNU General Public License for more details.
6423 + * You should have received a copy of the GNU General Public License
6424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6428 + * copy-up/down functions
6431 +#ifndef __AUFS_CPUP_H__
6432 +#define __AUFS_CPUP_H__
6436 +#include <linux/path.h>
6442 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6443 +void au_cpup_attr_timesizes(struct inode *inode);
6444 +void au_cpup_attr_nlink(struct inode *inode, int force);
6445 +void au_cpup_attr_changeable(struct inode *inode);
6446 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6447 +void au_cpup_attr_all(struct inode *inode, int force);
6449 +/* ---------------------------------------------------------------------- */
6451 +struct au_cp_generic {
6452 + struct dentry *dentry;
6453 + aufs_bindex_t bdst, bsrc;
6455 + struct au_pin *pin;
6456 + unsigned int flags;
6460 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6461 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6463 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6464 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6466 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6468 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6469 + the branch is marked as RO */
6471 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6472 +#undef AuCpup_HOPEN
6473 +#define AuCpup_HOPEN 0
6476 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6477 +#define au_fset_cpup(flags, name) \
6478 + do { (flags) |= AuCpup_##name; } while (0)
6479 +#define au_fclr_cpup(flags, name) \
6480 + do { (flags) &= ~AuCpup_##name; } while (0)
6482 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6483 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6484 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6485 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6487 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6488 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6489 + struct au_pin *pin,
6490 + struct dentry *h_parent, void *arg),
6492 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6493 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6495 +/* ---------------------------------------------------------------------- */
6497 +/* keep timestamps when copyup */
6499 + struct dentry *dt_dentry;
6500 + struct path dt_h_path;
6501 + struct timespec64 dt_atime, dt_mtime;
6503 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6504 + struct path *h_path);
6505 +void au_dtime_revert(struct au_dtime *dt);
6507 +#endif /* __KERNEL__ */
6508 +#endif /* __AUFS_CPUP_H__ */
6509 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6510 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6511 +++ linux/fs/aufs/dbgaufs.c 2018-10-23 12:33:35.596042364 +0200
6513 +// SPDX-License-Identifier: GPL-2.0
6515 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6517 + * This program, aufs is free software; you can redistribute it and/or modify
6518 + * it under the terms of the GNU General Public License as published by
6519 + * the Free Software Foundation; either version 2 of the License, or
6520 + * (at your option) any later version.
6522 + * This program is distributed in the hope that it will be useful,
6523 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6524 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6525 + * GNU General Public License for more details.
6527 + * You should have received a copy of the GNU General Public License
6528 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6532 + * debugfs interface
6535 +#include <linux/debugfs.h>
6538 +#ifndef CONFIG_SYSFS
6539 +#error DEBUG_FS depends upon SYSFS
6542 +static struct dentry *dbgaufs;
6543 +static const mode_t dbgaufs_mode = 0444;
6545 +/* 20 is max digits length of ulong 64 */
6546 +struct dbgaufs_arg {
6552 + * common function for all XINO files
6554 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6555 + struct file *file)
6557 + kfree(file->private_data);
6561 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6566 + struct dbgaufs_arg *p;
6569 + p = kmalloc(sizeof(*p), GFP_NOFS);
6575 + file->private_data = p;
6579 + err = vfsub_getattr(&xf->f_path, &st);
6583 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6584 + cnt, st.blocks, st.blksize,
6585 + (long long)st.size);
6587 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6588 + st.blocks, st.blksize,
6589 + (long long)st.size);
6590 + AuDebugOn(p->n >= sizeof(p->a));
6592 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6600 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6601 + size_t count, loff_t *ppos)
6603 + struct dbgaufs_arg *p;
6605 + p = file->private_data;
6606 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6609 +/* ---------------------------------------------------------------------- */
6611 +struct dbgaufs_plink_arg {
6616 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6617 + struct file *file)
6619 + free_page((unsigned long)file->private_data);
6623 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6625 + int err, i, limit;
6626 + unsigned long n, sum;
6627 + struct dbgaufs_plink_arg *p;
6628 + struct au_sbinfo *sbinfo;
6629 + struct super_block *sb;
6630 + struct hlist_bl_head *hbl;
6633 + p = (void *)get_zeroed_page(GFP_NOFS);
6638 + sbinfo = inode->i_private;
6639 + sb = sbinfo->si_sb;
6640 + si_noflush_read_lock(sb);
6641 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6642 + limit = PAGE_SIZE - sizeof(p->n);
6644 + /* the number of buckets */
6645 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6650 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6652 + n = au_hbl_count(hbl);
6655 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6658 + if (unlikely(limit <= 0))
6661 + p->a[p->n - 1] = '\n';
6663 + /* the sum of plinks */
6664 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6667 + if (unlikely(limit <= 0))
6670 +#define str "1\n0\n0\n"
6671 + p->n = sizeof(str) - 1;
6672 + strcpy(p->a, str);
6675 + si_read_unlock(sb);
6678 + file->private_data = p;
6679 + goto out; /* success */
6682 + free_page((unsigned long)p);
6687 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6688 + size_t count, loff_t *ppos)
6690 + struct dbgaufs_plink_arg *p;
6692 + p = file->private_data;
6693 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6696 +static const struct file_operations dbgaufs_plink_fop = {
6697 + .owner = THIS_MODULE,
6698 + .open = dbgaufs_plink_open,
6699 + .release = dbgaufs_plink_release,
6700 + .read = dbgaufs_plink_read
6703 +/* ---------------------------------------------------------------------- */
6705 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6708 + struct au_sbinfo *sbinfo;
6709 + struct super_block *sb;
6711 + sbinfo = inode->i_private;
6712 + sb = sbinfo->si_sb;
6713 + si_noflush_read_lock(sb);
6714 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6715 + si_read_unlock(sb);
6719 +static const struct file_operations dbgaufs_xib_fop = {
6720 + .owner = THIS_MODULE,
6721 + .open = dbgaufs_xib_open,
6722 + .release = dbgaufs_xi_release,
6723 + .read = dbgaufs_xi_read
6726 +/* ---------------------------------------------------------------------- */
6728 +#define DbgaufsXi_PREFIX "xi"
6730 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6734 + aufs_bindex_t bindex;
6735 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6736 + struct au_sbinfo *sbinfo;
6737 + struct super_block *sb;
6738 + struct au_xino *xi;
6740 + struct qstr *name;
6741 + struct au_branch *br;
6744 + name = &file->f_path.dentry->d_name;
6745 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6746 + || memcmp(name->name, DbgaufsXi_PREFIX,
6747 + sizeof(DbgaufsXi_PREFIX) - 1)))
6750 + AuDebugOn(name->len >= sizeof(a));
6751 + memcpy(a, name->name, name->len);
6752 + a[name->len] = '\0';
6753 + p = strchr(a, '-');
6756 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6757 + if (unlikely(err))
6762 + err = kstrtol(p + 1, 10, &l);
6763 + if (unlikely(err))
6769 + sbinfo = inode->i_private;
6770 + sb = sbinfo->si_sb;
6771 + si_noflush_read_lock(sb);
6772 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6774 + br = au_sbr(sb, bindex);
6776 + if (unlikely(idx >= xi->xi_nfile))
6778 + xf = au_xino_file(xi, idx);
6780 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6781 + au_xino_count(br));
6784 + si_read_unlock(sb);
6790 +static const struct file_operations dbgaufs_xino_fop = {
6791 + .owner = THIS_MODULE,
6792 + .open = dbgaufs_xino_open,
6793 + .release = dbgaufs_xi_release,
6794 + .read = dbgaufs_xi_read
6797 +void dbgaufs_xino_del(struct au_branch *br)
6799 + struct dentry *dbgaufs;
6801 + dbgaufs = br->br_dbgaufs;
6805 + br->br_dbgaufs = NULL;
6806 + /* debugfs acquires the parent i_mutex */
6808 + debugfs_remove(dbgaufs);
6812 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6814 + aufs_bindex_t bbot;
6815 + struct au_branch *br;
6817 + if (!au_sbi(sb)->si_dbgaufs)
6820 + bbot = au_sbbot(sb);
6821 + for (; bindex <= bbot; bindex++) {
6822 + br = au_sbr(sb, bindex);
6823 + dbgaufs_xino_del(br);
6827 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6828 + unsigned int idx, struct dentry *parent,
6829 + struct au_sbinfo *sbinfo)
6831 + struct au_branch *br;
6833 + /* "xi" bindex(5) "-" idx(2) NULL */
6834 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6837 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6839 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6841 + br = au_sbr(sb, bindex);
6842 + if (br->br_dbgaufs) {
6843 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6845 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6846 + /* debugfs acquires the parent i_mutex */
6848 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6852 + pr_warn("failed renaming %pd/%s, ignored.\n",
6857 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6858 + sbinfo, &dbgaufs_xino_fop);
6860 + if (unlikely(!br->br_dbgaufs))
6861 + pr_warn("failed creating %pd/%s, ignored.\n",
6866 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6867 + struct dentry *parent, struct au_sbinfo *sbinfo)
6869 + struct au_branch *br;
6870 + struct au_xino *xi;
6873 + br = au_sbr(sb, bindex);
6875 + for (u = 0; u < xi->xi_nfile; u++)
6876 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6879 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6881 + struct au_sbinfo *sbinfo;
6882 + struct dentry *parent;
6883 + aufs_bindex_t bbot;
6885 + if (!au_opt_test(au_mntflags(sb), XINO))
6888 + sbinfo = au_sbi(sb);
6889 + parent = sbinfo->si_dbgaufs;
6893 + bbot = au_sbbot(sb);
6895 + for (; bindex <= bbot; bindex++)
6896 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6898 + for (; bbot >= bindex; bbot--)
6899 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6902 +/* ---------------------------------------------------------------------- */
6904 +#ifdef CONFIG_AUFS_EXPORT
6905 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6908 + struct au_sbinfo *sbinfo;
6909 + struct super_block *sb;
6911 + sbinfo = inode->i_private;
6912 + sb = sbinfo->si_sb;
6913 + si_noflush_read_lock(sb);
6914 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6915 + si_read_unlock(sb);
6919 +static const struct file_operations dbgaufs_xigen_fop = {
6920 + .owner = THIS_MODULE,
6921 + .open = dbgaufs_xigen_open,
6922 + .release = dbgaufs_xi_release,
6923 + .read = dbgaufs_xi_read
6926 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6931 + * This function is a dynamic '__init' function actually,
6932 + * so the tiny check for si_rwsem is unnecessary.
6934 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6937 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6938 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6939 + &dbgaufs_xigen_fop);
6940 + if (sbinfo->si_dbgaufs_xigen)
6946 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6950 +#endif /* CONFIG_AUFS_EXPORT */
6952 +/* ---------------------------------------------------------------------- */
6954 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6957 + * This function is a dynamic '__fin' function actually,
6958 + * so the tiny check for si_rwsem is unnecessary.
6960 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6962 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6963 + sbinfo->si_dbgaufs = NULL;
6966 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6969 + char name[SysaufsSiNameLen];
6972 + * This function is a dynamic '__init' function actually,
6973 + * so the tiny check for si_rwsem is unnecessary.
6975 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6979 + AuErr1("/debug/aufs is uninitialized\n");
6984 + sysaufs_name(sbinfo, name);
6985 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6986 + if (unlikely(!sbinfo->si_dbgaufs))
6989 + /* regardless plink/noplink option */
6990 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6991 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6992 + &dbgaufs_plink_fop);
6993 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6996 + /* regardless xino/noxino option */
6997 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6998 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6999 + &dbgaufs_xib_fop);
7000 + if (unlikely(!sbinfo->si_dbgaufs_xib))
7003 + err = dbgaufs_xigen_init(sbinfo);
7005 + goto out; /* success */
7008 + dbgaufs_si_fin(sbinfo);
7010 + if (unlikely(err))
7011 + pr_err("debugfs/aufs failed\n");
7015 +/* ---------------------------------------------------------------------- */
7017 +void dbgaufs_fin(void)
7019 + debugfs_remove(dbgaufs);
7022 +int __init dbgaufs_init(void)
7027 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7032 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7033 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7034 +++ linux/fs/aufs/dbgaufs.h 2018-08-12 23:43:05.453457863 +0200
7036 +/* SPDX-License-Identifier: GPL-2.0 */
7038 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7040 + * This program, aufs is free software; you can redistribute it and/or modify
7041 + * it under the terms of the GNU General Public License as published by
7042 + * the Free Software Foundation; either version 2 of the License, or
7043 + * (at your option) any later version.
7045 + * This program is distributed in the hope that it will be useful,
7046 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7047 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7048 + * GNU General Public License for more details.
7050 + * You should have received a copy of the GNU General Public License
7051 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7055 + * debugfs interface
7058 +#ifndef __DBGAUFS_H__
7059 +#define __DBGAUFS_H__
7063 +struct super_block;
7067 +#ifdef CONFIG_DEBUG_FS
7069 +void dbgaufs_xino_del(struct au_branch *br);
7070 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7071 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7072 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7073 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7074 +void dbgaufs_fin(void);
7075 +int __init dbgaufs_init(void);
7077 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7078 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7079 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7081 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7082 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7083 +AuStubVoid(dbgaufs_fin, void)
7084 +AuStubInt0(__init dbgaufs_init, void)
7085 +#endif /* CONFIG_DEBUG_FS */
7087 +#endif /* __KERNEL__ */
7088 +#endif /* __DBGAUFS_H__ */
7089 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7090 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7091 +++ linux/fs/aufs/dcsub.c 2018-08-12 23:43:05.453457863 +0200
7093 +// SPDX-License-Identifier: GPL-2.0
7095 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7097 + * This program, aufs is free software; you can redistribute it and/or modify
7098 + * it under the terms of the GNU General Public License as published by
7099 + * the Free Software Foundation; either version 2 of the License, or
7100 + * (at your option) any later version.
7102 + * This program is distributed in the hope that it will be useful,
7103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7105 + * GNU General Public License for more details.
7107 + * You should have received a copy of the GNU General Public License
7108 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7112 + * sub-routines for dentry cache
7117 +static void au_dpage_free(struct au_dpage *dpage)
7120 + struct dentry **p;
7122 + p = dpage->dentries;
7123 + for (i = 0; i < dpage->ndentry; i++)
7125 + free_page((unsigned long)dpage->dentries);
7128 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7134 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7135 + if (unlikely(!dpages->dpages))
7138 + p = (void *)__get_free_page(gfp);
7142 + dpages->dpages[0].ndentry = 0;
7143 + dpages->dpages[0].dentries = p;
7144 + dpages->ndpage = 1;
7145 + return 0; /* success */
7148 + kfree(dpages->dpages);
7153 +void au_dpages_free(struct au_dcsub_pages *dpages)
7156 + struct au_dpage *p;
7158 + p = dpages->dpages;
7159 + for (i = 0; i < dpages->ndpage; i++)
7160 + au_dpage_free(p++);
7161 + kfree(dpages->dpages);
7164 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7165 + struct dentry *dentry, gfp_t gfp)
7168 + struct au_dpage *dpage;
7171 + dpage = dpages->dpages + dpages->ndpage - 1;
7172 + sz = PAGE_SIZE / sizeof(dentry);
7173 + if (unlikely(dpage->ndentry >= sz)) {
7174 + AuLabel(new dpage);
7176 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7177 + p = au_kzrealloc(dpages->dpages, sz,
7178 + sz + sizeof(*dpages->dpages), gfp,
7183 + dpages->dpages = p;
7184 + dpage = dpages->dpages + dpages->ndpage;
7185 + p = (void *)__get_free_page(gfp);
7189 + dpage->ndentry = 0;
7190 + dpage->dentries = p;
7194 + AuDebugOn(au_dcount(dentry) <= 0);
7195 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7196 + return 0; /* success */
7202 +/* todo: BAD approach */
7203 +/* copied from linux/fs/dcache.c */
7211 +extern void d_walk(struct dentry *parent, void *data,
7212 + enum d_walk_ret (*enter)(void *, struct dentry *));
7214 +struct ac_dpages_arg {
7216 + struct au_dcsub_pages *dpages;
7217 + struct super_block *sb;
7218 + au_dpages_test test;
7222 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7224 + enum d_walk_ret ret;
7225 + struct ac_dpages_arg *arg = _arg;
7227 + ret = D_WALK_CONTINUE;
7228 + if (dentry->d_sb == arg->sb
7229 + && !IS_ROOT(dentry)
7230 + && au_dcount(dentry) > 0
7232 + && (!arg->test || arg->test(dentry, arg->arg))) {
7233 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7234 + if (unlikely(arg->err))
7235 + ret = D_WALK_QUIT;
7241 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7242 + au_dpages_test test, void *arg)
7244 + struct ac_dpages_arg args = {
7252 + d_walk(root, &args, au_call_dpages_append);
7257 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7258 + int do_include, au_dpages_test test, void *arg)
7263 + write_seqlock(&rename_lock);
7264 + spin_lock(&dentry->d_lock);
7266 + && au_dcount(dentry) > 0
7267 + && (!test || test(dentry, arg)))
7268 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7269 + spin_unlock(&dentry->d_lock);
7270 + if (unlikely(err))
7274 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7277 + while (!IS_ROOT(dentry)) {
7278 + dentry = dentry->d_parent; /* rename_lock is locked */
7279 + spin_lock(&dentry->d_lock);
7280 + if (au_dcount(dentry) > 0
7281 + && (!test || test(dentry, arg)))
7282 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7283 + spin_unlock(&dentry->d_lock);
7284 + if (unlikely(err))
7289 + write_sequnlock(&rename_lock);
7293 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7295 + return au_di(dentry) && dentry->d_sb == arg;
7298 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7299 + struct dentry *dentry, int do_include)
7301 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7302 + au_dcsub_dpages_aufs, dentry->d_sb);
7305 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7307 + struct path path[2] = {
7316 + return path_is_under(path + 0, path + 1);
7318 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7319 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7320 +++ linux/fs/aufs/dcsub.h 2018-08-12 23:43:05.453457863 +0200
7322 +/* SPDX-License-Identifier: GPL-2.0 */
7324 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7326 + * This program, aufs is free software; you can redistribute it and/or modify
7327 + * it under the terms of the GNU General Public License as published by
7328 + * the Free Software Foundation; either version 2 of the License, or
7329 + * (at your option) any later version.
7331 + * This program is distributed in the hope that it will be useful,
7332 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7333 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7334 + * GNU General Public License for more details.
7336 + * You should have received a copy of the GNU General Public License
7337 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7341 + * sub-routines for dentry cache
7344 +#ifndef __AUFS_DCSUB_H__
7345 +#define __AUFS_DCSUB_H__
7349 +#include <linux/dcache.h>
7350 +#include <linux/fs.h>
7354 + struct dentry **dentries;
7357 +struct au_dcsub_pages {
7359 + struct au_dpage *dpages;
7362 +/* ---------------------------------------------------------------------- */
7365 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7366 +void au_dpages_free(struct au_dcsub_pages *dpages);
7367 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7368 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7369 + au_dpages_test test, void *arg);
7370 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7371 + int do_include, au_dpages_test test, void *arg);
7372 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7373 + struct dentry *dentry, int do_include);
7374 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7376 +/* ---------------------------------------------------------------------- */
7379 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7380 + * include/linux/dcache.h. Try them (in the future).
7383 +static inline int au_d_hashed_positive(struct dentry *d)
7386 + struct inode *inode = d_inode(d);
7389 + if (unlikely(d_unhashed(d)
7390 + || d_is_negative(d)
7391 + || !inode->i_nlink))
7396 +static inline int au_d_linkable(struct dentry *d)
7399 + struct inode *inode = d_inode(d);
7401 + err = au_d_hashed_positive(d);
7403 + && d_is_positive(d)
7404 + && (inode->i_state & I_LINKABLE))
7409 +static inline int au_d_alive(struct dentry *d)
7412 + struct inode *inode;
7416 + err = au_d_hashed_positive(d);
7418 + inode = d_inode(d);
7419 + if (unlikely(d_unlinked(d)
7420 + || d_is_negative(d)
7421 + || !inode->i_nlink))
7427 +static inline int au_alive_dir(struct dentry *d)
7431 + err = au_d_alive(d);
7432 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7437 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7439 + return a->len == b->len
7440 + && !memcmp(a->name, b->name, a->len);
7445 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7447 + * the type of d_lockref.count became int, but the inlined function d_count()
7448 + * still returns unsigned int.
7449 + * I don't know why. Maybe it is for every d_count() users?
7450 + * Anyway au_dcount() lives on.
7452 +static inline int au_dcount(struct dentry *d)
7454 + return (int)d_count(d);
7457 +#endif /* __KERNEL__ */
7458 +#endif /* __AUFS_DCSUB_H__ */
7459 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7460 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7461 +++ linux/fs/aufs/debug.c 2018-10-23 12:33:35.596042364 +0200
7463 +// SPDX-License-Identifier: GPL-2.0
7465 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7467 + * This program, aufs is free software; you can redistribute it and/or modify
7468 + * it under the terms of the GNU General Public License as published by
7469 + * the Free Software Foundation; either version 2 of the License, or
7470 + * (at your option) any later version.
7472 + * This program is distributed in the hope that it will be useful,
7473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7475 + * GNU General Public License for more details.
7477 + * You should have received a copy of the GNU General Public License
7478 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7482 + * debug print functions
7487 +/* Returns 0, or -errno. arg is in kp->arg. */
7488 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7492 + err = kstrtoint(val, 0, &n);
7502 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7503 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7508 + return sprintf(buffer, "%d", atomic_read(a));
7511 +static struct kernel_param_ops param_ops_atomic_t = {
7512 + .set = param_atomic_t_set,
7513 + .get = param_atomic_t_get
7514 + /* void (*free)(void *arg) */
7517 +atomic_t aufs_debug = ATOMIC_INIT(0);
7518 +MODULE_PARM_DESC(debug, "debug print");
7519 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7521 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7522 +char *au_plevel = KERN_DEBUG;
7523 +#define dpri(fmt, ...) do { \
7525 + && strcmp(au_plevel, KERN_DEBUG)) \
7526 + || au_debug_test()) \
7527 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7530 +/* ---------------------------------------------------------------------- */
7532 +void au_dpri_whlist(struct au_nhash *whlist)
7534 + unsigned long ul, n;
7535 + struct hlist_head *head;
7536 + struct au_vdir_wh *pos;
7538 + n = whlist->nh_num;
7539 + head = whlist->nh_head;
7540 + for (ul = 0; ul < n; ul++) {
7541 + hlist_for_each_entry(pos, head, wh_hash)
7542 + dpri("b%d, %.*s, %d\n",
7544 + pos->wh_str.len, pos->wh_str.name,
7550 +void au_dpri_vdir(struct au_vdir *vdir)
7553 + union au_vdir_deblk_p p;
7556 + if (!vdir || IS_ERR(vdir)) {
7557 + dpri("err %ld\n", PTR_ERR(vdir));
7561 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7562 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7563 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7564 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7565 + p.deblk = vdir->vd_deblk[ul];
7567 + dpri("[%lu]: %p\n", ul, o);
7571 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7572 + struct dentry *wh)
7577 + if (!inode || IS_ERR(inode)) {
7578 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7582 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7583 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7584 + && sizeof(inode->i_blocks) != sizeof(u64));
7586 + n = (void *)wh->d_name.name;
7587 + l = wh->d_name.len;
7590 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7591 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7593 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7594 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7595 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7596 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7597 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7598 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7599 + inode->i_generation,
7600 + l ? ", wh " : "", l, n);
7604 +void au_dpri_inode(struct inode *inode)
7606 + struct au_iinfo *iinfo;
7607 + struct au_hinode *hi;
7608 + aufs_bindex_t bindex;
7611 + err = do_pri_inode(-1, inode, -1, NULL);
7612 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7615 + iinfo = au_ii(inode);
7616 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7617 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7618 + if (iinfo->ii_btop < 0)
7621 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7622 + hi = au_hinode(iinfo, bindex);
7624 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7628 +void au_dpri_dalias(struct inode *inode)
7632 + spin_lock(&inode->i_lock);
7633 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7634 + au_dpri_dentry(d);
7635 + spin_unlock(&inode->i_lock);
7638 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7640 + struct dentry *wh = NULL;
7642 + struct inode *inode;
7643 + struct au_iinfo *iinfo;
7644 + struct au_hinode *hi;
7646 + if (!dentry || IS_ERR(dentry)) {
7647 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7650 + /* do not call dget_parent() here */
7651 + /* note: access d_xxx without d_lock */
7652 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7653 + bindex, dentry, dentry,
7654 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7655 + au_dcount(dentry), dentry->d_flags,
7656 + d_unhashed(dentry) ? "un" : "");
7659 + if (d_is_positive(dentry))
7660 + inode = d_inode(dentry);
7662 + && au_test_aufs(dentry->d_sb)
7664 + && !au_is_bad_inode(inode)) {
7665 + iinfo = au_ii(inode);
7666 + hi = au_hinode(iinfo, bindex);
7668 + wh = hi->hi_whdentry;
7670 + do_pri_inode(bindex, inode, hn, wh);
7674 +void au_dpri_dentry(struct dentry *dentry)
7676 + struct au_dinfo *dinfo;
7677 + aufs_bindex_t bindex;
7680 + err = do_pri_dentry(-1, dentry);
7681 + if (err || !au_test_aufs(dentry->d_sb))
7684 + dinfo = au_di(dentry);
7687 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7688 + dinfo->di_btop, dinfo->di_bbot,
7689 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7690 + dinfo->di_tmpfile);
7691 + if (dinfo->di_btop < 0)
7693 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7694 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7697 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7701 + if (!file || IS_ERR(file)) {
7702 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7707 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7708 + && au_test_aufs(file->f_path.dentry->d_sb)
7710 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7711 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7712 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7713 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7714 + file->f_version, file->f_pos, a);
7715 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7716 + do_pri_dentry(bindex, file->f_path.dentry);
7720 +void au_dpri_file(struct file *file)
7722 + struct au_finfo *finfo;
7723 + struct au_fidir *fidir;
7724 + struct au_hfile *hfile;
7725 + aufs_bindex_t bindex;
7728 + err = do_pri_file(-1, file);
7730 + || IS_ERR_OR_NULL(file->f_path.dentry)
7731 + || !au_test_aufs(file->f_path.dentry->d_sb))
7734 + finfo = au_fi(file);
7737 + if (finfo->fi_btop < 0)
7739 + fidir = finfo->fi_hdir;
7741 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7743 + for (bindex = finfo->fi_btop;
7744 + bindex >= 0 && bindex <= fidir->fd_bbot;
7746 + hfile = fidir->fd_hfile + bindex;
7747 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7751 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7753 + struct vfsmount *mnt;
7754 + struct super_block *sb;
7756 + if (!br || IS_ERR(br))
7758 + mnt = au_br_mnt(br);
7759 + if (!mnt || IS_ERR(mnt))
7762 + if (!sb || IS_ERR(sb))
7765 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7766 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7768 + bindex, br->br_perm, br->br_id, br->br_wbr,
7769 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7770 + sb->s_flags, sb->s_count,
7771 + atomic_read(&sb->s_active),
7772 + !!au_xino_file(br->br_xino, /*idx*/-1));
7776 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7780 +void au_dpri_sb(struct super_block *sb)
7782 + struct au_sbinfo *sbinfo;
7783 + aufs_bindex_t bindex;
7785 + /* to reduce stack size */
7787 + struct vfsmount mnt;
7788 + struct au_branch fake;
7791 + /* this function can be called from magic sysrq */
7792 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7793 + if (unlikely(!a)) {
7794 + dpri("no memory\n");
7798 + a->mnt.mnt_sb = sb;
7799 + a->fake.br_path.mnt = &a->mnt;
7800 + err = do_pri_br(-1, &a->fake);
7802 + dpri("dev 0x%x\n", sb->s_dev);
7803 + if (err || !au_test_aufs(sb))
7806 + sbinfo = au_sbi(sb);
7809 + dpri("nw %d, gen %u, kobj %d\n",
7810 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7811 + kref_read(&sbinfo->si_kobj.kref));
7812 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7813 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7816 +/* ---------------------------------------------------------------------- */
7818 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7820 + struct inode *h_inode, *inode = d_inode(dentry);
7821 + struct dentry *h_dentry;
7822 + aufs_bindex_t bindex, bbot, bi;
7824 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7827 + bbot = au_dbbot(dentry);
7828 + bi = au_ibbot(inode);
7831 + bindex = au_dbtop(dentry);
7832 + bi = au_ibtop(inode);
7836 + for (; bindex <= bbot; bindex++) {
7837 + h_dentry = au_h_dptr(dentry, bindex);
7840 + h_inode = au_h_iptr(inode, bindex);
7841 + if (unlikely(h_inode != d_inode(h_dentry))) {
7843 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7844 + AuDbgDentry(dentry);
7845 + AuDbgInode(inode);
7852 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7855 + struct au_dcsub_pages dpages;
7856 + struct au_dpage *dpage;
7857 + struct dentry **dentries;
7859 + err = au_dpages_init(&dpages, GFP_NOFS);
7861 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7863 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7864 + dpage = dpages.dpages + i;
7865 + dentries = dpage->dentries;
7866 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7867 + AuDebugOn(au_digen_test(dentries[j], sigen));
7869 + au_dpages_free(&dpages);
7872 +void au_dbg_verify_kthread(void)
7874 + if (au_wkq_test()) {
7877 + * It may be recursive, but udba=notify between two aufs mounts,
7878 + * where a single ro branch is shared, is not a problem.
7884 +/* ---------------------------------------------------------------------- */
7886 +int __init au_debug_init(void)
7888 + aufs_bindex_t bindex;
7889 + struct au_vdir_destr destr;
7892 + AuDebugOn(bindex >= 0);
7895 + AuDebugOn(destr.len < NAME_MAX);
7897 +#ifdef CONFIG_4KSTACKS
7898 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7903 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7904 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7905 +++ linux/fs/aufs/debug.h 2018-08-12 23:43:05.453457863 +0200
7907 +/* SPDX-License-Identifier: GPL-2.0 */
7909 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7911 + * This program, aufs is free software; you can redistribute it and/or modify
7912 + * it under the terms of the GNU General Public License as published by
7913 + * the Free Software Foundation; either version 2 of the License, or
7914 + * (at your option) any later version.
7916 + * This program is distributed in the hope that it will be useful,
7917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7919 + * GNU General Public License for more details.
7921 + * You should have received a copy of the GNU General Public License
7922 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7926 + * debug print functions
7929 +#ifndef __AUFS_DEBUG_H__
7930 +#define __AUFS_DEBUG_H__
7934 +#include <linux/atomic.h>
7935 +#include <linux/module.h>
7936 +#include <linux/kallsyms.h>
7937 +#include <linux/sysrq.h>
7939 +#ifdef CONFIG_AUFS_DEBUG
7940 +#define AuDebugOn(a) BUG_ON(a)
7942 +/* module parameter */
7943 +extern atomic_t aufs_debug;
7944 +static inline void au_debug_on(void)
7946 + atomic_inc(&aufs_debug);
7948 +static inline void au_debug_off(void)
7950 + atomic_dec_if_positive(&aufs_debug);
7953 +static inline int au_debug_test(void)
7955 + return atomic_read(&aufs_debug) > 0;
7958 +#define AuDebugOn(a) do {} while (0)
7959 +AuStubVoid(au_debug_on, void)
7960 +AuStubVoid(au_debug_off, void)
7961 +AuStubInt0(au_debug_test, void)
7962 +#endif /* CONFIG_AUFS_DEBUG */
7964 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7966 +/* ---------------------------------------------------------------------- */
7970 +#define AuDbg(fmt, ...) do { \
7971 + if (au_debug_test()) \
7972 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7974 +#define AuLabel(l) AuDbg(#l "\n")
7975 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7976 +#define AuWarn1(fmt, ...) do { \
7977 + static unsigned char _c; \
7979 + pr_warn(fmt, ##__VA_ARGS__); \
7982 +#define AuErr1(fmt, ...) do { \
7983 + static unsigned char _c; \
7985 + pr_err(fmt, ##__VA_ARGS__); \
7988 +#define AuIOErr1(fmt, ...) do { \
7989 + static unsigned char _c; \
7991 + AuIOErr(fmt, ##__VA_ARGS__); \
7994 +#define AuUnsupportMsg "This operation is not supported." \
7995 + " Please report this application to aufs-users ML."
7996 +#define AuUnsupport(fmt, ...) do { \
7997 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
8001 +#define AuTraceErr(e) do { \
8002 + if (unlikely((e) < 0)) \
8003 + AuDbg("err %d\n", (int)(e)); \
8006 +#define AuTraceErrPtr(p) do { \
8008 + AuDbg("err %ld\n", PTR_ERR(p)); \
8011 +/* dirty macros for debug print, use with "%.*s" and caution */
8012 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8014 +/* ---------------------------------------------------------------------- */
8017 +#ifdef CONFIG_AUFS_DEBUG
8018 +extern struct mutex au_dbg_mtx;
8019 +extern char *au_plevel;
8021 +void au_dpri_whlist(struct au_nhash *whlist);
8023 +void au_dpri_vdir(struct au_vdir *vdir);
8025 +void au_dpri_inode(struct inode *inode);
8026 +void au_dpri_dalias(struct inode *inode);
8027 +void au_dpri_dentry(struct dentry *dentry);
8029 +void au_dpri_file(struct file *filp);
8030 +struct super_block;
8031 +void au_dpri_sb(struct super_block *sb);
8033 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8034 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8035 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8036 +void au_dbg_verify_kthread(void);
8038 +int __init au_debug_init(void);
8040 +#define AuDbgWhlist(w) do { \
8041 + mutex_lock(&au_dbg_mtx); \
8043 + au_dpri_whlist(w); \
8044 + mutex_unlock(&au_dbg_mtx); \
8047 +#define AuDbgVdir(v) do { \
8048 + mutex_lock(&au_dbg_mtx); \
8050 + au_dpri_vdir(v); \
8051 + mutex_unlock(&au_dbg_mtx); \
8054 +#define AuDbgInode(i) do { \
8055 + mutex_lock(&au_dbg_mtx); \
8057 + au_dpri_inode(i); \
8058 + mutex_unlock(&au_dbg_mtx); \
8061 +#define AuDbgDAlias(i) do { \
8062 + mutex_lock(&au_dbg_mtx); \
8064 + au_dpri_dalias(i); \
8065 + mutex_unlock(&au_dbg_mtx); \
8068 +#define AuDbgDentry(d) do { \
8069 + mutex_lock(&au_dbg_mtx); \
8071 + au_dpri_dentry(d); \
8072 + mutex_unlock(&au_dbg_mtx); \
8075 +#define AuDbgFile(f) do { \
8076 + mutex_lock(&au_dbg_mtx); \
8078 + au_dpri_file(f); \
8079 + mutex_unlock(&au_dbg_mtx); \
8082 +#define AuDbgSb(sb) do { \
8083 + mutex_lock(&au_dbg_mtx); \
8084 + AuDbg(#sb "\n"); \
8086 + mutex_unlock(&au_dbg_mtx); \
8089 +#define AuDbgSym(addr) do { \
8090 + char sym[KSYM_SYMBOL_LEN]; \
8091 + sprint_symbol(sym, (unsigned long)addr); \
8092 + AuDbg("%s\n", sym); \
8095 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8096 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8097 +AuStubVoid(au_dbg_verify_kthread, void)
8098 +AuStubInt0(__init au_debug_init, void)
8100 +#define AuDbgWhlist(w) do {} while (0)
8101 +#define AuDbgVdir(v) do {} while (0)
8102 +#define AuDbgInode(i) do {} while (0)
8103 +#define AuDbgDAlias(i) do {} while (0)
8104 +#define AuDbgDentry(d) do {} while (0)
8105 +#define AuDbgFile(f) do {} while (0)
8106 +#define AuDbgSb(sb) do {} while (0)
8107 +#define AuDbgSym(addr) do {} while (0)
8108 +#endif /* CONFIG_AUFS_DEBUG */
8110 +/* ---------------------------------------------------------------------- */
8112 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8113 +int __init au_sysrq_init(void);
8114 +void au_sysrq_fin(void);
8116 +#ifdef CONFIG_HW_CONSOLE
8117 +#define au_dbg_blocked() do { \
8119 + handle_sysrq('w'); \
8122 +AuStubVoid(au_dbg_blocked, void)
8126 +AuStubInt0(__init au_sysrq_init, void)
8127 +AuStubVoid(au_sysrq_fin, void)
8128 +AuStubVoid(au_dbg_blocked, void)
8129 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8131 +#endif /* __KERNEL__ */
8132 +#endif /* __AUFS_DEBUG_H__ */
8133 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8134 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8135 +++ linux/fs/aufs/dentry.c 2018-10-23 12:33:35.596042364 +0200
8137 +// SPDX-License-Identifier: GPL-2.0
8139 + * Copyright (C) 2005-2018 Junjiro R. Okajima
8141 + * This program, aufs is free software; you can redistribute it and/or modify
8142 + * it under the terms of the GNU General Public License as published by
8143 + * the Free Software Foundation; either version 2 of the License, or
8144 + * (at your option) any later version.
8146 + * This program is distributed in the hope that it will be useful,
8147 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8148 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8149 + * GNU General Public License for more details.
8151 + * You should have received a copy of the GNU General Public License
8152 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8156 + * lookup and dentry operations
8159 +#include <linux/namei.h>
8163 + * returns positive/negative dentry, NULL or an error.
8164 + * NULL means whiteout-ed or not-found.
8166 +static struct dentry*
8167 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8168 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8170 + struct dentry *h_dentry;
8171 + struct inode *h_inode;
8172 + struct au_branch *br;
8173 + int wh_found, opq;
8174 + unsigned char wh_able;
8175 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8176 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8180 + br = au_sbr(dentry->d_sb, bindex);
8181 + wh_able = !!au_br_whable(br->br_perm);
8183 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8184 + h_dentry = ERR_PTR(wh_found);
8187 + if (unlikely(wh_found < 0))
8190 + /* We found a whiteout */
8191 + /* au_set_dbbot(dentry, bindex); */
8192 + au_set_dbwh(dentry, bindex);
8194 + return NULL; /* success */
8198 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8200 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8201 + if (IS_ERR(h_dentry)) {
8202 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8208 + h_inode = d_inode(h_dentry);
8209 + if (d_is_negative(h_dentry)) {
8212 + } else if (wh_found
8213 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8215 + else if (au_ftest_lkup(args->flags, DIRREN)
8217 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8218 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8219 + (unsigned long long)h_inode->i_ino);
8223 + if (au_dbbot(dentry) <= bindex)
8224 + au_set_dbbot(dentry, bindex);
8225 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8226 + au_set_dbtop(dentry, bindex);
8227 + au_set_h_dptr(dentry, bindex, h_dentry);
8229 + if (!d_is_dir(h_dentry)
8231 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8232 + goto out; /* success */
8234 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8235 + opq = au_diropq_test(h_dentry);
8236 + inode_unlock_shared(h_inode);
8238 + au_set_dbdiropq(dentry, bindex);
8239 + else if (unlikely(opq < 0)) {
8240 + au_set_h_dptr(dentry, bindex, NULL);
8241 + h_dentry = ERR_PTR(opq);
8252 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8254 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8255 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8261 + * returns the number of lower positive dentries,
8262 + * otherwise an error.
8263 + * can be called at unlinking with @type is zero.
8265 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8266 + unsigned int flags)
8268 + int npositive, err;
8269 + aufs_bindex_t bindex, btail, bdiropq;
8270 + unsigned char isdir, dirperm1, dirren;
8271 + struct au_do_lookup_args args = {
8273 + .name = &dentry->d_name
8275 + struct dentry *parent;
8276 + struct super_block *sb;
8278 + sb = dentry->d_sb;
8279 + err = au_test_shwh(sb, args.name);
8280 + if (unlikely(err))
8283 + err = au_wh_name_alloc(&args.whname, args.name);
8284 + if (unlikely(err))
8287 + isdir = !!d_is_dir(dentry);
8288 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8289 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8291 + au_fset_lkup(args.flags, DIRREN);
8294 + parent = dget_parent(dentry);
8295 + btail = au_dbtaildir(parent);
8296 + for (bindex = btop; bindex <= btail; bindex++) {
8297 + struct dentry *h_parent, *h_dentry;
8298 + struct inode *h_inode, *h_dir;
8299 + struct au_branch *br;
8301 + h_dentry = au_h_dptr(dentry, bindex);
8303 + if (d_is_positive(h_dentry))
8307 + h_parent = au_h_dptr(parent, bindex);
8308 + if (!h_parent || !d_is_dir(h_parent))
8312 + /* if the inum matches, then use the prepared name */
8313 + err = au_dr_lkup_name(&args, bindex);
8314 + if (unlikely(err))
8318 + h_dir = d_inode(h_parent);
8319 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8320 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8321 + inode_unlock_shared(h_dir);
8322 + err = PTR_ERR(h_dentry);
8323 + if (IS_ERR(h_dentry))
8326 + au_fclr_lkup(args.flags, ALLOW_NEG);
8328 + au_fset_lkup(args.flags, IGNORE_PERM);
8330 + if (au_dbwh(dentry) == bindex)
8334 + if (d_is_negative(h_dentry))
8336 + h_inode = d_inode(h_dentry);
8339 + args.type = h_inode->i_mode & S_IFMT;
8340 + if (args.type != S_IFDIR)
8343 + /* the type of lower may be different */
8344 + bdiropq = au_dbdiropq(dentry);
8345 + if (bdiropq >= 0 && bdiropq <= bindex)
8348 + br = au_sbr(sb, bindex);
8350 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8351 + /*add_ent*/NULL)) {
8352 + /* prepare next name to lookup */
8353 + err = au_dr_lkup(&args, dentry, bindex);
8354 + if (unlikely(err))
8360 + AuLabel(positive);
8361 + au_update_dbtop(dentry);
8364 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8365 + && au_dbtop(dentry) < 0)) {
8367 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8373 + kfree(args.whname.name);
8375 + au_dr_lkup_fin(&args);
8380 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8382 + struct dentry *dentry;
8385 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8386 + dentry = vfsub_lkup_one(name, parent);
8388 + struct vfsub_lkup_one_args args = {
8394 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8395 + if (unlikely(wkq_err))
8396 + dentry = ERR_PTR(wkq_err);
8403 + * lookup @dentry on @bindex which should be negative.
8405 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8408 + struct dentry *parent, *h_parent, *h_dentry;
8409 + struct au_branch *br;
8411 + parent = dget_parent(dentry);
8412 + h_parent = au_h_dptr(parent, bindex);
8413 + br = au_sbr(dentry->d_sb, bindex);
8415 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8417 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8418 + err = PTR_ERR(h_dentry);
8419 + if (IS_ERR(h_dentry))
8421 + if (unlikely(d_is_positive(h_dentry))) {
8423 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8429 + if (bindex < au_dbtop(dentry))
8430 + au_set_dbtop(dentry, bindex);
8431 + if (au_dbbot(dentry) < bindex)
8432 + au_set_dbbot(dentry, bindex);
8433 + au_set_h_dptr(dentry, bindex, h_dentry);
8440 +/* ---------------------------------------------------------------------- */
8442 +/* subset of struct inode */
8444 + unsigned long i_ino;
8445 + /* unsigned int i_nlink; */
8451 + blkcnt_t i_blocks;
8456 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8458 + ia->i_ino = h_inode->i_ino;
8459 + /* ia->i_nlink = h_inode->i_nlink; */
8460 + ia->i_uid = h_inode->i_uid;
8461 + ia->i_gid = h_inode->i_gid;
8462 + ia->i_version = inode_query_iversion(h_inode);
8464 + ia->i_size = h_inode->i_size;
8465 + ia->i_blocks = h_inode->i_blocks;
8467 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8470 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8472 + return ia->i_ino != h_inode->i_ino
8473 + /* || ia->i_nlink != h_inode->i_nlink */
8474 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8475 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8476 + || !inode_eq_iversion(h_inode, ia->i_version)
8478 + || ia->i_size != h_inode->i_size
8479 + || ia->i_blocks != h_inode->i_blocks
8481 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8484 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8485 + struct au_branch *br)
8488 + struct au_iattr ia;
8489 + struct inode *h_inode;
8490 + struct dentry *h_d;
8491 + struct super_block *h_sb;
8494 + memset(&ia, -1, sizeof(ia));
8495 + h_sb = h_dentry->d_sb;
8497 + if (d_is_positive(h_dentry)) {
8498 + h_inode = d_inode(h_dentry);
8499 + au_iattr_save(&ia, h_inode);
8500 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8501 + /* nfs d_revalidate may return 0 for negative dentry */
8502 + /* fuse d_revalidate always return 0 for negative dentry */
8505 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8506 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8507 + err = PTR_ERR(h_d);
8512 + if (unlikely(h_d != h_dentry
8513 + || d_inode(h_d) != h_inode
8514 + || (h_inode && au_iattr_test(&ia, h_inode))))
8515 + err = au_busy_or_stale();
8523 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8524 + struct dentry *h_parent, struct au_branch *br)
8529 + if (udba == AuOpt_UDBA_REVAL
8530 + && !au_test_fs_remote(h_dentry->d_sb)) {
8532 + err = (d_inode(h_dentry->d_parent) != h_dir);
8533 + } else if (udba != AuOpt_UDBA_NONE)
8534 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8539 +/* ---------------------------------------------------------------------- */
8541 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8544 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8545 + struct au_hdentry tmp, *p, *q;
8546 + struct au_dinfo *dinfo;
8547 + struct super_block *sb;
8549 + DiMustWriteLock(dentry);
8551 + sb = dentry->d_sb;
8552 + dinfo = au_di(dentry);
8553 + bbot = dinfo->di_bbot;
8554 + bwh = dinfo->di_bwh;
8555 + bdiropq = dinfo->di_bdiropq;
8556 + bindex = dinfo->di_btop;
8557 + p = au_hdentry(dinfo, bindex);
8558 + for (; bindex <= bbot; bindex++, p++) {
8559 + if (!p->hd_dentry)
8562 + new_bindex = au_br_index(sb, p->hd_id);
8563 + if (new_bindex == bindex)
8566 + if (dinfo->di_bwh == bindex)
8568 + if (dinfo->di_bdiropq == bindex)
8569 + bdiropq = new_bindex;
8570 + if (new_bindex < 0) {
8572 + p->hd_dentry = NULL;
8576 + /* swap two lower dentries, and loop again */
8577 + q = au_hdentry(dinfo, new_bindex);
8581 + if (tmp.hd_dentry) {
8587 + dinfo->di_bwh = -1;
8588 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8589 + dinfo->di_bwh = bwh;
8591 + dinfo->di_bdiropq = -1;
8593 + && bdiropq <= au_sbbot(sb)
8594 + && au_sbr_whable(sb, bdiropq))
8595 + dinfo->di_bdiropq = bdiropq;
8598 + dinfo->di_btop = -1;
8599 + dinfo->di_bbot = -1;
8600 + bbot = au_dbbot(parent);
8602 + p = au_hdentry(dinfo, bindex);
8603 + for (; bindex <= bbot; bindex++, p++)
8604 + if (p->hd_dentry) {
8605 + dinfo->di_btop = bindex;
8609 + if (dinfo->di_btop >= 0) {
8611 + p = au_hdentry(dinfo, bindex);
8612 + for (; bindex >= 0; bindex--, p--)
8613 + if (p->hd_dentry) {
8614 + dinfo->di_bbot = bindex;
8623 +static void au_do_hide(struct dentry *dentry)
8625 + struct inode *inode;
8627 + if (d_really_is_positive(dentry)) {
8628 + inode = d_inode(dentry);
8629 + if (!d_is_dir(dentry)) {
8630 + if (inode->i_nlink && !d_unhashed(dentry))
8631 + drop_nlink(inode);
8633 + clear_nlink(inode);
8634 + /* stop next lookup */
8635 + inode->i_flags |= S_DEAD;
8637 + smp_mb(); /* necessary? */
8642 +static int au_hide_children(struct dentry *parent)
8644 + int err, i, j, ndentry;
8645 + struct au_dcsub_pages dpages;
8646 + struct au_dpage *dpage;
8647 + struct dentry *dentry;
8649 + err = au_dpages_init(&dpages, GFP_NOFS);
8650 + if (unlikely(err))
8652 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8653 + if (unlikely(err))
8656 + /* in reverse order */
8657 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8658 + dpage = dpages.dpages + i;
8659 + ndentry = dpage->ndentry;
8660 + for (j = ndentry - 1; j >= 0; j--) {
8661 + dentry = dpage->dentries[j];
8662 + if (dentry != parent)
8663 + au_do_hide(dentry);
8668 + au_dpages_free(&dpages);
8673 +static void au_hide(struct dentry *dentry)
8677 + AuDbgDentry(dentry);
8678 + if (d_is_dir(dentry)) {
8679 + /* shrink_dcache_parent(dentry); */
8680 + err = au_hide_children(dentry);
8681 + if (unlikely(err))
8682 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8685 + au_do_hide(dentry);
8689 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8691 + * a dirty branch is added
8692 + * - on the top of layers
8693 + * - in the middle of layers
8694 + * - to the bottom of layers
8696 + * on the added branch there exists
8699 + * - a same named entry
8701 + * * negative --> positive
8702 + * * positive --> positive
8703 + * - type is unchanged
8704 + * - type is changed
8706 + * * negative --> negative
8707 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8710 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8711 + struct au_dinfo *tmp)
8714 + aufs_bindex_t bindex, bbot;
8716 + struct dentry *dentry;
8717 + struct inode *inode;
8719 + } orig_h, tmp_h = {
8722 + struct au_hdentry *hd;
8723 + struct inode *inode, *h_inode;
8724 + struct dentry *h_dentry;
8727 + AuDebugOn(dinfo->di_btop < 0);
8729 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8730 + orig_h.inode = NULL;
8731 + if (d_is_positive(orig_h.dentry)) {
8732 + orig_h.inode = d_inode(orig_h.dentry);
8733 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8735 + if (tmp->di_btop >= 0) {
8736 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8737 + if (d_is_positive(tmp_h.dentry)) {
8738 + tmp_h.inode = d_inode(tmp_h.dentry);
8739 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8744 + if (d_really_is_positive(dentry))
8745 + inode = d_inode(dentry);
8746 + if (!orig_h.inode) {
8747 + AuDbg("negative originally\n");
8753 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8754 + AuDebugOn(dinfo->di_bdiropq != -1);
8756 + if (!tmp_h.inode) {
8757 + AuDbg("negative --> negative\n");
8758 + /* should have only one negative lower */
8759 + if (tmp->di_btop >= 0
8760 + && tmp->di_btop < dinfo->di_btop) {
8761 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8762 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8763 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8764 + au_di_cp(dinfo, tmp);
8765 + hd = au_hdentry(tmp, tmp->di_btop);
8766 + au_set_h_dptr(dentry, tmp->di_btop,
8767 + dget(hd->hd_dentry));
8769 + au_dbg_verify_dinode(dentry);
8771 + AuDbg("negative --> positive\n");
8773 + * similar to the behaviour of creating with bypassing
8775 + * unhash it in order to force an error in the
8776 + * succeeding create operation.
8777 + * we should not set S_DEAD here.
8780 + /* au_di_swap(tmp, dinfo); */
8781 + au_dbg_verify_dinode(dentry);
8784 + AuDbg("positive originally\n");
8785 + /* inode may be NULL */
8786 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8787 + if (!tmp_h.inode) {
8788 + AuDbg("positive --> negative\n");
8789 + /* or bypassing aufs */
8791 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8792 + dinfo->di_bwh = tmp->di_bwh;
8794 + err = au_refresh_hinode_self(inode);
8795 + au_dbg_verify_dinode(dentry);
8796 + } else if (orig_h.mode == tmp_h.mode) {
8797 + AuDbg("positive --> positive, same type\n");
8798 + if (!S_ISDIR(orig_h.mode)
8799 + && dinfo->di_btop > tmp->di_btop) {
8801 + * similar to the behaviour of removing and
8806 + err = au_refresh_hinode_self(inode);
8807 + au_dbg_verify_dinode(dentry);
8809 + /* fill empty slots */
8810 + if (dinfo->di_btop > tmp->di_btop)
8811 + dinfo->di_btop = tmp->di_btop;
8812 + if (dinfo->di_bbot < tmp->di_bbot)
8813 + dinfo->di_bbot = tmp->di_bbot;
8814 + dinfo->di_bwh = tmp->di_bwh;
8815 + dinfo->di_bdiropq = tmp->di_bdiropq;
8816 + bbot = dinfo->di_bbot;
8817 + bindex = tmp->di_btop;
8818 + hd = au_hdentry(tmp, bindex);
8819 + for (; bindex <= bbot; bindex++, hd++) {
8820 + if (au_h_dptr(dentry, bindex))
8822 + h_dentry = hd->hd_dentry;
8825 + AuDebugOn(d_is_negative(h_dentry));
8826 + h_inode = d_inode(h_dentry);
8827 + AuDebugOn(orig_h.mode
8828 + != (h_inode->i_mode
8830 + au_set_h_dptr(dentry, bindex,
8834 + err = au_refresh_hinode(inode, dentry);
8835 + au_dbg_verify_dinode(dentry);
8838 + AuDbg("positive --> positive, different type\n");
8839 + /* similar to the behaviour of removing and creating */
8842 + err = au_refresh_hinode_self(inode);
8843 + au_dbg_verify_dinode(dentry);
8851 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8853 + const struct dentry_operations *dop
8854 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8855 + static const unsigned int mask
8856 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8858 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8860 + if (dentry->d_op == dop)
8863 + AuDbg("%pd\n", dentry);
8864 + spin_lock(&dentry->d_lock);
8865 + if (dop == &aufs_dop)
8866 + dentry->d_flags |= mask;
8868 + dentry->d_flags &= ~mask;
8869 + dentry->d_op = dop;
8870 + spin_unlock(&dentry->d_lock);
8873 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8875 + int err, ebrange, nbr;
8876 + unsigned int sigen;
8877 + struct au_dinfo *dinfo, *tmp;
8878 + struct super_block *sb;
8879 + struct inode *inode;
8881 + DiMustWriteLock(dentry);
8882 + AuDebugOn(IS_ROOT(dentry));
8883 + AuDebugOn(d_really_is_negative(parent));
8885 + sb = dentry->d_sb;
8886 + sigen = au_sigen(sb);
8887 + err = au_digen_test(parent, sigen);
8888 + if (unlikely(err))
8891 + nbr = au_sbbot(sb) + 1;
8892 + dinfo = au_di(dentry);
8893 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8894 + if (unlikely(err))
8896 + ebrange = au_dbrange_test(dentry);
8898 + ebrange = au_do_refresh_hdentry(dentry, parent);
8900 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8901 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8902 + if (d_really_is_positive(dentry)) {
8903 + inode = d_inode(dentry);
8904 + err = au_refresh_hinode_self(inode);
8906 + au_dbg_verify_dinode(dentry);
8908 + goto out_dgen; /* success */
8912 + /* temporary dinfo */
8913 + AuDbgDentry(dentry);
8915 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8916 + if (unlikely(!tmp))
8918 + au_di_swap(tmp, dinfo);
8919 + /* returns the number of positive dentries */
8921 + * if current working dir is removed, it returns an error.
8922 + * but the dentry is legal.
8924 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8925 + AuDbgDentry(dentry);
8926 + au_di_swap(tmp, dinfo);
8927 + if (err == -ENOENT)
8930 + /* compare/refresh by dinfo */
8931 + AuDbgDentry(dentry);
8932 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8933 + au_dbg_verify_dinode(dentry);
8936 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8937 + au_rw_write_unlock(&tmp->di_rwsem);
8939 + if (unlikely(err))
8943 + au_update_digen(dentry);
8945 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8946 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8947 + AuDbgDentry(dentry);
8953 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8954 + struct dentry *dentry, aufs_bindex_t bindex)
8959 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8962 + AuDbg("b%d\n", bindex);
8964 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8965 + * due to whiteout and branch permission.
8967 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8968 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8969 + /* it may return tri-state */
8970 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8972 + if (unlikely(valid < 0))
8982 +/* todo: remove this */
8983 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8984 + unsigned int flags, int do_udba, int dirren)
8987 + umode_t mode, h_mode;
8988 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8989 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8990 + struct inode *h_inode, *h_cached_inode;
8991 + struct dentry *h_dentry;
8992 + struct qstr *name, *h_name;
8999 + unhashed = !!d_unhashed(dentry);
9000 + is_root = !!IS_ROOT(dentry);
9001 + name = &dentry->d_name;
9002 + tmpfile = au_di(dentry)->di_tmpfile;
9005 + * Theoretically, REVAL test should be unnecessary in case of
9007 + * But {fs,i}notify doesn't fire some necessary events,
9008 + * IN_ATTRIB for atime/nlink/pageio
9009 + * Let's do REVAL test too.
9011 + if (do_udba && inode) {
9012 + mode = (inode->i_mode & S_IFMT);
9013 + plus = (inode->i_nlink > 0);
9014 + ibs = au_ibtop(inode);
9015 + ibe = au_ibbot(inode);
9018 + btop = au_dbtop(dentry);
9020 + if (inode && S_ISDIR(inode->i_mode))
9021 + btail = au_dbtaildir(dentry);
9022 + for (bindex = btop; bindex <= btail; bindex++) {
9023 + h_dentry = au_h_dptr(dentry, bindex);
9027 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9028 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9029 + spin_lock(&h_dentry->d_lock);
9030 + h_name = &h_dentry->d_name;
9031 + if (unlikely(do_udba
9034 + && (unhashed != !!d_unhashed(h_dentry)
9035 + || (!tmpfile && !dirren
9036 + && !au_qstreq(name, h_name))
9039 + && !(flags & LOOKUP_OPEN)
9040 + && (h_dentry->d_flags
9041 + & DCACHE_NFSFS_RENAMED)))
9045 + h_unhashed = d_unhashed(h_dentry);
9046 + spin_unlock(&h_dentry->d_lock);
9047 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9048 + unhashed, h_unhashed, dentry, h_dentry);
9051 + spin_unlock(&h_dentry->d_lock);
9053 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9054 + if (unlikely(err))
9055 + /* do not goto err, to keep the errno */
9058 + /* todo: plink too? */
9063 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9067 + if (d_is_positive(h_dentry))
9068 + h_inode = d_inode(h_dentry);
9071 + h_cached_inode = h_inode;
9073 + h_mode = (h_inode->i_mode & S_IFMT);
9074 + h_plus = (h_inode->i_nlink > 0);
9076 + if (inode && ibs <= bindex && bindex <= ibe)
9077 + h_cached_inode = au_h_iptr(inode, bindex);
9080 + if (unlikely(plus != h_plus && !tmpfile))
9083 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9085 + && !IS_ROOT(h_dentry)
9086 + && unhashed != d_unhashed(h_dentry)))
9089 + if (unlikely(mode != h_mode
9090 + || h_cached_inode != h_inode))
9103 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9104 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9107 + struct dentry *parent;
9109 + if (!au_digen_test(dentry, sigen))
9112 + parent = dget_parent(dentry);
9113 + di_read_lock_parent(parent, AuLock_IR);
9114 + AuDebugOn(au_digen_test(parent, sigen));
9115 + au_dbg_verify_gen(parent, sigen);
9116 + err = au_refresh_dentry(dentry, parent);
9117 + di_read_unlock(parent, AuLock_IR);
9123 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9126 + struct dentry *d, *parent;
9128 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9129 + return simple_reval_dpath(dentry, sigen);
9131 + /* slow loop, keep it simple and stupid */
9132 + /* cf: au_cpup_dirs() */
9135 + while (au_digen_test(dentry, sigen)) {
9139 + parent = dget_parent(d);
9140 + if (!au_digen_test(parent, sigen))
9146 + di_write_lock_child2(d);
9148 + /* someone might update our dentry while we were sleeping */
9149 + if (au_digen_test(d, sigen)) {
9151 + * todo: consolidate with simple_reval_dpath(),
9152 + * do_refresh() and au_reval_for_attr().
9154 + di_read_lock_parent(parent, AuLock_IR);
9155 + err = au_refresh_dentry(d, parent);
9156 + di_read_unlock(parent, AuLock_IR);
9160 + di_write_unlock(d);
9162 + if (unlikely(err))
9170 + * if valid returns 1, otherwise 0.
9172 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9175 + unsigned int sigen;
9176 + unsigned char do_udba, dirren;
9177 + struct super_block *sb;
9178 + struct inode *inode;
9180 + /* todo: support rcu-walk? */
9181 + if (flags & LOOKUP_RCU)
9185 + if (unlikely(!au_di(dentry)))
9189 + sb = dentry->d_sb;
9192 + * i_mutex of parent dir may be held,
9193 + * but we should not return 'invalid' due to busy.
9195 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9196 + if (unlikely(err)) {
9202 + if (d_really_is_positive(dentry))
9203 + inode = d_inode(dentry);
9204 + if (unlikely(inode && au_is_bad_inode(inode))) {
9209 + if (unlikely(au_dbrange_test(dentry))) {
9215 + sigen = au_sigen(sb);
9216 + if (au_digen_test(dentry, sigen)) {
9217 + AuDebugOn(IS_ROOT(dentry));
9218 + err = au_reval_dpath(dentry, sigen);
9219 + if (unlikely(err)) {
9224 + di_downgrade_lock(dentry, AuLock_IR);
9227 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9229 + && !(inode->i_state && I_LINKABLE)
9230 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9235 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9236 + if (do_udba && inode) {
9237 + aufs_bindex_t btop = au_ibtop(inode);
9238 + struct inode *h_inode;
9241 + h_inode = au_h_iptr(inode, btop);
9242 + if (h_inode && au_test_higen(inode, h_inode)) {
9249 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9250 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9251 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9253 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9259 + di_downgrade_lock(dentry, AuLock_IR);
9261 + aufs_read_unlock(dentry, AuLock_IR);
9266 + AuDbg("%pd invalid, %d\n", dentry, valid);
9272 +static void aufs_d_release(struct dentry *dentry)
9274 + if (au_di(dentry)) {
9275 + au_di_fin(dentry);
9276 + au_hn_di_reinit(dentry);
9280 +const struct dentry_operations aufs_dop = {
9281 + .d_revalidate = aufs_d_revalidate,
9282 + .d_weak_revalidate = aufs_d_revalidate,
9283 + .d_release = aufs_d_release
9286 +/* aufs_dop without d_revalidate */
9287 +const struct dentry_operations aufs_dop_noreval = {
9288 + .d_release = aufs_d_release
9290 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9291 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9292 +++ linux/fs/aufs/dentry.h 2018-08-12 23:43:05.453457863 +0200
9294 +/* SPDX-License-Identifier: GPL-2.0 */
9296 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9298 + * This program, aufs is free software; you can redistribute it and/or modify
9299 + * it under the terms of the GNU General Public License as published by
9300 + * the Free Software Foundation; either version 2 of the License, or
9301 + * (at your option) any later version.
9303 + * This program is distributed in the hope that it will be useful,
9304 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9305 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9306 + * GNU General Public License for more details.
9308 + * You should have received a copy of the GNU General Public License
9309 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9313 + * lookup and dentry operations
9316 +#ifndef __AUFS_DENTRY_H__
9317 +#define __AUFS_DENTRY_H__
9321 +#include <linux/dcache.h>
9322 +#include "dirren.h"
9325 +struct au_hdentry {
9326 + struct dentry *hd_dentry;
9327 + aufs_bindex_t hd_id;
9331 + atomic_t di_generation;
9333 + struct au_rwsem di_rwsem;
9334 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9335 + unsigned char di_tmpfile; /* to allow the different name */
9336 + struct au_hdentry *di_hdentry;
9337 +} ____cacheline_aligned_in_smp;
9339 +/* ---------------------------------------------------------------------- */
9341 +/* flags for au_lkup_dentry() */
9342 +#define AuLkup_ALLOW_NEG 1
9343 +#define AuLkup_IGNORE_PERM (1 << 1)
9344 +#define AuLkup_DIRREN (1 << 2)
9345 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9346 +#define au_fset_lkup(flags, name) \
9347 + do { (flags) |= AuLkup_##name; } while (0)
9348 +#define au_fclr_lkup(flags, name) \
9349 + do { (flags) &= ~AuLkup_##name; } while (0)
9351 +#ifndef CONFIG_AUFS_DIRREN
9352 +#undef AuLkup_DIRREN
9353 +#define AuLkup_DIRREN 0
9356 +struct au_do_lookup_args {
9357 + unsigned int flags;
9359 + struct qstr whname, *name;
9360 + struct au_dr_lookup dirren;
9363 +/* ---------------------------------------------------------------------- */
9366 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9368 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9369 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9370 + struct dentry *h_parent, struct au_branch *br);
9372 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9373 + unsigned int flags);
9374 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9375 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9376 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9377 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9380 +void au_di_init_once(void *_di);
9381 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9382 +void au_di_free(struct au_dinfo *dinfo);
9383 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9384 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9385 +int au_di_init(struct dentry *dentry);
9386 +void au_di_fin(struct dentry *dentry);
9387 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9389 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9390 +void di_read_unlock(struct dentry *d, int flags);
9391 +void di_downgrade_lock(struct dentry *d, int flags);
9392 +void di_write_lock(struct dentry *d, unsigned int lsc);
9393 +void di_write_unlock(struct dentry *d);
9394 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9395 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9396 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9398 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9399 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9400 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9401 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9403 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9404 + struct dentry *h_dentry);
9405 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9406 +int au_dbrange_test(struct dentry *dentry);
9407 +void au_update_digen(struct dentry *dentry);
9408 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9409 +void au_update_dbtop(struct dentry *dentry);
9410 +void au_update_dbbot(struct dentry *dentry);
9411 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9413 +/* ---------------------------------------------------------------------- */
9415 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9417 + return dentry->d_fsdata;
9420 +/* ---------------------------------------------------------------------- */
9422 +/* lock subclass for dinfo */
9424 + AuLsc_DI_CHILD, /* child first */
9425 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9426 + AuLsc_DI_CHILD3, /* copyup dirs */
9430 + AuLsc_DI_TMP /* temp for replacing dinfo */
9434 + * di_read_lock_child, di_write_lock_child,
9435 + * di_read_lock_child2, di_write_lock_child2,
9436 + * di_read_lock_child3, di_write_lock_child3,
9437 + * di_read_lock_parent, di_write_lock_parent,
9438 + * di_read_lock_parent2, di_write_lock_parent2,
9439 + * di_read_lock_parent3, di_write_lock_parent3,
9441 +#define AuReadLockFunc(name, lsc) \
9442 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9443 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9445 +#define AuWriteLockFunc(name, lsc) \
9446 +static inline void di_write_lock_##name(struct dentry *d) \
9447 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9449 +#define AuRWLockFuncs(name, lsc) \
9450 + AuReadLockFunc(name, lsc) \
9451 + AuWriteLockFunc(name, lsc)
9453 +AuRWLockFuncs(child, CHILD);
9454 +AuRWLockFuncs(child2, CHILD2);
9455 +AuRWLockFuncs(child3, CHILD3);
9456 +AuRWLockFuncs(parent, PARENT);
9457 +AuRWLockFuncs(parent2, PARENT2);
9458 +AuRWLockFuncs(parent3, PARENT3);
9460 +#undef AuReadLockFunc
9461 +#undef AuWriteLockFunc
9462 +#undef AuRWLockFuncs
9464 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9465 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9466 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9468 +/* ---------------------------------------------------------------------- */
9470 +/* todo: memory barrier? */
9471 +static inline unsigned int au_digen(struct dentry *d)
9473 + return atomic_read(&au_di(d)->di_generation);
9476 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9478 + hdentry->hd_dentry = NULL;
9481 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9482 + aufs_bindex_t bindex)
9484 + return di->di_hdentry + bindex;
9487 +static inline void au_hdput(struct au_hdentry *hd)
9490 + dput(hd->hd_dentry);
9493 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9495 + DiMustAnyLock(dentry);
9496 + return au_di(dentry)->di_btop;
9499 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9501 + DiMustAnyLock(dentry);
9502 + return au_di(dentry)->di_bbot;
9505 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9507 + DiMustAnyLock(dentry);
9508 + return au_di(dentry)->di_bwh;
9511 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9513 + DiMustAnyLock(dentry);
9514 + return au_di(dentry)->di_bdiropq;
9517 +/* todo: hard/soft set? */
9518 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9520 + DiMustWriteLock(dentry);
9521 + au_di(dentry)->di_btop = bindex;
9524 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9526 + DiMustWriteLock(dentry);
9527 + au_di(dentry)->di_bbot = bindex;
9530 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9532 + DiMustWriteLock(dentry);
9533 + /* dbwh can be outside of btop - bbot range */
9534 + au_di(dentry)->di_bwh = bindex;
9537 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9539 + DiMustWriteLock(dentry);
9540 + au_di(dentry)->di_bdiropq = bindex;
9543 +/* ---------------------------------------------------------------------- */
9545 +#ifdef CONFIG_AUFS_HNOTIFY
9546 +static inline void au_digen_dec(struct dentry *d)
9548 + atomic_dec(&au_di(d)->di_generation);
9551 +static inline void au_hn_di_reinit(struct dentry *dentry)
9553 + dentry->d_fsdata = NULL;
9556 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9557 +#endif /* CONFIG_AUFS_HNOTIFY */
9559 +#endif /* __KERNEL__ */
9560 +#endif /* __AUFS_DENTRY_H__ */
9561 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9562 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9563 +++ linux/fs/aufs/dinfo.c 2018-08-12 23:43:05.453457863 +0200
9565 +// SPDX-License-Identifier: GPL-2.0
9567 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9569 + * This program, aufs is free software; you can redistribute it and/or modify
9570 + * it under the terms of the GNU General Public License as published by
9571 + * the Free Software Foundation; either version 2 of the License, or
9572 + * (at your option) any later version.
9574 + * This program is distributed in the hope that it will be useful,
9575 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9576 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9577 + * GNU General Public License for more details.
9579 + * You should have received a copy of the GNU General Public License
9580 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9584 + * dentry private data
9589 +void au_di_init_once(void *_dinfo)
9591 + struct au_dinfo *dinfo = _dinfo;
9593 + au_rw_init(&dinfo->di_rwsem);
9596 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9598 + struct au_dinfo *dinfo;
9601 + dinfo = au_cache_alloc_dinfo();
9602 + if (unlikely(!dinfo))
9605 + nbr = au_sbbot(sb) + 1;
9608 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9609 + if (dinfo->di_hdentry) {
9610 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9611 + dinfo->di_btop = -1;
9612 + dinfo->di_bbot = -1;
9613 + dinfo->di_bwh = -1;
9614 + dinfo->di_bdiropq = -1;
9615 + dinfo->di_tmpfile = 0;
9616 + for (i = 0; i < nbr; i++)
9617 + dinfo->di_hdentry[i].hd_id = -1;
9621 + au_cache_free_dinfo(dinfo);
9628 +void au_di_free(struct au_dinfo *dinfo)
9630 + struct au_hdentry *p;
9631 + aufs_bindex_t bbot, bindex;
9633 + /* dentry may not be revalidated */
9634 + bindex = dinfo->di_btop;
9635 + if (bindex >= 0) {
9636 + bbot = dinfo->di_bbot;
9637 + p = au_hdentry(dinfo, bindex);
9638 + while (bindex++ <= bbot)
9641 + kfree(dinfo->di_hdentry);
9642 + au_cache_free_dinfo(dinfo);
9645 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9647 + struct au_hdentry *p;
9650 + AuRwMustWriteLock(&a->di_rwsem);
9651 + AuRwMustWriteLock(&b->di_rwsem);
9653 +#define DiSwap(v, name) \
9655 + v = a->di_##name; \
9656 + a->di_##name = b->di_##name; \
9657 + b->di_##name = v; \
9660 + DiSwap(p, hdentry);
9664 + DiSwap(bi, bdiropq);
9670 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9672 + AuRwMustWriteLock(&dst->di_rwsem);
9673 + AuRwMustWriteLock(&src->di_rwsem);
9675 + dst->di_btop = src->di_btop;
9676 + dst->di_bbot = src->di_bbot;
9677 + dst->di_bwh = src->di_bwh;
9678 + dst->di_bdiropq = src->di_bdiropq;
9682 +int au_di_init(struct dentry *dentry)
9685 + struct super_block *sb;
9686 + struct au_dinfo *dinfo;
9689 + sb = dentry->d_sb;
9690 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9692 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9693 + /* smp_mb(); */ /* atomic_set */
9694 + dentry->d_fsdata = dinfo;
9701 +void au_di_fin(struct dentry *dentry)
9703 + struct au_dinfo *dinfo;
9705 + dinfo = au_di(dentry);
9706 + AuRwDestroy(&dinfo->di_rwsem);
9707 + au_di_free(dinfo);
9710 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9713 + struct au_hdentry *hdp;
9715 + AuRwMustWriteLock(&dinfo->di_rwsem);
9718 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9720 + sz = sizeof(*hdp);
9721 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9724 + dinfo->di_hdentry = hdp;
9731 +/* ---------------------------------------------------------------------- */
9733 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9736 + case AuLsc_DI_CHILD:
9737 + ii_write_lock_child(inode);
9739 + case AuLsc_DI_CHILD2:
9740 + ii_write_lock_child2(inode);
9742 + case AuLsc_DI_CHILD3:
9743 + ii_write_lock_child3(inode);
9745 + case AuLsc_DI_PARENT:
9746 + ii_write_lock_parent(inode);
9748 + case AuLsc_DI_PARENT2:
9749 + ii_write_lock_parent2(inode);
9751 + case AuLsc_DI_PARENT3:
9752 + ii_write_lock_parent3(inode);
9759 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9762 + case AuLsc_DI_CHILD:
9763 + ii_read_lock_child(inode);
9765 + case AuLsc_DI_CHILD2:
9766 + ii_read_lock_child2(inode);
9768 + case AuLsc_DI_CHILD3:
9769 + ii_read_lock_child3(inode);
9771 + case AuLsc_DI_PARENT:
9772 + ii_read_lock_parent(inode);
9774 + case AuLsc_DI_PARENT2:
9775 + ii_read_lock_parent2(inode);
9777 + case AuLsc_DI_PARENT3:
9778 + ii_read_lock_parent3(inode);
9785 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9787 + struct inode *inode;
9789 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9790 + if (d_really_is_positive(d)) {
9791 + inode = d_inode(d);
9792 + if (au_ftest_lock(flags, IW))
9793 + do_ii_write_lock(inode, lsc);
9794 + else if (au_ftest_lock(flags, IR))
9795 + do_ii_read_lock(inode, lsc);
9799 +void di_read_unlock(struct dentry *d, int flags)
9801 + struct inode *inode;
9803 + if (d_really_is_positive(d)) {
9804 + inode = d_inode(d);
9805 + if (au_ftest_lock(flags, IW)) {
9806 + au_dbg_verify_dinode(d);
9807 + ii_write_unlock(inode);
9808 + } else if (au_ftest_lock(flags, IR)) {
9809 + au_dbg_verify_dinode(d);
9810 + ii_read_unlock(inode);
9813 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9816 +void di_downgrade_lock(struct dentry *d, int flags)
9818 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9819 + ii_downgrade_lock(d_inode(d));
9820 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9823 +void di_write_lock(struct dentry *d, unsigned int lsc)
9825 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9826 + if (d_really_is_positive(d))
9827 + do_ii_write_lock(d_inode(d), lsc);
9830 +void di_write_unlock(struct dentry *d)
9832 + au_dbg_verify_dinode(d);
9833 + if (d_really_is_positive(d))
9834 + ii_write_unlock(d_inode(d));
9835 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9838 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9840 + AuDebugOn(d1 == d2
9841 + || d_inode(d1) == d_inode(d2)
9842 + || d1->d_sb != d2->d_sb);
9844 + if ((isdir && au_test_subdir(d1, d2))
9846 + di_write_lock_child(d1);
9847 + di_write_lock_child2(d2);
9849 + di_write_lock_child(d2);
9850 + di_write_lock_child2(d1);
9854 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9856 + AuDebugOn(d1 == d2
9857 + || d_inode(d1) == d_inode(d2)
9858 + || d1->d_sb != d2->d_sb);
9860 + if ((isdir && au_test_subdir(d1, d2))
9862 + di_write_lock_parent(d1);
9863 + di_write_lock_parent2(d2);
9865 + di_write_lock_parent(d2);
9866 + di_write_lock_parent2(d1);
9870 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9872 + di_write_unlock(d1);
9873 + if (d_inode(d1) == d_inode(d2))
9874 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9876 + di_write_unlock(d2);
9879 +/* ---------------------------------------------------------------------- */
9881 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9885 + DiMustAnyLock(dentry);
9887 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9889 + AuDebugOn(bindex < 0);
9890 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9891 + AuDebugOn(d && au_dcount(d) <= 0);
9896 + * extended version of au_h_dptr().
9897 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9900 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9902 + struct dentry *h_dentry;
9903 + struct inode *inode, *h_inode;
9905 + AuDebugOn(d_really_is_negative(dentry));
9908 + if (au_dbtop(dentry) <= bindex
9909 + && bindex <= au_dbbot(dentry))
9910 + h_dentry = au_h_dptr(dentry, bindex);
9911 + if (h_dentry && !au_d_linkable(h_dentry)) {
9913 + goto out; /* success */
9916 + inode = d_inode(dentry);
9917 + AuDebugOn(bindex < au_ibtop(inode));
9918 + AuDebugOn(au_ibbot(inode) < bindex);
9919 + h_inode = au_h_iptr(inode, bindex);
9920 + h_dentry = d_find_alias(h_inode);
9922 + if (!IS_ERR(h_dentry)) {
9923 + if (!au_d_linkable(h_dentry))
9924 + goto out; /* success */
9930 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9931 + h_dentry = au_plink_lkup(inode, bindex);
9932 + AuDebugOn(!h_dentry);
9933 + if (!IS_ERR(h_dentry)) {
9934 + if (!au_d_hashed_positive(h_dentry))
9935 + goto out; /* success */
9942 + AuDbgDentry(h_dentry);
9946 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9948 + aufs_bindex_t bbot, bwh;
9950 + bbot = au_dbbot(dentry);
9952 + bwh = au_dbwh(dentry);
9955 + if (0 < bwh && bwh < bbot)
9961 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9963 + aufs_bindex_t bbot, bopq;
9965 + bbot = au_dbtail(dentry);
9967 + bopq = au_dbdiropq(dentry);
9968 + if (0 <= bopq && bopq < bbot)
9974 +/* ---------------------------------------------------------------------- */
9976 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9977 + struct dentry *h_dentry)
9979 + struct au_dinfo *dinfo;
9980 + struct au_hdentry *hd;
9981 + struct au_branch *br;
9983 + DiMustWriteLock(dentry);
9985 + dinfo = au_di(dentry);
9986 + hd = au_hdentry(dinfo, bindex);
9988 + hd->hd_dentry = h_dentry;
9990 + br = au_sbr(dentry->d_sb, bindex);
9991 + hd->hd_id = br->br_id;
9995 +int au_dbrange_test(struct dentry *dentry)
9998 + aufs_bindex_t btop, bbot;
10001 + btop = au_dbtop(dentry);
10002 + bbot = au_dbbot(dentry);
10004 + AuDebugOn(bbot < 0 && btop > bbot);
10007 + AuDebugOn(bbot >= 0);
10013 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10018 + if (unlikely(au_digen(dentry) != sigen
10019 + || au_iigen_test(d_inode(dentry), sigen)))
10025 +void au_update_digen(struct dentry *dentry)
10027 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10028 + /* smp_mb(); */ /* atomic_set */
10031 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10033 + struct au_dinfo *dinfo;
10034 + struct dentry *h_d;
10035 + struct au_hdentry *hdp;
10036 + aufs_bindex_t bindex, bbot;
10038 + DiMustWriteLock(dentry);
10040 + dinfo = au_di(dentry);
10041 + if (!dinfo || dinfo->di_btop < 0)
10044 + if (do_put_zero) {
10045 + bbot = dinfo->di_bbot;
10046 + bindex = dinfo->di_btop;
10047 + hdp = au_hdentry(dinfo, bindex);
10048 + for (; bindex <= bbot; bindex++, hdp++) {
10049 + h_d = hdp->hd_dentry;
10050 + if (h_d && d_is_negative(h_d))
10051 + au_set_h_dptr(dentry, bindex, NULL);
10055 + dinfo->di_btop = 0;
10056 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10057 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10058 + if (hdp->hd_dentry)
10060 + if (dinfo->di_btop > dinfo->di_bbot) {
10061 + dinfo->di_btop = -1;
10062 + dinfo->di_bbot = -1;
10066 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10067 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10068 + if (hdp->hd_dentry)
10070 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10073 +void au_update_dbtop(struct dentry *dentry)
10075 + aufs_bindex_t bindex, bbot;
10076 + struct dentry *h_dentry;
10078 + bbot = au_dbbot(dentry);
10079 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10080 + h_dentry = au_h_dptr(dentry, bindex);
10083 + if (d_is_positive(h_dentry)) {
10084 + au_set_dbtop(dentry, bindex);
10087 + au_set_h_dptr(dentry, bindex, NULL);
10091 +void au_update_dbbot(struct dentry *dentry)
10093 + aufs_bindex_t bindex, btop;
10094 + struct dentry *h_dentry;
10096 + btop = au_dbtop(dentry);
10097 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10098 + h_dentry = au_h_dptr(dentry, bindex);
10101 + if (d_is_positive(h_dentry)) {
10102 + au_set_dbbot(dentry, bindex);
10105 + au_set_h_dptr(dentry, bindex, NULL);
10109 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10111 + aufs_bindex_t bindex, bbot;
10113 + bbot = au_dbbot(dentry);
10114 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10115 + if (au_h_dptr(dentry, bindex) == h_dentry)
10119 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10120 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10121 +++ linux/fs/aufs/dir.c 2018-10-23 12:33:35.596042364 +0200
10123 +// SPDX-License-Identifier: GPL-2.0
10125 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10127 + * This program, aufs is free software; you can redistribute it and/or modify
10128 + * it under the terms of the GNU General Public License as published by
10129 + * the Free Software Foundation; either version 2 of the License, or
10130 + * (at your option) any later version.
10132 + * This program is distributed in the hope that it will be useful,
10133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10135 + * GNU General Public License for more details.
10137 + * You should have received a copy of the GNU General Public License
10138 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10142 + * directory operations
10145 +#include <linux/fs_stack.h>
10148 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10150 + unsigned int nlink;
10152 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10154 + nlink = dir->i_nlink;
10155 + nlink += h_dir->i_nlink - 2;
10156 + if (h_dir->i_nlink < 2)
10158 + smp_mb(); /* for i_nlink */
10159 + /* 0 can happen in revaliding */
10160 + set_nlink(dir, nlink);
10163 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10165 + unsigned int nlink;
10167 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10169 + nlink = dir->i_nlink;
10170 + nlink -= h_dir->i_nlink - 2;
10171 + if (h_dir->i_nlink < 2)
10173 + smp_mb(); /* for i_nlink */
10174 + /* nlink == 0 means the branch-fs is broken */
10175 + set_nlink(dir, nlink);
10178 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10181 + aufs_bindex_t bindex, bbot;
10182 + struct file *h_file;
10183 + struct dentry *h_dentry;
10187 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10189 + bbot = au_fbbot_dir(file);
10190 + for (bindex = au_fbtop(file);
10191 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10193 + h_file = au_hf_dir(file, bindex);
10194 + if (h_file && file_inode(h_file))
10195 + sz += vfsub_f_size_read(h_file);
10198 + AuDebugOn(!dentry);
10199 + AuDebugOn(!d_is_dir(dentry));
10201 + bbot = au_dbtaildir(dentry);
10202 + for (bindex = au_dbtop(dentry);
10203 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10205 + h_dentry = au_h_dptr(dentry, bindex);
10206 + if (h_dentry && d_is_positive(h_dentry))
10207 + sz += i_size_read(d_inode(h_dentry));
10210 + if (sz < KMALLOC_MAX_SIZE)
10211 + sz = roundup_pow_of_two(sz);
10212 + if (sz > KMALLOC_MAX_SIZE)
10213 + sz = KMALLOC_MAX_SIZE;
10214 + else if (sz < NAME_MAX) {
10215 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10216 + sz = AUFS_RDBLK_DEF;
10221 +struct au_dir_ts_arg {
10222 + struct dentry *dentry;
10223 + aufs_bindex_t brid;
10226 +static void au_do_dir_ts(void *arg)
10228 + struct au_dir_ts_arg *a = arg;
10229 + struct au_dtime dt;
10230 + struct path h_path;
10231 + struct inode *dir, *h_dir;
10232 + struct super_block *sb;
10233 + struct au_branch *br;
10234 + struct au_hinode *hdir;
10236 + aufs_bindex_t btop, bindex;
10238 + sb = a->dentry->d_sb;
10239 + if (d_really_is_negative(a->dentry))
10241 + /* no dir->i_mutex lock */
10242 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10244 + dir = d_inode(a->dentry);
10245 + btop = au_ibtop(dir);
10246 + bindex = au_br_index(sb, a->brid);
10247 + if (bindex < btop)
10250 + br = au_sbr(sb, bindex);
10251 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10252 + if (!h_path.dentry)
10254 + h_path.mnt = au_br_mnt(br);
10255 + au_dtime_store(&dt, a->dentry, &h_path);
10257 + br = au_sbr(sb, btop);
10258 + if (!au_br_writable(br->br_perm))
10260 + h_path.dentry = au_h_dptr(a->dentry, btop);
10261 + h_path.mnt = au_br_mnt(br);
10262 + err = vfsub_mnt_want_write(h_path.mnt);
10265 + hdir = au_hi(dir, btop);
10266 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10267 + h_dir = au_h_iptr(dir, btop);
10268 + if (h_dir->i_nlink
10269 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10270 + dt.dt_h_path = h_path;
10271 + au_dtime_revert(&dt);
10273 + au_hn_inode_unlock(hdir);
10274 + vfsub_mnt_drop_write(h_path.mnt);
10275 + au_cpup_attr_timesizes(dir);
10278 + aufs_read_unlock(a->dentry, AuLock_DW);
10281 + au_nwt_done(&au_sbi(sb)->si_nowait);
10285 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10287 + int perm, wkq_err;
10288 + aufs_bindex_t btop;
10289 + struct au_dir_ts_arg *arg;
10290 + struct dentry *dentry;
10291 + struct super_block *sb;
10295 + dentry = d_find_any_alias(dir);
10296 + AuDebugOn(!dentry);
10297 + sb = dentry->d_sb;
10298 + btop = au_ibtop(dir);
10299 + if (btop == bindex) {
10300 + au_cpup_attr_timesizes(dir);
10304 + perm = au_sbr_perm(sb, btop);
10305 + if (!au_br_writable(perm))
10308 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10312 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10313 + arg->brid = au_sbr_id(sb, bindex);
10314 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10315 + if (unlikely(wkq_err)) {
10316 + pr_err("wkq %d\n", wkq_err);
10325 +/* ---------------------------------------------------------------------- */
10327 +static int reopen_dir(struct file *file)
10330 + unsigned int flags;
10331 + aufs_bindex_t bindex, btail, btop;
10332 + struct dentry *dentry, *h_dentry;
10333 + struct file *h_file;
10335 + /* open all lower dirs */
10336 + dentry = file->f_path.dentry;
10337 + btop = au_dbtop(dentry);
10338 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10339 + au_set_h_fptr(file, bindex, NULL);
10340 + au_set_fbtop(file, btop);
10342 + btail = au_dbtaildir(dentry);
10343 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10344 + au_set_h_fptr(file, bindex, NULL);
10345 + au_set_fbbot_dir(file, btail);
10347 + flags = vfsub_file_flags(file);
10348 + for (bindex = btop; bindex <= btail; bindex++) {
10349 + h_dentry = au_h_dptr(dentry, bindex);
10352 + h_file = au_hf_dir(file, bindex);
10356 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10357 + err = PTR_ERR(h_file);
10358 + if (IS_ERR(h_file))
10359 + goto out; /* close all? */
10360 + au_set_h_fptr(file, bindex, h_file);
10362 + au_update_figen(file);
10363 + /* todo: necessary? */
10364 + /* file->f_ra = h_file->f_ra; */
10371 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10374 + aufs_bindex_t bindex, btail;
10375 + struct dentry *dentry, *h_dentry;
10376 + struct vfsmount *mnt;
10378 + FiMustWriteLock(file);
10379 + AuDebugOn(h_file);
10382 + mnt = file->f_path.mnt;
10383 + dentry = file->f_path.dentry;
10384 + file->f_version = inode_query_iversion(d_inode(dentry));
10385 + bindex = au_dbtop(dentry);
10386 + au_set_fbtop(file, bindex);
10387 + btail = au_dbtaildir(dentry);
10388 + au_set_fbbot_dir(file, btail);
10389 + for (; !err && bindex <= btail; bindex++) {
10390 + h_dentry = au_h_dptr(dentry, bindex);
10394 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10395 + if (unlikely(err))
10397 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10398 + if (IS_ERR(h_file)) {
10399 + err = PTR_ERR(h_file);
10402 + au_set_h_fptr(file, bindex, h_file);
10404 + au_update_figen(file);
10405 + /* todo: necessary? */
10406 + /* file->f_ra = h_file->f_ra; */
10408 + return 0; /* success */
10411 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10412 + au_set_h_fptr(file, bindex, NULL);
10413 + au_set_fbtop(file, -1);
10414 + au_set_fbbot_dir(file, -1);
10419 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10420 + struct file *file)
10423 + struct super_block *sb;
10424 + struct au_fidir *fidir;
10427 + sb = file->f_path.dentry->d_sb;
10428 + si_read_lock(sb, AuLock_FLUSH);
10429 + fidir = au_fidir_alloc(sb);
10431 + struct au_do_open_args args = {
10432 + .open = do_open_dir,
10435 + err = au_do_open(file, &args);
10436 + if (unlikely(err))
10439 + si_read_unlock(sb);
10443 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10444 + struct file *file)
10446 + struct au_vdir *vdir_cache;
10447 + struct au_finfo *finfo;
10448 + struct au_fidir *fidir;
10449 + struct au_hfile *hf;
10450 + aufs_bindex_t bindex, bbot;
10452 + finfo = au_fi(file);
10453 + fidir = finfo->fi_hdir;
10455 + au_hbl_del(&finfo->fi_hlist,
10456 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10457 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10459 + au_vdir_free(vdir_cache);
10461 + bindex = finfo->fi_btop;
10462 + if (bindex >= 0) {
10463 + hf = fidir->fd_hfile + bindex;
10465 + * calls fput() instead of filp_close(),
10466 + * since no dnotify or lock for the lower file.
10468 + bbot = fidir->fd_bbot;
10469 + for (; bindex <= bbot; bindex++, hf++)
10471 + au_hfput(hf, /*execed*/0);
10474 + finfo->fi_hdir = NULL;
10476 + au_finfo_fin(file);
10480 +/* ---------------------------------------------------------------------- */
10482 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10485 + aufs_bindex_t bindex, bbot;
10486 + struct file *h_file;
10489 + bbot = au_fbbot_dir(file);
10490 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10491 + h_file = au_hf_dir(file, bindex);
10493 + err = vfsub_flush(h_file, id);
10498 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10500 + return au_do_flush(file, id, au_do_flush_dir);
10503 +/* ---------------------------------------------------------------------- */
10505 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10508 + aufs_bindex_t bbot, bindex;
10509 + struct inode *inode;
10510 + struct super_block *sb;
10513 + sb = dentry->d_sb;
10514 + inode = d_inode(dentry);
10515 + IMustLock(inode);
10516 + bbot = au_dbbot(dentry);
10517 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10518 + struct path h_path;
10520 + if (au_test_ro(sb, bindex, inode))
10522 + h_path.dentry = au_h_dptr(dentry, bindex);
10523 + if (!h_path.dentry)
10526 + h_path.mnt = au_sbr_mnt(sb, bindex);
10527 + err = vfsub_fsync(NULL, &h_path, datasync);
10533 +static int au_do_fsync_dir(struct file *file, int datasync)
10536 + aufs_bindex_t bbot, bindex;
10537 + struct file *h_file;
10538 + struct super_block *sb;
10539 + struct inode *inode;
10541 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10542 + if (unlikely(err))
10545 + inode = file_inode(file);
10546 + sb = inode->i_sb;
10547 + bbot = au_fbbot_dir(file);
10548 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10549 + h_file = au_hf_dir(file, bindex);
10550 + if (!h_file || au_test_ro(sb, bindex, inode))
10553 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10561 + * @file may be NULL
10563 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10567 + struct dentry *dentry;
10568 + struct inode *inode;
10569 + struct super_block *sb;
10572 + dentry = file->f_path.dentry;
10573 + inode = d_inode(dentry);
10574 + inode_lock(inode);
10575 + sb = dentry->d_sb;
10576 + si_noflush_read_lock(sb);
10578 + err = au_do_fsync_dir(file, datasync);
10580 + di_write_lock_child(dentry);
10581 + err = au_do_fsync_dir_no_file(dentry, datasync);
10583 + au_cpup_attr_timesizes(inode);
10584 + di_write_unlock(dentry);
10586 + fi_write_unlock(file);
10588 + si_read_unlock(sb);
10589 + inode_unlock(inode);
10593 +/* ---------------------------------------------------------------------- */
10595 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10598 + struct dentry *dentry;
10599 + struct inode *inode, *h_inode;
10600 + struct super_block *sb;
10602 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10604 + dentry = file->f_path.dentry;
10605 + inode = d_inode(dentry);
10606 + IMustLock(inode);
10608 + sb = dentry->d_sb;
10609 + si_read_lock(sb, AuLock_FLUSH);
10610 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10611 + if (unlikely(err))
10613 + err = au_alive_dir(dentry);
10615 + err = au_vdir_init(file);
10616 + di_downgrade_lock(dentry, AuLock_IR);
10617 + if (unlikely(err))
10620 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10621 + if (!au_test_nfsd()) {
10622 + err = au_vdir_fill_de(file, ctx);
10623 + fsstack_copy_attr_atime(inode, h_inode);
10626 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10627 + * encode_fh() and others.
10629 + atomic_inc(&h_inode->i_count);
10630 + di_read_unlock(dentry, AuLock_IR);
10631 + si_read_unlock(sb);
10632 + err = au_vdir_fill_de(file, ctx);
10633 + fsstack_copy_attr_atime(inode, h_inode);
10634 + fi_write_unlock(file);
10642 + di_read_unlock(dentry, AuLock_IR);
10643 + fi_write_unlock(file);
10645 + si_read_unlock(sb);
10649 +/* ---------------------------------------------------------------------- */
10651 +#define AuTestEmpty_WHONLY 1
10652 +#define AuTestEmpty_CALLED (1 << 1)
10653 +#define AuTestEmpty_SHWH (1 << 2)
10654 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10655 +#define au_fset_testempty(flags, name) \
10656 + do { (flags) |= AuTestEmpty_##name; } while (0)
10657 +#define au_fclr_testempty(flags, name) \
10658 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10660 +#ifndef CONFIG_AUFS_SHWH
10661 +#undef AuTestEmpty_SHWH
10662 +#define AuTestEmpty_SHWH 0
10665 +struct test_empty_arg {
10666 + struct dir_context ctx;
10667 + struct au_nhash *whlist;
10668 + unsigned int flags;
10670 + aufs_bindex_t bindex;
10673 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10674 + int namelen, loff_t offset __maybe_unused, u64 ino,
10675 + unsigned int d_type)
10677 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10679 + char *name = (void *)__name;
10682 + au_fset_testempty(arg->flags, CALLED);
10684 + if (name[0] == '.'
10685 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10686 + goto out; /* success */
10688 + if (namelen <= AUFS_WH_PFX_LEN
10689 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10690 + if (au_ftest_testempty(arg->flags, WHONLY)
10691 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10692 + arg->err = -ENOTEMPTY;
10696 + name += AUFS_WH_PFX_LEN;
10697 + namelen -= AUFS_WH_PFX_LEN;
10698 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10699 + arg->err = au_nhash_append_wh
10700 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10701 + au_ftest_testempty(arg->flags, SHWH));
10705 + AuTraceErr(arg->err);
10709 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10712 + struct file *h_file;
10713 + struct au_branch *br;
10715 + h_file = au_h_open(dentry, arg->bindex,
10716 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10717 + /*file*/NULL, /*force_wr*/0);
10718 + err = PTR_ERR(h_file);
10719 + if (IS_ERR(h_file))
10723 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10724 + && !file_inode(h_file)->i_nlink)
10729 + au_fclr_testempty(arg->flags, CALLED);
10731 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10734 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10738 + br = au_sbr(dentry->d_sb, arg->bindex);
10739 + au_lcnt_dec(&br->br_nfiles);
10744 +struct do_test_empty_args {
10746 + struct dentry *dentry;
10747 + struct test_empty_arg *arg;
10750 +static void call_do_test_empty(void *args)
10752 + struct do_test_empty_args *a = args;
10753 + *a->errp = do_test_empty(a->dentry, a->arg);
10756 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10758 + int err, wkq_err;
10759 + struct dentry *h_dentry;
10760 + struct inode *h_inode;
10762 + h_dentry = au_h_dptr(dentry, arg->bindex);
10763 + h_inode = d_inode(h_dentry);
10764 + /* todo: i_mode changes anytime? */
10765 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10766 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10767 + inode_unlock_shared(h_inode);
10769 + err = do_test_empty(dentry, arg);
10771 + struct do_test_empty_args args = {
10773 + .dentry = dentry,
10776 + unsigned int flags = arg->flags;
10778 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10779 + if (unlikely(wkq_err))
10781 + arg->flags = flags;
10787 +int au_test_empty_lower(struct dentry *dentry)
10790 + unsigned int rdhash;
10791 + aufs_bindex_t bindex, btop, btail;
10792 + struct au_nhash whlist;
10793 + struct test_empty_arg arg = {
10795 + .actor = test_empty_cb
10798 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10800 + SiMustAnyLock(dentry->d_sb);
10802 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10804 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10805 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10806 + if (unlikely(err))
10810 + arg.whlist = &whlist;
10811 + btop = au_dbtop(dentry);
10812 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10813 + au_fset_testempty(arg.flags, SHWH);
10814 + test_empty = do_test_empty;
10815 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10816 + test_empty = sio_test_empty;
10817 + arg.bindex = btop;
10818 + err = test_empty(dentry, &arg);
10819 + if (unlikely(err))
10822 + au_fset_testempty(arg.flags, WHONLY);
10823 + btail = au_dbtaildir(dentry);
10824 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10825 + struct dentry *h_dentry;
10827 + h_dentry = au_h_dptr(dentry, bindex);
10828 + if (h_dentry && d_is_positive(h_dentry)) {
10829 + arg.bindex = bindex;
10830 + err = test_empty(dentry, &arg);
10835 + au_nhash_wh_free(&whlist);
10840 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10843 + struct test_empty_arg arg = {
10845 + .actor = test_empty_cb
10848 + aufs_bindex_t bindex, btail;
10851 + arg.whlist = whlist;
10852 + arg.flags = AuTestEmpty_WHONLY;
10853 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10854 + au_fset_testempty(arg.flags, SHWH);
10855 + btail = au_dbtaildir(dentry);
10856 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10857 + struct dentry *h_dentry;
10859 + h_dentry = au_h_dptr(dentry, bindex);
10860 + if (h_dentry && d_is_positive(h_dentry)) {
10861 + arg.bindex = bindex;
10862 + err = sio_test_empty(dentry, &arg);
10869 +/* ---------------------------------------------------------------------- */
10871 +const struct file_operations aufs_dir_fop = {
10872 + .owner = THIS_MODULE,
10873 + .llseek = default_llseek,
10874 + .read = generic_read_dir,
10875 + .iterate_shared = aufs_iterate_shared,
10876 + .unlocked_ioctl = aufs_ioctl_dir,
10877 +#ifdef CONFIG_COMPAT
10878 + .compat_ioctl = aufs_compat_ioctl_dir,
10880 + .open = aufs_open_dir,
10881 + .release = aufs_release_dir,
10882 + .flush = aufs_flush_dir,
10883 + .fsync = aufs_fsync_dir
10885 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10886 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10887 +++ linux/fs/aufs/dir.h 2018-08-12 23:43:05.453457863 +0200
10889 +/* SPDX-License-Identifier: GPL-2.0 */
10891 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10893 + * This program, aufs is free software; you can redistribute it and/or modify
10894 + * it under the terms of the GNU General Public License as published by
10895 + * the Free Software Foundation; either version 2 of the License, or
10896 + * (at your option) any later version.
10898 + * This program is distributed in the hope that it will be useful,
10899 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10900 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10901 + * GNU General Public License for more details.
10903 + * You should have received a copy of the GNU General Public License
10904 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10908 + * directory operations
10911 +#ifndef __AUFS_DIR_H__
10912 +#define __AUFS_DIR_H__
10916 +#include <linux/fs.h>
10918 +/* ---------------------------------------------------------------------- */
10920 +/* need to be faster and smaller */
10923 + unsigned int nh_num;
10924 + struct hlist_head *nh_head;
10927 +struct au_vdir_destr {
10928 + unsigned char len;
10929 + unsigned char name[0];
10932 +struct au_vdir_dehstr {
10933 + struct hlist_node hash;
10934 + struct au_vdir_destr *str;
10935 +} ____cacheline_aligned_in_smp;
10937 +struct au_vdir_de {
10939 + unsigned char de_type;
10940 + /* caution: packed */
10941 + struct au_vdir_destr de_str;
10944 +struct au_vdir_wh {
10945 + struct hlist_node wh_hash;
10946 +#ifdef CONFIG_AUFS_SHWH
10948 + aufs_bindex_t wh_bindex;
10949 + unsigned char wh_type;
10951 + aufs_bindex_t wh_bindex;
10953 + /* caution: packed */
10954 + struct au_vdir_destr wh_str;
10957 +union au_vdir_deblk_p {
10958 + unsigned char *deblk;
10959 + struct au_vdir_de *de;
10963 + unsigned char **vd_deblk;
10964 + unsigned long vd_nblk;
10966 + unsigned long ul;
10967 + union au_vdir_deblk_p p;
10971 + unsigned int vd_deblk_sz;
10972 + unsigned long vd_jiffy;
10973 +} ____cacheline_aligned_in_smp;
10975 +/* ---------------------------------------------------------------------- */
10978 +extern const struct file_operations aufs_dir_fop;
10979 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10980 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10981 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10982 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10983 +int au_test_empty_lower(struct dentry *dentry);
10984 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10987 +unsigned int au_rdhash_est(loff_t sz);
10988 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10989 +void au_nhash_wh_free(struct au_nhash *whlist);
10990 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10992 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10993 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10994 + unsigned int d_type, aufs_bindex_t bindex,
10995 + unsigned char shwh);
10996 +void au_vdir_free(struct au_vdir *vdir);
10997 +int au_vdir_init(struct file *file);
10998 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
11001 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
11003 +#ifdef CONFIG_AUFS_RDU
11005 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
11006 +#ifdef CONFIG_COMPAT
11007 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
11008 + unsigned long arg);
11011 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11012 + unsigned int cmd, unsigned long arg)
11013 +#ifdef CONFIG_COMPAT
11014 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11015 + unsigned int cmd, unsigned long arg)
11019 +#endif /* __KERNEL__ */
11020 +#endif /* __AUFS_DIR_H__ */
11021 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11022 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11023 +++ linux/fs/aufs/dirren.c 2018-10-23 12:33:35.596042364 +0200
11025 +// SPDX-License-Identifier: GPL-2.0
11027 + * Copyright (C) 2017-2018 Junjiro R. Okajima
11029 + * This program, aufs is free software; you can redistribute it and/or modify
11030 + * it under the terms of the GNU General Public License as published by
11031 + * the Free Software Foundation; either version 2 of the License, or
11032 + * (at your option) any later version.
11034 + * This program is distributed in the hope that it will be useful,
11035 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11036 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11037 + * GNU General Public License for more details.
11039 + * You should have received a copy of the GNU General Public License
11040 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11044 + * special handling in renaming a directory
11045 + * in order to support looking-up the before-renamed name on the lower readonly
11049 +#include <linux/byteorder/generic.h>
11052 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11056 + idx = au_dr_ihash(ent->dr_h_ino);
11057 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11060 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11063 + struct hlist_bl_head *hbl;
11066 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11067 + hbl = dr->dr_h_ino + i;
11068 + hlist_bl_lock(hbl);
11069 + ret &= hlist_bl_empty(hbl);
11070 + hlist_bl_unlock(hbl);
11076 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11078 + struct au_dr_hino *found, *ent;
11079 + struct hlist_bl_head *hbl;
11080 + struct hlist_bl_node *pos;
11084 + idx = au_dr_ihash(ino);
11085 + hbl = dr->dr_h_ino + idx;
11086 + hlist_bl_lock(hbl);
11087 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11088 + if (ent->dr_h_ino == ino) {
11092 + hlist_bl_unlock(hbl);
11097 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11098 + struct au_dr_hino *add_ent)
11101 + struct hlist_bl_head *hbl;
11102 + struct hlist_bl_node *pos;
11103 + struct au_dr_hino *ent;
11106 + idx = au_dr_ihash(ino);
11107 + hbl = dr->dr_h_ino + idx;
11110 + struct hlist_bl_node *tmp;
11112 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11113 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11116 + hlist_bl_lock(hbl);
11117 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11118 + if (ent->dr_h_ino == ino) {
11122 + if (!found && add_ent)
11123 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11124 + hlist_bl_unlock(hbl);
11126 + if (!found && add_ent)
11127 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11132 +void au_dr_hino_free(struct au_dr_br *dr)
11135 + struct hlist_bl_head *hbl;
11136 + struct hlist_bl_node *pos, *tmp;
11137 + struct au_dr_hino *ent;
11139 + /* SiMustWriteLock(sb); */
11141 + for (i = 0; i < AuDirren_NHASH; i++) {
11142 + hbl = dr->dr_h_ino + i;
11143 + /* no spinlock since sbinfo must be write-locked */
11144 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11146 + INIT_HLIST_BL_HEAD(hbl);
11150 +/* returns the number of inodes or an error */
11151 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11152 + struct file *hinofile)
11156 + loff_t pos, oldsize;
11158 + struct inode *hinoinode;
11159 + struct hlist_bl_head *hbl;
11160 + struct hlist_bl_node *n1, *n2;
11161 + struct au_dr_hino *ent;
11163 + SiMustWriteLock(sb);
11164 + AuDebugOn(!au_br_writable(br->br_perm));
11166 + hinoinode = file_inode(hinofile);
11167 + oldsize = i_size_read(hinoinode);
11171 + hbl = br->br_dirren.dr_h_ino;
11172 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11173 + /* no bit-lock since sbinfo must be write-locked */
11174 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11175 + AuDbg("hi%llu, %pD2\n",
11176 + (unsigned long long)ent->dr_h_ino, hinofile);
11177 + u64 = cpu_to_be64(ent->dr_h_ino);
11178 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11179 + if (ssz == sizeof(u64))
11182 + /* write error */
11183 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11190 + /* regardless the error */
11191 + if (pos < oldsize) {
11192 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11200 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11207 + struct au_dr_hino *ent;
11208 + struct inode *hinoinode;
11209 + struct hlist_bl_head *hbl;
11213 + hbl = dr->dr_h_ino;
11214 + hinoinode = file_inode(hinofile);
11215 + sz = i_size_read(hinoinode);
11216 + AuDebugOn(sz % sizeof(u64));
11217 + n = sz / sizeof(u64);
11219 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11220 + if (unlikely(ssz != sizeof(u64))) {
11221 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11228 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11234 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11235 + AuDbg("hi%llu, %pD2\n",
11236 + (unsigned long long)ent->dr_h_ino, hinofile);
11237 + hidx = au_dr_ihash(ent->dr_h_ino);
11238 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11240 + goto out; /* success */
11243 + au_dr_hino_free(dr);
11250 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11251 + * @path is a switch to distinguish load and store.
11253 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11254 + struct au_branch *br, const struct path *path)
11257 + unsigned char load, suspend;
11258 + struct file *hinofile;
11259 + struct au_hinode *hdir;
11260 + struct inode *dir, *delegated;
11261 + struct path hinopath;
11262 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11263 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11265 + AuDebugOn(bindex < 0 && !br);
11266 + AuDebugOn(bindex >= 0 && br);
11271 + br = au_sbr(sb, bindex);
11274 + path = &br->br_path;
11275 + AuDebugOn(!au_br_writable(br->br_perm));
11276 + if (unlikely(!au_br_writable(br->br_perm)))
11282 + dir = d_inode(sb->s_root);
11283 + hdir = au_hinode(au_ii(dir), bindex);
11284 + dir = hdir->hi_inode;
11285 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11287 + dir = d_inode(path->dentry);
11288 + inode_lock_nested(dir, AuLsc_I_CHILD);
11290 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11291 + err = PTR_ERR(hinopath.dentry);
11292 + if (IS_ERR(hinopath.dentry))
11296 + flags = O_RDONLY;
11298 + if (d_is_negative(hinopath.dentry))
11299 + goto out_dput; /* success */
11301 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11302 + if (d_is_positive(hinopath.dentry)) {
11303 + delegated = NULL;
11304 + err = vfsub_unlink(dir, &hinopath, &delegated,
11307 + if (unlikely(err))
11308 + pr_err("ignored err %d, %pd2\n",
11309 + err, hinopath.dentry);
11310 + if (unlikely(err == -EWOULDBLOCK))
11315 + } else if (!d_is_positive(hinopath.dentry)) {
11316 + err = vfsub_create(dir, &hinopath, 0600,
11317 + /*want_excl*/false);
11319 + if (unlikely(err))
11322 + flags = O_WRONLY;
11324 + hinopath.mnt = path->mnt;
11325 + hinofile = vfsub_dentry_open(&hinopath, flags);
11327 + au_hn_inode_unlock(hdir);
11329 + inode_unlock(dir);
11330 + dput(hinopath.dentry);
11331 + AuTraceErrPtr(hinofile);
11332 + if (IS_ERR(hinofile)) {
11333 + err = PTR_ERR(hinofile);
11338 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11340 + err = au_dr_hino_store(sb, br, hinofile);
11345 + dput(hinopath.dentry);
11348 + au_hn_inode_unlock(hdir);
11350 + inode_unlock(dir);
11356 +/* ---------------------------------------------------------------------- */
11358 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11361 + struct kstatfs kstfs;
11363 + struct dentry *dentry;
11364 + struct super_block *sb;
11366 + err = vfs_statfs((void *)path, &kstfs);
11368 + if (unlikely(err))
11371 + /* todo: support for UUID */
11373 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11374 + brid->type = AuBrid_FSID;
11375 + brid->fsid = kstfs.f_fsid;
11377 + dentry = path->dentry;
11378 + sb = dentry->d_sb;
11381 + brid->type = AuBrid_DEV;
11390 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11391 + const struct path *path)
11394 + struct au_dr_br *dr;
11395 + struct hlist_bl_head *hbl;
11397 + dr = &br->br_dirren;
11398 + hbl = dr->dr_h_ino;
11399 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11400 + INIT_HLIST_BL_HEAD(hbl);
11402 + err = au_dr_brid_init(&dr->dr_brid, path);
11403 + if (unlikely(err))
11406 + if (au_opt_test(au_mntflags(sb), DIRREN))
11407 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11414 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11419 + if (au_br_writable(br->br_perm))
11420 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11422 + au_dr_hino_free(&br->br_dirren);
11427 +/* ---------------------------------------------------------------------- */
11429 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11430 + char *buf, size_t sz)
11433 + unsigned int major, minor;
11437 + err = snprintf(p, sz, "%d_", brid->type);
11438 + AuDebugOn(err > sz);
11441 + switch (brid->type) {
11442 + case AuBrid_Unset:
11444 + case AuBrid_UUID:
11445 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11447 + case AuBrid_FSID:
11448 + err = snprintf(p, sz, "%08x-%08x",
11449 + brid->fsid.val[0], brid->fsid.val[1]);
11452 + major = MAJOR(brid->dev);
11453 + minor = MINOR(brid->dev);
11454 + if (major <= 0xff && minor <= 0xff)
11455 + err = snprintf(p, sz, "%02x%02x", major, minor);
11457 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11460 + AuDebugOn(err > sz);
11463 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11464 + AuDebugOn(err > sz);
11471 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11474 + struct dentry *br_dentry;
11475 + struct inode *br_inode;
11477 + br_dentry = au_br_dentry(br);
11478 + br_inode = d_inode(br_dentry);
11479 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11480 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11481 + AuDebugOn(rlen > len);
11486 +/* ---------------------------------------------------------------------- */
11489 + * from the given @h_dentry, construct drinfo at @*fdata.
11490 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11493 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11494 + struct dentry *h_dentry,
11495 + unsigned char *allocated)
11498 + struct au_drinfo_fdata *f, *p;
11499 + struct au_drinfo *drinfo;
11500 + struct inode *h_inode;
11501 + struct qstr *qname;
11505 + h_inode = d_inode(h_dentry);
11506 + qname = &h_dentry->d_name;
11507 + drinfo = &f->drinfo;
11508 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11509 + drinfo->oldnamelen = qname->len;
11510 + if (*allocated < sizeof(*f) + qname->len) {
11511 + v = roundup_pow_of_two(*allocated + qname->len);
11512 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11513 + if (unlikely(!p)) {
11521 + drinfo = &f->drinfo;
11523 + memcpy(drinfo->oldname, qname->name, qname->len);
11524 + AuDbg("i%llu, %.*s\n",
11525 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11526 + drinfo->oldname);
11533 +/* callers have to free the return value */
11534 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11536 + struct au_drinfo *ret, *drinfo;
11537 + struct au_drinfo_fdata fdata;
11542 + ret = ERR_PTR(-EIO);
11544 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11545 + if (unlikely(ssz != sizeof(fdata))) {
11546 + AuIOErr("ssz %zd, %u, %pD2\n",
11547 + ssz, (unsigned int)sizeof(fdata), file);
11551 + fdata.magic = ntohl((__force __be32)fdata.magic);
11552 + switch (fdata.magic) {
11553 + case AUFS_DRINFO_MAGIC_V1:
11556 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11557 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11561 + drinfo = &fdata.drinfo;
11562 + len = drinfo->oldnamelen;
11564 + AuIOErr("broken drinfo %pD2\n", file);
11569 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11570 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11571 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11572 + (unsigned long long)drinfo->ino,
11573 + (unsigned long long)h_ino, file);
11574 + goto out; /* success */
11577 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11578 + if (unlikely(!ret)) {
11579 + ret = ERR_PTR(-ENOMEM);
11580 + AuTraceErrPtr(ret);
11585 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11586 + if (unlikely(ssz != len)) {
11588 + ret = ERR_PTR(-EIO);
11589 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11593 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11599 +/* ---------------------------------------------------------------------- */
11601 +/* in order to be revertible */
11602 +struct au_drinfo_rev_elm {
11604 + struct dentry *info_dentry;
11605 + struct au_drinfo *info_last;
11608 +struct au_drinfo_rev {
11609 + unsigned char already;
11610 + aufs_bindex_t nelm;
11611 + struct au_drinfo_rev_elm elm[0];
11614 +/* todo: isn't it too large? */
11615 +struct au_drinfo_store {
11616 + struct path h_ppath;
11617 + struct dentry *h_dentry;
11618 + struct au_drinfo_fdata *fdata;
11619 + char *infoname; /* inside of whname, just after PFX */
11620 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11621 + aufs_bindex_t btgt, btail;
11622 + unsigned char no_sio,
11623 + allocated, /* current size of *fdata */
11624 + infonamelen, /* room size for p */
11625 + whnamelen, /* length of the generated name */
11626 + renameback; /* renamed back */
11629 +/* on rename(2) error, the caller should revert it using @elm */
11630 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11631 + struct au_drinfo_rev_elm *elm)
11636 + struct path infopath = {
11637 + .mnt = w->h_ppath.mnt
11639 + struct inode *h_dir, *h_inode, *delegated;
11640 + struct file *infofile;
11641 + struct qstr *qname;
11644 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11646 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11648 + AuTraceErrPtr(infopath.dentry);
11649 + if (IS_ERR(infopath.dentry)) {
11650 + err = PTR_ERR(infopath.dentry);
11655 + h_dir = d_inode(w->h_ppath.dentry);
11656 + if (elm && d_is_negative(infopath.dentry)) {
11657 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11659 + if (unlikely(err))
11661 + elm->created = 1;
11662 + elm->info_dentry = dget(infopath.dentry);
11665 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11666 + AuTraceErrPtr(infofile);
11667 + if (IS_ERR(infofile)) {
11668 + err = PTR_ERR(infofile);
11672 + h_inode = d_inode(infopath.dentry);
11673 + if (elm && i_size_read(h_inode)) {
11674 + h_inode = d_inode(w->h_dentry);
11675 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11676 + AuTraceErrPtr(elm->info_last);
11677 + if (IS_ERR(elm->info_last)) {
11678 + err = PTR_ERR(elm->info_last);
11679 + elm->info_last = NULL;
11680 + AuDebugOn(elm->info_dentry);
11685 + if (elm && w->renameback) {
11686 + delegated = NULL;
11687 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11689 + if (unlikely(err == -EWOULDBLOCK))
11695 + qname = &w->h_dentry->d_name;
11696 + len = sizeof(*w->fdata) + qname->len;
11698 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11699 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11700 + if (ssz == len) {
11701 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11702 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11703 + goto out_fput; /* success */
11708 + /* the caller should revert it using @elm */
11714 + dput(infopath.dentry);
11720 +struct au_call_drinfo_do_store_args {
11722 + struct au_drinfo_store *w;
11723 + struct au_drinfo_rev_elm *elm;
11726 +static void au_call_drinfo_do_store(void *args)
11728 + struct au_call_drinfo_do_store_args *a = args;
11730 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11733 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11734 + struct au_drinfo_rev_elm *elm)
11736 + int err, wkq_err;
11739 + err = au_drinfo_do_store(w, elm);
11741 + struct au_call_drinfo_do_store_args a = {
11746 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11747 + if (unlikely(wkq_err))
11755 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11756 + aufs_bindex_t btgt)
11760 + memset(w, 0, sizeof(*w));
11761 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11762 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11763 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11764 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11766 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11769 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11770 + if (unlikely(!w->fdata)) {
11774 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11781 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11786 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11787 + struct au_drinfo_store *w)
11789 + struct au_drinfo_rev_elm *elm;
11790 + struct inode *h_dir, *delegated;
11792 + struct path infopath = {
11793 + .mnt = w->h_ppath.mnt
11796 + h_dir = d_inode(w->h_ppath.dentry);
11797 + IMustLock(h_dir);
11801 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11802 + AuDebugOn(elm->created && elm->info_last);
11803 + if (elm->created) {
11805 + delegated = NULL;
11806 + infopath.dentry = elm->info_dentry;
11807 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11810 + if (unlikely(err == -EWOULDBLOCK))
11812 + dput(elm->info_dentry);
11813 + } else if (elm->info_last) {
11815 + w->fdata->drinfo = *elm->info_last;
11816 + memcpy(w->fdata->drinfo.oldname,
11817 + elm->info_last->oldname,
11818 + elm->info_last->oldnamelen);
11819 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11820 + kfree(elm->info_last);
11822 + if (unlikely(err))
11823 + AuIOErr("%d, %s\n", err, w->whname);
11824 + /* go on even if err */
11828 +/* caller has to call au_dr_rename_fin() later */
11829 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11830 + struct qstr *dst_name, void *_rev)
11832 + int err, sz, nelm;
11833 + aufs_bindex_t bindex, btail;
11834 + struct au_drinfo_store work;
11835 + struct au_drinfo_rev *rev, **p;
11836 + struct au_drinfo_rev_elm *elm;
11837 + struct super_block *sb;
11838 + struct au_branch *br;
11839 + struct au_hinode *hdir;
11841 + err = au_drinfo_store_work_init(&work, btgt);
11843 + if (unlikely(err))
11847 + btail = au_dbtaildir(dentry);
11848 + nelm = btail - btgt;
11849 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11850 + rev = kcalloc(1, sz, GFP_NOFS);
11851 + if (unlikely(!rev)) {
11855 + rev->nelm = nelm;
11861 + sb = dentry->d_sb;
11862 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11863 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11864 + hdir = au_hi(d_inode(dentry), btgt);
11865 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11866 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11867 + work.h_dentry = au_h_dptr(dentry, bindex);
11868 + if (!work.h_dentry)
11871 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11872 + &work.allocated);
11874 + if (unlikely(err))
11877 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11878 + br = au_sbr(sb, bindex);
11879 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11880 + work.whnamelen += au_drinfo_name(br, work.infoname,
11881 + work.infonamelen);
11882 + AuDbg("whname %.*s, i%llu, %.*s\n",
11883 + work.whnamelen, work.whname,
11884 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11885 + work.fdata->drinfo.oldnamelen,
11886 + work.fdata->drinfo.oldname);
11888 + err = au_drinfo_store_sio(&work, elm);
11890 + if (unlikely(err))
11893 + if (unlikely(err)) {
11894 + /* revert all drinfo */
11895 + au_drinfo_store_rev(rev, &work);
11899 + au_hn_inode_unlock(hdir);
11902 + au_drinfo_store_work_fin(&work);
11907 +/* ---------------------------------------------------------------------- */
11909 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11910 + struct qstr *dst_name, void *_rev)
11912 + int err, already;
11914 + struct super_block *sb;
11915 + struct au_branch *br;
11916 + struct au_dr_br *dr;
11917 + struct dentry *h_dentry;
11918 + struct inode *h_inode;
11919 + struct au_dr_hino *ent;
11920 + struct au_drinfo_rev *rev, **p;
11922 + AuDbg("bindex %d\n", bindex);
11925 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11926 + if (unlikely(!ent))
11930 + br = au_sbr(sb, bindex);
11931 + dr = &br->br_dirren;
11932 + h_dentry = au_h_dptr(src, bindex);
11933 + h_inode = d_inode(h_dentry);
11934 + ino = h_inode->i_ino;
11935 + ent->dr_h_ino = ino;
11936 + already = au_dr_hino_test_add(dr, ino, ent);
11937 + AuDbg("b%d, hi%llu, already %d\n",
11938 + bindex, (unsigned long long)ino, already);
11940 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11945 + rev->already = already;
11946 + goto out; /* success */
11951 + au_dr_hino_del(dr, ent);
11959 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11961 + struct au_drinfo_rev *rev;
11962 + struct au_drinfo_rev_elm *elm;
11967 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11968 + dput(elm->info_dentry);
11969 + kfree(elm->info_last);
11974 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11977 + struct au_drinfo_store work;
11978 + struct au_drinfo_rev *rev = _rev;
11979 + struct super_block *sb;
11980 + struct au_branch *br;
11981 + struct inode *h_inode;
11982 + struct au_dr_br *dr;
11983 + struct au_dr_hino *ent;
11985 + err = au_drinfo_store_work_init(&work, btgt);
11986 + if (unlikely(err))
11990 + br = au_sbr(sb, btgt);
11991 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11992 + work.h_ppath.mnt = au_br_mnt(br);
11993 + au_drinfo_store_rev(rev, &work);
11994 + au_drinfo_store_work_fin(&work);
11995 + if (rev->already)
11998 + dr = &br->br_dirren;
11999 + h_inode = d_inode(work.h_ppath.dentry);
12000 + ent = au_dr_hino_find(dr, h_inode->i_ino);
12002 + au_dr_hino_del(dr, ent);
12007 + if (unlikely(err))
12008 + pr_err("failed to remove dirren info\n");
12011 +/* ---------------------------------------------------------------------- */
12013 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12014 + char *whname, int whnamelen,
12015 + struct dentry **info_dentry)
12017 + struct au_drinfo *drinfo;
12019 + struct inode *h_dir;
12020 + struct path infopath;
12023 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12025 + *info_dentry = NULL;
12028 + h_dir = d_inode(h_ppath->dentry);
12029 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12030 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12032 + if (IS_ERR(infopath.dentry)) {
12033 + drinfo = (void *)infopath.dentry;
12037 + if (d_is_negative(infopath.dentry))
12038 + goto out_dput; /* success */
12040 + infopath.mnt = h_ppath->mnt;
12041 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12042 + inode_unlock_shared(h_dir);
12045 + drinfo = (void *)f;
12049 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12050 + if (IS_ERR_OR_NULL(drinfo))
12053 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12054 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12059 + dput(infopath.dentry);
12062 + inode_unlock_shared(h_dir);
12063 + AuTraceErrPtr(drinfo);
12067 +struct au_drinfo_do_load_args {
12068 + struct au_drinfo **drinfop;
12069 + struct path *h_ppath;
12072 + struct dentry **info_dentry;
12075 +static void au_call_drinfo_do_load(void *args)
12077 + struct au_drinfo_do_load_args *a = args;
12079 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12083 +struct au_drinfo_load {
12084 + struct path h_ppath;
12085 + struct qstr *qname;
12086 + unsigned char no_sio;
12088 + aufs_bindex_t ninfo;
12089 + struct au_drinfo **drinfo;
12092 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12093 + struct au_branch *br)
12095 + int err, wkq_err, whnamelen, e;
12096 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12097 + = AUFS_WH_DR_INFO_PFX;
12098 + struct au_drinfo *drinfo;
12099 + struct qstr oldname;
12100 + struct inode *h_dir, *delegated;
12101 + struct dentry *info_dentry;
12102 + struct path infopath;
12104 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12105 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12106 + sizeof(whname) - whnamelen);
12108 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12111 + struct au_drinfo_do_load_args args = {
12112 + .drinfop = &drinfo,
12113 + .h_ppath = &w->h_ppath,
12114 + .whname = whname,
12115 + .whnamelen = whnamelen,
12116 + .info_dentry = &info_dentry
12118 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12119 + if (unlikely(wkq_err))
12120 + drinfo = ERR_PTR(wkq_err);
12122 + err = PTR_ERR(drinfo);
12123 + if (IS_ERR_OR_NULL(drinfo))
12127 + oldname.len = drinfo->oldnamelen;
12128 + oldname.name = drinfo->oldname;
12129 + if (au_qstreq(w->qname, &oldname)) {
12130 + /* the name is renamed back */
12134 + infopath.dentry = info_dentry;
12135 + infopath.mnt = w->h_ppath.mnt;
12136 + h_dir = d_inode(w->h_ppath.dentry);
12137 + delegated = NULL;
12138 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12139 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12140 + inode_unlock(h_dir);
12142 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12143 + if (unlikely(e == -EWOULDBLOCK))
12146 + kfree(w->drinfo[bindex]);
12147 + w->drinfo[bindex] = drinfo;
12148 + dput(info_dentry);
12155 +/* ---------------------------------------------------------------------- */
12157 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12159 + struct au_drinfo **p = drinfo;
12162 + kfree(*drinfo++);
12166 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12167 + aufs_bindex_t btgt)
12170 + struct au_drinfo_load w;
12171 + aufs_bindex_t bindex, bbot;
12172 + struct au_branch *br;
12173 + struct inode *h_dir;
12174 + struct au_dr_hino *ent;
12175 + struct super_block *sb;
12177 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12178 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12179 + AuLNPair(&lkup->whname), btgt);
12181 + sb = dentry->d_sb;
12182 + bbot = au_sbbot(sb);
12183 + w.ninfo = bbot + 1;
12184 + if (!lkup->dirren.drinfo) {
12185 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12186 + sizeof(*lkup->dirren.drinfo),
12188 + if (unlikely(!lkup->dirren.drinfo)) {
12192 + lkup->dirren.ninfo = w.ninfo;
12194 + w.drinfo = lkup->dirren.drinfo;
12195 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12196 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12197 + AuDebugOn(!w.h_ppath.dentry);
12198 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12199 + w.qname = &dentry->d_name;
12202 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12203 + br = au_sbr(sb, bindex);
12204 + err = au_drinfo_load(&w, bindex, br);
12205 + if (unlikely(err))
12207 + if (w.drinfo[bindex])
12211 + br = au_sbr(sb, btgt);
12212 + h_dir = d_inode(w.h_ppath.dentry);
12213 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12215 + au_dr_hino_del(&br->br_dirren, ent);
12218 + goto out; /* success */
12221 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12222 + lkup->dirren.ninfo = 0;
12223 + lkup->dirren.drinfo = NULL;
12229 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12231 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12234 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12237 + struct au_drinfo *drinfo;
12240 + if (!lkup->dirren.drinfo)
12242 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12243 + drinfo = lkup->dirren.drinfo[btgt + 1];
12247 + kfree(lkup->whname.name);
12248 + lkup->whname.name = NULL;
12249 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12250 + lkup->dirren.dr_name.name = drinfo->oldname;
12251 + lkup->name = &lkup->dirren.dr_name;
12252 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12254 + AuDbg("name %.*s, whname %.*s, b%d\n",
12255 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12263 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12267 + struct au_drinfo *drinfo;
12270 + if (!lkup->dirren.drinfo)
12272 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12273 + drinfo = lkup->dirren.drinfo[bindex + 1];
12277 + match = (drinfo->ino == h_ino);
12278 + AuDbg("match %d\n", match);
12284 +/* ---------------------------------------------------------------------- */
12286 +int au_dr_opt_set(struct super_block *sb)
12289 + aufs_bindex_t bindex, bbot;
12290 + struct au_branch *br;
12293 + bbot = au_sbbot(sb);
12294 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12295 + br = au_sbr(sb, bindex);
12296 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12302 +int au_dr_opt_flush(struct super_block *sb)
12305 + aufs_bindex_t bindex, bbot;
12306 + struct au_branch *br;
12309 + bbot = au_sbbot(sb);
12310 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12311 + br = au_sbr(sb, bindex);
12312 + if (au_br_writable(br->br_perm))
12313 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12319 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12322 + aufs_bindex_t bindex, bbot;
12323 + struct au_branch *br;
12327 + err = au_dr_opt_flush(sb);
12328 + if (unlikely(err))
12332 + bbot = au_sbbot(sb);
12333 + for (bindex = 0; bindex <= bbot; bindex++) {
12334 + br = au_sbr(sb, bindex);
12335 + au_dr_hino_free(&br->br_dirren);
12341 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12342 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12343 +++ linux/fs/aufs/dirren.h 2018-08-12 23:43:05.453457863 +0200
12345 +/* SPDX-License-Identifier: GPL-2.0 */
12347 + * Copyright (C) 2017-2018 Junjiro R. Okajima
12349 + * This program, aufs is free software; you can redistribute it and/or modify
12350 + * it under the terms of the GNU General Public License as published by
12351 + * the Free Software Foundation; either version 2 of the License, or
12352 + * (at your option) any later version.
12354 + * This program is distributed in the hope that it will be useful,
12355 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12356 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12357 + * GNU General Public License for more details.
12359 + * You should have received a copy of the GNU General Public License
12360 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12364 + * renamed dir info
12367 +#ifndef __AUFS_DIRREN_H__
12368 +#define __AUFS_DIRREN_H__
12372 +#include <linux/dcache.h>
12373 +#include <linux/statfs.h>
12374 +#include <linux/uuid.h>
12377 +#define AuDirren_NHASH 100
12379 +#ifdef CONFIG_AUFS_DIRREN
12380 +enum au_brid_type {
12387 +struct au_dr_brid {
12388 + enum au_brid_type type;
12390 + uuid_t uuid; /* unimplemented yet */
12396 +/* 20 is the max digits length of ulong 64 */
12397 +/* brid-type "_" uuid "_" inum */
12398 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12399 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12401 +struct au_dr_hino {
12402 + struct hlist_bl_node dr_hnode;
12407 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12408 + struct au_dr_brid dr_brid;
12411 +struct au_dr_lookup {
12412 + /* dr_name is pointed by struct au_do_lookup_args.name */
12413 + struct qstr dr_name; /* subset of dr_info */
12414 + aufs_bindex_t ninfo;
12415 + struct au_drinfo **drinfo;
12418 +struct au_dr_hino;
12420 +struct au_dr_br { };
12421 +struct au_dr_lookup { };
12424 +/* ---------------------------------------------------------------------- */
12427 +struct au_do_lookup_args;
12429 +#ifdef CONFIG_AUFS_DIRREN
12430 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12431 + struct au_dr_hino *add_ent);
12432 +void au_dr_hino_free(struct au_dr_br *dr);
12433 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12434 + const struct path *path);
12435 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12436 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12437 + struct qstr *dst_name, void *_rev);
12438 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12439 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12440 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12441 + aufs_bindex_t bindex);
12442 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12443 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12445 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12446 +int au_dr_opt_set(struct super_block *sb);
12447 +int au_dr_opt_flush(struct super_block *sb);
12448 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12450 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12451 + struct au_dr_hino *add_ent);
12452 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12453 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12454 + const struct path *path);
12455 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12456 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12457 + struct qstr *dst_name, void *_rev);
12458 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12459 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12461 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12462 + aufs_bindex_t bindex);
12463 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12464 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12465 + aufs_bindex_t bindex, ino_t h_ino);
12466 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12467 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12468 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12469 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12472 +/* ---------------------------------------------------------------------- */
12474 +#ifdef CONFIG_AUFS_DIRREN
12475 +static inline int au_dr_ihash(ino_t h_ino)
12477 + return h_ino % AuDirren_NHASH;
12480 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12483 +#endif /* __KERNEL__ */
12484 +#endif /* __AUFS_DIRREN_H__ */
12485 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12486 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12487 +++ linux/fs/aufs/dynop.c 2018-10-23 12:33:35.596042364 +0200
12489 +// SPDX-License-Identifier: GPL-2.0
12491 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12493 + * This program, aufs is free software; you can redistribute it and/or modify
12494 + * it under the terms of the GNU General Public License as published by
12495 + * the Free Software Foundation; either version 2 of the License, or
12496 + * (at your option) any later version.
12498 + * This program is distributed in the hope that it will be useful,
12499 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12500 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12501 + * GNU General Public License for more details.
12503 + * You should have received a copy of the GNU General Public License
12504 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12508 + * dynamically customizable operations for regular files
12513 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12516 + * How large will these lists be?
12517 + * Usually just a few elements, 20-30 at most for each, I guess.
12519 +static struct hlist_bl_head dynop[AuDyLast];
12521 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12522 + const void *h_op)
12524 + struct au_dykey *key, *tmp;
12525 + struct hlist_bl_node *pos;
12528 + hlist_bl_lock(hbl);
12529 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12530 + if (tmp->dk_op.dy_hop == h_op) {
12532 + kref_get(&key->dk_kref);
12535 + hlist_bl_unlock(hbl);
12540 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12542 + struct au_dykey **k, *found;
12543 + const void *h_op = key->dk_op.dy_hop;
12547 + k = br->br_dykey;
12548 + for (i = 0; i < AuBrDynOp; i++)
12550 + if (k[i]->dk_op.dy_hop == h_op) {
12557 + spin_lock(&br->br_dykey_lock);
12558 + for (; i < AuBrDynOp; i++)
12560 + if (k[i]->dk_op.dy_hop == h_op) {
12568 + spin_unlock(&br->br_dykey_lock);
12569 + BUG_ON(i == AuBrDynOp); /* expand the array */
12575 +/* kref_get() if @key is already added */
12576 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12578 + struct au_dykey *tmp, *found;
12579 + struct hlist_bl_node *pos;
12580 + const void *h_op = key->dk_op.dy_hop;
12583 + hlist_bl_lock(hbl);
12584 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12585 + if (tmp->dk_op.dy_hop == h_op) {
12586 + kref_get(&tmp->dk_kref);
12591 + hlist_bl_add_head(&key->dk_hnode, hbl);
12592 + hlist_bl_unlock(hbl);
12599 +static void dy_free_rcu(struct rcu_head *rcu)
12601 + struct au_dykey *key;
12603 + key = container_of(rcu, struct au_dykey, dk_rcu);
12608 +static void dy_free(struct kref *kref)
12610 + struct au_dykey *key;
12611 + struct hlist_bl_head *hbl;
12613 + key = container_of(kref, struct au_dykey, dk_kref);
12614 + hbl = dynop + key->dk_op.dy_type;
12615 + au_hbl_del(&key->dk_hnode, hbl);
12616 + call_rcu(&key->dk_rcu, dy_free_rcu);
12619 +void au_dy_put(struct au_dykey *key)
12621 + kref_put(&key->dk_kref, dy_free);
12624 +/* ---------------------------------------------------------------------- */
12626 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12628 +#ifdef CONFIG_AUFS_DEBUG
12629 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12630 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12632 +#define DyDbgDeclare(cnt) do {} while (0)
12633 +#define DyDbgInc(cnt) do {} while (0)
12636 +#define DySet(func, dst, src, h_op, h_sb) do { \
12638 + if (h_op->func) { \
12640 + dst.func = src.func; \
12642 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12646 +#define DySetForce(func, dst, src) do { \
12647 + AuDebugOn(!src.func); \
12649 + dst.func = src.func; \
12652 +#define DySetAop(func) \
12653 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12654 +#define DySetAopForce(func) \
12655 + DySetForce(func, dyaop->da_op, aufs_aop)
12657 +static void dy_aop(struct au_dykey *key, const void *h_op,
12658 + struct super_block *h_sb __maybe_unused)
12660 + struct au_dyaop *dyaop = (void *)key;
12661 + const struct address_space_operations *h_aop = h_op;
12662 + DyDbgDeclare(cnt);
12664 + AuDbg("%s\n", au_sbtype(h_sb));
12666 + DySetAop(writepage);
12667 + DySetAopForce(readpage); /* force */
12668 + DySetAop(writepages);
12669 + DySetAop(set_page_dirty);
12670 + DySetAop(readpages);
12671 + DySetAop(write_begin);
12672 + DySetAop(write_end);
12674 + DySetAop(invalidatepage);
12675 + DySetAop(releasepage);
12676 + DySetAop(freepage);
12677 + /* this one will be changed according to an aufs mount option */
12678 + DySetAop(direct_IO);
12679 + DySetAop(migratepage);
12680 + DySetAop(isolate_page);
12681 + DySetAop(putback_page);
12682 + DySetAop(launder_page);
12683 + DySetAop(is_partially_uptodate);
12684 + DySetAop(is_dirty_writeback);
12685 + DySetAop(error_remove_page);
12686 + DySetAop(swap_activate);
12687 + DySetAop(swap_deactivate);
12689 + DyDbgSize(cnt, *h_aop);
12692 +/* ---------------------------------------------------------------------- */
12694 +static void dy_bug(struct kref *kref)
12699 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12701 + struct au_dykey *key, *old;
12702 + struct hlist_bl_head *hbl;
12705 + void (*set)(struct au_dykey *key, const void *h_op,
12706 + struct super_block *h_sb __maybe_unused);
12708 + static const struct op a[] = {
12710 + .sz = sizeof(struct au_dyaop),
12714 + const struct op *p;
12716 + hbl = dynop + op->dy_type;
12717 + key = dy_gfind_get(hbl, op->dy_hop);
12719 + goto out_add; /* success */
12721 + p = a + op->dy_type;
12722 + key = kzalloc(p->sz, GFP_NOFS);
12723 + if (unlikely(!key)) {
12724 + key = ERR_PTR(-ENOMEM);
12728 + key->dk_op.dy_hop = op->dy_hop;
12729 + kref_init(&key->dk_kref);
12730 + p->set(key, op->dy_hop, au_br_sb(br));
12731 + old = dy_gadd(hbl, key);
12738 + old = dy_bradd(br, key);
12740 + /* its ref-count should never be zero here */
12741 + kref_put(&key->dk_kref, dy_bug);
12746 +/* ---------------------------------------------------------------------- */
12748 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12749 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12750 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12751 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12752 + * See the aufs manual in detail.
12754 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12757 + dyaop->da_op.direct_IO = NULL;
12759 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12762 +static struct au_dyaop *dy_aget(struct au_branch *br,
12763 + const struct address_space_operations *h_aop,
12766 + struct au_dyaop *dyaop;
12767 + struct au_dynop op;
12769 + op.dy_type = AuDy_AOP;
12770 + op.dy_haop = h_aop;
12771 + dyaop = (void *)dy_get(&op, br);
12772 + if (IS_ERR(dyaop))
12774 + dy_adx(dyaop, do_dx);
12780 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12781 + struct inode *h_inode)
12784 + struct super_block *sb;
12785 + struct au_branch *br;
12786 + struct au_dyaop *dyaop;
12788 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12789 + IiMustWriteLock(inode);
12791 + sb = inode->i_sb;
12792 + br = au_sbr(sb, bindex);
12793 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12794 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12795 + err = PTR_ERR(dyaop);
12796 + if (IS_ERR(dyaop))
12797 + /* unnecessary to call dy_fput() */
12801 + inode->i_mapping->a_ops = &dyaop->da_op;
12808 + * Is it safe to replace a_ops during the inode/file is in operation?
12809 + * Yes, I hope so.
12811 +int au_dy_irefresh(struct inode *inode)
12814 + aufs_bindex_t btop;
12815 + struct inode *h_inode;
12818 + if (S_ISREG(inode->i_mode)) {
12819 + btop = au_ibtop(inode);
12820 + h_inode = au_h_iptr(inode, btop);
12821 + err = au_dy_iaop(inode, btop, h_inode);
12826 +void au_dy_arefresh(int do_dx)
12828 + struct hlist_bl_head *hbl;
12829 + struct hlist_bl_node *pos;
12830 + struct au_dykey *key;
12832 + hbl = dynop + AuDy_AOP;
12833 + hlist_bl_lock(hbl);
12834 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12835 + dy_adx((void *)key, do_dx);
12836 + hlist_bl_unlock(hbl);
12839 +/* ---------------------------------------------------------------------- */
12841 +void __init au_dy_init(void)
12845 + /* make sure that 'struct au_dykey *' can be any type */
12846 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12848 + for (i = 0; i < AuDyLast; i++)
12849 + INIT_HLIST_BL_HEAD(dynop + i);
12852 +void au_dy_fin(void)
12856 + for (i = 0; i < AuDyLast; i++)
12857 + WARN_ON(!hlist_bl_empty(dynop + i));
12859 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12860 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12861 +++ linux/fs/aufs/dynop.h 2018-08-12 23:43:05.456791299 +0200
12863 +/* SPDX-License-Identifier: GPL-2.0 */
12865 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12867 + * This program, aufs is free software; you can redistribute it and/or modify
12868 + * it under the terms of the GNU General Public License as published by
12869 + * the Free Software Foundation; either version 2 of the License, or
12870 + * (at your option) any later version.
12872 + * This program is distributed in the hope that it will be useful,
12873 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12874 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12875 + * GNU General Public License for more details.
12877 + * You should have received a copy of the GNU General Public License
12878 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12882 + * dynamically customizable operations (for regular files only)
12885 +#ifndef __AUFS_DYNOP_H__
12886 +#define __AUFS_DYNOP_H__
12890 +#include <linux/fs.h>
12891 +#include <linux/kref.h>
12893 +enum {AuDy_AOP, AuDyLast};
12898 + const void *dy_hop;
12899 + const struct address_space_operations *dy_haop;
12905 + struct hlist_bl_node dk_hnode;
12906 + struct rcu_head dk_rcu;
12908 + struct au_dynop dk_op;
12911 + * during I am in the branch local array, kref is gotten. when the
12912 + * branch is removed, kref is put.
12914 + struct kref dk_kref;
12917 +/* stop unioning since their sizes are very different from each other */
12919 + struct au_dykey da_key;
12920 + struct address_space_operations da_op; /* not const */
12923 +/* ---------------------------------------------------------------------- */
12927 +void au_dy_put(struct au_dykey *key);
12928 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12929 + struct inode *h_inode);
12930 +int au_dy_irefresh(struct inode *inode);
12931 +void au_dy_arefresh(int do_dio);
12933 +void __init au_dy_init(void);
12934 +void au_dy_fin(void);
12936 +#endif /* __KERNEL__ */
12937 +#endif /* __AUFS_DYNOP_H__ */
12938 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12939 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12940 +++ linux/fs/aufs/export.c 2018-10-23 12:33:35.596042364 +0200
12942 +// SPDX-License-Identifier: GPL-2.0
12944 + * Copyright (C) 2005-2018 Junjiro R. Okajima
12946 + * This program, aufs is free software; you can redistribute it and/or modify
12947 + * it under the terms of the GNU General Public License as published by
12948 + * the Free Software Foundation; either version 2 of the License, or
12949 + * (at your option) any later version.
12951 + * This program is distributed in the hope that it will be useful,
12952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12954 + * GNU General Public License for more details.
12956 + * You should have received a copy of the GNU General Public License
12957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12964 +#include <linux/exportfs.h>
12965 +#include <linux/fs_struct.h>
12966 +#include <linux/namei.h>
12967 +#include <linux/nsproxy.h>
12968 +#include <linux/random.h>
12969 +#include <linux/writeback.h>
12973 +#ifdef CONFIG_AUFS_INO_T_64
12981 +static ino_t decode_ino(__u32 *a)
12985 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12987 +#ifdef CONFIG_AUFS_INO_T_64
12993 +static void encode_ino(__u32 *a, ino_t ino)
12999 +#ifdef CONFIG_AUFS_INO_T_64
13004 +/* NFS file handle */
13008 +#ifdef CONFIG_AUFS_INO_T_64
13009 + /* support 64bit inode number */
13022 + Fh_ino = Fh_ino1,
13023 + Fh_dir_ino = Fh_dir_ino1
13026 +static int au_test_anon(struct dentry *dentry)
13028 + /* note: read d_flags without d_lock */
13029 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13032 +int au_test_nfsd(void)
13035 + struct task_struct *tsk = current;
13036 + char comm[sizeof(tsk->comm)];
13039 + if (tsk->flags & PF_KTHREAD) {
13040 + get_task_comm(comm, tsk);
13041 + ret = !strcmp(comm, "nfsd");
13047 +/* ---------------------------------------------------------------------- */
13048 +/* inode generation external table */
13050 +void au_xigen_inc(struct inode *inode)
13055 + struct super_block *sb;
13056 + struct au_sbinfo *sbinfo;
13058 + sb = inode->i_sb;
13059 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13061 + sbinfo = au_sbi(sb);
13062 + pos = inode->i_ino;
13063 + pos *= sizeof(igen);
13064 + igen = inode->i_generation + 1;
13065 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13066 + sizeof(igen), &pos);
13067 + if (sz == sizeof(igen))
13068 + return; /* success */
13070 + if (unlikely(sz >= 0))
13071 + AuIOErr("xigen error (%zd)\n", sz);
13074 +int au_xigen_new(struct inode *inode)
13079 + struct super_block *sb;
13080 + struct au_sbinfo *sbinfo;
13081 + struct file *file;
13084 + /* todo: dirty, at mount time */
13085 + if (inode->i_ino == AUFS_ROOT_INO)
13087 + sb = inode->i_sb;
13088 + SiMustAnyLock(sb);
13089 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13093 + pos = inode->i_ino;
13094 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13095 + AuIOErr1("too large i%lld\n", pos);
13098 + pos *= sizeof(inode->i_generation);
13101 + sbinfo = au_sbi(sb);
13102 + file = sbinfo->si_xigen;
13105 + if (vfsub_f_size_read(file)
13106 + < pos + sizeof(inode->i_generation)) {
13107 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13108 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13109 + sizeof(inode->i_generation), &pos);
13111 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13112 + sizeof(inode->i_generation), &pos);
13113 + if (sz == sizeof(inode->i_generation))
13114 + goto out; /* success */
13117 + if (unlikely(sz >= 0)) {
13119 + AuIOErr("xigen error (%zd)\n", sz);
13126 +int au_xigen_set(struct super_block *sb, struct path *path)
13129 + struct au_sbinfo *sbinfo;
13130 + struct file *file;
13132 + SiMustWriteLock(sb);
13134 + sbinfo = au_sbi(sb);
13135 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13136 + err = PTR_ERR(file);
13137 + if (IS_ERR(file))
13140 + if (sbinfo->si_xigen)
13141 + fput(sbinfo->si_xigen);
13142 + sbinfo->si_xigen = file;
13149 +void au_xigen_clr(struct super_block *sb)
13151 + struct au_sbinfo *sbinfo;
13153 + SiMustWriteLock(sb);
13155 + sbinfo = au_sbi(sb);
13156 + if (sbinfo->si_xigen) {
13157 + fput(sbinfo->si_xigen);
13158 + sbinfo->si_xigen = NULL;
13162 +/* ---------------------------------------------------------------------- */
13164 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13167 + struct dentry *dentry, *d;
13168 + struct inode *inode;
13169 + unsigned int sigen;
13172 + inode = ilookup(sb, ino);
13176 + dentry = ERR_PTR(-ESTALE);
13177 + sigen = au_sigen(sb);
13178 + if (unlikely(au_is_bad_inode(inode)
13179 + || IS_DEADDIR(inode)
13180 + || sigen != au_iigen(inode, NULL)))
13184 + if (!dir_ino || S_ISDIR(inode->i_mode))
13185 + dentry = d_find_alias(inode);
13187 + spin_lock(&inode->i_lock);
13188 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13189 + spin_lock(&d->d_lock);
13190 + if (!au_test_anon(d)
13191 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13192 + dentry = dget_dlock(d);
13193 + spin_unlock(&d->d_lock);
13196 + spin_unlock(&d->d_lock);
13198 + spin_unlock(&inode->i_lock);
13200 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13201 + /* need to refresh */
13209 + AuTraceErrPtr(dentry);
13213 +/* ---------------------------------------------------------------------- */
13215 +/* todo: dirty? */
13216 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13218 +struct au_compare_mnt_args {
13220 + struct super_block *sb;
13223 + struct vfsmount *mnt;
13226 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13228 + struct au_compare_mnt_args *a = arg;
13230 + if (mnt->mnt_sb != a->sb)
13232 + a->mnt = mntget(mnt);
13236 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13239 + struct path root;
13240 + struct au_compare_mnt_args args = {
13244 + get_fs_root(current->fs, &root);
13246 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13247 + rcu_read_unlock();
13250 + AuDebugOn(!args.mnt);
13254 +struct au_nfsd_si_lock {
13255 + unsigned int sigen;
13256 + aufs_bindex_t bindex, br_id;
13257 + unsigned char force_lock;
13260 +static int si_nfsd_read_lock(struct super_block *sb,
13261 + struct au_nfsd_si_lock *nsi_lock)
13264 + aufs_bindex_t bindex;
13266 + si_read_lock(sb, AuLock_FLUSH);
13268 + /* branch id may be wrapped around */
13270 + bindex = au_br_index(sb, nsi_lock->br_id);
13271 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13272 + goto out; /* success */
13276 + if (!nsi_lock->force_lock)
13277 + si_read_unlock(sb);
13280 + nsi_lock->bindex = bindex;
13284 +struct find_name_by_ino {
13285 + struct dir_context ctx;
13286 + int called, found;
13293 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13294 + loff_t offset, u64 ino, unsigned int d_type)
13296 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13300 + if (a->ino != ino)
13303 + memcpy(a->name, name, namelen);
13304 + a->namelen = namelen;
13309 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13310 + struct au_nfsd_si_lock *nsi_lock)
13312 + struct dentry *dentry, *parent;
13313 + struct file *file;
13314 + struct inode *dir;
13315 + struct find_name_by_ino arg = {
13317 + .actor = find_name_by_ino
13322 + parent = path->dentry;
13324 + si_read_unlock(parent->d_sb);
13325 + file = vfsub_dentry_open(path, au_dir_roflags);
13326 + dentry = (void *)file;
13327 + if (IS_ERR(file))
13330 + dentry = ERR_PTR(-ENOMEM);
13331 + arg.name = (void *)__get_free_page(GFP_NOFS);
13332 + if (unlikely(!arg.name))
13339 + err = vfsub_iterate_dir(file, &arg.ctx);
13340 + } while (!err && !arg.found && arg.called);
13341 + dentry = ERR_PTR(err);
13342 + if (unlikely(err))
13344 + /* instead of ENOENT */
13345 + dentry = ERR_PTR(-ESTALE);
13349 + /* do not call vfsub_lkup_one() */
13350 + dir = d_inode(parent);
13351 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13352 + AuTraceErrPtr(dentry);
13353 + if (IS_ERR(dentry))
13355 + AuDebugOn(au_test_anon(dentry));
13356 + if (unlikely(d_really_is_negative(dentry))) {
13358 + dentry = ERR_PTR(-ENOENT);
13362 + free_page((unsigned long)arg.name);
13366 + if (unlikely(nsi_lock
13367 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13368 + if (!IS_ERR(dentry)) {
13370 + dentry = ERR_PTR(-ESTALE);
13372 + AuTraceErrPtr(dentry);
13376 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13378 + struct au_nfsd_si_lock *nsi_lock)
13380 + struct dentry *dentry;
13381 + struct path path;
13383 + if (dir_ino != AUFS_ROOT_INO) {
13384 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13385 + dentry = path.dentry;
13386 + if (!path.dentry || IS_ERR(path.dentry))
13388 + AuDebugOn(au_test_anon(path.dentry));
13390 + path.dentry = dget(sb->s_root);
13392 + path.mnt = au_mnt_get(sb);
13393 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13397 + AuTraceErrPtr(dentry);
13401 +/* ---------------------------------------------------------------------- */
13403 +static int h_acceptable(void *expv, struct dentry *dentry)
13408 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13409 + char *buf, int len, struct super_block *sb)
13413 + struct path path;
13415 + p = d_path(h_rootpath, buf, len);
13420 + path.mnt = h_rootpath->mnt;
13421 + path.dentry = h_parent;
13422 + p = d_path(&path, buf, len);
13428 + path.mnt = au_mnt_get(sb);
13429 + path.dentry = sb->s_root;
13430 + p = d_path(&path, buf, len - strlen(p));
13431 + mntput(path.mnt);
13435 + p[strlen(p)] = '/';
13438 + AuTraceErrPtr(p);
13443 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13444 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13446 + struct dentry *dentry, *h_parent, *root;
13447 + struct super_block *h_sb;
13448 + char *pathname, *p;
13449 + struct vfsmount *h_mnt;
13450 + struct au_branch *br;
13452 + struct path path;
13454 + br = au_sbr(sb, nsi_lock->bindex);
13455 + h_mnt = au_br_mnt(br);
13456 + h_sb = h_mnt->mnt_sb;
13457 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13459 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13460 + fh_len - Fh_tail, fh[Fh_h_type],
13461 + h_acceptable, /*context*/NULL);
13463 + dentry = h_parent;
13464 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13465 + AuWarn1("%s decode_fh failed, %ld\n",
13466 + au_sbtype(h_sb), PTR_ERR(h_parent));
13470 + if (unlikely(au_test_anon(h_parent))) {
13471 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13472 + au_sbtype(h_sb));
13473 + goto out_h_parent;
13476 + dentry = ERR_PTR(-ENOMEM);
13477 + pathname = (void *)__get_free_page(GFP_NOFS);
13478 + if (unlikely(!pathname))
13479 + goto out_h_parent;
13481 + root = sb->s_root;
13482 + path.mnt = h_mnt;
13483 + di_read_lock_parent(root, !AuLock_IR);
13484 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13485 + di_read_unlock(root, !AuLock_IR);
13486 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13487 + dentry = (void *)p;
13489 + goto out_pathname;
13491 + si_read_unlock(sb);
13492 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13493 + dentry = ERR_PTR(err);
13494 + if (unlikely(err))
13497 + dentry = ERR_PTR(-ENOENT);
13498 + AuDebugOn(au_test_anon(path.dentry));
13499 + if (unlikely(d_really_is_negative(path.dentry)))
13502 + if (ino != d_inode(path.dentry)->i_ino)
13503 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13505 + dentry = dget(path.dentry);
13510 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13511 + if (!IS_ERR(dentry)) {
13513 + dentry = ERR_PTR(-ESTALE);
13516 + free_page((unsigned long)pathname);
13520 + AuTraceErrPtr(dentry);
13524 +/* ---------------------------------------------------------------------- */
13526 +static struct dentry *
13527 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13530 + struct dentry *dentry;
13531 + __u32 *fh = fid->raw;
13532 + struct au_branch *br;
13533 + ino_t ino, dir_ino;
13534 + struct au_nfsd_si_lock nsi_lock = {
13538 + dentry = ERR_PTR(-ESTALE);
13539 + /* it should never happen, but the file handle is unreliable */
13540 + if (unlikely(fh_len < Fh_tail))
13542 + nsi_lock.sigen = fh[Fh_sigen];
13543 + nsi_lock.br_id = fh[Fh_br_id];
13545 + /* branch id may be wrapped around */
13547 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13549 + nsi_lock.force_lock = 1;
13551 + /* is this inode still cached? */
13552 + ino = decode_ino(fh + Fh_ino);
13553 + /* it should never happen */
13554 + if (unlikely(ino == AUFS_ROOT_INO))
13557 + dir_ino = decode_ino(fh + Fh_dir_ino);
13558 + dentry = decode_by_ino(sb, ino, dir_ino);
13559 + if (IS_ERR(dentry))
13564 + /* is the parent dir cached? */
13565 + br = au_sbr(sb, nsi_lock.bindex);
13566 + au_lcnt_inc(&br->br_nfiles);
13567 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13568 + if (IS_ERR(dentry))
13573 + /* lookup path */
13574 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13575 + if (IS_ERR(dentry))
13577 + if (unlikely(!dentry))
13578 + /* todo?: make it ESTALE */
13582 + if (!au_digen_test(dentry, au_sigen(sb))
13583 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13584 + goto out_unlock; /* success */
13587 + dentry = ERR_PTR(-ESTALE);
13590 + au_lcnt_dec(&br->br_nfiles);
13591 + si_read_unlock(sb);
13593 + AuTraceErrPtr(dentry);
13597 +#if 0 /* reserved for future use */
13598 +/* support subtreecheck option */
13599 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13600 + int fh_len, int fh_type)
13602 + struct dentry *parent;
13603 + __u32 *fh = fid->raw;
13606 + dir_ino = decode_ino(fh + Fh_dir_ino);
13607 + parent = decode_by_ino(sb, dir_ino, 0);
13608 + if (IS_ERR(parent))
13611 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13612 + dir_ino, fh, fh_len);
13615 + AuTraceErrPtr(parent);
13620 +/* ---------------------------------------------------------------------- */
13622 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13623 + struct inode *dir)
13626 + aufs_bindex_t bindex;
13627 + struct super_block *sb, *h_sb;
13628 + struct dentry *dentry, *parent, *h_parent;
13629 + struct inode *h_dir;
13630 + struct au_branch *br;
13633 + if (unlikely(*max_len <= Fh_tail)) {
13634 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13638 + err = FILEID_ROOT;
13639 + if (inode->i_ino == AUFS_ROOT_INO) {
13640 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13645 + sb = inode->i_sb;
13646 + err = si_read_lock(sb, AuLock_FLUSH);
13647 + if (unlikely(err))
13650 +#ifdef CONFIG_AUFS_DEBUG
13651 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13652 + AuWarn1("NFS-exporting requires xino\n");
13656 + ii_read_lock_child(inode);
13657 + bindex = au_ibtop(inode);
13659 + dentry = d_find_any_alias(inode);
13660 + if (unlikely(!dentry))
13662 + AuDebugOn(au_test_anon(dentry));
13663 + parent = dget_parent(dentry);
13665 + if (unlikely(!parent))
13667 + if (d_really_is_positive(parent))
13668 + dir = d_inode(parent);
13671 + ii_read_lock_parent(dir);
13672 + h_dir = au_h_iptr(dir, bindex);
13673 + ii_read_unlock(dir);
13674 + if (unlikely(!h_dir))
13676 + h_parent = d_find_any_alias(h_dir);
13677 + if (unlikely(!h_parent))
13678 + goto out_hparent;
13681 + br = au_sbr(sb, bindex);
13682 + h_sb = au_br_sb(br);
13683 + if (unlikely(!h_sb->s_export_op)) {
13684 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13685 + goto out_hparent;
13688 + fh[Fh_br_id] = br->br_id;
13689 + fh[Fh_sigen] = au_sigen(sb);
13690 + encode_ino(fh + Fh_ino, inode->i_ino);
13691 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13692 + fh[Fh_igen] = inode->i_generation;
13694 + *max_len -= Fh_tail;
13695 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13697 + /*connectable or subtreecheck*/0);
13698 + err = fh[Fh_h_type];
13699 + *max_len += Fh_tail;
13700 + /* todo: macros? */
13701 + if (err != FILEID_INVALID)
13704 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13711 + ii_read_unlock(inode);
13712 + si_read_unlock(sb);
13714 + if (unlikely(err < 0))
13715 + err = FILEID_INVALID;
13719 +/* ---------------------------------------------------------------------- */
13721 +static int aufs_commit_metadata(struct inode *inode)
13724 + aufs_bindex_t bindex;
13725 + struct super_block *sb;
13726 + struct inode *h_inode;
13727 + int (*f)(struct inode *inode);
13729 + sb = inode->i_sb;
13730 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13731 + ii_write_lock_child(inode);
13732 + bindex = au_ibtop(inode);
13733 + AuDebugOn(bindex < 0);
13734 + h_inode = au_h_iptr(inode, bindex);
13736 + f = h_inode->i_sb->s_export_op->commit_metadata;
13738 + err = f(h_inode);
13740 + struct writeback_control wbc = {
13741 + .sync_mode = WB_SYNC_ALL,
13742 + .nr_to_write = 0 /* metadata only */
13745 + err = sync_inode(h_inode, &wbc);
13748 + au_cpup_attr_timesizes(inode);
13749 + ii_write_unlock(inode);
13750 + si_read_unlock(sb);
13754 +/* ---------------------------------------------------------------------- */
13756 +static struct export_operations aufs_export_op = {
13757 + .fh_to_dentry = aufs_fh_to_dentry,
13758 + /* .fh_to_parent = aufs_fh_to_parent, */
13759 + .encode_fh = aufs_encode_fh,
13760 + .commit_metadata = aufs_commit_metadata
13763 +void au_export_init(struct super_block *sb)
13765 + struct au_sbinfo *sbinfo;
13768 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13769 + && IS_MODULE(CONFIG_EXPORTFS),
13770 + AUFS_NAME ": unsupported configuration "
13771 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13773 + sb->s_export_op = &aufs_export_op;
13774 + sbinfo = au_sbi(sb);
13775 + sbinfo->si_xigen = NULL;
13776 + get_random_bytes(&u, sizeof(u));
13777 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13778 + atomic_set(&sbinfo->si_xigen_next, u);
13780 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13781 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13782 +++ linux/fs/aufs/fhsm.c 2018-10-23 12:33:35.596042364 +0200
13784 +// SPDX-License-Identifier: GPL-2.0
13786 + * Copyright (C) 2011-2018 Junjiro R. Okajima
13788 + * This program, aufs is free software; you can redistribute it and/or modify
13789 + * it under the terms of the GNU General Public License as published by
13790 + * the Free Software Foundation; either version 2 of the License, or
13791 + * (at your option) any later version.
13793 + * This program is distributed in the hope that it will be useful,
13794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13796 + * GNU General Public License for more details.
13798 + * You should have received a copy of the GNU General Public License
13799 + * along with this program; if not, write to the Free Software
13800 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13804 + * File-based Hierarchy Storage Management
13807 +#include <linux/anon_inodes.h>
13808 +#include <linux/poll.h>
13809 +#include <linux/seq_file.h>
13810 +#include <linux/statfs.h>
13813 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13815 + struct au_sbinfo *sbinfo;
13816 + struct au_fhsm *fhsm;
13818 + SiMustAnyLock(sb);
13820 + sbinfo = au_sbi(sb);
13821 + fhsm = &sbinfo->si_fhsm;
13822 + AuDebugOn(!fhsm);
13823 + return fhsm->fhsm_bottom;
13826 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13828 + struct au_sbinfo *sbinfo;
13829 + struct au_fhsm *fhsm;
13831 + SiMustWriteLock(sb);
13833 + sbinfo = au_sbi(sb);
13834 + fhsm = &sbinfo->si_fhsm;
13835 + AuDebugOn(!fhsm);
13836 + fhsm->fhsm_bottom = bindex;
13839 +/* ---------------------------------------------------------------------- */
13841 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13843 + struct au_br_fhsm *bf;
13845 + bf = br->br_fhsm;
13846 + MtxMustLock(&bf->bf_lock);
13848 + return !bf->bf_readable
13849 + || time_after(jiffies,
13850 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13853 +/* ---------------------------------------------------------------------- */
13855 +static void au_fhsm_notify(struct super_block *sb, int val)
13857 + struct au_sbinfo *sbinfo;
13858 + struct au_fhsm *fhsm;
13860 + SiMustAnyLock(sb);
13862 + sbinfo = au_sbi(sb);
13863 + fhsm = &sbinfo->si_fhsm;
13864 + if (au_fhsm_pid(fhsm)
13865 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13866 + atomic_set(&fhsm->fhsm_readable, val);
13868 + wake_up(&fhsm->fhsm_wqh);
13872 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13873 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13876 + struct au_branch *br;
13877 + struct au_br_fhsm *bf;
13879 + br = au_sbr(sb, bindex);
13880 + AuDebugOn(au_br_rdonly(br));
13881 + bf = br->br_fhsm;
13885 + mutex_lock(&bf->bf_lock);
13887 + MtxMustLock(&bf->bf_lock);
13889 + /* sb->s_root for NFS is unreliable */
13890 + err = au_br_stfs(br, &bf->bf_stfs);
13891 + if (unlikely(err)) {
13892 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13896 + bf->bf_jiffy = jiffies;
13897 + bf->bf_readable = 1;
13899 + au_fhsm_notify(sb, /*val*/1);
13901 + *rstfs = bf->bf_stfs;
13905 + mutex_unlock(&bf->bf_lock);
13906 + au_fhsm_notify(sb, /*val*/1);
13911 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13914 + struct au_sbinfo *sbinfo;
13915 + struct au_fhsm *fhsm;
13916 + struct au_branch *br;
13917 + struct au_br_fhsm *bf;
13919 + AuDbg("b%d, force %d\n", bindex, force);
13920 + SiMustAnyLock(sb);
13922 + sbinfo = au_sbi(sb);
13923 + fhsm = &sbinfo->si_fhsm;
13924 + if (!au_ftest_si(sbinfo, FHSM)
13925 + || fhsm->fhsm_bottom == bindex)
13928 + br = au_sbr(sb, bindex);
13929 + bf = br->br_fhsm;
13931 + mutex_lock(&bf->bf_lock);
13933 + || au_fhsm_pid(fhsm)
13934 + || au_fhsm_test_jiffy(sbinfo, br))
13935 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13937 + mutex_unlock(&bf->bf_lock);
13940 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13942 + aufs_bindex_t bindex, bbot;
13943 + struct au_branch *br;
13945 + /* exclude the bottom */
13946 + bbot = au_fhsm_bottom(sb);
13947 + for (bindex = 0; bindex < bbot; bindex++) {
13948 + br = au_sbr(sb, bindex);
13949 + if (au_br_fhsm(br->br_perm))
13950 + au_fhsm_wrote(sb, bindex, force);
13954 +/* ---------------------------------------------------------------------- */
13956 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13959 + struct au_sbinfo *sbinfo;
13960 + struct au_fhsm *fhsm;
13963 + sbinfo = file->private_data;
13964 + fhsm = &sbinfo->si_fhsm;
13965 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13966 + if (atomic_read(&fhsm->fhsm_readable))
13967 + mask = EPOLLIN /* | EPOLLRDNORM */;
13970 + AuDbg("mask 0x%x\n", mask);
13974 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13975 + struct aufs_stfs *stfs, __s16 brid)
13979 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13981 + err = __put_user(brid, &stbr->brid);
13982 + if (unlikely(err))
13988 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13989 + struct aufs_stbr __user *stbr, size_t count)
13993 + aufs_bindex_t bindex, bbot;
13994 + struct au_branch *br;
13995 + struct au_br_fhsm *bf;
13997 + /* except the bottom branch */
14000 + bbot = au_fhsm_bottom(sb);
14001 + for (bindex = 0; !err && bindex < bbot; bindex++) {
14002 + br = au_sbr(sb, bindex);
14003 + if (!au_br_fhsm(br->br_perm))
14006 + bf = br->br_fhsm;
14007 + mutex_lock(&bf->bf_lock);
14008 + if (bf->bf_readable) {
14010 + if (count >= sizeof(*stbr))
14011 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14014 + bf->bf_readable = 0;
14015 + count -= sizeof(*stbr);
14019 + mutex_unlock(&bf->bf_lock);
14022 + err = sizeof(*stbr) * nstbr;
14027 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14032 + aufs_bindex_t nfhsm, bindex, bbot;
14033 + struct au_sbinfo *sbinfo;
14034 + struct au_fhsm *fhsm;
14035 + struct au_branch *br;
14036 + struct super_block *sb;
14039 + sbinfo = file->private_data;
14040 + fhsm = &sbinfo->si_fhsm;
14042 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14043 + if (!atomic_read(&fhsm->fhsm_readable)) {
14044 + if (vfsub_file_flags(file) & O_NONBLOCK)
14047 + err = wait_event_interruptible_locked_irq
14049 + atomic_read(&fhsm->fhsm_readable));
14051 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14052 + if (unlikely(err))
14055 + /* sb may already be dead */
14056 + au_rw_read_lock(&sbinfo->si_rwsem);
14057 + readable = atomic_read(&fhsm->fhsm_readable);
14058 + if (readable > 0) {
14059 + sb = sbinfo->si_sb;
14061 + /* exclude the bottom branch */
14063 + bbot = au_fhsm_bottom(sb);
14064 + for (bindex = 0; bindex < bbot; bindex++) {
14065 + br = au_sbr(sb, bindex);
14066 + if (au_br_fhsm(br->br_perm))
14070 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14071 + atomic_set(&fhsm->fhsm_readable, 0);
14072 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14076 + au_rw_read_unlock(&sbinfo->si_rwsem);
14084 +static int au_fhsm_release(struct inode *inode, struct file *file)
14086 + struct au_sbinfo *sbinfo;
14087 + struct au_fhsm *fhsm;
14089 + /* sb may already be dead */
14090 + sbinfo = file->private_data;
14091 + fhsm = &sbinfo->si_fhsm;
14092 + spin_lock(&fhsm->fhsm_spin);
14093 + fhsm->fhsm_pid = 0;
14094 + spin_unlock(&fhsm->fhsm_spin);
14095 + kobject_put(&sbinfo->si_kobj);
14100 +static const struct file_operations au_fhsm_fops = {
14101 + .owner = THIS_MODULE,
14102 + .llseek = noop_llseek,
14103 + .read = au_fhsm_read,
14104 + .poll = au_fhsm_poll,
14105 + .release = au_fhsm_release
14108 +int au_fhsm_fd(struct super_block *sb, int oflags)
14111 + struct au_sbinfo *sbinfo;
14112 + struct au_fhsm *fhsm;
14115 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14119 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14123 + sbinfo = au_sbi(sb);
14124 + fhsm = &sbinfo->si_fhsm;
14125 + spin_lock(&fhsm->fhsm_spin);
14126 + if (!fhsm->fhsm_pid)
14127 + fhsm->fhsm_pid = current->pid;
14130 + spin_unlock(&fhsm->fhsm_spin);
14131 + if (unlikely(err))
14134 + oflags |= O_RDONLY;
14135 + /* oflags |= FMODE_NONOTIFY; */
14136 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14138 + if (unlikely(fd < 0))
14141 + /* succeed regardless 'fhsm' status */
14142 + kobject_get(&sbinfo->si_kobj);
14143 + si_noflush_read_lock(sb);
14144 + if (au_ftest_si(sbinfo, FHSM))
14145 + au_fhsm_wrote_all(sb, /*force*/0);
14146 + si_read_unlock(sb);
14147 + goto out; /* success */
14150 + spin_lock(&fhsm->fhsm_spin);
14151 + fhsm->fhsm_pid = 0;
14152 + spin_unlock(&fhsm->fhsm_spin);
14158 +/* ---------------------------------------------------------------------- */
14160 +int au_fhsm_br_alloc(struct au_branch *br)
14165 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14167 + au_br_fhsm_init(br->br_fhsm);
14174 +/* ---------------------------------------------------------------------- */
14176 +void au_fhsm_fin(struct super_block *sb)
14178 + au_fhsm_notify(sb, /*val*/-1);
14181 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14183 + struct au_fhsm *fhsm;
14185 + fhsm = &sbinfo->si_fhsm;
14186 + spin_lock_init(&fhsm->fhsm_spin);
14187 + init_waitqueue_head(&fhsm->fhsm_wqh);
14188 + atomic_set(&fhsm->fhsm_readable, 0);
14189 + fhsm->fhsm_expire
14190 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14191 + fhsm->fhsm_bottom = -1;
14194 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14196 + sbinfo->si_fhsm.fhsm_expire
14197 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14200 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14204 + if (!au_ftest_si(sbinfo, FHSM))
14207 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14208 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14209 + seq_printf(seq, ",fhsm_sec=%u", u);
14211 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14212 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14213 +++ linux/fs/aufs/file.c 2018-10-23 12:33:35.596042364 +0200
14215 +// SPDX-License-Identifier: GPL-2.0
14217 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14219 + * This program, aufs is free software; you can redistribute it and/or modify
14220 + * it under the terms of the GNU General Public License as published by
14221 + * the Free Software Foundation; either version 2 of the License, or
14222 + * (at your option) any later version.
14224 + * This program is distributed in the hope that it will be useful,
14225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14227 + * GNU General Public License for more details.
14229 + * You should have received a copy of the GNU General Public License
14230 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14234 + * handling file/dir, and address_space operation
14237 +#ifdef CONFIG_AUFS_DEBUG
14238 +#include <linux/migrate.h>
14240 +#include <linux/pagemap.h>
14243 +/* drop flags for writing */
14244 +unsigned int au_file_roflags(unsigned int flags)
14246 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14247 + flags |= O_RDONLY | O_NOATIME;
14251 +/* common functions to regular file and dir */
14252 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14253 + struct file *file, int force_wr)
14255 + struct file *h_file;
14256 + struct dentry *h_dentry;
14257 + struct inode *h_inode;
14258 + struct super_block *sb;
14259 + struct au_branch *br;
14260 + struct path h_path;
14263 + /* a race condition can happen between open and unlink/rmdir */
14264 + h_file = ERR_PTR(-ENOENT);
14265 + h_dentry = au_h_dptr(dentry, bindex);
14266 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14268 + h_inode = d_inode(h_dentry);
14269 + spin_lock(&h_dentry->d_lock);
14270 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14271 + /* || !d_inode(dentry)->i_nlink */
14273 + spin_unlock(&h_dentry->d_lock);
14274 + if (unlikely(err))
14277 + sb = dentry->d_sb;
14278 + br = au_sbr(sb, bindex);
14279 + err = au_br_test_oflag(flags, br);
14280 + h_file = ERR_PTR(err);
14281 + if (unlikely(err))
14284 + /* drop flags for writing */
14285 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14286 + if (force_wr && !(flags & O_WRONLY))
14288 + flags = au_file_roflags(flags);
14290 + h_file = ERR_PTR(-EROFS);
14291 + flags = au_file_roflags(flags);
14292 + if (unlikely(vfsub_native_ro(h_inode)
14293 + || IS_APPEND(h_inode)))
14295 + flags &= ~O_ACCMODE;
14296 + flags |= O_WRONLY;
14299 + flags &= ~O_CREAT;
14300 + au_lcnt_inc(&br->br_nfiles);
14301 + h_path.dentry = h_dentry;
14302 + h_path.mnt = au_br_mnt(br);
14303 + h_file = vfsub_dentry_open(&h_path, flags);
14304 + if (IS_ERR(h_file))
14307 + if (flags & __FMODE_EXEC) {
14308 + err = deny_write_access(h_file);
14309 + if (unlikely(err)) {
14311 + h_file = ERR_PTR(err);
14315 + fsnotify_open(h_file);
14316 + goto out; /* success */
14319 + au_lcnt_dec(&br->br_nfiles);
14324 +static int au_cmoo(struct dentry *dentry)
14326 + int err, cmoo, matched;
14327 + unsigned int udba;
14328 + struct path h_path;
14329 + struct au_pin pin;
14330 + struct au_cp_generic cpg = {
14331 + .dentry = dentry,
14336 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14338 + struct inode *delegated;
14339 + struct super_block *sb;
14340 + struct au_sbinfo *sbinfo;
14341 + struct au_fhsm *fhsm;
14343 + struct au_branch *br;
14344 + struct dentry *parent;
14345 + struct au_hinode *hdir;
14347 + DiMustWriteLock(dentry);
14348 + IiMustWriteLock(d_inode(dentry));
14351 + if (IS_ROOT(dentry))
14353 + cpg.bsrc = au_dbtop(dentry);
14357 + sb = dentry->d_sb;
14358 + sbinfo = au_sbi(sb);
14359 + fhsm = &sbinfo->si_fhsm;
14360 + pid = au_fhsm_pid(fhsm);
14363 + && (current->pid == pid
14364 + || rcu_dereference(current->real_parent)->pid == pid));
14365 + rcu_read_unlock();
14369 + br = au_sbr(sb, cpg.bsrc);
14370 + cmoo = au_br_cmoo(br->br_perm);
14373 + if (!d_is_reg(dentry))
14374 + cmoo &= AuBrAttr_COO_ALL;
14378 + parent = dget_parent(dentry);
14379 + di_write_lock_parent(parent);
14380 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14382 + if (unlikely(err < 0)) {
14383 + err = 0; /* there is no upper writable branch */
14386 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14388 + /* do not respect the coo attrib for the target branch */
14389 + err = au_cpup_dirs(dentry, cpg.bdst);
14390 + if (unlikely(err))
14393 + di_downgrade_lock(parent, AuLock_IR);
14394 + udba = au_opt_udba(sb);
14395 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14396 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14397 + if (unlikely(err))
14400 + err = au_sio_cpup_simple(&cpg);
14402 + if (unlikely(err))
14404 + if (!(cmoo & AuBrWAttr_MOO))
14405 + goto out_parent; /* success */
14407 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14408 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14409 + if (unlikely(err))
14412 + h_path.mnt = au_br_mnt(br);
14413 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14414 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14415 + delegated = NULL;
14416 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14418 + /* todo: keep h_dentry or not? */
14419 + if (unlikely(err == -EWOULDBLOCK)) {
14420 + pr_warn("cannot retry for NFSv4 delegation"
14421 + " for an internal unlink\n");
14424 + if (unlikely(err)) {
14425 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14429 + goto out_parent; /* success */
14432 + di_downgrade_lock(parent, AuLock_IR);
14434 + di_read_unlock(parent, AuLock_IR);
14441 +int au_do_open(struct file *file, struct au_do_open_args *args)
14443 + int err, aopen = args->aopen;
14444 + struct dentry *dentry;
14445 + struct au_finfo *finfo;
14448 + err = au_finfo_init(file, args->fidir);
14451 + err = au_finfo_init(file, args->fidir);
14454 + if (unlikely(err))
14457 + dentry = file->f_path.dentry;
14458 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14459 + di_write_lock_child(dentry);
14460 + err = au_cmoo(dentry);
14461 + di_downgrade_lock(dentry, AuLock_IR);
14464 + err = args->open(file, vfsub_file_flags(file), NULL);
14467 + err = args->open(file, vfsub_file_flags(file),
14472 + di_read_unlock(dentry, AuLock_IR);
14474 + finfo = au_fi(file);
14476 + finfo->fi_file = file;
14477 + au_hbl_add(&finfo->fi_hlist,
14478 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14481 + fi_write_unlock(file);
14484 + fi_write_unlock(file);
14487 + if (unlikely(err)) {
14488 + finfo->fi_hdir = NULL;
14489 + au_finfo_fin(file);
14497 +int au_reopen_nondir(struct file *file)
14500 + aufs_bindex_t btop;
14501 + struct dentry *dentry;
14502 + struct au_branch *br;
14503 + struct file *h_file, *h_file_tmp;
14505 + dentry = file->f_path.dentry;
14506 + btop = au_dbtop(dentry);
14507 + br = au_sbr(dentry->d_sb, btop);
14508 + h_file_tmp = NULL;
14509 + if (au_fbtop(file) == btop) {
14510 + h_file = au_hf_top(file);
14511 + if (file->f_mode == h_file->f_mode)
14512 + return 0; /* success */
14513 + h_file_tmp = h_file;
14514 + get_file(h_file_tmp);
14515 + au_lcnt_inc(&br->br_nfiles);
14516 + au_set_h_fptr(file, btop, NULL);
14518 + AuDebugOn(au_fi(file)->fi_hdir);
14521 + * file exists on both of rw and ro
14522 + * open --> dbtop and fbtop are both 0
14523 + * prepend a branch as rw, "rw" become ro
14525 + * delete the top branch, "rw" becomes rw again
14526 + * --> dbtop is 1, fbtop is still 0
14527 + * write --> fbtop is 0 but dbtop is 1
14529 + /* AuDebugOn(au_fbtop(file) < btop); */
14531 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14532 + file, /*force_wr*/0);
14533 + err = PTR_ERR(h_file);
14534 + if (IS_ERR(h_file)) {
14535 + if (h_file_tmp) {
14537 + au_set_h_fptr(file, btop, h_file_tmp);
14538 + h_file_tmp = NULL;
14540 + goto out; /* todo: close all? */
14544 + au_set_fbtop(file, btop);
14545 + au_set_h_fptr(file, btop, h_file);
14546 + au_update_figen(file);
14547 + /* todo: necessary? */
14548 + /* file->f_ra = h_file->f_ra; */
14551 + if (h_file_tmp) {
14552 + fput(h_file_tmp);
14553 + au_lcnt_dec(&br->br_nfiles);
14558 +/* ---------------------------------------------------------------------- */
14560 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14561 + struct dentry *hi_wh)
14564 + aufs_bindex_t btop;
14565 + struct au_dinfo *dinfo;
14566 + struct dentry *h_dentry;
14567 + struct au_hdentry *hdp;
14569 + dinfo = au_di(file->f_path.dentry);
14570 + AuRwMustWriteLock(&dinfo->di_rwsem);
14572 + btop = dinfo->di_btop;
14573 + dinfo->di_btop = btgt;
14574 + hdp = au_hdentry(dinfo, btgt);
14575 + h_dentry = hdp->hd_dentry;
14576 + hdp->hd_dentry = hi_wh;
14577 + err = au_reopen_nondir(file);
14578 + hdp->hd_dentry = h_dentry;
14579 + dinfo->di_btop = btop;
14584 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14585 + aufs_bindex_t bcpup, struct au_pin *pin)
14588 + struct inode *inode, *h_inode;
14589 + struct dentry *h_dentry, *hi_wh;
14590 + struct au_cp_generic cpg = {
14591 + .dentry = file->f_path.dentry,
14598 + au_update_dbtop(cpg.dentry);
14599 + inode = d_inode(cpg.dentry);
14601 + if (au_dbtop(cpg.dentry) <= bcpup
14602 + && au_dbbot(cpg.dentry) >= bcpup) {
14603 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14604 + if (h_dentry && d_is_positive(h_dentry))
14605 + h_inode = d_inode(h_dentry);
14607 + hi_wh = au_hi_wh(inode, bcpup);
14608 + if (!hi_wh && !h_inode)
14609 + err = au_sio_cpup_wh(&cpg, file);
14611 + /* already copied-up after unlink */
14612 + err = au_reopen_wh(file, bcpup, hi_wh);
14615 + && (inode->i_nlink > 1
14616 + || (inode->i_state & I_LINKABLE))
14617 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14618 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14624 + * prepare the @file for writing.
14626 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14629 + aufs_bindex_t dbtop;
14630 + struct dentry *parent;
14631 + struct inode *inode;
14632 + struct super_block *sb;
14633 + struct file *h_file;
14634 + struct au_cp_generic cpg = {
14635 + .dentry = file->f_path.dentry,
14640 + .flags = AuCpup_DTIME
14643 + sb = cpg.dentry->d_sb;
14644 + inode = d_inode(cpg.dentry);
14645 + cpg.bsrc = au_fbtop(file);
14646 + err = au_test_ro(sb, cpg.bsrc, inode);
14647 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14648 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14653 + /* need to cpup or reopen */
14654 + parent = dget_parent(cpg.dentry);
14655 + di_write_lock_parent(parent);
14656 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14658 + if (unlikely(err < 0))
14662 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14663 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14664 + if (unlikely(err))
14668 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14669 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14670 + if (unlikely(err))
14673 + dbtop = au_dbtop(cpg.dentry);
14674 + if (dbtop <= cpg.bdst)
14675 + cpg.bsrc = cpg.bdst;
14677 + if (dbtop <= cpg.bdst /* just reopen */
14678 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14680 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14681 + if (IS_ERR(h_file))
14682 + err = PTR_ERR(h_file);
14684 + di_downgrade_lock(parent, AuLock_IR);
14685 + if (dbtop > cpg.bdst)
14686 + err = au_sio_cpup_simple(&cpg);
14688 + err = au_reopen_nondir(file);
14689 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14691 + } else { /* copyup as wh and reopen */
14693 + * since writable hfsplus branch is not supported,
14694 + * h_open_pre/post() are unnecessary.
14696 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14697 + di_downgrade_lock(parent, AuLock_IR);
14701 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14702 + goto out_dput; /* success */
14708 + di_downgrade_lock(parent, AuLock_IR);
14710 + di_read_unlock(parent, AuLock_IR);
14717 +/* ---------------------------------------------------------------------- */
14719 +int au_do_flush(struct file *file, fl_owner_t id,
14720 + int (*flush)(struct file *file, fl_owner_t id))
14723 + struct super_block *sb;
14724 + struct inode *inode;
14726 + inode = file_inode(file);
14727 + sb = inode->i_sb;
14728 + si_noflush_read_lock(sb);
14729 + fi_read_lock(file);
14730 + ii_read_lock_child(inode);
14732 + err = flush(file, id);
14733 + au_cpup_attr_timesizes(inode);
14735 + ii_read_unlock(inode);
14736 + fi_read_unlock(file);
14737 + si_read_unlock(sb);
14741 +/* ---------------------------------------------------------------------- */
14743 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14746 + struct au_pin pin;
14747 + struct au_finfo *finfo;
14748 + struct dentry *parent, *hi_wh;
14749 + struct inode *inode;
14750 + struct super_block *sb;
14751 + struct au_cp_generic cpg = {
14752 + .dentry = file->f_path.dentry,
14757 + .flags = AuCpup_DTIME
14760 + FiMustWriteLock(file);
14763 + finfo = au_fi(file);
14764 + sb = cpg.dentry->d_sb;
14765 + inode = d_inode(cpg.dentry);
14766 + cpg.bdst = au_ibtop(inode);
14767 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14770 + parent = dget_parent(cpg.dentry);
14771 + if (au_test_ro(sb, cpg.bdst, inode)) {
14772 + di_read_lock_parent(parent, !AuLock_IR);
14773 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14775 + di_read_unlock(parent, !AuLock_IR);
14776 + if (unlikely(err < 0))
14781 + di_read_lock_parent(parent, AuLock_IR);
14782 + hi_wh = au_hi_wh(inode, cpg.bdst);
14783 + if (!S_ISDIR(inode->i_mode)
14784 + && au_opt_test(au_mntflags(sb), PLINK)
14785 + && au_plink_test(inode)
14786 + && !d_unhashed(cpg.dentry)
14787 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14788 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14789 + if (unlikely(err))
14792 + /* always superio. */
14793 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14794 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14796 + err = au_sio_cpup_simple(&cpg);
14799 + } else if (hi_wh) {
14800 + /* already copied-up after unlink */
14801 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14802 + *need_reopen = 0;
14806 + di_read_unlock(parent, AuLock_IR);
14813 +static void au_do_refresh_dir(struct file *file)
14815 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14816 + struct au_hfile *p, tmp, *q;
14817 + struct au_finfo *finfo;
14818 + struct super_block *sb;
14819 + struct au_fidir *fidir;
14821 + FiMustWriteLock(file);
14823 + sb = file->f_path.dentry->d_sb;
14824 + finfo = au_fi(file);
14825 + fidir = finfo->fi_hdir;
14826 + AuDebugOn(!fidir);
14827 + p = fidir->fd_hfile + finfo->fi_btop;
14828 + brid = p->hf_br->br_id;
14829 + bbot = fidir->fd_bbot;
14830 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14834 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14835 + if (new_bindex == bindex)
14837 + if (new_bindex < 0) {
14838 + au_set_h_fptr(file, bindex, NULL);
14842 + /* swap two lower inode, and loop again */
14843 + q = fidir->fd_hfile + new_bindex;
14847 + if (tmp.hf_file) {
14853 + p = fidir->fd_hfile;
14854 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14855 + bbot = au_sbbot(sb);
14856 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14857 + finfo->fi_btop++, p++)
14858 + if (p->hf_file) {
14859 + if (file_inode(p->hf_file))
14861 + au_hfput(p, /*execed*/0);
14864 + bbot = au_br_index(sb, brid);
14865 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14866 + finfo->fi_btop++, p++)
14868 + au_hfput(p, /*execed*/0);
14869 + bbot = au_sbbot(sb);
14872 + p = fidir->fd_hfile + bbot;
14873 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14874 + fidir->fd_bbot--, p--)
14875 + if (p->hf_file) {
14876 + if (file_inode(p->hf_file))
14878 + au_hfput(p, /*execed*/0);
14880 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14884 + * after branch manipulating, refresh the file.
14886 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14888 + int err, need_reopen, nbr;
14889 + aufs_bindex_t bbot, bindex;
14890 + struct dentry *dentry;
14891 + struct super_block *sb;
14892 + struct au_finfo *finfo;
14893 + struct au_hfile *hfile;
14895 + dentry = file->f_path.dentry;
14896 + sb = dentry->d_sb;
14897 + nbr = au_sbbot(sb) + 1;
14898 + finfo = au_fi(file);
14899 + if (!finfo->fi_hdir) {
14900 + hfile = &finfo->fi_htop;
14901 + AuDebugOn(!hfile->hf_file);
14902 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14903 + AuDebugOn(bindex < 0);
14904 + if (bindex != finfo->fi_btop)
14905 + au_set_fbtop(file, bindex);
14907 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14908 + if (unlikely(err))
14910 + au_do_refresh_dir(file);
14915 + if (!au_test_mmapped(file))
14916 + err = au_file_refresh_by_inode(file, &need_reopen);
14917 + if (finfo->fi_hdir)
14918 + /* harmless if err */
14919 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14920 + if (!err && need_reopen && !d_unlinked(dentry))
14921 + err = reopen(file);
14923 + au_update_figen(file);
14924 + goto out; /* success */
14927 + /* error, close all lower files */
14928 + if (finfo->fi_hdir) {
14929 + bbot = au_fbbot_dir(file);
14930 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14931 + au_set_h_fptr(file, bindex, NULL);
14938 +/* common function to regular file and dir */
14939 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14940 + int wlock, unsigned int fi_lsc)
14943 + unsigned int sigen, figen;
14944 + aufs_bindex_t btop;
14945 + unsigned char pseudo_link;
14946 + struct dentry *dentry;
14947 + struct inode *inode;
14950 + dentry = file->f_path.dentry;
14951 + inode = d_inode(dentry);
14952 + sigen = au_sigen(dentry->d_sb);
14953 + fi_write_lock_nested(file, fi_lsc);
14954 + figen = au_figen(file);
14956 + di_write_lock_child(dentry);
14958 + di_write_lock_child2(dentry);
14959 + btop = au_dbtop(dentry);
14960 + pseudo_link = (btop != au_ibtop(inode));
14961 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14963 + di_downgrade_lock(dentry, AuLock_IR);
14964 + fi_downgrade_lock(file);
14966 + goto out; /* success */
14969 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14970 + if (au_digen_test(dentry, sigen)) {
14971 + err = au_reval_dpath(dentry, sigen);
14972 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14976 + err = refresh_file(file, reopen);
14979 + di_downgrade_lock(dentry, AuLock_IR);
14980 + fi_downgrade_lock(file);
14983 + di_write_unlock(dentry);
14984 + fi_write_unlock(file);
14991 +/* ---------------------------------------------------------------------- */
14993 +/* cf. aufs_nopage() */
14994 +/* for madvise(2) */
14995 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14997 + unlock_page(page);
15001 +/* it will never be called, but necessary to support O_DIRECT */
15002 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
15003 +{ BUG(); return 0; }
15005 +/* they will never be called. */
15006 +#ifdef CONFIG_AUFS_DEBUG
15007 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
15008 + loff_t pos, unsigned len, unsigned flags,
15009 + struct page **pagep, void **fsdata)
15010 +{ AuUnsupport(); return 0; }
15011 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15012 + loff_t pos, unsigned len, unsigned copied,
15013 + struct page *page, void *fsdata)
15014 +{ AuUnsupport(); return 0; }
15015 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15016 +{ AuUnsupport(); return 0; }
15018 +static int aufs_set_page_dirty(struct page *page)
15019 +{ AuUnsupport(); return 0; }
15020 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15021 + unsigned int length)
15022 +{ AuUnsupport(); }
15023 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15024 +{ AuUnsupport(); return 0; }
15025 +#if 0 /* called by memory compaction regardless file */
15026 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15027 + struct page *page, enum migrate_mode mode)
15028 +{ AuUnsupport(); return 0; }
15030 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15031 +{ AuUnsupport(); return true; }
15032 +static void aufs_putback_page(struct page *page)
15033 +{ AuUnsupport(); }
15034 +static int aufs_launder_page(struct page *page)
15035 +{ AuUnsupport(); return 0; }
15036 +static int aufs_is_partially_uptodate(struct page *page,
15037 + unsigned long from,
15038 + unsigned long count)
15039 +{ AuUnsupport(); return 0; }
15040 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15042 +{ AuUnsupport(); }
15043 +static int aufs_error_remove_page(struct address_space *mapping,
15044 + struct page *page)
15045 +{ AuUnsupport(); return 0; }
15046 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15048 +{ AuUnsupport(); return 0; }
15049 +static void aufs_swap_deactivate(struct file *file)
15050 +{ AuUnsupport(); }
15051 +#endif /* CONFIG_AUFS_DEBUG */
15053 +const struct address_space_operations aufs_aop = {
15054 + .readpage = aufs_readpage,
15055 + .direct_IO = aufs_direct_IO,
15056 +#ifdef CONFIG_AUFS_DEBUG
15057 + .writepage = aufs_writepage,
15058 + /* no writepages, because of writepage */
15059 + .set_page_dirty = aufs_set_page_dirty,
15060 + /* no readpages, because of readpage */
15061 + .write_begin = aufs_write_begin,
15062 + .write_end = aufs_write_end,
15063 + /* no bmap, no block device */
15064 + .invalidatepage = aufs_invalidatepage,
15065 + .releasepage = aufs_releasepage,
15066 + /* is fallback_migrate_page ok? */
15067 + /* .migratepage = aufs_migratepage, */
15068 + .isolate_page = aufs_isolate_page,
15069 + .putback_page = aufs_putback_page,
15070 + .launder_page = aufs_launder_page,
15071 + .is_partially_uptodate = aufs_is_partially_uptodate,
15072 + .is_dirty_writeback = aufs_is_dirty_writeback,
15073 + .error_remove_page = aufs_error_remove_page,
15074 + .swap_activate = aufs_swap_activate,
15075 + .swap_deactivate = aufs_swap_deactivate
15076 +#endif /* CONFIG_AUFS_DEBUG */
15078 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15079 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15080 +++ linux/fs/aufs/file.h 2018-08-12 23:43:05.456791299 +0200
15082 +/* SPDX-License-Identifier: GPL-2.0 */
15084 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15086 + * This program, aufs is free software; you can redistribute it and/or modify
15087 + * it under the terms of the GNU General Public License as published by
15088 + * the Free Software Foundation; either version 2 of the License, or
15089 + * (at your option) any later version.
15091 + * This program is distributed in the hope that it will be useful,
15092 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15093 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15094 + * GNU General Public License for more details.
15096 + * You should have received a copy of the GNU General Public License
15097 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15101 + * file operations
15104 +#ifndef __AUFS_FILE_H__
15105 +#define __AUFS_FILE_H__
15109 +#include <linux/file.h>
15110 +#include <linux/fs.h>
15111 +#include <linux/mm_types.h>
15112 +#include <linux/poll.h>
15113 +#include "rwsem.h"
15117 + struct file *hf_file;
15118 + struct au_branch *hf_br;
15123 + aufs_bindex_t fd_bbot;
15124 + aufs_bindex_t fd_nent;
15125 + struct au_vdir *fd_vdir_cache;
15126 + struct au_hfile fd_hfile[];
15129 +static inline int au_fidir_sz(int nent)
15131 + AuDebugOn(nent < 0);
15132 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15136 + atomic_t fi_generation;
15138 + struct au_rwsem fi_rwsem;
15139 + aufs_bindex_t fi_btop;
15141 + /* do not union them */
15142 + struct { /* for non-dir */
15143 + struct au_hfile fi_htop;
15144 + atomic_t fi_mmapped;
15146 + struct au_fidir *fi_hdir; /* for dir only */
15148 + struct hlist_bl_node fi_hlist;
15149 + struct file *fi_file; /* very ugly */
15150 +} ____cacheline_aligned_in_smp;
15152 +/* ---------------------------------------------------------------------- */
15155 +extern const struct address_space_operations aufs_aop;
15156 +unsigned int au_file_roflags(unsigned int flags);
15157 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15158 + struct file *file, int force_wr);
15159 +struct au_do_open_args {
15161 + int (*open)(struct file *file, int flags,
15162 + struct file *h_file);
15163 + struct au_fidir *fidir;
15164 + struct file *h_file;
15166 +int au_do_open(struct file *file, struct au_do_open_args *args);
15167 +int au_reopen_nondir(struct file *file);
15169 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15170 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15171 + int wlock, unsigned int fi_lsc);
15172 +int au_do_flush(struct file *file, fl_owner_t id,
15173 + int (*flush)(struct file *file, fl_owner_t id));
15176 +#ifdef CONFIG_AUFS_POLL
15177 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15180 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15182 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15184 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15185 + struct file *h_file);
15187 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15188 + aufs_bindex_t bindex, int force_wr)
15189 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15190 + struct file *h_file);
15194 +extern const struct file_operations aufs_file_fop;
15195 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15196 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15197 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15200 +void au_hfput(struct au_hfile *hf, int execed);
15201 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15202 + struct file *h_file);
15204 +void au_update_figen(struct file *file);
15205 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15206 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15208 +void au_fi_init_once(void *_fi);
15209 +void au_finfo_fin(struct file *file);
15210 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15213 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15214 +#ifdef CONFIG_COMPAT
15215 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15216 + unsigned long arg);
15217 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15218 + unsigned long arg);
15221 +/* ---------------------------------------------------------------------- */
15223 +static inline struct au_finfo *au_fi(struct file *file)
15225 + return file->private_data;
15228 +/* ---------------------------------------------------------------------- */
15230 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15231 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15232 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15233 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15235 +#define fi_read_trylock_nested(f) \
15236 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15237 +#define fi_write_trylock_nested(f) \
15238 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15241 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15242 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15243 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15245 +/* lock subclass for finfo */
15251 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15253 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15256 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15258 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15262 + * fi_read_lock_1, fi_write_lock_1,
15263 + * fi_read_lock_2, fi_write_lock_2
15265 +#define AuReadLockFunc(name) \
15266 +static inline void fi_read_lock_##name(struct file *f) \
15267 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15269 +#define AuWriteLockFunc(name) \
15270 +static inline void fi_write_lock_##name(struct file *f) \
15271 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15273 +#define AuRWLockFuncs(name) \
15274 + AuReadLockFunc(name) \
15275 + AuWriteLockFunc(name)
15280 +#undef AuReadLockFunc
15281 +#undef AuWriteLockFunc
15282 +#undef AuRWLockFuncs
15284 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15285 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15286 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15288 +/* ---------------------------------------------------------------------- */
15290 +/* todo: hard/soft set? */
15291 +static inline aufs_bindex_t au_fbtop(struct file *file)
15293 + FiMustAnyLock(file);
15294 + return au_fi(file)->fi_btop;
15297 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15299 + FiMustAnyLock(file);
15300 + AuDebugOn(!au_fi(file)->fi_hdir);
15301 + return au_fi(file)->fi_hdir->fd_bbot;
15304 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15306 + FiMustAnyLock(file);
15307 + AuDebugOn(!au_fi(file)->fi_hdir);
15308 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15311 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15313 + FiMustWriteLock(file);
15314 + au_fi(file)->fi_btop = bindex;
15317 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15319 + FiMustWriteLock(file);
15320 + AuDebugOn(!au_fi(file)->fi_hdir);
15321 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15324 +static inline void au_set_fvdir_cache(struct file *file,
15325 + struct au_vdir *vdir_cache)
15327 + FiMustWriteLock(file);
15328 + AuDebugOn(!au_fi(file)->fi_hdir);
15329 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15332 +static inline struct file *au_hf_top(struct file *file)
15334 + FiMustAnyLock(file);
15335 + AuDebugOn(au_fi(file)->fi_hdir);
15336 + return au_fi(file)->fi_htop.hf_file;
15339 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15341 + FiMustAnyLock(file);
15342 + AuDebugOn(!au_fi(file)->fi_hdir);
15343 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15346 +/* todo: memory barrier? */
15347 +static inline unsigned int au_figen(struct file *f)
15349 + return atomic_read(&au_fi(f)->fi_generation);
15352 +static inline void au_set_mmapped(struct file *f)
15354 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15356 + pr_warn("fi_mmapped wrapped around\n");
15357 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15361 +static inline void au_unset_mmapped(struct file *f)
15363 + atomic_dec(&au_fi(f)->fi_mmapped);
15366 +static inline int au_test_mmapped(struct file *f)
15368 + return atomic_read(&au_fi(f)->fi_mmapped);
15371 +/* customize vma->vm_file */
15373 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15374 + struct file *file)
15378 + f = vma->vm_file;
15380 + vma->vm_file = file;
15385 +#define AuDbgVmRegion(file, vma) do {} while (0)
15387 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15388 + struct file *file)
15390 + au_do_vm_file_reset(vma, file);
15393 +#define AuDbgVmRegion(file, vma) \
15394 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15396 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15397 + struct file *file)
15401 + au_do_vm_file_reset(vma, file);
15402 + f = vma->vm_region->vm_file;
15404 + vma->vm_region->vm_file = file;
15407 +#endif /* CONFIG_MMU */
15409 +/* handle vma->vm_prfile */
15410 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15411 + struct file *file)
15414 + vma->vm_prfile = file;
15415 +#ifndef CONFIG_MMU
15417 + vma->vm_region->vm_prfile = file;
15421 +#endif /* __KERNEL__ */
15422 +#endif /* __AUFS_FILE_H__ */
15423 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15424 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15425 +++ linux/fs/aufs/finfo.c 2018-10-23 12:33:35.596042364 +0200
15427 +// SPDX-License-Identifier: GPL-2.0
15429 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15431 + * This program, aufs is free software; you can redistribute it and/or modify
15432 + * it under the terms of the GNU General Public License as published by
15433 + * the Free Software Foundation; either version 2 of the License, or
15434 + * (at your option) any later version.
15436 + * This program is distributed in the hope that it will be useful,
15437 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15438 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15439 + * GNU General Public License for more details.
15441 + * You should have received a copy of the GNU General Public License
15442 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15446 + * file private data
15451 +void au_hfput(struct au_hfile *hf, int execed)
15454 + allow_write_access(hf->hf_file);
15455 + fput(hf->hf_file);
15456 + hf->hf_file = NULL;
15457 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15458 + hf->hf_br = NULL;
15461 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15463 + struct au_finfo *finfo = au_fi(file);
15464 + struct au_hfile *hf;
15465 + struct au_fidir *fidir;
15467 + fidir = finfo->fi_hdir;
15469 + AuDebugOn(finfo->fi_btop != bindex);
15470 + hf = &finfo->fi_htop;
15472 + hf = fidir->fd_hfile + bindex;
15474 + if (hf && hf->hf_file)
15475 + au_hfput(hf, vfsub_file_execed(file));
15477 + FiMustWriteLock(file);
15478 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15479 + hf->hf_file = val;
15480 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15484 +void au_update_figen(struct file *file)
15486 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15487 + /* smp_mb(); */ /* atomic_set */
15490 +/* ---------------------------------------------------------------------- */
15492 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15494 + struct au_fidir *fidir;
15497 + nbr = au_sbbot(sb) + 1;
15499 + nbr = 2; /* initial allocate for 2 branches */
15500 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15502 + fidir->fd_bbot = -1;
15503 + fidir->fd_nent = nbr;
15509 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15512 + struct au_fidir *fidir, *p;
15514 + AuRwMustWriteLock(&finfo->fi_rwsem);
15515 + fidir = finfo->fi_hdir;
15516 + AuDebugOn(!fidir);
15519 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15520 + GFP_NOFS, may_shrink);
15522 + p->fd_nent = nbr;
15523 + finfo->fi_hdir = p;
15530 +/* ---------------------------------------------------------------------- */
15532 +void au_finfo_fin(struct file *file)
15534 + struct au_finfo *finfo;
15536 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15538 + finfo = au_fi(file);
15539 + AuDebugOn(finfo->fi_hdir);
15540 + AuRwDestroy(&finfo->fi_rwsem);
15541 + au_cache_free_finfo(finfo);
15544 +void au_fi_init_once(void *_finfo)
15546 + struct au_finfo *finfo = _finfo;
15548 + au_rw_init(&finfo->fi_rwsem);
15551 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15554 + struct au_finfo *finfo;
15555 + struct dentry *dentry;
15558 + dentry = file->f_path.dentry;
15559 + finfo = au_cache_alloc_finfo();
15560 + if (unlikely(!finfo))
15564 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15565 + au_rw_write_lock(&finfo->fi_rwsem);
15566 + finfo->fi_btop = -1;
15567 + finfo->fi_hdir = fidir;
15568 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15569 + /* smp_mb(); */ /* atomic_set */
15571 + file->private_data = finfo;
15576 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15577 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15578 +++ linux/fs/aufs/f_op.c 2018-10-23 12:33:35.596042364 +0200
15580 +// SPDX-License-Identifier: GPL-2.0
15582 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15584 + * This program, aufs is free software; you can redistribute it and/or modify
15585 + * it under the terms of the GNU General Public License as published by
15586 + * the Free Software Foundation; either version 2 of the License, or
15587 + * (at your option) any later version.
15589 + * This program is distributed in the hope that it will be useful,
15590 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15591 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15592 + * GNU General Public License for more details.
15594 + * You should have received a copy of the GNU General Public License
15595 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15599 + * file and vm operations
15602 +#include <linux/aio.h>
15603 +#include <linux/fs_stack.h>
15604 +#include <linux/mman.h>
15605 +#include <linux/security.h>
15608 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15611 + aufs_bindex_t bindex;
15612 + struct dentry *dentry, *h_dentry;
15613 + struct au_finfo *finfo;
15614 + struct inode *h_inode;
15616 + FiMustWriteLock(file);
15619 + dentry = file->f_path.dentry;
15620 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15621 + finfo = au_fi(file);
15622 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15623 + atomic_set(&finfo->fi_mmapped, 0);
15624 + bindex = au_dbtop(dentry);
15626 + h_dentry = au_h_dptr(dentry, bindex);
15627 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15628 + if (unlikely(err))
15630 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15631 + if (IS_ERR(h_file)) {
15632 + err = PTR_ERR(h_file);
15636 + h_dentry = h_file->f_path.dentry;
15637 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15638 + if (unlikely(err))
15640 + /* br ref is already inc-ed */
15643 + if ((flags & __O_TMPFILE)
15644 + && !(flags & O_EXCL)) {
15645 + h_inode = file_inode(h_file);
15646 + spin_lock(&h_inode->i_lock);
15647 + h_inode->i_state |= I_LINKABLE;
15648 + spin_unlock(&h_inode->i_lock);
15650 + au_set_fbtop(file, bindex);
15651 + au_set_h_fptr(file, bindex, h_file);
15652 + au_update_figen(file);
15653 + /* todo: necessary? */
15654 + /* file->f_ra = h_file->f_ra; */
15660 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15661 + struct file *file)
15664 + struct super_block *sb;
15665 + struct au_do_open_args args = {
15666 + .open = au_do_open_nondir
15669 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15670 + file, vfsub_file_flags(file), file->f_mode);
15672 + sb = file->f_path.dentry->d_sb;
15673 + si_read_lock(sb, AuLock_FLUSH);
15674 + err = au_do_open(file, &args);
15675 + si_read_unlock(sb);
15679 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15681 + struct au_finfo *finfo;
15682 + aufs_bindex_t bindex;
15684 + finfo = au_fi(file);
15685 + au_hbl_del(&finfo->fi_hlist,
15686 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15687 + bindex = finfo->fi_btop;
15689 + au_set_h_fptr(file, bindex, NULL);
15691 + au_finfo_fin(file);
15695 +/* ---------------------------------------------------------------------- */
15697 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15700 + struct file *h_file;
15703 + h_file = au_hf_top(file);
15705 + err = vfsub_flush(h_file, id);
15709 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15711 + return au_do_flush(file, id, au_do_flush_nondir);
15714 +/* ---------------------------------------------------------------------- */
15716 + * read and write functions acquire [fdi]_rwsem once, but release before
15717 + * mmap_sem. This is because to stop a race condition between mmap(2).
15718 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15719 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15720 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15723 +/* Callers should call au_read_post() or fput() in the end */
15724 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15726 + struct file *h_file;
15729 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15731 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15732 + h_file = au_hf_top(file);
15733 + get_file(h_file);
15735 + fi_read_unlock(file);
15737 + h_file = ERR_PTR(err);
15742 +static void au_read_post(struct inode *inode, struct file *h_file)
15744 + /* update without lock, I don't think it a problem */
15745 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15749 +struct au_write_pre {
15751 + unsigned int lsc;
15755 + aufs_bindex_t btop;
15759 + * return with iinfo is write-locked
15760 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15763 +static struct file *au_write_pre(struct file *file, int do_ready,
15764 + struct au_write_pre *wpre)
15766 + struct file *h_file;
15767 + struct dentry *dentry;
15769 + unsigned int lsc;
15770 + struct au_pin pin;
15775 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15776 + h_file = ERR_PTR(err);
15777 + if (unlikely(err))
15780 + dentry = file->f_path.dentry;
15782 + err = au_ready_to_write(file, -1, &pin);
15783 + if (unlikely(err)) {
15784 + h_file = ERR_PTR(err);
15785 + di_write_unlock(dentry);
15790 + di_downgrade_lock(dentry, /*flags*/0);
15792 + wpre->btop = au_fbtop(file);
15793 + h_file = au_hf_top(file);
15794 + get_file(h_file);
15796 + wpre->blks = file_inode(h_file)->i_blocks;
15799 + di_read_unlock(dentry, /*flags*/0);
15802 + fi_write_unlock(file);
15807 +static void au_write_post(struct inode *inode, struct file *h_file,
15808 + struct au_write_pre *wpre, ssize_t written)
15810 + struct inode *h_inode;
15812 + au_cpup_attr_timesizes(inode);
15813 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15814 + h_inode = file_inode(h_file);
15815 + inode->i_mode = h_inode->i_mode;
15816 + ii_write_unlock(inode);
15817 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15819 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15820 + /*force*/h_inode->i_blocks > wpre->blks);
15824 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15828 + struct inode *inode;
15829 + struct file *h_file;
15830 + struct super_block *sb;
15832 + inode = file_inode(file);
15833 + sb = inode->i_sb;
15834 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15836 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15837 + err = PTR_ERR(h_file);
15838 + if (IS_ERR(h_file))
15841 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15842 + err = vfsub_read_u(h_file, buf, count, ppos);
15843 + /* todo: necessary? */
15844 + /* file->f_ra = h_file->f_ra; */
15845 + au_read_post(inode, h_file);
15848 + si_read_unlock(sb);
15853 + * todo: very ugly
15854 + * it locks both of i_mutex and si_rwsem for read in safe.
15855 + * if the plink maintenance mode continues forever (that is the problem),
15856 + * may loop forever.
15858 +static void au_mtx_and_read_lock(struct inode *inode)
15861 + struct super_block *sb = inode->i_sb;
15864 + inode_lock(inode);
15865 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15868 + inode_unlock(inode);
15869 + si_read_lock(sb, AuLock_NOPLMW);
15870 + si_read_unlock(sb);
15874 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15875 + size_t count, loff_t *ppos)
15878 + struct au_write_pre wpre;
15879 + struct inode *inode;
15880 + struct file *h_file;
15881 + char __user *buf = (char __user *)ubuf;
15883 + inode = file_inode(file);
15884 + au_mtx_and_read_lock(inode);
15887 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15888 + err = PTR_ERR(h_file);
15889 + if (IS_ERR(h_file))
15892 + err = vfsub_write_u(h_file, buf, count, ppos);
15893 + au_write_post(inode, h_file, &wpre, err);
15896 + si_read_unlock(inode->i_sb);
15897 + inode_unlock(inode);
15901 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15902 + struct iov_iter *iov_iter)
15905 + struct file *file;
15906 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15908 + err = security_file_permission(h_file, rw);
15909 + if (unlikely(err))
15914 + if (rw == MAY_READ)
15915 + iter = h_file->f_op->read_iter;
15916 + else if (rw == MAY_WRITE)
15917 + iter = h_file->f_op->write_iter;
15919 + file = kio->ki_filp;
15920 + kio->ki_filp = h_file;
15923 + err = iter(kio, iov_iter);
15926 + /* currently there is no such fs */
15928 + kio->ki_filp = file;
15934 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15937 + struct file *file, *h_file;
15938 + struct inode *inode;
15939 + struct super_block *sb;
15941 + file = kio->ki_filp;
15942 + inode = file_inode(file);
15943 + sb = inode->i_sb;
15944 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15946 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15947 + err = PTR_ERR(h_file);
15948 + if (IS_ERR(h_file))
15951 + if (au_test_loopback_kthread()) {
15952 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15953 + if (file->f_mapping != h_file->f_mapping) {
15954 + file->f_mapping = h_file->f_mapping;
15955 + smp_mb(); /* unnecessary? */
15958 + fi_read_unlock(file);
15960 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15961 + /* todo: necessary? */
15962 + /* file->f_ra = h_file->f_ra; */
15963 + au_read_post(inode, h_file);
15966 + si_read_unlock(sb);
15970 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15973 + struct au_write_pre wpre;
15974 + struct inode *inode;
15975 + struct file *file, *h_file;
15977 + file = kio->ki_filp;
15978 + inode = file_inode(file);
15979 + au_mtx_and_read_lock(inode);
15982 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15983 + err = PTR_ERR(h_file);
15984 + if (IS_ERR(h_file))
15987 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15988 + au_write_post(inode, h_file, &wpre, err);
15991 + si_read_unlock(inode->i_sb);
15992 + inode_unlock(inode);
15996 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15997 + struct pipe_inode_info *pipe, size_t len,
15998 + unsigned int flags)
16001 + struct file *h_file;
16002 + struct inode *inode;
16003 + struct super_block *sb;
16005 + inode = file_inode(file);
16006 + sb = inode->i_sb;
16007 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16009 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16010 + err = PTR_ERR(h_file);
16011 + if (IS_ERR(h_file))
16014 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16015 + /* todo: necessary? */
16016 + /* file->f_ra = h_file->f_ra; */
16017 + au_read_post(inode, h_file);
16020 + si_read_unlock(sb);
16025 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16026 + size_t len, unsigned int flags)
16029 + struct au_write_pre wpre;
16030 + struct inode *inode;
16031 + struct file *h_file;
16033 + inode = file_inode(file);
16034 + au_mtx_and_read_lock(inode);
16037 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16038 + err = PTR_ERR(h_file);
16039 + if (IS_ERR(h_file))
16042 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16043 + au_write_post(inode, h_file, &wpre, err);
16046 + si_read_unlock(inode->i_sb);
16047 + inode_unlock(inode);
16051 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16055 + struct au_write_pre wpre;
16056 + struct inode *inode;
16057 + struct file *h_file;
16059 + inode = file_inode(file);
16060 + au_mtx_and_read_lock(inode);
16063 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16064 + err = PTR_ERR(h_file);
16065 + if (IS_ERR(h_file))
16069 + err = vfs_fallocate(h_file, mode, offset, len);
16071 + au_write_post(inode, h_file, &wpre, /*written*/1);
16074 + si_read_unlock(inode->i_sb);
16075 + inode_unlock(inode);
16079 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16080 + struct file *dst, loff_t dst_pos,
16081 + size_t len, unsigned int flags)
16084 + struct au_write_pre wpre;
16085 + enum { SRC, DST };
16087 + struct inode *inode;
16088 + struct file *h_file;
16089 + struct super_block *h_sb;
16091 +#define a_src a[SRC]
16092 +#define a_dst a[DST]
16095 + a_src.inode = file_inode(src);
16096 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16098 + a_dst.inode = file_inode(dst);
16099 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16102 + au_mtx_and_read_lock(a_dst.inode);
16104 + * in order to match the order in di_write_lock2_{child,parent}(),
16105 + * use f_path.dentry for this comparison.
16107 + if (src->f_path.dentry < dst->f_path.dentry) {
16108 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16109 + err = PTR_ERR(a_src.h_file);
16110 + if (IS_ERR(a_src.h_file))
16113 + wpre.lsc = AuLsc_FI_2;
16114 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16115 + err = PTR_ERR(a_dst.h_file);
16116 + if (IS_ERR(a_dst.h_file)) {
16117 + au_read_post(a_src.inode, a_src.h_file);
16121 + wpre.lsc = AuLsc_FI_1;
16122 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16123 + err = PTR_ERR(a_dst.h_file);
16124 + if (IS_ERR(a_dst.h_file))
16127 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16128 + err = PTR_ERR(a_src.h_file);
16129 + if (IS_ERR(a_src.h_file)) {
16130 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16137 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16138 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16139 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16145 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16146 + dst_pos, len, flags);
16149 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16150 + fi_read_unlock(src);
16151 + au_read_post(a_src.inode, a_src.h_file);
16153 + si_read_unlock(a_dst.inode->i_sb);
16154 + inode_unlock(a_dst.inode);
16161 +/* ---------------------------------------------------------------------- */
16164 + * The locking order around current->mmap_sem.
16165 + * - in most and regular cases
16166 + * file I/O syscall -- aufs_read() or something
16167 + * -- si_rwsem for read -- mmap_sem
16168 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16170 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16171 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16172 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16173 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16174 + * It means that when aufs acquires si_rwsem for write, the process should never
16175 + * acquire mmap_sem.
16177 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16178 + * problem either since any directory is not able to be mmap-ed.
16179 + * The similar scenario is applied to aufs_readlink() too.
16182 +#if 0 /* stop calling security_file_mmap() */
16183 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16184 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16186 +static unsigned long au_arch_prot_conv(unsigned long flags)
16188 + /* currently ppc64 only */
16189 +#ifdef CONFIG_PPC64
16190 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16191 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16192 + return AuConv_VM_PROT(flags, SAO);
16194 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16199 +static unsigned long au_prot_conv(unsigned long flags)
16201 + return AuConv_VM_PROT(flags, READ)
16202 + | AuConv_VM_PROT(flags, WRITE)
16203 + | AuConv_VM_PROT(flags, EXEC)
16204 + | au_arch_prot_conv(flags);
16207 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16208 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16210 +static unsigned long au_flag_conv(unsigned long flags)
16212 + return AuConv_VM_MAP(flags, GROWSDOWN)
16213 + | AuConv_VM_MAP(flags, DENYWRITE)
16214 + | AuConv_VM_MAP(flags, LOCKED);
16218 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16221 + const unsigned char wlock
16222 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16223 + struct super_block *sb;
16224 + struct file *h_file;
16225 + struct inode *inode;
16227 + AuDbgVmRegion(file, vma);
16229 + inode = file_inode(file);
16230 + sb = inode->i_sb;
16232 + si_read_lock(sb, AuLock_NOPLMW);
16234 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16236 + err = PTR_ERR(h_file);
16237 + if (IS_ERR(h_file))
16241 + au_set_mmapped(file);
16242 + au_vm_file_reset(vma, h_file);
16244 + * we cannot call security_mmap_file() here since it may acquire
16245 + * mmap_sem or i_mutex.
16247 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16248 + * au_flag_conv(vma->vm_flags));
16251 + err = call_mmap(h_file, vma);
16253 + au_vm_prfile_set(vma, file);
16254 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16255 + goto out_fput; /* success */
16257 + au_unset_mmapped(file);
16258 + au_vm_file_reset(vma, file);
16262 + ii_write_unlock(inode);
16267 + si_read_unlock(sb);
16273 +/* ---------------------------------------------------------------------- */
16275 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16279 + struct au_write_pre wpre;
16280 + struct inode *inode;
16281 + struct file *h_file;
16283 + err = 0; /* -EBADF; */ /* posix? */
16284 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16287 + inode = file_inode(file);
16288 + au_mtx_and_read_lock(inode);
16291 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16292 + err = PTR_ERR(h_file);
16293 + if (IS_ERR(h_file))
16296 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16297 + au_write_post(inode, h_file, &wpre, /*written*/0);
16300 + si_read_unlock(inode->i_sb);
16301 + inode_unlock(inode);
16306 +static int aufs_fasync(int fd, struct file *file, int flag)
16309 + struct file *h_file;
16310 + struct super_block *sb;
16312 + sb = file->f_path.dentry->d_sb;
16313 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16315 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16316 + err = PTR_ERR(h_file);
16317 + if (IS_ERR(h_file))
16320 + if (h_file->f_op->fasync)
16321 + err = h_file->f_op->fasync(fd, h_file, flag);
16322 + fput(h_file); /* instead of au_read_post() */
16325 + si_read_unlock(sb);
16329 +static int aufs_setfl(struct file *file, unsigned long arg)
16332 + struct file *h_file;
16333 + struct super_block *sb;
16335 + sb = file->f_path.dentry->d_sb;
16336 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16338 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16339 + err = PTR_ERR(h_file);
16340 + if (IS_ERR(h_file))
16343 + /* stop calling h_file->fasync */
16344 + arg |= vfsub_file_flags(file) & FASYNC;
16345 + err = setfl(/*unused fd*/-1, h_file, arg);
16346 + fput(h_file); /* instead of au_read_post() */
16349 + si_read_unlock(sb);
16353 +/* ---------------------------------------------------------------------- */
16355 +/* no one supports this operation, currently */
16357 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16358 + size_t len, loff_t *pos, int more)
16363 +/* ---------------------------------------------------------------------- */
16365 +const struct file_operations aufs_file_fop = {
16366 + .owner = THIS_MODULE,
16368 + .llseek = default_llseek,
16370 + .read = aufs_read,
16371 + .write = aufs_write,
16372 + .read_iter = aufs_read_iter,
16373 + .write_iter = aufs_write_iter,
16375 +#ifdef CONFIG_AUFS_POLL
16376 + .poll = aufs_poll,
16378 + .unlocked_ioctl = aufs_ioctl_nondir,
16379 +#ifdef CONFIG_COMPAT
16380 + .compat_ioctl = aufs_compat_ioctl_nondir,
16382 + .mmap = aufs_mmap,
16383 + .open = aufs_open_nondir,
16384 + .flush = aufs_flush_nondir,
16385 + .release = aufs_release_nondir,
16386 + .fsync = aufs_fsync_nondir,
16387 + .fasync = aufs_fasync,
16388 + /* .sendpage = aufs_sendpage, */
16389 + .setfl = aufs_setfl,
16390 + .splice_write = aufs_splice_write,
16391 + .splice_read = aufs_splice_read,
16393 + .aio_splice_write = aufs_aio_splice_write,
16394 + .aio_splice_read = aufs_aio_splice_read,
16396 + .fallocate = aufs_fallocate,
16397 + .copy_file_range = aufs_copy_file_range
16399 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16400 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16401 +++ linux/fs/aufs/fstype.h 2018-08-12 23:43:05.456791299 +0200
16403 +/* SPDX-License-Identifier: GPL-2.0 */
16405 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16407 + * This program, aufs is free software; you can redistribute it and/or modify
16408 + * it under the terms of the GNU General Public License as published by
16409 + * the Free Software Foundation; either version 2 of the License, or
16410 + * (at your option) any later version.
16412 + * This program is distributed in the hope that it will be useful,
16413 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16414 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16415 + * GNU General Public License for more details.
16417 + * You should have received a copy of the GNU General Public License
16418 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16422 + * judging filesystem type
16425 +#ifndef __AUFS_FSTYPE_H__
16426 +#define __AUFS_FSTYPE_H__
16430 +#include <linux/fs.h>
16431 +#include <linux/magic.h>
16432 +#include <linux/nfs_fs.h>
16433 +#include <linux/romfs_fs.h>
16435 +static inline int au_test_aufs(struct super_block *sb)
16437 + return sb->s_magic == AUFS_SUPER_MAGIC;
16440 +static inline const char *au_sbtype(struct super_block *sb)
16442 + return sb->s_type->name;
16445 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16447 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16448 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16454 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16456 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16457 + return sb->s_magic == ROMFS_MAGIC;
16463 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16465 +#if IS_ENABLED(CONFIG_CRAMFS)
16466 + return sb->s_magic == CRAMFS_MAGIC;
16471 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16473 +#if IS_ENABLED(CONFIG_NFS_FS)
16474 + return sb->s_magic == NFS_SUPER_MAGIC;
16480 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16482 +#if IS_ENABLED(CONFIG_FUSE_FS)
16483 + return sb->s_magic == FUSE_SUPER_MAGIC;
16489 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16491 +#if IS_ENABLED(CONFIG_XFS_FS)
16492 + return sb->s_magic == XFS_SB_MAGIC;
16498 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16500 +#ifdef CONFIG_TMPFS
16501 + return sb->s_magic == TMPFS_MAGIC;
16507 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16509 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16510 + return !strcmp(au_sbtype(sb), "ecryptfs");
16516 +static inline int au_test_ramfs(struct super_block *sb)
16518 + return sb->s_magic == RAMFS_MAGIC;
16521 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16523 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16524 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16530 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16532 +#ifdef CONFIG_PROC_FS
16533 + return sb->s_magic == PROC_SUPER_MAGIC;
16539 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16541 +#ifdef CONFIG_SYSFS
16542 + return sb->s_magic == SYSFS_MAGIC;
16548 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16550 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16551 + return sb->s_magic == CONFIGFS_MAGIC;
16557 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16559 +#if IS_ENABLED(CONFIG_MINIX_FS)
16560 + return sb->s_magic == MINIX3_SUPER_MAGIC
16561 + || sb->s_magic == MINIX2_SUPER_MAGIC
16562 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16563 + || sb->s_magic == MINIX_SUPER_MAGIC
16564 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16570 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16572 +#if IS_ENABLED(CONFIG_FAT_FS)
16573 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16579 +static inline int au_test_msdos(struct super_block *sb)
16581 + return au_test_fat(sb);
16584 +static inline int au_test_vfat(struct super_block *sb)
16586 + return au_test_fat(sb);
16589 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16591 +#ifdef CONFIG_SECURITYFS
16592 + return sb->s_magic == SECURITYFS_MAGIC;
16598 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16600 +#if IS_ENABLED(CONFIG_SQUASHFS)
16601 + return sb->s_magic == SQUASHFS_MAGIC;
16607 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16609 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16610 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16616 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16618 +#if IS_ENABLED(CONFIG_XENFS)
16619 + return sb->s_magic == XENFS_SUPER_MAGIC;
16625 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16627 +#ifdef CONFIG_DEBUG_FS
16628 + return sb->s_magic == DEBUGFS_MAGIC;
16634 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16636 +#if IS_ENABLED(CONFIG_NILFS)
16637 + return sb->s_magic == NILFS_SUPER_MAGIC;
16643 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16645 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16646 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16652 +/* ---------------------------------------------------------------------- */
16654 + * they can't be an aufs branch.
16656 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16659 +#ifndef CONFIG_AUFS_BR_RAMFS
16660 + au_test_ramfs(sb) ||
16662 + au_test_procfs(sb)
16663 + || au_test_sysfs(sb)
16664 + || au_test_configfs(sb)
16665 + || au_test_debugfs(sb)
16666 + || au_test_securityfs(sb)
16667 + || au_test_xenfs(sb)
16668 + || au_test_ecryptfs(sb)
16669 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16670 + || au_test_aufs(sb); /* will be supported in next version */
16673 +static inline int au_test_fs_remote(struct super_block *sb)
16675 + return !au_test_tmpfs(sb)
16676 +#ifdef CONFIG_AUFS_BR_RAMFS
16677 + && !au_test_ramfs(sb)
16679 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16682 +/* ---------------------------------------------------------------------- */
16685 + * Note: these functions (below) are created after reading ->getattr() in all
16686 + * filesystems under linux/fs. it means we have to do so in every update...
16690 + * some filesystems require getattr to refresh the inode attributes before
16692 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16693 + * and leave the work for d_revalidate()
16695 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16697 + return au_test_nfs(sb)
16698 + || au_test_fuse(sb)
16699 + /* || au_test_btrfs(sb) */ /* untested */
16704 + * filesystems which don't maintain i_size or i_blocks.
16706 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16708 + return au_test_xfs(sb)
16709 + || au_test_btrfs(sb)
16710 + || au_test_ubifs(sb)
16711 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16712 + /* || au_test_minix(sb) */ /* untested */
16717 + * filesystems which don't store the correct value in some of their inode
16720 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16722 + return au_test_fs_bad_iattr_size(sb)
16723 + || au_test_fat(sb)
16724 + || au_test_msdos(sb)
16725 + || au_test_vfat(sb);
16728 +/* they don't check i_nlink in link(2) */
16729 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16731 + return au_test_tmpfs(sb)
16732 +#ifdef CONFIG_AUFS_BR_RAMFS
16733 + || au_test_ramfs(sb)
16735 + || au_test_ubifs(sb)
16736 + || au_test_hfsplus(sb);
16740 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16742 +static inline int au_test_fs_notime(struct super_block *sb)
16744 + return au_test_nfs(sb)
16745 + || au_test_fuse(sb)
16746 + || au_test_ubifs(sb)
16750 +/* temporary support for i#1 in cramfs */
16751 +static inline int au_test_fs_unique_ino(struct inode *inode)
16753 + if (au_test_cramfs(inode->i_sb))
16754 + return inode->i_ino != 1;
16758 +/* ---------------------------------------------------------------------- */
16761 + * the filesystem where the xino files placed must support i/o after unlink and
16762 + * maintain i_size and i_blocks.
16764 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16766 + return au_test_fs_remote(sb)
16767 + || au_test_fs_bad_iattr_size(sb)
16768 + /* don't want unnecessary work for xino */
16769 + || au_test_aufs(sb)
16770 + || au_test_ecryptfs(sb)
16771 + || au_test_nilfs(sb);
16774 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16776 + return au_test_tmpfs(sb)
16777 + || au_test_ramfs(sb);
16781 + * test if the @sb is real-readonly.
16783 +static inline int au_test_fs_rr(struct super_block *sb)
16785 + return au_test_squashfs(sb)
16786 + || au_test_iso9660(sb)
16787 + || au_test_cramfs(sb)
16788 + || au_test_romfs(sb);
16792 + * test if the @inode is nfs with 'noacl' option
16793 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16795 +static inline int au_test_nfs_noacl(struct inode *inode)
16797 + return au_test_nfs(inode->i_sb)
16798 + /* && IS_POSIXACL(inode) */
16799 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16802 +#endif /* __KERNEL__ */
16803 +#endif /* __AUFS_FSTYPE_H__ */
16804 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16805 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16806 +++ linux/fs/aufs/hbl.h 2018-08-12 23:43:05.456791299 +0200
16808 +/* SPDX-License-Identifier: GPL-2.0 */
16810 + * Copyright (C) 2017-2018 Junjiro R. Okajima
16812 + * This program, aufs is free software; you can redistribute it and/or modify
16813 + * it under the terms of the GNU General Public License as published by
16814 + * the Free Software Foundation; either version 2 of the License, or
16815 + * (at your option) any later version.
16817 + * This program is distributed in the hope that it will be useful,
16818 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16819 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16820 + * GNU General Public License for more details.
16822 + * You should have received a copy of the GNU General Public License
16823 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16827 + * helpers for hlist_bl.h
16830 +#ifndef __AUFS_HBL_H__
16831 +#define __AUFS_HBL_H__
16835 +#include <linux/list_bl.h>
16837 +static inline void au_hbl_add(struct hlist_bl_node *node,
16838 + struct hlist_bl_head *hbl)
16840 + hlist_bl_lock(hbl);
16841 + hlist_bl_add_head(node, hbl);
16842 + hlist_bl_unlock(hbl);
16845 +static inline void au_hbl_del(struct hlist_bl_node *node,
16846 + struct hlist_bl_head *hbl)
16848 + hlist_bl_lock(hbl);
16849 + hlist_bl_del(node);
16850 + hlist_bl_unlock(hbl);
16853 +#define au_hbl_for_each(pos, head) \
16854 + for (pos = hlist_bl_first(head); \
16858 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16860 + unsigned long cnt;
16861 + struct hlist_bl_node *pos;
16864 + hlist_bl_lock(hbl);
16865 + au_hbl_for_each(pos, hbl)
16867 + hlist_bl_unlock(hbl);
16871 +#endif /* __KERNEL__ */
16872 +#endif /* __AUFS_HBL_H__ */
16873 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16874 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16875 +++ linux/fs/aufs/hfsnotify.c 2018-10-23 12:33:35.596042364 +0200
16877 +// SPDX-License-Identifier: GPL-2.0
16879 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16881 + * This program, aufs is free software; you can redistribute it and/or modify
16882 + * it under the terms of the GNU General Public License as published by
16883 + * the Free Software Foundation; either version 2 of the License, or
16884 + * (at your option) any later version.
16886 + * This program is distributed in the hope that it will be useful,
16887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16889 + * GNU General Public License for more details.
16891 + * You should have received a copy of the GNU General Public License
16892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16896 + * fsnotify for the lower directories
16901 +/* FS_IN_IGNORED is unnecessary */
16902 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16903 + | FS_CREATE | FS_EVENT_ON_CHILD);
16904 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16905 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16907 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16909 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16911 + /* AuDbg("here\n"); */
16912 + au_cache_free_hnotify(hn);
16913 + smp_mb__before_atomic(); /* for atomic64_dec */
16914 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16915 + wake_up(&au_hfsn_wq);
16918 +static int au_hfsn_alloc(struct au_hinode *hinode)
16921 + struct au_hnotify *hn;
16922 + struct super_block *sb;
16923 + struct au_branch *br;
16924 + struct fsnotify_mark *mark;
16925 + aufs_bindex_t bindex;
16927 + hn = hinode->hi_notify;
16928 + sb = hn->hn_aufs_inode->i_sb;
16929 + bindex = au_br_index(sb, hinode->hi_id);
16930 + br = au_sbr(sb, bindex);
16931 + AuDebugOn(!br->br_hfsn);
16933 + mark = &hn->hn_mark;
16934 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16935 + mark->mask = AuHfsnMask;
16937 + * by udba rename or rmdir, aufs assign a new inode to the known
16938 + * h_inode, so specify 1 to allow dups.
16941 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16947 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16949 + struct fsnotify_mark *mark;
16950 + unsigned long long ull;
16951 + struct fsnotify_group *group;
16953 + ull = atomic64_inc_return(&au_hfsn_ifree);
16956 + mark = &hn->hn_mark;
16957 + spin_lock(&mark->lock);
16958 + group = mark->group;
16959 + fsnotify_get_group(group);
16960 + spin_unlock(&mark->lock);
16962 + fsnotify_destroy_mark(mark, group);
16963 + fsnotify_put_mark(mark);
16964 + fsnotify_put_group(group);
16967 + /* free hn by myself */
16971 +/* ---------------------------------------------------------------------- */
16973 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16975 + struct fsnotify_mark *mark;
16977 + mark = &hinode->hi_notify->hn_mark;
16978 + spin_lock(&mark->lock);
16980 + AuDebugOn(mark->mask & AuHfsnMask);
16981 + mark->mask |= AuHfsnMask;
16983 + AuDebugOn(!(mark->mask & AuHfsnMask));
16984 + mark->mask &= ~AuHfsnMask;
16986 + spin_unlock(&mark->lock);
16987 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16990 +/* ---------------------------------------------------------------------- */
16992 +/* #define AuDbgHnotify */
16993 +#ifdef AuDbgHnotify
16994 +static char *au_hfsn_name(u32 mask)
16996 +#ifdef CONFIG_AUFS_DEBUG
16997 +#define test_ret(flag) \
16999 + if (mask & flag) \
17002 + test_ret(FS_ACCESS);
17003 + test_ret(FS_MODIFY);
17004 + test_ret(FS_ATTRIB);
17005 + test_ret(FS_CLOSE_WRITE);
17006 + test_ret(FS_CLOSE_NOWRITE);
17007 + test_ret(FS_OPEN);
17008 + test_ret(FS_MOVED_FROM);
17009 + test_ret(FS_MOVED_TO);
17010 + test_ret(FS_CREATE);
17011 + test_ret(FS_DELETE);
17012 + test_ret(FS_DELETE_SELF);
17013 + test_ret(FS_MOVE_SELF);
17014 + test_ret(FS_UNMOUNT);
17015 + test_ret(FS_Q_OVERFLOW);
17016 + test_ret(FS_IN_IGNORED);
17017 + test_ret(FS_ISDIR);
17018 + test_ret(FS_IN_ONESHOT);
17019 + test_ret(FS_EVENT_ON_CHILD);
17028 +/* ---------------------------------------------------------------------- */
17030 +static void au_hfsn_free_group(struct fsnotify_group *group)
17032 + struct au_br_hfsnotify *hfsn = group->private;
17034 + /* AuDbg("here\n"); */
17038 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17039 + struct inode *inode,
17040 + u32 mask, const void *data, int data_type,
17041 + const unsigned char *file_name, u32 cookie,
17042 + struct fsnotify_iter_info *iter_info)
17045 + struct au_hnotify *hnotify;
17046 + struct inode *h_dir, *h_inode;
17047 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17048 + struct fsnotify_mark *inode_mark;
17050 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17053 + /* if FS_UNMOUNT happens, there must be another bug */
17054 + AuDebugOn(mask & FS_UNMOUNT);
17055 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17060 +#ifdef AuDbgHnotify
17062 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17063 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17064 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17065 + h_dir->i_ino, mask, au_hfsn_name(mask),
17066 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17067 + /* WARN_ON(1); */
17072 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17073 + AuDebugOn(!inode_mark);
17074 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17075 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17081 +static struct fsnotify_ops au_hfsn_ops = {
17082 + .handle_event = au_hfsn_handle_event,
17083 + .free_group_priv = au_hfsn_free_group,
17084 + .free_mark = au_hfsn_free_mark
17087 +/* ---------------------------------------------------------------------- */
17089 +static void au_hfsn_fin_br(struct au_branch *br)
17091 + struct au_br_hfsnotify *hfsn;
17093 + hfsn = br->br_hfsn;
17096 + fsnotify_put_group(hfsn->hfsn_group);
17101 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17104 + struct fsnotify_group *group;
17105 + struct au_br_hfsnotify *hfsn;
17108 + br->br_hfsn = NULL;
17109 + if (!au_br_hnotifyable(perm))
17113 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17114 + if (unlikely(!hfsn))
17118 + group = fsnotify_alloc_group(&au_hfsn_ops);
17119 + if (IS_ERR(group)) {
17120 + err = PTR_ERR(group);
17121 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17125 + group->private = hfsn;
17126 + hfsn->hfsn_group = group;
17127 + br->br_hfsn = hfsn;
17128 + goto out; /* success */
17136 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17141 + if (!br->br_hfsn)
17142 + err = au_hfsn_init_br(br, perm);
17147 +/* ---------------------------------------------------------------------- */
17149 +static void au_hfsn_fin(void)
17151 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17152 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17155 +const struct au_hnotify_op au_hnotify_op = {
17156 + .ctl = au_hfsn_ctl,
17157 + .alloc = au_hfsn_alloc,
17158 + .free = au_hfsn_free,
17160 + .fin = au_hfsn_fin,
17162 + .reset_br = au_hfsn_reset_br,
17163 + .fin_br = au_hfsn_fin_br,
17164 + .init_br = au_hfsn_init_br
17166 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17167 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17168 +++ linux/fs/aufs/hfsplus.c 2018-10-23 12:33:35.596042364 +0200
17170 +// SPDX-License-Identifier: GPL-2.0
17172 + * Copyright (C) 2010-2018 Junjiro R. Okajima
17174 + * This program, aufs is free software; you can redistribute it and/or modify
17175 + * it under the terms of the GNU General Public License as published by
17176 + * the Free Software Foundation; either version 2 of the License, or
17177 + * (at your option) any later version.
17179 + * This program is distributed in the hope that it will be useful,
17180 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17181 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17182 + * GNU General Public License for more details.
17184 + * You should have received a copy of the GNU General Public License
17185 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17189 + * special support for filesystems which acquires an inode mutex
17190 + * at final closing a file, eg, hfsplus.
17192 + * This trick is very simple and stupid, just to open the file before really
17193 + * necessary open to tell hfsplus that this is not the final closing.
17194 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17195 + * and au_h_open_post() after releasing it.
17200 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17203 + struct file *h_file;
17204 + struct dentry *h_dentry;
17206 + h_dentry = au_h_dptr(dentry, bindex);
17207 + AuDebugOn(!h_dentry);
17208 + AuDebugOn(d_is_negative(h_dentry));
17211 + if (au_test_hfsplus(h_dentry->d_sb)
17212 + && d_is_reg(h_dentry))
17213 + h_file = au_h_open(dentry, bindex,
17214 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17215 + /*file*/NULL, force_wr);
17219 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17220 + struct file *h_file)
17222 + struct au_branch *br;
17226 + br = au_sbr(dentry->d_sb, bindex);
17227 + au_lcnt_dec(&br->br_nfiles);
17230 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17231 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17232 +++ linux/fs/aufs/hnotify.c 2018-10-23 12:33:35.596042364 +0200
17234 +// SPDX-License-Identifier: GPL-2.0
17236 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17238 + * This program, aufs is free software; you can redistribute it and/or modify
17239 + * it under the terms of the GNU General Public License as published by
17240 + * the Free Software Foundation; either version 2 of the License, or
17241 + * (at your option) any later version.
17243 + * This program is distributed in the hope that it will be useful,
17244 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17245 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17246 + * GNU General Public License for more details.
17248 + * You should have received a copy of the GNU General Public License
17249 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17253 + * abstraction to notify the direct changes on lower directories
17258 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17261 + struct au_hnotify *hn;
17264 + hn = au_cache_alloc_hnotify();
17266 + hn->hn_aufs_inode = inode;
17267 + hinode->hi_notify = hn;
17268 + err = au_hnotify_op.alloc(hinode);
17270 + if (unlikely(err)) {
17271 + hinode->hi_notify = NULL;
17272 + au_cache_free_hnotify(hn);
17274 + * The upper dir was removed by udba, but the same named
17275 + * dir left. In this case, aufs assigns a new inode
17276 + * number and set the monitor again.
17277 + * For the lower dir, the old monitor is still left.
17279 + if (err == -EEXIST)
17288 +void au_hn_free(struct au_hinode *hinode)
17290 + struct au_hnotify *hn;
17292 + hn = hinode->hi_notify;
17294 + hinode->hi_notify = NULL;
17295 + if (au_hnotify_op.free(hinode, hn))
17296 + au_cache_free_hnotify(hn);
17300 +/* ---------------------------------------------------------------------- */
17302 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17304 + if (hinode->hi_notify)
17305 + au_hnotify_op.ctl(hinode, do_set);
17308 +void au_hn_reset(struct inode *inode, unsigned int flags)
17310 + aufs_bindex_t bindex, bbot;
17311 + struct inode *hi;
17312 + struct dentry *iwhdentry;
17314 + bbot = au_ibbot(inode);
17315 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17316 + hi = au_h_iptr(inode, bindex);
17320 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17321 + iwhdentry = au_hi_wh(inode, bindex);
17325 + au_set_h_iptr(inode, bindex, NULL, 0);
17326 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17327 + flags & ~AuHi_XINO);
17330 + /* inode_unlock(hi); */
17334 +/* ---------------------------------------------------------------------- */
17336 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17339 + aufs_bindex_t bindex, bbot, bfound, btop;
17340 + struct inode *h_i;
17343 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17344 + pr_warn("branch root dir was changed\n");
17349 + bbot = au_ibbot(inode);
17350 + btop = au_ibtop(inode);
17351 +#if 0 /* reserved for future use */
17352 + if (bindex == bbot) {
17353 + /* keep this ino in rename case */
17357 + for (bindex = btop; bindex <= bbot; bindex++)
17358 + if (au_h_iptr(inode, bindex) == h_inode) {
17365 + for (bindex = btop; bindex <= bbot; bindex++) {
17366 + h_i = au_h_iptr(inode, bindex);
17370 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17371 + /* ignore this error */
17372 + /* bad action? */
17375 + /* children inode number will be broken */
17382 +static int hn_gen_tree(struct dentry *dentry)
17384 + int err, i, j, ndentry;
17385 + struct au_dcsub_pages dpages;
17386 + struct au_dpage *dpage;
17387 + struct dentry **dentries;
17389 + err = au_dpages_init(&dpages, GFP_NOFS);
17390 + if (unlikely(err))
17392 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17393 + if (unlikely(err))
17396 + for (i = 0; i < dpages.ndpage; i++) {
17397 + dpage = dpages.dpages + i;
17398 + dentries = dpage->dentries;
17399 + ndentry = dpage->ndentry;
17400 + for (j = 0; j < ndentry; j++) {
17401 + struct dentry *d;
17408 + if (d_really_is_positive(d))
17409 + /* todo: reset children xino?
17410 + cached children only? */
17411 + au_iigen_dec(d_inode(d));
17416 + au_dpages_free(&dpages);
17419 + /* discard children */
17420 + dentry_unhash(dentry);
17428 + * return 0 if processed.
17430 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17431 + const unsigned int isdir)
17434 + struct dentry *d;
17435 + struct qstr *dname;
17438 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17439 + pr_warn("branch root dir was changed\n");
17445 + AuDebugOn(!name);
17446 + au_iigen_dec(inode);
17447 + spin_lock(&inode->i_lock);
17448 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17449 + spin_lock(&d->d_lock);
17450 + dname = &d->d_name;
17451 + if (dname->len != nlen
17452 + && memcmp(dname->name, name, nlen)) {
17453 + spin_unlock(&d->d_lock);
17458 + spin_unlock(&d->d_lock);
17461 + spin_unlock(&inode->i_lock);
17463 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17464 + d = d_find_any_alias(inode);
17466 + au_iigen_dec(inode);
17470 + spin_lock(&d->d_lock);
17471 + dname = &d->d_name;
17472 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17473 + spin_unlock(&d->d_lock);
17474 + err = hn_gen_tree(d);
17475 + spin_lock(&d->d_lock);
17477 + spin_unlock(&d->d_lock);
17486 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17490 + if (IS_ROOT(dentry)) {
17491 + pr_warn("branch root dir was changed\n");
17497 + au_digen_dec(dentry);
17498 + if (d_really_is_positive(dentry))
17499 + au_iigen_dec(d_inode(dentry));
17501 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17502 + if (d_really_is_positive(dentry))
17503 + err = hn_gen_tree(dentry);
17510 +/* ---------------------------------------------------------------------- */
17512 +/* hnotify job flags */
17513 +#define AuHnJob_XINO0 1
17514 +#define AuHnJob_GEN (1 << 1)
17515 +#define AuHnJob_DIRENT (1 << 2)
17516 +#define AuHnJob_ISDIR (1 << 3)
17517 +#define AuHnJob_TRYXINO0 (1 << 4)
17518 +#define AuHnJob_MNTPNT (1 << 5)
17519 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17520 +#define au_fset_hnjob(flags, name) \
17521 + do { (flags) |= AuHnJob_##name; } while (0)
17522 +#define au_fclr_hnjob(flags, name) \
17523 + do { (flags) &= ~AuHnJob_##name; } while (0)
17531 +struct au_hnotify_args {
17532 + struct inode *h_dir, *dir, *h_child_inode;
17534 + unsigned int flags[AuHnLast];
17535 + unsigned int h_child_nlen;
17536 + char h_child_name[];
17539 +struct hn_job_args {
17540 + unsigned int flags;
17541 + struct inode *inode, *h_inode, *dir, *h_dir;
17542 + struct dentry *dentry;
17547 +static int hn_job(struct hn_job_args *a)
17549 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17553 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17554 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17556 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17559 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17560 + if (!a->h_inode->i_nlink
17561 + && !(a->h_inode->i_state & I_LINKABLE))
17562 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17563 + inode_unlock_shared(a->h_inode);
17566 + /* make the generation obsolete */
17567 + if (au_ftest_hnjob(a->flags, GEN)) {
17570 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17572 + if (e && a->dentry)
17573 + hn_gen_by_name(a->dentry, isdir);
17574 + /* ignore this error */
17577 + /* make dir entries obsolete */
17578 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17579 + struct au_vdir *vdir;
17581 + vdir = au_ivdir(a->inode);
17583 + vdir->vd_jiffy = 0;
17584 + /* IMustLock(a->inode); */
17585 + /* inode_inc_iversion(a->inode); */
17588 + /* can do nothing but warn */
17589 + if (au_ftest_hnjob(a->flags, MNTPNT)
17591 + && d_mountpoint(a->dentry))
17592 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17597 +/* ---------------------------------------------------------------------- */
17599 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17600 + struct inode *dir)
17602 + struct dentry *dentry, *d, *parent;
17603 + struct qstr *dname;
17605 + parent = d_find_any_alias(dir);
17610 + spin_lock(&parent->d_lock);
17611 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17612 + /* AuDbg("%pd\n", d); */
17613 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17614 + dname = &d->d_name;
17615 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17616 + goto cont_unlock;
17620 + goto cont_unlock;
17621 + if (au_dcount(d) > 0) {
17622 + dentry = dget_dlock(d);
17623 + spin_unlock(&d->d_lock);
17628 + spin_unlock(&d->d_lock);
17630 + spin_unlock(&parent->d_lock);
17634 + di_write_lock_child(dentry);
17639 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17640 + aufs_bindex_t bindex, ino_t h_ino)
17642 + struct inode *inode;
17647 + err = au_xino_read(sb, bindex, h_ino, &ino);
17649 + inode = ilookup(sb, ino);
17653 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17654 + pr_warn("wrong root branch\n");
17660 + ii_write_lock_child(inode);
17666 +static void au_hn_bh(void *_args)
17668 + struct au_hnotify_args *a = _args;
17669 + struct super_block *sb;
17670 + aufs_bindex_t bindex, bbot, bfound;
17671 + unsigned char xino, try_iput;
17673 + struct inode *inode;
17675 + struct hn_job_args args;
17676 + struct dentry *dentry;
17677 + struct au_sbinfo *sbinfo;
17679 + AuDebugOn(!_args);
17680 + AuDebugOn(!a->h_dir);
17681 + AuDebugOn(!a->dir);
17682 + AuDebugOn(!a->mask);
17683 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17684 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17685 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17690 + * do not lock a->dir->i_mutex here
17691 + * because of d_revalidate() may cause a deadlock.
17693 + sb = a->dir->i_sb;
17695 + sbinfo = au_sbi(sb);
17696 + AuDebugOn(!sbinfo);
17697 + si_write_lock(sb, AuLock_NOPLMW);
17699 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17700 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17701 + case FS_MOVED_FROM:
17702 + case FS_MOVED_TO:
17703 + AuWarn1("DIRREN with UDBA may not work correctly "
17704 + "for the direct rename(2)\n");
17707 + ii_read_lock_parent(a->dir);
17709 + bbot = au_ibbot(a->dir);
17710 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17711 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17715 + ii_read_unlock(a->dir);
17716 + if (unlikely(bfound < 0))
17719 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17721 + if (a->h_child_inode)
17722 + h_ino = a->h_child_inode->i_ino;
17724 + if (a->h_child_nlen
17725 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17726 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17727 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17730 + if (dentry && d_really_is_positive(dentry))
17731 + inode = d_inode(dentry);
17732 + if (xino && !inode && h_ino
17733 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17734 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17735 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17736 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17740 + args.flags = a->flags[AuHn_CHILD];
17741 + args.dentry = dentry;
17742 + args.inode = inode;
17743 + args.h_inode = a->h_child_inode;
17744 + args.dir = a->dir;
17745 + args.h_dir = a->h_dir;
17746 + args.h_name = a->h_child_name;
17747 + args.h_nlen = a->h_child_nlen;
17748 + err = hn_job(&args);
17750 + if (au_di(dentry))
17751 + di_write_unlock(dentry);
17754 + if (inode && try_iput) {
17755 + ii_write_unlock(inode);
17759 + ii_write_lock_parent(a->dir);
17760 + args.flags = a->flags[AuHn_PARENT];
17761 + args.dentry = NULL;
17762 + args.inode = a->dir;
17763 + args.h_inode = a->h_dir;
17765 + args.h_dir = NULL;
17766 + args.h_name = NULL;
17768 + err = hn_job(&args);
17769 + ii_write_unlock(a->dir);
17772 + iput(a->h_child_inode);
17775 + si_write_unlock(sb);
17776 + au_nwt_done(&sbinfo->si_nowait);
17780 +/* ---------------------------------------------------------------------- */
17782 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17783 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17786 + unsigned int flags[AuHnLast], f;
17787 + unsigned char isdir, isroot, wh;
17788 + struct inode *dir;
17789 + struct au_hnotify_args *args;
17790 + char *p, *h_child_name;
17793 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17794 + dir = igrab(hnotify->hn_aufs_inode);
17798 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17800 + h_child_name = (void *)h_child_qstr->name;
17801 + len = h_child_qstr->len;
17802 + if (h_child_name) {
17803 + if (len > AUFS_WH_PFX_LEN
17804 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17805 + h_child_name += AUFS_WH_PFX_LEN;
17806 + len -= AUFS_WH_PFX_LEN;
17812 + if (h_child_inode)
17813 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17814 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17815 + flags[AuHn_CHILD] = 0;
17817 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17818 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17819 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17820 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17821 + case FS_MOVED_FROM:
17822 + case FS_MOVED_TO:
17823 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17824 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17827 + AuDebugOn(!h_child_name);
17832 + * aufs never be able to get this child inode.
17833 + * revalidation should be in d_revalidate()
17834 + * by checking i_nlink, i_generation or d_unhashed().
17836 + AuDebugOn(!h_child_name);
17837 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17838 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17846 + h_child_inode = NULL;
17849 + /* iput() and kfree() will be called in au_hnotify() */
17850 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17851 + if (unlikely(!args)) {
17852 + AuErr1("no memory\n");
17856 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17857 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17858 + args->mask = mask;
17860 + args->h_dir = igrab(h_dir);
17861 + if (h_child_inode)
17862 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17863 + args->h_child_inode = h_child_inode;
17864 + args->h_child_nlen = len;
17866 + p = (void *)args;
17867 + p += sizeof(*args);
17868 + memcpy(p, h_child_name, len);
17872 + /* NFS fires the event for silly-renamed one from kworker */
17874 + if (!dir->i_nlink
17875 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17877 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17878 + if (unlikely(err)) {
17879 + pr_err("wkq %d\n", err);
17880 + iput(args->h_child_inode);
17881 + iput(args->h_dir);
17890 +/* ---------------------------------------------------------------------- */
17892 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17896 + AuDebugOn(!(udba & AuOptMask_UDBA));
17899 + if (au_hnotify_op.reset_br)
17900 + err = au_hnotify_op.reset_br(udba, br, perm);
17905 +int au_hnotify_init_br(struct au_branch *br, int perm)
17910 + if (au_hnotify_op.init_br)
17911 + err = au_hnotify_op.init_br(br, perm);
17916 +void au_hnotify_fin_br(struct au_branch *br)
17918 + if (au_hnotify_op.fin_br)
17919 + au_hnotify_op.fin_br(br);
17922 +static void au_hn_destroy_cache(void)
17924 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17925 + au_cache[AuCache_HNOTIFY] = NULL;
17928 +int __init au_hnotify_init(void)
17933 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17934 + if (au_cache[AuCache_HNOTIFY]) {
17936 + if (au_hnotify_op.init)
17937 + err = au_hnotify_op.init();
17938 + if (unlikely(err))
17939 + au_hn_destroy_cache();
17945 +void au_hnotify_fin(void)
17947 + if (au_hnotify_op.fin)
17948 + au_hnotify_op.fin();
17950 + /* cf. au_cache_fin() */
17951 + if (au_cache[AuCache_HNOTIFY])
17952 + au_hn_destroy_cache();
17954 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17955 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17956 +++ linux/fs/aufs/iinfo.c 2018-10-23 12:33:35.599375796 +0200
17958 +// SPDX-License-Identifier: GPL-2.0
17960 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17962 + * This program, aufs is free software; you can redistribute it and/or modify
17963 + * it under the terms of the GNU General Public License as published by
17964 + * the Free Software Foundation; either version 2 of the License, or
17965 + * (at your option) any later version.
17967 + * This program is distributed in the hope that it will be useful,
17968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17970 + * GNU General Public License for more details.
17972 + * You should have received a copy of the GNU General Public License
17973 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17977 + * inode private data
17982 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17984 + struct inode *h_inode;
17985 + struct au_hinode *hinode;
17987 + IiMustAnyLock(inode);
17989 + hinode = au_hinode(au_ii(inode), bindex);
17990 + h_inode = hinode->hi_inode;
17991 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17995 +/* todo: hard/soft set? */
17996 +void au_hiput(struct au_hinode *hinode)
17998 + au_hn_free(hinode);
17999 + dput(hinode->hi_whdentry);
18000 + iput(hinode->hi_inode);
18003 +unsigned int au_hi_flags(struct inode *inode, int isdir)
18005 + unsigned int flags;
18006 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
18009 + if (au_opt_test(mnt_flags, XINO))
18010 + au_fset_hi(flags, XINO);
18011 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
18012 + au_fset_hi(flags, HNOTIFY);
18016 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18017 + struct inode *h_inode, unsigned int flags)
18019 + struct au_hinode *hinode;
18020 + struct inode *hi;
18021 + struct au_iinfo *iinfo = au_ii(inode);
18023 + IiMustWriteLock(inode);
18025 + hinode = au_hinode(iinfo, bindex);
18026 + hi = hinode->hi_inode;
18027 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18030 + au_hiput(hinode);
18031 + hinode->hi_inode = h_inode;
18034 + struct super_block *sb = inode->i_sb;
18035 + struct au_branch *br;
18037 + AuDebugOn(inode->i_mode
18038 + && (h_inode->i_mode & S_IFMT)
18039 + != (inode->i_mode & S_IFMT));
18040 + if (bindex == iinfo->ii_btop)
18041 + au_cpup_igen(inode, h_inode);
18042 + br = au_sbr(sb, bindex);
18043 + hinode->hi_id = br->br_id;
18044 + if (au_ftest_hi(flags, XINO)) {
18045 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18047 + if (unlikely(err))
18048 + AuIOErr1("failed au_xino_write() %d\n", err);
18051 + if (au_ftest_hi(flags, HNOTIFY)
18052 + && au_br_hnotifyable(br->br_perm)) {
18053 + err = au_hn_alloc(hinode, inode);
18054 + if (unlikely(err))
18055 + AuIOErr1("au_hn_alloc() %d\n", err);
18060 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18061 + struct dentry *h_wh)
18063 + struct au_hinode *hinode;
18065 + IiMustWriteLock(inode);
18067 + hinode = au_hinode(au_ii(inode), bindex);
18068 + AuDebugOn(hinode->hi_whdentry);
18069 + hinode->hi_whdentry = h_wh;
18072 +void au_update_iigen(struct inode *inode, int half)
18074 + struct au_iinfo *iinfo;
18075 + struct au_iigen *iigen;
18076 + unsigned int sigen;
18078 + sigen = au_sigen(inode->i_sb);
18079 + iinfo = au_ii(inode);
18080 + iigen = &iinfo->ii_generation;
18081 + spin_lock(&iigen->ig_spin);
18082 + iigen->ig_generation = sigen;
18084 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18086 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18087 + spin_unlock(&iigen->ig_spin);
18090 +/* it may be called at remount time, too */
18091 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18093 + struct au_iinfo *iinfo;
18094 + aufs_bindex_t bindex, bbot;
18096 + AuDebugOn(au_is_bad_inode(inode));
18097 + IiMustWriteLock(inode);
18099 + iinfo = au_ii(inode);
18100 + if (do_put_zero && iinfo->ii_btop >= 0) {
18101 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18103 + struct inode *h_i;
18105 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18108 + && !(h_i->i_state & I_LINKABLE))
18109 + au_set_h_iptr(inode, bindex, NULL, 0);
18113 + iinfo->ii_btop = -1;
18114 + iinfo->ii_bbot = -1;
18115 + bbot = au_sbbot(inode->i_sb);
18116 + for (bindex = 0; bindex <= bbot; bindex++)
18117 + if (au_hinode(iinfo, bindex)->hi_inode) {
18118 + iinfo->ii_btop = bindex;
18121 + if (iinfo->ii_btop >= 0)
18122 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18123 + if (au_hinode(iinfo, bindex)->hi_inode) {
18124 + iinfo->ii_bbot = bindex;
18127 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18130 +/* ---------------------------------------------------------------------- */
18132 +void au_icntnr_init_once(void *_c)
18134 + struct au_icntnr *c = _c;
18135 + struct au_iinfo *iinfo = &c->iinfo;
18137 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18138 + au_rw_init(&iinfo->ii_rwsem);
18139 + inode_init_once(&c->vfs_inode);
18142 +void au_hinode_init(struct au_hinode *hinode)
18144 + hinode->hi_inode = NULL;
18145 + hinode->hi_id = -1;
18146 + au_hn_init(hinode);
18147 + hinode->hi_whdentry = NULL;
18150 +int au_iinfo_init(struct inode *inode)
18152 + struct au_iinfo *iinfo;
18153 + struct super_block *sb;
18154 + struct au_hinode *hi;
18157 + sb = inode->i_sb;
18158 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18159 + nbr = au_sbbot(sb) + 1;
18160 + if (unlikely(nbr <= 0))
18162 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18164 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18166 + iinfo->ii_hinode = hi;
18167 + for (i = 0; i < nbr; i++, hi++)
18168 + au_hinode_init(hi);
18170 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18171 + iinfo->ii_btop = -1;
18172 + iinfo->ii_bbot = -1;
18173 + iinfo->ii_vdir = NULL;
18179 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18182 + struct au_hinode *hip;
18184 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18187 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18190 + iinfo->ii_hinode = hip;
18191 + i = iinfo->ii_bbot + 1;
18193 + for (; i < nbr; i++, hip++)
18194 + au_hinode_init(hip);
18201 +void au_iinfo_fin(struct inode *inode)
18203 + struct au_iinfo *iinfo;
18204 + struct au_hinode *hi;
18205 + struct super_block *sb;
18206 + aufs_bindex_t bindex, bbot;
18207 + const unsigned char unlinked = !inode->i_nlink;
18209 + AuDebugOn(au_is_bad_inode(inode));
18211 + sb = inode->i_sb;
18212 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18213 + if (si_pid_test(sb))
18214 + au_xino_delete_inode(inode, unlinked);
18217 + * it is safe to hide the dependency between sbinfo and
18221 + si_noflush_read_lock(sb);
18222 + au_xino_delete_inode(inode, unlinked);
18223 + si_read_unlock(sb);
18227 + iinfo = au_ii(inode);
18228 + if (iinfo->ii_vdir)
18229 + au_vdir_free(iinfo->ii_vdir);
18231 + bindex = iinfo->ii_btop;
18232 + if (bindex >= 0) {
18233 + hi = au_hinode(iinfo, bindex);
18234 + bbot = iinfo->ii_bbot;
18235 + while (bindex++ <= bbot) {
18236 + if (hi->hi_inode)
18241 + kfree(iinfo->ii_hinode);
18242 + AuRwDestroy(&iinfo->ii_rwsem);
18244 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18245 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18246 +++ linux/fs/aufs/inode.c 2018-08-12 23:43:05.460124736 +0200
18248 +// SPDX-License-Identifier: GPL-2.0
18250 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18252 + * This program, aufs is free software; you can redistribute it and/or modify
18253 + * it under the terms of the GNU General Public License as published by
18254 + * the Free Software Foundation; either version 2 of the License, or
18255 + * (at your option) any later version.
18257 + * This program is distributed in the hope that it will be useful,
18258 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18259 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18260 + * GNU General Public License for more details.
18262 + * You should have received a copy of the GNU General Public License
18263 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18267 + * inode functions
18272 +struct inode *au_igrab(struct inode *inode)
18275 + AuDebugOn(!atomic_read(&inode->i_count));
18281 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18283 + au_cpup_attr_all(inode, /*force*/0);
18284 + au_update_iigen(inode, /*half*/1);
18286 + inode_inc_iversion(inode);
18289 +static int au_ii_refresh(struct inode *inode, int *update)
18293 + aufs_bindex_t bindex, new_bindex;
18294 + struct super_block *sb;
18295 + struct au_iinfo *iinfo;
18296 + struct au_hinode *p, *q, tmp;
18298 + AuDebugOn(au_is_bad_inode(inode));
18299 + IiMustWriteLock(inode);
18302 + sb = inode->i_sb;
18303 + nbr = au_sbbot(sb) + 1;
18304 + type = inode->i_mode & S_IFMT;
18305 + iinfo = au_ii(inode);
18306 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18307 + if (unlikely(err))
18310 + AuDebugOn(iinfo->ii_btop < 0);
18311 + p = au_hinode(iinfo, iinfo->ii_btop);
18312 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18314 + if (!p->hi_inode)
18317 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18318 + new_bindex = au_br_index(sb, p->hi_id);
18319 + if (new_bindex == bindex)
18322 + if (new_bindex < 0) {
18325 + p->hi_inode = NULL;
18329 + if (new_bindex < iinfo->ii_btop)
18330 + iinfo->ii_btop = new_bindex;
18331 + if (iinfo->ii_bbot < new_bindex)
18332 + iinfo->ii_bbot = new_bindex;
18333 + /* swap two lower inode, and loop again */
18334 + q = au_hinode(iinfo, new_bindex);
18338 + if (tmp.hi_inode) {
18343 + au_update_ibrange(inode, /*do_put_zero*/0);
18344 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18345 + e = au_dy_irefresh(inode);
18346 + if (unlikely(e && !err))
18354 +void au_refresh_iop(struct inode *inode, int force_getattr)
18357 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18358 + const struct inode_operations *iop
18359 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18361 + if (inode->i_op == iop)
18364 + switch (inode->i_mode & S_IFMT) {
18366 + type = AuIop_DIR;
18369 + type = AuIop_SYMLINK;
18372 + type = AuIop_OTHER;
18376 + inode->i_op = iop + type;
18377 + /* unnecessary smp_wmb() */
18380 +int au_refresh_hinode_self(struct inode *inode)
18384 + err = au_ii_refresh(inode, &update);
18386 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18392 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18394 + int err, e, update;
18395 + unsigned int flags;
18397 + aufs_bindex_t bindex, bbot;
18398 + unsigned char isdir;
18399 + struct au_hinode *p;
18400 + struct au_iinfo *iinfo;
18402 + err = au_ii_refresh(inode, &update);
18403 + if (unlikely(err))
18407 + iinfo = au_ii(inode);
18408 + p = au_hinode(iinfo, iinfo->ii_btop);
18409 + mode = (inode->i_mode & S_IFMT);
18410 + isdir = S_ISDIR(mode);
18411 + flags = au_hi_flags(inode, isdir);
18412 + bbot = au_dbbot(dentry);
18413 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18414 + struct inode *h_i, *h_inode;
18415 + struct dentry *h_d;
18417 + h_d = au_h_dptr(dentry, bindex);
18418 + if (!h_d || d_is_negative(h_d))
18421 + h_inode = d_inode(h_d);
18422 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18423 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18424 + h_i = au_h_iptr(inode, bindex);
18426 + if (h_i == h_inode)
18432 + if (bindex < iinfo->ii_btop)
18433 + iinfo->ii_btop = bindex;
18434 + if (iinfo->ii_bbot < bindex)
18435 + iinfo->ii_bbot = bindex;
18436 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18439 + au_update_ibrange(inode, /*do_put_zero*/0);
18440 + e = au_dy_irefresh(inode);
18441 + if (unlikely(e && !err))
18444 + au_refresh_hinode_attr(inode, update && isdir);
18451 +static int set_inode(struct inode *inode, struct dentry *dentry)
18454 + unsigned int flags;
18456 + aufs_bindex_t bindex, btop, btail;
18457 + unsigned char isdir;
18458 + struct dentry *h_dentry;
18459 + struct inode *h_inode;
18460 + struct au_iinfo *iinfo;
18461 + struct inode_operations *iop;
18463 + IiMustWriteLock(inode);
18467 + iop = au_sbi(inode->i_sb)->si_iop_array;
18468 + btop = au_dbtop(dentry);
18469 + h_dentry = au_h_dptr(dentry, btop);
18470 + h_inode = d_inode(h_dentry);
18471 + mode = h_inode->i_mode;
18472 + switch (mode & S_IFMT) {
18474 + btail = au_dbtail(dentry);
18475 + inode->i_op = iop + AuIop_OTHER;
18476 + inode->i_fop = &aufs_file_fop;
18477 + err = au_dy_iaop(inode, btop, h_inode);
18478 + if (unlikely(err))
18483 + btail = au_dbtaildir(dentry);
18484 + inode->i_op = iop + AuIop_DIR;
18485 + inode->i_fop = &aufs_dir_fop;
18488 + btail = au_dbtail(dentry);
18489 + inode->i_op = iop + AuIop_SYMLINK;
18495 + btail = au_dbtail(dentry);
18496 + inode->i_op = iop + AuIop_OTHER;
18497 + init_special_inode(inode, mode, h_inode->i_rdev);
18500 + AuIOErr("Unknown file type 0%o\n", mode);
18505 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18506 + flags = au_hi_flags(inode, isdir);
18507 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18508 + && au_ftest_hi(flags, HNOTIFY)
18509 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18510 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18511 + au_fclr_hi(flags, HNOTIFY);
18512 + iinfo = au_ii(inode);
18513 + iinfo->ii_btop = btop;
18514 + iinfo->ii_bbot = btail;
18515 + for (bindex = btop; bindex <= btail; bindex++) {
18516 + h_dentry = au_h_dptr(dentry, bindex);
18518 + au_set_h_iptr(inode, bindex,
18519 + au_igrab(d_inode(h_dentry)), flags);
18521 + au_cpup_attr_all(inode, /*force*/1);
18523 + * to force calling aufs_get_acl() every time,
18524 + * do not call cache_no_acl() for aufs inode.
18532 + * successful returns with iinfo write_locked
18534 + * zero: success, matched
18535 + * plus: no error, but unmatched
18537 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18540 + unsigned int gen, igflags;
18541 + aufs_bindex_t bindex, bbot;
18542 + struct inode *h_inode, *h_dinode;
18543 + struct dentry *h_dentry;
18546 + * before this function, if aufs got any iinfo lock, it must be only
18547 + * one, the parent dir.
18548 + * it can happen by UDBA and the obsoleted inode number.
18551 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18555 + ii_write_lock_new_child(inode);
18556 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18557 + h_dinode = d_inode(h_dentry);
18558 + bbot = au_ibbot(inode);
18559 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18560 + h_inode = au_h_iptr(inode, bindex);
18561 + if (!h_inode || h_inode != h_dinode)
18565 + gen = au_iigen(inode, &igflags);
18566 + if (gen == au_digen(dentry)
18567 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18570 + /* fully refresh inode using dentry */
18571 + err = au_refresh_hinode(inode, dentry);
18573 + au_update_iigen(inode, /*half*/0);
18577 + if (unlikely(err))
18578 + ii_write_unlock(inode);
18583 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18584 + unsigned int d_type, ino_t *ino)
18587 + const int isnondir = d_type != DT_DIR;
18589 + /* prevent hardlinked inode number from race condition */
18591 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18592 + if (unlikely(err))
18596 + err = au_xino_read(sb, bindex, h_ino, ino);
18597 + if (unlikely(err))
18598 + goto out_xinondir;
18602 + *ino = au_xino_new_ino(sb);
18603 + if (unlikely(!*ino))
18604 + goto out_xinondir;
18605 + err = au_xino_write(sb, bindex, h_ino, *ino);
18606 + if (unlikely(err))
18607 + goto out_xinondir;
18611 + if (isnondir && idx >= 0)
18612 + au_xinondir_leave(sb, bindex, h_ino, idx);
18617 +/* successful returns with iinfo write_locked */
18618 +/* todo: return with unlocked? */
18619 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18621 + struct inode *inode, *h_inode;
18622 + struct dentry *h_dentry;
18623 + struct super_block *sb;
18624 + ino_t h_ino, ino;
18625 + int err, idx, hlinked;
18626 + aufs_bindex_t btop;
18628 + sb = dentry->d_sb;
18629 + btop = au_dbtop(dentry);
18630 + h_dentry = au_h_dptr(dentry, btop);
18631 + h_inode = d_inode(h_dentry);
18632 + h_ino = h_inode->i_ino;
18633 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18637 + * stop 'race'-ing between hardlinks under different
18641 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18642 + inode = ERR_PTR(err);
18643 + if (unlikely(err))
18647 + err = au_xino_read(sb, btop, h_ino, &ino);
18648 + inode = ERR_PTR(err);
18649 + if (unlikely(err))
18650 + goto out_xinondir;
18653 + ino = au_xino_new_ino(sb);
18654 + if (unlikely(!ino)) {
18655 + inode = ERR_PTR(-EIO);
18656 + goto out_xinondir;
18660 + AuDbg("i%lu\n", (unsigned long)ino);
18661 + inode = au_iget_locked(sb, ino);
18662 + err = PTR_ERR(inode);
18663 + if (IS_ERR(inode))
18664 + goto out_xinondir;
18666 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18667 + if (inode->i_state & I_NEW) {
18668 + ii_write_lock_new_child(inode);
18669 + err = set_inode(inode, dentry);
18671 + unlock_new_inode(inode);
18672 + goto out_xinondir; /* success */
18676 + * iget_failed() calls iput(), but we need to call
18677 + * ii_write_unlock() after iget_failed(). so dirty hack for
18680 + atomic_inc(&inode->i_count);
18681 + iget_failed(inode);
18682 + ii_write_unlock(inode);
18683 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18684 + /* ignore this error */
18686 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18688 + * horrible race condition between lookup, readdir and copyup
18689 + * (or something).
18691 + if (hlinked && idx >= 0)
18692 + au_xinondir_leave(sb, btop, h_ino, idx);
18693 + err = reval_inode(inode, dentry);
18694 + if (unlikely(err < 0)) {
18699 + goto out; /* success */
18700 + else if (hlinked && idx >= 0) {
18701 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18702 + if (unlikely(err)) {
18704 + inode = ERR_PTR(err);
18710 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18711 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18712 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18713 + btop, au_sbtype(h_dentry->d_sb), dentry,
18714 + (unsigned long)h_ino, (unsigned long)ino);
18716 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18719 + if (hlinked && idx >= 0)
18720 + au_xinondir_leave(sb, btop, h_ino, idx);
18726 + inode = ERR_PTR(err);
18728 + if (hlinked && idx >= 0)
18729 + au_xinondir_leave(sb, btop, h_ino, idx);
18734 +/* ---------------------------------------------------------------------- */
18736 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18737 + struct inode *inode)
18740 + struct inode *hi;
18742 + err = au_br_rdonly(au_sbr(sb, bindex));
18744 + /* pseudo-link after flushed may happen out of bounds */
18747 + && au_ibtop(inode) <= bindex
18748 + && bindex <= au_ibbot(inode)) {
18750 + * permission check is unnecessary since vfsub routine
18751 + * will be called later
18753 + hi = au_h_iptr(inode, bindex);
18755 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18761 +int au_test_h_perm(struct inode *h_inode, int mask)
18763 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18765 + return inode_permission(h_inode, mask);
18768 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18770 + if (au_test_nfs(h_inode->i_sb)
18771 + && (mask & MAY_WRITE)
18772 + && S_ISDIR(h_inode->i_mode))
18773 + mask |= MAY_READ; /* force permission check */
18774 + return au_test_h_perm(h_inode, mask);
18776 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18777 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18778 +++ linux/fs/aufs/inode.h 2018-08-12 23:43:05.460124736 +0200
18780 +/* SPDX-License-Identifier: GPL-2.0 */
18782 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18784 + * This program, aufs is free software; you can redistribute it and/or modify
18785 + * it under the terms of the GNU General Public License as published by
18786 + * the Free Software Foundation; either version 2 of the License, or
18787 + * (at your option) any later version.
18789 + * This program is distributed in the hope that it will be useful,
18790 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18791 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18792 + * GNU General Public License for more details.
18794 + * You should have received a copy of the GNU General Public License
18795 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18799 + * inode operations
18802 +#ifndef __AUFS_INODE_H__
18803 +#define __AUFS_INODE_H__
18807 +#include <linux/fsnotify.h>
18808 +#include "rwsem.h"
18812 +struct au_hnotify {
18813 +#ifdef CONFIG_AUFS_HNOTIFY
18814 +#ifdef CONFIG_AUFS_HFSNOTIFY
18815 + /* never use fsnotify_add_vfsmount_mark() */
18816 + struct fsnotify_mark hn_mark;
18818 + struct inode *hn_aufs_inode; /* no get/put */
18820 +} ____cacheline_aligned_in_smp;
18822 +struct au_hinode {
18823 + struct inode *hi_inode;
18824 + aufs_bindex_t hi_id;
18825 +#ifdef CONFIG_AUFS_HNOTIFY
18826 + struct au_hnotify *hi_notify;
18829 + /* reference to the copied-up whiteout with get/put */
18830 + struct dentry *hi_whdentry;
18834 +#define AuIG_HALF_REFRESHED 1
18835 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18836 +#define au_ig_fset(flags, name) \
18837 + do { (flags) |= AuIG_##name; } while (0)
18838 +#define au_ig_fclr(flags, name) \
18839 + do { (flags) &= ~AuIG_##name; } while (0)
18842 + spinlock_t ig_spin;
18843 + __u32 ig_generation, ig_flags;
18848 + struct au_iigen ii_generation;
18849 + struct super_block *ii_hsb1; /* no get/put */
18851 + struct au_rwsem ii_rwsem;
18852 + aufs_bindex_t ii_btop, ii_bbot;
18854 + struct au_hinode *ii_hinode;
18855 + struct au_vdir *ii_vdir;
18858 +struct au_icntnr {
18859 + struct au_iinfo iinfo;
18860 + struct inode vfs_inode;
18861 + struct hlist_bl_node plink;
18862 +} ____cacheline_aligned_in_smp;
18864 +/* au_pin flags */
18865 +#define AuPin_DI_LOCKED 1
18866 +#define AuPin_MNT_WRITE (1 << 1)
18867 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18868 +#define au_fset_pin(flags, name) \
18869 + do { (flags) |= AuPin_##name; } while (0)
18870 +#define au_fclr_pin(flags, name) \
18871 + do { (flags) &= ~AuPin_##name; } while (0)
18875 + struct dentry *dentry;
18876 + unsigned int udba;
18877 + unsigned char lsc_di, lsc_hi, flags;
18878 + aufs_bindex_t bindex;
18881 + struct dentry *parent;
18882 + struct au_hinode *hdir;
18883 + struct vfsmount *h_mnt;
18885 + /* temporary unlock/relock for copyup */
18886 + struct dentry *h_dentry, *h_parent;
18887 + struct au_branch *br;
18888 + struct task_struct *task;
18891 +void au_pin_hdir_unlock(struct au_pin *p);
18892 +int au_pin_hdir_lock(struct au_pin *p);
18893 +int au_pin_hdir_relock(struct au_pin *p);
18894 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18895 +void au_pin_hdir_release(struct au_pin *p);
18897 +/* ---------------------------------------------------------------------- */
18899 +static inline struct au_iinfo *au_ii(struct inode *inode)
18901 + BUG_ON(is_bad_inode(inode));
18902 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18905 +/* ---------------------------------------------------------------------- */
18908 +struct inode *au_igrab(struct inode *inode);
18909 +void au_refresh_iop(struct inode *inode, int force_getattr);
18910 +int au_refresh_hinode_self(struct inode *inode);
18911 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18912 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18913 + unsigned int d_type, ino_t *ino);
18914 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18915 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18916 + struct inode *inode);
18917 +int au_test_h_perm(struct inode *h_inode, int mask);
18918 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18920 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18921 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18923 +#ifdef CONFIG_AUFS_SHWH
18924 + return au_ino(sb, bindex, h_ino, d_type, ino);
18937 +extern struct inode_operations aufs_iop[AuIop_Last],
18938 + aufs_iop_nogetattr[AuIop_Last];
18940 +/* au_wr_dir flags */
18941 +#define AuWrDir_ADD_ENTRY 1
18942 +#define AuWrDir_ISDIR (1 << 1)
18943 +#define AuWrDir_TMPFILE (1 << 2)
18944 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18945 +#define au_fset_wrdir(flags, name) \
18946 + do { (flags) |= AuWrDir_##name; } while (0)
18947 +#define au_fclr_wrdir(flags, name) \
18948 + do { (flags) &= ~AuWrDir_##name; } while (0)
18950 +struct au_wr_dir_args {
18951 + aufs_bindex_t force_btgt;
18952 + unsigned char flags;
18954 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18955 + struct au_wr_dir_args *args);
18957 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18958 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18959 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18960 + unsigned int udba, unsigned char flags);
18961 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18962 + unsigned int udba, unsigned char flags) __must_check;
18963 +int au_do_pin(struct au_pin *pin) __must_check;
18964 +void au_unpin(struct au_pin *pin);
18965 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18967 +#define AuIcpup_DID_CPUP 1
18968 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18969 +#define au_fset_icpup(flags, name) \
18970 + do { (flags) |= AuIcpup_##name; } while (0)
18971 +#define au_fclr_icpup(flags, name) \
18972 + do { (flags) &= ~AuIcpup_##name; } while (0)
18974 +struct au_icpup_args {
18975 + unsigned char flags;
18976 + unsigned char pin_flags;
18977 + aufs_bindex_t btgt;
18978 + unsigned int udba;
18979 + struct au_pin pin;
18980 + struct path h_path;
18981 + struct inode *h_inode;
18984 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18985 + struct au_icpup_args *a);
18987 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18991 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18992 + struct dentry *h_parent, int isdir);
18993 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18995 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18996 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18998 +struct vfsub_aopen_args;
18999 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19000 + struct vfsub_aopen_args *args);
19001 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
19002 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
19003 + struct dentry *dentry);
19004 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
19007 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
19008 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19009 + struct dentry *h_parent, int isdir);
19010 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
19011 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19014 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19015 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19016 + struct inode *dir, struct dentry *dentry,
19017 + unsigned int flags);
19020 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19021 +void au_hiput(struct au_hinode *hinode);
19022 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19023 + struct dentry *h_wh);
19024 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19026 +/* hinode flags */
19027 +#define AuHi_XINO 1
19028 +#define AuHi_HNOTIFY (1 << 1)
19029 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19030 +#define au_fset_hi(flags, name) \
19031 + do { (flags) |= AuHi_##name; } while (0)
19032 +#define au_fclr_hi(flags, name) \
19033 + do { (flags) &= ~AuHi_##name; } while (0)
19035 +#ifndef CONFIG_AUFS_HNOTIFY
19036 +#undef AuHi_HNOTIFY
19037 +#define AuHi_HNOTIFY 0
19040 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19041 + struct inode *h_inode, unsigned int flags);
19043 +void au_update_iigen(struct inode *inode, int half);
19044 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19046 +void au_icntnr_init_once(void *_c);
19047 +void au_hinode_init(struct au_hinode *hinode);
19048 +int au_iinfo_init(struct inode *inode);
19049 +void au_iinfo_fin(struct inode *inode);
19050 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19052 +#ifdef CONFIG_PROC_FS
19054 +int au_plink_maint(struct super_block *sb, int flags);
19056 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19057 +int au_plink_maint_enter(struct super_block *sb);
19058 +#ifdef CONFIG_AUFS_DEBUG
19059 +void au_plink_list(struct super_block *sb);
19061 +AuStubVoid(au_plink_list, struct super_block *sb)
19063 +int au_plink_test(struct inode *inode);
19064 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19065 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19066 + struct dentry *h_dentry);
19067 +void au_plink_put(struct super_block *sb, int verbose);
19068 +void au_plink_clean(struct super_block *sb, int verbose);
19069 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19071 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19072 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19073 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19074 +AuStubVoid(au_plink_list, struct super_block *sb);
19075 +AuStubInt0(au_plink_test, struct inode *inode);
19076 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19077 + struct inode *inode, aufs_bindex_t bindex);
19078 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19079 + struct dentry *h_dentry);
19080 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19081 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19082 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19083 +#endif /* CONFIG_PROC_FS */
19085 +#ifdef CONFIG_AUFS_XATTR
19087 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19088 + unsigned int verbose);
19089 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19090 +void au_xattr_init(struct super_block *sb);
19092 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19093 + int ignore_flags, unsigned int verbose);
19094 +AuStubVoid(au_xattr_init, struct super_block *sb);
19097 +#ifdef CONFIG_FS_POSIX_ACL
19098 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19099 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19102 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19108 +struct au_sxattr {
19112 + const char *name;
19113 + const void *value;
19118 + struct posix_acl *acl;
19123 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19124 + struct au_sxattr *arg);
19127 +/* ---------------------------------------------------------------------- */
19129 +/* lock subclass for iinfo */
19131 + AuLsc_II_CHILD, /* child first */
19132 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19133 + AuLsc_II_CHILD3, /* copyup dirs */
19134 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19135 + AuLsc_II_PARENT2,
19136 + AuLsc_II_PARENT3, /* copyup dirs */
19137 + AuLsc_II_NEW_CHILD
19141 + * ii_read_lock_child, ii_write_lock_child,
19142 + * ii_read_lock_child2, ii_write_lock_child2,
19143 + * ii_read_lock_child3, ii_write_lock_child3,
19144 + * ii_read_lock_parent, ii_write_lock_parent,
19145 + * ii_read_lock_parent2, ii_write_lock_parent2,
19146 + * ii_read_lock_parent3, ii_write_lock_parent3,
19147 + * ii_read_lock_new_child, ii_write_lock_new_child,
19149 +#define AuReadLockFunc(name, lsc) \
19150 +static inline void ii_read_lock_##name(struct inode *i) \
19152 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19155 +#define AuWriteLockFunc(name, lsc) \
19156 +static inline void ii_write_lock_##name(struct inode *i) \
19158 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19161 +#define AuRWLockFuncs(name, lsc) \
19162 + AuReadLockFunc(name, lsc) \
19163 + AuWriteLockFunc(name, lsc)
19165 +AuRWLockFuncs(child, CHILD);
19166 +AuRWLockFuncs(child2, CHILD2);
19167 +AuRWLockFuncs(child3, CHILD3);
19168 +AuRWLockFuncs(parent, PARENT);
19169 +AuRWLockFuncs(parent2, PARENT2);
19170 +AuRWLockFuncs(parent3, PARENT3);
19171 +AuRWLockFuncs(new_child, NEW_CHILD);
19173 +#undef AuReadLockFunc
19174 +#undef AuWriteLockFunc
19175 +#undef AuRWLockFuncs
19177 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19178 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19179 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19181 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19182 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19183 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19185 +/* ---------------------------------------------------------------------- */
19187 +static inline void au_icntnr_init(struct au_icntnr *c)
19189 +#ifdef CONFIG_AUFS_DEBUG
19190 + c->vfs_inode.i_mode = 0;
19194 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19196 + unsigned int gen;
19197 + struct au_iinfo *iinfo;
19198 + struct au_iigen *iigen;
19200 + iinfo = au_ii(inode);
19201 + iigen = &iinfo->ii_generation;
19202 + spin_lock(&iigen->ig_spin);
19204 + *igflags = iigen->ig_flags;
19205 + gen = iigen->ig_generation;
19206 + spin_unlock(&iigen->ig_spin);
19211 +/* tiny test for inode number */
19212 +/* tmpfs generation is too rough */
19213 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19215 + struct au_iinfo *iinfo;
19217 + iinfo = au_ii(inode);
19218 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19219 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19220 + && iinfo->ii_higen == h_inode->i_generation);
19223 +static inline void au_iigen_dec(struct inode *inode)
19225 + struct au_iinfo *iinfo;
19226 + struct au_iigen *iigen;
19228 + iinfo = au_ii(inode);
19229 + iigen = &iinfo->ii_generation;
19230 + spin_lock(&iigen->ig_spin);
19231 + iigen->ig_generation--;
19232 + spin_unlock(&iigen->ig_spin);
19235 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19240 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19246 +/* ---------------------------------------------------------------------- */
19248 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19249 + aufs_bindex_t bindex)
19251 + return iinfo->ii_hinode + bindex;
19254 +static inline int au_is_bad_inode(struct inode *inode)
19256 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19259 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19260 + aufs_bindex_t bindex)
19262 + IiMustAnyLock(inode);
19263 + return au_hinode(au_ii(inode), bindex)->hi_id;
19266 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19268 + IiMustAnyLock(inode);
19269 + return au_ii(inode)->ii_btop;
19272 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19274 + IiMustAnyLock(inode);
19275 + return au_ii(inode)->ii_bbot;
19278 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19280 + IiMustAnyLock(inode);
19281 + return au_ii(inode)->ii_vdir;
19284 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19286 + IiMustAnyLock(inode);
19287 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19290 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19292 + IiMustWriteLock(inode);
19293 + au_ii(inode)->ii_btop = bindex;
19296 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19298 + IiMustWriteLock(inode);
19299 + au_ii(inode)->ii_bbot = bindex;
19302 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19304 + IiMustWriteLock(inode);
19305 + au_ii(inode)->ii_vdir = vdir;
19308 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19310 + IiMustAnyLock(inode);
19311 + return au_hinode(au_ii(inode), bindex);
19314 +/* ---------------------------------------------------------------------- */
19316 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19319 + return pin->parent;
19323 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19325 + if (pin && pin->hdir)
19326 + return pin->hdir->hi_inode;
19330 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19333 + return pin->hdir;
19337 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19340 + pin->dentry = dentry;
19343 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19344 + unsigned char lflag)
19348 + au_fset_pin(pin->flags, DI_LOCKED);
19350 + au_fclr_pin(pin->flags, DI_LOCKED);
19354 +#if 0 /* reserved */
19355 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19358 + dput(pin->parent);
19359 + pin->parent = dget(parent);
19364 +/* ---------------------------------------------------------------------- */
19367 +#ifdef CONFIG_AUFS_HNOTIFY
19368 +struct au_hnotify_op {
19369 + void (*ctl)(struct au_hinode *hinode, int do_set);
19370 + int (*alloc)(struct au_hinode *hinode);
19373 + * if it returns true, the the caller should free hinode->hi_notify,
19374 + * otherwise ->free() frees it.
19376 + int (*free)(struct au_hinode *hinode,
19377 + struct au_hnotify *hn) __must_check;
19379 + void (*fin)(void);
19380 + int (*init)(void);
19382 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19383 + void (*fin_br)(struct au_branch *br);
19384 + int (*init_br)(struct au_branch *br, int perm);
19388 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19389 +void au_hn_free(struct au_hinode *hinode);
19390 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19391 +void au_hn_reset(struct inode *inode, unsigned int flags);
19392 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19393 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19394 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19395 +int au_hnotify_init_br(struct au_branch *br, int perm);
19396 +void au_hnotify_fin_br(struct au_branch *br);
19397 +int __init au_hnotify_init(void);
19398 +void au_hnotify_fin(void);
19401 +extern const struct au_hnotify_op au_hnotify_op;
19404 +void au_hn_init(struct au_hinode *hinode)
19406 + hinode->hi_notify = NULL;
19409 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19411 + return hinode->hi_notify;
19415 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19416 + struct au_hinode *hinode __maybe_unused,
19417 + struct inode *inode __maybe_unused)
19418 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19419 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19420 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19421 + int do_set __maybe_unused)
19422 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19423 + unsigned int flags __maybe_unused)
19424 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19425 + struct au_branch *br __maybe_unused,
19426 + int perm __maybe_unused)
19427 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19428 + int perm __maybe_unused)
19429 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19430 +AuStubInt0(__init au_hnotify_init, void)
19431 +AuStubVoid(au_hnotify_fin, void)
19432 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19433 +#endif /* CONFIG_AUFS_HNOTIFY */
19435 +static inline void au_hn_suspend(struct au_hinode *hdir)
19437 + au_hn_ctl(hdir, /*do_set*/0);
19440 +static inline void au_hn_resume(struct au_hinode *hdir)
19442 + au_hn_ctl(hdir, /*do_set*/1);
19445 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19447 + inode_lock(hdir->hi_inode);
19448 + au_hn_suspend(hdir);
19451 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19452 + unsigned int sc __maybe_unused)
19454 + inode_lock_nested(hdir->hi_inode, sc);
19455 + au_hn_suspend(hdir);
19458 +#if 0 /* unused */
19459 +#include "vfsub.h"
19460 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19463 + inode_lock_shared_nested(hdir->hi_inode, sc);
19464 + au_hn_suspend(hdir);
19468 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19470 + au_hn_resume(hdir);
19471 + inode_unlock(hdir->hi_inode);
19474 +#endif /* __KERNEL__ */
19475 +#endif /* __AUFS_INODE_H__ */
19476 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19477 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19478 +++ linux/fs/aufs/ioctl.c 2018-10-23 12:33:35.599375796 +0200
19480 +// SPDX-License-Identifier: GPL-2.0
19482 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19484 + * This program, aufs is free software; you can redistribute it and/or modify
19485 + * it under the terms of the GNU General Public License as published by
19486 + * the Free Software Foundation; either version 2 of the License, or
19487 + * (at your option) any later version.
19489 + * This program is distributed in the hope that it will be useful,
19490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19492 + * GNU General Public License for more details.
19494 + * You should have received a copy of the GNU General Public License
19495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19500 + * plink-management and readdir in userspace.
19501 + * assist the pathconf(3) wrapper library.
19503 + * File-based Hierarchical Storage Management.
19506 +#include <linux/compat.h>
19507 +#include <linux/file.h>
19510 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19513 + aufs_bindex_t wbi, bindex, bbot;
19514 + struct file *h_file;
19515 + struct super_block *sb;
19516 + struct dentry *root;
19517 + struct au_branch *br;
19518 + struct aufs_wbr_fd wbrfd = {
19519 + .oflags = au_dir_roflags,
19522 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19523 + | O_NOATIME | O_CLOEXEC;
19525 + AuDebugOn(wbrfd.oflags & ~valid);
19528 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19529 + if (unlikely(err)) {
19535 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19536 + wbrfd.oflags |= au_dir_roflags;
19537 + AuDbg("0%o\n", wbrfd.oflags);
19538 + if (unlikely(wbrfd.oflags & ~valid))
19542 + fd = get_unused_fd_flags(0);
19544 + if (unlikely(fd < 0))
19547 + h_file = ERR_PTR(-EINVAL);
19550 + sb = path->dentry->d_sb;
19551 + root = sb->s_root;
19552 + aufs_read_lock(root, AuLock_IR);
19553 + bbot = au_sbbot(sb);
19554 + if (wbrfd.brid >= 0) {
19555 + wbi = au_br_index(sb, wbrfd.brid);
19556 + if (unlikely(wbi < 0 || wbi > bbot))
19560 + h_file = ERR_PTR(-ENOENT);
19561 + br = au_sbr(sb, wbi);
19562 + if (!au_br_writable(br->br_perm)) {
19566 + bindex = wbi + 1;
19568 + for (; bindex <= bbot; bindex++) {
19569 + br = au_sbr(sb, bindex);
19570 + if (au_br_writable(br->br_perm)) {
19572 + br = au_sbr(sb, wbi);
19577 + AuDbg("wbi %d\n", wbi);
19579 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19583 + aufs_read_unlock(root, AuLock_IR);
19584 + err = PTR_ERR(h_file);
19585 + if (IS_ERR(h_file))
19588 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19589 + fd_install(fd, h_file);
19591 + goto out; /* success */
19594 + put_unused_fd(fd);
19600 +/* ---------------------------------------------------------------------- */
19602 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19605 + struct dentry *dentry;
19608 + case AUFS_CTL_RDU:
19609 + case AUFS_CTL_RDU_INO:
19610 + err = au_rdu_ioctl(file, cmd, arg);
19613 + case AUFS_CTL_WBR_FD:
19614 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19617 + case AUFS_CTL_IBUSY:
19618 + err = au_ibusy_ioctl(file, arg);
19621 + case AUFS_CTL_BRINFO:
19622 + err = au_brinfo_ioctl(file, arg);
19625 + case AUFS_CTL_FHSM_FD:
19626 + dentry = file->f_path.dentry;
19627 + if (IS_ROOT(dentry))
19628 + err = au_fhsm_fd(dentry->d_sb, arg);
19634 + /* do not call the lower */
19635 + AuDbg("0x%x\n", cmd);
19643 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19648 + case AUFS_CTL_MVDOWN:
19649 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19652 + case AUFS_CTL_WBR_FD:
19653 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19657 + /* do not call the lower */
19658 + AuDbg("0x%x\n", cmd);
19666 +#ifdef CONFIG_COMPAT
19667 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19668 + unsigned long arg)
19673 + case AUFS_CTL_RDU:
19674 + case AUFS_CTL_RDU_INO:
19675 + err = au_rdu_compat_ioctl(file, cmd, arg);
19678 + case AUFS_CTL_IBUSY:
19679 + err = au_ibusy_compat_ioctl(file, arg);
19682 + case AUFS_CTL_BRINFO:
19683 + err = au_brinfo_compat_ioctl(file, arg);
19687 + err = aufs_ioctl_dir(file, cmd, arg);
19694 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19695 + unsigned long arg)
19697 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19700 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19701 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19702 +++ linux/fs/aufs/i_op_add.c 2018-10-23 12:33:35.596042364 +0200
19704 +// SPDX-License-Identifier: GPL-2.0
19706 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19708 + * This program, aufs is free software; you can redistribute it and/or modify
19709 + * it under the terms of the GNU General Public License as published by
19710 + * the Free Software Foundation; either version 2 of the License, or
19711 + * (at your option) any later version.
19713 + * This program is distributed in the hope that it will be useful,
19714 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19715 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19716 + * GNU General Public License for more details.
19718 + * You should have received a copy of the GNU General Public License
19719 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19723 + * inode operations (add entry)
19729 + * final procedure of adding a new entry, except link(2).
19730 + * remove whiteout, instantiate, copyup the parent dir's times and size
19731 + * and update version.
19732 + * if it failed, re-create the removed whiteout.
19734 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19735 + struct dentry *wh_dentry, struct dentry *dentry)
19738 + aufs_bindex_t bwh;
19739 + struct path h_path;
19740 + struct super_block *sb;
19741 + struct inode *inode, *h_dir;
19742 + struct dentry *wh;
19747 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19748 + IMustLock(h_dir);
19749 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19750 + bwh = au_dbwh(dentry);
19751 + h_path.dentry = wh_dentry;
19752 + h_path.mnt = au_sbr_mnt(sb, bindex);
19753 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19755 + if (unlikely(err))
19759 + inode = au_new_inode(dentry, /*must_new*/1);
19760 + if (!IS_ERR(inode)) {
19761 + d_instantiate(dentry, inode);
19762 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19764 + au_dir_ts(dir, bindex);
19765 + inode_inc_iversion(dir);
19766 + au_fhsm_wrote(sb, bindex, /*force*/0);
19767 + return 0; /* success */
19770 + err = PTR_ERR(inode);
19775 + /* dir inode is locked */
19776 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19777 + rerr = PTR_ERR(wh);
19778 + if (IS_ERR(wh)) {
19779 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19780 + dentry, err, rerr);
19789 +static int au_d_may_add(struct dentry *dentry)
19794 + if (unlikely(d_unhashed(dentry)))
19796 + if (unlikely(d_really_is_positive(dentry)))
19802 + * simple tests for the adding inode operations.
19803 + * following the checks in vfs, plus the parent-child relationship.
19805 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19806 + struct dentry *h_parent, int isdir)
19810 + struct dentry *h_dentry;
19811 + struct inode *h_inode;
19813 + err = -ENAMETOOLONG;
19814 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19817 + h_dentry = au_h_dptr(dentry, bindex);
19818 + if (d_really_is_negative(dentry)) {
19820 + if (unlikely(d_is_positive(h_dentry)))
19823 + /* rename(2) case */
19825 + if (unlikely(d_is_negative(h_dentry)))
19827 + h_inode = d_inode(h_dentry);
19828 + if (unlikely(!h_inode->i_nlink))
19831 + h_mode = h_inode->i_mode;
19834 + if (unlikely(S_ISDIR(h_mode)))
19836 + } else if (unlikely(!S_ISDIR(h_mode))) {
19843 + /* expected parent dir is locked */
19844 + if (unlikely(h_parent != h_dentry->d_parent))
19853 + * initial procedure of adding a new entry.
19854 + * prepare writable branch and the parent dir, lock it,
19855 + * and lookup whiteout for the new entry.
19857 +static struct dentry*
19858 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19859 + struct dentry *src_dentry, struct au_pin *pin,
19860 + struct au_wr_dir_args *wr_dir_args)
19862 + struct dentry *wh_dentry, *h_parent;
19863 + struct super_block *sb;
19864 + struct au_branch *br;
19866 + unsigned int udba;
19867 + aufs_bindex_t bcpup;
19869 + AuDbg("%pd\n", dentry);
19871 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19873 + wh_dentry = ERR_PTR(err);
19874 + if (unlikely(err < 0))
19877 + sb = dentry->d_sb;
19878 + udba = au_opt_udba(sb);
19879 + err = au_pin(pin, dentry, bcpup, udba,
19880 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19881 + wh_dentry = ERR_PTR(err);
19882 + if (unlikely(err))
19885 + h_parent = au_pinned_h_parent(pin);
19886 + if (udba != AuOpt_UDBA_NONE
19887 + && au_dbtop(dentry) == bcpup)
19888 + err = au_may_add(dentry, bcpup, h_parent,
19889 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19890 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19891 + err = -ENAMETOOLONG;
19892 + wh_dentry = ERR_PTR(err);
19893 + if (unlikely(err))
19896 + br = au_sbr(sb, bcpup);
19898 + struct path tmp = {
19899 + .dentry = h_parent,
19900 + .mnt = au_br_mnt(br)
19902 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19905 + wh_dentry = NULL;
19906 + if (bcpup != au_dbwh(dentry))
19907 + goto out; /* success */
19910 + * ENAMETOOLONG here means that if we allowed create such name, then it
19911 + * would not be able to removed in the future. So we don't allow such
19912 + * name here and we don't handle ENAMETOOLONG differently here.
19914 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19917 + if (IS_ERR(wh_dentry))
19920 + return wh_dentry;
19923 +/* ---------------------------------------------------------------------- */
19925 +enum { Mknod, Symlink, Creat };
19926 +struct simple_arg {
19933 + struct vfsub_aopen_args *aopen;
19936 + const char *symname;
19945 +static int add_simple(struct inode *dir, struct dentry *dentry,
19946 + struct simple_arg *arg)
19949 + aufs_bindex_t btop;
19950 + unsigned char created;
19951 + const unsigned char try_aopen
19952 + = (arg->type == Creat && arg->u.c.try_aopen);
19953 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19954 + struct dentry *wh_dentry, *parent;
19955 + struct inode *h_dir;
19956 + struct super_block *sb;
19957 + struct au_branch *br;
19958 + /* to reduce stack size */
19960 + struct au_dtime dt;
19961 + struct au_pin pin;
19962 + struct path h_path;
19963 + struct au_wr_dir_args wr_dir_args;
19966 + AuDbg("%pd\n", dentry);
19970 + a = kmalloc(sizeof(*a), GFP_NOFS);
19971 + if (unlikely(!a))
19973 + a->wr_dir_args.force_btgt = -1;
19974 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19976 + parent = dentry->d_parent; /* dir inode is locked */
19977 + if (!try_aopen) {
19978 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19979 + if (unlikely(err))
19982 + err = au_d_may_add(dentry);
19983 + if (unlikely(err))
19986 + di_write_lock_parent(parent);
19987 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19988 + &a->pin, &a->wr_dir_args);
19989 + err = PTR_ERR(wh_dentry);
19990 + if (IS_ERR(wh_dentry))
19993 + btop = au_dbtop(dentry);
19994 + sb = dentry->d_sb;
19995 + br = au_sbr(sb, btop);
19996 + a->h_path.dentry = au_h_dptr(dentry, btop);
19997 + a->h_path.mnt = au_br_mnt(br);
19998 + h_dir = au_pinned_h_dir(&a->pin);
19999 + switch (arg->type) {
20001 + if (!try_aopen || !h_dir->i_op->atomic_open) {
20002 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
20003 + arg->u.c.want_excl);
20005 + if (!err && try_aopen)
20006 + aopen->file->f_mode |= FMODE_CREATED;
20009 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
20010 + AuDbg("err %d\n", err);
20011 + AuDbgFile(aopen->file);
20012 + created = err >= 0
20013 + && !!(aopen->file->f_mode & FMODE_CREATED);
20017 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20021 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20028 + if (unlikely(err < 0))
20031 + err = epilog(dir, btop, wh_dentry, dentry);
20033 + goto out_unpin; /* success */
20036 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20037 + /* no delegation since it is just created */
20038 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20041 + AuIOErr("%pd revert failure(%d, %d)\n",
20042 + dentry, err, rerr);
20045 + au_dtime_revert(&a->dt);
20047 + if (try_aopen && h_dir->i_op->atomic_open
20048 + && (aopen->file->f_mode & FMODE_OPENED))
20049 + /* aopen->file is still opened */
20050 + au_lcnt_dec(&aopen->br->br_nfiles);
20053 + au_unpin(&a->pin);
20057 + di_write_unlock(parent);
20059 + if (unlikely(err)) {
20060 + au_update_dbtop(dentry);
20064 + aufs_read_unlock(dentry, AuLock_DW);
20071 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20074 + struct simple_arg arg = {
20081 + return add_simple(dir, dentry, &arg);
20084 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20086 + struct simple_arg arg = {
20088 + .u.s.symname = symname
20090 + return add_simple(dir, dentry, &arg);
20093 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20096 + struct simple_arg arg = {
20100 + .want_excl = want_excl
20103 + return add_simple(dir, dentry, &arg);
20106 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20107 + struct vfsub_aopen_args *aopen_args)
20109 + struct simple_arg arg = {
20112 + .mode = aopen_args->create_mode,
20113 + .want_excl = aopen_args->open_flag & O_EXCL,
20114 + .try_aopen = true,
20115 + .aopen = aopen_args
20118 + return add_simple(dir, dentry, &arg);
20121 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20124 + aufs_bindex_t bindex;
20125 + struct super_block *sb;
20126 + struct dentry *parent, *h_parent, *h_dentry;
20127 + struct inode *h_dir, *inode;
20128 + struct vfsmount *h_mnt;
20129 + struct au_wr_dir_args wr_dir_args = {
20130 + .force_btgt = -1,
20131 + .flags = AuWrDir_TMPFILE
20134 + /* copy-up may happen */
20138 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20139 + if (unlikely(err))
20142 + err = au_di_init(dentry);
20143 + if (unlikely(err))
20147 + parent = d_find_any_alias(dir);
20148 + AuDebugOn(!parent);
20149 + di_write_lock_parent(parent);
20150 + if (unlikely(d_inode(parent) != dir))
20153 + err = au_digen_test(parent, au_sigen(sb));
20154 + if (unlikely(err))
20157 + bindex = au_dbtop(parent);
20158 + au_set_dbtop(dentry, bindex);
20159 + au_set_dbbot(dentry, bindex);
20160 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20162 + if (unlikely(err < 0))
20165 + err = -EOPNOTSUPP;
20166 + h_dir = au_h_iptr(dir, bindex);
20167 + if (unlikely(!h_dir->i_op->tmpfile))
20170 + h_mnt = au_sbr_mnt(sb, bindex);
20171 + err = vfsub_mnt_want_write(h_mnt);
20172 + if (unlikely(err))
20175 + h_parent = au_h_dptr(parent, bindex);
20176 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20177 + if (IS_ERR(h_dentry)) {
20178 + err = PTR_ERR(h_dentry);
20182 + au_set_dbtop(dentry, bindex);
20183 + au_set_dbbot(dentry, bindex);
20184 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20185 + inode = au_new_inode(dentry, /*must_new*/1);
20186 + if (IS_ERR(inode)) {
20187 + err = PTR_ERR(inode);
20188 + au_set_h_dptr(dentry, bindex, NULL);
20189 + au_set_dbtop(dentry, -1);
20190 + au_set_dbbot(dentry, -1);
20192 + if (!inode->i_nlink)
20193 + set_nlink(inode, 1);
20194 + d_tmpfile(dentry, inode);
20195 + au_di(dentry)->di_tmpfile = 1;
20197 + /* update without i_mutex */
20198 + if (au_ibtop(dir) == au_dbtop(dentry))
20199 + au_cpup_attr_timesizes(dir);
20204 + vfsub_mnt_drop_write(h_mnt);
20206 + di_write_unlock(parent);
20208 + di_write_unlock(dentry);
20209 + if (unlikely(err)) {
20210 + au_di_fin(dentry);
20211 + dentry->d_fsdata = NULL;
20214 + si_read_unlock(sb);
20216 + inode_unlock(dir);
20220 +/* ---------------------------------------------------------------------- */
20222 +struct au_link_args {
20223 + aufs_bindex_t bdst, bsrc;
20224 + struct au_pin pin;
20225 + struct path h_path;
20226 + struct dentry *src_parent, *parent;
20229 +static int au_cpup_before_link(struct dentry *src_dentry,
20230 + struct au_link_args *a)
20233 + struct dentry *h_src_dentry;
20234 + struct au_cp_generic cpg = {
20235 + .dentry = src_dentry,
20240 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20243 + di_read_lock_parent(a->src_parent, AuLock_IR);
20244 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20245 + if (unlikely(err))
20248 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20249 + err = au_pin(&a->pin, src_dentry, a->bdst,
20250 + au_opt_udba(src_dentry->d_sb),
20251 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20252 + if (unlikely(err))
20255 + err = au_sio_cpup_simple(&cpg);
20256 + au_unpin(&a->pin);
20259 + di_read_unlock(a->src_parent, AuLock_IR);
20263 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20264 + struct au_link_args *a)
20267 + unsigned char plink;
20268 + aufs_bindex_t bbot;
20269 + struct dentry *h_src_dentry;
20270 + struct inode *h_inode, *inode, *delegated;
20271 + struct super_block *sb;
20272 + struct file *h_file;
20276 + sb = src_dentry->d_sb;
20277 + inode = d_inode(src_dentry);
20278 + if (au_ibtop(inode) <= a->bdst)
20279 + h_inode = au_h_iptr(inode, a->bdst);
20280 + if (!h_inode || !h_inode->i_nlink) {
20281 + /* copyup src_dentry as the name of dentry. */
20282 + bbot = au_dbbot(dentry);
20283 + if (bbot < a->bsrc)
20284 + au_set_dbbot(dentry, a->bsrc);
20285 + au_set_h_dptr(dentry, a->bsrc,
20286 + dget(au_h_dptr(src_dentry, a->bsrc)));
20287 + dget(a->h_path.dentry);
20288 + au_set_h_dptr(dentry, a->bdst, NULL);
20289 + AuDbg("temporary d_inode...\n");
20290 + spin_lock(&dentry->d_lock);
20291 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20292 + spin_unlock(&dentry->d_lock);
20293 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20294 + if (IS_ERR(h_file))
20295 + err = PTR_ERR(h_file);
20297 + struct au_cp_generic cpg = {
20298 + .dentry = dentry,
20303 + .flags = AuCpup_KEEPLINO
20305 + err = au_sio_cpup_simple(&cpg);
20306 + au_h_open_post(dentry, a->bsrc, h_file);
20308 + dput(a->h_path.dentry);
20309 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20311 + au_set_h_dptr(dentry, a->bdst,
20312 + a->h_path.dentry);
20314 + spin_lock(&dentry->d_lock);
20315 + dentry->d_inode = NULL; /* restore */
20316 + spin_unlock(&dentry->d_lock);
20317 + AuDbg("temporary d_inode...done\n");
20318 + au_set_h_dptr(dentry, a->bsrc, NULL);
20319 + au_set_dbbot(dentry, bbot);
20321 + /* the inode of src_dentry already exists on a.bdst branch */
20322 + h_src_dentry = d_find_alias(h_inode);
20323 + if (!h_src_dentry && au_plink_test(inode)) {
20325 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20326 + err = PTR_ERR(h_src_dentry);
20327 + if (IS_ERR(h_src_dentry))
20330 + if (unlikely(d_is_negative(h_src_dentry))) {
20331 + dput(h_src_dentry);
20332 + h_src_dentry = NULL;
20336 + if (h_src_dentry) {
20337 + delegated = NULL;
20338 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20339 + &a->h_path, &delegated);
20340 + if (unlikely(err == -EWOULDBLOCK)) {
20341 + pr_warn("cannot retry for NFSv4 delegation"
20342 + " for an internal link\n");
20345 + dput(h_src_dentry);
20347 + AuIOErr("no dentry found for hi%lu on b%d\n",
20348 + h_inode->i_ino, a->bdst);
20353 + if (!err && !plink)
20354 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20361 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20362 + struct dentry *dentry)
20365 + struct au_dtime dt;
20366 + struct au_link_args *a;
20367 + struct dentry *wh_dentry, *h_src_dentry;
20368 + struct inode *inode, *delegated;
20369 + struct super_block *sb;
20370 + struct au_wr_dir_args wr_dir_args = {
20371 + /* .force_btgt = -1, */
20372 + .flags = AuWrDir_ADD_ENTRY
20376 + inode = d_inode(src_dentry);
20377 + IMustLock(inode);
20380 + a = kzalloc(sizeof(*a), GFP_NOFS);
20381 + if (unlikely(!a))
20384 + a->parent = dentry->d_parent; /* dir inode is locked */
20385 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20386 + AuLock_NOPLM | AuLock_GEN);
20387 + if (unlikely(err))
20389 + err = au_d_linkable(src_dentry);
20390 + if (unlikely(err))
20392 + err = au_d_may_add(dentry);
20393 + if (unlikely(err))
20396 + a->src_parent = dget_parent(src_dentry);
20397 + wr_dir_args.force_btgt = au_ibtop(inode);
20399 + di_write_lock_parent(a->parent);
20400 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20401 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20403 + err = PTR_ERR(wh_dentry);
20404 + if (IS_ERR(wh_dentry))
20408 + sb = dentry->d_sb;
20409 + a->bdst = au_dbtop(dentry);
20410 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20411 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20412 + a->bsrc = au_ibtop(inode);
20413 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20414 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20415 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20416 + if (!h_src_dentry) {
20417 + a->bsrc = au_dbtop(src_dentry);
20418 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20419 + AuDebugOn(!h_src_dentry);
20420 + } else if (IS_ERR(h_src_dentry)) {
20421 + err = PTR_ERR(h_src_dentry);
20426 + * aufs doesn't touch the credential so
20427 + * security_dentry_create_files_as() is unnecessary.
20429 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20430 + if (a->bdst < a->bsrc
20431 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20432 + err = au_cpup_or_link(src_dentry, dentry, a);
20434 + delegated = NULL;
20435 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20436 + &a->h_path, &delegated);
20437 + if (unlikely(err == -EWOULDBLOCK)) {
20438 + pr_warn("cannot retry for NFSv4 delegation"
20439 + " for an internal link\n");
20443 + dput(h_src_dentry);
20446 + * copyup src_dentry to the branch we process,
20447 + * and then link(2) to it.
20449 + dput(h_src_dentry);
20450 + if (a->bdst < a->bsrc
20451 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20452 + au_unpin(&a->pin);
20453 + di_write_unlock(a->parent);
20454 + err = au_cpup_before_link(src_dentry, a);
20455 + di_write_lock_parent(a->parent);
20457 + err = au_pin(&a->pin, dentry, a->bdst,
20459 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20460 + if (unlikely(err))
20464 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20466 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20467 + delegated = NULL;
20468 + err = vfsub_link(h_src_dentry,
20469 + au_pinned_h_dir(&a->pin),
20470 + &a->h_path, &delegated);
20471 + if (unlikely(err == -EWOULDBLOCK)) {
20472 + pr_warn("cannot retry"
20473 + " for NFSv4 delegation"
20474 + " for an internal link\n");
20480 + if (unlikely(err))
20484 + a->h_path.dentry = wh_dentry;
20485 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20487 + if (unlikely(err))
20491 + au_dir_ts(dir, a->bdst);
20492 + inode_inc_iversion(dir);
20493 + inc_nlink(inode);
20494 + inode->i_ctime = dir->i_ctime;
20495 + d_instantiate(dentry, au_igrab(inode));
20496 + if (d_unhashed(a->h_path.dentry))
20497 + /* some filesystem calls d_drop() */
20499 + /* some filesystems consume an inode even hardlink */
20500 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20501 + goto out_unpin; /* success */
20504 + /* no delegation since it is just created */
20505 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20506 + /*delegated*/NULL, /*force*/0);
20507 + if (unlikely(rerr)) {
20508 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20511 + au_dtime_revert(&dt);
20513 + au_unpin(&a->pin);
20517 + di_write_unlock(a->parent);
20518 + dput(a->src_parent);
20520 + if (unlikely(err)) {
20521 + au_update_dbtop(dentry);
20524 + aufs_read_and_write_unlock2(dentry, src_dentry);
20532 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20535 + aufs_bindex_t bindex;
20536 + unsigned char diropq;
20537 + struct path h_path;
20538 + struct dentry *wh_dentry, *parent, *opq_dentry;
20539 + struct inode *h_inode;
20540 + struct super_block *sb;
20542 + struct au_pin pin;
20543 + struct au_dtime dt;
20544 + } *a; /* reduce the stack usage */
20545 + struct au_wr_dir_args wr_dir_args = {
20546 + .force_btgt = -1,
20547 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20553 + a = kmalloc(sizeof(*a), GFP_NOFS);
20554 + if (unlikely(!a))
20557 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20558 + if (unlikely(err))
20560 + err = au_d_may_add(dentry);
20561 + if (unlikely(err))
20564 + parent = dentry->d_parent; /* dir inode is locked */
20565 + di_write_lock_parent(parent);
20566 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20567 + &a->pin, &wr_dir_args);
20568 + err = PTR_ERR(wh_dentry);
20569 + if (IS_ERR(wh_dentry))
20572 + sb = dentry->d_sb;
20573 + bindex = au_dbtop(dentry);
20574 + h_path.dentry = au_h_dptr(dentry, bindex);
20575 + h_path.mnt = au_sbr_mnt(sb, bindex);
20576 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20577 + if (unlikely(err))
20580 + /* make the dir opaque */
20582 + h_inode = d_inode(h_path.dentry);
20584 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20585 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20586 + opq_dentry = au_diropq_create(dentry, bindex);
20587 + inode_unlock(h_inode);
20588 + err = PTR_ERR(opq_dentry);
20589 + if (IS_ERR(opq_dentry))
20591 + dput(opq_dentry);
20595 + err = epilog(dir, bindex, wh_dentry, dentry);
20598 + goto out_unpin; /* success */
20603 + AuLabel(revert opq);
20604 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20605 + rerr = au_diropq_remove(dentry, bindex);
20606 + inode_unlock(h_inode);
20608 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20609 + dentry, err, rerr);
20615 + AuLabel(revert dir);
20616 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20618 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20619 + dentry, err, rerr);
20622 + au_dtime_revert(&a->dt);
20624 + au_unpin(&a->pin);
20627 + di_write_unlock(parent);
20629 + if (unlikely(err)) {
20630 + au_update_dbtop(dentry);
20633 + aufs_read_unlock(dentry, AuLock_DW);
20639 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20640 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20641 +++ linux/fs/aufs/i_op.c 2018-10-23 12:33:35.596042364 +0200
20643 +// SPDX-License-Identifier: GPL-2.0
20645 + * Copyright (C) 2005-2018 Junjiro R. Okajima
20647 + * This program, aufs is free software; you can redistribute it and/or modify
20648 + * it under the terms of the GNU General Public License as published by
20649 + * the Free Software Foundation; either version 2 of the License, or
20650 + * (at your option) any later version.
20652 + * This program is distributed in the hope that it will be useful,
20653 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20654 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20655 + * GNU General Public License for more details.
20657 + * You should have received a copy of the GNU General Public License
20658 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20662 + * inode operations (except add/del/rename)
20665 +#include <linux/device_cgroup.h>
20666 +#include <linux/fs_stack.h>
20667 +#include <linux/namei.h>
20668 +#include <linux/security.h>
20671 +static int h_permission(struct inode *h_inode, int mask,
20672 + struct path *h_path, int brperm)
20675 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20678 + if (write_mask && IS_IMMUTABLE(h_inode))
20682 + if (((mask & MAY_EXEC)
20683 + && S_ISREG(h_inode->i_mode)
20684 + && (path_noexec(h_path)
20685 + || !(h_inode->i_mode & 0111))))
20689 + * - skip the lower fs test in the case of write to ro branch.
20690 + * - nfs dir permission write check is optimized, but a policy for
20691 + * link/rename requires a real check.
20692 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20693 + * in this case, generic_permission() returns -EOPNOTSUPP.
20695 + if ((write_mask && !au_br_writable(brperm))
20696 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20697 + && write_mask && !(mask & MAY_READ))
20698 + || !h_inode->i_op->permission) {
20699 + /* AuLabel(generic_permission); */
20700 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20701 + err = generic_permission(h_inode, mask);
20702 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20703 + err = h_inode->i_op->permission(h_inode, mask);
20706 + /* AuLabel(h_inode->permission); */
20707 + err = h_inode->i_op->permission(h_inode, mask);
20712 + err = devcgroup_inode_permission(h_inode, mask);
20714 + err = security_inode_permission(h_inode, mask);
20718 + /* todo: do we need to call ima_path_check()? */
20719 + struct path h_path = {
20723 + err = ima_path_check(&h_path,
20724 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20725 + IMA_COUNT_LEAVE);
20733 +static int aufs_permission(struct inode *inode, int mask)
20736 + aufs_bindex_t bindex, bbot;
20737 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20738 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20739 + struct inode *h_inode;
20740 + struct super_block *sb;
20741 + struct au_branch *br;
20743 + /* todo: support rcu-walk? */
20744 + if (mask & MAY_NOT_BLOCK)
20747 + sb = inode->i_sb;
20748 + si_read_lock(sb, AuLock_FLUSH);
20749 + ii_read_lock_child(inode);
20751 + err = au_iigen_test(inode, au_sigen(sb));
20752 + if (unlikely(err))
20758 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20759 + err = au_busy_or_stale();
20760 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20761 + if (unlikely(!h_inode
20762 + || (h_inode->i_mode & S_IFMT)
20763 + != (inode->i_mode & S_IFMT)))
20767 + bindex = au_ibtop(inode);
20768 + br = au_sbr(sb, bindex);
20769 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20772 + && !special_file(h_inode->i_mode)) {
20773 + /* test whether the upper writable branch exists */
20775 + for (; bindex >= 0; bindex--)
20776 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20784 + /* non-write to dir */
20786 + bbot = au_ibbot(inode);
20787 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20788 + h_inode = au_h_iptr(inode, bindex);
20790 + err = au_busy_or_stale();
20791 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20794 + br = au_sbr(sb, bindex);
20795 + err = h_permission(h_inode, mask, &br->br_path,
20801 + ii_read_unlock(inode);
20802 + si_read_unlock(sb);
20806 +/* ---------------------------------------------------------------------- */
20808 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20809 + unsigned int flags)
20811 + struct dentry *ret, *parent;
20812 + struct inode *inode;
20813 + struct super_block *sb;
20814 + int err, npositive;
20818 + /* todo: support rcu-walk? */
20819 + ret = ERR_PTR(-ECHILD);
20820 + if (flags & LOOKUP_RCU)
20823 + ret = ERR_PTR(-ENAMETOOLONG);
20824 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20828 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20829 + ret = ERR_PTR(err);
20830 + if (unlikely(err))
20833 + err = au_di_init(dentry);
20834 + ret = ERR_PTR(err);
20835 + if (unlikely(err))
20839 + npositive = 0; /* suppress a warning */
20840 + parent = dentry->d_parent; /* dir inode is locked */
20841 + di_read_lock_parent(parent, AuLock_IR);
20842 + err = au_alive_dir(parent);
20844 + err = au_digen_test(parent, au_sigen(sb));
20846 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20847 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20848 + AuLkup_ALLOW_NEG);
20851 + di_read_unlock(parent, AuLock_IR);
20852 + ret = ERR_PTR(err);
20853 + if (unlikely(err < 0))
20857 + inode = au_new_inode(dentry, /*must_new*/0);
20858 + if (IS_ERR(inode)) {
20859 + ret = (void *)inode;
20866 + atomic_inc(&inode->i_count);
20867 + ret = d_splice_alias(inode, dentry);
20869 + if (unlikely(d_need_lookup(dentry))) {
20870 + spin_lock(&dentry->d_lock);
20871 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20872 + spin_unlock(&dentry->d_lock);
20876 + if (!IS_ERR(ret)) {
20878 + if (ret && ret != dentry)
20879 + ii_write_unlock(inode);
20881 + ii_write_unlock(inode);
20888 + di_write_unlock(dentry);
20890 + si_read_unlock(sb);
20895 +/* ---------------------------------------------------------------------- */
20898 + * very dirty and complicated aufs ->atomic_open().
20899 + * aufs_atomic_open()
20900 + * + au_aopen_or_create()
20902 + * + vfsub_atomic_open()
20903 + * + branch fs ->atomic_open()
20904 + * may call the actual 'open' for h_file
20905 + * + inc br_nfiles only if opened
20906 + * + au_aopen_no_open() or au_aopen_do_open()
20908 + * au_aopen_do_open()
20909 + * + finish_open()
20910 + * + au_do_aopen()
20911 + * + au_do_open() the body of all 'open'
20912 + * + au_do_open_nondir()
20913 + * set the passed h_file
20915 + * au_aopen_no_open()
20916 + * + finish_no_open()
20919 +struct aopen_node {
20920 + struct hlist_bl_node hblist;
20921 + struct file *file, *h_file;
20924 +static int au_do_aopen(struct inode *inode, struct file *file)
20926 + struct hlist_bl_head *aopen;
20927 + struct hlist_bl_node *pos;
20928 + struct aopen_node *node;
20929 + struct au_do_open_args args = {
20931 + .open = au_do_open_nondir
20934 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20935 + hlist_bl_lock(aopen);
20936 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20937 + if (node->file == file) {
20938 + args.h_file = node->h_file;
20941 + hlist_bl_unlock(aopen);
20942 + /* AuDebugOn(!args.h_file); */
20944 + return au_do_open(file, &args);
20947 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20948 + struct aopen_node *aopen_node)
20951 + struct hlist_bl_head *aopen;
20954 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20955 + au_hbl_add(&aopen_node->hblist, aopen);
20956 + err = finish_open(file, dentry, au_do_aopen);
20957 + au_hbl_del(&aopen_node->hblist, aopen);
20958 + /* AuDbgFile(file); */
20959 + AuDbg("%pd%s%s\n", dentry,
20960 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20961 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20967 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20973 + err = finish_no_open(file, dentry);
20979 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20980 + struct file *file, unsigned int open_flag,
20981 + umode_t create_mode)
20983 + int err, did_open;
20984 + unsigned int lkup_flags;
20985 + aufs_bindex_t bindex;
20986 + struct super_block *sb;
20987 + struct dentry *parent, *d;
20988 + struct vfsub_aopen_args args = {
20989 + .open_flag = open_flag,
20990 + .create_mode = create_mode
20992 + struct aopen_node aopen_node = {
20997 + AuDbg("open_flag 0%o\n", open_flag);
20998 + AuDbgDentry(dentry);
21001 + if (!au_di(dentry)) {
21002 + lkup_flags = LOOKUP_OPEN;
21003 + if (open_flag & O_CREAT)
21004 + lkup_flags |= LOOKUP_CREATE;
21005 + d = aufs_lookup(dir, dentry, lkup_flags);
21007 + err = PTR_ERR(d);
21012 + * obsoleted dentry found.
21013 + * another error will be returned later.
21019 + AuDbgDentry(dentry);
21022 + if (d_is_positive(dentry)
21023 + || d_unhashed(dentry)
21024 + || d_unlinked(dentry)
21025 + || !(open_flag & O_CREAT)) {
21026 + err = au_aopen_no_open(file, dentry);
21027 + goto out; /* success */
21030 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21031 + if (unlikely(err))
21034 + sb = dentry->d_sb;
21035 + parent = dentry->d_parent; /* dir is locked */
21036 + di_write_lock_parent(parent);
21037 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21038 + if (unlikely(err < 0))
21041 + AuDbgDentry(dentry);
21042 + if (d_is_positive(dentry)) {
21043 + err = au_aopen_no_open(file, dentry);
21044 + goto out_parent; /* success */
21047 + args.file = alloc_empty_file(file->f_flags, current_cred());
21048 + err = PTR_ERR(args.file);
21049 + if (IS_ERR(args.file))
21052 + bindex = au_dbtop(dentry);
21053 + err = au_aopen_or_create(dir, dentry, &args);
21055 + AuDbgFile(args.file);
21056 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21057 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21060 + args.file = NULL;
21062 + di_write_unlock(parent);
21063 + di_write_unlock(dentry);
21064 + if (unlikely(err < 0)) {
21071 + err = au_aopen_no_open(file, dentry);
21073 + aopen_node.h_file = args.file;
21074 + err = au_aopen_do_open(file, dentry, &aopen_node);
21076 + if (unlikely(err < 0)) {
21080 + au_lcnt_dec(&args.br->br_nfiles);
21082 + goto out_sb; /* success */
21085 + di_write_unlock(parent);
21086 + di_write_unlock(dentry);
21088 + si_read_unlock(sb);
21096 +/* ---------------------------------------------------------------------- */
21098 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21099 + const unsigned char add_entry, aufs_bindex_t bcpup,
21100 + aufs_bindex_t btop)
21103 + struct dentry *h_parent;
21104 + struct inode *h_dir;
21107 + IMustLock(d_inode(parent));
21109 + di_write_lock_parent(parent);
21112 + if (!au_h_dptr(parent, bcpup)) {
21113 + if (btop > bcpup)
21114 + err = au_cpup_dirs(dentry, bcpup);
21115 + else if (btop < bcpup)
21116 + err = au_cpdown_dirs(dentry, bcpup);
21120 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21121 + h_parent = au_h_dptr(parent, bcpup);
21122 + h_dir = d_inode(h_parent);
21123 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21124 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21125 + /* todo: no unlock here */
21126 + inode_unlock_shared(h_dir);
21128 + AuDbg("bcpup %d\n", bcpup);
21130 + if (d_really_is_negative(dentry))
21131 + au_set_h_dptr(dentry, btop, NULL);
21132 + au_update_dbrange(dentry, /*do_put_zero*/0);
21137 + di_write_unlock(parent);
21139 + err = bcpup; /* success */
21146 + * decide the branch and the parent dir where we will create a new entry.
21147 + * returns new bindex or an error.
21148 + * copyup the parent dir if needed.
21150 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21151 + struct au_wr_dir_args *args)
21154 + unsigned int flags;
21155 + aufs_bindex_t bcpup, btop, src_btop;
21156 + const unsigned char add_entry
21157 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21158 + | au_ftest_wrdir(args->flags, TMPFILE);
21159 + struct super_block *sb;
21160 + struct dentry *parent;
21161 + struct au_sbinfo *sbinfo;
21163 + sb = dentry->d_sb;
21164 + sbinfo = au_sbi(sb);
21165 + parent = dget_parent(dentry);
21166 + btop = au_dbtop(dentry);
21168 + if (args->force_btgt < 0) {
21169 + if (src_dentry) {
21170 + src_btop = au_dbtop(src_dentry);
21171 + if (src_btop < btop)
21172 + bcpup = src_btop;
21173 + } else if (add_entry) {
21175 + if (au_ftest_wrdir(args->flags, ISDIR))
21176 + au_fset_wbr(flags, DIR);
21177 + err = AuWbrCreate(sbinfo, dentry, flags);
21181 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21183 + err = AuWbrCopyup(sbinfo, dentry);
21185 + if (!IS_ROOT(dentry)) {
21186 + di_read_lock_parent(parent, !AuLock_IR);
21187 + err = AuWbrCopyup(sbinfo, dentry);
21188 + di_read_unlock(parent, !AuLock_IR);
21190 + err = AuWbrCopyup(sbinfo, dentry);
21193 + if (unlikely(err < 0))
21197 + bcpup = args->force_btgt;
21198 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21201 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21203 + if (bcpup == btop)
21204 + goto out; /* success */
21206 + /* copyup the new parent into the branch we process */
21207 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21209 + if (d_really_is_negative(dentry)) {
21210 + au_set_h_dptr(dentry, btop, NULL);
21211 + au_set_dbtop(dentry, bcpup);
21212 + au_set_dbbot(dentry, bcpup);
21214 + AuDebugOn(add_entry
21215 + && !au_ftest_wrdir(args->flags, TMPFILE)
21216 + && !au_h_dptr(dentry, bcpup));
21224 +/* ---------------------------------------------------------------------- */
21226 +void au_pin_hdir_unlock(struct au_pin *p)
21229 + au_hn_inode_unlock(p->hdir);
21232 +int au_pin_hdir_lock(struct au_pin *p)
21240 + /* even if an error happens later, keep this lock */
21241 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21244 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21249 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21250 + p->h_parent, p->br);
21256 +int au_pin_hdir_relock(struct au_pin *p)
21259 + struct inode *h_i;
21260 + struct dentry *h_d[] = {
21265 + err = au_pin_hdir_lock(p);
21266 + if (unlikely(err))
21269 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21272 + if (d_is_positive(h_d[i])) {
21273 + h_i = d_inode(h_d[i]);
21274 + err = !h_i->i_nlink;
21282 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21284 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21285 + p->hdir->hi_inode->i_rwsem.owner = task;
21289 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21292 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21293 + p->lsc_hi, 0, NULL, _RET_IP_);
21294 + au_pin_hdir_set_owner(p, current);
21298 +void au_pin_hdir_release(struct au_pin *p)
21301 + au_pin_hdir_set_owner(p, p->task);
21302 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21306 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21308 + if (pin && pin->parent)
21309 + return au_h_dptr(pin->parent, pin->bindex);
21313 +void au_unpin(struct au_pin *p)
21316 + au_pin_hdir_unlock(p);
21317 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21318 + vfsub_mnt_drop_write(p->h_mnt);
21322 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21323 + di_read_unlock(p->parent, AuLock_IR);
21324 + iput(p->hdir->hi_inode);
21326 + p->parent = NULL;
21329 + /* do not clear p->task */
21332 +int au_do_pin(struct au_pin *p)
21335 + struct super_block *sb;
21336 + struct inode *h_dir;
21339 + sb = p->dentry->d_sb;
21340 + p->br = au_sbr(sb, p->bindex);
21341 + if (IS_ROOT(p->dentry)) {
21342 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21343 + p->h_mnt = au_br_mnt(p->br);
21344 + err = vfsub_mnt_want_write(p->h_mnt);
21345 + if (unlikely(err)) {
21346 + au_fclr_pin(p->flags, MNT_WRITE);
21353 + p->h_dentry = NULL;
21354 + if (p->bindex <= au_dbbot(p->dentry))
21355 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21357 + p->parent = dget_parent(p->dentry);
21358 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21359 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21362 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21363 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21365 + h_dir = p->hdir->hi_inode;
21369 + * if DI_LOCKED is not set, then p->parent may be different
21370 + * and h_parent can be NULL.
21372 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21374 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21375 + di_read_unlock(p->parent, AuLock_IR);
21377 + p->parent = NULL;
21381 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21382 + p->h_mnt = au_br_mnt(p->br);
21383 + err = vfsub_mnt_want_write(p->h_mnt);
21384 + if (unlikely(err)) {
21385 + au_fclr_pin(p->flags, MNT_WRITE);
21386 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21387 + di_read_unlock(p->parent, AuLock_IR);
21389 + p->parent = NULL;
21395 + err = au_pin_hdir_lock(p);
21397 + goto out; /* success */
21402 + pr_err("err %d\n", err);
21403 + err = au_busy_or_stale();
21408 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21409 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21410 + unsigned int udba, unsigned char flags)
21412 + p->dentry = dentry;
21414 + p->lsc_di = lsc_di;
21415 + p->lsc_hi = lsc_hi;
21416 + p->flags = flags;
21417 + p->bindex = bindex;
21419 + p->parent = NULL;
21423 + p->h_dentry = NULL;
21424 + p->h_parent = NULL;
21426 + p->task = current;
21429 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21430 + unsigned int udba, unsigned char flags)
21432 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21434 + return au_do_pin(pin);
21437 +/* ---------------------------------------------------------------------- */
21440 + * ->setattr() and ->getattr() are called in various cases.
21441 + * chmod, stat: dentry is revalidated.
21442 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21444 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21446 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21447 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21450 + struct dentry *parent;
21453 + if (au_digen_test(dentry, sigen)) {
21454 + parent = dget_parent(dentry);
21455 + di_read_lock_parent(parent, AuLock_IR);
21456 + err = au_refresh_dentry(dentry, parent);
21457 + di_read_unlock(parent, AuLock_IR);
21465 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21466 + struct au_icpup_args *a)
21470 + aufs_bindex_t btop, ibtop;
21471 + struct dentry *hi_wh, *parent;
21472 + struct inode *inode;
21473 + struct au_wr_dir_args wr_dir_args = {
21474 + .force_btgt = -1,
21478 + if (d_is_dir(dentry))
21479 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21480 + /* plink or hi_wh() case */
21481 + btop = au_dbtop(dentry);
21482 + inode = d_inode(dentry);
21483 + ibtop = au_ibtop(inode);
21484 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21485 + wr_dir_args.force_btgt = ibtop;
21486 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21487 + if (unlikely(err < 0))
21491 + au_fset_icpup(a->flags, DID_CPUP);
21494 + a->pin_flags = AuPin_MNT_WRITE;
21496 + if (!IS_ROOT(dentry)) {
21497 + au_fset_pin(a->pin_flags, DI_LOCKED);
21498 + parent = dget_parent(dentry);
21499 + di_write_lock_parent(parent);
21502 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21503 + if (unlikely(err))
21507 + a->h_path.dentry = au_h_dptr(dentry, btop);
21508 + a->h_inode = d_inode(a->h_path.dentry);
21509 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21510 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21511 + if (ia->ia_size < i_size_read(a->h_inode))
21512 + sz = ia->ia_size;
21513 + inode_unlock_shared(a->h_inode);
21517 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21518 + hi_wh = au_hi_wh(inode, a->btgt);
21520 + struct au_cp_generic cpg = {
21521 + .dentry = dentry,
21527 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21528 + if (unlikely(err))
21530 + hi_wh = au_hi_wh(inode, a->btgt);
21531 + /* todo: revalidate hi_wh? */
21536 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21537 + di_downgrade_lock(parent, AuLock_IR);
21541 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21542 + goto out; /* success */
21544 + if (!d_unhashed(dentry)) {
21545 + struct au_cp_generic cpg = {
21546 + .dentry = dentry,
21551 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21553 + err = au_sio_cpup_simple(&cpg);
21555 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21556 + } else if (!hi_wh)
21557 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21559 + a->h_path.dentry = hi_wh; /* do not dget here */
21562 + a->h_inode = d_inode(a->h_path.dentry);
21564 + goto out; /* success */
21565 + au_unpin(&a->pin);
21568 + di_write_unlock(parent);
21573 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21577 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21580 + struct inode *inode, *delegated;
21581 + struct super_block *sb;
21582 + struct file *file;
21583 + struct au_icpup_args *a;
21585 + inode = d_inode(dentry);
21586 + IMustLock(inode);
21588 + err = setattr_prepare(dentry, ia);
21589 + if (unlikely(err))
21593 + a = kzalloc(sizeof(*a), GFP_NOFS);
21594 + if (unlikely(!a))
21597 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21598 + ia->ia_valid &= ~ATTR_MODE;
21601 + sb = dentry->d_sb;
21602 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21603 + if (unlikely(err))
21606 + if (ia->ia_valid & ATTR_FILE) {
21607 + /* currently ftruncate(2) only */
21608 + AuDebugOn(!d_is_reg(dentry));
21609 + file = ia->ia_file;
21610 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21612 + if (unlikely(err))
21614 + ia->ia_file = au_hf_top(file);
21615 + a->udba = AuOpt_UDBA_NONE;
21617 + /* fchmod() doesn't pass ia_file */
21618 + a->udba = au_opt_udba(sb);
21619 + di_write_lock_child(dentry);
21620 + /* no d_unlinked(), to set UDBA_NONE for root */
21621 + if (d_unhashed(dentry))
21622 + a->udba = AuOpt_UDBA_NONE;
21623 + if (a->udba != AuOpt_UDBA_NONE) {
21624 + AuDebugOn(IS_ROOT(dentry));
21625 + err = au_reval_for_attr(dentry, au_sigen(sb));
21626 + if (unlikely(err))
21631 + err = au_pin_and_icpup(dentry, ia, a);
21632 + if (unlikely(err < 0))
21634 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21635 + ia->ia_file = NULL;
21636 + ia->ia_valid &= ~ATTR_FILE;
21639 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21640 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21641 + == (ATTR_MODE | ATTR_CTIME)) {
21642 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21643 + if (unlikely(err))
21645 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21646 + && (ia->ia_valid & ATTR_CTIME)) {
21647 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21648 + if (unlikely(err))
21652 + if (ia->ia_valid & ATTR_SIZE) {
21655 + if (ia->ia_size < i_size_read(inode))
21657 + truncate_setsize(inode, ia->ia_size);
21660 + if (ia->ia_valid & ATTR_FILE)
21662 + inode_unlock(a->h_inode);
21663 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21664 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21666 + delegated = NULL;
21668 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21670 + err = break_deleg_wait(&delegated);
21678 + * regardless aufs 'acl' option setting.
21679 + * why don't all acl-aware fs call this func from their ->setattr()?
21681 + if (!err && (ia->ia_valid & ATTR_MODE))
21682 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21684 + au_cpup_attr_changeable(inode);
21687 + inode_unlock(a->h_inode);
21688 + au_unpin(&a->pin);
21689 + if (unlikely(err))
21690 + au_update_dbtop(dentry);
21692 + di_write_unlock(dentry);
21694 + fi_write_unlock(file);
21695 + ia->ia_file = file;
21696 + ia->ia_valid |= ATTR_FILE;
21699 + si_read_unlock(sb);
21707 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21708 +static int au_h_path_to_set_attr(struct dentry *dentry,
21709 + struct au_icpup_args *a, struct path *h_path)
21712 + struct super_block *sb;
21714 + sb = dentry->d_sb;
21715 + a->udba = au_opt_udba(sb);
21716 + /* no d_unlinked(), to set UDBA_NONE for root */
21717 + if (d_unhashed(dentry))
21718 + a->udba = AuOpt_UDBA_NONE;
21719 + if (a->udba != AuOpt_UDBA_NONE) {
21720 + AuDebugOn(IS_ROOT(dentry));
21721 + err = au_reval_for_attr(dentry, au_sigen(sb));
21722 + if (unlikely(err))
21725 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21726 + if (unlikely(err < 0))
21729 + h_path->dentry = a->h_path.dentry;
21730 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21736 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21737 + struct au_sxattr *arg)
21740 + struct path h_path;
21741 + struct super_block *sb;
21742 + struct au_icpup_args *a;
21743 + struct inode *h_inode;
21745 + IMustLock(inode);
21748 + a = kzalloc(sizeof(*a), GFP_NOFS);
21749 + if (unlikely(!a))
21752 + sb = dentry->d_sb;
21753 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21754 + if (unlikely(err))
21757 + h_path.dentry = NULL; /* silence gcc */
21758 + di_write_lock_child(dentry);
21759 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21760 + if (unlikely(err))
21763 + inode_unlock(a->h_inode);
21764 + switch (arg->type) {
21765 + case AU_XATTR_SET:
21766 + AuDebugOn(d_is_negative(h_path.dentry));
21767 + err = vfsub_setxattr(h_path.dentry,
21768 + arg->u.set.name, arg->u.set.value,
21769 + arg->u.set.size, arg->u.set.flags);
21772 + err = -EOPNOTSUPP;
21773 + h_inode = d_inode(h_path.dentry);
21774 + if (h_inode->i_op->set_acl)
21775 + /* this will call posix_acl_update_mode */
21776 + err = h_inode->i_op->set_acl(h_inode,
21777 + arg->u.acl_set.acl,
21778 + arg->u.acl_set.type);
21782 + au_cpup_attr_timesizes(inode);
21784 + au_unpin(&a->pin);
21785 + if (unlikely(err))
21786 + au_update_dbtop(dentry);
21789 + di_write_unlock(dentry);
21790 + si_read_unlock(sb);
21799 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21800 + unsigned int nlink)
21804 + inode->i_mode = st->mode;
21805 + /* don't i_[ug]id_write() here */
21806 + inode->i_uid = st->uid;
21807 + inode->i_gid = st->gid;
21808 + inode->i_atime = st->atime;
21809 + inode->i_mtime = st->mtime;
21810 + inode->i_ctime = st->ctime;
21812 + au_cpup_attr_nlink(inode, /*force*/0);
21813 + if (S_ISDIR(inode->i_mode)) {
21814 + n = inode->i_nlink;
21817 + smp_mb(); /* for i_nlink */
21818 + /* 0 can happen */
21819 + set_nlink(inode, n);
21822 + spin_lock(&inode->i_lock);
21823 + inode->i_blocks = st->blocks;
21824 + i_size_write(inode, st->size);
21825 + spin_unlock(&inode->i_lock);
21829 + * common routine for aufs_getattr() and au_getxattr().
21830 + * returns zero or negative (an error).
21831 + * @dentry will be read-locked in success.
21833 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21837 + unsigned int mnt_flags, sigen;
21838 + unsigned char udba_none;
21839 + aufs_bindex_t bindex;
21840 + struct super_block *sb, *h_sb;
21841 + struct inode *inode;
21843 + h_path->mnt = NULL;
21844 + h_path->dentry = NULL;
21847 + sb = dentry->d_sb;
21848 + mnt_flags = au_mntflags(sb);
21849 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21851 + if (unlikely(locked))
21852 + goto body; /* skip locking dinfo */
21854 + /* support fstat(2) */
21855 + if (!d_unlinked(dentry) && !udba_none) {
21856 + sigen = au_sigen(sb);
21857 + err = au_digen_test(dentry, sigen);
21859 + di_read_lock_child(dentry, AuLock_IR);
21860 + err = au_dbrange_test(dentry);
21861 + if (unlikely(err)) {
21862 + di_read_unlock(dentry, AuLock_IR);
21866 + AuDebugOn(IS_ROOT(dentry));
21867 + di_write_lock_child(dentry);
21868 + err = au_dbrange_test(dentry);
21870 + err = au_reval_for_attr(dentry, sigen);
21872 + di_downgrade_lock(dentry, AuLock_IR);
21874 + di_write_unlock(dentry);
21879 + di_read_lock_child(dentry, AuLock_IR);
21882 + inode = d_inode(dentry);
21883 + bindex = au_ibtop(inode);
21884 + h_path->mnt = au_sbr_mnt(sb, bindex);
21885 + h_sb = h_path->mnt->mnt_sb;
21887 + && !au_test_fs_bad_iattr(h_sb)
21889 + goto out; /* success */
21891 + if (au_dbtop(dentry) == bindex)
21892 + h_path->dentry = au_h_dptr(dentry, bindex);
21893 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21894 + h_path->dentry = au_plink_lkup(inode, bindex);
21895 + if (IS_ERR(h_path->dentry))
21896 + /* pretending success */
21897 + h_path->dentry = NULL;
21899 + dput(h_path->dentry);
21906 +static int aufs_getattr(const struct path *path, struct kstat *st,
21907 + u32 request, unsigned int query)
21910 + unsigned char positive;
21911 + struct path h_path;
21912 + struct dentry *dentry;
21913 + struct inode *inode;
21914 + struct super_block *sb;
21916 + dentry = path->dentry;
21917 + inode = d_inode(dentry);
21918 + sb = dentry->d_sb;
21919 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21920 + if (unlikely(err))
21922 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21923 + if (unlikely(err))
21925 + if (unlikely(!h_path.dentry))
21926 + /* illegally overlapped or something */
21927 + goto out_fill; /* pretending success */
21929 + positive = d_is_positive(h_path.dentry);
21931 + /* no vfsub version */
21932 + err = vfs_getattr(&h_path, st, request, query);
21935 + au_refresh_iattr(inode, st,
21936 + d_inode(h_path.dentry)->i_nlink);
21937 + goto out_fill; /* success */
21943 + generic_fillattr(inode, st);
21945 + di_read_unlock(dentry, AuLock_IR);
21947 + si_read_unlock(sb);
21953 +/* ---------------------------------------------------------------------- */
21955 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21956 + struct delayed_call *done)
21959 + struct dentry *h_dentry;
21960 + struct inode *h_inode;
21962 + aufs_bindex_t bindex;
21964 + ret = NULL; /* suppress a warning */
21969 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21970 + if (unlikely(err))
21973 + err = au_d_hashed_positive(dentry);
21974 + if (unlikely(err))
21978 + inode = d_inode(dentry);
21979 + bindex = au_ibtop(inode);
21980 + h_inode = au_h_iptr(inode, bindex);
21981 + if (unlikely(!h_inode->i_op->get_link))
21986 + if (au_dbtop(dentry) <= bindex) {
21987 + h_dentry = au_h_dptr(dentry, bindex);
21992 + h_dentry = d_find_any_alias(h_inode);
21993 + if (IS_ERR(h_dentry)) {
21994 + err = PTR_ERR(h_dentry);
21998 + if (unlikely(!h_dentry))
22002 + AuDbg("%ps\n", h_inode->i_op->get_link);
22003 + AuDbgDentry(h_dentry);
22004 + ret = vfs_get_link(h_dentry, done);
22007 + err = PTR_ERR(ret);
22010 + aufs_read_unlock(dentry, AuLock_IR);
22012 + if (unlikely(err))
22013 + ret = ERR_PTR(err);
22014 + AuTraceErrPtr(ret);
22018 +/* ---------------------------------------------------------------------- */
22020 +static int au_is_special(struct inode *inode)
22022 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
22025 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
22029 + aufs_bindex_t bindex;
22030 + struct super_block *sb;
22031 + struct inode *h_inode;
22032 + struct vfsmount *h_mnt;
22034 + sb = inode->i_sb;
22035 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
22036 + "unexpected s_flags 0x%lx", sb->s_flags);
22038 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
22040 + si_read_lock(sb, AuLock_FLUSH);
22041 + ii_write_lock_child(inode);
22044 + bindex = au_ibtop(inode);
22045 + h_inode = au_h_iptr(inode, bindex);
22046 + if (!au_test_ro(sb, bindex, inode)) {
22047 + h_mnt = au_sbr_mnt(sb, bindex);
22048 + err = vfsub_mnt_want_write(h_mnt);
22050 + err = vfsub_update_time(h_inode, ts, flags);
22051 + vfsub_mnt_drop_write(h_mnt);
22053 + } else if (au_is_special(h_inode)) {
22055 + * Never copy-up here.
22056 + * These special files may already be opened and used for
22057 + * communicating. If we copied it up, then the communication
22058 + * would be corrupted.
22060 + AuWarn1("timestamps for i%lu are ignored "
22061 + "since it is on readonly branch (hi%lu).\n",
22062 + inode->i_ino, h_inode->i_ino);
22063 + } else if (flags & ~S_ATIME) {
22065 + AuIOErr1("unexpected flags 0x%x\n", flags);
22070 + au_cpup_attr_timesizes(inode);
22071 + ii_write_unlock(inode);
22072 + si_read_unlock(sb);
22075 + if (!err && (flags & S_VERSION))
22076 + inode_inc_iversion(inode);
22081 +/* ---------------------------------------------------------------------- */
22083 +/* no getattr version will be set by module.c:aufs_init() */
22084 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22086 + [AuIop_SYMLINK] = {
22087 + .permission = aufs_permission,
22088 +#ifdef CONFIG_FS_POSIX_ACL
22089 + .get_acl = aufs_get_acl,
22090 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22093 + .setattr = aufs_setattr,
22094 + .getattr = aufs_getattr,
22096 +#ifdef CONFIG_AUFS_XATTR
22097 + .listxattr = aufs_listxattr,
22100 + .get_link = aufs_get_link,
22102 + /* .update_time = aufs_update_time */
22105 + .create = aufs_create,
22106 + .lookup = aufs_lookup,
22107 + .link = aufs_link,
22108 + .unlink = aufs_unlink,
22109 + .symlink = aufs_symlink,
22110 + .mkdir = aufs_mkdir,
22111 + .rmdir = aufs_rmdir,
22112 + .mknod = aufs_mknod,
22113 + .rename = aufs_rename,
22115 + .permission = aufs_permission,
22116 +#ifdef CONFIG_FS_POSIX_ACL
22117 + .get_acl = aufs_get_acl,
22118 + .set_acl = aufs_set_acl,
22121 + .setattr = aufs_setattr,
22122 + .getattr = aufs_getattr,
22124 +#ifdef CONFIG_AUFS_XATTR
22125 + .listxattr = aufs_listxattr,
22128 + .update_time = aufs_update_time,
22129 + .atomic_open = aufs_atomic_open,
22130 + .tmpfile = aufs_tmpfile
22132 + [AuIop_OTHER] = {
22133 + .permission = aufs_permission,
22134 +#ifdef CONFIG_FS_POSIX_ACL
22135 + .get_acl = aufs_get_acl,
22136 + .set_acl = aufs_set_acl,
22139 + .setattr = aufs_setattr,
22140 + .getattr = aufs_getattr,
22142 +#ifdef CONFIG_AUFS_XATTR
22143 + .listxattr = aufs_listxattr,
22146 + .update_time = aufs_update_time
22149 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22150 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22151 +++ linux/fs/aufs/i_op_del.c 2018-10-23 12:33:35.599375796 +0200
22153 +// SPDX-License-Identifier: GPL-2.0
22155 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22157 + * This program, aufs is free software; you can redistribute it and/or modify
22158 + * it under the terms of the GNU General Public License as published by
22159 + * the Free Software Foundation; either version 2 of the License, or
22160 + * (at your option) any later version.
22162 + * This program is distributed in the hope that it will be useful,
22163 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22164 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22165 + * GNU General Public License for more details.
22167 + * You should have received a copy of the GNU General Public License
22168 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22172 + * inode operations (del entry)
22178 + * decide if a new whiteout for @dentry is necessary or not.
22179 + * when it is necessary, prepare the parent dir for the upper branch whose
22180 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22181 + * be done by caller.
22183 + * 0: wh is unnecessary
22184 + * plus: wh is necessary
22187 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22189 + int need_wh, err;
22190 + aufs_bindex_t btop;
22191 + struct super_block *sb;
22193 + sb = dentry->d_sb;
22194 + btop = au_dbtop(dentry);
22195 + if (*bcpup < 0) {
22197 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22198 + err = AuWbrCopyup(au_sbi(sb), dentry);
22200 + if (unlikely(err < 0))
22204 + AuDebugOn(btop < *bcpup
22205 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22206 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22208 + if (*bcpup != btop) {
22209 + err = au_cpup_dirs(dentry, *bcpup);
22210 + if (unlikely(err))
22214 + struct au_dinfo *dinfo, *tmp;
22216 + need_wh = -ENOMEM;
22217 + dinfo = au_di(dentry);
22218 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22220 + au_di_cp(tmp, dinfo);
22221 + au_di_swap(tmp, dinfo);
22222 + /* returns the number of positive dentries */
22223 + need_wh = au_lkup_dentry(dentry, btop + 1,
22224 + /* AuLkup_IGNORE_PERM */ 0);
22225 + au_di_swap(tmp, dinfo);
22226 + au_rw_write_unlock(&tmp->di_rwsem);
22230 + AuDbg("need_wh %d\n", need_wh);
22238 + * simple tests for the del-entry operations.
22239 + * following the checks in vfs, plus the parent-child relationship.
22241 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22242 + struct dentry *h_parent, int isdir)
22246 + struct dentry *h_dentry, *h_latest;
22247 + struct inode *h_inode;
22249 + h_dentry = au_h_dptr(dentry, bindex);
22250 + if (d_really_is_positive(dentry)) {
22252 + if (unlikely(d_is_negative(h_dentry)))
22254 + h_inode = d_inode(h_dentry);
22255 + if (unlikely(!h_inode->i_nlink))
22258 + h_mode = h_inode->i_mode;
22261 + if (unlikely(S_ISDIR(h_mode)))
22263 + } else if (unlikely(!S_ISDIR(h_mode))) {
22268 + /* rename(2) case */
22270 + if (unlikely(d_is_positive(h_dentry)))
22275 + /* expected parent dir is locked */
22276 + if (unlikely(h_parent != h_dentry->d_parent))
22281 + * rmdir a dir may break the consistency on some filesystem.
22282 + * let's try heavy test.
22285 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22286 + && au_test_h_perm(d_inode(h_parent),
22287 + MAY_EXEC | MAY_WRITE)))
22290 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22292 + if (IS_ERR(h_latest))
22294 + if (h_latest == h_dentry)
22303 + * decide the branch where we operate for @dentry. the branch index will be set
22304 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22305 + * dir for reverting.
22306 + * when a new whiteout is necessary, create it.
22308 +static struct dentry*
22309 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22310 + struct au_dtime *dt, struct au_pin *pin)
22312 + struct dentry *wh_dentry;
22313 + struct super_block *sb;
22314 + struct path h_path;
22315 + int err, need_wh;
22316 + unsigned int udba;
22317 + aufs_bindex_t bcpup;
22319 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22320 + wh_dentry = ERR_PTR(need_wh);
22321 + if (unlikely(need_wh < 0))
22324 + sb = dentry->d_sb;
22325 + udba = au_opt_udba(sb);
22327 + err = au_pin(pin, dentry, bcpup, udba,
22328 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22329 + wh_dentry = ERR_PTR(err);
22330 + if (unlikely(err))
22333 + h_path.dentry = au_pinned_h_parent(pin);
22334 + if (udba != AuOpt_UDBA_NONE
22335 + && au_dbtop(dentry) == bcpup) {
22336 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22337 + wh_dentry = ERR_PTR(err);
22338 + if (unlikely(err))
22342 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22343 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22344 + wh_dentry = NULL;
22346 + goto out; /* success, no need to create whiteout */
22348 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22349 + if (IS_ERR(wh_dentry))
22352 + /* returns with the parent is locked and wh_dentry is dget-ed */
22353 + goto out; /* success */
22358 + return wh_dentry;
22362 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22363 + * in order to be revertible and save time for removing many child whiteouts
22365 + * returns 1 when there are too many child whiteout and caller should remove
22366 + * them asynchronously. returns 0 when the number of children is enough small to
22367 + * remove now or the branch fs is a remote fs.
22368 + * otherwise return an error.
22370 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22371 + struct au_nhash *whlist, struct inode *dir)
22373 + int rmdir_later, err, dirwh;
22374 + struct dentry *h_dentry;
22375 + struct super_block *sb;
22376 + struct inode *inode;
22378 + sb = dentry->d_sb;
22379 + SiMustAnyLock(sb);
22380 + h_dentry = au_h_dptr(dentry, bindex);
22381 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22382 + if (unlikely(err))
22385 + /* stop monitoring */
22386 + inode = d_inode(dentry);
22387 + au_hn_free(au_hi(inode, bindex));
22389 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22390 + dirwh = au_sbi(sb)->si_dirwh;
22391 + rmdir_later = (dirwh <= 1);
22392 + if (!rmdir_later)
22393 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22396 + return rmdir_later;
22399 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22400 + if (unlikely(err)) {
22401 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22402 + h_dentry, bindex, err);
22412 + * final procedure for deleting a entry.
22413 + * maintain dentry and iattr.
22415 +static void epilog(struct inode *dir, struct dentry *dentry,
22416 + aufs_bindex_t bindex)
22418 + struct inode *inode;
22420 + inode = d_inode(dentry);
22422 + inode->i_ctime = dir->i_ctime;
22424 + au_dir_ts(dir, bindex);
22425 + inode_inc_iversion(dir);
22429 + * when an error happened, remove the created whiteout and revert everything.
22431 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22432 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22433 + struct dentry *dentry, struct au_dtime *dt)
22436 + struct path h_path = {
22437 + .dentry = wh_dentry,
22438 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22441 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22443 + au_set_dbwh(dentry, bwh);
22444 + au_dtime_revert(dt);
22448 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22452 +/* ---------------------------------------------------------------------- */
22454 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22457 + aufs_bindex_t bwh, bindex, btop;
22458 + struct inode *inode, *h_dir, *delegated;
22459 + struct dentry *parent, *wh_dentry;
22460 + /* to reduce stack size */
22462 + struct au_dtime dt;
22463 + struct au_pin pin;
22464 + struct path h_path;
22470 + a = kmalloc(sizeof(*a), GFP_NOFS);
22471 + if (unlikely(!a))
22474 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22475 + if (unlikely(err))
22477 + err = au_d_hashed_positive(dentry);
22478 + if (unlikely(err))
22480 + inode = d_inode(dentry);
22481 + IMustLock(inode);
22483 + if (unlikely(d_is_dir(dentry)))
22484 + goto out_unlock; /* possible? */
22486 + btop = au_dbtop(dentry);
22487 + bwh = au_dbwh(dentry);
22489 + parent = dentry->d_parent; /* dir inode is locked */
22490 + di_write_lock_parent(parent);
22491 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22493 + err = PTR_ERR(wh_dentry);
22494 + if (IS_ERR(wh_dentry))
22497 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22498 + a->h_path.dentry = au_h_dptr(dentry, btop);
22499 + dget(a->h_path.dentry);
22500 + if (bindex == btop) {
22501 + h_dir = au_pinned_h_dir(&a->pin);
22502 + delegated = NULL;
22503 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22504 + if (unlikely(err == -EWOULDBLOCK)) {
22505 + pr_warn("cannot retry for NFSv4 delegation"
22506 + " for an internal unlink\n");
22510 + /* dir inode is locked */
22511 + h_dir = d_inode(wh_dentry->d_parent);
22512 + IMustLock(h_dir);
22517 + vfsub_drop_nlink(inode);
22518 + epilog(dir, dentry, bindex);
22520 + /* update target timestamps */
22521 + if (bindex == btop) {
22522 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22524 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22526 + /* todo: this timestamp may be reverted later */
22527 + inode->i_ctime = h_dir->i_ctime;
22528 + goto out_unpin; /* success */
22535 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22542 + au_unpin(&a->pin);
22544 + dput(a->h_path.dentry);
22546 + di_write_unlock(parent);
22548 + aufs_read_unlock(dentry, AuLock_DW);
22555 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22557 + int err, rmdir_later;
22558 + aufs_bindex_t bwh, bindex, btop;
22559 + struct inode *inode;
22560 + struct dentry *parent, *wh_dentry, *h_dentry;
22561 + struct au_whtmp_rmdir *args;
22562 + /* to reduce stack size */
22564 + struct au_dtime dt;
22565 + struct au_pin pin;
22571 + a = kmalloc(sizeof(*a), GFP_NOFS);
22572 + if (unlikely(!a))
22575 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22576 + if (unlikely(err))
22578 + err = au_alive_dir(dentry);
22579 + if (unlikely(err))
22581 + inode = d_inode(dentry);
22582 + IMustLock(inode);
22584 + if (unlikely(!d_is_dir(dentry)))
22585 + goto out_unlock; /* possible? */
22588 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22589 + if (unlikely(!args))
22592 + parent = dentry->d_parent; /* dir inode is locked */
22593 + di_write_lock_parent(parent);
22594 + err = au_test_empty(dentry, &args->whlist);
22595 + if (unlikely(err))
22598 + btop = au_dbtop(dentry);
22599 + bwh = au_dbwh(dentry);
22601 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22603 + err = PTR_ERR(wh_dentry);
22604 + if (IS_ERR(wh_dentry))
22607 + h_dentry = au_h_dptr(dentry, btop);
22610 + if (bindex == btop) {
22611 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22613 + rmdir_later = err;
22617 + /* stop monitoring */
22618 + au_hn_free(au_hi(inode, btop));
22620 + /* dir inode is locked */
22621 + IMustLock(d_inode(wh_dentry->d_parent));
22626 + vfsub_dead_dir(inode);
22627 + au_set_dbdiropq(dentry, -1);
22628 + epilog(dir, dentry, bindex);
22630 + if (rmdir_later) {
22631 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22635 + goto out_unpin; /* success */
22643 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22650 + au_unpin(&a->pin);
22654 + di_write_unlock(parent);
22656 + au_whtmp_rmdir_free(args);
22658 + aufs_read_unlock(dentry, AuLock_DW);
22665 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22666 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22667 +++ linux/fs/aufs/i_op_ren.c 2018-10-23 12:33:35.599375796 +0200
22669 +// SPDX-License-Identifier: GPL-2.0
22671 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22673 + * This program, aufs is free software; you can redistribute it and/or modify
22674 + * it under the terms of the GNU General Public License as published by
22675 + * the Free Software Foundation; either version 2 of the License, or
22676 + * (at your option) any later version.
22678 + * This program is distributed in the hope that it will be useful,
22679 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22680 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22681 + * GNU General Public License for more details.
22683 + * You should have received a copy of the GNU General Public License
22684 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22688 + * inode operation (rename entry)
22689 + * todo: this is crazy monster
22694 +enum { AuSRC, AuDST, AuSrcDst };
22695 +enum { AuPARENT, AuCHILD, AuParentChild };
22697 +#define AuRen_ISDIR_SRC 1
22698 +#define AuRen_ISDIR_DST (1 << 1)
22699 +#define AuRen_ISSAMEDIR (1 << 2)
22700 +#define AuRen_WHSRC (1 << 3)
22701 +#define AuRen_WHDST (1 << 4)
22702 +#define AuRen_MNT_WRITE (1 << 5)
22703 +#define AuRen_DT_DSTDIR (1 << 6)
22704 +#define AuRen_DIROPQ_SRC (1 << 7)
22705 +#define AuRen_DIROPQ_DST (1 << 8)
22706 +#define AuRen_DIRREN (1 << 9)
22707 +#define AuRen_DROPPED_SRC (1 << 10)
22708 +#define AuRen_DROPPED_DST (1 << 11)
22709 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22710 +#define au_fset_ren(flags, name) \
22711 + do { (flags) |= AuRen_##name; } while (0)
22712 +#define au_fclr_ren(flags, name) \
22713 + do { (flags) &= ~AuRen_##name; } while (0)
22715 +#ifndef CONFIG_AUFS_DIRREN
22716 +#undef AuRen_DIRREN
22717 +#define AuRen_DIRREN 0
22720 +struct au_ren_args {
22722 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22724 + struct inode *dir, *inode;
22725 + struct au_hinode *hdir, *hinode;
22726 + struct au_dtime dt[AuParentChild];
22727 + aufs_bindex_t btop, bdiropq;
22730 +#define src_dentry sd[AuSRC].dentry
22731 +#define src_dir sd[AuSRC].dir
22732 +#define src_inode sd[AuSRC].inode
22733 +#define src_h_dentry sd[AuSRC].h_dentry
22734 +#define src_parent sd[AuSRC].parent
22735 +#define src_h_parent sd[AuSRC].h_parent
22736 +#define src_wh_dentry sd[AuSRC].wh_dentry
22737 +#define src_hdir sd[AuSRC].hdir
22738 +#define src_hinode sd[AuSRC].hinode
22739 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22740 +#define src_dt sd[AuSRC].dt
22741 +#define src_btop sd[AuSRC].btop
22742 +#define src_bdiropq sd[AuSRC].bdiropq
22744 +#define dst_dentry sd[AuDST].dentry
22745 +#define dst_dir sd[AuDST].dir
22746 +#define dst_inode sd[AuDST].inode
22747 +#define dst_h_dentry sd[AuDST].h_dentry
22748 +#define dst_parent sd[AuDST].parent
22749 +#define dst_h_parent sd[AuDST].h_parent
22750 +#define dst_wh_dentry sd[AuDST].wh_dentry
22751 +#define dst_hdir sd[AuDST].hdir
22752 +#define dst_hinode sd[AuDST].hinode
22753 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22754 +#define dst_dt sd[AuDST].dt
22755 +#define dst_btop sd[AuDST].btop
22756 +#define dst_bdiropq sd[AuDST].bdiropq
22758 + struct dentry *h_trap;
22759 + struct au_branch *br;
22760 + struct path h_path;
22761 + struct au_nhash whlist;
22762 + aufs_bindex_t btgt, src_bwh;
22765 + unsigned short auren_flags;
22766 + unsigned char flags; /* syscall parameter */
22767 + unsigned char exchange;
22770 + struct au_whtmp_rmdir *thargs;
22771 + struct dentry *h_dst;
22772 + struct au_hinode *h_root;
22775 +/* ---------------------------------------------------------------------- */
22778 + * functions for reverting.
22779 + * when an error happened in a single rename systemcall, we should revert
22780 + * everything as if nothing happened.
22781 + * we don't need to revert the copied-up/down the parent dir since they are
22785 +#define RevertFailure(fmt, ...) do { \
22786 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22787 + ##__VA_ARGS__, err, rerr); \
22791 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22794 + struct dentry *d;
22795 +#define src_or_dst(member) a->sd[idx].member
22797 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22798 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22799 + rerr = au_diropq_remove(d, a->btgt);
22800 + au_hn_inode_unlock(src_or_dst(hinode));
22801 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22803 + RevertFailure("remove diropq %pd", d);
22805 +#undef src_or_dst_
22808 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22810 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22811 + au_ren_do_rev_diropq(err, a, AuSRC);
22812 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22813 + au_ren_do_rev_diropq(err, a, AuDST);
22816 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22819 + struct inode *delegated;
22821 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22822 + a->src_h_parent);
22823 + rerr = PTR_ERR(a->h_path.dentry);
22824 + if (IS_ERR(a->h_path.dentry)) {
22825 + RevertFailure("lkup one %pd", a->src_dentry);
22829 + delegated = NULL;
22830 + rerr = vfsub_rename(a->dst_h_dir,
22831 + au_h_dptr(a->src_dentry, a->btgt),
22832 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22833 + if (unlikely(rerr == -EWOULDBLOCK)) {
22834 + pr_warn("cannot retry for NFSv4 delegation"
22835 + " for an internal rename\n");
22838 + d_drop(a->h_path.dentry);
22839 + dput(a->h_path.dentry);
22840 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22842 + RevertFailure("rename %pd", a->src_dentry);
22845 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22848 + struct inode *delegated;
22850 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22851 + a->dst_h_parent);
22852 + rerr = PTR_ERR(a->h_path.dentry);
22853 + if (IS_ERR(a->h_path.dentry)) {
22854 + RevertFailure("lkup one %pd", a->dst_dentry);
22857 + if (d_is_positive(a->h_path.dentry)) {
22858 + d_drop(a->h_path.dentry);
22859 + dput(a->h_path.dentry);
22863 + delegated = NULL;
22864 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22865 + &delegated, a->flags);
22866 + if (unlikely(rerr == -EWOULDBLOCK)) {
22867 + pr_warn("cannot retry for NFSv4 delegation"
22868 + " for an internal rename\n");
22871 + d_drop(a->h_path.dentry);
22872 + dput(a->h_path.dentry);
22874 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22876 + RevertFailure("rename %pd", a->h_dst);
22879 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22883 + a->h_path.dentry = a->src_wh_dentry;
22884 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22885 + au_set_dbwh(a->src_dentry, a->src_bwh);
22887 + RevertFailure("unlink %pd", a->src_wh_dentry);
22889 +#undef RevertFailure
22891 +/* ---------------------------------------------------------------------- */
22894 + * when we have to copyup the renaming entry, do it with the rename-target name
22895 + * in order to minimize the cost (the later actual rename is unnecessary).
22896 + * otherwise rename it on the target branch.
22898 +static int au_ren_or_cpup(struct au_ren_args *a)
22901 + struct dentry *d;
22902 + struct inode *delegated;
22904 + d = a->src_dentry;
22905 + if (au_dbtop(d) == a->btgt) {
22906 + a->h_path.dentry = a->dst_h_dentry;
22907 + AuDebugOn(au_dbtop(d) != a->btgt);
22908 + delegated = NULL;
22909 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22910 + a->dst_h_dir, &a->h_path, &delegated,
22912 + if (unlikely(err == -EWOULDBLOCK)) {
22913 + pr_warn("cannot retry for NFSv4 delegation"
22914 + " for an internal rename\n");
22920 + if (!err && a->h_dst)
22921 + /* it will be set to dinfo later */
22927 +/* cf. aufs_rmdir() */
22928 +static int au_ren_del_whtmp(struct au_ren_args *a)
22931 + struct inode *dir;
22933 + dir = a->dst_dir;
22934 + SiMustAnyLock(dir->i_sb);
22935 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22936 + au_sbi(dir->i_sb)->si_dirwh)
22937 + || au_test_fs_remote(a->h_dst->d_sb)) {
22938 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22939 + if (unlikely(err))
22940 + pr_warn("failed removing whtmp dir %pd (%d), "
22941 + "ignored.\n", a->h_dst, err);
22943 + au_nhash_wh_free(&a->thargs->whlist);
22944 + a->thargs->whlist = a->whlist;
22945 + a->whlist.nh_num = 0;
22946 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22948 + a->thargs = NULL;
22954 +/* make it 'opaque' dir. */
22955 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22958 + struct dentry *d, *diropq;
22959 +#define src_or_dst(member) a->sd[idx].member
22962 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22963 + src_or_dst(bdiropq) = au_dbdiropq(d);
22964 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22965 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22966 + diropq = au_diropq_create(d, a->btgt);
22967 + au_hn_inode_unlock(src_or_dst(hinode));
22968 + if (IS_ERR(diropq))
22969 + err = PTR_ERR(diropq);
22973 +#undef src_or_dst_
22977 +static int au_ren_diropq(struct au_ren_args *a)
22980 + unsigned char always;
22981 + struct dentry *d;
22984 + d = a->dst_dentry; /* already renamed on the branch */
22985 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22986 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22987 + && !au_ftest_ren(a->auren_flags, DIRREN)
22988 + && a->btgt != au_dbdiropq(a->src_dentry)
22989 + && (a->dst_wh_dentry
22990 + || a->btgt <= au_dbdiropq(d)
22991 + /* hide the lower to keep xino */
22992 + /* the lowers may not be a dir, but we hide them anyway */
22993 + || a->btgt < au_dbbot(d)
22996 + err = au_ren_do_diropq(a, AuSRC);
22997 + if (unlikely(err))
22999 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
23001 + if (!a->exchange)
23002 + goto out; /* success */
23004 + d = a->src_dentry; /* already renamed on the branch */
23005 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23006 + && a->btgt != au_dbdiropq(a->dst_dentry)
23007 + && (a->btgt < au_dbdiropq(d)
23008 + || a->btgt < au_dbbot(d)
23010 + AuDbgDentry(a->src_dentry);
23011 + AuDbgDentry(a->dst_dentry);
23012 + err = au_ren_do_diropq(a, AuDST);
23013 + if (unlikely(err))
23014 + goto out_rev_src;
23015 + au_fset_ren(a->auren_flags, DIROPQ_DST);
23017 + goto out; /* success */
23020 + AuDbg("err %d, reverting src\n", err);
23021 + au_ren_rev_diropq(err, a);
23026 +static int do_rename(struct au_ren_args *a)
23029 + struct dentry *d, *h_d;
23031 + if (!a->exchange) {
23032 + /* prepare workqueue args for asynchronous rmdir */
23033 + h_d = a->dst_h_dentry;
23034 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23035 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
23036 + && d_is_positive(h_d)) {
23038 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
23040 + if (unlikely(!a->thargs))
23042 + a->h_dst = dget(h_d);
23045 + /* create whiteout for src_dentry */
23046 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
23047 + a->src_bwh = au_dbwh(a->src_dentry);
23048 + AuDebugOn(a->src_bwh >= 0);
23049 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
23050 + a->src_h_parent);
23051 + err = PTR_ERR(a->src_wh_dentry);
23052 + if (IS_ERR(a->src_wh_dentry))
23056 + /* lookup whiteout for dentry */
23057 + if (au_ftest_ren(a->auren_flags, WHDST)) {
23058 + h_d = au_wh_lkup(a->dst_h_parent,
23059 + &a->dst_dentry->d_name, a->br);
23060 + err = PTR_ERR(h_d);
23063 + if (d_is_negative(h_d))
23066 + a->dst_wh_dentry = h_d;
23069 + /* rename dentry to tmpwh */
23071 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23072 + if (unlikely(err))
23075 + d = a->dst_dentry;
23076 + au_set_h_dptr(d, a->btgt, NULL);
23077 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23078 + if (unlikely(err))
23080 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23084 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23086 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23087 + && d_is_positive(a->dst_h_dentry)
23088 + && a->src_btop != a->btgt);
23091 + /* rename by vfs_rename or cpup */
23092 + err = au_ren_or_cpup(a);
23093 + if (unlikely(err))
23094 + /* leave the copied-up one */
23097 + /* make dir opaque */
23098 + err = au_ren_diropq(a);
23099 + if (unlikely(err))
23102 + /* update target timestamps */
23103 + if (a->exchange) {
23104 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23105 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23106 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23107 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23109 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23110 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23111 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23112 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23114 + if (!a->exchange) {
23115 + /* remove whiteout for dentry */
23116 + if (a->dst_wh_dentry) {
23117 + a->h_path.dentry = a->dst_wh_dentry;
23118 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23120 + if (unlikely(err))
23124 + /* remove whtmp */
23126 + au_ren_del_whtmp(a); /* ignore this error */
23128 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23131 + goto out_success;
23134 + au_ren_rev_diropq(err, a);
23136 + au_ren_rev_rename(err, a);
23140 + au_ren_rev_whtmp(err, a);
23142 + dput(a->dst_wh_dentry);
23143 + a->dst_wh_dentry = NULL;
23145 + if (a->src_wh_dentry)
23146 + au_ren_rev_whsrc(err, a);
23148 + dput(a->src_wh_dentry);
23149 + dput(a->dst_wh_dentry);
23153 + au_whtmp_rmdir_free(a->thargs);
23154 + a->thargs = NULL;
23160 +/* ---------------------------------------------------------------------- */
23163 + * test if @dentry dir can be rename destination or not.
23164 + * success means, it is a logically empty dir.
23166 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23168 + return au_test_empty(dentry, whlist);
23172 + * test if @a->src_dentry dir can be rename source or not.
23173 + * if it can, return 0.
23175 + * - it is a logically empty dir.
23176 + * - or, it exists on writable branch and has no children including whiteouts
23177 + * on the lower branch unless DIRREN is on.
23179 +static int may_rename_srcdir(struct au_ren_args *a)
23182 + unsigned int rdhash;
23183 + aufs_bindex_t btop, btgt;
23184 + struct dentry *dentry;
23185 + struct super_block *sb;
23186 + struct au_sbinfo *sbinfo;
23188 + dentry = a->src_dentry;
23189 + sb = dentry->d_sb;
23190 + sbinfo = au_sbi(sb);
23191 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23192 + au_fset_ren(a->auren_flags, DIRREN);
23195 + btop = au_dbtop(dentry);
23196 + if (btop != btgt) {
23197 + struct au_nhash whlist;
23199 + SiMustAnyLock(sb);
23200 + rdhash = sbinfo->si_rdhash;
23202 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23204 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23205 + if (unlikely(err))
23207 + err = au_test_empty(dentry, &whlist);
23208 + au_nhash_wh_free(&whlist);
23212 + if (btop == au_dbtaildir(dentry))
23213 + return 0; /* success */
23215 + err = au_test_empty_lower(dentry);
23218 + if (err == -ENOTEMPTY) {
23219 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23222 + AuWarn1("renaming dir who has child(ren) on multiple "
23223 + "branches, is not supported\n");
23230 +/* side effect: sets whlist and h_dentry */
23231 +static int au_ren_may_dir(struct au_ren_args *a)
23234 + unsigned int rdhash;
23235 + struct dentry *d;
23237 + d = a->dst_dentry;
23238 + SiMustAnyLock(d->d_sb);
23241 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23242 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23244 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23245 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23246 + if (unlikely(err))
23249 + if (!a->exchange) {
23250 + au_set_dbtop(d, a->dst_btop);
23251 + err = may_rename_dstdir(d, &a->whlist);
23252 + au_set_dbtop(d, a->btgt);
23254 + err = may_rename_srcdir(a);
23256 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23257 + if (unlikely(err))
23260 + d = a->src_dentry;
23261 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23262 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23263 + err = may_rename_srcdir(a);
23264 + if (unlikely(err)) {
23265 + au_nhash_wh_free(&a->whlist);
23266 + a->whlist.nh_num = 0;
23273 +/* ---------------------------------------------------------------------- */
23276 + * simple tests for rename.
23277 + * following the checks in vfs, plus the parent-child relationship.
23279 +static int au_may_ren(struct au_ren_args *a)
23282 + struct inode *h_inode;
23284 + if (a->src_btop == a->btgt) {
23285 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23286 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23287 + if (unlikely(err))
23290 + if (unlikely(a->src_h_dentry == a->h_trap))
23295 + if (a->dst_btop != a->btgt)
23298 + err = -ENOTEMPTY;
23299 + if (unlikely(a->dst_h_dentry == a->h_trap))
23303 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23304 + if (d_really_is_negative(a->dst_dentry)) {
23305 + if (d_is_negative(a->dst_h_dentry))
23306 + err = au_may_add(a->dst_dentry, a->btgt,
23307 + a->dst_h_parent, isdir);
23309 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23311 + h_inode = d_inode(a->dst_h_dentry);
23312 + if (h_inode->i_nlink)
23313 + err = au_may_del(a->dst_dentry, a->btgt,
23314 + a->dst_h_parent, isdir);
23318 + if (unlikely(err == -ENOENT || err == -EEXIST))
23324 +/* ---------------------------------------------------------------------- */
23329 + * - src_dir and dir by lock_rename()
23330 + * - inode if exists
23333 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23335 + * + di_write_lock2_child()
23336 + * + di_write_lock_child()
23337 + * + ii_write_lock_child()
23338 + * + di_write_lock_child2()
23339 + * + ii_write_lock_child2()
23340 + * + src_parent and parent
23341 + * + di_write_lock_parent()
23342 + * + ii_write_lock_parent()
23343 + * + di_write_lock_parent2()
23344 + * + ii_write_lock_parent2()
23345 + * + lower src_dir and dir by vfsub_lock_rename()
23346 + * + verify the every relationships between child and parent. if any
23347 + * of them failed, unlock all and return -EBUSY.
23349 +static void au_ren_unlock(struct au_ren_args *a)
23351 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23352 + a->dst_h_parent, a->dst_hdir);
23353 + if (au_ftest_ren(a->auren_flags, DIRREN)
23355 + au_hn_inode_unlock(a->h_root);
23356 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23357 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23360 +static int au_ren_lock(struct au_ren_args *a)
23363 + unsigned int udba;
23366 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23367 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23368 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23369 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23371 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23372 + if (unlikely(err))
23374 + au_fset_ren(a->auren_flags, MNT_WRITE);
23375 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23376 + struct dentry *root;
23377 + struct inode *dir;
23380 + * sbinfo is already locked, so this ii_read_lock is
23381 + * unnecessary. but our debugging feature checks it.
23383 + root = a->src_inode->i_sb->s_root;
23384 + if (root != a->src_parent && root != a->dst_parent) {
23385 + dir = d_inode(root);
23386 + ii_read_lock_parent3(dir);
23387 + a->h_root = au_hi(dir, a->btgt);
23388 + ii_read_unlock(dir);
23389 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23392 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23393 + a->dst_h_parent, a->dst_hdir);
23394 + udba = au_opt_udba(a->src_dentry->d_sb);
23395 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23396 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23397 + err = au_busy_or_stale();
23398 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23399 + err = au_h_verify(a->src_h_dentry, udba,
23400 + d_inode(a->src_h_parent), a->src_h_parent,
23402 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23403 + err = au_h_verify(a->dst_h_dentry, udba,
23404 + d_inode(a->dst_h_parent), a->dst_h_parent,
23407 + goto out; /* success */
23409 + err = au_busy_or_stale();
23410 + au_ren_unlock(a);
23416 +/* ---------------------------------------------------------------------- */
23418 +static void au_ren_refresh_dir(struct au_ren_args *a)
23420 + struct inode *dir;
23422 + dir = a->dst_dir;
23423 + inode_inc_iversion(dir);
23424 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23425 + /* is this updating defined in POSIX? */
23426 + au_cpup_attr_timesizes(a->src_inode);
23427 + au_cpup_attr_nlink(dir, /*force*/1);
23429 + au_dir_ts(dir, a->btgt);
23431 + if (a->exchange) {
23432 + dir = a->src_dir;
23433 + inode_inc_iversion(dir);
23434 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23435 + /* is this updating defined in POSIX? */
23436 + au_cpup_attr_timesizes(a->dst_inode);
23437 + au_cpup_attr_nlink(dir, /*force*/1);
23439 + au_dir_ts(dir, a->btgt);
23442 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23445 + dir = a->src_dir;
23446 + inode_inc_iversion(dir);
23447 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23448 + au_cpup_attr_nlink(dir, /*force*/1);
23449 + au_dir_ts(dir, a->btgt);
23452 +static void au_ren_refresh(struct au_ren_args *a)
23454 + aufs_bindex_t bbot, bindex;
23455 + struct dentry *d, *h_d;
23456 + struct inode *i, *h_i;
23457 + struct super_block *sb;
23459 + d = a->dst_dentry;
23462 + /* already dget-ed by au_ren_or_cpup() */
23463 + au_set_h_dptr(d, a->btgt, a->h_dst);
23465 + i = a->dst_inode;
23467 + if (!a->exchange) {
23468 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23469 + vfsub_drop_nlink(i);
23471 + vfsub_dead_dir(i);
23472 + au_cpup_attr_timesizes(i);
23474 + au_update_dbrange(d, /*do_put_zero*/1);
23476 + au_cpup_attr_nlink(i, /*force*/1);
23479 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23480 + au_set_h_dptr(d, bindex, NULL);
23481 + bbot = au_dbbot(d);
23482 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23483 + au_set_h_dptr(d, bindex, NULL);
23484 + au_update_dbrange(d, /*do_put_zero*/0);
23488 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23489 + d_drop(a->src_dentry);
23490 + if (au_ftest_ren(a->auren_flags, DIRREN))
23491 + au_set_dbwh(a->src_dentry, -1);
23495 + d = a->src_dentry;
23496 + au_set_dbwh(d, -1);
23497 + bbot = au_dbbot(d);
23498 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23499 + h_d = au_h_dptr(d, bindex);
23501 + au_set_h_dptr(d, bindex, NULL);
23503 + au_set_dbbot(d, a->btgt);
23506 + i = a->src_inode;
23507 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23508 + return; /* success */
23510 + bbot = au_ibbot(i);
23511 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23512 + h_i = au_h_iptr(i, bindex);
23514 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23515 + /* ignore this error */
23516 + au_set_h_iptr(i, bindex, NULL, 0);
23519 + au_set_ibbot(i, a->btgt);
23522 +/* ---------------------------------------------------------------------- */
23524 +/* mainly for link(2) and rename(2) */
23525 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23527 + aufs_bindex_t bdiropq, bwh;
23528 + struct dentry *parent;
23529 + struct au_branch *br;
23531 + parent = dentry->d_parent;
23532 + IMustLock(d_inode(parent)); /* dir is locked */
23534 + bdiropq = au_dbdiropq(parent);
23535 + bwh = au_dbwh(dentry);
23536 + br = au_sbr(dentry->d_sb, btgt);
23537 + if (au_br_rdonly(br)
23538 + || (0 <= bdiropq && bdiropq < btgt)
23539 + || (0 <= bwh && bwh < btgt))
23542 + AuDbg("btgt %d\n", btgt);
23546 +/* sets src_btop, dst_btop and btgt */
23547 +static int au_ren_wbr(struct au_ren_args *a)
23550 + struct au_wr_dir_args wr_dir_args = {
23551 + /* .force_btgt = -1, */
23552 + .flags = AuWrDir_ADD_ENTRY
23555 + a->src_btop = au_dbtop(a->src_dentry);
23556 + a->dst_btop = au_dbtop(a->dst_dentry);
23557 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23558 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23559 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23560 + wr_dir_args.force_btgt = a->src_btop;
23561 + if (a->dst_inode && a->dst_btop < a->src_btop)
23562 + wr_dir_args.force_btgt = a->dst_btop;
23563 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23564 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23567 + au_update_dbtop(a->dst_dentry);
23572 +static void au_ren_dt(struct au_ren_args *a)
23574 + a->h_path.dentry = a->src_h_parent;
23575 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23576 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23577 + a->h_path.dentry = a->dst_h_parent;
23578 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23581 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23582 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23586 + a->h_path.dentry = a->src_h_dentry;
23587 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23588 + if (d_is_positive(a->dst_h_dentry)) {
23589 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23590 + a->h_path.dentry = a->dst_h_dentry;
23591 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23595 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23597 + struct dentry *h_d;
23598 + struct inode *h_inode;
23600 + au_dtime_revert(a->src_dt + AuPARENT);
23601 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23602 + au_dtime_revert(a->dst_dt + AuPARENT);
23604 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23605 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23606 + h_inode = d_inode(h_d);
23607 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23608 + au_dtime_revert(a->src_dt + AuCHILD);
23609 + inode_unlock(h_inode);
23611 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23612 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23613 + h_inode = d_inode(h_d);
23614 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23615 + au_dtime_revert(a->dst_dt + AuCHILD);
23616 + inode_unlock(h_inode);
23621 +/* ---------------------------------------------------------------------- */
23623 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23624 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23625 + unsigned int _flags)
23627 + int err, lock_flags;
23629 + /* reduce stack space */
23630 + struct au_ren_args *a;
23631 + struct au_pin pin;
23633 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23634 + IMustLock(_src_dir);
23635 + IMustLock(_dst_dir);
23638 + if (unlikely(_flags & RENAME_WHITEOUT))
23642 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23643 + a = kzalloc(sizeof(*a), GFP_NOFS);
23644 + if (unlikely(!a))
23647 + a->flags = _flags;
23648 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23649 + && RENAME_EXCHANGE > U8_MAX);
23650 + a->exchange = _flags & RENAME_EXCHANGE;
23651 + a->src_dir = _src_dir;
23652 + a->src_dentry = _src_dentry;
23653 + a->src_inode = NULL;
23654 + if (d_really_is_positive(a->src_dentry))
23655 + a->src_inode = d_inode(a->src_dentry);
23656 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23657 + a->dst_dir = _dst_dir;
23658 + a->dst_dentry = _dst_dentry;
23659 + a->dst_inode = NULL;
23660 + if (d_really_is_positive(a->dst_dentry))
23661 + a->dst_inode = d_inode(a->dst_dentry);
23662 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23663 + if (a->dst_inode) {
23665 + * if EXCHANGE && src is non-dir && dst is dir,
23666 + * dst is not locked.
23668 + /* IMustLock(a->dst_inode); */
23669 + au_igrab(a->dst_inode);
23673 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23674 + if (d_is_dir(a->src_dentry)) {
23675 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23676 + if (unlikely(!a->exchange
23677 + && d_really_is_positive(a->dst_dentry)
23678 + && !d_is_dir(a->dst_dentry)))
23680 + lock_flags |= AuLock_DIRS;
23682 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23683 + au_fset_ren(a->auren_flags, ISDIR_DST);
23684 + if (unlikely(!a->exchange
23685 + && d_really_is_positive(a->src_dentry)
23686 + && !d_is_dir(a->src_dentry)))
23688 + lock_flags |= AuLock_DIRS;
23690 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23692 + if (unlikely(err))
23695 + err = au_d_hashed_positive(a->src_dentry);
23696 + if (unlikely(err))
23699 + if (a->dst_inode) {
23701 + * If it is a dir, VFS unhash it before this
23702 + * function. It means we cannot rely upon d_unhashed().
23704 + if (unlikely(!a->dst_inode->i_nlink))
23706 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23707 + err = au_d_hashed_positive(a->dst_dentry);
23708 + if (unlikely(err && !a->exchange))
23710 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23712 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23716 + * is it possible?
23717 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23718 + * there may exist a problem somewhere else.
23721 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23724 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23725 + di_write_lock_parent(a->dst_parent);
23727 + /* which branch we process */
23728 + err = au_ren_wbr(a);
23729 + if (unlikely(err < 0))
23731 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23732 + a->h_path.mnt = au_br_mnt(a->br);
23734 + /* are they available to be renamed */
23735 + err = au_ren_may_dir(a);
23736 + if (unlikely(err))
23737 + goto out_children;
23739 + /* prepare the writable parent dir on the same branch */
23740 + if (a->dst_btop == a->btgt) {
23741 + au_fset_ren(a->auren_flags, WHDST);
23743 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23744 + if (unlikely(err))
23745 + goto out_children;
23749 + if (!a->exchange) {
23750 + if (a->src_dir != a->dst_dir) {
23752 + * this temporary unlock is safe,
23753 + * because both dir->i_mutex are locked.
23755 + di_write_unlock(a->dst_parent);
23756 + di_write_lock_parent(a->src_parent);
23757 + err = au_wr_dir_need_wh(a->src_dentry,
23758 + au_ftest_ren(a->auren_flags,
23761 + di_write_unlock(a->src_parent);
23762 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23764 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23766 + err = au_wr_dir_need_wh(a->src_dentry,
23767 + au_ftest_ren(a->auren_flags,
23771 + if (unlikely(err < 0))
23772 + goto out_children;
23774 + au_fset_ren(a->auren_flags, WHSRC);
23777 + if (a->src_btop != a->btgt) {
23778 + err = au_pin(&pin, a->src_dentry, a->btgt,
23779 + au_opt_udba(a->src_dentry->d_sb),
23780 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23782 + struct au_cp_generic cpg = {
23783 + .dentry = a->src_dentry,
23785 + .bsrc = a->src_btop,
23788 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23790 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23791 + err = au_sio_cpup_simple(&cpg);
23794 + if (unlikely(err))
23795 + goto out_children;
23796 + a->src_btop = a->btgt;
23797 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23798 + if (!a->exchange)
23799 + au_fset_ren(a->auren_flags, WHSRC);
23803 + if (a->exchange && a->dst_inode
23804 + && a->dst_btop != a->btgt) {
23805 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23806 + au_opt_udba(a->dst_dentry->d_sb),
23807 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23809 + struct au_cp_generic cpg = {
23810 + .dentry = a->dst_dentry,
23812 + .bsrc = a->dst_btop,
23815 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23817 + err = au_sio_cpup_simple(&cpg);
23820 + if (unlikely(err))
23821 + goto out_children;
23822 + a->dst_btop = a->btgt;
23823 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23826 + /* lock them all */
23827 + err = au_ren_lock(a);
23828 + if (unlikely(err))
23829 + /* leave the copied-up one */
23830 + goto out_children;
23832 + if (!a->exchange) {
23833 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23834 + err = au_may_ren(a);
23835 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23836 + err = -ENAMETOOLONG;
23837 + if (unlikely(err))
23841 + /* store timestamps to be revertible */
23844 + /* store dirren info */
23845 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23846 + err = au_dr_rename(a->src_dentry, a->btgt,
23847 + &a->dst_dentry->d_name, &rev);
23849 + if (unlikely(err))
23854 + err = do_rename(a);
23855 + if (unlikely(err))
23858 + if (au_ftest_ren(a->auren_flags, DIRREN))
23859 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23861 + /* update dir attributes */
23862 + au_ren_refresh_dir(a);
23864 + /* dput/iput all lower dentries */
23865 + au_ren_refresh(a);
23867 + goto out_hdir; /* success */
23870 + if (au_ftest_ren(a->auren_flags, DIRREN))
23871 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23873 + au_ren_rev_dt(err, a);
23875 + au_ren_unlock(a);
23877 + au_nhash_wh_free(&a->whlist);
23878 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23879 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23880 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23881 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23885 + if (d_unhashed(a->src_dentry))
23886 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23887 + if (d_unhashed(a->dst_dentry))
23888 + au_fset_ren(a->auren_flags, DROPPED_DST);
23889 + if (!a->exchange)
23890 + d_move(a->src_dentry, a->dst_dentry);
23892 + d_exchange(a->src_dentry, a->dst_dentry);
23893 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23894 + d_drop(a->dst_dentry);
23896 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23897 + d_drop(a->src_dentry);
23899 + au_update_dbtop(a->dst_dentry);
23900 + if (!a->dst_inode)
23901 + d_drop(a->dst_dentry);
23903 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23904 + di_write_unlock(a->dst_parent);
23906 + di_write_unlock2(a->src_parent, a->dst_parent);
23908 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23910 + iput(a->dst_inode);
23912 + au_whtmp_rmdir_free(a->thargs);
23918 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23919 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23920 +++ linux/fs/aufs/Kconfig 2018-06-04 09:08:09.181412645 +0200
23922 +# SPDX-License-Identifier: GPL-2.0
23924 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23926 + Aufs is a stackable unification filesystem such as Unionfs,
23927 + which unifies several directories and provides a merged single
23929 + In the early days, aufs was entirely re-designed and
23930 + re-implemented Unionfs Version 1.x series. Introducing many
23931 + original ideas, approaches and improvements, it becomes totally
23932 + different from Unionfs while keeping the basic features.
23936 + prompt "Maximum number of branches"
23937 + default AUFS_BRANCH_MAX_127
23939 + Specifies the maximum number of branches (or member directories)
23940 + in a single aufs. The larger value consumes more system
23941 + resources and has a minor impact to performance.
23942 +config AUFS_BRANCH_MAX_127
23945 + Specifies the maximum number of branches (or member directories)
23946 + in a single aufs. The larger value consumes more system
23947 + resources and has a minor impact to performance.
23948 +config AUFS_BRANCH_MAX_511
23951 + Specifies the maximum number of branches (or member directories)
23952 + in a single aufs. The larger value consumes more system
23953 + resources and has a minor impact to performance.
23954 +config AUFS_BRANCH_MAX_1023
23957 + Specifies the maximum number of branches (or member directories)
23958 + in a single aufs. The larger value consumes more system
23959 + resources and has a minor impact to performance.
23960 +config AUFS_BRANCH_MAX_32767
23963 + Specifies the maximum number of branches (or member directories)
23964 + in a single aufs. The larger value consumes more system
23965 + resources and has a minor impact to performance.
23968 +config AUFS_SBILIST
23970 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23973 + Automatic configuration for internal use.
23974 + When aufs supports Magic SysRq or /proc, enabled automatically.
23976 +config AUFS_HNOTIFY
23977 + bool "Detect direct branch access (bypassing aufs)"
23979 + If you want to modify files on branches directly, eg. bypassing aufs,
23980 + and want aufs to detect the changes of them fully, then enable this
23981 + option and use 'udba=notify' mount option.
23982 + Currently there is only one available configuration, "fsnotify".
23983 + It will have a negative impact to the performance.
23984 + See detail in aufs.5.
23987 + prompt "method" if AUFS_HNOTIFY
23988 + default AUFS_HFSNOTIFY
23989 +config AUFS_HFSNOTIFY
23994 +config AUFS_EXPORT
23995 + bool "NFS-exportable aufs"
23996 + depends on EXPORTFS
23998 + If you want to export your mounted aufs via NFS, then enable this
23999 + option. There are several requirements for this configuration.
24000 + See detail in aufs.5.
24002 +config AUFS_INO_T_64
24004 + depends on AUFS_EXPORT
24005 + depends on 64BIT && !(ALPHA || S390)
24008 + Automatic configuration for internal use.
24009 + /* typedef unsigned long/int __kernel_ino_t */
24010 + /* alpha and s390x are int */
24013 + bool "support for XATTR/EA (including Security Labels)"
24015 + If your branch fs supports XATTR/EA and you want to make them
24016 + available in aufs too, then enable this opsion and specify the
24017 + branch attributes for EA.
24018 + See detail in aufs.5.
24021 + bool "File-based Hierarchical Storage Management"
24023 + Hierarchical Storage Management (or HSM) is a well-known feature
24024 + in the storage world. Aufs provides this feature as file-based.
24025 + with multiple branches.
24026 + These multiple branches are prioritized, ie. the topmost one
24027 + should be the fastest drive and be used heavily.
24030 + bool "Readdir in userspace"
24032 + Aufs has two methods to provide a merged view for a directory,
24033 + by a user-space library and by kernel-space natively. The latter
24034 + is always enabled but sometimes large and slow.
24035 + If you enable this option, install the library in aufs2-util
24036 + package, and set some environment variables for your readdir(3),
24037 + then the work will be handled in user-space which generally
24038 + shows better performance in most cases.
24039 + See detail in aufs.5.
24041 +config AUFS_DIRREN
24042 + bool "Workaround for rename(2)-ing a directory"
24044 + By default, aufs returns EXDEV error in renameing a dir who has
24045 + his child on the lower branch, since it is a bad idea to issue
24046 + rename(2) internally for every lower branch. But user may not
24047 + accept this behaviour. So here is a workaround to allow such
24048 + rename(2) and store some extra infromation on the writable
24049 + branch. Obviously this costs high (and I don't like it).
24050 + To use this feature, you need to enable this configuration AND
24051 + to specify the mount option `dirren.'
24052 + See details in aufs.5 and the design documents.
24055 + bool "Show whiteouts"
24057 + If you want to make the whiteouts in aufs visible, then enable
24058 + this option and specify 'shwh' mount option. Although it may
24059 + sounds like philosophy or something, but in technically it
24060 + simply shows the name of whiteout with keeping its behaviour.
24062 +config AUFS_BR_RAMFS
24063 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
24065 + If you want to use ramfs as an aufs branch fs, then enable this
24066 + option. Generally tmpfs is recommended.
24067 + Aufs prohibited them to be a branch fs by default, because
24068 + initramfs becomes unusable after switch_root or something
24069 + generally. If you sets initramfs as an aufs branch and boot your
24070 + system by switch_root, you will meet a problem easily since the
24071 + files in initramfs may be inaccessible.
24072 + Unless you are going to use ramfs as an aufs branch fs without
24073 + switch_root or something, leave it N.
24075 +config AUFS_BR_FUSE
24076 + bool "Fuse fs as an aufs branch"
24077 + depends on FUSE_FS
24080 + If you want to use fuse-based userspace filesystem as an aufs
24081 + branch fs, then enable this option.
24082 + It implements the internal poll(2) operation which is
24083 + implemented by fuse only (curretnly).
24088 + Automatic configuration for internal use.
24090 +config AUFS_BR_HFSPLUS
24091 + bool "Hfsplus as an aufs branch"
24092 + depends on HFSPLUS_FS
24095 + If you want to use hfsplus fs as an aufs branch fs, then enable
24096 + this option. This option introduces a small overhead at
24097 + copying-up a file on hfsplus.
24099 +config AUFS_BDEV_LOOP
24101 + depends on BLK_DEV_LOOP
24104 + Automatic configuration for internal use.
24105 + Convert =[ym] into =y.
24108 + bool "Debug aufs"
24110 + Enable this to compile aufs internal debug code.
24111 + It will have a negative impact to the performance.
24113 +config AUFS_MAGIC_SYSRQ
24115 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24118 + Automatic configuration for internal use.
24119 + When aufs supports Magic SysRq, enabled automatically.
24121 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24122 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24123 +++ linux/fs/aufs/lcnt.h 2018-10-23 12:33:35.599375796 +0200
24125 +/* SPDX-License-Identifier: GPL-2.0 */
24127 + * Copyright (C) 2018 Junjiro R. Okajima
24129 + * This program, aufs is free software; you can redistribute it and/or modify
24130 + * it under the terms of the GNU General Public License as published by
24131 + * the Free Software Foundation; either version 2 of the License, or
24132 + * (at your option) any later version.
24134 + * This program is distributed in the hope that it will be useful,
24135 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24136 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24137 + * GNU General Public License for more details.
24139 + * You should have received a copy of the GNU General Public License
24140 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24144 + * simple long counter wrapper
24147 +#ifndef __AUFS_LCNT_H__
24148 +#define __AUFS_LCNT_H__
24152 +#include "debug.h"
24154 +#define AuLCntATOMIC 1
24155 +#define AuLCntPCPUCNT 2
24157 + * why does percpu_refcount require extra synchronize_rcu()s in
24158 + * au_br_do_free()
24160 +#define AuLCntPCPUREF 3
24162 +/* #define AuLCntChosen AuLCntATOMIC */
24163 +#define AuLCntChosen AuLCntPCPUCNT
24164 +/* #define AuLCntChosen AuLCntPCPUREF */
24166 +#if AuLCntChosen == AuLCntATOMIC
24167 +#include <linux/atomic.h>
24169 +typedef atomic_long_t au_lcnt_t;
24171 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24173 + atomic_long_set(cnt, 0);
24177 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24182 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24183 + int do_sync __maybe_unused)
24188 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24190 + atomic_long_inc(cnt);
24193 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24195 + atomic_long_dec(cnt);
24198 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24200 + return atomic_long_read(cnt);
24204 +#if AuLCntChosen == AuLCntPCPUCNT
24205 +#include <linux/percpu_counter.h>
24207 +typedef struct percpu_counter au_lcnt_t;
24209 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24211 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24214 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24219 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24221 + percpu_counter_destroy(cnt);
24224 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24226 + percpu_counter_inc(cnt);
24229 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24231 + percpu_counter_dec(cnt);
24234 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24238 + n = percpu_counter_sum(cnt);
24240 + if (LONG_MAX != LLONG_MAX
24242 + AuWarn1("%s\n", "wrap-around");
24248 +#if AuLCntChosen == AuLCntPCPUREF
24249 +#include <linux/percpu-refcount.h>
24251 +typedef struct percpu_ref au_lcnt_t;
24253 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24256 + release = percpu_ref_exit;
24257 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24260 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24262 + synchronize_rcu();
24265 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24267 + percpu_ref_kill(cnt);
24269 + au_lcnt_wait_for_fin(cnt);
24272 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24274 + percpu_ref_get(cnt);
24277 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24279 + percpu_ref_put(cnt);
24283 + * avoid calling this func as possible.
24285 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24289 + percpu_ref_switch_to_atomic_sync(cnt);
24290 + l = atomic_long_read(&cnt->count);
24292 + percpu_ref_switch_to_percpu(cnt);
24294 + /* percpu_ref is initialized by 1 instead of 0 */
24299 +#ifdef CONFIG_AUFS_DEBUG
24300 +#define AuLCntZero(val) do { \
24303 + AuDbg("%s = %ld\n", #val, l); \
24306 +#define AuLCntZero(val) do {} while (0)
24309 +#endif /* __KERNEL__ */
24310 +#endif /* __AUFS_LCNT_H__ */
24311 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24312 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24313 +++ linux/fs/aufs/loop.c 2018-08-12 23:43:05.460124736 +0200
24315 +// SPDX-License-Identifier: GPL-2.0
24317 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24319 + * This program, aufs is free software; you can redistribute it and/or modify
24320 + * it under the terms of the GNU General Public License as published by
24321 + * the Free Software Foundation; either version 2 of the License, or
24322 + * (at your option) any later version.
24324 + * This program is distributed in the hope that it will be useful,
24325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24327 + * GNU General Public License for more details.
24329 + * You should have received a copy of the GNU General Public License
24330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24334 + * support for loopback block device as a branch
24339 +/* added into drivers/block/loop.c */
24340 +static struct file *(*backing_file_func)(struct super_block *sb);
24343 + * test if two lower dentries have overlapping branches.
24345 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24347 + struct super_block *h_sb;
24348 + struct file *backing_file;
24350 + if (unlikely(!backing_file_func)) {
24351 + /* don't load "loop" module here */
24352 + backing_file_func = symbol_get(loop_backing_file);
24353 + if (unlikely(!backing_file_func))
24354 + /* "loop" module is not loaded */
24358 + h_sb = h_adding->d_sb;
24359 + backing_file = backing_file_func(h_sb);
24360 + if (!backing_file)
24363 + h_adding = backing_file->f_path.dentry;
24365 + * h_adding can be local NFS.
24366 + * in this case aufs cannot detect the loop.
24368 + if (unlikely(h_adding->d_sb == sb))
24370 + return !!au_test_subdir(h_adding, sb->s_root);
24373 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24374 +int au_test_loopback_kthread(void)
24377 + struct task_struct *tsk = current;
24378 + char c, comm[sizeof(tsk->comm)];
24381 + if (tsk->flags & PF_KTHREAD) {
24382 + get_task_comm(comm, tsk);
24384 + ret = ('0' <= c && c <= '9'
24385 + && !strncmp(comm, "loop", 4));
24391 +/* ---------------------------------------------------------------------- */
24393 +#define au_warn_loopback_step 16
24394 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24395 +static unsigned long *au_warn_loopback_array;
24397 +void au_warn_loopback(struct super_block *h_sb)
24399 + int i, new_nelem;
24400 + unsigned long *a, magic;
24401 + static DEFINE_SPINLOCK(spin);
24403 + magic = h_sb->s_magic;
24404 + spin_lock(&spin);
24405 + a = au_warn_loopback_array;
24406 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24407 + if (a[i] == magic) {
24408 + spin_unlock(&spin);
24412 + /* h_sb is new to us, print it */
24413 + if (i < au_warn_loopback_nelem) {
24418 + /* expand the array */
24419 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24420 + a = au_kzrealloc(au_warn_loopback_array,
24421 + au_warn_loopback_nelem * sizeof(unsigned long),
24422 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24423 + /*may_shrink*/0);
24425 + au_warn_loopback_nelem = new_nelem;
24426 + au_warn_loopback_array = a;
24431 + spin_unlock(&spin);
24432 + AuWarn1("realloc failed, ignored\n");
24436 + spin_unlock(&spin);
24437 + pr_warn("you may want to try another patch for loopback file "
24438 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24441 +int au_loopback_init(void)
24444 + struct super_block *sb __maybe_unused;
24446 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24449 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24450 + sizeof(unsigned long), GFP_NOFS);
24451 + if (unlikely(!au_warn_loopback_array))
24457 +void au_loopback_fin(void)
24459 + if (backing_file_func)
24460 + symbol_put(loop_backing_file);
24461 + kfree(au_warn_loopback_array);
24463 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24464 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24465 +++ linux/fs/aufs/loop.h 2018-08-12 23:43:05.460124736 +0200
24467 +/* SPDX-License-Identifier: GPL-2.0 */
24469 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24471 + * This program, aufs is free software; you can redistribute it and/or modify
24472 + * it under the terms of the GNU General Public License as published by
24473 + * the Free Software Foundation; either version 2 of the License, or
24474 + * (at your option) any later version.
24476 + * This program is distributed in the hope that it will be useful,
24477 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24478 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24479 + * GNU General Public License for more details.
24481 + * You should have received a copy of the GNU General Public License
24482 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24486 + * support for loopback mount as a branch
24489 +#ifndef __AUFS_LOOP_H__
24490 +#define __AUFS_LOOP_H__
24495 +struct super_block;
24497 +#ifdef CONFIG_AUFS_BDEV_LOOP
24498 +/* drivers/block/loop.c */
24499 +struct file *loop_backing_file(struct super_block *sb);
24502 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24503 +int au_test_loopback_kthread(void);
24504 +void au_warn_loopback(struct super_block *h_sb);
24506 +int au_loopback_init(void);
24507 +void au_loopback_fin(void);
24509 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24510 + struct dentry *h_adding)
24511 +AuStubInt0(au_test_loopback_kthread, void)
24512 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24514 +AuStubInt0(au_loopback_init, void)
24515 +AuStubVoid(au_loopback_fin, void)
24516 +#endif /* BLK_DEV_LOOP */
24518 +#endif /* __KERNEL__ */
24519 +#endif /* __AUFS_LOOP_H__ */
24520 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24521 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24522 +++ linux/fs/aufs/magic.mk 2018-06-04 09:08:09.188079511 +0200
24524 +# SPDX-License-Identifier: GPL-2.0
24526 +# defined in ${srctree}/fs/fuse/inode.c
24528 +ifdef CONFIG_FUSE_FS
24529 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24532 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24534 +ifdef CONFIG_XFS_FS
24535 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24538 +# defined in ${srctree}/fs/configfs/mount.c
24540 +ifdef CONFIG_CONFIGFS_FS
24541 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24544 +# defined in ${srctree}/fs/ubifs/ubifs.h
24546 +ifdef CONFIG_UBIFS_FS
24547 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24550 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24552 +ifdef CONFIG_HFSPLUS_FS
24553 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24555 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24556 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24557 +++ linux/fs/aufs/Makefile 2018-06-04 09:08:09.181412645 +0200
24559 +# SPDX-License-Identifier: GPL-2.0
24561 +include ${src}/magic.mk
24562 +ifeq (${CONFIG_AUFS_FS},m)
24563 +include ${src}/conf.mk
24565 +-include ${src}/priv_def.mk
24567 +# cf. include/linux/kernel.h
24569 +ccflags-y += -DDEBUG
24570 +# sparse requires the full pathname
24572 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24574 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24577 +obj-$(CONFIG_AUFS_FS) += aufs.o
24578 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24579 + wkq.o vfsub.o dcsub.o \
24580 + cpup.o whout.o wbr_policy.o \
24581 + dinfo.o dentry.o \
24583 + finfo.o file.o f_op.o \
24585 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24589 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24590 +aufs-$(CONFIG_SYSFS) += sysfs.o
24591 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24592 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24593 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24594 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24595 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24596 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24597 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24598 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24599 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24600 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24601 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24602 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24603 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24604 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24605 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24606 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24607 +++ linux/fs/aufs/module.c 2018-08-12 23:43:05.460124736 +0200
24609 +// SPDX-License-Identifier: GPL-2.0
24611 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24613 + * This program, aufs is free software; you can redistribute it and/or modify
24614 + * it under the terms of the GNU General Public License as published by
24615 + * the Free Software Foundation; either version 2 of the License, or
24616 + * (at your option) any later version.
24618 + * This program is distributed in the hope that it will be useful,
24619 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24620 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24621 + * GNU General Public License for more details.
24623 + * You should have received a copy of the GNU General Public License
24624 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24628 + * module global variables and operations
24631 +#include <linux/module.h>
24632 +#include <linux/seq_file.h>
24635 +/* shrinkable realloc */
24636 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24644 +#if 0 /* unused */
24651 + AuDebugOn(!new_sz);
24654 + diff = au_kmidx_sub(sz, new_sz);
24660 + /* expand or SLOB */
24661 + p = krealloc(p, new_sz, gfp);
24662 + else if (new_sz < sz && may_shrink) {
24666 + q = kmalloc(new_sz, gfp);
24669 + memcpy(q, p, new_sz);
24681 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24684 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24685 + if (p && new_sz > nused)
24686 + memset(p + nused, 0, new_sz - nused);
24690 +/* ---------------------------------------------------------------------- */
24694 +struct kmem_cache *au_cache[AuCache_Last];
24696 +static void au_cache_fin(void)
24701 + * Make sure all delayed rcu free inodes are flushed before we
24706 + /* excluding AuCache_HNOTIFY */
24707 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24708 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24709 + kmem_cache_destroy(au_cache[i]);
24710 + au_cache[i] = NULL;
24714 +static int __init au_cache_init(void)
24716 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24717 + if (au_cache[AuCache_DINFO])
24718 + /* SLAB_DESTROY_BY_RCU */
24719 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24720 + au_icntnr_init_once);
24721 + if (au_cache[AuCache_ICNTNR])
24722 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24723 + au_fi_init_once);
24724 + if (au_cache[AuCache_FINFO])
24725 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24726 + if (au_cache[AuCache_VDIR])
24727 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24728 + if (au_cache[AuCache_DEHSTR])
24735 +/* ---------------------------------------------------------------------- */
24737 +int au_dir_roflags;
24739 +#ifdef CONFIG_AUFS_SBILIST
24741 + * iterate_supers_type() doesn't protect us from
24742 + * remounting (branch management)
24744 +struct hlist_bl_head au_sbilist;
24748 + * functions for module interface.
24750 +MODULE_LICENSE("GPL");
24751 +/* MODULE_LICENSE("GPL v2"); */
24752 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24753 +MODULE_DESCRIPTION(AUFS_NAME
24754 + " -- Advanced multi layered unification filesystem");
24755 +MODULE_VERSION(AUFS_VERSION);
24756 +MODULE_ALIAS_FS(AUFS_NAME);
24758 +/* this module parameter has no meaning when SYSFS is disabled */
24759 +int sysaufs_brs = 1;
24760 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24761 +module_param_named(brs, sysaufs_brs, int, 0444);
24763 +/* this module parameter has no meaning when USER_NS is disabled */
24765 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24766 +module_param_named(allow_userns, au_userns, bool, 0444);
24768 +/* ---------------------------------------------------------------------- */
24770 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24772 +int au_seq_path(struct seq_file *seq, struct path *path)
24776 + err = seq_path(seq, path, au_esc_chars);
24785 +/* ---------------------------------------------------------------------- */
24787 +static int __init aufs_init(void)
24792 + p = au_esc_chars;
24793 + for (i = 1; i <= ' '; i++)
24799 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24801 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24802 + for (i = 0; i < AuIop_Last; i++)
24803 + aufs_iop_nogetattr[i].getattr = NULL;
24805 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24807 + au_sbilist_init();
24808 + sysaufs_brs_init();
24811 + err = sysaufs_init();
24812 + if (unlikely(err))
24814 + err = dbgaufs_init();
24815 + if (unlikely(err))
24816 + goto out_sysaufs;
24817 + err = au_procfs_init();
24818 + if (unlikely(err))
24819 + goto out_dbgaufs;
24820 + err = au_wkq_init();
24821 + if (unlikely(err))
24823 + err = au_loopback_init();
24824 + if (unlikely(err))
24826 + err = au_hnotify_init();
24827 + if (unlikely(err))
24828 + goto out_loopback;
24829 + err = au_sysrq_init();
24830 + if (unlikely(err))
24832 + err = au_cache_init();
24833 + if (unlikely(err))
24836 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24837 + err = register_filesystem(&aufs_fs_type);
24838 + if (unlikely(err))
24841 + /* since we define pr_fmt, call printk directly */
24842 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24843 + goto out; /* success */
24850 + au_hnotify_fin();
24852 + au_loopback_fin();
24866 +static void __exit aufs_exit(void)
24868 + unregister_filesystem(&aufs_fs_type);
24871 + au_hnotify_fin();
24872 + au_loopback_fin();
24880 +module_init(aufs_init);
24881 +module_exit(aufs_exit);
24882 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24883 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24884 +++ linux/fs/aufs/module.h 2018-08-12 23:43:05.460124736 +0200
24886 +/* SPDX-License-Identifier: GPL-2.0 */
24888 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24890 + * This program, aufs is free software; you can redistribute it and/or modify
24891 + * it under the terms of the GNU General Public License as published by
24892 + * the Free Software Foundation; either version 2 of the License, or
24893 + * (at your option) any later version.
24895 + * This program is distributed in the hope that it will be useful,
24896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24898 + * GNU General Public License for more details.
24900 + * You should have received a copy of the GNU General Public License
24901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24905 + * module initialization and module-global
24908 +#ifndef __AUFS_MODULE_H__
24909 +#define __AUFS_MODULE_H__
24913 +#include <linux/slab.h>
24918 +/* module parameters */
24919 +extern int sysaufs_brs;
24920 +extern bool au_userns;
24922 +/* ---------------------------------------------------------------------- */
24924 +extern int au_dir_roflags;
24926 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24927 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24930 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24932 +#ifndef CONFIG_SLOB
24933 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24935 + return -1; /* SLOB is untested */
24939 +int au_seq_path(struct seq_file *seq, struct path *path);
24941 +#ifdef CONFIG_PROC_FS
24943 +int __init au_procfs_init(void);
24944 +void au_procfs_fin(void);
24946 +AuStubInt0(au_procfs_init, void);
24947 +AuStubVoid(au_procfs_fin, void);
24950 +/* ---------------------------------------------------------------------- */
24959 + AuCache_HNOTIFY, /* must be last */
24963 +extern struct kmem_cache *au_cache[AuCache_Last];
24965 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24966 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24967 +#define AuCacheCtor(type, ctor) \
24968 + kmem_cache_create(#type, sizeof(struct type), \
24969 + __alignof__(struct type), AuCacheFlags, ctor)
24971 +#define AuCacheFuncs(name, index) \
24972 +static inline struct au_##name *au_cache_alloc_##name(void) \
24973 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24974 +static inline void au_cache_free_##name(struct au_##name *p) \
24975 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
24977 +AuCacheFuncs(dinfo, DINFO);
24978 +AuCacheFuncs(icntnr, ICNTNR);
24979 +AuCacheFuncs(finfo, FINFO);
24980 +AuCacheFuncs(vdir, VDIR);
24981 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24982 +#ifdef CONFIG_AUFS_HNOTIFY
24983 +AuCacheFuncs(hnotify, HNOTIFY);
24986 +#endif /* __KERNEL__ */
24987 +#endif /* __AUFS_MODULE_H__ */
24988 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24989 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24990 +++ linux/fs/aufs/mvdown.c 2018-08-12 23:43:05.460124736 +0200
24992 +// SPDX-License-Identifier: GPL-2.0
24994 + * Copyright (C) 2011-2018 Junjiro R. Okajima
24996 + * This program, aufs is free software; you can redistribute it and/or modify
24997 + * it under the terms of the GNU General Public License as published by
24998 + * the Free Software Foundation; either version 2 of the License, or
24999 + * (at your option) any later version.
25001 + * This program is distributed in the hope that it will be useful,
25002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25004 + * GNU General Public License for more details.
25006 + * You should have received a copy of the GNU General Public License
25007 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25011 + * move-down, opposite of copy-up
25016 +struct au_mvd_args {
25018 + struct super_block *h_sb;
25019 + struct dentry *h_parent;
25020 + struct au_hinode *hdir;
25021 + struct inode *h_dir, *h_inode;
25022 + struct au_pin pin;
25023 + } info[AUFS_MVDOWN_NARRAY];
25025 + struct aufs_mvdown mvdown;
25026 + struct dentry *dentry, *parent;
25027 + struct inode *inode, *dir;
25028 + struct super_block *sb;
25029 + aufs_bindex_t bopq, bwh, bfound;
25030 + unsigned char rename_lock;
25033 +#define mvd_errno mvdown.au_errno
25034 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25035 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25036 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25037 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25039 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25040 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25041 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25042 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25043 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25044 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25046 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25047 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25048 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25049 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25050 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25051 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25053 +#define AU_MVD_PR(flag, ...) do { \
25055 + pr_err(__VA_ARGS__); \
25058 +static int find_lower_writable(struct au_mvd_args *a)
25060 + struct super_block *sb;
25061 + aufs_bindex_t bindex, bbot;
25062 + struct au_branch *br;
25065 + bindex = a->mvd_bsrc;
25066 + bbot = au_sbbot(sb);
25067 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25068 + for (bindex++; bindex <= bbot; bindex++) {
25069 + br = au_sbr(sb, bindex);
25070 + if (au_br_fhsm(br->br_perm)
25071 + && !sb_rdonly(au_br_sb(br)))
25074 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25075 + for (bindex++; bindex <= bbot; bindex++) {
25076 + br = au_sbr(sb, bindex);
25077 + if (!au_br_rdonly(br))
25081 + for (bindex++; bindex <= bbot; bindex++) {
25082 + br = au_sbr(sb, bindex);
25083 + if (!sb_rdonly(au_br_sb(br))) {
25084 + if (au_br_rdonly(br))
25086 + |= AUFS_MVDOWN_ROLOWER_R;
25094 +/* make the parent dir on bdst */
25095 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25100 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25101 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25102 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25103 + a->mvd_h_dst_parent = NULL;
25104 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25105 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25106 + if (!a->mvd_h_dst_parent) {
25107 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25108 + if (unlikely(err)) {
25109 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25112 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25120 +/* lock them all */
25121 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25124 + struct dentry *h_trap;
25126 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25127 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25128 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25129 + au_opt_udba(a->sb),
25130 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25132 + if (unlikely(err)) {
25133 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25137 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25138 + a->rename_lock = 0;
25139 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25140 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25141 + au_opt_udba(a->sb),
25142 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25143 + err = au_do_pin(&a->mvd_pin_src);
25145 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25146 + if (unlikely(err)) {
25147 + AU_MVD_PR(dmsg, "pin_src failed\n");
25150 + goto out; /* success */
25153 + a->rename_lock = 1;
25154 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25155 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25156 + au_opt_udba(a->sb),
25157 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25159 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25160 + if (unlikely(err)) {
25161 + AU_MVD_PR(dmsg, "pin_src failed\n");
25162 + au_pin_hdir_lock(&a->mvd_pin_dst);
25165 + au_pin_hdir_unlock(&a->mvd_pin_src);
25166 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25167 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25169 + err = (h_trap != a->mvd_h_src_parent);
25171 + err = (h_trap != a->mvd_h_dst_parent);
25173 + BUG_ON(err); /* it should never happen */
25174 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25177 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25178 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25179 + au_pin_hdir_lock(&a->mvd_pin_src);
25180 + au_unpin(&a->mvd_pin_src);
25181 + au_pin_hdir_lock(&a->mvd_pin_dst);
25184 + goto out; /* success */
25187 + au_unpin(&a->mvd_pin_dst);
25193 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25195 + if (!a->rename_lock)
25196 + au_unpin(&a->mvd_pin_src);
25198 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25199 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25200 + au_pin_hdir_lock(&a->mvd_pin_src);
25201 + au_unpin(&a->mvd_pin_src);
25202 + au_pin_hdir_lock(&a->mvd_pin_dst);
25204 + au_unpin(&a->mvd_pin_dst);
25207 +/* copy-down the file */
25208 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25211 + struct au_cp_generic cpg = {
25212 + .dentry = a->dentry,
25213 + .bdst = a->mvd_bdst,
25214 + .bsrc = a->mvd_bsrc,
25216 + .pin = &a->mvd_pin_dst,
25217 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25220 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25221 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25222 + au_fset_cpup(cpg.flags, OVERWRITE);
25223 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25224 + au_fset_cpup(cpg.flags, RWDST);
25225 + err = au_sio_cpdown_simple(&cpg);
25226 + if (unlikely(err))
25227 + AU_MVD_PR(dmsg, "cpdown failed\n");
25234 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25237 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25240 + struct path h_path;
25241 + struct au_branch *br;
25242 + struct inode *delegated;
25244 + br = au_sbr(a->sb, a->mvd_bdst);
25245 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25246 + err = PTR_ERR(h_path.dentry);
25247 + if (IS_ERR(h_path.dentry)) {
25248 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25253 + if (d_is_positive(h_path.dentry)) {
25254 + h_path.mnt = au_br_mnt(br);
25255 + delegated = NULL;
25256 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25257 + &delegated, /*force*/0);
25258 + if (unlikely(err == -EWOULDBLOCK)) {
25259 + pr_warn("cannot retry for NFSv4 delegation"
25260 + " for an internal unlink\n");
25263 + if (unlikely(err))
25264 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25266 + dput(h_path.dentry);
25274 + * unlink the topmost h_dentry
25276 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25279 + struct path h_path;
25280 + struct inode *delegated;
25282 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25283 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25284 + delegated = NULL;
25285 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25286 + if (unlikely(err == -EWOULDBLOCK)) {
25287 + pr_warn("cannot retry for NFSv4 delegation"
25288 + " for an internal unlink\n");
25291 + if (unlikely(err))
25292 + AU_MVD_PR(dmsg, "unlink failed\n");
25298 +/* Since mvdown succeeded, we ignore an error of this function */
25299 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25302 + struct au_branch *br;
25304 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25305 + br = au_sbr(a->sb, a->mvd_bsrc);
25306 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25308 + br = au_sbr(a->sb, a->mvd_bdst);
25309 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25310 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25313 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25315 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25319 + * copy-down the file and unlink the bsrc file.
25320 + * - unlink the bdst whout if exist
25321 + * - copy-down the file (with whtmp name and rename)
25322 + * - unlink the bsrc file
25324 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25328 + err = au_do_mkdir(dmsg, a);
25330 + err = au_do_lock(dmsg, a);
25331 + if (unlikely(err))
25335 + * do not revert the activities we made on bdst since they should be
25336 + * harmless in aufs.
25339 + err = au_do_cpdown(dmsg, a);
25341 + err = au_do_unlink_wh(dmsg, a);
25342 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25343 + err = au_do_unlink(dmsg, a);
25344 + if (unlikely(err))
25347 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25348 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25349 + if (find_lower_writable(a) < 0)
25350 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25352 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25353 + au_do_stfs(dmsg, a);
25355 + /* maintain internal array */
25356 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25357 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25358 + au_set_dbtop(a->dentry, a->mvd_bdst);
25359 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25360 + au_set_ibtop(a->inode, a->mvd_bdst);
25362 + /* hide the lower */
25363 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25364 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25365 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25366 + au_set_ibbot(a->inode, a->mvd_bsrc);
25368 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25369 + au_set_dbbot(a->dentry, a->mvd_bdst);
25370 + if (au_ibbot(a->inode) < a->mvd_bdst)
25371 + au_set_ibbot(a->inode, a->mvd_bdst);
25374 + au_do_unlock(dmsg, a);
25380 +/* ---------------------------------------------------------------------- */
25382 +/* make sure the file is idle */
25383 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25385 + int err, plinked;
25388 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25389 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25390 + && au_dcount(a->dentry) == 1
25391 + && atomic_read(&a->inode->i_count) == 1
25392 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25393 + && (!plinked || !au_plink_test(a->inode))
25394 + && a->inode->i_nlink == 1)
25399 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25400 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25401 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25402 + a->mvd_h_src_inode->i_nlink,
25403 + plinked, plinked ? au_plink_test(a->inode) : 0);
25410 +/* make sure the parent dir is fine */
25411 +static int au_mvd_args_parent(const unsigned char dmsg,
25412 + struct au_mvd_args *a)
25415 + aufs_bindex_t bindex;
25418 + if (unlikely(au_alive_dir(a->parent))) {
25420 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25424 + a->bopq = au_dbdiropq(a->parent);
25425 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25426 + AuDbg("b%d\n", bindex);
25427 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25428 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25430 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25431 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25432 + a->bopq, a->mvd_bdst);
25440 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25441 + struct au_mvd_args *a)
25444 + struct au_dinfo *dinfo, *tmp;
25446 + /* lookup the next lower positive entry */
25448 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25449 + if (unlikely(!tmp))
25454 + dinfo = au_di(a->dentry);
25455 + au_di_cp(tmp, dinfo);
25456 + au_di_swap(tmp, dinfo);
25458 + /* returns the number of positive dentries */
25459 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25460 + /* AuLkup_IGNORE_PERM */ 0);
25462 + a->bwh = au_dbwh(a->dentry);
25463 + else if (err > 0)
25464 + a->bfound = au_dbtop(a->dentry);
25466 + au_di_swap(tmp, dinfo);
25467 + au_rw_write_unlock(&tmp->di_rwsem);
25469 + if (unlikely(err < 0))
25470 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25473 + * here, we have these cases.
25475 + * no positive dentry under bsrc. there are more sub-cases.
25477 + * there no whiteout, we can safely move-down.
25480 + * bsrc < bwh && bwh < bdst
25481 + * there is a whiteout on RO branch. cannot proceed.
25483 + * there is a whiteout on the RW target branch. it should
25486 + * there is a whiteout somewhere unrelated branch.
25487 + * -1 < bfound && bfound <= bsrc
25490 + * found, but it is on RO branch between bsrc and bdst. cannot
25493 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25496 + * found, after we create the file on bdst, it will be hidden.
25499 + AuDebugOn(a->bfound == -1
25501 + && a->bwh <= a->mvd_bsrc);
25502 + AuDebugOn(-1 < a->bfound
25503 + && a->bfound <= a->mvd_bsrc);
25506 + if (a->bfound == -1
25507 + && a->mvd_bsrc < a->bwh
25509 + && a->bwh < a->mvd_bdst) {
25510 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25511 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25512 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25514 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25515 + a->mvd_errno = EAU_MVDOWN_UPPER;
25516 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25517 + a->mvd_bdst, a->bfound);
25521 + err = 0; /* success */
25528 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25533 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25534 + && a->bfound == a->mvd_bdst)
25540 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25543 + struct au_branch *br;
25546 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25550 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25551 + a->mvd_bsrc = au_ibtop(a->inode);
25553 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25554 + if (unlikely(a->mvd_bsrc < 0
25555 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25556 + || au_dbbot(a->dentry) < a->mvd_bsrc
25557 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25558 + || (a->mvd_bsrc < au_ibtop(a->inode)
25559 + || au_ibbot(a->inode) < a->mvd_bsrc
25560 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25561 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25562 + AU_MVD_PR(dmsg, "no upper\n");
25566 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25567 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25568 + AU_MVD_PR(dmsg, "on the bottom\n");
25571 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25572 + br = au_sbr(a->sb, a->mvd_bsrc);
25573 + err = au_br_rdonly(br);
25574 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25575 + if (unlikely(err))
25577 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25578 + || IS_APPEND(a->mvd_h_src_inode))) {
25580 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25586 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25587 + a->mvd_bdst = find_lower_writable(a);
25588 + if (unlikely(a->mvd_bdst < 0)) {
25589 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25590 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25594 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25595 + if (unlikely(a->mvd_bdst < 0
25596 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25597 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25598 + AU_MVD_PR(dmsg, "no lower brid\n");
25603 + err = au_mvd_args_busy(dmsg, a);
25605 + err = au_mvd_args_parent(dmsg, a);
25607 + err = au_mvd_args_intermediate(dmsg, a);
25609 + err = au_mvd_args_exist(dmsg, a);
25611 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25618 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25621 + unsigned char dmsg;
25622 + struct au_mvd_args *args;
25623 + struct inode *inode;
25625 + inode = d_inode(dentry);
25627 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25631 + args = kmalloc(sizeof(*args), GFP_NOFS);
25632 + if (unlikely(!args))
25635 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25637 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25638 + if (unlikely(err)) {
25643 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25644 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25645 + args->mvdown.au_errno = 0;
25646 + args->dentry = dentry;
25647 + args->inode = inode;
25648 + args->sb = dentry->d_sb;
25651 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25652 + args->parent = dget_parent(dentry);
25653 + args->dir = d_inode(args->parent);
25654 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25655 + dput(args->parent);
25656 + if (unlikely(args->parent != dentry->d_parent)) {
25657 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25661 + inode_lock_nested(inode, I_MUTEX_CHILD);
25662 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25663 + if (unlikely(err))
25666 + di_write_lock_parent(args->parent);
25667 + err = au_mvd_args(dmsg, args);
25668 + if (unlikely(err))
25671 + err = au_do_mvdown(dmsg, args);
25672 + if (unlikely(err))
25675 + au_cpup_attr_timesizes(args->dir);
25676 + au_cpup_attr_timesizes(inode);
25677 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25678 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25679 + /* au_digen_dec(dentry); */
25682 + di_write_unlock(args->parent);
25683 + aufs_read_unlock(dentry, AuLock_DW);
25685 + inode_unlock(inode);
25687 + inode_unlock(args->dir);
25689 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25697 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25698 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25699 +++ linux/fs/aufs/opts.c 2018-10-23 12:33:35.599375796 +0200
25701 +// SPDX-License-Identifier: GPL-2.0
25703 + * Copyright (C) 2005-2018 Junjiro R. Okajima
25705 + * This program, aufs is free software; you can redistribute it and/or modify
25706 + * it under the terms of the GNU General Public License as published by
25707 + * the Free Software Foundation; either version 2 of the License, or
25708 + * (at your option) any later version.
25710 + * This program is distributed in the hope that it will be useful,
25711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25713 + * GNU General Public License for more details.
25715 + * You should have received a copy of the GNU General Public License
25716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25720 + * mount options/flags
25723 +#include <linux/namei.h>
25724 +#include <linux/types.h> /* a distribution requires */
25725 +#include <linux/parser.h>
25728 +/* ---------------------------------------------------------------------- */
25732 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25733 + Opt_idel, Opt_imod,
25734 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25735 + Opt_rdblk_def, Opt_rdhash_def,
25736 + Opt_xino, Opt_noxino,
25737 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25738 + Opt_trunc_xino_path, Opt_itrunc_xino,
25739 + Opt_trunc_xib, Opt_notrunc_xib,
25740 + Opt_shwh, Opt_noshwh,
25741 + Opt_plink, Opt_noplink, Opt_list_plink,
25743 + Opt_dio, Opt_nodio,
25744 + Opt_diropq_a, Opt_diropq_w,
25745 + Opt_warn_perm, Opt_nowarn_perm,
25746 + Opt_wbr_copyup, Opt_wbr_create,
25748 + Opt_verbose, Opt_noverbose,
25749 + Opt_sum, Opt_nosum, Opt_wsum,
25750 + Opt_dirperm1, Opt_nodirperm1,
25751 + Opt_dirren, Opt_nodirren,
25752 + Opt_acl, Opt_noacl,
25753 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25756 +static match_table_t options = {
25757 + {Opt_br, "br=%s"},
25758 + {Opt_br, "br:%s"},
25760 + {Opt_add, "add=%d:%s"},
25761 + {Opt_add, "add:%d:%s"},
25762 + {Opt_add, "ins=%d:%s"},
25763 + {Opt_add, "ins:%d:%s"},
25764 + {Opt_append, "append=%s"},
25765 + {Opt_append, "append:%s"},
25766 + {Opt_prepend, "prepend=%s"},
25767 + {Opt_prepend, "prepend:%s"},
25769 + {Opt_del, "del=%s"},
25770 + {Opt_del, "del:%s"},
25771 + /* {Opt_idel, "idel:%d"}, */
25772 + {Opt_mod, "mod=%s"},
25773 + {Opt_mod, "mod:%s"},
25774 + /* {Opt_imod, "imod:%d:%s"}, */
25776 + {Opt_dirwh, "dirwh=%d"},
25778 + {Opt_xino, "xino=%s"},
25779 + {Opt_noxino, "noxino"},
25780 + {Opt_trunc_xino, "trunc_xino"},
25781 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25782 + {Opt_notrunc_xino, "notrunc_xino"},
25783 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25784 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25785 + /* {Opt_zxino, "zxino=%s"}, */
25786 + {Opt_trunc_xib, "trunc_xib"},
25787 + {Opt_notrunc_xib, "notrunc_xib"},
25789 +#ifdef CONFIG_PROC_FS
25790 + {Opt_plink, "plink"},
25792 + {Opt_ignore_silent, "plink"},
25795 + {Opt_noplink, "noplink"},
25797 +#ifdef CONFIG_AUFS_DEBUG
25798 + {Opt_list_plink, "list_plink"},
25801 + {Opt_udba, "udba=%s"},
25803 + {Opt_dio, "dio"},
25804 + {Opt_nodio, "nodio"},
25806 +#ifdef CONFIG_AUFS_DIRREN
25807 + {Opt_dirren, "dirren"},
25808 + {Opt_nodirren, "nodirren"},
25810 + {Opt_ignore, "dirren"},
25811 + {Opt_ignore_silent, "nodirren"},
25814 +#ifdef CONFIG_AUFS_FHSM
25815 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25817 + {Opt_ignore, "fhsm_sec=%d"},
25820 + {Opt_diropq_a, "diropq=always"},
25821 + {Opt_diropq_a, "diropq=a"},
25822 + {Opt_diropq_w, "diropq=whiteouted"},
25823 + {Opt_diropq_w, "diropq=w"},
25825 + {Opt_warn_perm, "warn_perm"},
25826 + {Opt_nowarn_perm, "nowarn_perm"},
25828 + /* keep them temporary */
25829 + {Opt_ignore_silent, "nodlgt"},
25830 + {Opt_ignore, "clean_plink"},
25832 +#ifdef CONFIG_AUFS_SHWH
25833 + {Opt_shwh, "shwh"},
25835 + {Opt_noshwh, "noshwh"},
25837 + {Opt_dirperm1, "dirperm1"},
25838 + {Opt_nodirperm1, "nodirperm1"},
25840 + {Opt_verbose, "verbose"},
25841 + {Opt_verbose, "v"},
25842 + {Opt_noverbose, "noverbose"},
25843 + {Opt_noverbose, "quiet"},
25844 + {Opt_noverbose, "q"},
25845 + {Opt_noverbose, "silent"},
25847 + {Opt_sum, "sum"},
25848 + {Opt_nosum, "nosum"},
25849 + {Opt_wsum, "wsum"},
25851 + {Opt_rdcache, "rdcache=%d"},
25852 + {Opt_rdblk, "rdblk=%d"},
25853 + {Opt_rdblk_def, "rdblk=def"},
25854 + {Opt_rdhash, "rdhash=%d"},
25855 + {Opt_rdhash_def, "rdhash=def"},
25857 + {Opt_wbr_create, "create=%s"},
25858 + {Opt_wbr_create, "create_policy=%s"},
25859 + {Opt_wbr_copyup, "cpup=%s"},
25860 + {Opt_wbr_copyup, "copyup=%s"},
25861 + {Opt_wbr_copyup, "copyup_policy=%s"},
25863 + /* generic VFS flag */
25864 +#ifdef CONFIG_FS_POSIX_ACL
25865 + {Opt_acl, "acl"},
25866 + {Opt_noacl, "noacl"},
25868 + {Opt_ignore, "acl"},
25869 + {Opt_ignore_silent, "noacl"},
25872 + /* internal use for the scripts */
25873 + {Opt_ignore_silent, "si=%s"},
25875 + {Opt_br, "dirs=%s"},
25876 + {Opt_ignore, "debug=%d"},
25877 + {Opt_ignore, "delete=whiteout"},
25878 + {Opt_ignore, "delete=all"},
25879 + {Opt_ignore, "imap=%s"},
25881 + /* temporary workaround, due to old mount(8)? */
25882 + {Opt_ignore_silent, "relatime"},
25887 +/* ---------------------------------------------------------------------- */
25889 +static const char *au_parser_pattern(int val, match_table_t tbl)
25891 + struct match_token *p;
25894 + while (p->pattern) {
25895 + if (p->token == val)
25896 + return p->pattern;
25903 +static const char *au_optstr(int *val, match_table_t tbl)
25905 + struct match_token *p;
25912 + while (p->pattern) {
25914 + && (v & p->token) == p->token) {
25915 + *val &= ~p->token;
25916 + return p->pattern;
25925 +/* ---------------------------------------------------------------------- */
25927 +static match_table_t brperm = {
25928 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25929 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25930 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25934 +static match_table_t brattr = {
25936 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25937 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25938 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25939 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25940 +#ifdef CONFIG_AUFS_FHSM
25941 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25943 +#ifdef CONFIG_AUFS_XATTR
25944 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25945 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25946 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25947 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25948 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25949 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25952 + /* ro/rr branch */
25953 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25956 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25957 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25962 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25969 + p = strchr(str, '+');
25972 + v = match_token(str, table, args);
25974 + if (v & AuBrAttr_CMOO_Mask)
25975 + attr &= ~AuBrAttr_CMOO_Mask;
25980 + pr_warn("ignored branch attribute %s\n", str);
25990 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25998 + p = au_optstr(&perm, brattr);
26001 + memcpy(q, p, sz + 1);
26007 + p = au_optstr(&perm, brattr);
26011 + memcpy(q, p, sz + 1);
26017 + return q - str->a;
26020 +static int noinline_for_stack br_perm_val(char *perm)
26022 + int val, bad, sz;
26024 + substring_t args[MAX_OPT_ARGS];
26025 + au_br_perm_str_t attr;
26027 + p = strchr(perm, '+');
26030 + val = match_token(perm, brperm, args);
26034 + pr_warn("ignored branch permission %s\n", perm);
26035 + val = AuBrPerm_RO;
26041 + val |= br_attr_val(p + 1, brattr, args);
26044 + switch (val & AuBrPerm_Mask) {
26045 + case AuBrPerm_RO:
26046 + case AuBrPerm_RR:
26047 + bad = val & AuBrWAttr_Mask;
26048 + val &= ~AuBrWAttr_Mask;
26050 + case AuBrPerm_RW:
26051 + bad = val & AuBrRAttr_Mask;
26052 + val &= ~AuBrRAttr_Mask;
26057 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26058 + * does not treat it as an error, just warning.
26059 + * this is a tiny guard for the user operation.
26061 + if (val & AuBrAttr_UNPIN) {
26062 + bad |= AuBrAttr_UNPIN;
26063 + val &= ~AuBrAttr_UNPIN;
26066 + if (unlikely(bad)) {
26067 + sz = au_do_optstr_br_attr(&attr, bad);
26069 + pr_warn("ignored branch attribute %s\n", attr.a);
26076 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26078 + au_br_perm_str_t attr;
26084 + p = au_optstr(&perm, brperm);
26085 + AuDebugOn(!p || !*p);
26087 + memcpy(q, p, sz + 1);
26090 + sz = au_do_optstr_br_attr(&attr, perm);
26093 + memcpy(q, attr.a, sz + 1);
26096 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26099 +/* ---------------------------------------------------------------------- */
26101 +static match_table_t udbalevel = {
26102 + {AuOpt_UDBA_REVAL, "reval"},
26103 + {AuOpt_UDBA_NONE, "none"},
26104 +#ifdef CONFIG_AUFS_HNOTIFY
26105 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26106 +#ifdef CONFIG_AUFS_HFSNOTIFY
26107 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26113 +static int noinline_for_stack udba_val(char *str)
26115 + substring_t args[MAX_OPT_ARGS];
26117 + return match_token(str, udbalevel, args);
26120 +const char *au_optstr_udba(int udba)
26122 + return au_parser_pattern(udba, udbalevel);
26125 +/* ---------------------------------------------------------------------- */
26127 +static match_table_t au_wbr_create_policy = {
26128 + {AuWbrCreate_TDP, "tdp"},
26129 + {AuWbrCreate_TDP, "top-down-parent"},
26130 + {AuWbrCreate_RR, "rr"},
26131 + {AuWbrCreate_RR, "round-robin"},
26132 + {AuWbrCreate_MFS, "mfs"},
26133 + {AuWbrCreate_MFS, "most-free-space"},
26134 + {AuWbrCreate_MFSV, "mfs:%d"},
26135 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26137 + /* top-down regardless the parent, and then mfs */
26138 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26139 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26141 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26142 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26143 + {AuWbrCreate_PMFS, "pmfs"},
26144 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26145 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26146 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26151 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26152 + struct au_opt_wbr_create *create)
26155 + unsigned long long ull;
26158 + if (!match_u64(arg, &ull))
26159 + create->mfsrr_watermark = ull;
26161 + pr_err("bad integer in %s\n", str);
26168 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26169 + struct au_opt_wbr_create *create)
26174 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26175 + create->mfs_second = n;
26177 + pr_err("bad integer in %s\n", str);
26184 +static int noinline_for_stack
26185 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26188 + substring_t args[MAX_OPT_ARGS];
26190 + err = match_token(str, au_wbr_create_policy, args);
26191 + create->wbr_create = err;
26193 + case AuWbrCreate_MFSRRV:
26194 + case AuWbrCreate_TDMFSV:
26195 + case AuWbrCreate_PMFSRRV:
26196 + e = au_wbr_mfs_wmark(&args[0], str, create);
26198 + e = au_wbr_mfs_sec(&args[1], str, create);
26202 + case AuWbrCreate_MFSRR:
26203 + case AuWbrCreate_TDMFS:
26204 + case AuWbrCreate_PMFSRR:
26205 + e = au_wbr_mfs_wmark(&args[0], str, create);
26206 + if (unlikely(e)) {
26211 + case AuWbrCreate_MFS:
26212 + case AuWbrCreate_PMFS:
26213 + create->mfs_second = AUFS_MFS_DEF_SEC;
26215 + case AuWbrCreate_MFSV:
26216 + case AuWbrCreate_PMFSV:
26217 + e = au_wbr_mfs_sec(&args[0], str, create);
26226 +const char *au_optstr_wbr_create(int wbr_create)
26228 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26231 +static match_table_t au_wbr_copyup_policy = {
26232 + {AuWbrCopyup_TDP, "tdp"},
26233 + {AuWbrCopyup_TDP, "top-down-parent"},
26234 + {AuWbrCopyup_BUP, "bup"},
26235 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26236 + {AuWbrCopyup_BU, "bu"},
26237 + {AuWbrCopyup_BU, "bottom-up"},
26241 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26243 + substring_t args[MAX_OPT_ARGS];
26245 + return match_token(str, au_wbr_copyup_policy, args);
26248 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26250 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26253 +/* ---------------------------------------------------------------------- */
26255 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26257 +static void dump_opts(struct au_opts *opts)
26259 +#ifdef CONFIG_AUFS_DEBUG
26260 + /* reduce stack space */
26262 + struct au_opt_add *add;
26263 + struct au_opt_del *del;
26264 + struct au_opt_mod *mod;
26265 + struct au_opt_xino *xino;
26266 + struct au_opt_xino_itrunc *xino_itrunc;
26267 + struct au_opt_wbr_create *create;
26269 + struct au_opt *opt;
26272 + while (opt->type != Opt_tail) {
26273 + switch (opt->type) {
26275 + u.add = &opt->add;
26276 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26277 + u.add->bindex, u.add->pathname, u.add->perm,
26278 + u.add->path.dentry);
26282 + u.del = &opt->del;
26283 + AuDbg("del {%s, %p}\n",
26284 + u.del->pathname, u.del->h_path.dentry);
26288 + u.mod = &opt->mod;
26289 + AuDbg("mod {%s, 0x%x, %p}\n",
26290 + u.mod->path, u.mod->perm, u.mod->h_root);
26293 + u.add = &opt->add;
26294 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26295 + u.add->bindex, u.add->pathname, u.add->perm,
26296 + u.add->path.dentry);
26298 + case Opt_prepend:
26299 + u.add = &opt->add;
26300 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26301 + u.add->bindex, u.add->pathname, u.add->perm,
26302 + u.add->path.dentry);
26305 + AuDbg("dirwh %d\n", opt->dirwh);
26307 + case Opt_rdcache:
26308 + AuDbg("rdcache %d\n", opt->rdcache);
26311 + AuDbg("rdblk %u\n", opt->rdblk);
26313 + case Opt_rdblk_def:
26314 + AuDbg("rdblk_def\n");
26317 + AuDbg("rdhash %u\n", opt->rdhash);
26319 + case Opt_rdhash_def:
26320 + AuDbg("rdhash_def\n");
26323 + u.xino = &opt->xino;
26324 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26326 + case Opt_trunc_xino:
26327 + AuLabel(trunc_xino);
26329 + case Opt_notrunc_xino:
26330 + AuLabel(notrunc_xino);
26332 + case Opt_trunc_xino_path:
26333 + case Opt_itrunc_xino:
26334 + u.xino_itrunc = &opt->xino_itrunc;
26335 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26340 + case Opt_trunc_xib:
26341 + AuLabel(trunc_xib);
26343 + case Opt_notrunc_xib:
26344 + AuLabel(notrunc_xib);
26352 + case Opt_dirperm1:
26353 + AuLabel(dirperm1);
26355 + case Opt_nodirperm1:
26356 + AuLabel(nodirperm1);
26361 + case Opt_noplink:
26362 + AuLabel(noplink);
26364 + case Opt_list_plink:
26365 + AuLabel(list_plink);
26368 + AuDbg("udba %d, %s\n",
26369 + opt->udba, au_optstr_udba(opt->udba));
26377 + case Opt_diropq_a:
26378 + AuLabel(diropq_a);
26380 + case Opt_diropq_w:
26381 + AuLabel(diropq_w);
26383 + case Opt_warn_perm:
26384 + AuLabel(warn_perm);
26386 + case Opt_nowarn_perm:
26387 + AuLabel(nowarn_perm);
26389 + case Opt_verbose:
26390 + AuLabel(verbose);
26392 + case Opt_noverbose:
26393 + AuLabel(noverbose);
26404 + case Opt_wbr_create:
26405 + u.create = &opt->wbr_create;
26406 + AuDbg("create %d, %s\n", u.create->wbr_create,
26407 + au_optstr_wbr_create(u.create->wbr_create));
26408 + switch (u.create->wbr_create) {
26409 + case AuWbrCreate_MFSV:
26410 + case AuWbrCreate_PMFSV:
26411 + AuDbg("%d sec\n", u.create->mfs_second);
26413 + case AuWbrCreate_MFSRR:
26414 + case AuWbrCreate_TDMFS:
26415 + AuDbg("%llu watermark\n",
26416 + u.create->mfsrr_watermark);
26418 + case AuWbrCreate_MFSRRV:
26419 + case AuWbrCreate_TDMFSV:
26420 + case AuWbrCreate_PMFSRRV:
26421 + AuDbg("%llu watermark, %d sec\n",
26422 + u.create->mfsrr_watermark,
26423 + u.create->mfs_second);
26427 + case Opt_wbr_copyup:
26428 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26429 + au_optstr_wbr_copyup(opt->wbr_copyup));
26431 + case Opt_fhsm_sec:
26432 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26437 + case Opt_nodirren:
26438 + AuLabel(nodirren);
26454 +void au_opts_free(struct au_opts *opts)
26456 + struct au_opt *opt;
26459 + while (opt->type != Opt_tail) {
26460 + switch (opt->type) {
26463 + case Opt_prepend:
26464 + path_put(&opt->add.path);
26468 + path_put(&opt->del.h_path);
26472 + dput(opt->mod.h_root);
26475 + fput(opt->xino.file);
26482 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26483 + aufs_bindex_t bindex)
26486 + struct au_opt_add *add = &opt->add;
26489 + add->bindex = bindex;
26490 + add->perm = AuBrPerm_RO;
26491 + add->pathname = opt_str;
26492 + p = strchr(opt_str, '=');
26496 + add->perm = br_perm_val(p);
26499 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26502 + add->perm = AuBrPerm_RO;
26503 + if (au_test_fs_rr(add->path.dentry->d_sb))
26504 + add->perm = AuBrPerm_RR;
26505 + else if (!bindex && !(sb_flags & SB_RDONLY))
26506 + add->perm = AuBrPerm_RW;
26508 + opt->type = Opt_add;
26511 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26518 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26522 + del->pathname = args[0].from;
26523 + AuDbg("del path %s\n", del->pathname);
26525 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26526 + if (unlikely(err))
26527 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26532 +#if 0 /* reserved for future use */
26533 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26534 + struct au_opt_del *del, substring_t args[])
26537 + struct dentry *root;
26540 + root = sb->s_root;
26541 + aufs_read_lock(root, AuLock_FLUSH);
26542 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26543 + pr_err("out of bounds, %d\n", bindex);
26548 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26549 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26552 + aufs_read_unlock(root, !AuLock_IR);
26557 +static int noinline_for_stack
26558 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26561 + struct path path;
26565 + mod->path = args[0].from;
26566 + p = strchr(mod->path, '=');
26567 + if (unlikely(!p)) {
26568 + pr_err("no permission %s\n", args[0].from);
26573 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26574 + if (unlikely(err)) {
26575 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26579 + mod->perm = br_perm_val(p);
26580 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26581 + mod->h_root = dget(path.dentry);
26588 +#if 0 /* reserved for future use */
26589 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26590 + struct au_opt_mod *mod, substring_t args[])
26593 + struct dentry *root;
26596 + root = sb->s_root;
26597 + aufs_read_lock(root, AuLock_FLUSH);
26598 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26599 + pr_err("out of bounds, %d\n", bindex);
26604 + mod->perm = br_perm_val(args[1].from);
26605 + AuDbg("mod path %s, perm 0x%x, %s\n",
26606 + mod->path, mod->perm, args[1].from);
26607 + mod->h_root = dget(au_h_dptr(root, bindex));
26610 + aufs_read_unlock(root, !AuLock_IR);
26615 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26616 + substring_t args[])
26619 + struct file *file;
26621 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26622 + err = PTR_ERR(file);
26623 + if (IS_ERR(file))
26627 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26629 + pr_err("%s must be outside\n", args[0].from);
26634 + xino->file = file;
26635 + xino->path = args[0].from;
26641 +static int noinline_for_stack
26642 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26643 + struct au_opt_xino_itrunc *xino_itrunc,
26644 + substring_t args[])
26647 + aufs_bindex_t bbot, bindex;
26648 + struct path path;
26649 + struct dentry *root;
26651 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26652 + if (unlikely(err)) {
26653 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26657 + xino_itrunc->bindex = -1;
26658 + root = sb->s_root;
26659 + aufs_read_lock(root, AuLock_FLUSH);
26660 + bbot = au_sbbot(sb);
26661 + for (bindex = 0; bindex <= bbot; bindex++) {
26662 + if (au_h_dptr(root, bindex) == path.dentry) {
26663 + xino_itrunc->bindex = bindex;
26667 + aufs_read_unlock(root, !AuLock_IR);
26670 + if (unlikely(xino_itrunc->bindex < 0)) {
26671 + pr_err("no such branch %s\n", args[0].from);
26679 +/* called without aufs lock */
26680 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26682 + int err, n, token;
26683 + aufs_bindex_t bindex;
26684 + unsigned char skipped;
26685 + struct dentry *root;
26686 + struct au_opt *opt, *opt_tail;
26688 + /* reduce the stack space */
26690 + struct au_opt_xino_itrunc *xino_itrunc;
26691 + struct au_opt_wbr_create *create;
26694 + substring_t args[MAX_OPT_ARGS];
26698 + a = kmalloc(sizeof(*a), GFP_NOFS);
26699 + if (unlikely(!a))
26702 + root = sb->s_root;
26706 + opt_tail = opt + opts->max_opt - 1;
26707 + opt->type = Opt_tail;
26708 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26711 + token = match_token(opt_str, options, a->args);
26715 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26717 + err = opt_add(opt, opt_str, opts->sb_flags,
26719 + if (unlikely(!err && ++opt > opt_tail)) {
26723 + opt->type = Opt_tail;
26728 + if (unlikely(match_int(&a->args[0], &n))) {
26729 + pr_err("bad integer in %s\n", opt_str);
26733 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26736 + opt->type = token;
26739 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26740 + /*dummy bindex*/1);
26742 + opt->type = token;
26744 + case Opt_prepend:
26745 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26748 + opt->type = token;
26751 + err = au_opts_parse_del(&opt->del, a->args);
26753 + opt->type = token;
26755 +#if 0 /* reserved for future use */
26757 + del->pathname = "(indexed)";
26758 + if (unlikely(match_int(&args[0], &n))) {
26759 + pr_err("bad integer in %s\n", opt_str);
26762 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26764 + opt->type = token;
26768 + err = au_opts_parse_mod(&opt->mod, a->args);
26770 + opt->type = token;
26772 +#ifdef IMOD /* reserved for future use */
26774 + u.mod->path = "(indexed)";
26775 + if (unlikely(match_int(&a->args[0], &n))) {
26776 + pr_err("bad integer in %s\n", opt_str);
26779 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26781 + opt->type = token;
26785 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26787 + opt->type = token;
26790 + case Opt_trunc_xino_path:
26791 + err = au_opts_parse_xino_itrunc_path
26792 + (sb, &opt->xino_itrunc, a->args);
26794 + opt->type = token;
26797 + case Opt_itrunc_xino:
26798 + u.xino_itrunc = &opt->xino_itrunc;
26799 + if (unlikely(match_int(&a->args[0], &n))) {
26800 + pr_err("bad integer in %s\n", opt_str);
26803 + u.xino_itrunc->bindex = n;
26804 + aufs_read_lock(root, AuLock_FLUSH);
26805 + if (n < 0 || au_sbbot(sb) < n) {
26806 + pr_err("out of bounds, %d\n", n);
26807 + aufs_read_unlock(root, !AuLock_IR);
26810 + aufs_read_unlock(root, !AuLock_IR);
26812 + opt->type = token;
26816 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26819 + opt->type = token;
26822 + case Opt_rdcache:
26823 + if (unlikely(match_int(&a->args[0], &n))) {
26824 + pr_err("bad integer in %s\n", opt_str);
26827 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26828 + pr_err("rdcache must be smaller than %d\n",
26829 + AUFS_RDCACHE_MAX);
26832 + opt->rdcache = n;
26834 + opt->type = token;
26837 + if (unlikely(match_int(&a->args[0], &n)
26839 + || n > KMALLOC_MAX_SIZE)) {
26840 + pr_err("bad integer in %s\n", opt_str);
26843 + if (unlikely(n && n < NAME_MAX)) {
26844 + pr_err("rdblk must be larger than %d\n",
26850 + opt->type = token;
26853 + if (unlikely(match_int(&a->args[0], &n)
26855 + || n * sizeof(struct hlist_head)
26856 + > KMALLOC_MAX_SIZE)) {
26857 + pr_err("bad integer in %s\n", opt_str);
26862 + opt->type = token;
26865 + case Opt_trunc_xino:
26866 + case Opt_notrunc_xino:
26868 + case Opt_trunc_xib:
26869 + case Opt_notrunc_xib:
26872 + case Opt_dirperm1:
26873 + case Opt_nodirperm1:
26875 + case Opt_noplink:
26876 + case Opt_list_plink:
26879 + case Opt_diropq_a:
26880 + case Opt_diropq_w:
26881 + case Opt_warn_perm:
26882 + case Opt_nowarn_perm:
26883 + case Opt_verbose:
26884 + case Opt_noverbose:
26888 + case Opt_rdblk_def:
26889 + case Opt_rdhash_def:
26891 + case Opt_nodirren:
26895 + opt->type = token;
26899 + opt->udba = udba_val(a->args[0].from);
26900 + if (opt->udba >= 0) {
26902 + opt->type = token;
26904 + pr_err("wrong value, %s\n", opt_str);
26907 + case Opt_wbr_create:
26908 + u.create = &opt->wbr_create;
26909 + u.create->wbr_create
26910 + = au_wbr_create_val(a->args[0].from, u.create);
26911 + if (u.create->wbr_create >= 0) {
26913 + opt->type = token;
26915 + pr_err("wrong value, %s\n", opt_str);
26917 + case Opt_wbr_copyup:
26918 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26919 + if (opt->wbr_copyup >= 0) {
26921 + opt->type = token;
26923 + pr_err("wrong value, %s\n", opt_str);
26926 + case Opt_fhsm_sec:
26927 + if (unlikely(match_int(&a->args[0], &n)
26929 + pr_err("bad integer in %s\n", opt_str);
26932 + if (sysaufs_brs) {
26933 + opt->fhsm_second = n;
26934 + opt->type = token;
26936 + pr_warn("ignored %s\n", opt_str);
26941 + pr_warn("ignored %s\n", opt_str);
26943 + case Opt_ignore_silent:
26948 + pr_err("unknown option %s\n", opt_str);
26952 + if (!err && !skipped) {
26953 + if (unlikely(++opt > opt_tail)) {
26956 + opt->type = Opt_tail;
26959 + opt->type = Opt_tail;
26965 + if (unlikely(err))
26966 + au_opts_free(opts);
26972 +static int au_opt_wbr_create(struct super_block *sb,
26973 + struct au_opt_wbr_create *create)
26976 + struct au_sbinfo *sbinfo;
26978 + SiMustWriteLock(sb);
26980 + err = 1; /* handled */
26981 + sbinfo = au_sbi(sb);
26982 + if (sbinfo->si_wbr_create_ops->fin) {
26983 + err = sbinfo->si_wbr_create_ops->fin(sb);
26988 + sbinfo->si_wbr_create = create->wbr_create;
26989 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26990 + switch (create->wbr_create) {
26991 + case AuWbrCreate_MFSRRV:
26992 + case AuWbrCreate_MFSRR:
26993 + case AuWbrCreate_TDMFS:
26994 + case AuWbrCreate_TDMFSV:
26995 + case AuWbrCreate_PMFSRR:
26996 + case AuWbrCreate_PMFSRRV:
26997 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26999 + case AuWbrCreate_MFS:
27000 + case AuWbrCreate_MFSV:
27001 + case AuWbrCreate_PMFS:
27002 + case AuWbrCreate_PMFSV:
27003 + sbinfo->si_wbr_mfs.mfs_expire
27004 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27008 + if (sbinfo->si_wbr_create_ops->init)
27009 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27016 + * plus: processed without an error
27017 + * zero: unprocessed
27019 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27020 + struct au_opts *opts)
27023 + struct au_sbinfo *sbinfo;
27025 + SiMustWriteLock(sb);
27027 + err = 1; /* handled */
27028 + sbinfo = au_sbi(sb);
27029 + switch (opt->type) {
27031 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27032 + sbinfo->si_mntflags |= opt->udba;
27033 + opts->given_udba |= opt->udba;
27037 + au_opt_set(sbinfo->si_mntflags, PLINK);
27039 + case Opt_noplink:
27040 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27041 + au_plink_put(sb, /*verbose*/1);
27042 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27044 + case Opt_list_plink:
27045 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27046 + au_plink_list(sb);
27050 + au_opt_set(sbinfo->si_mntflags, DIO);
27051 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27054 + au_opt_clr(sbinfo->si_mntflags, DIO);
27055 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27058 + case Opt_fhsm_sec:
27059 + au_fhsm_set(sbinfo, opt->fhsm_second);
27062 + case Opt_diropq_a:
27063 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27065 + case Opt_diropq_w:
27066 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27069 + case Opt_warn_perm:
27070 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27072 + case Opt_nowarn_perm:
27073 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27076 + case Opt_verbose:
27077 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27079 + case Opt_noverbose:
27080 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27084 + au_opt_set(sbinfo->si_mntflags, SUM);
27087 + au_opt_clr(sbinfo->si_mntflags, SUM);
27088 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27090 + au_opt_clr(sbinfo->si_mntflags, SUM);
27091 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27094 + case Opt_wbr_create:
27095 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27097 + case Opt_wbr_copyup:
27098 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27099 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27103 + sbinfo->si_dirwh = opt->dirwh;
27106 + case Opt_rdcache:
27107 + sbinfo->si_rdcache
27108 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27111 + sbinfo->si_rdblk = opt->rdblk;
27113 + case Opt_rdblk_def:
27114 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27117 + sbinfo->si_rdhash = opt->rdhash;
27119 + case Opt_rdhash_def:
27120 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27124 + au_opt_set(sbinfo->si_mntflags, SHWH);
27127 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27130 + case Opt_dirperm1:
27131 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27133 + case Opt_nodirperm1:
27134 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27137 + case Opt_trunc_xino:
27138 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27140 + case Opt_notrunc_xino:
27141 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27144 + case Opt_trunc_xino_path:
27145 + case Opt_itrunc_xino:
27146 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27152 + case Opt_trunc_xib:
27153 + au_fset_opts(opts->flags, TRUNC_XIB);
27155 + case Opt_notrunc_xib:
27156 + au_fclr_opts(opts->flags, TRUNC_XIB);
27161 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27162 + err = au_dr_opt_set(sb);
27167 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27169 + case Opt_nodirren:
27171 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27172 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27178 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27182 + sb->s_flags |= SB_POSIXACL;
27185 + sb->s_flags &= ~SB_POSIXACL;
27197 + * returns tri-state.
27198 + * plus: processed without an error
27199 + * zero: unprocessed
27202 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27203 + struct au_opts *opts)
27205 + int err, do_refresh;
27208 + switch (opt->type) {
27210 + opt->add.bindex = au_sbbot(sb) + 1;
27211 + if (opt->add.bindex < 0)
27212 + opt->add.bindex = 0;
27214 + case Opt_prepend:
27215 + opt->add.bindex = 0;
27216 + add: /* indented label */
27218 + err = au_br_add(sb, &opt->add,
27219 + au_ftest_opts(opts->flags, REMOUNT));
27222 + au_fset_opts(opts->flags, REFRESH);
27228 + err = au_br_del(sb, &opt->del,
27229 + au_ftest_opts(opts->flags, REMOUNT));
27232 + au_fset_opts(opts->flags, TRUNC_XIB);
27233 + au_fset_opts(opts->flags, REFRESH);
27239 + err = au_br_mod(sb, &opt->mod,
27240 + au_ftest_opts(opts->flags, REMOUNT),
27245 + au_fset_opts(opts->flags, REFRESH);
27252 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27253 + struct au_opt_xino **opt_xino,
27254 + struct au_opts *opts)
27259 + switch (opt->type) {
27261 + err = au_xino_set(sb, &opt->xino,
27262 + !!au_ftest_opts(opts->flags, REMOUNT));
27263 + if (unlikely(err))
27266 + *opt_xino = &opt->xino;
27271 + *opt_xino = (void *)-1;
27278 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27279 + unsigned int pending)
27282 + aufs_bindex_t bindex, bbot;
27283 + unsigned char do_plink, skip, do_free, can_no_dreval;
27284 + struct au_branch *br;
27285 + struct au_wbr *wbr;
27286 + struct dentry *root, *dentry;
27287 + struct inode *dir, *h_dir;
27288 + struct au_sbinfo *sbinfo;
27289 + struct au_hinode *hdir;
27291 + SiMustAnyLock(sb);
27293 + sbinfo = au_sbi(sb);
27294 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27296 + if (!(sb_flags & SB_RDONLY)) {
27297 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27298 + pr_warn("first branch should be rw\n");
27299 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27300 + pr_warn_once("shwh should be used with ro\n");
27303 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27304 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27305 + pr_warn_once("udba=*notify requires xino\n");
27307 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27308 + pr_warn_once("dirperm1 breaks the protection"
27309 + " by the permission bits on the lower branch\n");
27313 + root = sb->s_root;
27314 + dir = d_inode(root);
27315 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27316 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27318 + bbot = au_sbbot(sb);
27319 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27321 + h_dir = au_h_iptr(dir, bindex);
27322 + br = au_sbr(sb, bindex);
27324 + if ((br->br_perm & AuBrAttr_ICEX)
27325 + && !h_dir->i_op->listxattr)
27326 + br->br_perm &= ~AuBrAttr_ICEX;
27328 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27329 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27330 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27334 + wbr = br->br_wbr;
27336 + wbr_wh_read_lock(wbr);
27338 + if (!au_br_writable(br->br_perm)) {
27341 + || (!wbr->wbr_whbase
27342 + && !wbr->wbr_plink
27343 + && !wbr->wbr_orph));
27344 + } else if (!au_br_wh_linkable(br->br_perm)) {
27345 + /* skip = (!br->br_whbase && !br->br_orph); */
27346 + skip = (!wbr || !wbr->wbr_whbase);
27347 + if (skip && wbr) {
27349 + skip = !!wbr->wbr_plink;
27351 + skip = !wbr->wbr_plink;
27354 + /* skip = (br->br_whbase && br->br_ohph); */
27355 + skip = (wbr && wbr->wbr_whbase);
27358 + skip = !!wbr->wbr_plink;
27360 + skip = !wbr->wbr_plink;
27364 + wbr_wh_read_unlock(wbr);
27366 + if (can_no_dreval) {
27367 + dentry = br->br_path.dentry;
27368 + spin_lock(&dentry->d_lock);
27369 + if (dentry->d_flags &
27370 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27371 + can_no_dreval = 0;
27372 + spin_unlock(&dentry->d_lock);
27375 + if (au_br_fhsm(br->br_perm)) {
27377 + AuDebugOn(!br->br_fhsm);
27383 + hdir = au_hi(dir, bindex);
27384 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27386 + wbr_wh_write_lock(wbr);
27387 + err = au_wh_init(br, sb);
27389 + wbr_wh_write_unlock(wbr);
27390 + au_hn_inode_unlock(hdir);
27392 + if (!err && do_free) {
27394 + br->br_wbr = NULL;
27398 + if (can_no_dreval)
27399 + au_fset_si(sbinfo, NO_DREVAL);
27401 + au_fclr_si(sbinfo, NO_DREVAL);
27404 + au_fset_si(sbinfo, FHSM);
27405 + for (bindex = bbot; bindex >= 0; bindex--) {
27406 + br = au_sbr(sb, bindex);
27407 + if (au_br_fhsm(br->br_perm)) {
27408 + au_fhsm_set_bottom(sb, bindex);
27413 + au_fclr_si(sbinfo, FHSM);
27414 + au_fhsm_set_bottom(sb, -1);
27420 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27423 + unsigned int tmp;
27424 + aufs_bindex_t bindex, bbot;
27425 + struct au_opt *opt;
27426 + struct au_opt_xino *opt_xino, xino;
27427 + struct au_sbinfo *sbinfo;
27428 + struct au_branch *br;
27429 + struct inode *dir;
27431 + SiMustWriteLock(sb);
27436 + while (err >= 0 && opt->type != Opt_tail)
27437 + err = au_opt_simple(sb, opt++, opts);
27440 + else if (unlikely(err < 0))
27443 + /* disable xino and udba temporary */
27444 + sbinfo = au_sbi(sb);
27445 + tmp = sbinfo->si_mntflags;
27446 + au_opt_clr(sbinfo->si_mntflags, XINO);
27447 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27450 + while (err >= 0 && opt->type != Opt_tail)
27451 + err = au_opt_br(sb, opt++, opts);
27454 + else if (unlikely(err < 0))
27457 + bbot = au_sbbot(sb);
27458 + if (unlikely(bbot < 0)) {
27460 + pr_err("no branches\n");
27464 + if (au_opt_test(tmp, XINO))
27465 + au_opt_set(sbinfo->si_mntflags, XINO);
27467 + while (!err && opt->type != Opt_tail)
27468 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27469 + if (unlikely(err))
27472 + err = au_opts_verify(sb, sb->s_flags, tmp);
27473 + if (unlikely(err))
27476 + /* restore xino */
27477 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27478 + xino.file = au_xino_def(sb);
27479 + err = PTR_ERR(xino.file);
27480 + if (IS_ERR(xino.file))
27483 + err = au_xino_set(sb, &xino, /*remount*/0);
27485 + if (unlikely(err))
27489 + /* restore udba */
27490 + tmp &= AuOptMask_UDBA;
27491 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27492 + sbinfo->si_mntflags |= tmp;
27493 + bbot = au_sbbot(sb);
27494 + for (bindex = 0; bindex <= bbot; bindex++) {
27495 + br = au_sbr(sb, bindex);
27496 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27497 + if (unlikely(err))
27498 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27500 + /* go on even if err */
27502 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27503 + dir = d_inode(sb->s_root);
27504 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27511 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27514 + unsigned char no_dreval;
27515 + struct inode *dir;
27516 + struct au_opt_xino *opt_xino;
27517 + struct au_opt *opt;
27518 + struct au_sbinfo *sbinfo;
27520 + SiMustWriteLock(sb);
27522 + err = au_dr_opt_flush(sb);
27523 + if (unlikely(err))
27525 + au_fset_opts(opts->flags, DR_FLUSHED);
27527 + dir = d_inode(sb->s_root);
27528 + sbinfo = au_sbi(sb);
27531 + while (err >= 0 && opt->type != Opt_tail) {
27532 + err = au_opt_simple(sb, opt, opts);
27534 + err = au_opt_br(sb, opt, opts);
27536 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27542 + /* go on even err */
27544 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27545 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27546 + if (unlikely(rerr && !err))
27549 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27550 + au_fset_opts(opts->flags, REFRESH_IDOP);
27552 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27553 + rerr = au_xib_trunc(sb);
27554 + if (unlikely(rerr && !err))
27558 + /* will be handled by the caller */
27559 + if (!au_ftest_opts(opts->flags, REFRESH)
27560 + && (opts->given_udba
27561 + || au_opt_test(sbinfo->si_mntflags, XINO)
27562 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27564 + au_fset_opts(opts->flags, REFRESH);
27566 + AuDbg("status 0x%x\n", opts->flags);
27572 +/* ---------------------------------------------------------------------- */
27574 +unsigned int au_opt_udba(struct super_block *sb)
27576 + return au_mntflags(sb) & AuOptMask_UDBA;
27578 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27579 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27580 +++ linux/fs/aufs/opts.h 2018-08-12 23:43:05.460124736 +0200
27582 +/* SPDX-License-Identifier: GPL-2.0 */
27584 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27586 + * This program, aufs is free software; you can redistribute it and/or modify
27587 + * it under the terms of the GNU General Public License as published by
27588 + * the Free Software Foundation; either version 2 of the License, or
27589 + * (at your option) any later version.
27591 + * This program is distributed in the hope that it will be useful,
27592 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27593 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27594 + * GNU General Public License for more details.
27596 + * You should have received a copy of the GNU General Public License
27597 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27601 + * mount options/flags
27604 +#ifndef __AUFS_OPTS_H__
27605 +#define __AUFS_OPTS_H__
27609 +#include <linux/path.h>
27613 +/* ---------------------------------------------------------------------- */
27616 +#define AuOpt_XINO 1 /* external inode number bitmap
27617 + and translation table */
27618 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27619 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27620 +#define AuOpt_UDBA_REVAL (1 << 3)
27621 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27622 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27623 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27624 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27626 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27627 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27628 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27629 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27630 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27631 +#define AuOpt_DIO (1 << 14) /* direct io */
27632 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27634 +#ifndef CONFIG_AUFS_HNOTIFY
27635 +#undef AuOpt_UDBA_HNOTIFY
27636 +#define AuOpt_UDBA_HNOTIFY 0
27638 +#ifndef CONFIG_AUFS_DIRREN
27639 +#undef AuOpt_DIRREN
27640 +#define AuOpt_DIRREN 0
27642 +#ifndef CONFIG_AUFS_SHWH
27644 +#define AuOpt_SHWH 0
27647 +#define AuOpt_Def (AuOpt_XINO \
27648 + | AuOpt_UDBA_REVAL \
27650 + /* | AuOpt_DIRPERM1 */ \
27651 + | AuOpt_WARN_PERM)
27652 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27653 + | AuOpt_UDBA_REVAL \
27654 + | AuOpt_UDBA_HNOTIFY)
27656 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27657 +#define au_opt_set(flags, name) do { \
27658 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27659 + ((flags) |= AuOpt_##name); \
27661 +#define au_opt_set_udba(flags, name) do { \
27662 + (flags) &= ~AuOptMask_UDBA; \
27663 + ((flags) |= AuOpt_##name); \
27665 +#define au_opt_clr(flags, name) do { \
27666 + ((flags) &= ~AuOpt_##name); \
27669 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27671 +#ifdef CONFIG_PROC_FS
27674 + return mntflags & ~AuOpt_PLINK;
27678 +/* ---------------------------------------------------------------------- */
27680 +/* policies to select one among multiple writable branches */
27682 + AuWbrCreate_TDP, /* top down parent */
27683 + AuWbrCreate_RR, /* round robin */
27684 + AuWbrCreate_MFS, /* most free space */
27685 + AuWbrCreate_MFSV, /* mfs with seconds */
27686 + AuWbrCreate_MFSRR, /* mfs then rr */
27687 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27688 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27689 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27690 + AuWbrCreate_PMFS, /* parent and mfs */
27691 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27692 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27693 + AuWbrCreate_PMFSRRV, /* plus seconds */
27695 + AuWbrCreate_Def = AuWbrCreate_TDP
27699 + AuWbrCopyup_TDP, /* top down parent */
27700 + AuWbrCopyup_BUP, /* bottom up parent */
27701 + AuWbrCopyup_BU, /* bottom up */
27703 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27706 +/* ---------------------------------------------------------------------- */
27708 +struct au_opt_add {
27709 + aufs_bindex_t bindex;
27712 + struct path path;
27715 +struct au_opt_del {
27717 + struct path h_path;
27720 +struct au_opt_mod {
27723 + struct dentry *h_root;
27726 +struct au_opt_xino {
27728 + struct file *file;
27731 +struct au_opt_xino_itrunc {
27732 + aufs_bindex_t bindex;
27735 +struct au_opt_wbr_create {
27738 + unsigned long long mfsrr_watermark;
27744 + struct au_opt_xino xino;
27745 + struct au_opt_xino_itrunc xino_itrunc;
27746 + struct au_opt_add add;
27747 + struct au_opt_del del;
27748 + struct au_opt_mod mod;
27751 + unsigned int rdblk;
27752 + unsigned int rdhash;
27754 + struct au_opt_wbr_create wbr_create;
27756 + unsigned int fhsm_second;
27761 +#define AuOpts_REMOUNT 1
27762 +#define AuOpts_REFRESH (1 << 1)
27763 +#define AuOpts_TRUNC_XIB (1 << 2)
27764 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27765 +#define AuOpts_REFRESH_IDOP (1 << 4)
27766 +#define AuOpts_DR_FLUSHED (1 << 5)
27767 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27768 +#define au_fset_opts(flags, name) \
27769 + do { (flags) |= AuOpts_##name; } while (0)
27770 +#define au_fclr_opts(flags, name) \
27771 + do { (flags) &= ~AuOpts_##name; } while (0)
27773 +#ifndef CONFIG_AUFS_DIRREN
27774 +#undef AuOpts_DR_FLUSHED
27775 +#define AuOpts_DR_FLUSHED 0
27779 + struct au_opt *opt;
27782 + unsigned int given_udba;
27783 + unsigned int flags;
27784 + unsigned long sb_flags;
27787 +/* ---------------------------------------------------------------------- */
27790 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27791 +const char *au_optstr_udba(int udba);
27792 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27793 +const char *au_optstr_wbr_create(int wbr_create);
27795 +void au_opts_free(struct au_opts *opts);
27796 +struct super_block;
27797 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27798 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27799 + unsigned int pending);
27800 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27801 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27803 +unsigned int au_opt_udba(struct super_block *sb);
27805 +#endif /* __KERNEL__ */
27806 +#endif /* __AUFS_OPTS_H__ */
27807 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27808 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27809 +++ linux/fs/aufs/plink.c 2018-10-23 12:33:35.599375796 +0200
27811 +// SPDX-License-Identifier: GPL-2.0
27813 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27815 + * This program, aufs is free software; you can redistribute it and/or modify
27816 + * it under the terms of the GNU General Public License as published by
27817 + * the Free Software Foundation; either version 2 of the License, or
27818 + * (at your option) any later version.
27820 + * This program is distributed in the hope that it will be useful,
27821 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27822 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27823 + * GNU General Public License for more details.
27825 + * You should have received a copy of the GNU General Public License
27826 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27836 + * the pseudo-link maintenance mode.
27837 + * during a user process maintains the pseudo-links,
27838 + * prohibit adding a new plink and branch manipulation.
27842 + * For entry functions which will handle plink, and i_mutex is already held
27844 + * They cannot wait and should return an error at once.
27845 + * Callers has to check the error.
27847 + * For entry functions which will handle plink, but i_mutex is not held
27849 + * They can wait the plink maintenance mode to finish.
27851 + * They behave like F_SETLK and F_SETLKW.
27852 + * If the caller never handle plink, then both flags are unnecessary.
27855 +int au_plink_maint(struct super_block *sb, int flags)
27859 + struct task_struct *parent, *prev;
27860 + struct au_sbinfo *sbi;
27862 + SiMustAnyLock(sb);
27865 + if (!au_opt_test(au_mntflags(sb), PLINK))
27868 + sbi = au_sbi(sb);
27869 + pid = sbi->si_plink_maint_pid;
27870 + if (!pid || pid == current->pid)
27873 + /* todo: it highly depends upon /sbin/mount.aufs */
27875 + parent = current;
27879 + parent = rcu_dereference(parent->real_parent);
27880 + if (parent == prev)
27882 + ppid = task_pid_vnr(parent);
27883 + if (pid == ppid) {
27884 + rcu_read_unlock();
27889 + rcu_read_unlock();
27891 + if (au_ftest_lock(flags, NOPLMW)) {
27892 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27893 + /* AuDebugOn(!lockdep_depth(current)); */
27894 + while (sbi->si_plink_maint_pid) {
27895 + si_read_unlock(sb);
27896 + /* gave up wake_up_bit() */
27897 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27899 + if (au_ftest_lock(flags, FLUSH))
27900 + au_nwt_flush(&sbi->si_nowait);
27901 + si_noflush_read_lock(sb);
27903 + } else if (au_ftest_lock(flags, NOPLM)) {
27904 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27912 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27914 + spin_lock(&sbinfo->si_plink_maint_lock);
27915 + sbinfo->si_plink_maint_pid = 0;
27916 + spin_unlock(&sbinfo->si_plink_maint_lock);
27917 + wake_up_all(&sbinfo->si_plink_wq);
27920 +int au_plink_maint_enter(struct super_block *sb)
27923 + struct au_sbinfo *sbinfo;
27926 + sbinfo = au_sbi(sb);
27927 + /* make sure i am the only one in this fs */
27928 + si_write_lock(sb, AuLock_FLUSH);
27929 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27930 + spin_lock(&sbinfo->si_plink_maint_lock);
27931 + if (!sbinfo->si_plink_maint_pid)
27932 + sbinfo->si_plink_maint_pid = current->pid;
27935 + spin_unlock(&sbinfo->si_plink_maint_lock);
27937 + si_write_unlock(sb);
27942 +/* ---------------------------------------------------------------------- */
27944 +#ifdef CONFIG_AUFS_DEBUG
27945 +void au_plink_list(struct super_block *sb)
27948 + struct au_sbinfo *sbinfo;
27949 + struct hlist_bl_head *hbl;
27950 + struct hlist_bl_node *pos;
27951 + struct au_icntnr *icntnr;
27953 + SiMustAnyLock(sb);
27955 + sbinfo = au_sbi(sb);
27956 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27957 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27959 + for (i = 0; i < AuPlink_NHASH; i++) {
27960 + hbl = sbinfo->si_plink + i;
27961 + hlist_bl_lock(hbl);
27962 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27963 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27964 + hlist_bl_unlock(hbl);
27969 +/* is the inode pseudo-linked? */
27970 +int au_plink_test(struct inode *inode)
27973 + struct au_sbinfo *sbinfo;
27974 + struct hlist_bl_head *hbl;
27975 + struct hlist_bl_node *pos;
27976 + struct au_icntnr *icntnr;
27978 + sbinfo = au_sbi(inode->i_sb);
27979 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27980 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27981 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27984 + i = au_plink_hash(inode->i_ino);
27985 + hbl = sbinfo->si_plink + i;
27986 + hlist_bl_lock(hbl);
27987 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27988 + if (&icntnr->vfs_inode == inode) {
27992 + hlist_bl_unlock(hbl);
27996 +/* ---------------------------------------------------------------------- */
27999 + * generate a name for plink.
28000 + * the file will be stored under AUFS_WH_PLINKDIR.
28002 +/* 20 is max digits length of ulong 64 */
28003 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28005 +static int plink_name(char *name, int len, struct inode *inode,
28006 + aufs_bindex_t bindex)
28009 + struct inode *h_inode;
28011 + h_inode = au_h_iptr(inode, bindex);
28012 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28016 +struct au_do_plink_lkup_args {
28017 + struct dentry **errp;
28018 + struct qstr *tgtname;
28019 + struct dentry *h_parent;
28020 + struct au_branch *br;
28023 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28024 + struct dentry *h_parent,
28025 + struct au_branch *br)
28027 + struct dentry *h_dentry;
28028 + struct inode *h_inode;
28030 + h_inode = d_inode(h_parent);
28031 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28032 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28033 + inode_unlock_shared(h_inode);
28037 +static void au_call_do_plink_lkup(void *args)
28039 + struct au_do_plink_lkup_args *a = args;
28040 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28043 +/* lookup the plink-ed @inode under the branch at @bindex */
28044 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28046 + struct dentry *h_dentry, *h_parent;
28047 + struct au_branch *br;
28049 + char a[PLINK_NAME_LEN];
28050 + struct qstr tgtname = QSTR_INIT(a, 0);
28052 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28054 + br = au_sbr(inode->i_sb, bindex);
28055 + h_parent = br->br_wbr->wbr_plink;
28056 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28058 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28059 + struct au_do_plink_lkup_args args = {
28060 + .errp = &h_dentry,
28061 + .tgtname = &tgtname,
28062 + .h_parent = h_parent,
28066 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28067 + if (unlikely(wkq_err))
28068 + h_dentry = ERR_PTR(wkq_err);
28070 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28075 +/* create a pseudo-link */
28076 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28077 + struct dentry *h_dentry, struct au_branch *br)
28080 + struct path h_path = {
28081 + .mnt = au_br_mnt(br)
28083 + struct inode *h_dir, *delegated;
28085 + h_dir = d_inode(h_parent);
28086 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28088 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28089 + err = PTR_ERR(h_path.dentry);
28090 + if (IS_ERR(h_path.dentry))
28094 + /* wh.plink dir is not monitored */
28095 + /* todo: is it really safe? */
28096 + if (d_is_positive(h_path.dentry)
28097 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28098 + delegated = NULL;
28099 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28100 + if (unlikely(err == -EWOULDBLOCK)) {
28101 + pr_warn("cannot retry for NFSv4 delegation"
28102 + " for an internal unlink\n");
28105 + dput(h_path.dentry);
28106 + h_path.dentry = NULL;
28110 + if (!err && d_is_negative(h_path.dentry)) {
28111 + delegated = NULL;
28112 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28113 + if (unlikely(err == -EWOULDBLOCK)) {
28114 + pr_warn("cannot retry for NFSv4 delegation"
28115 + " for an internal link\n");
28119 + dput(h_path.dentry);
28122 + inode_unlock(h_dir);
28126 +struct do_whplink_args {
28128 + struct qstr *tgt;
28129 + struct dentry *h_parent;
28130 + struct dentry *h_dentry;
28131 + struct au_branch *br;
28134 +static void call_do_whplink(void *args)
28136 + struct do_whplink_args *a = args;
28137 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28140 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28141 + aufs_bindex_t bindex, struct au_branch *br)
28143 + int err, wkq_err;
28144 + struct au_wbr *wbr;
28145 + struct dentry *h_parent;
28146 + char a[PLINK_NAME_LEN];
28147 + struct qstr tgtname = QSTR_INIT(a, 0);
28149 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28150 + h_parent = wbr->wbr_plink;
28151 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28153 + /* always superio. */
28154 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28155 + struct do_whplink_args args = {
28158 + .h_parent = h_parent,
28159 + .h_dentry = h_dentry,
28162 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28163 + if (unlikely(wkq_err))
28166 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28172 + * create a new pseudo-link for @h_dentry on @bindex.
28173 + * the linked inode is held in aufs @inode.
28175 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28176 + struct dentry *h_dentry)
28178 + struct super_block *sb;
28179 + struct au_sbinfo *sbinfo;
28180 + struct hlist_bl_head *hbl;
28181 + struct hlist_bl_node *pos;
28182 + struct au_icntnr *icntnr;
28183 + int found, err, cnt, i;
28185 + sb = inode->i_sb;
28186 + sbinfo = au_sbi(sb);
28187 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28188 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28190 + found = au_plink_test(inode);
28194 + i = au_plink_hash(inode->i_ino);
28195 + hbl = sbinfo->si_plink + i;
28198 + hlist_bl_lock(hbl);
28199 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28200 + if (&icntnr->vfs_inode == inode) {
28206 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28207 + hlist_bl_add_head(&icntnr->plink, hbl);
28209 + hlist_bl_unlock(hbl);
28211 + cnt = au_hbl_count(hbl);
28212 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28213 + if (cnt > AUFS_PLINK_WARN)
28214 + AuWarn1(msg ", %d\n", cnt);
28216 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28217 + if (unlikely(err)) {
28218 + pr_warn("err %d, damaged pseudo link.\n", err);
28219 + au_hbl_del(&icntnr->plink, hbl);
28220 + iput(&icntnr->vfs_inode);
28223 + iput(&icntnr->vfs_inode);
28226 +/* free all plinks */
28227 +void au_plink_put(struct super_block *sb, int verbose)
28230 + struct au_sbinfo *sbinfo;
28231 + struct hlist_bl_head *hbl;
28232 + struct hlist_bl_node *pos, *tmp;
28233 + struct au_icntnr *icntnr;
28235 + SiMustWriteLock(sb);
28237 + sbinfo = au_sbi(sb);
28238 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28239 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28241 + /* no spin_lock since sbinfo is write-locked */
28243 + for (i = 0; i < AuPlink_NHASH; i++) {
28244 + hbl = sbinfo->si_plink + i;
28245 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28246 + pr_warn("pseudo-link is not flushed");
28249 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28250 + iput(&icntnr->vfs_inode);
28251 + INIT_HLIST_BL_HEAD(hbl);
28255 +void au_plink_clean(struct super_block *sb, int verbose)
28257 + struct dentry *root;
28259 + root = sb->s_root;
28260 + aufs_write_lock(root);
28261 + if (au_opt_test(au_mntflags(sb), PLINK))
28262 + au_plink_put(sb, verbose);
28263 + aufs_write_unlock(root);
28266 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28269 + aufs_bindex_t btop, bbot, bindex;
28272 + btop = au_ibtop(inode);
28273 + bbot = au_ibbot(inode);
28275 + for (bindex = btop; bindex <= bbot; bindex++) {
28276 + if (!au_h_iptr(inode, bindex)
28277 + || au_ii_br_id(inode, bindex) != br_id)
28279 + au_set_h_iptr(inode, bindex, NULL, 0);
28284 + for (bindex = btop; bindex <= bbot; bindex++)
28285 + if (au_h_iptr(inode, bindex)) {
28295 +/* free the plinks on a branch specified by @br_id */
28296 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28298 + struct au_sbinfo *sbinfo;
28299 + struct hlist_bl_head *hbl;
28300 + struct hlist_bl_node *pos, *tmp;
28301 + struct au_icntnr *icntnr;
28302 + struct inode *inode;
28305 + SiMustWriteLock(sb);
28307 + sbinfo = au_sbi(sb);
28308 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28309 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28311 + /* no bit_lock since sbinfo is write-locked */
28312 + for (i = 0; i < AuPlink_NHASH; i++) {
28313 + hbl = sbinfo->si_plink + i;
28314 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28315 + inode = au_igrab(&icntnr->vfs_inode);
28316 + ii_write_lock_child(inode);
28317 + do_put = au_plink_do_half_refresh(inode, br_id);
28319 + hlist_bl_del(&icntnr->plink);
28322 + ii_write_unlock(inode);
28327 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28328 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28329 +++ linux/fs/aufs/poll.c 2018-08-12 23:43:05.460124736 +0200
28331 +// SPDX-License-Identifier: GPL-2.0
28333 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28335 + * This program, aufs is free software; you can redistribute it and/or modify
28336 + * it under the terms of the GNU General Public License as published by
28337 + * the Free Software Foundation; either version 2 of the License, or
28338 + * (at your option) any later version.
28340 + * This program is distributed in the hope that it will be useful,
28341 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28342 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28343 + * GNU General Public License for more details.
28345 + * You should have received a copy of the GNU General Public License
28346 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28351 + * There is only one filesystem which implements ->poll operation, currently.
28356 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28359 + struct file *h_file;
28360 + struct super_block *sb;
28362 + /* We should pretend an error happened. */
28363 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28364 + sb = file->f_path.dentry->d_sb;
28365 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28367 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28368 + if (IS_ERR(h_file)) {
28369 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28373 + mask = vfs_poll(h_file, pt);
28374 + fput(h_file); /* instead of au_read_post() */
28377 + si_read_unlock(sb);
28378 + if (mask & EPOLLERR)
28379 + AuDbg("mask 0x%x\n", mask);
28382 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28383 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28384 +++ linux/fs/aufs/posix_acl.c 2018-08-12 23:43:05.460124736 +0200
28386 +// SPDX-License-Identifier: GPL-2.0
28388 + * Copyright (C) 2014-2018 Junjiro R. Okajima
28390 + * This program, aufs is free software; you can redistribute it and/or modify
28391 + * it under the terms of the GNU General Public License as published by
28392 + * the Free Software Foundation; either version 2 of the License, or
28393 + * (at your option) any later version.
28395 + * This program is distributed in the hope that it will be useful,
28396 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28397 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28398 + * GNU General Public License for more details.
28400 + * You should have received a copy of the GNU General Public License
28401 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28405 + * posix acl operations
28408 +#include <linux/fs.h>
28411 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28413 + struct posix_acl *acl;
28415 + aufs_bindex_t bindex;
28416 + struct inode *h_inode;
28417 + struct super_block *sb;
28420 + sb = inode->i_sb;
28421 + si_read_lock(sb, AuLock_FLUSH);
28422 + ii_read_lock_child(inode);
28423 + if (!(sb->s_flags & SB_POSIXACL))
28426 + bindex = au_ibtop(inode);
28427 + h_inode = au_h_iptr(inode, bindex);
28428 + if (unlikely(!h_inode
28429 + || ((h_inode->i_mode & S_IFMT)
28430 + != (inode->i_mode & S_IFMT)))) {
28431 + err = au_busy_or_stale();
28432 + acl = ERR_PTR(err);
28436 + /* always topmost only */
28437 + acl = get_acl(h_inode, type);
28438 + if (!IS_ERR_OR_NULL(acl))
28439 + set_cached_acl(inode, type, acl);
28442 + ii_read_unlock(inode);
28443 + si_read_unlock(sb);
28445 + AuTraceErrPtr(acl);
28449 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28453 + struct dentry *dentry;
28454 + struct au_sxattr arg = {
28455 + .type = AU_ACL_SET,
28462 + IMustLock(inode);
28464 + if (inode->i_ino == AUFS_ROOT_INO)
28465 + dentry = dget(inode->i_sb->s_root);
28467 + dentry = d_find_alias(inode);
28469 + dentry = d_find_any_alias(inode);
28471 + pr_warn("cannot handle this inode, "
28472 + "please report to aufs-users ML\n");
28478 + ssz = au_sxattr(dentry, inode, &arg);
28483 + set_cached_acl(inode, type, acl);
28489 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28490 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28491 +++ linux/fs/aufs/procfs.c 2018-08-12 23:43:05.460124736 +0200
28493 +// SPDX-License-Identifier: GPL-2.0
28495 + * Copyright (C) 2010-2018 Junjiro R. Okajima
28497 + * This program, aufs is free software; you can redistribute it and/or modify
28498 + * it under the terms of the GNU General Public License as published by
28499 + * the Free Software Foundation; either version 2 of the License, or
28500 + * (at your option) any later version.
28502 + * This program is distributed in the hope that it will be useful,
28503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28505 + * GNU General Public License for more details.
28507 + * You should have received a copy of the GNU General Public License
28508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28512 + * procfs interfaces
28515 +#include <linux/proc_fs.h>
28518 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28520 + struct au_sbinfo *sbinfo;
28522 + sbinfo = file->private_data;
28524 + au_plink_maint_leave(sbinfo);
28525 + kobject_put(&sbinfo->si_kobj);
28531 +static void au_procfs_plm_write_clean(struct file *file)
28533 + struct au_sbinfo *sbinfo;
28535 + sbinfo = file->private_data;
28537 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28540 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28543 + struct super_block *sb;
28544 + struct au_sbinfo *sbinfo;
28545 + struct hlist_bl_node *pos;
28548 + if (unlikely(file->private_data))
28552 + /* don't use au_sbilist_lock() here */
28553 + hlist_bl_lock(&au_sbilist);
28554 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28555 + if (id == sysaufs_si_id(sbinfo)) {
28556 + kobject_get(&sbinfo->si_kobj);
28557 + sb = sbinfo->si_sb;
28560 + hlist_bl_unlock(&au_sbilist);
28563 + if (unlikely(!sb))
28566 + err = au_plink_maint_enter(sb);
28568 + /* keep kobject_get() */
28569 + file->private_data = sbinfo;
28571 + kobject_put(&sbinfo->si_kobj);
28577 + * Accept a valid "si=xxxx" only.
28578 + * Once it is accepted successfully, accept "clean" too.
28580 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28581 + size_t count, loff_t *ppos)
28584 + unsigned long id;
28585 + /* last newline is allowed */
28586 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28589 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28593 + if (unlikely(count > sizeof(buf)))
28596 + err = copy_from_user(buf, ubuf, count);
28597 + if (unlikely(err)) {
28604 + if (!strcmp("clean", buf)) {
28605 + au_procfs_plm_write_clean(file);
28606 + goto out_success;
28607 + } else if (unlikely(strncmp("si=", buf, 3)))
28610 + err = kstrtoul(buf + 3, 16, &id);
28611 + if (unlikely(err))
28614 + err = au_procfs_plm_write_si(file, id);
28615 + if (unlikely(err))
28619 + err = count; /* success */
28624 +static const struct file_operations au_procfs_plm_fop = {
28625 + .write = au_procfs_plm_write,
28626 + .release = au_procfs_plm_release,
28627 + .owner = THIS_MODULE
28630 +/* ---------------------------------------------------------------------- */
28632 +static struct proc_dir_entry *au_procfs_dir;
28634 +void au_procfs_fin(void)
28636 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28637 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28640 +int __init au_procfs_init(void)
28643 + struct proc_dir_entry *entry;
28646 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28647 + if (unlikely(!au_procfs_dir))
28650 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28651 + au_procfs_dir, &au_procfs_plm_fop);
28652 + if (unlikely(!entry))
28656 + goto out; /* success */
28660 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28664 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28665 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28666 +++ linux/fs/aufs/rdu.c 2018-08-12 23:43:05.463458173 +0200
28668 +// SPDX-License-Identifier: GPL-2.0
28670 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28672 + * This program, aufs is free software; you can redistribute it and/or modify
28673 + * it under the terms of the GNU General Public License as published by
28674 + * the Free Software Foundation; either version 2 of the License, or
28675 + * (at your option) any later version.
28677 + * This program is distributed in the hope that it will be useful,
28678 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28679 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28680 + * GNU General Public License for more details.
28682 + * You should have received a copy of the GNU General Public License
28683 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28687 + * readdir in userspace.
28690 +#include <linux/compat.h>
28691 +#include <linux/fs_stack.h>
28692 +#include <linux/security.h>
28695 +/* bits for struct aufs_rdu.flags */
28696 +#define AuRdu_CALLED 1
28697 +#define AuRdu_CONT (1 << 1)
28698 +#define AuRdu_FULL (1 << 2)
28699 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28700 +#define au_fset_rdu(flags, name) \
28701 + do { (flags) |= AuRdu_##name; } while (0)
28702 +#define au_fclr_rdu(flags, name) \
28703 + do { (flags) &= ~AuRdu_##name; } while (0)
28705 +struct au_rdu_arg {
28706 + struct dir_context ctx;
28707 + struct aufs_rdu *rdu;
28708 + union au_rdu_ent_ul ent;
28709 + unsigned long end;
28711 + struct super_block *sb;
28715 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28716 + loff_t offset, u64 h_ino, unsigned int d_type)
28719 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28720 + struct aufs_rdu *rdu = arg->rdu;
28721 + struct au_rdu_ent ent;
28725 + au_fset_rdu(rdu->cookie.flags, CALLED);
28726 + len = au_rdu_len(nlen);
28727 + if (arg->ent.ul + len < arg->end) {
28729 + ent.bindex = rdu->cookie.bindex;
28730 + ent.type = d_type;
28732 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28733 + ent.type = DT_UNKNOWN;
28735 + /* unnecessary to support mmap_sem since this is a dir */
28737 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28739 + if (copy_to_user(arg->ent.e->name, name, nlen))
28741 + /* the terminating NULL */
28742 + if (__put_user(0, arg->ent.e->name + nlen))
28745 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28746 + arg->ent.ul += len;
28750 + au_fset_rdu(rdu->cookie.flags, FULL);
28752 + rdu->tail = arg->ent;
28756 + /* AuTraceErr(err); */
28760 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28764 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28766 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28767 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28769 + if (unlikely(offset != cookie->h_pos))
28775 + au_fclr_rdu(cookie->flags, CALLED);
28777 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28781 + && au_ftest_rdu(cookie->flags, CALLED)
28782 + && !au_ftest_rdu(cookie->flags, FULL));
28783 + cookie->h_pos = h_file->f_pos;
28790 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28793 + aufs_bindex_t bbot;
28794 + struct au_rdu_arg arg = {
28796 + .actor = au_rdu_fill
28799 + struct dentry *dentry;
28800 + struct inode *inode;
28801 + struct file *h_file;
28802 + struct au_rdu_cookie *cookie = &rdu->cookie;
28804 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28805 + if (unlikely(err)) {
28811 + rdu->tail = rdu->ent;
28814 + arg.ent = rdu->ent;
28815 + arg.end = arg.ent.ul;
28816 + arg.end += rdu->sz;
28819 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28822 + err = security_file_permission(file, MAY_READ);
28824 + if (unlikely(err))
28827 + dentry = file->f_path.dentry;
28828 + inode = d_inode(dentry);
28829 + inode_lock_shared(inode);
28831 + arg.sb = inode->i_sb;
28832 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28833 + if (unlikely(err))
28835 + err = au_alive_dir(dentry);
28836 + if (unlikely(err))
28838 + /* todo: reval? */
28839 + fi_read_lock(file);
28842 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28843 + && cookie->generation != au_figen(file)))
28848 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28850 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28852 + bbot = au_fbtop(file);
28853 + if (cookie->bindex < bbot)
28854 + cookie->bindex = bbot;
28855 + bbot = au_fbbot_dir(file);
28856 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28857 + for (; !err && cookie->bindex <= bbot;
28858 + cookie->bindex++, cookie->h_pos = 0) {
28859 + h_file = au_hf_dir(file, cookie->bindex);
28863 + au_fclr_rdu(cookie->flags, FULL);
28864 + err = au_rdu_do(h_file, &arg);
28866 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28869 + AuDbg("rent %llu\n", rdu->rent);
28871 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28872 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28873 + au_fset_rdu(cookie->flags, CONT);
28874 + cookie->generation = au_figen(file);
28877 + ii_read_lock_child(inode);
28878 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28879 + ii_read_unlock(inode);
28882 + fi_read_unlock(file);
28884 + si_read_unlock(arg.sb);
28886 + inode_unlock_shared(inode);
28892 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28896 + unsigned long long nent;
28897 + union au_rdu_ent_ul *u;
28898 + struct au_rdu_ent ent;
28899 + struct super_block *sb;
28902 + nent = rdu->nent;
28904 + sb = file->f_path.dentry->d_sb;
28905 + si_read_lock(sb, AuLock_FLUSH);
28906 + while (nent-- > 0) {
28907 + /* unnecessary to support mmap_sem since this is a dir */
28908 + err = copy_from_user(&ent, u->e, sizeof(ent));
28910 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28911 + if (unlikely(err)) {
28917 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28919 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28921 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28923 + if (unlikely(err)) {
28928 + err = __put_user(ino, &u->e->ino);
28929 + if (unlikely(err)) {
28934 + u->ul += au_rdu_len(ent.nlen);
28936 + si_read_unlock(sb);
28941 +/* ---------------------------------------------------------------------- */
28943 +static int au_rdu_verify(struct aufs_rdu *rdu)
28945 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28946 + "%llu, b%d, 0x%x, g%u}\n",
28947 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28949 + rdu->rent, rdu->shwh, rdu->full,
28950 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28951 + rdu->cookie.generation);
28953 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28957 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28961 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28964 + struct aufs_rdu rdu;
28965 + void __user *p = (void __user *)arg;
28967 + err = copy_from_user(&rdu, p, sizeof(rdu));
28968 + if (unlikely(err)) {
28973 + err = au_rdu_verify(&rdu);
28974 + if (unlikely(err))
28978 + case AUFS_CTL_RDU:
28979 + err = au_rdu(file, &rdu);
28980 + if (unlikely(err))
28983 + e = copy_to_user(p, &rdu, sizeof(rdu));
28984 + if (unlikely(e)) {
28989 + case AUFS_CTL_RDU_INO:
28990 + err = au_rdu_ino(file, &rdu);
28994 + /* err = -ENOTTY; */
29003 +#ifdef CONFIG_COMPAT
29004 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29007 + struct aufs_rdu rdu;
29008 + void __user *p = compat_ptr(arg);
29010 + /* todo: get_user()? */
29011 + err = copy_from_user(&rdu, p, sizeof(rdu));
29012 + if (unlikely(err)) {
29017 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29018 + err = au_rdu_verify(&rdu);
29019 + if (unlikely(err))
29023 + case AUFS_CTL_RDU:
29024 + err = au_rdu(file, &rdu);
29025 + if (unlikely(err))
29028 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29029 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29030 + e = copy_to_user(p, &rdu, sizeof(rdu));
29031 + if (unlikely(e)) {
29036 + case AUFS_CTL_RDU_INO:
29037 + err = au_rdu_ino(file, &rdu);
29041 + /* err = -ENOTTY; */
29050 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29051 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29052 +++ linux/fs/aufs/rwsem.h 2018-10-23 12:33:35.599375796 +0200
29054 +/* SPDX-License-Identifier: GPL-2.0 */
29056 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29058 + * This program, aufs is free software; you can redistribute it and/or modify
29059 + * it under the terms of the GNU General Public License as published by
29060 + * the Free Software Foundation; either version 2 of the License, or
29061 + * (at your option) any later version.
29063 + * This program is distributed in the hope that it will be useful,
29064 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29065 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29066 + * GNU General Public License for more details.
29068 + * You should have received a copy of the GNU General Public License
29069 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29073 + * simple read-write semaphore wrappers
29076 +#ifndef __AUFS_RWSEM_H__
29077 +#define __AUFS_RWSEM_H__
29081 +#include "debug.h"
29083 +/* in the future, the name 'au_rwsem' will be totally gone */
29084 +#define au_rwsem rw_semaphore
29086 +/* to debug easier, do not make them inlined functions */
29087 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29088 +/* rwsem_is_locked() is unusable */
29089 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29091 + && !lockdep_is_held_type(rw, 1))
29092 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29094 + && !lockdep_is_held_type(rw, 0))
29095 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29097 + && !lockdep_is_held(rw))
29098 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29100 + && lockdep_is_held(rw))
29102 +#define au_rw_init(rw) init_rwsem(rw)
29104 +#define au_rw_init_wlock(rw) do { \
29105 + au_rw_init(rw); \
29106 + down_write(rw); \
29109 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29110 + au_rw_init(rw); \
29111 + down_write_nested(rw, lsc); \
29114 +#define au_rw_read_lock(rw) down_read(rw)
29115 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29116 +#define au_rw_read_unlock(rw) up_read(rw)
29117 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29118 +#define au_rw_write_lock(rw) down_write(rw)
29119 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29120 +#define au_rw_write_unlock(rw) up_write(rw)
29121 +/* why is not _nested version defined? */
29122 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29123 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29125 +#endif /* __KERNEL__ */
29126 +#endif /* __AUFS_RWSEM_H__ */
29127 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29128 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29129 +++ linux/fs/aufs/sbinfo.c 2018-10-23 12:33:35.599375796 +0200
29131 +// SPDX-License-Identifier: GPL-2.0
29133 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29135 + * This program, aufs is free software; you can redistribute it and/or modify
29136 + * it under the terms of the GNU General Public License as published by
29137 + * the Free Software Foundation; either version 2 of the License, or
29138 + * (at your option) any later version.
29140 + * This program is distributed in the hope that it will be useful,
29141 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29143 + * GNU General Public License for more details.
29145 + * You should have received a copy of the GNU General Public License
29146 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29150 + * superblock private data
29156 + * they are necessary regardless sysfs is disabled.
29158 +void au_si_free(struct kobject *kobj)
29161 + struct au_sbinfo *sbinfo;
29162 + char *locked __maybe_unused; /* debug only */
29164 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29165 + for (i = 0; i < AuPlink_NHASH; i++)
29166 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29167 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29169 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29170 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29171 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29172 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29174 + dbgaufs_si_fin(sbinfo);
29175 + au_rw_write_lock(&sbinfo->si_rwsem);
29176 + au_br_free(sbinfo);
29177 + au_rw_write_unlock(&sbinfo->si_rwsem);
29179 + kfree(sbinfo->si_branch);
29180 + mutex_destroy(&sbinfo->si_xib_mtx);
29181 + AuRwDestroy(&sbinfo->si_rwsem);
29183 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29184 + /* si_nfiles is waited too */
29188 +int au_si_alloc(struct super_block *sb)
29191 + struct au_sbinfo *sbinfo;
29194 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29195 + if (unlikely(!sbinfo))
29198 + /* will be reallocated separately */
29199 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29200 + if (unlikely(!sbinfo->si_branch))
29203 + err = sysaufs_si_init(sbinfo);
29205 + dbgaufs_si_null(sbinfo);
29206 + err = dbgaufs_si_init(sbinfo);
29207 + if (unlikely(err))
29208 + kobject_put(&sbinfo->si_kobj);
29210 + if (unlikely(err))
29213 + au_nwt_init(&sbinfo->si_nowait);
29214 + au_rw_init_wlock(&sbinfo->si_rwsem);
29216 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29217 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29219 + sbinfo->si_bbot = -1;
29220 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29222 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29223 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29224 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29225 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29227 + au_fhsm_init(sbinfo);
29229 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29231 + sbinfo->si_xino_jiffy = jiffies;
29232 + sbinfo->si_xino_expire
29233 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29234 + mutex_init(&sbinfo->si_xib_mtx);
29235 + /* leave si_xib_last_pindex and si_xib_next_bit */
29237 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29239 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29240 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29241 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29242 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29244 + for (i = 0; i < AuPlink_NHASH; i++)
29245 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29246 + init_waitqueue_head(&sbinfo->si_plink_wq);
29247 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29249 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29251 + /* with getattr by default */
29252 + sbinfo->si_iop_array = aufs_iop;
29254 + /* leave other members for sysaufs and si_mnt. */
29255 + sbinfo->si_sb = sb;
29256 + sb->s_fs_info = sbinfo;
29258 + return 0; /* success */
29261 + kfree(sbinfo->si_branch);
29268 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29271 + struct au_branch **brp;
29273 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29276 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29277 + if (unlikely(!sz))
29278 + sz = sizeof(*brp);
29279 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29282 + sbinfo->si_branch = brp;
29289 +/* ---------------------------------------------------------------------- */
29291 +unsigned int au_sigen_inc(struct super_block *sb)
29293 + unsigned int gen;
29294 + struct inode *inode;
29296 + SiMustWriteLock(sb);
29298 + gen = ++au_sbi(sb)->si_generation;
29299 + au_update_digen(sb->s_root);
29300 + inode = d_inode(sb->s_root);
29301 + au_update_iigen(inode, /*half*/0);
29302 + inode_inc_iversion(inode);
29306 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29308 + aufs_bindex_t br_id;
29310 + struct au_sbinfo *sbinfo;
29312 + SiMustWriteLock(sb);
29314 + sbinfo = au_sbi(sb);
29315 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29316 + br_id = ++sbinfo->si_last_br_id;
29317 + AuDebugOn(br_id < 0);
29318 + if (br_id && au_br_index(sb, br_id) < 0)
29325 +/* ---------------------------------------------------------------------- */
29327 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29328 +int si_read_lock(struct super_block *sb, int flags)
29333 + if (au_ftest_lock(flags, FLUSH))
29334 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29336 + si_noflush_read_lock(sb);
29337 + err = au_plink_maint(sb, flags);
29338 + if (unlikely(err))
29339 + si_read_unlock(sb);
29344 +int si_write_lock(struct super_block *sb, int flags)
29348 + if (au_ftest_lock(flags, FLUSH))
29349 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29351 + si_noflush_write_lock(sb);
29352 + err = au_plink_maint(sb, flags);
29353 + if (unlikely(err))
29354 + si_write_unlock(sb);
29359 +/* dentry and super_block lock. call at entry point */
29360 +int aufs_read_lock(struct dentry *dentry, int flags)
29363 + struct super_block *sb;
29365 + sb = dentry->d_sb;
29366 + err = si_read_lock(sb, flags);
29367 + if (unlikely(err))
29370 + if (au_ftest_lock(flags, DW))
29371 + di_write_lock_child(dentry);
29373 + di_read_lock_child(dentry, flags);
29375 + if (au_ftest_lock(flags, GEN)) {
29376 + err = au_digen_test(dentry, au_sigen(sb));
29377 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29378 + AuDebugOn(!err && au_dbrange_test(dentry));
29380 + err = au_dbrange_test(dentry);
29381 + if (unlikely(err))
29382 + aufs_read_unlock(dentry, flags);
29389 +void aufs_read_unlock(struct dentry *dentry, int flags)
29391 + if (au_ftest_lock(flags, DW))
29392 + di_write_unlock(dentry);
29394 + di_read_unlock(dentry, flags);
29395 + si_read_unlock(dentry->d_sb);
29398 +void aufs_write_lock(struct dentry *dentry)
29400 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29401 + di_write_lock_child(dentry);
29404 +void aufs_write_unlock(struct dentry *dentry)
29406 + di_write_unlock(dentry);
29407 + si_write_unlock(dentry->d_sb);
29410 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29413 + unsigned int sigen;
29414 + struct super_block *sb;
29417 + err = si_read_lock(sb, flags);
29418 + if (unlikely(err))
29421 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29423 + if (au_ftest_lock(flags, GEN)) {
29424 + sigen = au_sigen(sb);
29425 + err = au_digen_test(d1, sigen);
29426 + AuDebugOn(!err && au_dbrange_test(d1));
29428 + err = au_digen_test(d2, sigen);
29429 + AuDebugOn(!err && au_dbrange_test(d2));
29431 + if (unlikely(err))
29432 + aufs_read_and_write_unlock2(d1, d2);
29439 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29441 + di_write_unlock2(d1, d2);
29442 + si_read_unlock(d1->d_sb);
29444 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29445 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29446 +++ linux/fs/aufs/super.c 2018-10-23 12:33:35.599375796 +0200
29448 +// SPDX-License-Identifier: GPL-2.0
29450 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29452 + * This program, aufs is free software; you can redistribute it and/or modify
29453 + * it under the terms of the GNU General Public License as published by
29454 + * the Free Software Foundation; either version 2 of the License, or
29455 + * (at your option) any later version.
29457 + * This program is distributed in the hope that it will be useful,
29458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29460 + * GNU General Public License for more details.
29462 + * You should have received a copy of the GNU General Public License
29463 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29467 + * mount and super_block operations
29470 +#include <linux/mm.h>
29471 +#include <linux/seq_file.h>
29472 +#include <linux/statfs.h>
29473 +#include <linux/vmalloc.h>
29477 + * super_operations
29479 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29481 + struct au_icntnr *c;
29483 + c = au_cache_alloc_icntnr();
29485 + au_icntnr_init(c);
29486 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29487 + c->iinfo.ii_hinode = NULL;
29488 + return &c->vfs_inode;
29493 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29495 + struct inode *inode = container_of(head, struct inode, i_rcu);
29497 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29500 +static void aufs_destroy_inode(struct inode *inode)
29502 + if (!au_is_bad_inode(inode))
29503 + au_iinfo_fin(inode);
29504 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29507 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29509 + struct inode *inode;
29512 + inode = iget_locked(sb, ino);
29513 + if (unlikely(!inode)) {
29514 + inode = ERR_PTR(-ENOMEM);
29517 + if (!(inode->i_state & I_NEW))
29520 + err = au_xigen_new(inode);
29522 + err = au_iinfo_init(inode);
29524 + inode_inc_iversion(inode);
29526 + iget_failed(inode);
29527 + inode = ERR_PTR(err);
29531 + /* never return NULL */
29532 + AuDebugOn(!inode);
29533 + AuTraceErrPtr(inode);
29537 +/* lock free root dinfo */
29538 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29541 + aufs_bindex_t bindex, bbot;
29542 + struct path path;
29543 + struct au_hdentry *hdp;
29544 + struct au_branch *br;
29545 + au_br_perm_str_t perm;
29548 + bbot = au_sbbot(sb);
29550 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29551 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29552 + br = au_sbr(sb, bindex);
29553 + path.mnt = au_br_mnt(br);
29554 + path.dentry = hdp->hd_dentry;
29555 + err = au_seq_path(seq, &path);
29557 + au_optstr_br_perm(&perm, br->br_perm);
29558 + seq_printf(seq, "=%s", perm.a);
29559 + if (bindex != bbot)
29560 + seq_putc(seq, ':');
29563 + if (unlikely(err || seq_has_overflowed(seq)))
29569 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29570 + const char *append)
29575 + while (*pat != ':')
29578 + strcpy(p, append);
29579 + AuDebugOn(strlen(fmt) >= len);
29582 +static void au_show_wbr_create(struct seq_file *m, int v,
29583 + struct au_sbinfo *sbinfo)
29587 + struct au_wbr_mfs *mfs;
29589 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29591 + seq_puts(m, ",create=");
29592 + pat = au_optstr_wbr_create(v);
29593 + mfs = &sbinfo->si_wbr_mfs;
29595 + case AuWbrCreate_TDP:
29596 + case AuWbrCreate_RR:
29597 + case AuWbrCreate_MFS:
29598 + case AuWbrCreate_PMFS:
29599 + seq_puts(m, pat);
29601 + case AuWbrCreate_MFSRR:
29602 + case AuWbrCreate_TDMFS:
29603 + case AuWbrCreate_PMFSRR:
29604 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29605 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29607 + case AuWbrCreate_MFSV:
29608 + case AuWbrCreate_PMFSV:
29609 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29610 + seq_printf(m, fmt,
29611 + jiffies_to_msecs(mfs->mfs_expire)
29614 + case AuWbrCreate_MFSRRV:
29615 + case AuWbrCreate_TDMFSV:
29616 + case AuWbrCreate_PMFSRRV:
29617 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29618 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29619 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29626 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29628 +#ifdef CONFIG_SYSFS
29632 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29633 + aufs_bindex_t bindex, brid;
29634 + struct qstr *name;
29636 + struct dentry *d, *h_root;
29637 + struct au_branch *br;
29639 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29642 + f = au_sbi(sb)->si_xib;
29646 + /* stop printing the default xino path on the first writable branch */
29648 + bindex = au_xi_root(sb, f->f_path.dentry);
29649 + if (bindex >= 0) {
29650 + br = au_sbr_sb(sb, bindex);
29651 + h_root = au_br_dentry(br);
29654 + d = f->f_path.dentry;
29655 + name = &d->d_name;
29656 + /* safe ->d_parent because the file is unlinked */
29657 + if (d->d_parent == h_root
29658 + && name->len == len
29659 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29662 + seq_puts(seq, ",xino=");
29663 + err = au_xino_path(seq, f);
29670 +/* seq_file will re-call me in case of too long string */
29671 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29674 + unsigned int mnt_flags, v;
29675 + struct super_block *sb;
29676 + struct au_sbinfo *sbinfo;
29678 +#define AuBool(name, str) do { \
29679 + v = au_opt_test(mnt_flags, name); \
29680 + if (v != au_opt_test(AuOpt_Def, name)) \
29681 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29684 +#define AuStr(name, str) do { \
29685 + v = mnt_flags & AuOptMask_##name; \
29686 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29687 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29690 +#define AuUInt(name, str, val) do { \
29691 + if (val != AUFS_##name##_DEF) \
29692 + seq_printf(m, "," #str "=%u", val); \
29695 + sb = dentry->d_sb;
29696 + if (sb->s_flags & SB_POSIXACL)
29697 + seq_puts(m, ",acl");
29699 + if (sb->s_flags & SB_I_VERSION)
29700 + seq_puts(m, ",i_version");
29703 + /* lock free root dinfo */
29704 + si_noflush_read_lock(sb);
29705 + sbinfo = au_sbi(sb);
29706 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29708 + mnt_flags = au_mntflags(sb);
29709 + if (au_opt_test(mnt_flags, XINO)) {
29710 + err = au_show_xino(m, sb);
29711 + if (unlikely(err))
29714 + seq_puts(m, ",noxino");
29716 + AuBool(TRUNC_XINO, trunc_xino);
29717 + AuStr(UDBA, udba);
29718 + AuBool(SHWH, shwh);
29719 + AuBool(PLINK, plink);
29720 + AuBool(DIO, dio);
29721 + AuBool(DIRPERM1, dirperm1);
29723 + v = sbinfo->si_wbr_create;
29724 + if (v != AuWbrCreate_Def)
29725 + au_show_wbr_create(m, v, sbinfo);
29727 + v = sbinfo->si_wbr_copyup;
29728 + if (v != AuWbrCopyup_Def)
29729 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29731 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29732 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29733 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29735 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29737 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29738 + AuUInt(RDCACHE, rdcache, v);
29740 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29741 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29743 + au_fhsm_show(m, sbinfo);
29745 + AuBool(DIRREN, dirren);
29746 + AuBool(SUM, sum);
29747 + /* AuBool(SUM_W, wsum); */
29748 + AuBool(WARN_PERM, warn_perm);
29749 + AuBool(VERBOSE, verbose);
29752 + /* be sure to print "br:" last */
29753 + if (!sysaufs_brs) {
29754 + seq_puts(m, ",br:");
29755 + au_show_brs(m, sb);
29757 + si_read_unlock(sb);
29765 +/* ---------------------------------------------------------------------- */
29767 +/* sum mode which returns the summation for statfs(2) */
29769 +static u64 au_add_till_max(u64 a, u64 b)
29777 + return ULLONG_MAX;
29780 +static u64 au_mul_till_max(u64 a, long mul)
29788 + return ULLONG_MAX;
29791 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29794 + long bsize, factor;
29795 + u64 blocks, bfree, bavail, files, ffree;
29796 + aufs_bindex_t bbot, bindex, i;
29797 + unsigned char shared;
29798 + struct path h_path;
29799 + struct super_block *h_sb;
29802 + bsize = LONG_MAX;
29808 + bbot = au_sbbot(sb);
29809 + for (bindex = 0; bindex <= bbot; bindex++) {
29810 + h_path.mnt = au_sbr_mnt(sb, bindex);
29811 + h_sb = h_path.mnt->mnt_sb;
29813 + for (i = 0; !shared && i < bindex; i++)
29814 + shared = (au_sbr_sb(sb, i) == h_sb);
29818 + /* sb->s_root for NFS is unreliable */
29819 + h_path.dentry = h_path.mnt->mnt_root;
29820 + err = vfs_statfs(&h_path, buf);
29821 + if (unlikely(err))
29824 + if (bsize > buf->f_bsize) {
29826 + * we will reduce bsize, so we have to expand blocks
29827 + * etc. to match them again
29829 + factor = (bsize / buf->f_bsize);
29830 + blocks = au_mul_till_max(blocks, factor);
29831 + bfree = au_mul_till_max(bfree, factor);
29832 + bavail = au_mul_till_max(bavail, factor);
29833 + bsize = buf->f_bsize;
29836 + factor = (buf->f_bsize / bsize);
29837 + blocks = au_add_till_max(blocks,
29838 + au_mul_till_max(buf->f_blocks, factor));
29839 + bfree = au_add_till_max(bfree,
29840 + au_mul_till_max(buf->f_bfree, factor));
29841 + bavail = au_add_till_max(bavail,
29842 + au_mul_till_max(buf->f_bavail, factor));
29843 + files = au_add_till_max(files, buf->f_files);
29844 + ffree = au_add_till_max(ffree, buf->f_ffree);
29847 + buf->f_bsize = bsize;
29848 + buf->f_blocks = blocks;
29849 + buf->f_bfree = bfree;
29850 + buf->f_bavail = bavail;
29851 + buf->f_files = files;
29852 + buf->f_ffree = ffree;
29853 + buf->f_frsize = 0;
29859 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29862 + struct path h_path;
29863 + struct super_block *sb;
29865 + /* lock free root dinfo */
29866 + sb = dentry->d_sb;
29867 + si_noflush_read_lock(sb);
29868 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29869 + /* sb->s_root for NFS is unreliable */
29870 + h_path.mnt = au_sbr_mnt(sb, 0);
29871 + h_path.dentry = h_path.mnt->mnt_root;
29872 + err = vfs_statfs(&h_path, buf);
29874 + err = au_statfs_sum(sb, buf);
29875 + si_read_unlock(sb);
29878 + buf->f_type = AUFS_SUPER_MAGIC;
29879 + buf->f_namelen = AUFS_MAX_NAMELEN;
29880 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29882 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29887 +/* ---------------------------------------------------------------------- */
29889 +static int aufs_sync_fs(struct super_block *sb, int wait)
29892 + aufs_bindex_t bbot, bindex;
29893 + struct au_branch *br;
29894 + struct super_block *h_sb;
29897 + si_noflush_read_lock(sb);
29898 + bbot = au_sbbot(sb);
29899 + for (bindex = 0; bindex <= bbot; bindex++) {
29900 + br = au_sbr(sb, bindex);
29901 + if (!au_br_writable(br->br_perm))
29904 + h_sb = au_sbr_sb(sb, bindex);
29905 + e = vfsub_sync_filesystem(h_sb, wait);
29906 + if (unlikely(e && !err))
29908 + /* go on even if an error happens */
29910 + si_read_unlock(sb);
29915 +/* ---------------------------------------------------------------------- */
29917 +/* final actions when unmounting a file system */
29918 +static void aufs_put_super(struct super_block *sb)
29920 + struct au_sbinfo *sbinfo;
29922 + sbinfo = au_sbi(sb);
29924 + kobject_put(&sbinfo->si_kobj);
29927 +/* ---------------------------------------------------------------------- */
29929 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29930 + struct super_block *sb, void *arg)
29933 + unsigned long long n, sz;
29940 + if (*hint > ULLONG_MAX / sizeof(array)) {
29941 + array = ERR_PTR(-EMFILE);
29942 + pr_err("hint %llu\n", *hint);
29946 + sz = sizeof(array) * *hint;
29947 + array = kzalloc(sz, GFP_NOFS);
29948 + if (unlikely(!array))
29949 + array = vzalloc(sz);
29950 + if (unlikely(!array)) {
29951 + array = ERR_PTR(-ENOMEM);
29955 + n = cb(sb, array, *hint, arg);
29956 + AuDebugOn(n > *hint);
29963 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29964 + unsigned long long max __maybe_unused,
29967 + unsigned long long n;
29968 + struct inode **p, *inode;
29969 + struct list_head *head;
29974 + spin_lock(&sb->s_inode_list_lock);
29975 + list_for_each_entry(inode, head, i_sb_list) {
29976 + if (!au_is_bad_inode(inode)
29977 + && au_ii(inode)->ii_btop >= 0) {
29978 + spin_lock(&inode->i_lock);
29979 + if (atomic_read(&inode->i_count)) {
29983 + AuDebugOn(n > max);
29985 + spin_unlock(&inode->i_lock);
29988 + spin_unlock(&sb->s_inode_list_lock);
29993 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29995 + struct au_sbinfo *sbi;
29997 + sbi = au_sbi(sb);
29998 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29999 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30002 +void au_iarray_free(struct inode **a, unsigned long long max)
30004 + unsigned long long ull;
30006 + for (ull = 0; ull < max; ull++)
30011 +/* ---------------------------------------------------------------------- */
30014 + * refresh dentry and inode at remount time.
30016 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30017 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30018 + struct dentry *parent)
30022 + di_write_lock_child(dentry);
30023 + di_read_lock_parent(parent, AuLock_IR);
30024 + err = au_refresh_dentry(dentry, parent);
30025 + if (!err && dir_flags)
30026 + au_hn_reset(d_inode(dentry), dir_flags);
30027 + di_read_unlock(parent, AuLock_IR);
30028 + di_write_unlock(dentry);
30033 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30034 + struct au_sbinfo *sbinfo,
30035 + const unsigned int dir_flags, unsigned int do_idop)
30038 + struct dentry *parent;
30041 + parent = dget_parent(dentry);
30042 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30043 + if (d_really_is_positive(dentry)) {
30044 + if (!d_is_dir(dentry))
30045 + err = au_do_refresh(dentry, /*dir_flags*/0,
30048 + err = au_do_refresh(dentry, dir_flags, parent);
30049 + if (unlikely(err))
30050 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30053 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30054 + AuDbgDentry(dentry);
30060 + au_refresh_dop(dentry, /*force_reval*/0);
30062 + au_refresh_dop(dentry, /*force_reval*/1);
30068 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30070 + int err, i, j, ndentry, e;
30071 + unsigned int sigen;
30072 + struct au_dcsub_pages dpages;
30073 + struct au_dpage *dpage;
30074 + struct dentry **dentries, *d;
30075 + struct au_sbinfo *sbinfo;
30076 + struct dentry *root = sb->s_root;
30077 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30080 + au_refresh_dop(root, /*force_reval*/0);
30082 + err = au_dpages_init(&dpages, GFP_NOFS);
30083 + if (unlikely(err))
30085 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30086 + if (unlikely(err))
30089 + sigen = au_sigen(sb);
30090 + sbinfo = au_sbi(sb);
30091 + for (i = 0; i < dpages.ndpage; i++) {
30092 + dpage = dpages.dpages + i;
30093 + dentries = dpage->dentries;
30094 + ndentry = dpage->ndentry;
30095 + for (j = 0; j < ndentry; j++) {
30097 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30099 + if (unlikely(e && !err))
30101 + /* go on even err */
30106 + au_dpages_free(&dpages);
30111 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30114 + unsigned int sigen;
30115 + unsigned long long max, ull;
30116 + struct inode *inode, **array;
30118 + array = au_iarray_alloc(sb, &max);
30119 + err = PTR_ERR(array);
30120 + if (IS_ERR(array))
30124 + sigen = au_sigen(sb);
30125 + for (ull = 0; ull < max; ull++) {
30126 + inode = array[ull];
30127 + if (unlikely(!inode))
30131 + ii_write_lock_child(inode);
30132 + if (au_iigen(inode, NULL) != sigen) {
30133 + e = au_refresh_hinode_self(inode);
30134 + if (unlikely(e)) {
30135 + au_refresh_iop(inode, /*force_getattr*/1);
30136 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30139 + /* go on even if err */
30142 + if (!e && do_idop)
30143 + au_refresh_iop(inode, /*force_getattr*/0);
30144 + ii_write_unlock(inode);
30147 + au_iarray_free(array, max);
30153 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30156 + unsigned int udba;
30157 + aufs_bindex_t bindex, bbot;
30158 + struct dentry *root;
30159 + struct inode *inode;
30160 + struct au_branch *br;
30161 + struct au_sbinfo *sbi;
30163 + au_sigen_inc(sb);
30164 + sbi = au_sbi(sb);
30165 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30167 + root = sb->s_root;
30168 + DiMustNoWaiters(root);
30169 + inode = d_inode(root);
30170 + IiMustNoWaiters(inode);
30172 + udba = au_opt_udba(sb);
30173 + bbot = au_sbbot(sb);
30174 + for (bindex = 0; bindex <= bbot; bindex++) {
30175 + br = au_sbr(sb, bindex);
30176 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30177 + if (unlikely(err))
30178 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30180 + /* go on even if err */
30182 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30185 + if (au_ftest_si(sbi, NO_DREVAL)) {
30186 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30187 + sb->s_d_op = &aufs_dop_noreval;
30188 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30189 + sbi->si_iop_array = aufs_iop_nogetattr;
30191 + AuDebugOn(sb->s_d_op == &aufs_dop);
30192 + sb->s_d_op = &aufs_dop;
30193 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30194 + sbi->si_iop_array = aufs_iop;
30196 + pr_info("reset to %ps and %ps\n",
30197 + sb->s_d_op, sbi->si_iop_array);
30200 + di_write_unlock(root);
30201 + err = au_refresh_d(sb, do_idop);
30202 + e = au_refresh_i(sb, do_idop);
30203 + if (unlikely(e && !err))
30205 + /* aufs_write_lock() calls ..._child() */
30206 + di_write_lock_child(root);
30208 + au_cpup_attr_all(inode, /*force*/1);
30210 + if (unlikely(err))
30211 + AuIOErr("refresh failed, ignored, %d\n", err);
30214 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30215 +static int cvt_err(int err)
30229 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30232 + unsigned int mntflags;
30233 + struct au_opts opts = {
30236 + struct dentry *root;
30237 + struct inode *inode;
30238 + struct au_sbinfo *sbinfo;
30241 + root = sb->s_root;
30242 + if (!data || !*data) {
30243 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30245 + di_write_lock_child(root);
30246 + err = au_opts_verify(sb, *flags, /*pending*/0);
30247 + aufs_write_unlock(root);
30253 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30254 + if (unlikely(!opts.opt))
30256 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30257 + opts.flags = AuOpts_REMOUNT;
30258 + opts.sb_flags = *flags;
30260 + /* parse it before aufs lock */
30261 + err = au_opts_parse(sb, data, &opts);
30262 + if (unlikely(err))
30265 + sbinfo = au_sbi(sb);
30266 + inode = d_inode(root);
30267 + inode_lock(inode);
30268 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30269 + if (unlikely(err))
30271 + di_write_lock_child(root);
30273 + /* au_opts_remount() may return an error */
30274 + err = au_opts_remount(sb, &opts);
30275 + au_opts_free(&opts);
30277 + if (au_ftest_opts(opts.flags, REFRESH))
30278 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30280 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30281 + mntflags = au_mntflags(sb);
30282 + do_dx = !!au_opt_test(mntflags, DIO);
30283 + au_dy_arefresh(do_dx);
30286 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30287 + aufs_write_unlock(root);
30290 + inode_unlock(inode);
30292 + free_page((unsigned long)opts.opt);
30294 + err = cvt_err(err);
30299 +static const struct super_operations aufs_sop = {
30300 + .alloc_inode = aufs_alloc_inode,
30301 + .destroy_inode = aufs_destroy_inode,
30302 + /* always deleting, no clearing */
30303 + .drop_inode = generic_delete_inode,
30304 + .show_options = aufs_show_options,
30305 + .statfs = aufs_statfs,
30306 + .put_super = aufs_put_super,
30307 + .sync_fs = aufs_sync_fs,
30308 + .remount_fs = aufs_remount_fs
30311 +/* ---------------------------------------------------------------------- */
30313 +static int alloc_root(struct super_block *sb)
30316 + struct inode *inode;
30317 + struct dentry *root;
30320 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30321 + err = PTR_ERR(inode);
30322 + if (IS_ERR(inode))
30325 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30326 + inode->i_fop = &aufs_dir_fop;
30327 + inode->i_mode = S_IFDIR;
30328 + set_nlink(inode, 2);
30329 + unlock_new_inode(inode);
30331 + root = d_make_root(inode);
30332 + if (unlikely(!root))
30334 + err = PTR_ERR(root);
30335 + if (IS_ERR(root))
30338 + err = au_di_init(root);
30340 + sb->s_root = root;
30341 + return 0; /* success */
30349 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30350 + int silent __maybe_unused)
30353 + struct au_opts opts = {
30356 + struct au_sbinfo *sbinfo;
30357 + struct dentry *root;
30358 + struct inode *inode;
30359 + char *arg = raw_data;
30361 + if (unlikely(!arg || !*arg)) {
30363 + pr_err("no arg\n");
30368 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30369 + if (unlikely(!opts.opt))
30371 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30372 + opts.sb_flags = sb->s_flags;
30374 + err = au_si_alloc(sb);
30375 + if (unlikely(err))
30377 + sbinfo = au_sbi(sb);
30379 + /* all timestamps always follow the ones on the branch */
30380 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30381 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30382 + sb->s_op = &aufs_sop;
30383 + sb->s_d_op = &aufs_dop;
30384 + sb->s_magic = AUFS_SUPER_MAGIC;
30385 + sb->s_maxbytes = 0;
30386 + sb->s_stack_depth = 1;
30387 + au_export_init(sb);
30388 + au_xattr_init(sb);
30390 + err = alloc_root(sb);
30391 + if (unlikely(err)) {
30392 + si_write_unlock(sb);
30395 + root = sb->s_root;
30396 + inode = d_inode(root);
30399 + * actually we can parse options regardless aufs lock here.
30400 + * but at remount time, parsing must be done before aufs lock.
30401 + * so we follow the same rule.
30403 + ii_write_lock_parent(inode);
30404 + aufs_write_unlock(root);
30405 + err = au_opts_parse(sb, arg, &opts);
30406 + if (unlikely(err))
30409 + /* lock vfs_inode first, then aufs. */
30410 + inode_lock(inode);
30411 + aufs_write_lock(root);
30412 + err = au_opts_mount(sb, &opts);
30413 + au_opts_free(&opts);
30414 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30415 + sb->s_d_op = &aufs_dop_noreval;
30416 + pr_info("%ps\n", sb->s_d_op);
30417 + au_refresh_dop(root, /*force_reval*/0);
30418 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30419 + au_refresh_iop(inode, /*force_getattr*/0);
30421 + aufs_write_unlock(root);
30422 + inode_unlock(inode);
30424 + goto out_opts; /* success */
30428 + sb->s_root = NULL;
30430 + kobject_put(&sbinfo->si_kobj);
30431 + sb->s_fs_info = NULL;
30433 + free_page((unsigned long)opts.opt);
30436 + err = cvt_err(err);
30441 +/* ---------------------------------------------------------------------- */
30443 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30444 + const char *dev_name __maybe_unused,
30447 + struct dentry *root;
30449 + /* all timestamps always follow the ones on the branch */
30450 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30451 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30452 + if (IS_ERR(root))
30455 + au_sbilist_add(root->d_sb);
30461 +static void aufs_kill_sb(struct super_block *sb)
30463 + struct au_sbinfo *sbinfo;
30465 + sbinfo = au_sbi(sb);
30467 + au_sbilist_del(sb);
30468 + aufs_write_lock(sb->s_root);
30470 + if (sbinfo->si_wbr_create_ops->fin)
30471 + sbinfo->si_wbr_create_ops->fin(sb);
30472 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30473 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30474 + au_remount_refresh(sb, /*do_idop*/0);
30476 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30477 + au_plink_put(sb, /*verbose*/1);
30479 + au_dr_opt_flush(sb);
30480 + sbinfo->si_sb = NULL;
30481 + aufs_write_unlock(sb->s_root);
30482 + au_nwt_flush(&sbinfo->si_nowait);
30484 + kill_anon_super(sb);
30487 +struct file_system_type aufs_fs_type = {
30488 + .name = AUFS_FSTYPE,
30489 + /* a race between rename and others */
30490 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30491 + .mount = aufs_mount,
30492 + .kill_sb = aufs_kill_sb,
30493 + /* no need to __module_get() and module_put(). */
30494 + .owner = THIS_MODULE,
30496 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30497 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30498 +++ linux/fs/aufs/super.h 2018-10-23 12:33:35.599375796 +0200
30500 +/* SPDX-License-Identifier: GPL-2.0 */
30502 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30504 + * This program, aufs is free software; you can redistribute it and/or modify
30505 + * it under the terms of the GNU General Public License as published by
30506 + * the Free Software Foundation; either version 2 of the License, or
30507 + * (at your option) any later version.
30509 + * This program is distributed in the hope that it will be useful,
30510 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30511 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30512 + * GNU General Public License for more details.
30514 + * You should have received a copy of the GNU General Public License
30515 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30519 + * super_block operations
30522 +#ifndef __AUFS_SUPER_H__
30523 +#define __AUFS_SUPER_H__
30527 +#include <linux/fs.h>
30528 +#include <linux/kobject.h>
30531 +#include "rwsem.h"
30534 +/* policies to select one among multiple writable branches */
30535 +struct au_wbr_copyup_operations {
30536 + int (*copyup)(struct dentry *dentry);
30539 +#define AuWbr_DIR 1 /* target is a dir */
30540 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30542 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30543 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30544 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30546 +struct au_wbr_create_operations {
30547 + int (*create)(struct dentry *dentry, unsigned int flags);
30548 + int (*init)(struct super_block *sb);
30549 + int (*fin)(struct super_block *sb);
30552 +struct au_wbr_mfs {
30553 + struct mutex mfs_lock; /* protect this structure */
30554 + unsigned long mfs_jiffy;
30555 + unsigned long mfs_expire;
30556 + aufs_bindex_t mfs_bindex;
30558 + unsigned long long mfsrr_bytes;
30559 + unsigned long long mfsrr_watermark;
30562 +#define AuPlink_NHASH 100
30563 +static inline int au_plink_hash(ino_t ino)
30565 + return ino % AuPlink_NHASH;
30568 +/* File-based Hierarchical Storage Management */
30570 +#ifdef CONFIG_AUFS_FHSM
30571 + /* allow only one process who can receive the notification */
30572 + spinlock_t fhsm_spin;
30574 + wait_queue_head_t fhsm_wqh;
30575 + atomic_t fhsm_readable;
30577 + /* these are protected by si_rwsem */
30578 + unsigned long fhsm_expire;
30579 + aufs_bindex_t fhsm_bottom;
30584 +struct au_sbinfo {
30585 + /* nowait tasks in the system-wide workqueue */
30586 + struct au_nowait_tasks si_nowait;
30589 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30590 + * rwsem for au_sbinfo is necessary.
30592 + struct au_rwsem si_rwsem;
30595 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30598 + au_lcnt_t si_ninodes, si_nfiles;
30600 + /* branch management */
30601 + unsigned int si_generation;
30603 + /* see AuSi_ flags */
30604 + unsigned char au_si_status;
30606 + aufs_bindex_t si_bbot;
30608 + /* dirty trick to keep br_id plus */
30609 + unsigned int si_last_br_id :
30610 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30611 + struct au_branch **si_branch;
30613 + /* policy to select a writable branch */
30614 + unsigned char si_wbr_copyup;
30615 + unsigned char si_wbr_create;
30616 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30617 + struct au_wbr_create_operations *si_wbr_create_ops;
30619 + /* round robin */
30620 + atomic_t si_wbr_rr_next;
30622 + /* most free space */
30623 + struct au_wbr_mfs si_wbr_mfs;
30625 + /* File-based Hierarchical Storage Management */
30626 + struct au_fhsm si_fhsm;
30628 + /* mount flags */
30629 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30630 + unsigned int si_mntflags;
30632 + /* external inode number (bitmap and translation table) */
30633 + vfs_readf_t si_xread;
30634 + vfs_writef_t si_xwrite;
30635 + loff_t si_ximaxent; /* max entries in a xino */
30637 + struct file *si_xib;
30638 + struct mutex si_xib_mtx; /* protect xib members */
30639 + unsigned long *si_xib_buf;
30640 + unsigned long si_xib_last_pindex;
30641 + int si_xib_next_bit;
30643 + unsigned long si_xino_jiffy;
30644 + unsigned long si_xino_expire;
30645 + /* reserved for future use */
30646 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30648 +#ifdef CONFIG_AUFS_EXPORT
30649 + /* i_generation */
30650 + /* todo: make xigen file an array to support many inode numbers */
30651 + struct file *si_xigen;
30652 + atomic_t si_xigen_next;
30655 + /* dirty trick to support atomic_open */
30656 + struct hlist_bl_head si_aopen;
30658 + /* vdir parameters */
30659 + unsigned long si_rdcache; /* max cache time in jiffies */
30660 + unsigned int si_rdblk; /* deblk size */
30661 + unsigned int si_rdhash; /* hash size */
30664 + * If the number of whiteouts are larger than si_dirwh, leave all of
30665 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30666 + * future fsck.aufs or kernel thread will remove them later.
30667 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30669 + unsigned int si_dirwh;
30671 + /* pseudo_link list */
30672 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30673 + wait_queue_head_t si_plink_wq;
30674 + spinlock_t si_plink_maint_lock;
30675 + pid_t si_plink_maint_pid;
30678 + struct hlist_bl_head si_files;
30680 + /* with/without getattr, brother of sb->s_d_op */
30681 + struct inode_operations *si_iop_array;
30684 + * sysfs and lifetime management.
30685 + * this is not a small structure and it may be a waste of memory in case
30686 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30687 + * but using sysfs is majority.
30689 + struct kobject si_kobj;
30690 +#ifdef CONFIG_DEBUG_FS
30691 + struct dentry *si_dbgaufs;
30692 + struct dentry *si_dbgaufs_plink;
30693 + struct dentry *si_dbgaufs_xib;
30694 +#ifdef CONFIG_AUFS_EXPORT
30695 + struct dentry *si_dbgaufs_xigen;
30699 +#ifdef CONFIG_AUFS_SBILIST
30700 + struct hlist_bl_node si_list;
30703 + /* dirty, necessary for unmounting, sysfs and sysrq */
30704 + struct super_block *si_sb;
30707 +/* sbinfo status flags */
30709 + * set true when refresh_dirs() failed at remount time.
30710 + * then try refreshing dirs at access time again.
30711 + * if it is false, refreshing dirs at access time is unnecessary
30713 +#define AuSi_FAILED_REFRESH_DIR 1
30714 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30715 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30717 +#ifndef CONFIG_AUFS_FHSM
30719 +#define AuSi_FHSM 0
30722 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30723 + unsigned int flag)
30725 + AuRwMustAnyLock(&sbi->si_rwsem);
30726 + return sbi->au_si_status & flag;
30728 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30729 +#define au_fset_si(sbinfo, name) do { \
30730 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30731 + (sbinfo)->au_si_status |= AuSi_##name; \
30733 +#define au_fclr_si(sbinfo, name) do { \
30734 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30735 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30738 +/* ---------------------------------------------------------------------- */
30740 +/* policy to select one among writable branches */
30741 +#define AuWbrCopyup(sbinfo, ...) \
30742 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30743 +#define AuWbrCreate(sbinfo, ...) \
30744 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30746 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30747 +#define AuLock_DW 1 /* write-lock dentry */
30748 +#define AuLock_IR (1 << 1) /* read-lock inode */
30749 +#define AuLock_IW (1 << 2) /* write-lock inode */
30750 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30751 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30752 + /* except RENAME_EXCHANGE */
30753 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30754 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30755 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30756 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30757 +#define au_fset_lock(flags, name) \
30758 + do { (flags) |= AuLock_##name; } while (0)
30759 +#define au_fclr_lock(flags, name) \
30760 + do { (flags) &= ~AuLock_##name; } while (0)
30762 +/* ---------------------------------------------------------------------- */
30765 +extern struct file_system_type aufs_fs_type;
30766 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30767 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30768 + unsigned long long max, void *arg);
30769 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30770 + struct super_block *sb, void *arg);
30771 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30772 +void au_iarray_free(struct inode **a, unsigned long long max);
30775 +void au_si_free(struct kobject *kobj);
30776 +int au_si_alloc(struct super_block *sb);
30777 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30779 +unsigned int au_sigen_inc(struct super_block *sb);
30780 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30782 +int si_read_lock(struct super_block *sb, int flags);
30783 +int si_write_lock(struct super_block *sb, int flags);
30784 +int aufs_read_lock(struct dentry *dentry, int flags);
30785 +void aufs_read_unlock(struct dentry *dentry, int flags);
30786 +void aufs_write_lock(struct dentry *dentry);
30787 +void aufs_write_unlock(struct dentry *dentry);
30788 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30789 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30791 +/* wbr_policy.c */
30792 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30793 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30794 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30795 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30796 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30799 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30801 +#ifdef CONFIG_AUFS_FHSM
30804 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30808 + spin_lock(&fhsm->fhsm_spin);
30809 + pid = fhsm->fhsm_pid;
30810 + spin_unlock(&fhsm->fhsm_spin);
30815 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30816 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30817 +int au_fhsm_fd(struct super_block *sb, int oflags);
30818 +int au_fhsm_br_alloc(struct au_branch *br);
30819 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30820 +void au_fhsm_fin(struct super_block *sb);
30821 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30822 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30823 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30825 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30827 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30828 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30829 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30830 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30831 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30832 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30833 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30834 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30835 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30838 +/* ---------------------------------------------------------------------- */
30840 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30842 + return sb->s_fs_info;
30845 +/* ---------------------------------------------------------------------- */
30847 +#ifdef CONFIG_AUFS_EXPORT
30848 +int au_test_nfsd(void);
30849 +void au_export_init(struct super_block *sb);
30850 +void au_xigen_inc(struct inode *inode);
30851 +int au_xigen_new(struct inode *inode);
30852 +int au_xigen_set(struct super_block *sb, struct path *path);
30853 +void au_xigen_clr(struct super_block *sb);
30855 +static inline int au_busy_or_stale(void)
30857 + if (!au_test_nfsd())
30862 +AuStubInt0(au_test_nfsd, void)
30863 +AuStubVoid(au_export_init, struct super_block *sb)
30864 +AuStubVoid(au_xigen_inc, struct inode *inode)
30865 +AuStubInt0(au_xigen_new, struct inode *inode)
30866 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30867 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30868 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30869 +#endif /* CONFIG_AUFS_EXPORT */
30871 +/* ---------------------------------------------------------------------- */
30873 +#ifdef CONFIG_AUFS_SBILIST
30875 +extern struct hlist_bl_head au_sbilist;
30877 +static inline void au_sbilist_init(void)
30879 + INIT_HLIST_BL_HEAD(&au_sbilist);
30882 +static inline void au_sbilist_add(struct super_block *sb)
30884 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30887 +static inline void au_sbilist_del(struct super_block *sb)
30889 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30892 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30893 +static inline void au_sbilist_lock(void)
30895 + hlist_bl_lock(&au_sbilist);
30898 +static inline void au_sbilist_unlock(void)
30900 + hlist_bl_unlock(&au_sbilist);
30902 +#define AuGFP_SBILIST GFP_ATOMIC
30904 +AuStubVoid(au_sbilist_lock, void)
30905 +AuStubVoid(au_sbilist_unlock, void)
30906 +#define AuGFP_SBILIST GFP_NOFS
30907 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30909 +AuStubVoid(au_sbilist_init, void)
30910 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30911 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30912 +AuStubVoid(au_sbilist_lock, void)
30913 +AuStubVoid(au_sbilist_unlock, void)
30914 +#define AuGFP_SBILIST GFP_NOFS
30917 +/* ---------------------------------------------------------------------- */
30919 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30922 + * This function is a dynamic '__init' function actually,
30923 + * so the tiny check for si_rwsem is unnecessary.
30925 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30926 +#ifdef CONFIG_DEBUG_FS
30927 + sbinfo->si_dbgaufs = NULL;
30928 + sbinfo->si_dbgaufs_plink = NULL;
30929 + sbinfo->si_dbgaufs_xib = NULL;
30930 +#ifdef CONFIG_AUFS_EXPORT
30931 + sbinfo->si_dbgaufs_xigen = NULL;
30936 +/* ---------------------------------------------------------------------- */
30938 +/* current->atomic_flags */
30939 +/* this value should never corrupt the ones defined in linux/sched.h */
30940 +#define PFA_AUFS 7
30942 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30943 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30944 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30946 +static inline int si_pid_test(struct super_block *sb)
30948 + return !!task_test_aufs(current);
30951 +static inline void si_pid_clr(struct super_block *sb)
30953 + AuDebugOn(!task_test_aufs(current));
30954 + task_clear_aufs(current);
30957 +static inline void si_pid_set(struct super_block *sb)
30959 + AuDebugOn(task_test_aufs(current));
30960 + task_set_aufs(current);
30963 +/* ---------------------------------------------------------------------- */
30965 +/* lock superblock. mainly for entry point functions */
30966 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30967 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30968 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30969 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30971 +#define __si_read_trylock_nested(sb) \
30972 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30973 +#define __si_write_trylock_nested(sb) \
30974 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30977 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30978 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30979 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30981 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30982 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30983 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30985 +static inline void si_noflush_read_lock(struct super_block *sb)
30987 + __si_read_lock(sb);
30991 +static inline int si_noflush_read_trylock(struct super_block *sb)
30995 + locked = __si_read_trylock(sb);
31001 +static inline void si_noflush_write_lock(struct super_block *sb)
31003 + __si_write_lock(sb);
31007 +static inline int si_noflush_write_trylock(struct super_block *sb)
31011 + locked = __si_write_trylock(sb);
31017 +#if 0 /* reserved */
31018 +static inline int si_read_trylock(struct super_block *sb, int flags)
31020 + if (au_ftest_lock(flags, FLUSH))
31021 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31022 + return si_noflush_read_trylock(sb);
31026 +static inline void si_read_unlock(struct super_block *sb)
31029 + __si_read_unlock(sb);
31032 +#if 0 /* reserved */
31033 +static inline int si_write_trylock(struct super_block *sb, int flags)
31035 + if (au_ftest_lock(flags, FLUSH))
31036 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31037 + return si_noflush_write_trylock(sb);
31041 +static inline void si_write_unlock(struct super_block *sb)
31044 + __si_write_unlock(sb);
31047 +#if 0 /* reserved */
31048 +static inline void si_downgrade_lock(struct super_block *sb)
31050 + __si_downgrade_lock(sb);
31054 +/* ---------------------------------------------------------------------- */
31056 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31058 + SiMustAnyLock(sb);
31059 + return au_sbi(sb)->si_bbot;
31062 +static inline unsigned int au_mntflags(struct super_block *sb)
31064 + SiMustAnyLock(sb);
31065 + return au_sbi(sb)->si_mntflags;
31068 +static inline unsigned int au_sigen(struct super_block *sb)
31070 + SiMustAnyLock(sb);
31071 + return au_sbi(sb)->si_generation;
31074 +static inline struct au_branch *au_sbr(struct super_block *sb,
31075 + aufs_bindex_t bindex)
31077 + SiMustAnyLock(sb);
31078 + return au_sbi(sb)->si_branch[0 + bindex];
31081 +static inline loff_t au_xi_maxent(struct super_block *sb)
31083 + SiMustAnyLock(sb);
31084 + return au_sbi(sb)->si_ximaxent;
31087 +#endif /* __KERNEL__ */
31088 +#endif /* __AUFS_SUPER_H__ */
31089 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31090 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31091 +++ linux/fs/aufs/sysaufs.c 2018-08-12 23:43:05.463458173 +0200
31093 +// SPDX-License-Identifier: GPL-2.0
31095 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31097 + * This program, aufs is free software; you can redistribute it and/or modify
31098 + * it under the terms of the GNU General Public License as published by
31099 + * the Free Software Foundation; either version 2 of the License, or
31100 + * (at your option) any later version.
31102 + * This program is distributed in the hope that it will be useful,
31103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31105 + * GNU General Public License for more details.
31107 + * You should have received a copy of the GNU General Public License
31108 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31112 + * sysfs interface and lifetime management
31113 + * they are necessary regardless sysfs is disabled.
31116 +#include <linux/random.h>
31119 +unsigned long sysaufs_si_mask;
31120 +struct kset *sysaufs_kset;
31122 +#define AuSiAttr(_name) { \
31123 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31124 + .show = sysaufs_si_##_name, \
31127 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31128 +struct attribute *sysaufs_si_attrs[] = {
31129 + &sysaufs_si_attr_xi_path.attr,
31133 +static const struct sysfs_ops au_sbi_ops = {
31134 + .show = sysaufs_si_show
31137 +static struct kobj_type au_sbi_ktype = {
31138 + .release = au_si_free,
31139 + .sysfs_ops = &au_sbi_ops,
31140 + .default_attrs = sysaufs_si_attrs
31143 +/* ---------------------------------------------------------------------- */
31145 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31149 + sbinfo->si_kobj.kset = sysaufs_kset;
31150 + /* cf. sysaufs_name() */
31151 + err = kobject_init_and_add
31152 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31153 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31158 +void sysaufs_fin(void)
31160 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31161 + kset_unregister(sysaufs_kset);
31164 +int __init sysaufs_init(void)
31169 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31170 + } while (!sysaufs_si_mask);
31173 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31174 + if (unlikely(!sysaufs_kset))
31176 + err = PTR_ERR(sysaufs_kset);
31177 + if (IS_ERR(sysaufs_kset))
31179 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31180 + if (unlikely(err))
31181 + kset_unregister(sysaufs_kset);
31186 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31187 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31188 +++ linux/fs/aufs/sysaufs.h 2018-08-12 23:43:05.463458173 +0200
31190 +/* SPDX-License-Identifier: GPL-2.0 */
31192 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31194 + * This program, aufs is free software; you can redistribute it and/or modify
31195 + * it under the terms of the GNU General Public License as published by
31196 + * the Free Software Foundation; either version 2 of the License, or
31197 + * (at your option) any later version.
31199 + * This program is distributed in the hope that it will be useful,
31200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31202 + * GNU General Public License for more details.
31204 + * You should have received a copy of the GNU General Public License
31205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31209 + * sysfs interface and mount lifetime management
31212 +#ifndef __SYSAUFS_H__
31213 +#define __SYSAUFS_H__
31217 +#include <linux/sysfs.h>
31218 +#include "module.h"
31220 +struct super_block;
31223 +struct sysaufs_si_attr {
31224 + struct attribute attr;
31225 + int (*show)(struct seq_file *seq, struct super_block *sb);
31228 +/* ---------------------------------------------------------------------- */
31231 +extern unsigned long sysaufs_si_mask;
31232 +extern struct kset *sysaufs_kset;
31233 +extern struct attribute *sysaufs_si_attrs[];
31234 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31235 +int __init sysaufs_init(void);
31236 +void sysaufs_fin(void);
31238 +/* ---------------------------------------------------------------------- */
31240 +/* some people doesn't like to show a pointer in kernel */
31241 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31243 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31246 +#define SysaufsSiNamePrefix "si_"
31247 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31248 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31250 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31251 + sysaufs_si_id(sbinfo));
31255 +#ifdef CONFIG_SYSFS
31257 +extern struct attribute_group *sysaufs_attr_group;
31259 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31260 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31262 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31263 +#ifdef CONFIG_COMPAT
31264 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31267 +void sysaufs_br_init(struct au_branch *br);
31268 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31269 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31271 +#define sysaufs_brs_init() do {} while (0)
31274 +#define sysaufs_attr_group NULL
31276 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31277 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31278 + struct attribute *attr, char *buf)
31279 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31280 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31281 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31283 +static inline void sysaufs_brs_init(void)
31288 +#endif /* CONFIG_SYSFS */
31290 +#endif /* __KERNEL__ */
31291 +#endif /* __SYSAUFS_H__ */
31292 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31293 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31294 +++ linux/fs/aufs/sysfs.c 2018-08-12 23:43:05.463458173 +0200
31296 +// SPDX-License-Identifier: GPL-2.0
31298 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31300 + * This program, aufs is free software; you can redistribute it and/or modify
31301 + * it under the terms of the GNU General Public License as published by
31302 + * the Free Software Foundation; either version 2 of the License, or
31303 + * (at your option) any later version.
31305 + * This program is distributed in the hope that it will be useful,
31306 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31307 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31308 + * GNU General Public License for more details.
31310 + * You should have received a copy of the GNU General Public License
31311 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31315 + * sysfs interface
31318 +#include <linux/compat.h>
31319 +#include <linux/seq_file.h>
31322 +#ifdef CONFIG_AUFS_FS_MODULE
31323 +/* this entry violates the "one line per file" policy of sysfs */
31324 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31328 + static char *conf =
31329 +/* this file is generated at compiling */
31330 +#include "conf.str"
31333 + err = snprintf(buf, PAGE_SIZE, conf);
31334 + if (unlikely(err >= PAGE_SIZE))
31339 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31342 +static struct attribute *au_attr[] = {
31343 +#ifdef CONFIG_AUFS_FS_MODULE
31344 + &au_config_attr.attr,
31346 + NULL, /* need to NULL terminate the list of attributes */
31349 +static struct attribute_group sysaufs_attr_group_body = {
31353 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31355 +/* ---------------------------------------------------------------------- */
31357 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31361 + SiMustAnyLock(sb);
31364 + if (au_opt_test(au_mntflags(sb), XINO)) {
31365 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31366 + seq_putc(seq, '\n');
31372 + * the lifetime of branch is independent from the entry under sysfs.
31373 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31376 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31377 + aufs_bindex_t bindex, int idx)
31380 + struct path path;
31381 + struct dentry *root;
31382 + struct au_branch *br;
31383 + au_br_perm_str_t perm;
31385 + AuDbg("b%d\n", bindex);
31388 + root = sb->s_root;
31389 + di_read_lock_parent(root, !AuLock_IR);
31390 + br = au_sbr(sb, bindex);
31393 + case AuBrSysfs_BR:
31394 + path.mnt = au_br_mnt(br);
31395 + path.dentry = au_h_dptr(root, bindex);
31396 + err = au_seq_path(seq, &path);
31398 + au_optstr_br_perm(&perm, br->br_perm);
31399 + seq_printf(seq, "=%s\n", perm.a);
31402 + case AuBrSysfs_BRID:
31403 + seq_printf(seq, "%d\n", br->br_id);
31406 + di_read_unlock(root, !AuLock_IR);
31407 + if (unlikely(err || seq_has_overflowed(seq)))
31413 +/* ---------------------------------------------------------------------- */
31415 +static struct seq_file *au_seq(char *p, ssize_t len)
31417 + struct seq_file *seq;
31419 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31421 + /* mutex_init(&seq.lock); */
31424 + return seq; /* success */
31427 + seq = ERR_PTR(-ENOMEM);
31431 +#define SysaufsBr_PREFIX "br"
31432 +#define SysaufsBrid_PREFIX "brid"
31434 +/* todo: file size may exceed PAGE_SIZE */
31435 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31441 + aufs_bindex_t bbot;
31442 + struct au_sbinfo *sbinfo;
31443 + struct super_block *sb;
31444 + struct seq_file *seq;
31446 + struct attribute **cattr;
31448 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31449 + sb = sbinfo->si_sb;
31452 + * prevent a race condition between sysfs and aufs.
31453 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31454 + * prohibits maintaining the sysfs entries.
31455 + * hew we acquire read lock after sysfs_get_active_two().
31456 + * on the other hand, the remount process may maintain the sysfs/aufs
31457 + * entries after acquiring write lock.
31458 + * it can cause a deadlock.
31459 + * simply we gave up processing read here.
31462 + if (unlikely(!si_noflush_read_trylock(sb)))
31465 + seq = au_seq(buf, PAGE_SIZE);
31466 + err = PTR_ERR(seq);
31470 + name = (void *)attr->name;
31471 + cattr = sysaufs_si_attrs;
31473 + if (!strcmp(name, (*cattr)->name)) {
31474 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31481 + if (!strncmp(name, SysaufsBrid_PREFIX,
31482 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31483 + idx = AuBrSysfs_BRID;
31484 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31485 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31486 + sizeof(SysaufsBr_PREFIX) - 1)) {
31487 + idx = AuBrSysfs_BR;
31488 + name += sizeof(SysaufsBr_PREFIX) - 1;
31492 + err = kstrtol(name, 10, &l);
31494 + bbot = au_sbbot(sb);
31496 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31503 + err = seq->count;
31504 + /* sysfs limit */
31505 + if (unlikely(err == PAGE_SIZE))
31510 + si_read_unlock(sb);
31515 +/* ---------------------------------------------------------------------- */
31517 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31521 + aufs_bindex_t bindex, bbot;
31524 + struct seq_file *seq;
31525 + struct au_branch *br;
31527 + si_read_lock(sb, AuLock_FLUSH);
31528 + bbot = au_sbbot(sb);
31534 + buf = (void *)__get_free_page(GFP_NOFS);
31535 + if (unlikely(!buf))
31538 + seq = au_seq(buf, PAGE_SIZE);
31539 + err = PTR_ERR(seq);
31543 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31544 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31545 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31546 + if (unlikely(err))
31549 + br = au_sbr(sb, bindex);
31550 + brid = br->br_id;
31551 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31552 + err = __put_user(brid, &arg->id);
31553 + if (unlikely(err))
31556 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31557 + err = __put_user(br->br_perm, &arg->perm);
31558 + if (unlikely(err))
31561 + err = au_seq_path(seq, &br->br_path);
31562 + if (unlikely(err))
31564 + seq_putc(seq, '\0');
31565 + if (!seq_has_overflowed(seq)) {
31566 + err = copy_to_user(arg->path, seq->buf, seq->count);
31568 + if (unlikely(err))
31575 + if (unlikely(err))
31581 + free_page((unsigned long)buf);
31583 + si_read_unlock(sb);
31587 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31589 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31592 +#ifdef CONFIG_COMPAT
31593 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31595 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31599 +/* ---------------------------------------------------------------------- */
31601 +void sysaufs_br_init(struct au_branch *br)
31604 + struct au_brsysfs *br_sysfs;
31605 + struct attribute *attr;
31607 + br_sysfs = br->br_sysfs;
31608 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31609 + attr = &br_sysfs->attr;
31610 + sysfs_attr_init(attr);
31611 + attr->name = br_sysfs->name;
31612 + attr->mode = 0444;
31617 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31619 + struct au_branch *br;
31620 + struct kobject *kobj;
31621 + struct au_brsysfs *br_sysfs;
31623 + aufs_bindex_t bbot;
31625 + if (!sysaufs_brs)
31628 + kobj = &au_sbi(sb)->si_kobj;
31629 + bbot = au_sbbot(sb);
31630 + for (; bindex <= bbot; bindex++) {
31631 + br = au_sbr(sb, bindex);
31632 + br_sysfs = br->br_sysfs;
31633 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31634 + sysfs_remove_file(kobj, &br_sysfs->attr);
31640 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31643 + aufs_bindex_t bbot;
31644 + struct kobject *kobj;
31645 + struct au_branch *br;
31646 + struct au_brsysfs *br_sysfs;
31648 + if (!sysaufs_brs)
31651 + kobj = &au_sbi(sb)->si_kobj;
31652 + bbot = au_sbbot(sb);
31653 + for (; bindex <= bbot; bindex++) {
31654 + br = au_sbr(sb, bindex);
31655 + br_sysfs = br->br_sysfs;
31656 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31657 + SysaufsBr_PREFIX "%d", bindex);
31658 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31659 + SysaufsBrid_PREFIX "%d", bindex);
31660 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31661 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31662 + if (unlikely(err))
31663 + pr_warn("failed %s under sysfs(%d)\n",
31664 + br_sysfs->name, err);
31669 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31670 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31671 +++ linux/fs/aufs/sysrq.c 2018-10-23 12:33:35.599375796 +0200
31673 +// SPDX-License-Identifier: GPL-2.0
31675 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31677 + * This program, aufs is free software; you can redistribute it and/or modify
31678 + * it under the terms of the GNU General Public License as published by
31679 + * the Free Software Foundation; either version 2 of the License, or
31680 + * (at your option) any later version.
31682 + * This program is distributed in the hope that it will be useful,
31683 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31684 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31685 + * GNU General Public License for more details.
31687 + * You should have received a copy of the GNU General Public License
31688 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31692 + * magic sysrq handler
31695 +/* #include <linux/sysrq.h> */
31696 +#include <linux/writeback.h>
31699 +/* ---------------------------------------------------------------------- */
31701 +static void sysrq_sb(struct super_block *sb)
31704 + struct au_sbinfo *sbinfo;
31705 + struct file *file;
31706 + struct hlist_bl_head *files;
31707 + struct hlist_bl_node *pos;
31708 + struct au_finfo *finfo;
31710 + plevel = au_plevel;
31711 + au_plevel = KERN_WARNING;
31713 + /* since we define pr_fmt, call printk directly */
31714 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31716 + sbinfo = au_sbi(sb);
31717 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31718 + pr("superblock\n");
31722 + pr("root dentry\n");
31723 + au_dpri_dentry(sb->s_root);
31724 + pr("root inode\n");
31725 + au_dpri_inode(d_inode(sb->s_root));
31730 + int err, i, j, ndentry;
31731 + struct au_dcsub_pages dpages;
31732 + struct au_dpage *dpage;
31734 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31735 + if (unlikely(err))
31737 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31739 + for (i = 0; i < dpages.ndpage; i++) {
31740 + dpage = dpages.dpages + i;
31741 + ndentry = dpage->ndentry;
31742 + for (j = 0; j < ndentry; j++)
31743 + au_dpri_dentry(dpage->dentries[j]);
31745 + au_dpages_free(&dpages);
31753 + pr("isolated inode\n");
31754 + spin_lock(&sb->s_inode_list_lock);
31755 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31756 + spin_lock(&i->i_lock);
31757 + if (1 || hlist_empty(&i->i_dentry))
31758 + au_dpri_inode(i);
31759 + spin_unlock(&i->i_lock);
31761 + spin_unlock(&sb->s_inode_list_lock);
31765 + files = &au_sbi(sb)->si_files;
31766 + hlist_bl_lock(files);
31767 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31770 + file = finfo->fi_file;
31771 + mode = file_inode(file)->i_mode;
31772 + if (!special_file(mode))
31773 + au_dpri_file(file);
31775 + hlist_bl_unlock(files);
31779 + au_plevel = plevel;
31782 +/* ---------------------------------------------------------------------- */
31784 +/* module parameter */
31785 +static char *aufs_sysrq_key = "a";
31786 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31787 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31789 +static void au_sysrq(int key __maybe_unused)
31791 + struct au_sbinfo *sbinfo;
31792 + struct hlist_bl_node *pos;
31795 + au_sbilist_lock();
31796 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31797 + sysrq_sb(sbinfo->si_sb);
31798 + au_sbilist_unlock();
31802 +static struct sysrq_key_op au_sysrq_op = {
31803 + .handler = au_sysrq,
31804 + .help_msg = "Aufs",
31805 + .action_msg = "Aufs",
31806 + .enable_mask = SYSRQ_ENABLE_DUMP
31809 +/* ---------------------------------------------------------------------- */
31811 +int __init au_sysrq_init(void)
31817 + key = *aufs_sysrq_key;
31818 + if ('a' <= key && key <= 'z')
31819 + err = register_sysrq_key(key, &au_sysrq_op);
31820 + if (unlikely(err))
31821 + pr_err("err %d, sysrq=%c\n", err, key);
31825 +void au_sysrq_fin(void)
31829 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31830 + if (unlikely(err))
31831 + pr_err("err %d (ignored)\n", err);
31833 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31834 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31835 +++ linux/fs/aufs/vdir.c 2018-10-23 12:33:35.599375796 +0200
31837 +// SPDX-License-Identifier: GPL-2.0
31839 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31841 + * This program, aufs is free software; you can redistribute it and/or modify
31842 + * it under the terms of the GNU General Public License as published by
31843 + * the Free Software Foundation; either version 2 of the License, or
31844 + * (at your option) any later version.
31846 + * This program is distributed in the hope that it will be useful,
31847 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31848 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31849 + * GNU General Public License for more details.
31851 + * You should have received a copy of the GNU General Public License
31852 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31856 + * virtual or vertical directory
31861 +static unsigned int calc_size(int nlen)
31863 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31866 +static int set_deblk_end(union au_vdir_deblk_p *p,
31867 + union au_vdir_deblk_p *deblk_end)
31869 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31870 + p->de->de_str.len = 0;
31874 + return -1; /* error */
31877 +/* returns true or false */
31878 +static int is_deblk_end(union au_vdir_deblk_p *p,
31879 + union au_vdir_deblk_p *deblk_end)
31881 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31882 + return !p->de->de_str.len;
31886 +static unsigned char *last_deblk(struct au_vdir *vdir)
31888 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31891 +/* ---------------------------------------------------------------------- */
31893 +/* estimate the appropriate size for name hash table */
31894 +unsigned int au_rdhash_est(loff_t sz)
31902 + if (sz < AUFS_RDHASH_DEF)
31903 + n = AUFS_RDHASH_DEF;
31904 + /* pr_info("n %u\n", n); */
31909 + * the allocated memory has to be freed by
31910 + * au_nhash_wh_free() or au_nhash_de_free().
31912 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31914 + struct hlist_head *head;
31918 + sz = sizeof(*nhash->nh_head) * num_hash;
31919 + head = kmalloc(sz, gfp);
31921 + nhash->nh_num = num_hash;
31922 + nhash->nh_head = head;
31923 + for (u = 0; u < num_hash; u++)
31924 + INIT_HLIST_HEAD(head++);
31925 + return 0; /* success */
31931 +static void nhash_count(struct hlist_head *head)
31935 + struct hlist_node *pos;
31938 + hlist_for_each(pos, head)
31940 + pr_info("%lu\n", n);
31944 +static void au_nhash_wh_do_free(struct hlist_head *head)
31946 + struct au_vdir_wh *pos;
31947 + struct hlist_node *node;
31949 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31953 +static void au_nhash_de_do_free(struct hlist_head *head)
31955 + struct au_vdir_dehstr *pos;
31956 + struct hlist_node *node;
31958 + hlist_for_each_entry_safe(pos, node, head, hash)
31959 + au_cache_free_vdir_dehstr(pos);
31962 +static void au_nhash_do_free(struct au_nhash *nhash,
31963 + void (*free)(struct hlist_head *head))
31966 + struct hlist_head *head;
31968 + n = nhash->nh_num;
31972 + head = nhash->nh_head;
31973 + while (n-- > 0) {
31974 + nhash_count(head);
31977 + kfree(nhash->nh_head);
31980 +void au_nhash_wh_free(struct au_nhash *whlist)
31982 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31985 +static void au_nhash_de_free(struct au_nhash *delist)
31987 + au_nhash_do_free(delist, au_nhash_de_do_free);
31990 +/* ---------------------------------------------------------------------- */
31992 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31996 + unsigned int u, n;
31997 + struct hlist_head *head;
31998 + struct au_vdir_wh *pos;
32001 + n = whlist->nh_num;
32002 + head = whlist->nh_head;
32003 + for (u = 0; u < n; u++, head++)
32004 + hlist_for_each_entry(pos, head, wh_hash)
32005 + if (pos->wh_bindex == btgt && ++num > limit)
32010 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32011 + unsigned char *name,
32012 + unsigned int len)
32015 + /* const unsigned int magic_bit = 12; */
32017 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32024 + /* v = hash_long(v, magic_bit); */
32025 + v %= nhash->nh_num;
32026 + return nhash->nh_head + v;
32029 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32032 + return str->len == nlen && !memcmp(str->name, name, nlen);
32035 +/* returns found or not */
32036 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32038 + struct hlist_head *head;
32039 + struct au_vdir_wh *pos;
32040 + struct au_vdir_destr *str;
32042 + head = au_name_hash(whlist, name, nlen);
32043 + hlist_for_each_entry(pos, head, wh_hash) {
32044 + str = &pos->wh_str;
32045 + AuDbg("%.*s\n", str->len, str->name);
32046 + if (au_nhash_test_name(str, name, nlen))
32052 +/* returns found(true) or not */
32053 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32055 + struct hlist_head *head;
32056 + struct au_vdir_dehstr *pos;
32057 + struct au_vdir_destr *str;
32059 + head = au_name_hash(delist, name, nlen);
32060 + hlist_for_each_entry(pos, head, hash) {
32062 + AuDbg("%.*s\n", str->len, str->name);
32063 + if (au_nhash_test_name(str, name, nlen))
32069 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32070 + unsigned char d_type)
32072 +#ifdef CONFIG_AUFS_SHWH
32073 + wh->wh_ino = ino;
32074 + wh->wh_type = d_type;
32078 +/* ---------------------------------------------------------------------- */
32080 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32081 + unsigned int d_type, aufs_bindex_t bindex,
32082 + unsigned char shwh)
32085 + struct au_vdir_destr *str;
32086 + struct au_vdir_wh *wh;
32088 + AuDbg("%.*s\n", nlen, name);
32089 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32092 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32093 + if (unlikely(!wh))
32097 + wh->wh_bindex = bindex;
32099 + au_shwh_init_wh(wh, ino, d_type);
32100 + str = &wh->wh_str;
32102 + memcpy(str->name, name, nlen);
32103 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32110 +static int append_deblk(struct au_vdir *vdir)
32113 + unsigned long ul;
32114 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32115 + union au_vdir_deblk_p p, deblk_end;
32116 + unsigned char **o;
32119 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32120 + GFP_NOFS, /*may_shrink*/0);
32121 + if (unlikely(!o))
32124 + vdir->vd_deblk = o;
32125 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32127 + ul = vdir->vd_nblk++;
32128 + vdir->vd_deblk[ul] = p.deblk;
32129 + vdir->vd_last.ul = ul;
32130 + vdir->vd_last.p.deblk = p.deblk;
32131 + deblk_end.deblk = p.deblk + deblk_sz;
32132 + err = set_deblk_end(&p, &deblk_end);
32139 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32140 + unsigned int d_type, struct au_nhash *delist)
32144 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32145 + union au_vdir_deblk_p p, *room, deblk_end;
32146 + struct au_vdir_dehstr *dehstr;
32148 + p.deblk = last_deblk(vdir);
32149 + deblk_end.deblk = p.deblk + deblk_sz;
32150 + room = &vdir->vd_last.p;
32151 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32152 + || !is_deblk_end(room, &deblk_end));
32154 + sz = calc_size(nlen);
32155 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32156 + err = append_deblk(vdir);
32157 + if (unlikely(err))
32160 + p.deblk = last_deblk(vdir);
32161 + deblk_end.deblk = p.deblk + deblk_sz;
32163 + AuDebugOn(room->deblk != p.deblk);
32167 + dehstr = au_cache_alloc_vdir_dehstr();
32168 + if (unlikely(!dehstr))
32171 + dehstr->str = &room->de->de_str;
32172 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32173 + room->de->de_ino = ino;
32174 + room->de->de_type = d_type;
32175 + room->de->de_str.len = nlen;
32176 + memcpy(room->de->de_str.name, name, nlen);
32179 + room->deblk += sz;
32180 + if (unlikely(set_deblk_end(room, &deblk_end)))
32181 + err = append_deblk(vdir);
32188 +/* ---------------------------------------------------------------------- */
32190 +void au_vdir_free(struct au_vdir *vdir)
32192 + unsigned char **deblk;
32194 + deblk = vdir->vd_deblk;
32195 + while (vdir->vd_nblk--)
32197 + kfree(vdir->vd_deblk);
32198 + au_cache_free_vdir(vdir);
32201 +static struct au_vdir *alloc_vdir(struct file *file)
32203 + struct au_vdir *vdir;
32204 + struct super_block *sb;
32207 + sb = file->f_path.dentry->d_sb;
32208 + SiMustAnyLock(sb);
32211 + vdir = au_cache_alloc_vdir();
32212 + if (unlikely(!vdir))
32215 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32216 + if (unlikely(!vdir->vd_deblk))
32219 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32220 + if (!vdir->vd_deblk_sz) {
32221 + /* estimate the appropriate size for deblk */
32222 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32223 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32225 + vdir->vd_nblk = 0;
32226 + vdir->vd_version = 0;
32227 + vdir->vd_jiffy = 0;
32228 + err = append_deblk(vdir);
32230 + return vdir; /* success */
32232 + kfree(vdir->vd_deblk);
32235 + au_cache_free_vdir(vdir);
32237 + vdir = ERR_PTR(err);
32241 +static int reinit_vdir(struct au_vdir *vdir)
32244 + union au_vdir_deblk_p p, deblk_end;
32246 + while (vdir->vd_nblk > 1) {
32247 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
32248 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32251 + p.deblk = vdir->vd_deblk[0];
32252 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32253 + err = set_deblk_end(&p, &deblk_end);
32254 + /* keep vd_dblk_sz */
32255 + vdir->vd_last.ul = 0;
32256 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32257 + vdir->vd_version = 0;
32258 + vdir->vd_jiffy = 0;
32263 +/* ---------------------------------------------------------------------- */
32265 +#define AuFillVdir_CALLED 1
32266 +#define AuFillVdir_WHABLE (1 << 1)
32267 +#define AuFillVdir_SHWH (1 << 2)
32268 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32269 +#define au_fset_fillvdir(flags, name) \
32270 + do { (flags) |= AuFillVdir_##name; } while (0)
32271 +#define au_fclr_fillvdir(flags, name) \
32272 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32274 +#ifndef CONFIG_AUFS_SHWH
32275 +#undef AuFillVdir_SHWH
32276 +#define AuFillVdir_SHWH 0
32279 +struct fillvdir_arg {
32280 + struct dir_context ctx;
32281 + struct file *file;
32282 + struct au_vdir *vdir;
32283 + struct au_nhash delist;
32284 + struct au_nhash whlist;
32285 + aufs_bindex_t bindex;
32286 + unsigned int flags;
32290 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32291 + loff_t offset __maybe_unused, u64 h_ino,
32292 + unsigned int d_type)
32294 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32295 + char *name = (void *)__name;
32296 + struct super_block *sb;
32298 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32301 + sb = arg->file->f_path.dentry->d_sb;
32302 + au_fset_fillvdir(arg->flags, CALLED);
32304 + if (nlen <= AUFS_WH_PFX_LEN
32305 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32306 + if (test_known(&arg->delist, name, nlen)
32307 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32308 + goto out; /* already exists or whiteouted */
32310 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32312 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32313 + d_type = DT_UNKNOWN;
32314 + arg->err = append_de(arg->vdir, name, nlen, ino,
32315 + d_type, &arg->delist);
32317 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32318 + name += AUFS_WH_PFX_LEN;
32319 + nlen -= AUFS_WH_PFX_LEN;
32320 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32321 + goto out; /* already whiteouted */
32323 + ino = 0; /* just to suppress a warning */
32325 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32328 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32329 + d_type = DT_UNKNOWN;
32330 + arg->err = au_nhash_append_wh
32331 + (&arg->whlist, name, nlen, ino, d_type,
32332 + arg->bindex, shwh);
32338 + arg->vdir->vd_jiffy = jiffies;
32340 + AuTraceErr(arg->err);
32344 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32345 + struct au_nhash *whlist, struct au_nhash *delist)
32347 +#ifdef CONFIG_AUFS_SHWH
32349 + unsigned int nh, u;
32350 + struct hlist_head *head;
32351 + struct au_vdir_wh *pos;
32352 + struct hlist_node *n;
32354 + struct au_vdir_destr *destr;
32356 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32359 + o = p = (void *)__get_free_page(GFP_NOFS);
32360 + if (unlikely(!p))
32364 + nh = whlist->nh_num;
32365 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32366 + p += AUFS_WH_PFX_LEN;
32367 + for (u = 0; u < nh; u++) {
32368 + head = whlist->nh_head + u;
32369 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32370 + destr = &pos->wh_str;
32371 + memcpy(p, destr->name, destr->len);
32372 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32373 + pos->wh_ino, pos->wh_type, delist);
32374 + if (unlikely(err))
32379 + free_page((unsigned long)o);
32389 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32392 + unsigned int rdhash;
32394 + aufs_bindex_t bbot, bindex, btop;
32395 + unsigned char shwh;
32396 + struct file *hf, *file;
32397 + struct super_block *sb;
32399 + file = arg->file;
32400 + sb = file->f_path.dentry->d_sb;
32401 + SiMustAnyLock(sb);
32403 + rdhash = au_sbi(sb)->si_rdhash;
32405 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32406 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32407 + if (unlikely(err))
32409 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32410 + if (unlikely(err))
32416 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32418 + au_fset_fillvdir(arg->flags, SHWH);
32420 + btop = au_fbtop(file);
32421 + bbot = au_fbbot_dir(file);
32422 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32423 + hf = au_hf_dir(file, bindex);
32427 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32429 + if (unlikely(offset))
32432 + arg->bindex = bindex;
32433 + au_fclr_fillvdir(arg->flags, WHABLE);
32435 + || (bindex != bbot
32436 + && au_br_whable(au_sbr_perm(sb, bindex))))
32437 + au_fset_fillvdir(arg->flags, WHABLE);
32440 + au_fclr_fillvdir(arg->flags, CALLED);
32442 + err = vfsub_iterate_dir(hf, &arg->ctx);
32445 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32448 + * dir_relax() may be good for concurrency, but aufs should not
32449 + * use it since it will cause a lockdep problem.
32453 + if (!err && shwh)
32454 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32456 + au_nhash_wh_free(&arg->whlist);
32459 + au_nhash_de_free(&arg->delist);
32464 +static int read_vdir(struct file *file, int may_read)
32467 + unsigned long expire;
32468 + unsigned char do_read;
32469 + struct fillvdir_arg arg = {
32471 + .actor = fillvdir
32474 + struct inode *inode;
32475 + struct au_vdir *vdir, *allocated;
32478 + inode = file_inode(file);
32479 + IMustLock(inode);
32480 + IiMustWriteLock(inode);
32481 + SiMustAnyLock(inode->i_sb);
32483 + allocated = NULL;
32485 + expire = au_sbi(inode->i_sb)->si_rdcache;
32486 + vdir = au_ivdir(inode);
32489 + vdir = alloc_vdir(file);
32490 + err = PTR_ERR(vdir);
32491 + if (IS_ERR(vdir))
32494 + allocated = vdir;
32495 + } else if (may_read
32496 + && (!inode_eq_iversion(inode, vdir->vd_version)
32497 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32499 + err = reinit_vdir(vdir);
32500 + if (unlikely(err))
32505 + return 0; /* success */
32509 + err = au_do_read_vdir(&arg);
32511 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32512 + vdir->vd_version = inode_query_iversion(inode);
32513 + vdir->vd_last.ul = 0;
32514 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32516 + au_set_ivdir(inode, allocated);
32517 + } else if (allocated)
32518 + au_vdir_free(allocated);
32524 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32527 + unsigned long ul, n;
32528 + const unsigned int deblk_sz = src->vd_deblk_sz;
32530 + AuDebugOn(tgt->vd_nblk != 1);
32533 + if (tgt->vd_nblk < src->vd_nblk) {
32534 + unsigned char **p;
32536 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32537 + GFP_NOFS, /*may_shrink*/0);
32538 + if (unlikely(!p))
32540 + tgt->vd_deblk = p;
32543 + if (tgt->vd_deblk_sz != deblk_sz) {
32544 + unsigned char *p;
32546 + tgt->vd_deblk_sz = deblk_sz;
32547 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32548 + /*may_shrink*/1);
32549 + if (unlikely(!p))
32551 + tgt->vd_deblk[0] = p;
32553 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32554 + tgt->vd_version = src->vd_version;
32555 + tgt->vd_jiffy = src->vd_jiffy;
32557 + n = src->vd_nblk;
32558 + for (ul = 1; ul < n; ul++) {
32559 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32561 + if (unlikely(!tgt->vd_deblk[ul]))
32565 + tgt->vd_nblk = n;
32566 + tgt->vd_last.ul = tgt->vd_last.ul;
32567 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32568 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32569 + - src->vd_deblk[src->vd_last.ul];
32571 + return 0; /* success */
32574 + rerr = reinit_vdir(tgt);
32579 +int au_vdir_init(struct file *file)
32582 + struct inode *inode;
32583 + struct au_vdir *vdir_cache, *allocated;
32585 + /* test file->f_pos here instead of ctx->pos */
32586 + err = read_vdir(file, !file->f_pos);
32587 + if (unlikely(err))
32590 + allocated = NULL;
32591 + vdir_cache = au_fvdir_cache(file);
32592 + if (!vdir_cache) {
32593 + vdir_cache = alloc_vdir(file);
32594 + err = PTR_ERR(vdir_cache);
32595 + if (IS_ERR(vdir_cache))
32597 + allocated = vdir_cache;
32598 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32599 + /* test file->f_pos here instead of ctx->pos */
32600 + err = reinit_vdir(vdir_cache);
32601 + if (unlikely(err))
32604 + return 0; /* success */
32606 + inode = file_inode(file);
32607 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32609 + file->f_version = inode_query_iversion(inode);
32611 + au_set_fvdir_cache(file, allocated);
32612 + } else if (allocated)
32613 + au_vdir_free(allocated);
32619 +static loff_t calc_offset(struct au_vdir *vdir)
32622 + union au_vdir_deblk_p p;
32624 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32625 + offset = vdir->vd_last.p.deblk - p.deblk;
32626 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32630 +/* returns true or false */
32631 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32634 + unsigned int deblk_sz;
32635 + unsigned long ul, n;
32637 + union au_vdir_deblk_p p, deblk_end;
32638 + struct au_vdir *vdir_cache;
32641 + vdir_cache = au_fvdir_cache(file);
32642 + offset = calc_offset(vdir_cache);
32643 + AuDbg("offset %lld\n", offset);
32644 + if (ctx->pos == offset)
32647 + vdir_cache->vd_last.ul = 0;
32648 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32653 + deblk_sz = vdir_cache->vd_deblk_sz;
32654 + ul = div64_u64(ctx->pos, deblk_sz);
32655 + AuDbg("ul %lu\n", ul);
32656 + if (ul >= vdir_cache->vd_nblk)
32659 + n = vdir_cache->vd_nblk;
32660 + for (; ul < n; ul++) {
32661 + p.deblk = vdir_cache->vd_deblk[ul];
32662 + deblk_end.deblk = p.deblk + deblk_sz;
32664 + offset *= deblk_sz;
32665 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32668 + l = calc_size(p.de->de_str.len);
32672 + if (!is_deblk_end(&p, &deblk_end)) {
32674 + vdir_cache->vd_last.ul = ul;
32675 + vdir_cache->vd_last.p = p;
32683 + AuDbg("valid %d\n", !valid);
32687 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32689 + unsigned int l, deblk_sz;
32690 + union au_vdir_deblk_p deblk_end;
32691 + struct au_vdir *vdir_cache;
32692 + struct au_vdir_de *de;
32694 + if (!seek_vdir(file, ctx))
32697 + vdir_cache = au_fvdir_cache(file);
32698 + deblk_sz = vdir_cache->vd_deblk_sz;
32700 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32701 + deblk_end.deblk += deblk_sz;
32702 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32703 + de = vdir_cache->vd_last.p.de;
32704 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32705 + de->de_str.len, de->de_str.name, ctx->pos,
32706 + (unsigned long)de->de_ino, de->de_type);
32707 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32708 + de->de_str.len, de->de_ino,
32710 + /* todo: ignore the error caused by udba? */
32711 + /* return err; */
32715 + l = calc_size(de->de_str.len);
32716 + vdir_cache->vd_last.p.deblk += l;
32719 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32720 + vdir_cache->vd_last.ul++;
32721 + vdir_cache->vd_last.p.deblk
32722 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32723 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32732 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32733 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32734 +++ linux/fs/aufs/vfsub.c 2018-10-23 12:33:35.599375796 +0200
32736 +// SPDX-License-Identifier: GPL-2.0
32738 + * Copyright (C) 2005-2018 Junjiro R. Okajima
32740 + * This program, aufs is free software; you can redistribute it and/or modify
32741 + * it under the terms of the GNU General Public License as published by
32742 + * the Free Software Foundation; either version 2 of the License, or
32743 + * (at your option) any later version.
32745 + * This program is distributed in the hope that it will be useful,
32746 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32747 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32748 + * GNU General Public License for more details.
32750 + * You should have received a copy of the GNU General Public License
32751 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32755 + * sub-routines for VFS
32758 +#include <linux/mnt_namespace.h>
32759 +#include <linux/namei.h>
32760 +#include <linux/nsproxy.h>
32761 +#include <linux/security.h>
32762 +#include <linux/splice.h>
32765 +#ifdef CONFIG_AUFS_BR_FUSE
32766 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32768 + if (!au_test_fuse(h_sb) || !au_userns)
32771 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32775 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32780 + down_read(&h_sb->s_umount);
32781 + err = __sync_filesystem(h_sb, wait);
32782 + up_read(&h_sb->s_umount);
32788 +/* ---------------------------------------------------------------------- */
32790 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32794 + struct super_block *h_sb;
32796 + /* for remote fs, leave work for its getattr or d_revalidate */
32797 + /* for bad i_attr fs, handle them in aufs_getattr() */
32798 + /* still some fs may acquire i_mutex. we need to skip them */
32802 + h_sb = h_path->dentry->d_sb;
32803 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32805 + err = vfsub_getattr(h_path, &st);
32810 +/* ---------------------------------------------------------------------- */
32812 +struct file *vfsub_dentry_open(struct path *path, int flags)
32814 + struct file *file;
32816 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32818 + if (!IS_ERR_OR_NULL(file)
32819 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32820 + i_readcount_inc(d_inode(path->dentry));
32825 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32827 + struct file *file;
32830 + file = filp_open(path,
32831 + oflags /* | __FMODE_NONOTIFY */,
32834 + if (IS_ERR(file))
32836 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32843 + * Ideally this function should call VFS:do_last() in order to keep all its
32844 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32845 + * structure such as nameidata. This is a second (or third) best approach.
32846 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32848 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32849 + struct vfsub_aopen_args *args)
32852 + struct au_branch *br = args->br;
32853 + struct file *file = args->file;
32854 + /* copied from linux/fs/namei.c:atomic_open() */
32855 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32858 + AuDebugOn(!dir->i_op->atomic_open);
32860 + err = au_br_test_oflag(args->open_flag, br);
32861 + if (unlikely(err))
32864 + au_lcnt_inc(&br->br_nfiles);
32865 + file->f_path.dentry = DENTRY_NOT_SET;
32866 + file->f_path.mnt = au_br_mnt(br);
32867 + AuDbg("%ps\n", dir->i_op->atomic_open);
32868 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32869 + args->create_mode);
32870 + if (unlikely(err < 0)) {
32871 + au_lcnt_dec(&br->br_nfiles);
32875 + /* temporary workaround for nfsv4 branch */
32876 + if (au_test_nfs(dir->i_sb))
32877 + nfs_mark_for_revalidate(dir);
32879 + if (file->f_mode & FMODE_CREATED)
32880 + fsnotify_create(dir, dentry);
32881 + if (!(file->f_mode & FMODE_OPENED)) {
32882 + au_lcnt_dec(&br->br_nfiles);
32886 + /* todo: call VFS:may_open() here */
32887 + /* todo: ima_file_check() too? */
32888 + if (!err && (args->open_flag & __FMODE_EXEC))
32889 + err = deny_write_access(file);
32891 + fsnotify_open(file);
32893 + au_lcnt_dec(&br->br_nfiles);
32894 + /* note that the file is created and still opened */
32900 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32904 + err = kern_path(name, flags, path);
32905 + if (!err && d_is_positive(path->dentry))
32906 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32910 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32911 + struct dentry *parent, int len)
32913 + struct path path = {
32917 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32918 + if (IS_ERR(path.dentry))
32920 + if (d_is_positive(path.dentry))
32921 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32924 + AuTraceErrPtr(path.dentry);
32925 + return path.dentry;
32928 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32931 + struct path path = {
32935 + /* VFS checks it too, but by WARN_ON_ONCE() */
32936 + IMustLock(d_inode(parent));
32938 + path.dentry = lookup_one_len(name, parent, len);
32939 + if (IS_ERR(path.dentry))
32941 + if (d_is_positive(path.dentry))
32942 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32945 + AuTraceErrPtr(path.dentry);
32946 + return path.dentry;
32949 +void vfsub_call_lkup_one(void *args)
32951 + struct vfsub_lkup_one_args *a = args;
32952 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32955 +/* ---------------------------------------------------------------------- */
32957 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32958 + struct dentry *d2, struct au_hinode *hdir2)
32960 + struct dentry *d;
32963 + d = lock_rename(d1, d2);
32965 + au_hn_suspend(hdir1);
32966 + if (hdir1 != hdir2)
32967 + au_hn_suspend(hdir2);
32972 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32973 + struct dentry *d2, struct au_hinode *hdir2)
32975 + au_hn_resume(hdir1);
32976 + if (hdir1 != hdir2)
32977 + au_hn_resume(hdir2);
32979 + unlock_rename(d1, d2);
32983 +/* ---------------------------------------------------------------------- */
32985 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32988 + struct dentry *d;
32992 + d = path->dentry;
32993 + path->dentry = d->d_parent;
32994 + err = security_path_mknod(path, d, mode, 0);
32995 + path->dentry = d;
32996 + if (unlikely(err))
33000 + err = vfs_create(dir, path->dentry, mode, want_excl);
33003 + struct path tmp = *path;
33006 + vfsub_update_h_iattr(&tmp, &did);
33008 + tmp.dentry = path->dentry->d_parent;
33009 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33018 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33021 + struct dentry *d;
33025 + d = path->dentry;
33026 + path->dentry = d->d_parent;
33027 + err = security_path_symlink(path, d, symname);
33028 + path->dentry = d;
33029 + if (unlikely(err))
33033 + err = vfs_symlink(dir, path->dentry, symname);
33036 + struct path tmp = *path;
33039 + vfsub_update_h_iattr(&tmp, &did);
33041 + tmp.dentry = path->dentry->d_parent;
33042 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33051 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33054 + struct dentry *d;
33058 + d = path->dentry;
33059 + path->dentry = d->d_parent;
33060 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33061 + path->dentry = d;
33062 + if (unlikely(err))
33066 + err = vfs_mknod(dir, path->dentry, mode, dev);
33069 + struct path tmp = *path;
33072 + vfsub_update_h_iattr(&tmp, &did);
33074 + tmp.dentry = path->dentry->d_parent;
33075 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33084 +static int au_test_nlink(struct inode *inode)
33086 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33088 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33089 + || inode->i_nlink < link_max)
33094 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33095 + struct inode **delegated_inode)
33098 + struct dentry *d;
33102 + err = au_test_nlink(d_inode(src_dentry));
33103 + if (unlikely(err))
33106 + /* we don't call may_linkat() */
33107 + d = path->dentry;
33108 + path->dentry = d->d_parent;
33109 + err = security_path_link(src_dentry, path, d);
33110 + path->dentry = d;
33111 + if (unlikely(err))
33115 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33118 + struct path tmp = *path;
33121 + /* fuse has different memory inode for the same inumber */
33122 + vfsub_update_h_iattr(&tmp, &did);
33124 + tmp.dentry = path->dentry->d_parent;
33125 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33126 + tmp.dentry = src_dentry;
33127 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33136 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33137 + struct inode *dir, struct path *path,
33138 + struct inode **delegated_inode, unsigned int flags)
33141 + struct path tmp = {
33144 + struct dentry *d;
33147 + IMustLock(src_dir);
33149 + d = path->dentry;
33150 + path->dentry = d->d_parent;
33151 + tmp.dentry = src_dentry->d_parent;
33152 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33153 + path->dentry = d;
33154 + if (unlikely(err))
33158 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33159 + delegated_inode, flags);
33164 + tmp.dentry = d->d_parent;
33165 + vfsub_update_h_iattr(&tmp, &did);
33167 + tmp.dentry = src_dentry;
33168 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33169 + tmp.dentry = src_dentry->d_parent;
33170 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33179 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33182 + struct dentry *d;
33186 + d = path->dentry;
33187 + path->dentry = d->d_parent;
33188 + err = security_path_mkdir(path, d, mode);
33189 + path->dentry = d;
33190 + if (unlikely(err))
33194 + err = vfs_mkdir(dir, path->dentry, mode);
33197 + struct path tmp = *path;
33200 + vfsub_update_h_iattr(&tmp, &did);
33202 + tmp.dentry = path->dentry->d_parent;
33203 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33212 +int vfsub_rmdir(struct inode *dir, struct path *path)
33215 + struct dentry *d;
33219 + d = path->dentry;
33220 + path->dentry = d->d_parent;
33221 + err = security_path_rmdir(path, d);
33222 + path->dentry = d;
33223 + if (unlikely(err))
33227 + err = vfs_rmdir(dir, path->dentry);
33230 + struct path tmp = {
33231 + .dentry = path->dentry->d_parent,
33235 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33242 +/* ---------------------------------------------------------------------- */
33244 +/* todo: support mmap_sem? */
33245 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33251 + err = vfs_read(file, ubuf, count, ppos);
33254 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33258 +/* todo: kernel_read()? */
33259 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33263 + mm_segment_t oldfs;
33270 + oldfs = get_fs();
33271 + set_fs(KERNEL_DS);
33272 + err = vfsub_read_u(file, buf.u, count, ppos);
33277 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33283 + err = vfs_write(file, ubuf, count, ppos);
33286 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33290 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33293 + mm_segment_t oldfs;
33296 + const char __user *u;
33300 + oldfs = get_fs();
33301 + set_fs(KERNEL_DS);
33302 + err = vfsub_write_u(file, buf.u, count, ppos);
33307 +int vfsub_flush(struct file *file, fl_owner_t id)
33312 + if (file->f_op->flush) {
33313 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33314 + err = file->f_op->flush(file, id);
33317 + err = file->f_op->flush(file, id);
33321 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33327 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33331 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33334 + err = iterate_dir(file, ctx);
33337 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33342 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33343 + struct pipe_inode_info *pipe, size_t len,
33344 + unsigned int flags)
33349 + err = do_splice_to(in, ppos, pipe, len, flags);
33351 + file_accessed(in);
33353 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33357 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33358 + loff_t *ppos, size_t len, unsigned int flags)
33363 + err = do_splice_from(pipe, out, ppos, len, flags);
33366 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33370 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33374 + /* file can be NULL */
33376 + err = vfs_fsync(file, datasync);
33380 + AuDebugOn(!file);
33381 + path = &file->f_path;
33383 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33388 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33389 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33390 + struct file *h_file)
33393 + struct inode *h_inode;
33394 + struct super_block *h_sb;
33397 + err = vfsub_truncate(h_path, length);
33401 + h_inode = d_inode(h_path->dentry);
33402 + h_sb = h_inode->i_sb;
33404 + sb_start_write(h_sb);
33406 + err = locks_verify_truncate(h_inode, h_file, length);
33408 + err = security_path_truncate(h_path);
33411 + err = do_truncate(h_path->dentry, length, attr, h_file);
33415 + sb_end_write(h_sb);
33422 +/* ---------------------------------------------------------------------- */
33424 +struct au_vfsub_mkdir_args {
33426 + struct inode *dir;
33427 + struct path *path;
33431 +static void au_call_vfsub_mkdir(void *args)
33433 + struct au_vfsub_mkdir_args *a = args;
33434 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33437 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33439 + int err, do_sio, wkq_err;
33441 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33444 + err = vfsub_mkdir(dir, path, mode);
33447 + struct au_vfsub_mkdir_args args = {
33453 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33454 + if (unlikely(wkq_err))
33461 +struct au_vfsub_rmdir_args {
33463 + struct inode *dir;
33464 + struct path *path;
33467 +static void au_call_vfsub_rmdir(void *args)
33469 + struct au_vfsub_rmdir_args *a = args;
33470 + *a->errp = vfsub_rmdir(a->dir, a->path);
33473 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33475 + int err, do_sio, wkq_err;
33477 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33480 + err = vfsub_rmdir(dir, path);
33483 + struct au_vfsub_rmdir_args args = {
33488 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33489 + if (unlikely(wkq_err))
33496 +/* ---------------------------------------------------------------------- */
33498 +struct notify_change_args {
33500 + struct path *path;
33501 + struct iattr *ia;
33502 + struct inode **delegated_inode;
33505 +static void call_notify_change(void *args)
33507 + struct notify_change_args *a = args;
33508 + struct inode *h_inode;
33510 + h_inode = d_inode(a->path->dentry);
33511 + IMustLock(h_inode);
33513 + *a->errp = -EPERM;
33514 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33516 + *a->errp = notify_change(a->path->dentry, a->ia,
33517 + a->delegated_inode);
33520 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33522 + AuTraceErr(*a->errp);
33525 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33526 + struct inode **delegated_inode)
33529 + struct notify_change_args args = {
33533 + .delegated_inode = delegated_inode
33536 + call_notify_change(&args);
33541 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33542 + struct inode **delegated_inode)
33544 + int err, wkq_err;
33545 + struct notify_change_args args = {
33549 + .delegated_inode = delegated_inode
33552 + wkq_err = au_wkq_wait(call_notify_change, &args);
33553 + if (unlikely(wkq_err))
33559 +/* ---------------------------------------------------------------------- */
33561 +struct unlink_args {
33563 + struct inode *dir;
33564 + struct path *path;
33565 + struct inode **delegated_inode;
33568 +static void call_unlink(void *args)
33570 + struct unlink_args *a = args;
33571 + struct dentry *d = a->path->dentry;
33572 + struct inode *h_inode;
33573 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33574 + && au_dcount(d) == 1);
33576 + IMustLock(a->dir);
33578 + a->path->dentry = d->d_parent;
33579 + *a->errp = security_path_unlink(a->path, d);
33580 + a->path->dentry = d;
33581 + if (unlikely(*a->errp))
33584 + if (!stop_sillyrename)
33587 + if (d_is_positive(d)) {
33588 + h_inode = d_inode(d);
33593 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33596 + struct path tmp = {
33597 + .dentry = d->d_parent,
33598 + .mnt = a->path->mnt
33600 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33603 + if (!stop_sillyrename)
33608 + AuTraceErr(*a->errp);
33612 + * @dir: must be locked.
33613 + * @dentry: target dentry.
33615 +int vfsub_unlink(struct inode *dir, struct path *path,
33616 + struct inode **delegated_inode, int force)
33619 + struct unlink_args args = {
33623 + .delegated_inode = delegated_inode
33627 + call_unlink(&args);
33631 + wkq_err = au_wkq_wait(call_unlink, &args);
33632 + if (unlikely(wkq_err))
33638 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33639 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33640 +++ linux/fs/aufs/vfsub.h 2018-10-23 12:33:35.599375796 +0200
33642 +/* SPDX-License-Identifier: GPL-2.0 */
33644 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33646 + * This program, aufs is free software; you can redistribute it and/or modify
33647 + * it under the terms of the GNU General Public License as published by
33648 + * the Free Software Foundation; either version 2 of the License, or
33649 + * (at your option) any later version.
33651 + * This program is distributed in the hope that it will be useful,
33652 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33653 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33654 + * GNU General Public License for more details.
33656 + * You should have received a copy of the GNU General Public License
33657 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33661 + * sub-routines for VFS
33664 +#ifndef __AUFS_VFSUB_H__
33665 +#define __AUFS_VFSUB_H__
33669 +#include <linux/fs.h>
33670 +#include <linux/iversion.h>
33671 +#include <linux/mount.h>
33672 +#include <linux/posix_acl.h>
33673 +#include <linux/xattr.h>
33674 +#include "debug.h"
33676 +/* copied from linux/fs/internal.h */
33677 +/* todo: BAD approach!! */
33678 +extern void __mnt_drop_write(struct vfsmount *);
33679 +extern struct file *alloc_empty_file(int, const struct cred *);
33681 +/* ---------------------------------------------------------------------- */
33683 +/* lock subclass for lower inode */
33684 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33685 +/* reduce? gave up. */
33687 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33688 + AuLsc_I_PARENT, /* lower inode, parent first */
33689 + AuLsc_I_PARENT2, /* copyup dirs */
33690 + AuLsc_I_PARENT3, /* copyup wh */
33696 +/* to debug easier, do not make them inlined functions */
33697 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33698 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33700 +/* ---------------------------------------------------------------------- */
33702 +static inline void vfsub_drop_nlink(struct inode *inode)
33704 + AuDebugOn(!inode->i_nlink);
33705 + drop_nlink(inode);
33708 +static inline void vfsub_dead_dir(struct inode *inode)
33710 + AuDebugOn(!S_ISDIR(inode->i_mode));
33711 + inode->i_flags |= S_DEAD;
33712 + clear_nlink(inode);
33715 +static inline int vfsub_native_ro(struct inode *inode)
33717 + return sb_rdonly(inode->i_sb)
33718 + || IS_RDONLY(inode)
33719 + /* || IS_APPEND(inode) */
33720 + || IS_IMMUTABLE(inode);
33723 +#ifdef CONFIG_AUFS_BR_FUSE
33724 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33726 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33729 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33731 +/* ---------------------------------------------------------------------- */
33733 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33734 +struct file *vfsub_dentry_open(struct path *path, int flags);
33735 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33737 +struct vfsub_aopen_args {
33738 + struct file *file;
33739 + unsigned int open_flag;
33740 + umode_t create_mode;
33741 + struct au_branch *br;
33743 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33744 + struct vfsub_aopen_args *args);
33745 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33747 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33748 + struct dentry *parent, int len);
33749 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33752 +struct vfsub_lkup_one_args {
33753 + struct dentry **errp;
33754 + struct qstr *name;
33755 + struct dentry *parent;
33758 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33759 + struct dentry *parent)
33761 + return vfsub_lookup_one_len(name->name, parent, name->len);
33764 +void vfsub_call_lkup_one(void *args);
33766 +/* ---------------------------------------------------------------------- */
33768 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33773 + err = mnt_want_write(mnt);
33778 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33781 + mnt_drop_write(mnt);
33785 +#if 0 /* reserved */
33786 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33789 + mnt_drop_write_file(file);
33794 +/* ---------------------------------------------------------------------- */
33797 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33798 + struct dentry *d2, struct au_hinode *hdir2);
33799 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33800 + struct dentry *d2, struct au_hinode *hdir2);
33802 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33804 +int vfsub_symlink(struct inode *dir, struct path *path,
33805 + const char *symname);
33806 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33807 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33808 + struct path *path, struct inode **delegated_inode);
33809 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33810 + struct inode *hdir, struct path *path,
33811 + struct inode **delegated_inode, unsigned int flags);
33812 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33813 +int vfsub_rmdir(struct inode *dir, struct path *path);
33815 +/* ---------------------------------------------------------------------- */
33817 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33819 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33821 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33823 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33825 +int vfsub_flush(struct file *file, fl_owner_t id);
33826 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33828 +static inline loff_t vfsub_f_size_read(struct file *file)
33830 + return i_size_read(file_inode(file));
33833 +static inline unsigned int vfsub_file_flags(struct file *file)
33835 + unsigned int flags;
33837 + spin_lock(&file->f_lock);
33838 + flags = file->f_flags;
33839 + spin_unlock(&file->f_lock);
33844 +static inline int vfsub_file_execed(struct file *file)
33846 + /* todo: direct access f_flags */
33847 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33850 +#if 0 /* reserved */
33851 +static inline void vfsub_file_accessed(struct file *h_file)
33853 + file_accessed(h_file);
33854 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33858 +#if 0 /* reserved */
33859 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33860 + struct dentry *h_dentry)
33862 + struct path h_path = {
33863 + .dentry = h_dentry,
33866 + touch_atime(&h_path);
33867 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33871 +static inline int vfsub_update_time(struct inode *h_inode,
33872 + struct timespec64 *ts, int flags)
33874 + return update_time(h_inode, ts, flags);
33875 + /* no vfsub_update_h_iattr() since we don't have struct path */
33878 +#ifdef CONFIG_FS_POSIX_ACL
33879 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33883 + err = posix_acl_chmod(h_inode, h_mode);
33884 + if (err == -EOPNOTSUPP)
33889 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33892 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33893 + struct pipe_inode_info *pipe, size_t len,
33894 + unsigned int flags);
33895 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33896 + loff_t *ppos, size_t len, unsigned int flags);
33898 +static inline long vfsub_truncate(struct path *path, loff_t length)
33903 + err = vfs_truncate(path, length);
33908 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33909 + struct file *h_file);
33910 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33913 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33916 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
33922 + err = vfs_clone_file_range(src, 0, dst, 0, len);
33928 +/* copy_file_range(2) is a systemcall */
33929 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33930 + struct file *dst, loff_t dst_pos,
33931 + size_t len, unsigned int flags)
33936 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33942 +/* ---------------------------------------------------------------------- */
33944 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33949 + err = vfs_llseek(file, offset, origin);
33954 +/* ---------------------------------------------------------------------- */
33956 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33957 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33958 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33959 + struct inode **delegated_inode);
33960 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33961 + struct inode **delegated_inode);
33962 +int vfsub_unlink(struct inode *dir, struct path *path,
33963 + struct inode **delegated_inode, int force);
33965 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33967 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33970 +/* ---------------------------------------------------------------------- */
33972 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33973 + const void *value, size_t size, int flags)
33978 + err = vfs_setxattr(dentry, name, value, size, flags);
33984 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33989 + err = vfs_removexattr(dentry, name);
33995 +#endif /* __KERNEL__ */
33996 +#endif /* __AUFS_VFSUB_H__ */
33997 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33998 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33999 +++ linux/fs/aufs/wbr_policy.c 2018-08-12 23:43:05.463458173 +0200
34001 +// SPDX-License-Identifier: GPL-2.0
34003 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34005 + * This program, aufs is free software; you can redistribute it and/or modify
34006 + * it under the terms of the GNU General Public License as published by
34007 + * the Free Software Foundation; either version 2 of the License, or
34008 + * (at your option) any later version.
34010 + * This program is distributed in the hope that it will be useful,
34011 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34012 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34013 + * GNU General Public License for more details.
34015 + * You should have received a copy of the GNU General Public License
34016 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34020 + * policies for selecting one among multiple writable branches
34023 +#include <linux/statfs.h>
34026 +/* subset of cpup_attr() */
34027 +static noinline_for_stack
34028 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34032 + struct inode *h_isrc;
34034 + h_isrc = d_inode(h_src);
34035 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34036 + ia.ia_mode = h_isrc->i_mode;
34037 + ia.ia_uid = h_isrc->i_uid;
34038 + ia.ia_gid = h_isrc->i_gid;
34039 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34040 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34041 + /* no delegation since it is just created */
34042 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34044 + /* is this nfs only? */
34045 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34046 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34047 + ia.ia_mode = h_isrc->i_mode;
34048 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34054 +#define AuCpdown_PARENT_OPQ 1
34055 +#define AuCpdown_WHED (1 << 1)
34056 +#define AuCpdown_MADE_DIR (1 << 2)
34057 +#define AuCpdown_DIROPQ (1 << 3)
34058 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34059 +#define au_fset_cpdown(flags, name) \
34060 + do { (flags) |= AuCpdown_##name; } while (0)
34061 +#define au_fclr_cpdown(flags, name) \
34062 + do { (flags) &= ~AuCpdown_##name; } while (0)
34064 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34065 + unsigned int *flags)
34068 + struct dentry *opq_dentry;
34070 + opq_dentry = au_diropq_create(dentry, bdst);
34071 + err = PTR_ERR(opq_dentry);
34072 + if (IS_ERR(opq_dentry))
34074 + dput(opq_dentry);
34075 + au_fset_cpdown(*flags, DIROPQ);
34081 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34082 + struct inode *dir, aufs_bindex_t bdst)
34085 + struct path h_path;
34086 + struct au_branch *br;
34088 + br = au_sbr(dentry->d_sb, bdst);
34089 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34090 + err = PTR_ERR(h_path.dentry);
34091 + if (IS_ERR(h_path.dentry))
34095 + if (d_is_positive(h_path.dentry)) {
34096 + h_path.mnt = au_br_mnt(br);
34097 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34100 + dput(h_path.dentry);
34106 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34107 + struct au_pin *pin,
34108 + struct dentry *h_parent, void *arg)
34111 + aufs_bindex_t bopq, btop;
34112 + struct path h_path;
34113 + struct dentry *parent;
34114 + struct inode *h_dir, *h_inode, *inode, *dir;
34115 + unsigned int *flags = arg;
34117 + btop = au_dbtop(dentry);
34118 + /* dentry is di-locked */
34119 + parent = dget_parent(dentry);
34120 + dir = d_inode(parent);
34121 + h_dir = d_inode(h_parent);
34122 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34123 + IMustLock(h_dir);
34125 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34126 + if (unlikely(err < 0))
34128 + h_path.dentry = au_h_dptr(dentry, bdst);
34129 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34130 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34131 + if (unlikely(err))
34133 + au_fset_cpdown(*flags, MADE_DIR);
34135 + bopq = au_dbdiropq(dentry);
34136 + au_fclr_cpdown(*flags, WHED);
34137 + au_fclr_cpdown(*flags, DIROPQ);
34138 + if (au_dbwh(dentry) == bdst)
34139 + au_fset_cpdown(*flags, WHED);
34140 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34141 + au_fset_cpdown(*flags, PARENT_OPQ);
34142 + h_inode = d_inode(h_path.dentry);
34143 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34144 + if (au_ftest_cpdown(*flags, WHED)) {
34145 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34146 + if (unlikely(err)) {
34147 + inode_unlock(h_inode);
34152 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34153 + inode_unlock(h_inode);
34154 + if (unlikely(err))
34157 + if (au_ftest_cpdown(*flags, WHED)) {
34158 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34159 + if (unlikely(err))
34163 + inode = d_inode(dentry);
34164 + if (au_ibbot(inode) < bdst)
34165 + au_set_ibbot(inode, bdst);
34166 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34167 + au_hi_flags(inode, /*isdir*/1));
34168 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34169 + goto out; /* success */
34173 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34174 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34175 + rerr = au_diropq_remove(dentry, bdst);
34176 + inode_unlock(h_inode);
34177 + if (unlikely(rerr)) {
34178 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34179 + dentry, bdst, rerr);
34185 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34186 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34187 + if (unlikely(rerr)) {
34188 + AuIOErr("failed removing %pd b%d (%d)\n",
34189 + dentry, bdst, rerr);
34194 + au_set_h_dptr(dentry, bdst, NULL);
34195 + if (au_dbbot(dentry) == bdst)
34196 + au_update_dbbot(dentry);
34202 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34205 + unsigned int flags;
34208 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34213 +/* ---------------------------------------------------------------------- */
34215 +/* policies for create */
34217 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34219 + int err, i, j, ndentry;
34220 + aufs_bindex_t bopq;
34221 + struct au_dcsub_pages dpages;
34222 + struct au_dpage *dpage;
34223 + struct dentry **dentries, *parent, *d;
34225 + err = au_dpages_init(&dpages, GFP_NOFS);
34226 + if (unlikely(err))
34228 + parent = dget_parent(dentry);
34229 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34230 + if (unlikely(err))
34234 + for (i = 0; i < dpages.ndpage; i++) {
34235 + dpage = dpages.dpages + i;
34236 + dentries = dpage->dentries;
34237 + ndentry = dpage->ndentry;
34238 + for (j = 0; j < ndentry; j++) {
34240 + di_read_lock_parent2(d, !AuLock_IR);
34241 + bopq = au_dbdiropq(d);
34242 + di_read_unlock(d, !AuLock_IR);
34243 + if (bopq >= 0 && bopq < err)
34250 + au_dpages_free(&dpages);
34255 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34257 + for (; bindex >= 0; bindex--)
34258 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34263 +/* top down parent */
34264 +static int au_wbr_create_tdp(struct dentry *dentry,
34265 + unsigned int flags __maybe_unused)
34268 + aufs_bindex_t btop, bindex;
34269 + struct super_block *sb;
34270 + struct dentry *parent, *h_parent;
34272 + sb = dentry->d_sb;
34273 + btop = au_dbtop(dentry);
34275 + if (!au_br_rdonly(au_sbr(sb, btop)))
34279 + parent = dget_parent(dentry);
34280 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34281 + h_parent = au_h_dptr(parent, bindex);
34282 + if (!h_parent || d_is_negative(h_parent))
34285 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34292 + /* bottom up here */
34293 + if (unlikely(err < 0)) {
34294 + err = au_wbr_bu(sb, btop - 1);
34296 + err = au_wbr_nonopq(dentry, err);
34300 + AuDbg("b%d\n", err);
34304 +/* ---------------------------------------------------------------------- */
34306 +/* an exception for the policy other than tdp */
34307 +static int au_wbr_create_exp(struct dentry *dentry)
34310 + aufs_bindex_t bwh, bdiropq;
34311 + struct dentry *parent;
34314 + bwh = au_dbwh(dentry);
34315 + parent = dget_parent(dentry);
34316 + bdiropq = au_dbdiropq(parent);
34318 + if (bdiropq >= 0)
34319 + err = min(bdiropq, bwh);
34322 + AuDbg("%d\n", err);
34323 + } else if (bdiropq >= 0) {
34325 + AuDbg("%d\n", err);
34330 + err = au_wbr_nonopq(dentry, err);
34332 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34335 + AuDbg("%d\n", err);
34339 +/* ---------------------------------------------------------------------- */
34342 +static int au_wbr_create_init_rr(struct super_block *sb)
34346 + err = au_wbr_bu(sb, au_sbbot(sb));
34347 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34350 + AuDbg("b%d\n", err);
34354 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34358 + aufs_bindex_t bindex, bbot;
34359 + struct super_block *sb;
34362 + err = au_wbr_create_exp(dentry);
34366 + sb = dentry->d_sb;
34367 + next = &au_sbi(sb)->si_wbr_rr_next;
34368 + bbot = au_sbbot(sb);
34370 + for (bindex = 0; bindex <= bbot; bindex++) {
34371 + if (!au_ftest_wbr(flags, DIR)) {
34372 + err = atomic_dec_return(next) + 1;
34373 + /* modulo for 0 is meaningless */
34374 + if (unlikely(!err))
34375 + err = atomic_dec_return(next) + 1;
34377 + err = atomic_read(next);
34378 + AuDbg("%d\n", err);
34381 + AuDbg("%d\n", err);
34382 + if (!au_br_rdonly(au_sbr(sb, err)))
34388 + err = au_wbr_nonopq(dentry, err);
34391 + AuDbg("%d\n", err);
34395 +/* ---------------------------------------------------------------------- */
34397 +/* most free space */
34398 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34400 + struct super_block *sb;
34401 + struct au_branch *br;
34402 + struct au_wbr_mfs *mfs;
34403 + struct dentry *h_parent;
34404 + aufs_bindex_t bindex, bbot;
34406 + unsigned long long b, bavail;
34407 + struct path h_path;
34408 + /* reduce the stack usage */
34409 + struct kstatfs *st;
34411 + st = kmalloc(sizeof(*st), GFP_NOFS);
34412 + if (unlikely(!st)) {
34413 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34418 + sb = dentry->d_sb;
34419 + mfs = &au_sbi(sb)->si_wbr_mfs;
34420 + MtxMustLock(&mfs->mfs_lock);
34421 + mfs->mfs_bindex = -EROFS;
34422 + mfs->mfsrr_bytes = 0;
34425 + bbot = au_sbbot(sb);
34427 + bindex = au_dbtop(parent);
34428 + bbot = au_dbtaildir(parent);
34431 + for (; bindex <= bbot; bindex++) {
34433 + h_parent = au_h_dptr(parent, bindex);
34434 + if (!h_parent || d_is_negative(h_parent))
34437 + br = au_sbr(sb, bindex);
34438 + if (au_br_rdonly(br))
34441 + /* sb->s_root for NFS is unreliable */
34442 + h_path.mnt = au_br_mnt(br);
34443 + h_path.dentry = h_path.mnt->mnt_root;
34444 + err = vfs_statfs(&h_path, st);
34445 + if (unlikely(err)) {
34446 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34450 + /* when the available size is equal, select the lower one */
34451 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34452 + || sizeof(b) < sizeof(st->f_bsize));
34453 + b = st->f_bavail * st->f_bsize;
34454 + br->br_wbr->wbr_bytes = b;
34455 + if (b >= bavail) {
34457 + mfs->mfs_bindex = bindex;
34458 + mfs->mfs_jiffy = jiffies;
34462 + mfs->mfsrr_bytes = bavail;
34463 + AuDbg("b%d\n", mfs->mfs_bindex);
34467 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34470 + struct dentry *parent;
34471 + struct super_block *sb;
34472 + struct au_wbr_mfs *mfs;
34474 + err = au_wbr_create_exp(dentry);
34478 + sb = dentry->d_sb;
34480 + if (au_ftest_wbr(flags, PARENT))
34481 + parent = dget_parent(dentry);
34482 + mfs = &au_sbi(sb)->si_wbr_mfs;
34483 + mutex_lock(&mfs->mfs_lock);
34484 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34485 + || mfs->mfs_bindex < 0
34486 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34487 + au_mfs(dentry, parent);
34488 + mutex_unlock(&mfs->mfs_lock);
34489 + err = mfs->mfs_bindex;
34493 + err = au_wbr_nonopq(dentry, err);
34496 + AuDbg("b%d\n", err);
34500 +static int au_wbr_create_init_mfs(struct super_block *sb)
34502 + struct au_wbr_mfs *mfs;
34504 + mfs = &au_sbi(sb)->si_wbr_mfs;
34505 + mutex_init(&mfs->mfs_lock);
34506 + mfs->mfs_jiffy = 0;
34507 + mfs->mfs_bindex = -EROFS;
34512 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34514 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34518 +/* ---------------------------------------------------------------------- */
34520 +/* top down regardless parent, and then mfs */
34521 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34522 + unsigned int flags __maybe_unused)
34525 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34526 + unsigned long long watermark;
34527 + struct super_block *sb;
34528 + struct au_wbr_mfs *mfs;
34529 + struct au_branch *br;
34530 + struct dentry *parent;
34532 + sb = dentry->d_sb;
34533 + mfs = &au_sbi(sb)->si_wbr_mfs;
34534 + mutex_lock(&mfs->mfs_lock);
34535 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34536 + || mfs->mfs_bindex < 0)
34537 + au_mfs(dentry, /*parent*/NULL);
34538 + watermark = mfs->mfsrr_watermark;
34539 + bmfs = mfs->mfs_bindex;
34540 + mutex_unlock(&mfs->mfs_lock);
34542 + /* another style of au_wbr_create_exp() */
34543 + bwh = au_dbwh(dentry);
34544 + parent = dget_parent(dentry);
34545 + btail = au_dbtaildir(parent);
34546 + if (bwh >= 0 && bwh < btail)
34549 + err = au_wbr_nonopq(dentry, btail);
34550 + if (unlikely(err < 0))
34554 + for (bindex = 0; bindex <= btail; bindex++) {
34555 + br = au_sbr(sb, bindex);
34556 + if (au_br_rdonly(br))
34558 + if (br->br_wbr->wbr_bytes > watermark) {
34569 + AuDbg("b%d\n", err);
34573 +/* ---------------------------------------------------------------------- */
34575 +/* most free space and then round robin */
34576 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34579 + struct au_wbr_mfs *mfs;
34581 + err = au_wbr_create_mfs(dentry, flags);
34583 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34584 + mutex_lock(&mfs->mfs_lock);
34585 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34586 + err = au_wbr_create_rr(dentry, flags);
34587 + mutex_unlock(&mfs->mfs_lock);
34590 + AuDbg("b%d\n", err);
34594 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34598 + au_wbr_create_init_mfs(sb); /* ignore */
34599 + err = au_wbr_create_init_rr(sb);
34604 +/* ---------------------------------------------------------------------- */
34606 +/* top down parent and most free space */
34607 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34610 + unsigned long long b;
34611 + aufs_bindex_t bindex, btop, bbot;
34612 + struct super_block *sb;
34613 + struct dentry *parent, *h_parent;
34614 + struct au_branch *br;
34616 + err = au_wbr_create_tdp(dentry, flags);
34617 + if (unlikely(err < 0))
34619 + parent = dget_parent(dentry);
34620 + btop = au_dbtop(parent);
34621 + bbot = au_dbtaildir(parent);
34622 + if (btop == bbot)
34623 + goto out_parent; /* success */
34625 + e2 = au_wbr_create_mfs(dentry, flags);
34627 + goto out_parent; /* success */
34629 + /* when the available size is equal, select upper one */
34630 + sb = dentry->d_sb;
34631 + br = au_sbr(sb, err);
34632 + b = br->br_wbr->wbr_bytes;
34633 + AuDbg("b%d, %llu\n", err, b);
34635 + for (bindex = btop; bindex <= bbot; bindex++) {
34636 + h_parent = au_h_dptr(parent, bindex);
34637 + if (!h_parent || d_is_negative(h_parent))
34640 + br = au_sbr(sb, bindex);
34641 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34642 + b = br->br_wbr->wbr_bytes;
34644 + AuDbg("b%d, %llu\n", err, b);
34649 + err = au_wbr_nonopq(dentry, err);
34654 + AuDbg("b%d\n", err);
34658 +/* ---------------------------------------------------------------------- */
34661 + * - top down parent
34662 + * - most free space with parent
34663 + * - most free space round-robin regardless parent
34665 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34668 + unsigned long long watermark;
34669 + struct super_block *sb;
34670 + struct au_branch *br;
34671 + struct au_wbr_mfs *mfs;
34673 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34674 + if (unlikely(err < 0))
34677 + sb = dentry->d_sb;
34678 + br = au_sbr(sb, err);
34679 + mfs = &au_sbi(sb)->si_wbr_mfs;
34680 + mutex_lock(&mfs->mfs_lock);
34681 + watermark = mfs->mfsrr_watermark;
34682 + mutex_unlock(&mfs->mfs_lock);
34683 + if (br->br_wbr->wbr_bytes < watermark)
34684 + /* regardless the parent dir */
34685 + err = au_wbr_create_mfsrr(dentry, flags);
34688 + AuDbg("b%d\n", err);
34692 +/* ---------------------------------------------------------------------- */
34694 +/* policies for copyup */
34696 +/* top down parent */
34697 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34699 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34702 +/* bottom up parent */
34703 +static int au_wbr_copyup_bup(struct dentry *dentry)
34706 + aufs_bindex_t bindex, btop;
34707 + struct dentry *parent, *h_parent;
34708 + struct super_block *sb;
34711 + sb = dentry->d_sb;
34712 + parent = dget_parent(dentry);
34713 + btop = au_dbtop(parent);
34714 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34715 + h_parent = au_h_dptr(parent, bindex);
34716 + if (!h_parent || d_is_negative(h_parent))
34719 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34726 + /* bottom up here */
34727 + if (unlikely(err < 0))
34728 + err = au_wbr_bu(sb, btop - 1);
34730 + AuDbg("b%d\n", err);
34735 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34739 + err = au_wbr_bu(dentry->d_sb, btop);
34740 + AuDbg("b%d\n", err);
34742 + err = au_wbr_nonopq(dentry, err);
34744 + AuDbg("b%d\n", err);
34748 +static int au_wbr_copyup_bu(struct dentry *dentry)
34751 + aufs_bindex_t btop;
34753 + btop = au_dbtop(dentry);
34754 + err = au_wbr_do_copyup_bu(dentry, btop);
34758 +/* ---------------------------------------------------------------------- */
34760 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34761 + [AuWbrCopyup_TDP] = {
34762 + .copyup = au_wbr_copyup_tdp
34764 + [AuWbrCopyup_BUP] = {
34765 + .copyup = au_wbr_copyup_bup
34767 + [AuWbrCopyup_BU] = {
34768 + .copyup = au_wbr_copyup_bu
34772 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34773 + [AuWbrCreate_TDP] = {
34774 + .create = au_wbr_create_tdp
34776 + [AuWbrCreate_RR] = {
34777 + .create = au_wbr_create_rr,
34778 + .init = au_wbr_create_init_rr
34780 + [AuWbrCreate_MFS] = {
34781 + .create = au_wbr_create_mfs,
34782 + .init = au_wbr_create_init_mfs,
34783 + .fin = au_wbr_create_fin_mfs
34785 + [AuWbrCreate_MFSV] = {
34786 + .create = au_wbr_create_mfs,
34787 + .init = au_wbr_create_init_mfs,
34788 + .fin = au_wbr_create_fin_mfs
34790 + [AuWbrCreate_MFSRR] = {
34791 + .create = au_wbr_create_mfsrr,
34792 + .init = au_wbr_create_init_mfsrr,
34793 + .fin = au_wbr_create_fin_mfs
34795 + [AuWbrCreate_MFSRRV] = {
34796 + .create = au_wbr_create_mfsrr,
34797 + .init = au_wbr_create_init_mfsrr,
34798 + .fin = au_wbr_create_fin_mfs
34800 + [AuWbrCreate_TDMFS] = {
34801 + .create = au_wbr_create_tdmfs,
34802 + .init = au_wbr_create_init_mfs,
34803 + .fin = au_wbr_create_fin_mfs
34805 + [AuWbrCreate_TDMFSV] = {
34806 + .create = au_wbr_create_tdmfs,
34807 + .init = au_wbr_create_init_mfs,
34808 + .fin = au_wbr_create_fin_mfs
34810 + [AuWbrCreate_PMFS] = {
34811 + .create = au_wbr_create_pmfs,
34812 + .init = au_wbr_create_init_mfs,
34813 + .fin = au_wbr_create_fin_mfs
34815 + [AuWbrCreate_PMFSV] = {
34816 + .create = au_wbr_create_pmfs,
34817 + .init = au_wbr_create_init_mfs,
34818 + .fin = au_wbr_create_fin_mfs
34820 + [AuWbrCreate_PMFSRR] = {
34821 + .create = au_wbr_create_pmfsrr,
34822 + .init = au_wbr_create_init_mfsrr,
34823 + .fin = au_wbr_create_fin_mfs
34825 + [AuWbrCreate_PMFSRRV] = {
34826 + .create = au_wbr_create_pmfsrr,
34827 + .init = au_wbr_create_init_mfsrr,
34828 + .fin = au_wbr_create_fin_mfs
34831 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34832 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34833 +++ linux/fs/aufs/whout.c 2018-10-23 12:33:35.599375796 +0200
34835 +// SPDX-License-Identifier: GPL-2.0
34837 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34839 + * This program, aufs is free software; you can redistribute it and/or modify
34840 + * it under the terms of the GNU General Public License as published by
34841 + * the Free Software Foundation; either version 2 of the License, or
34842 + * (at your option) any later version.
34844 + * This program is distributed in the hope that it will be useful,
34845 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34846 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34847 + * GNU General Public License for more details.
34849 + * You should have received a copy of the GNU General Public License
34850 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34854 + * whiteout for logical deletion and opaque directory
34859 +#define WH_MASK 0444
34862 + * If a directory contains this file, then it is opaque. We start with the
34863 + * .wh. flag so that it is blocked by lookup.
34865 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34866 + sizeof(AUFS_WH_DIROPQ) - 1);
34869 + * generate whiteout name, which is NOT terminated by NULL.
34870 + * @name: original d_name.name
34871 + * @len: original d_name.len
34872 + * @wh: whiteout qstr
34873 + * returns zero when succeeds, otherwise error.
34874 + * succeeded value as wh->name should be freed by kfree().
34876 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34880 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34881 + return -ENAMETOOLONG;
34883 + wh->len = name->len + AUFS_WH_PFX_LEN;
34884 + p = kmalloc(wh->len, GFP_NOFS);
34887 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34888 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34895 +/* ---------------------------------------------------------------------- */
34898 + * test if the @wh_name exists under @h_parent.
34899 + * @try_sio specifies the necessary of super-io.
34901 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34904 + struct dentry *wh_dentry;
34907 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34909 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34910 + err = PTR_ERR(wh_dentry);
34911 + if (IS_ERR(wh_dentry)) {
34912 + if (err == -ENAMETOOLONG)
34918 + if (d_is_negative(wh_dentry))
34919 + goto out_wh; /* success */
34922 + if (d_is_reg(wh_dentry))
34923 + goto out_wh; /* success */
34926 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34927 + wh_dentry, d_inode(wh_dentry)->i_mode);
34936 + * test if the @h_dentry sets opaque or not.
34938 +int au_diropq_test(struct dentry *h_dentry)
34941 + struct inode *h_dir;
34943 + h_dir = d_inode(h_dentry);
34944 + err = au_wh_test(h_dentry, &diropq_name,
34945 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34950 + * returns a negative dentry whose name is unique and temporary.
34952 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34953 + struct qstr *prefix)
34955 + struct dentry *dentry;
34957 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34959 + /* strict atomic_t is unnecessary here */
34960 + static unsigned short cnt;
34963 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34966 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34967 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34968 + dentry = ERR_PTR(-ENAMETOOLONG);
34969 + if (unlikely(qs.len > NAME_MAX))
34971 + dentry = ERR_PTR(-ENOMEM);
34972 + name = kmalloc(qs.len + 1, GFP_NOFS);
34973 + if (unlikely(!name))
34977 + /* doubly whiteout-ed */
34978 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34979 + p = name + AUFS_WH_PFX_LEN * 2;
34980 + memcpy(p, prefix->name, prefix->len);
34981 + p += prefix->len;
34983 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34986 + for (i = 0; i < 3; i++) {
34987 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34988 + dentry = au_sio_lkup_one(&qs, h_parent);
34989 + if (IS_ERR(dentry) || d_is_negative(dentry))
34993 + /* pr_warn("could not get random name\n"); */
34994 + dentry = ERR_PTR(-EEXIST);
34995 + AuDbg("%.*s\n", AuLNPair(&qs));
34999 + if (name != defname)
35002 + AuTraceErrPtr(dentry);
35007 + * rename the @h_dentry on @br to the whiteouted temporary name.
35009 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35012 + struct path h_path = {
35013 + .mnt = au_br_mnt(br)
35015 + struct inode *h_dir, *delegated;
35016 + struct dentry *h_parent;
35018 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35019 + h_dir = d_inode(h_parent);
35020 + IMustLock(h_dir);
35022 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35023 + err = PTR_ERR(h_path.dentry);
35024 + if (IS_ERR(h_path.dentry))
35027 + /* under the same dir, no need to lock_rename() */
35028 + delegated = NULL;
35029 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35032 + if (unlikely(err == -EWOULDBLOCK)) {
35033 + pr_warn("cannot retry for NFSv4 delegation"
35034 + " for an internal rename\n");
35037 + dput(h_path.dentry);
35044 +/* ---------------------------------------------------------------------- */
35046 + * functions for removing a whiteout
35049 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35052 + struct inode *delegated;
35055 + * forces superio when the dir has a sticky bit.
35056 + * this may be a violation of unix fs semantics.
35058 + force = (h_dir->i_mode & S_ISVTX)
35059 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35060 + delegated = NULL;
35061 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35062 + if (unlikely(err == -EWOULDBLOCK)) {
35063 + pr_warn("cannot retry for NFSv4 delegation"
35064 + " for an internal unlink\n");
35070 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35071 + struct dentry *dentry)
35075 + err = do_unlink_wh(h_dir, h_path);
35076 + if (!err && dentry)
35077 + au_set_dbwh(dentry, -1);
35082 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35083 + struct au_branch *br)
35086 + struct path h_path = {
35087 + .mnt = au_br_mnt(br)
35091 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35092 + if (IS_ERR(h_path.dentry))
35093 + err = PTR_ERR(h_path.dentry);
35095 + if (d_is_reg(h_path.dentry))
35096 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35097 + dput(h_path.dentry);
35103 +/* ---------------------------------------------------------------------- */
35105 + * initialize/clean whiteout for a branch
35108 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35112 + struct inode *delegated;
35114 + if (d_is_negative(whpath->dentry))
35118 + err = vfsub_rmdir(h_dir, whpath);
35120 + delegated = NULL;
35121 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35122 + if (unlikely(err == -EWOULDBLOCK)) {
35123 + pr_warn("cannot retry for NFSv4 delegation"
35124 + " for an internal unlink\n");
35128 + if (unlikely(err))
35129 + pr_warn("failed removing %pd (%d), ignored.\n",
35130 + whpath->dentry, err);
35133 +static int test_linkable(struct dentry *h_root)
35135 + struct inode *h_dir = d_inode(h_root);
35137 + if (h_dir->i_op->link)
35140 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35141 + h_root, au_sbtype(h_root->d_sb));
35145 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35146 +static int au_whdir(struct inode *h_dir, struct path *path)
35151 + if (d_is_negative(path->dentry)) {
35154 + if (au_test_nfs(path->dentry->d_sb))
35156 + err = vfsub_mkdir(h_dir, path, mode);
35157 + } else if (d_is_dir(path->dentry))
35160 + pr_err("unknown %pd exists\n", path->dentry);
35165 +struct au_wh_base {
35166 + const struct qstr *name;
35167 + struct dentry *dentry;
35170 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35171 + struct path *h_path)
35173 + h_path->dentry = base[AuBrWh_BASE].dentry;
35174 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35175 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35176 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35177 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35178 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35182 + * returns tri-state,
35183 + * minus: error, caller should print the message
35185 + * plus: error, caller should NOT print the message
35187 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35188 + int do_plink, struct au_wh_base base[],
35189 + struct path *h_path)
35192 + struct inode *h_dir;
35194 + h_dir = d_inode(h_root);
35195 + h_path->dentry = base[AuBrWh_BASE].dentry;
35196 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35197 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35199 + err = test_linkable(h_root);
35200 + if (unlikely(err)) {
35205 + err = au_whdir(h_dir, h_path);
35206 + if (unlikely(err))
35208 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35210 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35211 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35212 + err = au_whdir(h_dir, h_path);
35213 + if (unlikely(err))
35215 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35222 + * for the moment, aufs supports the branch filesystem which does not support
35223 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35224 + * copyup failed. finally, such filesystem will not be used as the writable
35227 + * returns tri-state, see above.
35229 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35230 + int do_plink, struct au_wh_base base[],
35231 + struct path *h_path)
35234 + struct inode *h_dir;
35236 + WbrWhMustWriteLock(wbr);
35238 + err = test_linkable(h_root);
35239 + if (unlikely(err)) {
35245 + * todo: should this create be done in /sbin/mount.aufs helper?
35248 + h_dir = d_inode(h_root);
35249 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35250 + h_path->dentry = base[AuBrWh_BASE].dentry;
35251 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35252 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35255 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35256 + if (unlikely(err))
35259 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35261 + err = au_whdir(h_dir, h_path);
35262 + if (unlikely(err))
35264 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35266 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35267 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35269 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35270 + err = au_whdir(h_dir, h_path);
35271 + if (unlikely(err))
35273 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35280 + * initialize the whiteout base file/dir for @br.
35282 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35285 + const unsigned char do_plink
35286 + = !!au_opt_test(au_mntflags(sb), PLINK);
35287 + struct inode *h_dir;
35288 + struct path path = br->br_path;
35289 + struct dentry *h_root = path.dentry;
35290 + struct au_wbr *wbr = br->br_wbr;
35291 + static const struct qstr base_name[] = {
35292 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35293 + sizeof(AUFS_BASE_NAME) - 1),
35294 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35295 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35296 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35297 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35299 + struct au_wh_base base[] = {
35300 + [AuBrWh_BASE] = {
35301 + .name = base_name + AuBrWh_BASE,
35304 + [AuBrWh_PLINK] = {
35305 + .name = base_name + AuBrWh_PLINK,
35308 + [AuBrWh_ORPH] = {
35309 + .name = base_name + AuBrWh_ORPH,
35315 + WbrWhMustWriteLock(wbr);
35317 + for (i = 0; i < AuBrWh_Last; i++) {
35318 + /* doubly whiteouted */
35319 + struct dentry *d;
35321 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35322 + err = PTR_ERR(d);
35326 + base[i].dentry = d;
35328 + && wbr->wbr_wh[i]
35329 + && wbr->wbr_wh[i] != base[i].dentry);
35333 + for (i = 0; i < AuBrWh_Last; i++) {
35334 + dput(wbr->wbr_wh[i]);
35335 + wbr->wbr_wh[i] = NULL;
35339 + if (!au_br_writable(br->br_perm)) {
35340 + h_dir = d_inode(h_root);
35341 + au_wh_init_ro(h_dir, base, &path);
35342 + } else if (!au_br_wh_linkable(br->br_perm)) {
35343 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35349 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35355 + goto out; /* success */
35358 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35359 + err, h_root, au_sbtype(h_root->d_sb));
35361 + for (i = 0; i < AuBrWh_Last; i++)
35362 + dput(base[i].dentry);
35366 +/* ---------------------------------------------------------------------- */
35368 + * whiteouts are all hard-linked usually.
35369 + * when its link count reaches a ceiling, we create a new whiteout base
35370 + * asynchronously.
35373 +struct reinit_br_wh {
35374 + struct super_block *sb;
35375 + struct au_branch *br;
35378 +static void reinit_br_wh(void *arg)
35381 + aufs_bindex_t bindex;
35382 + struct path h_path;
35383 + struct reinit_br_wh *a = arg;
35384 + struct au_wbr *wbr;
35385 + struct inode *dir, *delegated;
35386 + struct dentry *h_root;
35387 + struct au_hinode *hdir;
35390 + wbr = a->br->br_wbr;
35391 + /* big aufs lock */
35392 + si_noflush_write_lock(a->sb);
35393 + if (!au_br_writable(a->br->br_perm))
35395 + bindex = au_br_index(a->sb, a->br->br_id);
35396 + if (unlikely(bindex < 0))
35399 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35400 + dir = d_inode(a->sb->s_root);
35401 + hdir = au_hi(dir, bindex);
35402 + h_root = au_h_dptr(a->sb->s_root, bindex);
35403 + AuDebugOn(h_root != au_br_dentry(a->br));
35405 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35406 + wbr_wh_write_lock(wbr);
35407 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35410 + h_path.dentry = wbr->wbr_whbase;
35411 + h_path.mnt = au_br_mnt(a->br);
35412 + delegated = NULL;
35413 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35415 + if (unlikely(err == -EWOULDBLOCK)) {
35416 + pr_warn("cannot retry for NFSv4 delegation"
35417 + " for an internal unlink\n");
35421 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35424 + dput(wbr->wbr_whbase);
35425 + wbr->wbr_whbase = NULL;
35427 + err = au_wh_init(a->br, a->sb);
35428 + wbr_wh_write_unlock(wbr);
35429 + au_hn_inode_unlock(hdir);
35430 + di_read_unlock(a->sb->s_root, AuLock_IR);
35432 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35436 + atomic_dec(&wbr->wbr_wh_running);
35437 + au_lcnt_dec(&a->br->br_count);
35438 + si_write_unlock(a->sb);
35439 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35441 + if (unlikely(err))
35442 + AuIOErr("err %d\n", err);
35445 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35447 + int do_dec, wkq_err;
35448 + struct reinit_br_wh *arg;
35451 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35454 + /* ignore ENOMEM */
35455 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35458 + * dec(wh_running), kfree(arg) and dec(br_count)
35459 + * in reinit function
35463 + au_lcnt_inc(&br->br_count);
35464 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35465 + if (unlikely(wkq_err)) {
35466 + atomic_dec(&br->br_wbr->wbr_wh_running);
35467 + au_lcnt_dec(&br->br_count);
35475 + atomic_dec(&br->br_wbr->wbr_wh_running);
35478 +/* ---------------------------------------------------------------------- */
35481 + * create the whiteout @wh.
35483 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35484 + struct dentry *wh)
35487 + struct path h_path = {
35490 + struct au_branch *br;
35491 + struct au_wbr *wbr;
35492 + struct dentry *h_parent;
35493 + struct inode *h_dir, *delegated;
35495 + h_parent = wh->d_parent; /* dir inode is locked */
35496 + h_dir = d_inode(h_parent);
35497 + IMustLock(h_dir);
35499 + br = au_sbr(sb, bindex);
35500 + h_path.mnt = au_br_mnt(br);
35501 + wbr = br->br_wbr;
35502 + wbr_wh_read_lock(wbr);
35503 + if (wbr->wbr_whbase) {
35504 + delegated = NULL;
35505 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35506 + if (unlikely(err == -EWOULDBLOCK)) {
35507 + pr_warn("cannot retry for NFSv4 delegation"
35508 + " for an internal link\n");
35511 + if (!err || err != -EMLINK)
35514 + /* link count full. re-initialize br_whbase. */
35515 + kick_reinit_br_wh(sb, br);
35518 + /* return this error in this context */
35519 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35521 + au_fhsm_wrote(sb, bindex, /*force*/0);
35524 + wbr_wh_read_unlock(wbr);
35528 +/* ---------------------------------------------------------------------- */
35531 + * create or remove the diropq.
35533 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35534 + unsigned int flags)
35536 + struct dentry *opq_dentry, *h_dentry;
35537 + struct super_block *sb;
35538 + struct au_branch *br;
35541 + sb = dentry->d_sb;
35542 + br = au_sbr(sb, bindex);
35543 + h_dentry = au_h_dptr(dentry, bindex);
35544 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35545 + if (IS_ERR(opq_dentry))
35548 + if (au_ftest_diropq(flags, CREATE)) {
35549 + err = link_or_create_wh(sb, bindex, opq_dentry);
35551 + au_set_dbdiropq(dentry, bindex);
35552 + goto out; /* success */
35555 + struct path tmp = {
35556 + .dentry = opq_dentry,
35557 + .mnt = au_br_mnt(br)
35559 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35561 + au_set_dbdiropq(dentry, -1);
35563 + dput(opq_dentry);
35564 + opq_dentry = ERR_PTR(err);
35567 + return opq_dentry;
35570 +struct do_diropq_args {
35571 + struct dentry **errp;
35572 + struct dentry *dentry;
35573 + aufs_bindex_t bindex;
35574 + unsigned int flags;
35577 +static void call_do_diropq(void *args)
35579 + struct do_diropq_args *a = args;
35580 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35583 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35584 + unsigned int flags)
35586 + struct dentry *diropq, *h_dentry;
35588 + h_dentry = au_h_dptr(dentry, bindex);
35589 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35590 + diropq = do_diropq(dentry, bindex, flags);
35593 + struct do_diropq_args args = {
35595 + .dentry = dentry,
35596 + .bindex = bindex,
35600 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35601 + if (unlikely(wkq_err))
35602 + diropq = ERR_PTR(wkq_err);
35608 +/* ---------------------------------------------------------------------- */
35611 + * lookup whiteout dentry.
35612 + * @h_parent: lower parent dentry which must exist and be locked
35613 + * @base_name: name of dentry which will be whiteouted
35614 + * returns dentry for whiteout.
35616 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35617 + struct au_branch *br)
35620 + struct qstr wh_name;
35621 + struct dentry *wh_dentry;
35623 + err = au_wh_name_alloc(&wh_name, base_name);
35624 + wh_dentry = ERR_PTR(err);
35626 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35627 + kfree(wh_name.name);
35629 + return wh_dentry;
35633 + * link/create a whiteout for @dentry on @bindex.
35635 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35636 + struct dentry *h_parent)
35638 + struct dentry *wh_dentry;
35639 + struct super_block *sb;
35642 + sb = dentry->d_sb;
35643 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35644 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35645 + err = link_or_create_wh(sb, bindex, wh_dentry);
35647 + au_set_dbwh(dentry, bindex);
35648 + au_fhsm_wrote(sb, bindex, /*force*/0);
35651 + wh_dentry = ERR_PTR(err);
35655 + return wh_dentry;
35658 +/* ---------------------------------------------------------------------- */
35660 +/* Delete all whiteouts in this directory on branch bindex. */
35661 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35662 + aufs_bindex_t bindex, struct au_branch *br)
35665 + unsigned long ul, n;
35666 + struct qstr wh_name;
35668 + struct hlist_head *head;
35669 + struct au_vdir_wh *pos;
35670 + struct au_vdir_destr *str;
35673 + p = (void *)__get_free_page(GFP_NOFS);
35674 + wh_name.name = p;
35675 + if (unlikely(!wh_name.name))
35679 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35680 + p += AUFS_WH_PFX_LEN;
35681 + n = whlist->nh_num;
35682 + head = whlist->nh_head;
35683 + for (ul = 0; !err && ul < n; ul++, head++) {
35684 + hlist_for_each_entry(pos, head, wh_hash) {
35685 + if (pos->wh_bindex != bindex)
35688 + str = &pos->wh_str;
35689 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35690 + memcpy(p, str->name, str->len);
35691 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35692 + err = unlink_wh_name(h_dentry, &wh_name, br);
35697 + AuIOErr("whiteout name too long %.*s\n",
35698 + str->len, str->name);
35703 + free_page((unsigned long)wh_name.name);
35709 +struct del_wh_children_args {
35711 + struct dentry *h_dentry;
35712 + struct au_nhash *whlist;
35713 + aufs_bindex_t bindex;
35714 + struct au_branch *br;
35717 +static void call_del_wh_children(void *args)
35719 + struct del_wh_children_args *a = args;
35720 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35723 +/* ---------------------------------------------------------------------- */
35725 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35727 + struct au_whtmp_rmdir *whtmp;
35729 + unsigned int rdhash;
35731 + SiMustAnyLock(sb);
35733 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35734 + if (unlikely(!whtmp)) {
35735 + whtmp = ERR_PTR(-ENOMEM);
35739 + /* no estimation for dir size */
35740 + rdhash = au_sbi(sb)->si_rdhash;
35742 + rdhash = AUFS_RDHASH_DEF;
35743 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35744 + if (unlikely(err)) {
35746 + whtmp = ERR_PTR(err);
35753 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35756 + au_lcnt_dec(&whtmp->br->br_count);
35757 + dput(whtmp->wh_dentry);
35758 + iput(whtmp->dir);
35759 + au_nhash_wh_free(&whtmp->whlist);
35764 + * rmdir the whiteouted temporary named dir @h_dentry.
35765 + * @whlist: whiteouted children.
35767 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35768 + struct dentry *wh_dentry, struct au_nhash *whlist)
35771 + unsigned int h_nlink;
35772 + struct path h_tmp;
35773 + struct inode *wh_inode, *h_dir;
35774 + struct au_branch *br;
35776 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35777 + IMustLock(h_dir);
35779 + br = au_sbr(dir->i_sb, bindex);
35780 + wh_inode = d_inode(wh_dentry);
35781 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35784 + * someone else might change some whiteouts while we were sleeping.
35785 + * it means this whlist may have an obsoleted entry.
35787 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35788 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35791 + struct del_wh_children_args args = {
35793 + .h_dentry = wh_dentry,
35794 + .whlist = whlist,
35795 + .bindex = bindex,
35799 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35800 + if (unlikely(wkq_err))
35803 + inode_unlock(wh_inode);
35806 + h_tmp.dentry = wh_dentry;
35807 + h_tmp.mnt = au_br_mnt(br);
35808 + h_nlink = h_dir->i_nlink;
35809 + err = vfsub_rmdir(h_dir, &h_tmp);
35810 + /* some fs doesn't change the parent nlink in some cases */
35811 + h_nlink -= h_dir->i_nlink;
35815 + if (au_ibtop(dir) == bindex) {
35816 + /* todo: dir->i_mutex is necessary */
35817 + au_cpup_attr_timesizes(dir);
35819 + vfsub_drop_nlink(dir);
35821 + return 0; /* success */
35824 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35828 +static void call_rmdir_whtmp(void *args)
35831 + aufs_bindex_t bindex;
35832 + struct au_whtmp_rmdir *a = args;
35833 + struct super_block *sb;
35834 + struct dentry *h_parent;
35835 + struct inode *h_dir;
35836 + struct au_hinode *hdir;
35838 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35839 + /* inode_lock(a->dir); */
35841 + sb = a->dir->i_sb;
35842 + si_read_lock(sb, !AuLock_FLUSH);
35843 + if (!au_br_writable(a->br->br_perm))
35845 + bindex = au_br_index(sb, a->br->br_id);
35846 + if (unlikely(bindex < 0))
35850 + ii_write_lock_parent(a->dir);
35851 + h_parent = dget_parent(a->wh_dentry);
35852 + h_dir = d_inode(h_parent);
35853 + hdir = au_hi(a->dir, bindex);
35854 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35855 + if (unlikely(err))
35857 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35858 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35861 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35862 + au_hn_inode_unlock(hdir);
35863 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35867 + ii_write_unlock(a->dir);
35869 + /* inode_unlock(a->dir); */
35870 + au_whtmp_rmdir_free(a);
35871 + si_read_unlock(sb);
35872 + au_nwt_done(&au_sbi(sb)->si_nowait);
35873 + if (unlikely(err))
35874 + AuIOErr("err %d\n", err);
35877 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35878 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35881 + struct super_block *sb;
35885 + /* all post-process will be done in do_rmdir_whtmp(). */
35887 + args->dir = au_igrab(dir);
35888 + args->br = au_sbr(sb, bindex);
35889 + au_lcnt_inc(&args->br->br_count);
35890 + args->wh_dentry = dget(wh_dentry);
35891 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35892 + if (unlikely(wkq_err)) {
35893 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35894 + au_whtmp_rmdir_free(args);
35897 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35898 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35899 +++ linux/fs/aufs/whout.h 2018-08-12 23:43:05.463458173 +0200
35901 +/* SPDX-License-Identifier: GPL-2.0 */
35903 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35905 + * This program, aufs is free software; you can redistribute it and/or modify
35906 + * it under the terms of the GNU General Public License as published by
35907 + * the Free Software Foundation; either version 2 of the License, or
35908 + * (at your option) any later version.
35910 + * This program is distributed in the hope that it will be useful,
35911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35913 + * GNU General Public License for more details.
35915 + * You should have received a copy of the GNU General Public License
35916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35920 + * whiteout for logical deletion and opaque directory
35923 +#ifndef __AUFS_WHOUT_H__
35924 +#define __AUFS_WHOUT_H__
35931 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35932 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35933 +int au_diropq_test(struct dentry *h_dentry);
35935 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35936 + struct qstr *prefix);
35937 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35938 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35939 + struct dentry *dentry);
35940 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35942 +/* diropq flags */
35943 +#define AuDiropq_CREATE 1
35944 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35945 +#define au_fset_diropq(flags, name) \
35946 + do { (flags) |= AuDiropq_##name; } while (0)
35947 +#define au_fclr_diropq(flags, name) \
35948 + do { (flags) &= ~AuDiropq_##name; } while (0)
35950 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35951 + unsigned int flags);
35952 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35953 + struct au_branch *br);
35954 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35955 + struct dentry *h_parent);
35957 +/* real rmdir for the whiteout-ed dir */
35958 +struct au_whtmp_rmdir {
35959 + struct inode *dir;
35960 + struct au_branch *br;
35961 + struct dentry *wh_dentry;
35962 + struct au_nhash whlist;
35965 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35966 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35967 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35968 + struct dentry *wh_dentry, struct au_nhash *whlist);
35969 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35970 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35972 +/* ---------------------------------------------------------------------- */
35974 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35975 + aufs_bindex_t bindex)
35977 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35980 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35982 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35985 +#endif /* __KERNEL__ */
35986 +#endif /* __AUFS_WHOUT_H__ */
35987 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35988 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35989 +++ linux/fs/aufs/wkq.c 2018-10-23 12:33:35.599375796 +0200
35991 +// SPDX-License-Identifier: GPL-2.0
35993 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35995 + * This program, aufs is free software; you can redistribute it and/or modify
35996 + * it under the terms of the GNU General Public License as published by
35997 + * the Free Software Foundation; either version 2 of the License, or
35998 + * (at your option) any later version.
36000 + * This program is distributed in the hope that it will be useful,
36001 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36002 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36003 + * GNU General Public License for more details.
36005 + * You should have received a copy of the GNU General Public License
36006 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36010 + * workqueue for asynchronous/super-io operations
36011 + * todo: try new credential scheme
36014 +#include <linux/module.h>
36017 +/* internal workqueue named AUFS_WKQ_NAME */
36019 +static struct workqueue_struct *au_wkq;
36021 +struct au_wkinfo {
36022 + struct work_struct wk;
36023 + struct kobject *kobj;
36025 + unsigned int flags; /* see wkq.h */
36027 + au_wkq_func_t func;
36030 +#ifdef CONFIG_LOCKDEP
36032 + struct held_lock **hlock;
36035 + struct completion *comp;
36038 +/* ---------------------------------------------------------------------- */
36040 + * Aufs passes some operations to the workqueue such as the internal copyup.
36041 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36042 + * job run by workqueue depends upon the locks acquired in the other task.
36043 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36044 + * information too. And the job in the workqueue restores the info in order to
36045 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36046 + * correctly and expectedly.
36049 +#ifndef CONFIG_LOCKDEP
36050 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36051 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36052 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36053 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36054 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36056 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36058 + wkinfo->hlock = NULL;
36059 + wkinfo->dont_check = 0;
36066 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36068 + static DEFINE_SPINLOCK(spin);
36071 + struct lock_class_key *key;
36073 + { .name = "&sbinfo->si_rwsem" },
36074 + { .name = "&finfo->fi_rwsem" },
36075 + { .name = "&dinfo->di_rwsem" },
36076 + { .name = "&iinfo->ii_rwsem" }
36081 + /* lockless read from 'set.' see below */
36082 + if (set == ARRAY_SIZE(a)) {
36083 + for (i = 0; i < ARRAY_SIZE(a); i++)
36084 + if (a[i].key == key)
36089 + spin_lock(&spin);
36091 + for (i = 0; i < ARRAY_SIZE(a); i++)
36092 + if (a[i].key == key) {
36093 + spin_unlock(&spin);
36096 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36098 + if (unlikely(a[i].key == key)) { /* rare but possible */
36099 + spin_unlock(&spin);
36104 + if (strstr(a[i].name, name)) {
36106 + * the order of these three lines is important for the
36107 + * lockless read above.
36110 + spin_unlock(&spin);
36112 + /* AuDbg("%d, %s\n", set, name); */
36116 + spin_unlock(&spin);
36125 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36128 + struct task_struct *curr;
36129 + struct held_lock **hl, *held_locks, *p;
36133 + wkinfo->dont_check = lockdep_recursing(curr);
36134 + if (wkinfo->dont_check)
36136 + n = curr->lockdep_depth;
36141 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36142 + if (unlikely(!wkinfo->hlock))
36147 + if (0 && au_debug_test()) /* left for debugging */
36148 + lockdep_print_held_locks(curr);
36150 + held_locks = curr->held_locks;
36151 + hl = wkinfo->hlock;
36153 + p = held_locks++;
36154 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36163 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36165 + kfree(wkinfo->hlock);
36168 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36170 + struct held_lock *p, **hl = wkinfo->hlock;
36173 + if (wkinfo->dont_check)
36177 + while ((p = *hl++)) { /* assignment */
36178 + subclass = lockdep_hlock_class(p)->subclass;
36179 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36181 + rwsem_acquire_read(p->instance, subclass, 0,
36182 + /*p->acquire_ip*/_RET_IP_);
36184 + rwsem_acquire(p->instance, subclass, 0,
36185 + /*p->acquire_ip*/_RET_IP_);
36189 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36191 + struct held_lock *p, **hl = wkinfo->hlock;
36193 + if (wkinfo->dont_check)
36197 + while ((p = *hl++)) /* assignment */
36198 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36202 +static void wkq_func(struct work_struct *wk)
36204 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36206 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36207 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36209 + au_wkq_lockdep_pre(wkinfo);
36210 + wkinfo->func(wkinfo->args);
36211 + au_wkq_lockdep_post(wkinfo);
36212 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36213 + complete(wkinfo->comp);
36215 + kobject_put(wkinfo->kobj);
36216 + module_put(THIS_MODULE); /* todo: ?? */
36222 + * Since struct completion is large, try allocating it dynamically.
36224 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36225 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36227 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36229 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36231 + init_completion(*comp);
36232 + wkinfo->comp = *comp;
36238 +static void au_wkq_comp_free(struct completion *comp)
36246 +#define AuWkqCompDeclare(name) \
36247 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36248 + struct completion *comp = &_ ## name
36250 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36252 + wkinfo->comp = *comp;
36256 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36260 +#endif /* 4KSTACKS */
36262 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36264 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36265 + if (au_wkq_test()) {
36266 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36267 + " due to a dead dir by UDBA,"
36268 + " or async xino write?\n");
36269 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36272 + au_dbg_verify_kthread();
36274 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36275 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36276 + queue_work(au_wkq, &wkinfo->wk);
36278 + INIT_WORK(&wkinfo->wk, wkq_func);
36279 + schedule_work(&wkinfo->wk);
36284 + * Be careful. It is easy to make deadlock happen.
36285 + * processA: lock, wkq and wait
36286 + * processB: wkq and wait, lock in wkq
36289 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36292 + AuWkqCompDeclare(comp);
36293 + struct au_wkinfo wkinfo = {
36299 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36300 + if (unlikely(err))
36302 + err = au_wkq_lockdep_alloc(&wkinfo);
36303 + if (unlikely(err))
36306 + au_wkq_run(&wkinfo);
36307 + /* no timeout, no interrupt */
36308 + wait_for_completion(wkinfo.comp);
36310 + au_wkq_lockdep_free(&wkinfo);
36313 + au_wkq_comp_free(comp);
36315 + destroy_work_on_stack(&wkinfo.wk);
36320 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36321 + * problem in a concurrent umounting.
36323 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36324 + unsigned int flags)
36327 + struct au_wkinfo *wkinfo;
36329 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36332 + * wkq_func() must free this wkinfo.
36333 + * it highly depends upon the implementation of workqueue.
36336 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36338 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36339 + wkinfo->flags = flags & ~AuWkq_WAIT;
36340 + wkinfo->func = func;
36341 + wkinfo->args = args;
36342 + wkinfo->comp = NULL;
36343 + au_wkq_lockdep_init(wkinfo);
36344 + kobject_get(wkinfo->kobj);
36345 + __module_get(THIS_MODULE); /* todo: ?? */
36347 + au_wkq_run(wkinfo);
36350 + au_nwt_done(&au_sbi(sb)->si_nowait);
36356 +/* ---------------------------------------------------------------------- */
36358 +void au_nwt_init(struct au_nowait_tasks *nwt)
36360 + atomic_set(&nwt->nw_len, 0);
36361 + /* smp_mb(); */ /* atomic_set */
36362 + init_waitqueue_head(&nwt->nw_wq);
36365 +void au_wkq_fin(void)
36367 + destroy_workqueue(au_wkq);
36370 +int __init au_wkq_init(void)
36375 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36376 + if (IS_ERR(au_wkq))
36377 + err = PTR_ERR(au_wkq);
36378 + else if (!au_wkq)
36383 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36384 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36385 +++ linux/fs/aufs/wkq.h 2018-10-23 12:33:35.599375796 +0200
36387 +/* SPDX-License-Identifier: GPL-2.0 */
36389 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36391 + * This program, aufs is free software; you can redistribute it and/or modify
36392 + * it under the terms of the GNU General Public License as published by
36393 + * the Free Software Foundation; either version 2 of the License, or
36394 + * (at your option) any later version.
36396 + * This program is distributed in the hope that it will be useful,
36397 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36398 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36399 + * GNU General Public License for more details.
36401 + * You should have received a copy of the GNU General Public License
36402 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36406 + * workqueue for asynchronous/super-io operations
36407 + * todo: try new credentials management scheme
36410 +#ifndef __AUFS_WKQ_H__
36411 +#define __AUFS_WKQ_H__
36415 +#include <linux/wait.h>
36417 +struct super_block;
36419 +/* ---------------------------------------------------------------------- */
36422 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36424 +struct au_nowait_tasks {
36426 + wait_queue_head_t nw_wq;
36429 +/* ---------------------------------------------------------------------- */
36431 +typedef void (*au_wkq_func_t)(void *args);
36434 +#define AuWkq_WAIT 1
36435 +#define AuWkq_NEST (1 << 1)
36436 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36437 +#define au_fset_wkq(flags, name) \
36438 + do { (flags) |= AuWkq_##name; } while (0)
36439 +#define au_fclr_wkq(flags, name) \
36440 + do { (flags) &= ~AuWkq_##name; } while (0)
36443 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36444 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36445 + unsigned int flags);
36446 +void au_nwt_init(struct au_nowait_tasks *nwt);
36447 +int __init au_wkq_init(void);
36448 +void au_wkq_fin(void);
36450 +/* ---------------------------------------------------------------------- */
36452 +static inline int au_wkq_test(void)
36454 + return current->flags & PF_WQ_WORKER;
36457 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36459 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36462 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36464 + if (atomic_dec_and_test(&nwt->nw_len))
36465 + wake_up_all(&nwt->nw_wq);
36468 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36470 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36474 +#endif /* __KERNEL__ */
36475 +#endif /* __AUFS_WKQ_H__ */
36476 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36477 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36478 +++ linux/fs/aufs/xattr.c 2018-08-12 23:43:05.466791610 +0200
36480 +// SPDX-License-Identifier: GPL-2.0
36482 + * Copyright (C) 2014-2018 Junjiro R. Okajima
36484 + * This program, aufs is free software; you can redistribute it and/or modify
36485 + * it under the terms of the GNU General Public License as published by
36486 + * the Free Software Foundation; either version 2 of the License, or
36487 + * (at your option) any later version.
36489 + * This program is distributed in the hope that it will be useful,
36490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36492 + * GNU General Public License for more details.
36494 + * You should have received a copy of the GNU General Public License
36495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36499 + * handling xattr functions
36502 +#include <linux/fs.h>
36503 +#include <linux/posix_acl_xattr.h>
36504 +#include <linux/xattr.h>
36507 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36509 + if (!ignore_flags)
36517 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36522 +#define cmp(brattr, prefix) do { \
36523 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36524 + XATTR_##prefix##_PREFIX_LEN)) { \
36525 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36531 + cmp(SEC, SECURITY);
36532 + cmp(SYS, SYSTEM);
36533 + cmp(TR, TRUSTED);
36537 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36544 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36546 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36547 + char *name, char **buf, unsigned int ignore_flags,
36548 + unsigned int verbose)
36552 + struct inode *h_idst;
36554 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36556 + if (unlikely(err <= 0)) {
36557 + if (err == -ENODATA
36558 + || (err == -EOPNOTSUPP
36559 + && ((ignore_flags & au_xattr_out_of_list)
36560 + || (au_test_nfs_noacl(d_inode(h_src))
36561 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36563 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36566 + if (err && (verbose || au_debug_test()))
36567 + pr_err("%s, err %d\n", name, err);
36571 + /* unlock it temporary */
36572 + h_idst = d_inode(h_dst);
36573 + inode_unlock(h_idst);
36574 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36575 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36576 + if (unlikely(err)) {
36577 + if (verbose || au_debug_test())
36578 + pr_err("%s, err %d\n", name, err);
36579 + err = au_xattr_ignore(err, name, ignore_flags);
36586 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36587 + unsigned int verbose)
36589 + int err, unlocked, acl_access, acl_default;
36591 + struct inode *h_isrc, *h_idst;
36592 + char *value, *p, *o, *e;
36594 + /* try stopping to update the source inode while we are referencing */
36595 + /* there should not be the parent-child relationship between them */
36596 + h_isrc = d_inode(h_src);
36597 + h_idst = d_inode(h_dst);
36598 + inode_unlock(h_idst);
36599 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36600 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36603 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36604 + ssz = vfs_listxattr(h_src, NULL, 0);
36606 + if (unlikely(err < 0)) {
36608 + if (err == -ENODATA
36609 + || err == -EOPNOTSUPP)
36610 + err = 0; /* ignore */
36619 + p = kmalloc(ssz, GFP_NOFS);
36621 + if (unlikely(!p))
36623 + err = vfs_listxattr(h_src, p, ssz);
36625 + inode_unlock_shared(h_isrc);
36627 + AuDbg("err %d, ssz %zd\n", err, ssz);
36628 + if (unlikely(err < 0))
36636 + while (!err && p < e) {
36637 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36638 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36639 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36640 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36642 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36644 + p += strlen(p) + 1;
36647 + ignore_flags |= au_xattr_out_of_list;
36648 + if (!err && !acl_access) {
36649 + err = au_do_cpup_xattr(h_dst, h_src,
36650 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36651 + ignore_flags, verbose);
36654 + if (!err && !acl_default) {
36655 + err = au_do_cpup_xattr(h_dst, h_src,
36656 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36657 + ignore_flags, verbose);
36667 + inode_unlock_shared(h_isrc);
36672 +/* ---------------------------------------------------------------------- */
36674 +static int au_smack_reentering(struct super_block *sb)
36676 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36678 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36679 + * i_op->getxattr(). ouch.
36681 + return si_pid_test(sb);
36692 +struct au_lgxattr {
36700 + const char *name;
36707 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36711 + struct path h_path;
36712 + struct super_block *sb;
36714 + sb = dentry->d_sb;
36715 + reenter = au_smack_reentering(sb);
36717 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36718 + if (unlikely(err))
36721 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36722 + if (unlikely(err))
36724 + if (unlikely(!h_path.dentry))
36725 + /* illegally overlapped or something */
36726 + goto out_di; /* pretending success */
36728 + /* always topmost entry only */
36729 + switch (arg->type) {
36730 + case AU_XATTR_LIST:
36731 + err = vfs_listxattr(h_path.dentry,
36732 + arg->u.list.list, arg->u.list.size);
36734 + case AU_XATTR_GET:
36735 + AuDebugOn(d_is_negative(h_path.dentry));
36736 + err = vfs_getxattr(h_path.dentry,
36737 + arg->u.get.name, arg->u.get.value,
36738 + arg->u.get.size);
36744 + di_read_unlock(dentry, AuLock_IR);
36747 + si_read_unlock(sb);
36753 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36755 + struct au_lgxattr arg = {
36756 + .type = AU_XATTR_LIST,
36763 + return au_lgxattr(dentry, &arg);
36766 +static ssize_t au_getxattr(struct dentry *dentry,
36767 + struct inode *inode __maybe_unused,
36768 + const char *name, void *value, size_t size)
36770 + struct au_lgxattr arg = {
36771 + .type = AU_XATTR_GET,
36779 + return au_lgxattr(dentry, &arg);
36782 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36783 + const char *name, const void *value, size_t size,
36786 + struct au_sxattr arg = {
36787 + .type = AU_XATTR_SET,
36796 + return au_sxattr(dentry, inode, &arg);
36799 +/* ---------------------------------------------------------------------- */
36801 +static int au_xattr_get(const struct xattr_handler *handler,
36802 + struct dentry *dentry, struct inode *inode,
36803 + const char *name, void *buffer, size_t size)
36805 + return au_getxattr(dentry, inode, name, buffer, size);
36808 +static int au_xattr_set(const struct xattr_handler *handler,
36809 + struct dentry *dentry, struct inode *inode,
36810 + const char *name, const void *value, size_t size,
36813 + return au_setxattr(dentry, inode, name, value, size, flags);
36816 +static const struct xattr_handler au_xattr_handler = {
36819 + .get = au_xattr_get,
36820 + .set = au_xattr_set
36823 +static const struct xattr_handler *au_xattr_handlers[] = {
36824 +#ifdef CONFIG_FS_POSIX_ACL
36825 + &posix_acl_access_xattr_handler,
36826 + &posix_acl_default_xattr_handler,
36828 + &au_xattr_handler, /* must be last */
36832 +void au_xattr_init(struct super_block *sb)
36834 + sb->s_xattr = au_xattr_handlers;
36836 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36837 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36838 +++ linux/fs/aufs/xino.c 2018-10-23 12:33:35.599375796 +0200
36840 +// SPDX-License-Identifier: GPL-2.0
36842 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36844 + * This program, aufs is free software; you can redistribute it and/or modify
36845 + * it under the terms of the GNU General Public License as published by
36846 + * the Free Software Foundation; either version 2 of the License, or
36847 + * (at your option) any later version.
36849 + * This program is distributed in the hope that it will be useful,
36850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36852 + * GNU General Public License for more details.
36854 + * You should have received a copy of the GNU General Public License
36855 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36859 + * external inode number translation table and bitmap
36861 + * things to consider
36863 + * + au_xino object
36864 + * + XINO files (xino, xib, xigen)
36865 + * + dynamic debugfs entries (xiN)
36866 + * + static debugfs entries (xib, xigen)
36867 + * + static sysfs entry (xi_path)
36868 + * - several entry points to handle them.
36869 + * + mount(2) without xino option (default)
36870 + * + mount(2) with xino option
36871 + * + mount(2) with noxino option
36873 + * + remount with add/del branches
36874 + * + remount with xino/noxino options
36877 +#include <linux/seq_file.h>
36878 +#include <linux/statfs.h>
36881 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36882 + aufs_bindex_t bbot,
36883 + struct super_block *h_sb)
36885 + /* todo: try binary-search if the branches are many */
36886 + for (; btop <= bbot; btop++)
36887 + if (h_sb == au_sbr_sb(sb, btop))
36893 + * find another branch who is on the same filesystem of the specified
36894 + * branch{@btgt}. search until @bbot.
36896 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36897 + aufs_bindex_t bbot)
36899 + aufs_bindex_t bindex;
36900 + struct super_block *tgt_sb;
36902 + tgt_sb = au_sbr_sb(sb, btgt);
36903 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36905 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36910 +/* ---------------------------------------------------------------------- */
36913 + * stop unnecessary notify events at creating xino files
36916 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36918 + aufs_bindex_t bfound, bindex, bbot;
36919 + struct dentry *parent;
36920 + struct au_branch *br;
36923 + parent = dentry->d_parent; /* safe d_parent access */
36924 + bbot = au_sbbot(sb);
36925 + for (bindex = 0; bindex <= bbot; bindex++) {
36926 + br = au_sbr(sb, bindex);
36927 + if (au_br_dentry(br) == parent) {
36933 + AuDbg("bfound b%d\n", bfound);
36937 +struct au_xino_lock_dir {
36938 + struct au_hinode *hdir;
36939 + struct dentry *parent;
36940 + struct inode *dir;
36943 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36944 + unsigned int lsc)
36946 + struct dentry *parent;
36947 + struct inode *dir;
36949 + parent = dget_parent(dentry);
36950 + dir = d_inode(parent);
36951 + inode_lock_nested(dir, lsc);
36952 +#if 0 /* it should not happen */
36953 + spin_lock(&dentry->d_lock);
36954 + if (unlikely(dentry->d_parent != parent)) {
36955 + spin_unlock(&dentry->d_lock);
36956 + inode_unlock(dir);
36961 + spin_unlock(&dentry->d_lock);
36968 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36969 + struct au_xino_lock_dir *ldir)
36971 + aufs_bindex_t bindex;
36973 + ldir->hdir = NULL;
36974 + bindex = au_xi_root(sb, xipath->dentry);
36975 + if (bindex >= 0) {
36976 + /* rw branch root */
36977 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36978 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36981 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36983 + ldir->dir = d_inode(ldir->parent);
36987 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36990 + au_hn_inode_unlock(ldir->hdir);
36992 + inode_unlock(ldir->dir);
36993 + dput(ldir->parent);
36997 +/* ---------------------------------------------------------------------- */
37000 + * create and set a new xino file
37002 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent)
37004 + struct file *file;
37005 + struct dentry *h_parent, *d;
37006 + struct inode *h_dir, *inode;
37010 + * at mount-time, and the xino file is the default path,
37011 + * hnotify is disabled so we have no notify events to ignore.
37012 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37014 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37015 + /* | __FMODE_NONOTIFY */,
37017 + if (IS_ERR(file)) {
37019 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37023 + /* keep file count */
37025 + d = file->f_path.dentry;
37026 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37027 + /* mnt_want_write() is unnecessary here */
37028 + h_dir = d_inode(h_parent);
37029 + inode = file_inode(file);
37030 + /* no delegation since it is just created */
37031 + if (inode->i_nlink)
37032 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37034 + inode_unlock(h_dir);
37036 + if (unlikely(err)) {
37038 + pr_err("unlink %s(%d)\n", fpath, err);
37043 + if (unlikely(sb == d->d_sb)) {
37045 + pr_err("%s must be outside\n", fpath);
37048 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37050 + pr_err("xino doesn't support %s(%s)\n",
37051 + fpath, au_sbtype(d->d_sb));
37054 + return file; /* success */
37058 + file = ERR_PTR(err);
37063 + * create a new xinofile at the same place/path as @base.
37065 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37066 + struct file *copy_src)
37068 + struct file *file;
37069 + struct dentry *dentry, *parent;
37070 + struct inode *dir, *delegated;
37071 + struct qstr *name;
37072 + struct path path;
37073 + int err, do_unlock;
37074 + struct au_xino_lock_dir ldir;
37077 + au_xino_lock_dir(sb, base, &ldir);
37078 + dentry = base->dentry;
37079 + parent = dentry->d_parent; /* dir inode is locked */
37080 + dir = d_inode(parent);
37083 + name = &dentry->d_name;
37084 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37085 + if (IS_ERR(path.dentry)) {
37086 + file = (void *)path.dentry;
37087 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37091 + /* no need to mnt_want_write() since we call dentry_open() later */
37092 + err = vfs_create(dir, path.dentry, 0666, NULL);
37093 + if (unlikely(err)) {
37094 + file = ERR_PTR(err);
37095 + pr_err("%pd create err %d\n", dentry, err);
37099 + path.mnt = base->mnt;
37100 + file = vfsub_dentry_open(&path,
37101 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37102 + /* | __FMODE_NONOTIFY */);
37103 + if (IS_ERR(file)) {
37104 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37108 + delegated = NULL;
37109 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37110 + au_xino_unlock_dir(&ldir);
37112 + if (unlikely(err == -EWOULDBLOCK)) {
37113 + pr_warn("cannot retry for NFSv4 delegation"
37114 + " for an internal unlink\n");
37117 + if (unlikely(err)) {
37118 + pr_err("%pd unlink err %d\n", dentry, err);
37123 + /* no one can touch copy_src xino */
37124 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37125 + if (unlikely(err)) {
37126 + pr_err("%pd copy err %d\n", dentry, err);
37130 + goto out_dput; /* success */
37134 + file = ERR_PTR(err);
37136 + dput(path.dentry);
37139 + au_xino_unlock_dir(&ldir);
37143 +struct file *au_xino_file1(struct au_xino *xi)
37145 + struct file *file;
37146 + unsigned int u, nfile;
37149 + nfile = xi->xi_nfile;
37150 + for (u = 0; u < nfile; u++) {
37151 + file = xi->xi_file[u];
37159 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37170 + if (idx < xi->xi_nfile) {
37171 + f = xi->xi_file[idx];
37175 + p = au_kzrealloc(xi->xi_file,
37176 + sizeof(*xi->xi_file) * xi->xi_nfile,
37177 + sizeof(*xi->xi_file) * (idx + 1),
37178 + GFP_NOFS, /*may_shrink*/0);
37180 + MtxMustLock(&xi->xi_mtx);
37182 + xi->xi_nfile = idx + 1;
37190 + xi->xi_file[idx] = file;
37197 + * if @xinew->xi is not set, then create new xigen file.
37199 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37201 + struct file *file;
37204 + SiMustAnyLock(sb);
37206 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37207 + if (IS_ERR(file)) {
37208 + err = PTR_ERR(file);
37209 + pr_err("%s[%d], err %d\n",
37210 + xinew->xi ? "xino" : "xigen",
37211 + xinew->idx, err);
37216 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37219 + /* todo: make xigen file an array */
37220 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37223 + if (unlikely(err))
37224 + file = ERR_PTR(err);
37230 +/* ---------------------------------------------------------------------- */
37233 + * truncate xino files
37235 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37236 + int idx, struct kstatfs *st)
37240 + struct file *file, *new_xino;
37241 + struct au_xi_new xinew = {
37246 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37247 + file = au_xino_file(xinew.xi, idx);
37251 + xinew.base = &file->f_path;
37252 + err = vfs_statfs(xinew.base, st);
37253 + if (unlikely(err)) {
37254 + AuErr1("statfs err %d, ignored\n", err);
37259 + blocks = file_inode(file)->i_blocks;
37260 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37261 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37263 + xinew.copy_src = file;
37264 + new_xino = au_xi_new(sb, &xinew);
37265 + if (IS_ERR(new_xino)) {
37266 + err = PTR_ERR(new_xino);
37267 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37271 + err = vfs_statfs(&new_xino->f_path, st);
37273 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37274 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37275 + st->f_bfree, st->f_blocks);
37277 + AuErr1("statfs err %d, ignored\n", err);
37285 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37288 + unsigned long jiffy;
37289 + aufs_bindex_t bbot;
37290 + struct kstatfs *st;
37291 + struct au_branch *br;
37292 + struct au_xino *xi;
37295 + st = kmalloc(sizeof(*st), GFP_NOFS);
37296 + if (unlikely(!st))
37300 + bbot = au_sbbot(sb);
37301 + if (unlikely(bindex < 0 || bbot < bindex))
37306 + br = au_sbr(sb, bindex);
37307 + xi = br->br_xino;
37308 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37309 + err = au_xino_do_trunc(sb, bindex, i, st);
37311 + au_sbi(sb)->si_xino_jiffy = jiffy;
37319 +struct xino_do_trunc_args {
37320 + struct super_block *sb;
37321 + struct au_branch *br;
37325 +static void xino_do_trunc(void *_args)
37327 + struct xino_do_trunc_args *args = _args;
37328 + struct super_block *sb;
37329 + struct au_branch *br;
37330 + struct inode *dir;
37332 + aufs_bindex_t bindex;
37336 + dir = d_inode(sb->s_root);
37340 + si_noflush_write_lock(sb);
37341 + ii_read_lock_parent(dir);
37342 + bindex = au_br_index(sb, br->br_id);
37343 + err = au_xino_trunc(sb, bindex, idx);
37344 + ii_read_unlock(dir);
37345 + if (unlikely(err))
37346 + pr_warn("err b%d, (%d)\n", bindex, err);
37347 + atomic_dec(&br->br_xino->xi_truncating);
37348 + au_lcnt_dec(&br->br_count);
37349 + si_write_unlock(sb);
37350 + au_nwt_done(&au_sbi(sb)->si_nowait);
37355 + * returns the index in the xi_file array whose corresponding file is necessary
37356 + * to truncate, or -1 which means no need to truncate.
37358 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37362 + struct kstatfs st;
37363 + struct au_sbinfo *sbinfo;
37364 + struct au_xino *xi;
37365 + struct file *file;
37367 + /* todo: si_xino_expire and the ratio should be customizable */
37368 + sbinfo = au_sbi(sb);
37369 + if (time_before(jiffies,
37370 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37373 + /* truncation border */
37374 + xi = br->br_xino;
37375 + for (u = 0; u < xi->xi_nfile; u++) {
37376 + file = au_xino_file(xi, u);
37380 + err = vfs_statfs(&file->f_path, &st);
37381 + if (unlikely(err)) {
37382 + AuErr1("statfs err %d, ignored\n", err);
37385 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37386 + >= AUFS_XINO_DEF_TRUNC)
37393 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37396 + struct xino_do_trunc_args *args;
37399 + idx = xino_trunc_test(sb, br);
37403 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37406 + /* lock and kfree() will be called in trunc_xino() */
37407 + args = kmalloc(sizeof(*args), GFP_NOFS);
37408 + if (unlikely(!args)) {
37409 + AuErr1("no memory\n");
37413 + au_lcnt_inc(&br->br_count);
37417 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37419 + return; /* success */
37421 + pr_err("wkq %d\n", wkq_err);
37422 + au_lcnt_dec(&br->br_count);
37426 + atomic_dec(&br->br_xino->xi_truncating);
37429 +/* ---------------------------------------------------------------------- */
37431 +struct au_xi_calc {
37436 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37437 + struct au_xi_calc *calc)
37441 + maxent = au_xi_maxent(sb);
37442 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37443 + calc->pos *= sizeof(ino_t);
37446 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37447 + struct au_xi_calc *calc)
37450 + struct file *file;
37451 + struct au_xino *xi = br->br_xino;
37452 + struct au_xi_new xinew = {
37456 + SiMustAnyLock(sb);
37462 + mutex_lock(&xi->xi_mtx);
37463 + file = au_xino_file(xi, calc->idx);
37467 + file = au_xino_file(xi, /*idx*/-1);
37468 + AuDebugOn(!file);
37469 + xinew.idx = calc->idx;
37470 + xinew.base = &file->f_path;
37471 + /* xinew.copy_src = NULL; */
37472 + file = au_xi_new(sb, &xinew);
37473 + if (IS_ERR(file))
37474 + err = PTR_ERR(file);
37477 + mutex_unlock(&xi->xi_mtx);
37482 +struct au_xino_do_new_async_args {
37483 + struct super_block *sb;
37484 + struct au_branch *br;
37485 + struct au_xi_calc calc;
37489 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37490 + struct au_xi_calc *calc, ino_t ino);
37492 +static void au_xino_call_do_new_async(void *args)
37494 + struct au_xino_do_new_async_args *a = args;
37495 + struct au_branch *br;
37496 + struct super_block *sb;
37497 + struct au_sbinfo *sbi;
37498 + struct inode *root;
37499 + struct file *file;
37504 + sbi = au_sbi(sb);
37505 + si_noflush_read_lock(sb);
37506 + root = d_inode(sb->s_root);
37507 + ii_read_lock_child(root);
37508 + err = au_xino_do_new_async(sb, br, &a->calc);
37510 + file = au_xino_file(br->br_xino, a->calc.idx);
37512 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc,
37514 + if (unlikely(err))
37515 + AuIOErr("err %d\n", err);
37517 + AuIOErr("err %d\n", err);
37518 + au_lcnt_dec(&br->br_count);
37519 + ii_read_unlock(root);
37520 + si_read_unlock(sb);
37521 + au_nwt_done(&sbi->si_nowait);
37526 + * create a new xino file asynchronously
37528 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37529 + struct au_xi_calc *calc, ino_t ino)
37532 + struct au_xino_do_new_async_args *arg;
37535 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37536 + if (unlikely(!arg))
37541 + arg->calc = *calc;
37543 + au_lcnt_inc(&br->br_count);
37544 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37545 + if (unlikely(err)) {
37546 + pr_err("wkq %d\n", err);
37547 + au_lcnt_dec(&br->br_count);
37556 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37557 + * at the position of @h_ino.
37559 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37564 + struct au_xi_calc calc;
37565 + struct au_sbinfo *sbinfo;
37566 + struct file *file;
37569 + if (!au_opt_test(au_mntflags(sb), XINO))
37570 + return 0; /* no xino */
37573 + au_xi_calc(sb, h_ino, &calc);
37574 + file = au_xino_file(au_sbr(sb, bindex)->br_xino, calc.idx);
37576 + || vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37577 + return 0; /* no ino */
37579 + sbinfo = au_sbi(sb);
37580 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37581 + if (sz == sizeof(*ino))
37582 + return 0; /* success */
37585 + if (unlikely(sz >= 0)) {
37587 + AuIOErr("xino read error (%zd)\n", sz);
37592 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37593 + struct au_xi_calc *calc, ino_t ino)
37597 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37598 + if (sz == sizeof(ino))
37599 + return 0; /* success */
37601 + AuIOErr("write failed (%zd)\n", sz);
37606 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37607 + * at the position of @h_ino.
37608 + * even if @ino is zero, it is written to the xinofile and means no entry.
37609 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37610 + * try truncating it.
37612 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37616 + unsigned int mnt_flags;
37617 + struct au_xi_calc calc;
37618 + struct file *file;
37619 + struct au_branch *br;
37620 + struct au_xino *xi;
37622 + SiMustAnyLock(sb);
37624 + mnt_flags = au_mntflags(sb);
37625 + if (!au_opt_test(mnt_flags, XINO))
37628 + au_xi_calc(sb, h_ino, &calc);
37629 + br = au_sbr(sb, bindex);
37630 + xi = br->br_xino;
37631 + file = au_xino_file(xi, calc.idx);
37633 + /* create and write a new xino file asynchronously */
37634 + err = au_xino_new_async(sb, br, &calc, ino);
37636 + return 0; /* success */
37640 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37642 + br = au_sbr(sb, bindex);
37643 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37644 + && au_test_fs_trunc_xino(au_br_sb(br)))
37645 + xino_try_trunc(sb, br);
37646 + return 0; /* success */
37650 + AuIOErr("write failed (%d)\n", err);
37654 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37655 + size_t size, loff_t *pos);
37657 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37658 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37662 + mm_segment_t oldfs;
37668 + const int prevent_endless = 10;
37672 + oldfs = get_fs();
37673 + set_fs(KERNEL_DS);
37675 + err = func(file, buf.u, size, pos);
37676 + if (err == -EINTR
37677 + && !au_wkq_test()
37678 + && fatal_signal_pending(current)) {
37680 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37681 + BUG_ON(err == -EINTR);
37682 + oldfs = get_fs();
37683 + set_fs(KERNEL_DS);
37685 + } while (i++ < prevent_endless
37686 + && (err == -EAGAIN || err == -EINTR));
37689 +#if 0 /* reserved for future use */
37691 + fsnotify_access(file->f_path.dentry);
37697 +struct xino_fread_args {
37699 + vfs_readf_t func;
37700 + struct file *file;
37706 +static void call_xino_fread(void *args)
37708 + struct xino_fread_args *a = args;
37709 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37712 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37713 + size_t size, loff_t *pos)
37717 + struct xino_fread_args args = {
37726 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37727 + if (unlikely(wkq_err))
37733 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37734 + size_t size, loff_t *pos);
37736 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37737 + size_t size, loff_t *pos)
37740 + mm_segment_t oldfs;
37743 + const char __user *u;
37746 + const int prevent_endless = 10;
37750 + oldfs = get_fs();
37751 + set_fs(KERNEL_DS);
37753 + err = func(file, buf.u, size, pos);
37754 + if (err == -EINTR
37755 + && !au_wkq_test()
37756 + && fatal_signal_pending(current)) {
37758 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37759 + BUG_ON(err == -EINTR);
37760 + oldfs = get_fs();
37761 + set_fs(KERNEL_DS);
37763 + } while (i++ < prevent_endless
37764 + && (err == -EAGAIN || err == -EINTR));
37767 +#if 0 /* reserved for future use */
37769 + fsnotify_modify(file->f_path.dentry);
37775 +struct do_xino_fwrite_args {
37777 + vfs_writef_t func;
37778 + struct file *file;
37784 +static void call_do_xino_fwrite(void *args)
37786 + struct do_xino_fwrite_args *a = args;
37787 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37790 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37791 + size_t size, loff_t *pos)
37795 + struct do_xino_fwrite_args args = {
37805 + * it breaks RLIMIT_FSIZE and normal user's limit,
37806 + * users should care about quota and real 'filesystem full.'
37808 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37809 + if (unlikely(wkq_err))
37815 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37816 + size_t size, loff_t *pos)
37820 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37822 + err = do_xino_fwrite(func, file, buf, size, pos);
37826 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37833 +/* ---------------------------------------------------------------------- */
37836 + * inode number bitmap
37838 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37839 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37843 + AuDebugOn(bit < 0 || page_bits <= bit);
37844 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37848 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37850 + AuDebugOn(ino < AUFS_FIRST_INO);
37851 + ino -= AUFS_FIRST_INO;
37852 + *pindex = ino / page_bits;
37853 + *bit = ino % page_bits;
37856 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37861 + struct au_sbinfo *sbinfo;
37862 + struct file *xib;
37863 + unsigned long *p;
37865 + sbinfo = au_sbi(sb);
37866 + MtxMustLock(&sbinfo->si_xib_mtx);
37867 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37868 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37870 + if (pindex == sbinfo->si_xib_last_pindex)
37873 + xib = sbinfo->si_xib;
37874 + p = sbinfo->si_xib_buf;
37875 + pos = sbinfo->si_xib_last_pindex;
37876 + pos *= PAGE_SIZE;
37877 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37878 + if (unlikely(sz != PAGE_SIZE))
37882 + pos *= PAGE_SIZE;
37883 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37884 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37886 + memset(p, 0, PAGE_SIZE);
37887 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37889 + if (sz == PAGE_SIZE) {
37890 + sbinfo->si_xib_last_pindex = pindex;
37891 + return 0; /* success */
37895 + AuIOErr1("write failed (%zd)\n", sz);
37902 +static void au_xib_clear_bit(struct inode *inode)
37905 + unsigned long pindex;
37906 + struct super_block *sb;
37907 + struct au_sbinfo *sbinfo;
37909 + AuDebugOn(inode->i_nlink);
37911 + sb = inode->i_sb;
37912 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37913 + AuDebugOn(page_bits <= bit);
37914 + sbinfo = au_sbi(sb);
37915 + mutex_lock(&sbinfo->si_xib_mtx);
37916 + err = xib_pindex(sb, pindex);
37918 + clear_bit(bit, sbinfo->si_xib_buf);
37919 + sbinfo->si_xib_next_bit = bit;
37921 + mutex_unlock(&sbinfo->si_xib_mtx);
37924 +/* ---------------------------------------------------------------------- */
37927 + * truncate a xino bitmap file
37931 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37935 + unsigned long pindex;
37936 + loff_t pos, pend;
37937 + struct au_sbinfo *sbinfo;
37938 + vfs_readf_t func;
37940 + unsigned long *p;
37943 + sbinfo = au_sbi(sb);
37944 + MtxMustLock(&sbinfo->si_xib_mtx);
37945 + p = sbinfo->si_xib_buf;
37946 + func = sbinfo->si_xread;
37947 + pend = vfsub_f_size_read(file);
37949 + while (pos < pend) {
37950 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37952 + if (unlikely(sz <= 0))
37956 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37957 + if (unlikely(*ino < AUFS_FIRST_INO))
37960 + xib_calc_bit(*ino, &pindex, &bit);
37961 + AuDebugOn(page_bits <= bit);
37962 + err = xib_pindex(sb, pindex);
37974 +static int xib_restore(struct super_block *sb)
37977 + unsigned int nfile;
37978 + aufs_bindex_t bindex, bbot;
37980 + struct au_branch *br;
37981 + struct au_xino *xi;
37982 + struct file *file;
37985 + page = (void *)__get_free_page(GFP_NOFS);
37986 + if (unlikely(!page))
37990 + bbot = au_sbbot(sb);
37991 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37992 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37993 + br = au_sbr(sb, bindex);
37994 + xi = br->br_xino;
37995 + nfile = xi->xi_nfile;
37996 + for (i = 0; i < nfile; i++) {
37997 + file = au_xino_file(xi, i);
37999 + err = do_xib_restore(sb, file, page);
38002 + AuDbg("skip shared b%d\n", bindex);
38003 + free_page((unsigned long)page);
38009 +int au_xib_trunc(struct super_block *sb)
38014 + struct au_sbinfo *sbinfo;
38015 + unsigned long *p;
38016 + struct file *file;
38018 + SiMustWriteLock(sb);
38021 + sbinfo = au_sbi(sb);
38022 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38025 + file = sbinfo->si_xib;
38026 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38029 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38030 + err = PTR_ERR(file);
38031 + if (IS_ERR(file))
38033 + fput(sbinfo->si_xib);
38034 + sbinfo->si_xib = file;
38036 + p = sbinfo->si_xib_buf;
38037 + memset(p, 0, PAGE_SIZE);
38039 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38040 + if (unlikely(sz != PAGE_SIZE)) {
38042 + AuIOErr("err %d\n", err);
38048 + mutex_lock(&sbinfo->si_xib_mtx);
38049 + /* mnt_want_write() is unnecessary here */
38050 + err = xib_restore(sb);
38051 + mutex_unlock(&sbinfo->si_xib_mtx);
38057 +/* ---------------------------------------------------------------------- */
38059 +struct au_xino *au_xino_alloc(unsigned int nfile)
38061 + struct au_xino *xi;
38063 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38064 + if (unlikely(!xi))
38066 + xi->xi_nfile = nfile;
38067 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38068 + if (unlikely(!xi->xi_file))
38071 + xi->xi_nondir.total = 8; /* initial size */
38072 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38074 + if (unlikely(!xi->xi_nondir.array))
38077 + spin_lock_init(&xi->xi_nondir.spin);
38078 + init_waitqueue_head(&xi->xi_nondir.wqh);
38079 + mutex_init(&xi->xi_mtx);
38080 + /* init_waitqueue_head(&xi->xi_wq); */
38081 + /* atomic_set(&xi->xi_pending, 0); */
38082 + atomic_set(&xi->xi_truncating, 0);
38083 + kref_init(&xi->xi_kref);
38084 + goto out; /* success */
38087 + kfree(xi->xi_file);
38095 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38098 + struct au_xino *xi;
38101 + xi = au_xino_alloc(idx + 1);
38102 + if (unlikely(!xi)) {
38109 + xi->xi_file[idx] = file;
38110 + AuDebugOn(br->br_xino);
38111 + br->br_xino = xi;
38117 +static void au_xino_release(struct kref *kref)
38119 + struct au_xino *xi;
38122 + xi = container_of(kref, struct au_xino, xi_kref);
38123 + for (i = 0; i < xi->xi_nfile; i++)
38124 + if (xi->xi_file[i])
38125 + fput(xi->xi_file[i]);
38126 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38127 + AuDebugOn(xi->xi_nondir.array[i]);
38128 + mutex_destroy(&xi->xi_mtx);
38129 + kfree(xi->xi_file);
38130 + kfree(xi->xi_nondir.array);
38134 +int au_xino_put(struct au_branch *br)
38137 + struct au_xino *xi;
38140 + xi = br->br_xino;
38142 + br->br_xino = NULL;
38143 + ret = kref_put(&xi->xi_kref, au_xino_release);
38149 +/* ---------------------------------------------------------------------- */
38152 + * xino mount option handlers
38156 +static void xino_clear_xib(struct super_block *sb)
38158 + struct au_sbinfo *sbinfo;
38160 + SiMustWriteLock(sb);
38162 + sbinfo = au_sbi(sb);
38163 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38164 + if (sbinfo->si_xib)
38165 + fput(sbinfo->si_xib);
38166 + sbinfo->si_xib = NULL;
38167 + if (sbinfo->si_xib_buf)
38168 + free_page((unsigned long)sbinfo->si_xib_buf);
38169 + sbinfo->si_xib_buf = NULL;
38172 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38176 + struct au_sbinfo *sbinfo;
38177 + struct file *file;
38178 + struct super_block *xi_sb;
38180 + SiMustWriteLock(sb);
38182 + sbinfo = au_sbi(sb);
38183 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38184 + err = PTR_ERR(file);
38185 + if (IS_ERR(file))
38187 + if (sbinfo->si_xib)
38188 + fput(sbinfo->si_xib);
38189 + sbinfo->si_xib = file;
38190 + sbinfo->si_xread = vfs_readf(file);
38191 + sbinfo->si_xwrite = vfs_writef(file);
38192 + xi_sb = file_inode(file)->i_sb;
38193 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38194 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38196 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38197 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38200 + sbinfo->si_ximaxent /= sizeof(ino_t);
38203 + if (!sbinfo->si_xib_buf)
38204 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38205 + if (unlikely(!sbinfo->si_xib_buf))
38208 + sbinfo->si_xib_last_pindex = 0;
38209 + sbinfo->si_xib_next_bit = 0;
38210 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38212 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38213 + PAGE_SIZE, &pos);
38214 + if (unlikely(err != PAGE_SIZE))
38218 + goto out; /* success */
38221 + if (sbinfo->si_xib_buf)
38222 + free_page((unsigned long)sbinfo->si_xib_buf);
38223 + sbinfo->si_xib_buf = NULL;
38227 + fput(sbinfo->si_xib);
38228 + sbinfo->si_xib = NULL;
38234 +/* xino for each branch */
38235 +static void xino_clear_br(struct super_block *sb)
38237 + aufs_bindex_t bindex, bbot;
38238 + struct au_branch *br;
38240 + bbot = au_sbbot(sb);
38241 + for (bindex = 0; bindex <= bbot; bindex++) {
38242 + br = au_sbr(sb, bindex);
38248 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38249 + aufs_bindex_t bshared)
38251 + struct au_branch *brshared;
38253 + brshared = au_sbr(sb, bshared);
38254 + AuDebugOn(!brshared->br_xino);
38255 + AuDebugOn(!brshared->br_xino->xi_file);
38256 + if (br->br_xino != brshared->br_xino) {
38257 + au_xino_get(brshared);
38259 + br->br_xino = brshared->br_xino;
38263 +struct au_xino_do_set_br {
38264 + vfs_writef_t writef;
38265 + struct au_branch *br;
38267 + aufs_bindex_t bshared;
38270 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38271 + struct au_xino_do_set_br *args)
38274 + struct au_xi_calc calc;
38275 + struct file *file;
38276 + struct au_branch *br;
38277 + struct au_xi_new xinew = {
38282 + xinew.xi = br->br_xino;
38283 + au_xi_calc(sb, args->h_ino, &calc);
38284 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38285 + if (args->bshared >= 0)
38286 + /* shared xino */
38287 + au_xino_set_br_shared(sb, br, args->bshared);
38288 + else if (!xinew.xi) {
38290 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38291 + if (unlikely(err))
38295 + /* force re-creating */
38296 + xinew.xi = br->br_xino;
38297 + xinew.idx = calc.idx;
38298 + mutex_lock(&xinew.xi->xi_mtx);
38299 + file = au_xi_new(sb, &xinew);
38300 + mutex_unlock(&xinew.xi->xi_mtx);
38301 + err = PTR_ERR(file);
38302 + if (IS_ERR(file))
38304 + AuDebugOn(!file);
38306 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38307 + if (unlikely(err))
38315 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38318 + aufs_bindex_t bindex, bbot;
38319 + struct au_xino_do_set_br args;
38320 + struct inode *inode;
38322 + SiMustWriteLock(sb);
38324 + bbot = au_sbbot(sb);
38325 + inode = d_inode(sb->s_root);
38326 + args.writef = au_sbi(sb)->si_xwrite;
38327 + for (bindex = 0; bindex <= bbot; bindex++) {
38328 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38329 + args.br = au_sbr(sb, bindex);
38330 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38331 + err = au_xino_do_set_br(sb, path, &args);
38332 + if (unlikely(err))
38340 +void au_xino_clr(struct super_block *sb)
38342 + struct au_sbinfo *sbinfo;
38344 + au_xigen_clr(sb);
38345 + xino_clear_xib(sb);
38346 + xino_clear_br(sb);
38347 + dbgaufs_brs_del(sb, 0);
38348 + sbinfo = au_sbi(sb);
38349 + /* lvalue, do not call au_mntflags() */
38350 + au_opt_clr(sbinfo->si_mntflags, XINO);
38353 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38356 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38357 + struct qstr *dname, *cur_name;
38358 + struct file *cur_xino;
38359 + struct au_sbinfo *sbinfo;
38360 + struct path *path, *cur_path;
38362 + SiMustWriteLock(sb);
38365 + sbinfo = au_sbi(sb);
38366 + path = &xiopt->file->f_path;
38367 + dentry = path->dentry;
38368 + parent = dget_parent(dentry);
38371 + cur_xino = sbinfo->si_xib;
38373 + cur_path = &cur_xino->f_path;
38374 + cur_dentry = cur_path->dentry;
38375 + cur_parent = dget_parent(cur_dentry);
38376 + cur_name = &cur_dentry->d_name;
38377 + dname = &dentry->d_name;
38378 + skip = (cur_parent == parent
38379 + && au_qstreq(dname, cur_name));
38380 + dput(cur_parent);
38386 + au_opt_set(sbinfo->si_mntflags, XINO);
38387 + err = au_xino_set_xib(sb, path);
38388 + /* si_x{read,write} are set */
38390 + err = au_xigen_set(sb, path);
38392 + err = au_xino_set_br(sb, path);
38394 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38395 + goto out; /* success */
38399 + AuIOErr("failed setting xino(%d).\n", err);
38408 + * create a xinofile at the default place/path.
38410 +struct file *au_xino_def(struct super_block *sb)
38412 + struct file *file;
38414 + struct au_branch *br;
38415 + struct super_block *h_sb;
38416 + struct path path;
38417 + aufs_bindex_t bbot, bindex, bwr;
38420 + bbot = au_sbbot(sb);
38422 + for (bindex = 0; bindex <= bbot; bindex++) {
38423 + br = au_sbr(sb, bindex);
38424 + if (au_br_writable(br->br_perm)
38425 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38432 + file = ERR_PTR(-ENOMEM);
38433 + page = (void *)__get_free_page(GFP_NOFS);
38434 + if (unlikely(!page))
38436 + path.mnt = au_br_mnt(br);
38437 + path.dentry = au_h_dptr(sb->s_root, bwr);
38438 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38439 + file = (void *)p;
38440 + if (!IS_ERR(p)) {
38441 + strcat(p, "/" AUFS_XINO_FNAME);
38442 + AuDbg("%s\n", p);
38443 + file = au_xino_create(sb, p, /*silent*/0);
38445 + free_page((unsigned long)page);
38447 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
38448 + if (IS_ERR(file))
38450 + h_sb = file->f_path.dentry->d_sb;
38451 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38452 + pr_err("xino doesn't support %s(%s)\n",
38453 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38455 + file = ERR_PTR(-EINVAL);
38463 +/* ---------------------------------------------------------------------- */
38466 + * initialize the xinofile for the specified branch @br
38467 + * at the place/path where @base_file indicates.
38468 + * test whether another branch is on the same filesystem or not,
38469 + * if found then share the xinofile with another branch.
38471 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38472 + struct path *base)
38475 + struct au_xino_do_set_br args = {
38480 + args.writef = au_sbi(sb)->si_xwrite;
38481 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38483 + err = au_xino_do_set_br(sb, base, &args);
38484 + if (unlikely(err))
38490 +/* ---------------------------------------------------------------------- */
38493 + * get an unused inode number from bitmap
38495 +ino_t au_xino_new_ino(struct super_block *sb)
38498 + unsigned long *p, pindex, ul, pend;
38499 + struct au_sbinfo *sbinfo;
38500 + struct file *file;
38501 + int free_bit, err;
38503 + if (!au_opt_test(au_mntflags(sb), XINO))
38504 + return iunique(sb, AUFS_FIRST_INO);
38506 + sbinfo = au_sbi(sb);
38507 + mutex_lock(&sbinfo->si_xib_mtx);
38508 + p = sbinfo->si_xib_buf;
38509 + free_bit = sbinfo->si_xib_next_bit;
38510 + if (free_bit < page_bits && !test_bit(free_bit, p))
38511 + goto out; /* success */
38512 + free_bit = find_first_zero_bit(p, page_bits);
38513 + if (free_bit < page_bits)
38514 + goto out; /* success */
38516 + pindex = sbinfo->si_xib_last_pindex;
38517 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38518 + err = xib_pindex(sb, ul);
38519 + if (unlikely(err))
38521 + free_bit = find_first_zero_bit(p, page_bits);
38522 + if (free_bit < page_bits)
38523 + goto out; /* success */
38526 + file = sbinfo->si_xib;
38527 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38528 + for (ul = pindex + 1; ul <= pend; ul++) {
38529 + err = xib_pindex(sb, ul);
38530 + if (unlikely(err))
38532 + free_bit = find_first_zero_bit(p, page_bits);
38533 + if (free_bit < page_bits)
38534 + goto out; /* success */
38539 + set_bit(free_bit, p);
38540 + sbinfo->si_xib_next_bit = free_bit + 1;
38541 + pindex = sbinfo->si_xib_last_pindex;
38542 + mutex_unlock(&sbinfo->si_xib_mtx);
38543 + ino = xib_calc_ino(pindex, free_bit);
38544 + AuDbg("i%lu\n", (unsigned long)ino);
38547 + mutex_unlock(&sbinfo->si_xib_mtx);
38552 +/* for s_op->delete_inode() */
38553 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38556 + unsigned int mnt_flags;
38557 + aufs_bindex_t bindex, bbot, bi;
38558 + unsigned char try_trunc;
38559 + struct au_iinfo *iinfo;
38560 + struct super_block *sb;
38561 + struct au_hinode *hi;
38562 + struct inode *h_inode;
38563 + struct au_branch *br;
38564 + vfs_writef_t xwrite;
38565 + struct au_xi_calc calc;
38566 + struct file *file;
38568 + AuDebugOn(au_is_bad_inode(inode));
38570 + sb = inode->i_sb;
38571 + mnt_flags = au_mntflags(sb);
38572 + if (!au_opt_test(mnt_flags, XINO)
38573 + || inode->i_ino == AUFS_ROOT_INO)
38577 + au_xigen_inc(inode);
38578 + au_xib_clear_bit(inode);
38581 + iinfo = au_ii(inode);
38582 + bindex = iinfo->ii_btop;
38586 + xwrite = au_sbi(sb)->si_xwrite;
38587 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38588 + hi = au_hinode(iinfo, bindex);
38589 + bbot = iinfo->ii_bbot;
38590 + for (; bindex <= bbot; bindex++, hi++) {
38591 + h_inode = hi->hi_inode;
38593 + || (!unlinked && h_inode->i_nlink))
38596 + /* inode may not be revalidated */
38597 + bi = au_br_index(sb, hi->hi_id);
38601 + br = au_sbr(sb, bi);
38602 + au_xi_calc(sb, h_inode->i_ino, &calc);
38603 + file = au_xino_file(br->br_xino, calc.idx);
38604 + if (IS_ERR_OR_NULL(file))
38607 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38608 + if (!err && try_trunc
38609 + && au_test_fs_trunc_xino(au_br_sb(br)))
38610 + xino_try_trunc(sb, br);
38614 +/* ---------------------------------------------------------------------- */
38616 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38618 + int found, total, i;
38621 + total = xi->xi_nondir.total;
38622 + for (i = 0; i < total; i++) {
38623 + if (xi->xi_nondir.array[i] != h_ino)
38632 +static int au_xinondir_expand(struct au_xino *xi)
38637 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38640 + sz = xi->xi_nondir.total * sizeof(ino_t);
38641 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38643 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38644 + /*may_shrink*/0);
38646 + xi->xi_nondir.array = p;
38647 + xi->xi_nondir.total <<= 1;
38648 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38656 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38657 + ino_t h_ino, int idx)
38659 + struct au_xino *xi;
38661 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38662 + xi = au_sbr(sb, bindex)->br_xino;
38663 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38665 + spin_lock(&xi->xi_nondir.spin);
38666 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38667 + xi->xi_nondir.array[idx] = 0;
38668 + spin_unlock(&xi->xi_nondir.spin);
38669 + wake_up_all(&xi->xi_nondir.wqh);
38672 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38675 + int err, found, empty;
38676 + struct au_xino *xi;
38680 + if (!au_opt_test(au_mntflags(sb), XINO))
38681 + goto out; /* no xino */
38683 + xi = au_sbr(sb, bindex)->br_xino;
38686 + spin_lock(&xi->xi_nondir.spin);
38687 + found = au_xinondir_find(xi, h_ino);
38688 + if (found == -1) {
38689 + empty = au_xinondir_find(xi, /*h_ino*/0);
38690 + if (empty == -1) {
38691 + empty = xi->xi_nondir.total;
38692 + err = au_xinondir_expand(xi);
38693 + if (unlikely(err))
38696 + xi->xi_nondir.array[empty] = h_ino;
38699 + spin_unlock(&xi->xi_nondir.spin);
38700 + wait_event(xi->xi_nondir.wqh,
38701 + xi->xi_nondir.array[found] != h_ino);
38706 + spin_unlock(&xi->xi_nondir.spin);
38711 +/* ---------------------------------------------------------------------- */
38713 +int au_xino_path(struct seq_file *seq, struct file *file)
38717 + err = au_seq_path(seq, &file->f_path);
38718 + if (unlikely(err))
38721 +#define Deleted "\\040(deleted)"
38722 + seq->count -= sizeof(Deleted) - 1;
38723 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38724 + sizeof(Deleted) - 1));
38730 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38731 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38732 +++ linux/include/uapi/linux/aufs_type.h 2018-10-23 12:33:35.602709228 +0200
38734 +/* SPDX-License-Identifier: GPL-2.0 */
38736 + * Copyright (C) 2005-2018 Junjiro R. Okajima
38738 + * This program, aufs is free software; you can redistribute it and/or modify
38739 + * it under the terms of the GNU General Public License as published by
38740 + * the Free Software Foundation; either version 2 of the License, or
38741 + * (at your option) any later version.
38743 + * This program is distributed in the hope that it will be useful,
38744 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38746 + * GNU General Public License for more details.
38748 + * You should have received a copy of the GNU General Public License
38749 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38752 +#ifndef __AUFS_TYPE_H__
38753 +#define __AUFS_TYPE_H__
38755 +#define AUFS_NAME "aufs"
38759 + * define it before including all other headers.
38760 + * sched.h may use pr_* macros before defining "current", so define the
38761 + * no-current version first, and re-define later.
38763 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38764 +#include <linux/sched.h>
38766 +#define pr_fmt(fmt) \
38767 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38768 + (int)sizeof(current->comm), current->comm, current->pid
38770 +#include <stdint.h>
38771 +#include <sys/types.h>
38772 +#endif /* __KERNEL__ */
38774 +#include <linux/limits.h>
38776 +#define AUFS_VERSION "4.x-rcN-20181022"
38778 +/* todo? move this to linux-2.6.19/include/magic.h */
38779 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38781 +/* ---------------------------------------------------------------------- */
38783 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38784 +typedef int8_t aufs_bindex_t;
38785 +#define AUFS_BRANCH_MAX 127
38787 +typedef int16_t aufs_bindex_t;
38788 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38789 +#define AUFS_BRANCH_MAX 511
38790 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38791 +#define AUFS_BRANCH_MAX 1023
38792 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38793 +#define AUFS_BRANCH_MAX 32767
38798 +#ifndef AUFS_BRANCH_MAX
38799 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38801 +#endif /* __KERNEL__ */
38803 +/* ---------------------------------------------------------------------- */
38805 +#define AUFS_FSTYPE AUFS_NAME
38807 +#define AUFS_ROOT_INO 2
38808 +#define AUFS_FIRST_INO 11
38810 +#define AUFS_WH_PFX ".wh."
38811 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38812 +#define AUFS_WH_TMP_LEN 4
38813 +/* a limit for rmdir/rename a dir and copyup */
38814 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38815 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38817 + - AUFS_WH_TMP_LEN) /* hex */
38818 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38819 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38820 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38821 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38822 +#define AUFS_DIRWH_DEF 3
38823 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38824 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38825 +#define AUFS_RDBLK_DEF 512 /* bytes */
38826 +#define AUFS_RDHASH_DEF 32
38827 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38828 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38829 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38830 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38831 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38833 +/* pseudo-link maintenace under /proc */
38834 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38835 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38836 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38838 +/* dirren, renamed dir */
38839 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38840 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38841 +/* whiteouted doubly */
38842 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38843 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38845 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38846 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38848 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38849 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38850 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38852 +/* doubly whiteouted */
38853 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38854 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38855 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38857 +/* branch permissions and attributes */
38858 +#define AUFS_BRPERM_RW "rw"
38859 +#define AUFS_BRPERM_RO "ro"
38860 +#define AUFS_BRPERM_RR "rr"
38861 +#define AUFS_BRATTR_COO_REG "coo_reg"
38862 +#define AUFS_BRATTR_COO_ALL "coo_all"
38863 +#define AUFS_BRATTR_FHSM "fhsm"
38864 +#define AUFS_BRATTR_UNPIN "unpin"
38865 +#define AUFS_BRATTR_ICEX "icex"
38866 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38867 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38868 +#define AUFS_BRATTR_ICEX_TR "icextr"
38869 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38870 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38871 +#define AUFS_BRRATTR_WH "wh"
38872 +#define AUFS_BRWATTR_NLWH "nolwh"
38873 +#define AUFS_BRWATTR_MOO "moo"
38875 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38876 +#define AuBrPerm_RO (1 << 1) /* readonly */
38877 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38878 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38880 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38881 +#define AuBrAttr_COO_ALL (1 << 4)
38882 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38884 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38885 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38886 + branch. meaningless since
38887 + linux-3.18-rc1 */
38889 +/* ignore error in copying XATTR */
38890 +#define AuBrAttr_ICEX_SEC (1 << 7)
38891 +#define AuBrAttr_ICEX_SYS (1 << 8)
38892 +#define AuBrAttr_ICEX_TR (1 << 9)
38893 +#define AuBrAttr_ICEX_USR (1 << 10)
38894 +#define AuBrAttr_ICEX_OTH (1 << 11)
38895 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38896 + | AuBrAttr_ICEX_SYS \
38897 + | AuBrAttr_ICEX_TR \
38898 + | AuBrAttr_ICEX_USR \
38899 + | AuBrAttr_ICEX_OTH)
38901 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38902 +#define AuBrRAttr_Mask AuBrRAttr_WH
38904 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38905 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38906 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38908 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38910 +/* #warning test userspace */
38912 +#ifndef CONFIG_AUFS_FHSM
38913 +#undef AuBrAttr_FHSM
38914 +#define AuBrAttr_FHSM 0
38916 +#ifndef CONFIG_AUFS_XATTR
38917 +#undef AuBrAttr_ICEX
38918 +#define AuBrAttr_ICEX 0
38919 +#undef AuBrAttr_ICEX_SEC
38920 +#define AuBrAttr_ICEX_SEC 0
38921 +#undef AuBrAttr_ICEX_SYS
38922 +#define AuBrAttr_ICEX_SYS 0
38923 +#undef AuBrAttr_ICEX_TR
38924 +#define AuBrAttr_ICEX_TR 0
38925 +#undef AuBrAttr_ICEX_USR
38926 +#define AuBrAttr_ICEX_USR 0
38927 +#undef AuBrAttr_ICEX_OTH
38928 +#define AuBrAttr_ICEX_OTH 0
38932 +/* the longest combination */
38933 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38934 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38935 + "+" AUFS_BRATTR_COO_REG \
38936 + "+" AUFS_BRATTR_FHSM \
38937 + "+" AUFS_BRATTR_UNPIN \
38938 + "+" AUFS_BRATTR_ICEX_SEC \
38939 + "+" AUFS_BRATTR_ICEX_SYS \
38940 + "+" AUFS_BRATTR_ICEX_USR \
38941 + "+" AUFS_BRATTR_ICEX_OTH \
38942 + "+" AUFS_BRWATTR_NLWH)
38945 + char a[AuBrPermStrSz];
38946 +} au_br_perm_str_t;
38948 +static inline int au_br_writable(int brperm)
38950 + return brperm & AuBrPerm_RW;
38953 +static inline int au_br_whable(int brperm)
38955 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38958 +static inline int au_br_wh_linkable(int brperm)
38960 + return !(brperm & AuBrWAttr_NoLinkWH);
38963 +static inline int au_br_cmoo(int brperm)
38965 + return brperm & AuBrAttr_CMOO_Mask;
38968 +static inline int au_br_fhsm(int brperm)
38970 + return brperm & AuBrAttr_FHSM;
38973 +/* ---------------------------------------------------------------------- */
38977 + /* readdir in userspace */
38981 + AuCtl_WBR_FD, /* pathconf wrapper */
38982 + AuCtl_IBUSY, /* busy inode */
38983 + AuCtl_MVDOWN, /* move-down */
38984 + AuCtl_BR, /* info about branches */
38985 + AuCtl_FHSM_FD /* connection for fhsm */
38988 +/* borrowed from linux/include/linux/kernel.h */
38990 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38991 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38994 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38996 +#define __aligned(x) __attribute__((aligned(x)))
39001 +#define __packed __attribute__((packed))
39005 +struct au_rdu_cookie {
39010 + uint32_t generation;
39013 +struct au_rdu_ent {
39022 +static inline int au_rdu_len(int nlen)
39024 + /* include the terminating NULL */
39025 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39026 + sizeof(uint64_t));
39029 +union au_rdu_ent_ul {
39030 + struct au_rdu_ent __user *e;
39042 + uint64_t sz; /* AuCtl_RDU */
39043 + uint64_t nent; /* AuCtl_RDU_INO */
39045 + union au_rdu_ent_ul ent;
39046 + uint16_t verify[AufsCtlRduV_End];
39048 + /* input/output */
39052 + union au_rdu_ent_ul tail;
39053 + /* number of entries which were added in a single call */
39058 + struct au_rdu_cookie cookie;
39061 +/* ---------------------------------------------------------------------- */
39063 +/* dirren. the branch is identified by the filename who contains this */
39064 +struct au_drinfo {
39067 + uint8_t oldnamelen;
39068 + uint64_t _padding;
39070 + uint8_t oldname[0];
39073 +struct au_drinfo_fdata {
39075 + struct au_drinfo drinfo;
39078 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39080 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39082 +/* ---------------------------------------------------------------------- */
39084 +struct aufs_wbr_fd {
39089 +/* ---------------------------------------------------------------------- */
39091 +struct aufs_ibusy {
39092 + uint64_t ino, h_ino;
39096 +/* ---------------------------------------------------------------------- */
39098 +/* error code for move-down */
39099 +/* the actual message strings are implemented in aufs-util.git */
39101 + EAU_MVDOWN_OPAQUE = 1,
39102 + EAU_MVDOWN_WHITEOUT,
39103 + EAU_MVDOWN_UPPER,
39104 + EAU_MVDOWN_BOTTOM,
39105 + EAU_MVDOWN_NOUPPER,
39106 + EAU_MVDOWN_NOLOWERBR,
39110 +/* flags for move-down */
39111 +#define AUFS_MVDOWN_DMSG 1
39112 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39113 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39114 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39115 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39116 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39117 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39118 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39119 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39120 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39121 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39122 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39123 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39125 +/* index for move-down */
39127 + AUFS_MVDOWN_UPPER,
39128 + AUFS_MVDOWN_LOWER,
39129 + AUFS_MVDOWN_NARRAY
39133 + * additional info of move-down
39134 + * number of free blocks and inodes.
39135 + * subset of struct kstatfs, but smaller and always 64bit.
39137 +struct aufs_stfs {
39138 + uint64_t f_blocks;
39139 + uint64_t f_bavail;
39140 + uint64_t f_files;
39141 + uint64_t f_ffree;
39144 +struct aufs_stbr {
39145 + int16_t brid; /* optional input */
39146 + int16_t bindex; /* output */
39147 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39150 +struct aufs_mvdown {
39151 + uint32_t flags; /* input/output */
39152 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39153 + int8_t au_errno; /* output */
39156 +/* ---------------------------------------------------------------------- */
39158 +union aufs_brinfo {
39159 + /* PATH_MAX may differ between kernel-space and user-space */
39160 + char _spacer[4096];
39168 +/* ---------------------------------------------------------------------- */
39170 +#define AuCtlType 'A'
39171 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39172 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39173 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39174 + struct aufs_wbr_fd)
39175 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39176 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39177 + struct aufs_mvdown)
39178 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39179 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39181 +#endif /* __AUFS_TYPE_H__ */
39182 SPDX-License-Identifier: GPL-2.0
39183 aufs4.x-rcN loopback patch
39185 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39186 index 9e534a3..74cd74e 100644
39187 --- a/drivers/block/loop.c
39188 +++ b/drivers/block/loop.c
39189 @@ -626,6 +626,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39193 +static struct file *loop_real_file(struct file *file)
39195 + struct file *f = NULL;
39197 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39198 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39202 static void loop_reread_partitions(struct loop_device *lo,
39203 struct block_device *bdev)
39205 @@ -690,6 +699,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39208 struct file *file, *old_file;
39209 + struct file *f, *virt_file = NULL, *old_virt_file;
39213 @@ -705,12 +715,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39217 + f = loop_real_file(file);
39219 + virt_file = file;
39224 error = loop_validate_file(file, bdev);
39228 old_file = lo->lo_backing_file;
39229 + old_virt_file = lo->lo_backing_virt_file;
39233 @@ -722,6 +739,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39234 blk_mq_freeze_queue(lo->lo_queue);
39235 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39236 lo->lo_backing_file = file;
39237 + lo->lo_backing_virt_file = virt_file;
39238 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39239 mapping_set_gfp_mask(file->f_mapping,
39240 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39241 @@ -729,12 +747,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39242 blk_mq_unfreeze_queue(lo->lo_queue);
39245 + if (old_virt_file)
39246 + fput(old_virt_file);
39247 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
39248 loop_reread_partitions(lo, bdev);
39258 @@ -922,7 +944,7 @@ static int loop_prepare_queue(struct loop_device *lo)
39259 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39260 struct block_device *bdev, unsigned int arg)
39262 - struct file *file;
39263 + struct file *file, *f, *virt_file = NULL;
39264 struct inode *inode;
39265 struct address_space *mapping;
39267 @@ -936,6 +958,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39271 + f = loop_real_file(file);
39273 + virt_file = file;
39279 if (lo->lo_state != Lo_unbound)
39280 @@ -968,6 +996,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39281 lo->lo_device = bdev;
39282 lo->lo_flags = lo_flags;
39283 lo->lo_backing_file = file;
39284 + lo->lo_backing_virt_file = virt_file;
39285 lo->transfer = NULL;
39287 lo->lo_sizelimit = 0;
39288 @@ -1001,6 +1030,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39295 /* This is safe: open() is still holding a reference. */
39296 module_put(THIS_MODULE);
39297 @@ -1047,6 +1078,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39298 static int loop_clr_fd(struct loop_device *lo)
39300 struct file *filp = lo->lo_backing_file;
39301 + struct file *virt_filp = lo->lo_backing_virt_file;
39302 gfp_t gfp = lo->old_gfp_mask;
39303 struct block_device *bdev = lo->lo_device;
39305 @@ -1078,6 +1110,7 @@ static int loop_clr_fd(struct loop_device *lo)
39306 spin_lock_irq(&lo->lo_lock);
39307 lo->lo_state = Lo_rundown;
39308 lo->lo_backing_file = NULL;
39309 + lo->lo_backing_virt_file = NULL;
39310 spin_unlock_irq(&lo->lo_lock);
39312 loop_release_xfer(lo);
39313 @@ -1126,6 +1159,8 @@ static int loop_clr_fd(struct loop_device *lo)
39314 * bd_mutex which is usually taken before lo_ctl_mutex.
39322 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39323 index 4d42c7a..a4974ee 100644
39324 --- a/drivers/block/loop.h
39325 +++ b/drivers/block/loop.h
39326 @@ -46,7 +46,7 @@ struct loop_device {
39327 int (*ioctl)(struct loop_device *, int cmd,
39328 unsigned long arg);
39330 - struct file * lo_backing_file;
39331 + struct file * lo_backing_file, *lo_backing_virt_file;
39332 struct block_device *lo_device;
39335 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39336 index 5309874..1a334cf 100644
39337 --- a/fs/aufs/f_op.c
39338 +++ b/fs/aufs/f_op.c
39339 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39340 if (IS_ERR(h_file))
39343 - if (au_test_loopback_kthread()) {
39344 + if (0 && au_test_loopback_kthread()) {
39345 au_warn_loopback(h_file->f_path.dentry->d_sb);
39346 if (file->f_mapping != h_file->f_mapping) {
39347 file->f_mapping = h_file->f_mapping;
39348 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39349 index 3d84349..a642de5 100644
39350 --- a/fs/aufs/loop.c
39351 +++ b/fs/aufs/loop.c
39352 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39353 symbol_put(loop_backing_file);
39354 kfree(au_warn_loopback_array);
39357 +/* ---------------------------------------------------------------------- */
39359 +/* support the loopback block device insude aufs */
39361 +struct file *aufs_real_loop(struct file *file)
39365 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39366 + fi_read_lock(file);
39367 + f = au_hf_top(file);
39368 + fi_read_unlock(file);
39372 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39373 index 05d703d..6bb23c8 100644
39374 --- a/fs/aufs/loop.h
39375 +++ b/fs/aufs/loop.h
39376 @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb);
39378 int au_loopback_init(void);
39379 void au_loopback_fin(void);
39381 +struct file *aufs_real_loop(struct file *file);
39383 +AuStub(struct file *, loop_backing_file, return NULL)
39385 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
39386 struct dentry *h_adding)
39387 AuStubInt0(au_test_loopback_kthread, void)
39388 @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39390 AuStubInt0(au_loopback_init, void)
39391 AuStubVoid(au_loopback_fin, void)
39393 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39394 #endif /* BLK_DEV_LOOP */
39396 #endif /* __KERNEL__ */
39397 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39398 index 777503e..7130061 100644
39399 --- a/fs/aufs/super.c
39400 +++ b/fs/aufs/super.c
39401 @@ -845,7 +845,10 @@ static const struct super_operations aufs_sop = {
39402 .statfs = aufs_statfs,
39403 .put_super = aufs_put_super,
39404 .sync_fs = aufs_sync_fs,
39405 - .remount_fs = aufs_remount_fs
39406 + .remount_fs = aufs_remount_fs,
39407 +#ifdef CONFIG_AUFS_BDEV_LOOP
39408 + .real_loop = aufs_real_loop
39412 /* ---------------------------------------------------------------------- */
39413 diff --git a/include/linux/fs.h b/include/linux/fs.h
39414 index 7fb92a9..cff3ca3 100644
39415 --- a/include/linux/fs.h
39416 +++ b/include/linux/fs.h
39417 @@ -1882,6 +1882,10 @@ struct super_operations {
39418 struct shrink_control *);
39419 long (*free_cached_objects)(struct super_block *,
39420 struct shrink_control *);
39421 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39423 + struct file *(*real_loop)(struct file *);