1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 7aee6d6..ec92031 100644
7 @@ -248,6 +248,7 @@ source "fs/pstore/Kconfig"
8 source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/exofs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 7bbaca9..a026491 100644
19 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 aufs4.x-rcN base patch
26 diff --git a/MAINTAINERS b/MAINTAINERS
27 index af0cb69..d360d2e 100644
30 @@ -2465,6 +2465,19 @@ F: include/linux/audit.h
31 F: include/uapi/linux/audit.h
34 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
35 +M: "J. R. Okajima" <hooanon05g@gmail.com>
36 +L: linux-unionfs@vger.kernel.org
37 +L: aufs-users@lists.sourceforge.net (members only)
38 +W: http://aufs.sourceforge.net
39 +T: git://github.com/sfjro/aufs4-linux.git
41 +F: Documentation/filesystems/aufs/
42 +F: Documentation/ABI/testing/debugfs-aufs
43 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: include/uapi/linux/aufs_type.h
47 AUXILIARY DISPLAY DRIVERS
48 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
49 W: http://miguelojeda.es/auxdisplay.htm
50 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
51 index 85de673..d44de9d 100644
52 --- a/drivers/block/loop.c
53 +++ b/drivers/block/loop.c
54 @@ -686,6 +686,24 @@ static inline int is_loop_device(struct file *file)
55 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
60 + * no get/put for file.
62 +struct file *loop_backing_file(struct super_block *sb)
65 + struct loop_device *l;
68 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
69 + l = sb->s_bdev->bd_disk->private_data;
70 + ret = l->lo_backing_file;
74 +EXPORT_SYMBOL_GPL(loop_backing_file);
76 /* loop sysfs attributes */
78 static ssize_t loop_attr_show(struct device *dev, char *page,
79 diff --git a/fs/dcache.c b/fs/dcache.c
80 index f901413..e3719a5 100644
83 @@ -1197,7 +1197,7 @@ enum d_walk_ret {
85 * The @enter() and @finish() callbacks are called with d_lock held.
87 -static void d_walk(struct dentry *parent, void *data,
88 +void d_walk(struct dentry *parent, void *data,
89 enum d_walk_ret (*enter)(void *, struct dentry *),
90 void (*finish)(void *))
92 diff --git a/fs/fcntl.c b/fs/fcntl.c
93 index 448a111..f51c2cf 100644
98 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
100 -static int setfl(int fd, struct file * filp, unsigned long arg)
101 +int setfl(int fd, struct file * filp, unsigned long arg)
103 struct inode * inode = file_inode(filp);
105 @@ -62,6 +62,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
107 if (filp->f_op->check_flags)
108 error = filp->f_op->check_flags(arg);
109 + if (!error && filp->f_op->setfl)
110 + error = filp->f_op->setfl(filp, arg);
114 diff --git a/fs/inode.c b/fs/inode.c
115 index d1e35b5..f7800d6 100644
118 @@ -1655,7 +1655,7 @@ EXPORT_SYMBOL(generic_update_time);
119 * This does the actual work of updating an inodes time or version. Must have
120 * had called mnt_want_write() before calling this.
122 -static int update_time(struct inode *inode, struct timespec *time, int flags)
123 +int update_time(struct inode *inode, struct timespec *time, int flags)
125 int (*update_time)(struct inode *, struct timespec *, int);
127 diff --git a/fs/namespace.c b/fs/namespace.c
128 index d18deb4..e5a4a7f 100644
131 @@ -846,6 +846,12 @@ static inline int check_mnt(struct mount *mnt)
132 return mnt->mnt_ns == current->nsproxy->mnt_ns;
135 +/* for aufs, CONFIG_AUFS_BR_FUSE */
136 +int is_current_mnt_ns(struct vfsmount *mnt)
138 + return check_mnt(real_mount(mnt));
142 * vfsmount lock must be held for write
144 diff --git a/fs/read_write.c b/fs/read_write.c
145 index f0d4b16..6aa8c7a 100644
146 --- a/fs/read_write.c
147 +++ b/fs/read_write.c
148 @@ -483,6 +483,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
152 +vfs_readf_t vfs_readf(struct file *file)
154 + const struct file_operations *fop = file->f_op;
158 + if (fop->read_iter)
159 + return new_sync_read;
160 + return ERR_PTR(-ENOSYS);
163 +vfs_writef_t vfs_writef(struct file *file)
165 + const struct file_operations *fop = file->f_op;
169 + if (fop->write_iter)
170 + return new_sync_write;
171 + return ERR_PTR(-ENOSYS);
174 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
177 diff --git a/fs/splice.c b/fs/splice.c
178 index f3084cc..eb888c6 100644
181 @@ -837,8 +837,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
183 * Attempt to initiate a splice from pipe to file.
185 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
186 - loff_t *ppos, size_t len, unsigned int flags)
187 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
188 + loff_t *ppos, size_t len, unsigned int flags)
190 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
191 loff_t *, size_t, unsigned int);
192 @@ -854,9 +854,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
194 * Attempt to initiate a splice from a file to a pipe.
196 -static long do_splice_to(struct file *in, loff_t *ppos,
197 - struct pipe_inode_info *pipe, size_t len,
198 - unsigned int flags)
199 +long do_splice_to(struct file *in, loff_t *ppos,
200 + struct pipe_inode_info *pipe, size_t len,
201 + unsigned int flags)
203 ssize_t (*splice_read)(struct file *, loff_t *,
204 struct pipe_inode_info *, size_t, unsigned int);
205 diff --git a/fs/sync.c b/fs/sync.c
206 index a576aa2..eb61780 100644
210 * wait == 1 case since in that case write_inode() functions do
211 * sync_dirty_buffer() and thus effectively write one block at a time.
213 -static int __sync_filesystem(struct super_block *sb, int wait)
214 +int __sync_filesystem(struct super_block *sb, int wait)
218 diff --git a/include/linux/file.h b/include/linux/file.h
219 index 61eb82c..e700888 100644
220 --- a/include/linux/file.h
221 +++ b/include/linux/file.h
222 @@ -19,6 +19,7 @@ struct dentry;
224 extern struct file *alloc_file(const struct path *, fmode_t mode,
225 const struct file_operations *fop);
226 +extern struct file *get_empty_filp(void);
228 static inline void fput_light(struct file *file, int fput_needed)
230 diff --git a/include/linux/fs.h b/include/linux/fs.h
231 index 13dab19..8ab6566 100644
232 --- a/include/linux/fs.h
233 +++ b/include/linux/fs.h
234 @@ -1264,6 +1264,7 @@ extern void fasync_free(struct fasync_struct *);
235 /* can be called from interrupts */
236 extern void kill_fasync(struct fasync_struct **, int, int);
238 +extern int setfl(int fd, struct file * filp, unsigned long arg);
239 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
240 extern int f_setown(struct file *filp, unsigned long arg, int force);
241 extern void f_delown(struct file *filp);
242 @@ -1710,6 +1711,7 @@ struct file_operations {
243 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
244 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
245 int (*check_flags)(int);
246 + int (*setfl)(struct file *, unsigned long);
247 int (*flock) (struct file *, int, struct file_lock *);
248 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
249 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
250 @@ -1780,6 +1782,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
251 struct iovec *fast_pointer,
252 struct iovec **ret_pointer);
254 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
255 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
257 +vfs_readf_t vfs_readf(struct file *file);
258 +vfs_writef_t vfs_writef(struct file *file);
260 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
261 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
262 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
263 @@ -2182,6 +2190,7 @@ extern int current_umask(void);
264 extern void ihold(struct inode * inode);
265 extern void iput(struct inode *);
266 extern int generic_update_time(struct inode *, struct timespec *, int);
267 +extern int update_time(struct inode *, struct timespec *, int);
270 extern struct kobject *fs_kobj;
271 @@ -2462,6 +2471,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
275 +extern int __sync_filesystem(struct super_block *, int);
276 extern int sync_filesystem(struct super_block *);
277 extern const struct file_operations def_blk_fops;
278 extern const struct file_operations def_chr_fops;
279 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
280 index bfa8e0b..728d810 100644
281 --- a/include/linux/lockdep.h
282 +++ b/include/linux/lockdep.h
283 @@ -405,6 +405,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
284 return lock->key == key;
287 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
292 @@ -529,6 +531,7 @@ struct lock_class_key { };
294 #define lockdep_depth(tsk) (0)
296 +#define lockdep_is_held(lock) (1)
297 #define lockdep_is_held_type(l, r) (1)
299 #define lockdep_assert_held(l) do { (void)(l); } while (0)
300 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
301 index 12b2ab5..8b810d1 100644
302 --- a/include/linux/mnt_namespace.h
303 +++ b/include/linux/mnt_namespace.h
305 struct mnt_namespace;
307 struct user_namespace;
310 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
311 struct user_namespace *, struct fs_struct *);
312 extern void put_mnt_ns(struct mnt_namespace *ns);
314 +extern int is_current_mnt_ns(struct vfsmount *mnt);
316 extern const struct file_operations proc_mounts_operations;
317 extern const struct file_operations proc_mountinfo_operations;
318 extern const struct file_operations proc_mountstats_operations;
319 diff --git a/include/linux/splice.h b/include/linux/splice.h
320 index db42746..12f3a5a 100644
321 --- a/include/linux/splice.h
322 +++ b/include/linux/splice.h
323 @@ -86,4 +86,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
325 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
326 extern const struct pipe_buf_operations default_pipe_buf_ops;
328 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
329 + loff_t *ppos, size_t len, unsigned int flags);
330 +extern long do_splice_to(struct file *in, loff_t *ppos,
331 + struct pipe_inode_info *pipe, size_t len,
332 + unsigned int flags);
334 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
335 index e36e652..bc97a97 100644
336 --- a/kernel/locking/lockdep.c
337 +++ b/kernel/locking/lockdep.c
338 @@ -144,7 +144,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
339 unsigned long nr_lock_classes;
340 static struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
342 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
343 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
345 if (!hlock->class_idx) {
347 @@ -155,6 +155,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
349 return lock_classes + hlock->class_idx - 1;
351 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
353 #ifdef CONFIG_LOCK_STAT
354 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
355 aufs4.x-rcN mmap patch
357 diff --git a/fs/proc/base.c b/fs/proc/base.c
358 index ad3b076..ad4a50d 100644
361 @@ -1987,7 +1987,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
362 down_read(&mm->mmap_sem);
363 vma = find_exact_vma(mm, vm_start, vm_end);
364 if (vma && vma->vm_file) {
365 - *path = vma->vm_file->f_path;
366 + *path = vma_pr_or_file(vma)->f_path;
370 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
371 index 7563437..7c0dc0f 100644
372 --- a/fs/proc/nommu.c
373 +++ b/fs/proc/nommu.c
374 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
375 file = region->vm_file;
378 - struct inode *inode = file_inode(region->vm_file);
379 + struct inode *inode;
381 + file = vmr_pr_or_file(region);
382 + inode = file_inode(file);
383 dev = inode->i_sb->s_dev;
386 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
387 index 5589b4b..f60aea2 100644
388 --- a/fs/proc/task_mmu.c
389 +++ b/fs/proc/task_mmu.c
390 @@ -309,7 +309,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
391 const char *name = NULL;
394 - struct inode *inode = file_inode(vma->vm_file);
395 + struct inode *inode;
397 + file = vma_pr_or_file(vma);
398 + inode = file_inode(file);
399 dev = inode->i_sb->s_dev;
401 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
402 @@ -1734,7 +1737,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
403 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
404 struct vm_area_struct *vma = v;
405 struct numa_maps *md = &numa_priv->md;
406 - struct file *file = vma->vm_file;
407 + struct file *file = vma_pr_or_file(vma);
408 struct mm_struct *mm = vma->vm_mm;
409 struct mm_walk walk = {
410 .hugetlb_entry = gather_hugetlb_stats,
411 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
412 index b00b7660..93e8a86 100644
413 --- a/fs/proc/task_nommu.c
414 +++ b/fs/proc/task_nommu.c
415 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
419 - struct inode *inode = file_inode(vma->vm_file);
420 + struct inode *inode;
422 + file = vma_pr_or_file(vma);
423 + inode = file_inode(file);
424 dev = inode->i_sb->s_dev;
426 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
427 diff --git a/include/linux/mm.h b/include/linux/mm.h
428 index 065d99d..04486c3 100644
429 --- a/include/linux/mm.h
430 +++ b/include/linux/mm.h
431 @@ -1348,6 +1348,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
435 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
436 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
438 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
439 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
441 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
443 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
445 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
446 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
449 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
450 +extern void vmr_do_fput(struct vm_region *, const char[], int);
452 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
454 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
455 +#endif /* !CONFIG_MMU */
457 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len,
458 unsigned int gup_flags);
459 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
460 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
461 index 1861ea8..d85a914 100644
462 --- a/include/linux/mm_types.h
463 +++ b/include/linux/mm_types.h
464 @@ -260,6 +260,7 @@ struct vm_region {
465 unsigned long vm_top; /* region allocated to here */
466 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
467 struct file *vm_file; /* the backing file or NULL */
468 + struct file *vm_prfile; /* the virtual backing file or NULL */
470 int vm_usage; /* region usage count (access under nommu_region_sem) */
471 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
472 @@ -334,6 +335,7 @@ struct vm_area_struct {
473 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
475 struct file * vm_file; /* File we map to (can be NULL). */
476 + struct file *vm_prfile; /* shadow of vm_file */
477 void * vm_private_data; /* was vm_pte (shared mem) */
479 atomic_long_t swap_readahead_info;
480 diff --git a/kernel/fork.c b/kernel/fork.c
481 index 07cc743..b1d2b43 100644
484 @@ -676,7 +676,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
485 struct inode *inode = file_inode(file);
486 struct address_space *mapping = file->f_mapping;
490 if (tmp->vm_flags & VM_DENYWRITE)
491 atomic_dec(&inode->i_writecount);
492 i_mmap_lock_write(mapping);
493 diff --git a/mm/Makefile b/mm/Makefile
494 index e3ac3ae..745b26c 100644
497 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
498 mm_init.o mmu_context.o percpu.o slab_common.o \
499 compaction.o vmacache.o swap_slots.o \
500 interval_tree.o list_lru.o workingset.o \
502 + prfile.o debug.o $(mmu-y)
506 diff --git a/mm/filemap.c b/mm/filemap.c
507 index 594d73f..7183aef 100644
510 @@ -2590,7 +2590,7 @@ int filemap_page_mkwrite(struct vm_fault *vmf)
511 int ret = VM_FAULT_LOCKED;
513 sb_start_pagefault(inode->i_sb);
514 - file_update_time(vmf->vma->vm_file);
515 + vma_file_update_time(vmf->vma);
517 if (page->mapping != inode->i_mapping) {
519 diff --git a/mm/mmap.c b/mm/mmap.c
520 index 680506f..081406a 100644
523 @@ -171,7 +171,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
524 if (vma->vm_ops && vma->vm_ops->close)
525 vma->vm_ops->close(vma);
527 - fput(vma->vm_file);
529 mpol_put(vma_policy(vma));
530 kmem_cache_free(vm_area_cachep, vma);
532 @@ -896,7 +896,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
535 uprobe_munmap(next, next->vm_start, next->vm_end);
540 anon_vma_merge(vma, next);
541 @@ -1746,8 +1746,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
549 /* Undo any partial mapping done by a device driver. */
550 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
551 @@ -2569,7 +2569,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
555 - get_file(new->vm_file);
558 if (new->vm_ops && new->vm_ops->open)
559 new->vm_ops->open(new);
560 @@ -2588,7 +2588,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
561 if (new->vm_ops && new->vm_ops->close)
562 new->vm_ops->close(new);
564 - fput(new->vm_file);
566 unlink_anon_vmas(new);
568 mpol_put(vma_policy(new));
569 @@ -2750,7 +2750,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
570 struct vm_area_struct *vma;
571 unsigned long populate = 0;
572 unsigned long ret = -EINVAL;
574 + struct file *file, *prfile;
576 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
577 current->comm, current->pid);
578 @@ -2825,10 +2825,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
582 - file = get_file(vma->vm_file);
584 + file = vma->vm_file;
585 + prfile = vma->vm_prfile;
586 ret = do_mmap_pgoff(vma->vm_file, start, size,
587 prot, flags, pgoff, &populate, NULL);
588 + if (!IS_ERR_VALUE(ret) && file && prfile) {
589 + struct vm_area_struct *new_vma;
591 + new_vma = find_vma(mm, ret);
592 + if (!new_vma->vm_prfile)
593 + new_vma->vm_prfile = prfile;
594 + if (new_vma != vma)
598 + * two fput()s instead of vma_fput(vma),
599 + * coz vma may not be available anymore.
605 up_write(&mm->mmap_sem);
607 @@ -3136,7 +3153,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
608 if (anon_vma_clone(new_vma, vma))
609 goto out_free_mempol;
610 if (new_vma->vm_file)
611 - get_file(new_vma->vm_file);
612 + vma_get_file(new_vma);
613 if (new_vma->vm_ops && new_vma->vm_ops->open)
614 new_vma->vm_ops->open(new_vma);
615 vma_link(mm, new_vma, prev, rb_link, rb_parent);
616 diff --git a/mm/nommu.c b/mm/nommu.c
617 index 17c00d9..4bcdf94 100644
620 @@ -641,7 +641,7 @@ static void __put_nommu_region(struct vm_region *region)
621 up_write(&nommu_region_sem);
624 - fput(region->vm_file);
627 /* IO memory and memory shared directly out of the pagecache
628 * from ramfs/tmpfs mustn't be released here */
629 @@ -799,7 +799,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
630 if (vma->vm_ops && vma->vm_ops->close)
631 vma->vm_ops->close(vma);
633 - fput(vma->vm_file);
635 put_nommu_region(vma->vm_region);
636 kmem_cache_free(vm_area_cachep, vma);
638 @@ -1321,7 +1321,7 @@ unsigned long do_mmap(struct file *file,
639 goto error_just_free;
642 - fput(region->vm_file);
644 kmem_cache_free(vm_region_jar, region);
647 @@ -1396,10 +1396,10 @@ unsigned long do_mmap(struct file *file,
648 up_write(&nommu_region_sem);
651 - fput(region->vm_file);
653 kmem_cache_free(vm_region_jar, region);
655 - fput(vma->vm_file);
657 kmem_cache_free(vm_area_cachep, vma);
660 diff --git a/mm/prfile.c b/mm/prfile.c
662 index 0000000..1ef053b
667 + * Mainly for aufs which mmap(2) different file and wants to print different
668 + * path in /proc/PID/maps.
669 + * Call these functions via macros defined in linux/mm.h.
671 + * See Documentation/filesystems/aufs/design/06mmap.txt
673 + * Copyright (c) 2014-2017 Junjro R. Okajima
674 + * Copyright (c) 2014 Ian Campbell
677 +#include <linux/mm.h>
678 +#include <linux/file.h>
679 +#include <linux/fs.h>
681 +/* #define PRFILE_TRACE */
682 +static inline void prfile_trace(struct file *f, struct file *pr,
683 + const char func[], int line, const char func2[])
687 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
691 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
694 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
696 + prfile_trace(f, pr, func, line, __func__);
697 + file_update_time(f);
699 + file_update_time(pr);
702 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
705 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
707 + prfile_trace(f, pr, func, line, __func__);
708 + return (f && pr) ? pr : f;
711 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
713 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
715 + prfile_trace(f, pr, func, line, __func__);
721 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
723 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
725 + prfile_trace(f, pr, func, line, __func__);
732 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
735 + struct file *f = region->vm_file, *pr = region->vm_prfile;
737 + prfile_trace(f, pr, func, line, __func__);
738 + return (f && pr) ? pr : f;
741 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
743 + struct file *f = region->vm_file, *pr = region->vm_prfile;
745 + prfile_trace(f, pr, func, line, __func__);
750 +#endif /* !CONFIG_MMU */
751 aufs4.x-rcN standalone patch
753 diff --git a/fs/dcache.c b/fs/dcache.c
754 index e3719a5..3203470 100644
757 @@ -1305,6 +1305,7 @@ void d_walk(struct dentry *parent, void *data,
761 +EXPORT_SYMBOL_GPL(d_walk);
764 struct vfsmount *mnt;
765 @@ -2894,6 +2895,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
767 write_sequnlock(&rename_lock);
769 +EXPORT_SYMBOL_GPL(d_exchange);
772 * d_ancestor - search for an ancestor
773 diff --git a/fs/exec.c b/fs/exec.c
774 index 3e14ba2..6818b01 100644
777 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
778 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
779 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
781 +EXPORT_SYMBOL_GPL(path_noexec);
785 diff --git a/fs/fcntl.c b/fs/fcntl.c
786 index f51c2cf..58bf222 100644
789 @@ -84,6 +84,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
793 +EXPORT_SYMBOL_GPL(setfl);
795 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
797 diff --git a/fs/file_table.c b/fs/file_table.c
798 index 61517f5..c6bab39c 100644
799 --- a/fs/file_table.c
800 +++ b/fs/file_table.c
801 @@ -148,6 +148,7 @@ struct file *get_empty_filp(void)
803 return ERR_PTR(-ENFILE);
805 +EXPORT_SYMBOL_GPL(get_empty_filp);
808 * alloc_file - allocate and initialize a 'struct file'
809 @@ -258,6 +259,7 @@ void flush_delayed_fput(void)
813 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
815 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
817 @@ -300,6 +302,7 @@ void __fput_sync(struct file *file)
821 +EXPORT_SYMBOL_GPL(__fput_sync);
823 void put_filp(struct file *file)
825 @@ -308,6 +311,7 @@ void put_filp(struct file *file)
829 +EXPORT_SYMBOL_GPL(put_filp);
831 void __init files_init(void)
833 diff --git a/fs/inode.c b/fs/inode.c
834 index f7800d6..f31a6c7 100644
837 @@ -1664,6 +1664,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
839 return update_time(inode, time, flags);
841 +EXPORT_SYMBOL_GPL(update_time);
844 * touch_atime - update the access time
845 diff --git a/fs/namespace.c b/fs/namespace.c
846 index e5a4a7f..6d0c376 100644
849 @@ -517,6 +517,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
850 mnt_dec_writers(real_mount(mnt));
853 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
856 * mnt_drop_write - give up write access to a mount
857 @@ -851,6 +852,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
859 return check_mnt(real_mount(mnt));
861 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
864 * vfsmount lock must be held for write
865 @@ -1887,6 +1889,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
869 +EXPORT_SYMBOL_GPL(iterate_mounts);
871 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
873 diff --git a/fs/notify/group.c b/fs/notify/group.c
874 index 3235753..14a2d48 100644
875 --- a/fs/notify/group.c
876 +++ b/fs/notify/group.c
878 #include <linux/srcu.h>
879 #include <linux/rculist.h>
880 #include <linux/wait.h>
881 +#include <linux/module.h>
883 #include <linux/fsnotify_backend.h>
884 #include "fsnotify.h"
885 @@ -109,6 +110,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
887 atomic_inc(&group->refcnt);
889 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
892 * Drop a reference to a group. Free it if it's through.
893 @@ -118,6 +120,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
894 if (atomic_dec_and_test(&group->refcnt))
895 fsnotify_final_destroy_group(group);
897 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
900 * Create a new fsnotify_group and hold a reference for the group returned.
901 @@ -147,6 +150,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
905 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
907 int fsnotify_fasync(int fd, struct file *file, int on)
909 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
910 index 9991f88..117042c 100644
911 --- a/fs/notify/mark.c
912 +++ b/fs/notify/mark.c
913 @@ -118,6 +118,7 @@ static bool fsnotify_get_mark_safe(struct fsnotify_mark *mark)
915 return atomic_inc_not_zero(&mark->refcnt);
917 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
919 static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
921 @@ -395,6 +396,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
922 mutex_unlock(&group->mark_mutex);
923 fsnotify_free_mark(mark);
925 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
928 * Sorting function for lists of fsnotify marks.
929 @@ -607,6 +609,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
930 fsnotify_put_mark(mark);
933 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
935 int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
936 struct vfsmount *mnt, int allow_dups)
937 @@ -742,6 +745,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
938 fsnotify_get_group(group);
941 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
944 * Destroy all marks in destroy_list, waits for SRCU period to finish before
945 diff --git a/fs/open.c b/fs/open.c
946 index 7ea1184..6e2e241 100644
949 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
950 inode_unlock(dentry->d_inode);
953 +EXPORT_SYMBOL_GPL(do_truncate);
955 long vfs_truncate(const struct path *path, loff_t length)
957 @@ -691,6 +692,7 @@ int open_check_o_direct(struct file *f)
961 +EXPORT_SYMBOL_GPL(open_check_o_direct);
963 static int do_dentry_open(struct file *f,
965 diff --git a/fs/read_write.c b/fs/read_write.c
966 index 6aa8c7a..b5d392e 100644
967 --- a/fs/read_write.c
968 +++ b/fs/read_write.c
969 @@ -453,6 +453,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
973 +EXPORT_SYMBOL_GPL(vfs_read);
975 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
977 @@ -493,6 +494,7 @@ vfs_readf_t vfs_readf(struct file *file)
978 return new_sync_read;
979 return ERR_PTR(-ENOSYS);
981 +EXPORT_SYMBOL_GPL(vfs_readf);
983 vfs_writef_t vfs_writef(struct file *file)
985 @@ -504,6 +506,7 @@ vfs_writef_t vfs_writef(struct file *file)
986 return new_sync_write;
987 return ERR_PTR(-ENOSYS);
989 +EXPORT_SYMBOL_GPL(vfs_writef);
991 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
993 @@ -573,6 +576,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
997 +EXPORT_SYMBOL_GPL(vfs_write);
999 static inline loff_t file_pos_read(struct file *file)
1001 diff --git a/fs/splice.c b/fs/splice.c
1002 index eb888c6..7ab89d2 100644
1005 @@ -850,6 +850,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
1007 return splice_write(pipe, out, ppos, len, flags);
1009 +EXPORT_SYMBOL_GPL(do_splice_from);
1012 * Attempt to initiate a splice from a file to a pipe.
1013 @@ -879,6 +880,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
1015 return splice_read(in, ppos, pipe, len, flags);
1017 +EXPORT_SYMBOL_GPL(do_splice_to);
1020 * splice_direct_to_actor - splices data directly between two non-pipes
1021 diff --git a/fs/sync.c b/fs/sync.c
1022 index eb61780..32c5a05 100644
1025 @@ -38,6 +38,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
1026 sb->s_op->sync_fs(sb, wait);
1027 return __sync_blockdev(sb->s_bdev, wait);
1029 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1032 * Write out and wait upon all dirty data associated with this
1033 diff --git a/fs/xattr.c b/fs/xattr.c
1034 index 61cd28b..35570cd 100644
1037 @@ -297,6 +297,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1038 *xattr_value = value;
1041 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1044 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1045 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1046 index bc97a97..895a1ba 100644
1047 --- a/kernel/locking/lockdep.c
1048 +++ b/kernel/locking/lockdep.c
1049 @@ -155,6 +155,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1051 return lock_classes + hlock->class_idx - 1;
1053 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1054 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1056 #ifdef CONFIG_LOCK_STAT
1057 diff --git a/kernel/task_work.c b/kernel/task_work.c
1058 index 836a72a..aa00d49 100644
1059 --- a/kernel/task_work.c
1060 +++ b/kernel/task_work.c
1061 @@ -115,3 +115,4 @@ void task_work_run(void)
1065 +EXPORT_SYMBOL_GPL(task_work_run);
1066 diff --git a/security/commoncap.c b/security/commoncap.c
1067 index fc46f5b..90543ef 100644
1068 --- a/security/commoncap.c
1069 +++ b/security/commoncap.c
1070 @@ -1270,12 +1270,14 @@ int cap_mmap_addr(unsigned long addr)
1074 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1076 int cap_mmap_file(struct file *file, unsigned long reqprot,
1077 unsigned long prot, unsigned long flags)
1081 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1083 #ifdef CONFIG_SECURITY
1085 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1086 index 03c1652..f88c84b 100644
1087 --- a/security/device_cgroup.c
1088 +++ b/security/device_cgroup.c
1090 #include <linux/device_cgroup.h>
1091 #include <linux/cgroup.h>
1092 #include <linux/ctype.h>
1093 +#include <linux/export.h>
1094 #include <linux/list.h>
1095 #include <linux/uaccess.h>
1096 #include <linux/seq_file.h>
1097 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
1098 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
1101 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
1103 int devcgroup_inode_mknod(int mode, dev_t dev)
1105 diff --git a/security/security.c b/security/security.c
1106 index 4bf0f57..b30d1e1 100644
1107 --- a/security/security.c
1108 +++ b/security/security.c
1109 @@ -530,6 +530,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1111 return call_int_hook(path_rmdir, 0, dir, dentry);
1113 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1115 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1117 @@ -546,6 +547,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1119 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1121 +EXPORT_SYMBOL_GPL(security_path_symlink);
1123 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1124 struct dentry *new_dentry)
1125 @@ -554,6 +556,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1127 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1129 +EXPORT_SYMBOL_GPL(security_path_link);
1131 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1132 const struct path *new_dir, struct dentry *new_dentry,
1133 @@ -581,6 +584,7 @@ int security_path_truncate(const struct path *path)
1135 return call_int_hook(path_truncate, 0, path);
1137 +EXPORT_SYMBOL_GPL(security_path_truncate);
1139 int security_path_chmod(const struct path *path, umode_t mode)
1141 @@ -588,6 +592,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1143 return call_int_hook(path_chmod, 0, path, mode);
1145 +EXPORT_SYMBOL_GPL(security_path_chmod);
1147 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1149 @@ -595,6 +600,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1151 return call_int_hook(path_chown, 0, path, uid, gid);
1153 +EXPORT_SYMBOL_GPL(security_path_chown);
1155 int security_path_chroot(const struct path *path)
1157 @@ -680,6 +686,7 @@ int security_inode_readlink(struct dentry *dentry)
1159 return call_int_hook(inode_readlink, 0, dentry);
1161 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1163 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1165 @@ -695,6 +702,7 @@ int security_inode_permission(struct inode *inode, int mask)
1167 return call_int_hook(inode_permission, 0, inode, mask);
1169 +EXPORT_SYMBOL_GPL(security_inode_permission);
1171 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1173 @@ -866,6 +874,7 @@ int security_file_permission(struct file *file, int mask)
1175 return fsnotify_perm(file, mask);
1177 +EXPORT_SYMBOL_GPL(security_file_permission);
1179 int security_file_alloc(struct file *file)
1181 @@ -925,6 +934,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1183 return ima_file_mmap(file, prot);
1185 +EXPORT_SYMBOL_GPL(security_mmap_file);
1187 int security_mmap_addr(unsigned long addr)
1189 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1190 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1191 +++ linux/Documentation/ABI/testing/debugfs-aufs 2017-07-29 12:14:25.893041746 +0200
1193 +What: /debug/aufs/si_<id>/
1195 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1197 + Under /debug/aufs, a directory named si_<id> is created
1198 + per aufs mount, where <id> is a unique id generated
1201 +What: /debug/aufs/si_<id>/plink
1203 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1205 + It has three lines and shows the information about the
1206 + pseudo-link. The first line is a single number
1207 + representing a number of buckets. The second line is a
1208 + number of pseudo-links per buckets (separated by a
1209 + blank). The last line is a single number representing a
1210 + total number of psedo-links.
1211 + When the aufs mount option 'noplink' is specified, it
1212 + will show "1\n0\n0\n".
1214 +What: /debug/aufs/si_<id>/xib
1216 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1218 + It shows the consumed blocks by xib (External Inode Number
1219 + Bitmap), its block size and file size.
1220 + When the aufs mount option 'noxino' is specified, it
1221 + will be empty. About XINO files, see the aufs manual.
1223 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1225 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1227 + It shows the consumed blocks by xino (External Inode Number
1228 + Translation Table), its link count, block size and file
1230 + When the aufs mount option 'noxino' is specified, it
1231 + will be empty. About XINO files, see the aufs manual.
1233 +What: /debug/aufs/si_<id>/xigen
1235 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1237 + It shows the consumed blocks by xigen (External Inode
1238 + Generation Table), its block size and file size.
1239 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1241 + When the aufs mount option 'noxino' is specified, it
1242 + will be empty. About XINO files, see the aufs manual.
1243 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1244 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1245 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1247 +What: /sys/fs/aufs/si_<id>/
1249 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1251 + Under /sys/fs/aufs, a directory named si_<id> is created
1252 + per aufs mount, where <id> is a unique id generated
1255 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1257 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1259 + It shows the abolute path of a member directory (which
1260 + is called branch) in aufs, and its permission.
1262 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1264 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1266 + It shows the id of a member directory (which is called
1269 +What: /sys/fs/aufs/si_<id>/xi_path
1271 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1273 + It shows the abolute path of XINO (External Inode Number
1274 + Bitmap, Translation Table and Generation Table) file
1275 + even if it is the default path.
1276 + When the aufs mount option 'noxino' is specified, it
1277 + will be empty. About XINO files, see the aufs manual.
1278 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1279 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1280 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2017-11-12 22:24:42.257509799 +0100
1283 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1285 +# This program is free software; you can redistribute it and/or modify
1286 +# it under the terms of the GNU General Public License as published by
1287 +# the Free Software Foundation; either version 2 of the License, or
1288 +# (at your option) any later version.
1290 +# This program is distributed in the hope that it will be useful,
1291 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1292 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1293 +# GNU General Public License for more details.
1295 +# You should have received a copy of the GNU General Public License
1296 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1299 +----------------------------------------
1301 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1302 +1. abbrev. for "advanced multi-layered unification filesystem".
1303 +2. abbrev. for "another unionfs".
1304 +3. abbrev. for "auf das" in German which means "on the" in English.
1305 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1306 + But "Filesystem aufs Filesystem" is hard to understand.
1307 +4. abbrev. for "African Urban Fashion Show".
1309 +AUFS is a filesystem with features:
1310 +- multi layered stackable unification filesystem, the member directory
1311 + is called as a branch.
1312 +- branch permission and attribute, 'readonly', 'real-readonly',
1313 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1315 +- internal "file copy-on-write".
1316 +- logical deletion, whiteout.
1317 +- dynamic branch manipulation, adding, deleting and changing permission.
1318 +- allow bypassing aufs, user's direct branch access.
1319 +- external inode number translation table and bitmap which maintains the
1320 + persistent aufs inode number.
1321 +- seekable directory, including NFS readdir.
1322 +- file mapping, mmap and sharing pages.
1323 +- pseudo-link, hardlink over branches.
1324 +- loopback mounted filesystem as a branch.
1325 +- several policies to select one among multiple writable branches.
1326 +- revert a single systemcall when an error occurs in aufs.
1330 +Multi Layered Stackable Unification Filesystem
1331 +----------------------------------------------------------------------
1332 +Most people already knows what it is.
1333 +It is a filesystem which unifies several directories and provides a
1334 +merged single directory. When users access a file, the access will be
1335 +passed/re-directed/converted (sorry, I am not sure which English word is
1336 +correct) to the real file on the member filesystem. The member
1337 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1338 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1339 +readonly branch is handled by creating 'whiteout' on the upper writable
1342 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1343 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1344 +different approaches to implement the merged-view.
1345 +The former tries putting it into VFS, and the latter implements as a
1346 +separate filesystem.
1347 +(If I misunderstand about these implementations, please let me know and
1348 +I shall correct it. Because it is a long time ago when I read their
1349 +source files last time).
1351 +UnionMount's approach will be able to small, but may be hard to share
1352 +branches between several UnionMount since the whiteout in it is
1353 +implemented in the inode on branch filesystem and always
1354 +shared. According to Bharata's post, readdir does not seems to be
1356 +There are several missing features known in this implementations such as
1357 +- for users, the inode number may change silently. eg. copy-up.
1358 +- link(2) may break by copy-up.
1359 +- read(2) may get an obsoleted filedata (fstat(2) too).
1360 +- fcntl(F_SETLK) may be broken by copy-up.
1361 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1364 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1365 +merged into mainline. This is another implementation of UnionMount as a
1366 +separated filesystem. All the limitations and known problems which
1367 +UnionMount are equally inherited to "overlay" filesystem.
1369 +Unionfs has a longer history. When I started implementing a stackable
1370 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1371 +inode, dentry and file objects and they have an array pointing lower
1372 +same kind objects. After contributing many patches for Unionfs, I
1373 +re-started my project AUFS (Jun 2006).
1375 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1376 +implemented my own ideas, approaches and enhancements and it became
1377 +totally different one.
1379 +Comparing DM snapshot and fs based implementation
1380 +- the number of bytes to be copied between devices is much smaller.
1381 +- the type of filesystem must be one and only.
1382 +- the fs must be writable, no readonly fs, even for the lower original
1383 + device. so the compression fs will not be usable. but if we use
1384 + loopback mount, we may address this issue.
1386 + mount /cdrom/squashfs.img /sq
1387 + losetup /sq/ext2.img
1388 + losetup /somewhere/cow
1389 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1390 +- it will be difficult (or needs more operations) to extract the
1391 + difference between the original device and COW.
1392 +- DM snapshot-merge may help a lot when users try merging. in the
1393 + fs-layer union, users will use rsync(1).
1395 +You may want to read my old paper "Filesystems in LiveCD"
1396 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1399 +Several characters/aspects/persona of aufs
1400 +----------------------------------------------------------------------
1402 +Aufs has several characters, aspects or persona.
1403 +1. a filesystem, callee of VFS helper
1404 +2. sub-VFS, caller of VFS helper for branches
1405 +3. a virtual filesystem which maintains persistent inode number
1406 +4. reader/writer of files on branches such like an application
1408 +1. Callee of VFS Helper
1409 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1410 +unlink(2) from an application reaches sys_unlink() kernel function and
1411 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1412 +calls filesystem specific unlink operation. Actually aufs implements the
1413 +unlink operation but it behaves like a redirector.
1415 +2. Caller of VFS Helper for Branches
1416 +aufs_unlink() passes the unlink request to the branch filesystem as if
1417 +it were called from VFS. So the called unlink operation of the branch
1418 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1419 +every necessary pre/post operation for the branch filesystem.
1420 +- acquire the lock for the parent dir on a branch
1421 +- lookup in a branch
1422 +- revalidate dentry on a branch
1423 +- mnt_want_write() for a branch
1424 +- vfs_unlink() for a branch
1425 +- mnt_drop_write() for a branch
1426 +- release the lock on a branch
1428 +3. Persistent Inode Number
1429 +One of the most important issue for a filesystem is to maintain inode
1430 +numbers. This is particularly important to support exporting a
1431 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1432 +backend block device for its own. But some storage is necessary to
1433 +keep and maintain the inode numbers. It may be a large space and may not
1434 +suit to keep in memory. Aufs rents some space from its first writable
1435 +branch filesystem (by default) and creates file(s) on it. These files
1436 +are created by aufs internally and removed soon (currently) keeping
1438 +Note: Because these files are removed, they are totally gone after
1439 + unmounting aufs. It means the inode numbers are not persistent
1440 + across unmount or reboot. I have a plan to make them really
1441 + persistent which will be important for aufs on NFS server.
1443 +4. Read/Write Files Internally (copy-on-write)
1444 +Because a branch can be readonly, when you write a file on it, aufs will
1445 +"copy-up" it to the upper writable branch internally. And then write the
1446 +originally requested thing to the file. Generally kernel doesn't
1447 +open/read/write file actively. In aufs, even a single write may cause a
1448 +internal "file copy". This behaviour is very similar to cp(1) command.
1450 +Some people may think it is better to pass such work to user space
1451 +helper, instead of doing in kernel space. Actually I am still thinking
1452 +about it. But currently I have implemented it in kernel space.
1453 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1454 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1455 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2017-07-29 12:14:25.893041746 +0200
1458 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1460 +# This program is free software; you can redistribute it and/or modify
1461 +# it under the terms of the GNU General Public License as published by
1462 +# the Free Software Foundation; either version 2 of the License, or
1463 +# (at your option) any later version.
1465 +# This program is distributed in the hope that it will be useful,
1466 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1467 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1468 +# GNU General Public License for more details.
1470 +# You should have received a copy of the GNU General Public License
1471 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1473 +Basic Aufs Internal Structure
1475 +Superblock/Inode/Dentry/File Objects
1476 +----------------------------------------------------------------------
1477 +As like an ordinary filesystem, aufs has its own
1478 +superblock/inode/dentry/file objects. All these objects have a
1479 +dynamically allocated array and store the same kind of pointers to the
1480 +lower filesystem, branch.
1481 +For example, when you build a union with one readwrite branch and one
1482 +readonly, mounted /au, /rw and /ro respectively.
1484 +- /ro/fileA exists but /rw/fileA
1486 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1487 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1488 +- [0] = NULL (because /rw/fileA doesn't exist)
1491 +This style of an array is essentially same to the aufs
1492 +superblock/inode/dentry/file objects.
1494 +Because aufs supports manipulating branches, ie. add/delete/change
1495 +branches dynamically, these objects has its own generation. When
1496 +branches are changed, the generation in aufs superblock is
1497 +incremented. And a generation in other object are compared when it is
1498 +accessed. When a generation in other objects are obsoleted, aufs
1499 +refreshes the internal array.
1503 +----------------------------------------------------------------------
1504 +Additionally aufs superblock has some data for policies to select one
1505 +among multiple writable branches, XIB files, pseudo-links and kobject.
1506 +See below in detail.
1507 +About the policies which supports copy-down a directory, see
1508 +wbr_policy.txt too.
1511 +Branch and XINO(External Inode Number Translation Table)
1512 +----------------------------------------------------------------------
1513 +Every branch has its own xino (external inode number translation table)
1514 +file. The xino file is created and unlinked by aufs internally. When two
1515 +members of a union exist on the same filesystem, they share the single
1517 +The struct of a xino file is simple, just a sequence of aufs inode
1518 +numbers which is indexed by the lower inode number.
1519 +In the above sample, assume the inode number of /ro/fileA is i111 and
1520 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1521 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1523 +When the inode numbers are not contiguous, the xino file will be sparse
1524 +which has a hole in it and doesn't consume as much disk space as it
1525 +might appear. If your branch filesystem consumes disk space for such
1526 +holes, then you should specify 'xino=' option at mounting aufs.
1528 +Aufs has a mount option to free the disk blocks for such holes in XINO
1529 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1530 +meet a problem of disk shortage due to XINO files, then you should try
1531 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1532 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1533 +the holes in XINO files.
1535 +Also a writable branch has three kinds of "whiteout bases". All these
1536 +are existed when the branch is joined to aufs, and their names are
1537 +whiteout-ed doubly, so that users will never see their names in aufs
1539 +1. a regular file which will be hardlinked to all whiteouts.
1540 +2. a directory to store a pseudo-link.
1541 +3. a directory to store an "orphan"-ed file temporary.
1544 + When you remove a file on a readonly branch, aufs handles it as a
1545 + logical deletion and creates a whiteout on the upper writable branch
1546 + as a hardlink of this file in order not to consume inode on the
1549 + See below, Pseudo-link.
1551 + When "fileC" exists on the lower readonly branch only and it is
1552 + opened and removed with its parent dir, and then user writes
1553 + something into it, then aufs copies-up fileC to this
1554 + directory. Because there is no other dir to store fileC. After
1555 + creating a file under this dir, the file is unlinked.
1557 +Because aufs supports manipulating branches, ie. add/delete/change
1558 +dynamically, a branch has its own id. When the branch order changes,
1559 +aufs finds the new index by searching the branch id.
1563 +----------------------------------------------------------------------
1564 +Assume "fileA" exists on the lower readonly branch only and it is
1565 +hardlinked to "fileB" on the branch. When you write something to fileA,
1566 +aufs copies-up it to the upper writable branch. Additionally aufs
1567 +creates a hardlink under the Pseudo-link Directory of the writable
1568 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1569 +simple list. If fileB is read after unlinking fileA, aufs returns
1570 +filedata from the pseudo-link instead of the lower readonly
1571 +branch. Because the pseudo-link is based upon the inode, to keep the
1572 +inode number by xino (see above) is essentially necessary.
1574 +All the hardlinks under the Pseudo-link Directory of the writable branch
1575 +should be restored in a proper location later. Aufs provides a utility
1576 +to do this. The userspace helpers executed at remounting and unmounting
1578 +During this utility is running, it puts aufs into the pseudo-link
1579 +maintenance mode. In this mode, only the process which began the
1580 +maintenance mode (and its child processes) is allowed to operate in
1581 +aufs. Some other processes which are not related to the pseudo-link will
1582 +be allowed to run too, but the rest have to return an error or wait
1583 +until the maintenance mode ends. If a process already acquires an inode
1584 +mutex (in VFS), it has to return an error.
1587 +XIB(external inode number bitmap)
1588 +----------------------------------------------------------------------
1589 +Addition to the xino file per a branch, aufs has an external inode number
1590 +bitmap in a superblock object. It is also an internal file such like a
1592 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1594 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1596 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1597 +reduce the number of consumed disk blocks for these files.
1600 +Virtual or Vertical Dir, and Readdir in Userspace
1601 +----------------------------------------------------------------------
1602 +In order to support multiple layers (branches), aufs readdir operation
1603 +constructs a virtual dir block on memory. For readdir, aufs calls
1604 +vfs_readdir() internally for each dir on branches, merges their entries
1605 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1606 +object. So the file object has its entry list until it is closed. The
1607 +entry list will be updated when the file position is zero and becomes
1608 +obsoleted. This decision is made in aufs automatically.
1610 +The dynamically allocated memory block for the name of entries has a
1611 +unit of 512 bytes (by default) and stores the names contiguously (no
1612 +padding). Another block for each entry is handled by kmem_cache too.
1613 +During building dir blocks, aufs creates hash list and judging whether
1614 +the entry is whiteouted by its upper branch or already listed.
1615 +The merged result is cached in the corresponding inode object and
1616 +maintained by a customizable life-time option.
1618 +Some people may call it can be a security hole or invite DoS attack
1619 +since the opened and once readdir-ed dir (file object) holds its entry
1620 +list and becomes a pressure for system memory. But I'd say it is similar
1621 +to files under /proc or /sys. The virtual files in them also holds a
1622 +memory page (generally) while they are opened. When an idea to reduce
1623 +memory for them is introduced, it will be applied to aufs too.
1624 +For those who really hate this situation, I've developed readdir(3)
1625 +library which operates this merging in userspace. You just need to set
1626 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1627 +kernel space for readdir(3).
1631 +----------------------------------------------------------------------
1632 +Aufs sometimes requires privilege access to a branch. For instance,
1633 +in copy-up/down operation. When a user process is going to make changes
1634 +to a file which exists in the lower readonly branch only, and the mode
1635 +of one of ancestor directories may not be writable by a user
1636 +process. Here aufs copy-up the file with its ancestors and they may
1637 +require privilege to set its owner/group/mode/etc.
1638 +This is a typical case of a application character of aufs (see
1641 +Aufs uses workqueue synchronously for this case. It creates its own
1642 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1643 +passes the request to call mkdir or write (for example), and wait for
1644 +its completion. This approach solves a problem of a signal handler
1646 +If aufs didn't adopt the workqueue and changed the privilege of the
1647 +process, then the process may receive the unexpected SIGXFSZ or other
1650 +Also aufs uses the system global workqueue ("events" kernel thread) too
1651 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1652 +whiteout base and etc. This is unrelated to a privilege.
1653 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1654 +superblock at the beginning, at the same time waits for the completion
1655 +of all queued asynchronous tasks.
1659 +----------------------------------------------------------------------
1660 +The whiteout in aufs is very similar to Unionfs's. That is represented
1661 +by its filename. UnionMount takes an approach of a file mode, but I am
1662 +afraid several utilities (find(1) or something) will have to support it.
1664 +Basically the whiteout represents "logical deletion" which stops aufs to
1665 +lookup further, but also it represents "dir is opaque" which also stop
1668 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1669 +In order to make several functions in a single systemcall to be
1670 +revertible, aufs adopts an approach to rename a directory to a temporary
1671 +unique whiteouted name.
1672 +For example, in rename(2) dir where the target dir already existed, aufs
1673 +renames the target dir to a temporary unique whiteouted name before the
1674 +actual rename on a branch, and then handles other actions (make it opaque,
1675 +update the attributes, etc). If an error happens in these actions, aufs
1676 +simply renames the whiteouted name back and returns an error. If all are
1677 +succeeded, aufs registers a function to remove the whiteouted unique
1678 +temporary name completely and asynchronously to the system global
1683 +----------------------------------------------------------------------
1684 +It is a well-known feature or concept.
1685 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1686 +internally and makes change to the new file on the upper writable branch.
1687 +When the trigger systemcall does not update the timestamps of the parent
1688 +dir, aufs reverts it after copy-up.
1691 +Move-down (aufs3.9 and later)
1692 +----------------------------------------------------------------------
1693 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1694 +the lower readonly branch to the upper writable branch when a user
1695 +changes something about the file.
1696 +"Move-down" is an opposite action of copy-up. Basically this action is
1697 +ran manually instead of automatically and internally.
1698 +For desgin and implementation, aufs has to consider these issues.
1699 +- whiteout for the file may exist on the lower branch.
1700 +- ancestor directories may not exist on the lower branch.
1701 +- diropq for the ancestor directories may exist on the upper branch.
1702 +- free space on the lower branch will reduce.
1703 +- another access to the file may happen during moving-down, including
1704 + UDBA (see "Revalidate Dentry and UDBA").
1705 +- the file should not be hard-linked nor pseudo-linked. they should be
1706 + handled by auplink utility later.
1708 +Sometimes users want to move-down a file from the upper writable branch
1709 +to the lower readonly or writable branch. For instance,
1710 +- the free space of the upper writable branch is going to run out.
1711 +- create a new intermediate branch between the upper and lower branch.
1714 +For this purpose, use "aumvdown" command in aufs-util.git.
1715 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1716 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1717 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2017-07-29 12:14:25.893041746 +0200
1720 +# Copyright (C) 2015-2017 Junjiro R. Okajima
1722 +# This program is free software; you can redistribute it and/or modify
1723 +# it under the terms of the GNU General Public License as published by
1724 +# the Free Software Foundation; either version 2 of the License, or
1725 +# (at your option) any later version.
1727 +# This program is distributed in the hope that it will be useful,
1728 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1729 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1730 +# GNU General Public License for more details.
1732 +# You should have received a copy of the GNU General Public License
1733 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1735 +Support for a branch who has its ->atomic_open()
1736 +----------------------------------------------------------------------
1737 +The filesystems who implement its ->atomic_open() are not majority. For
1738 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1739 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1740 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1741 +sure whether all filesystems who have ->atomic_open() behave like this,
1742 +but NFSv4 surely returns the error.
1744 +In order to support ->atomic_open() for aufs, there are a few
1747 +A. Introduce aufs_atomic_open()
1748 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1750 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1751 + an aufs user Pip Cet's approach
1752 + - calls aufs_create(), VFS finish_open() and notify_change().
1753 + - pass fake-mode to finish_open(), and then correct the mode by
1755 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1756 + - no aufs_atomic_open().
1757 + - aufs_lookup() registers the TID to an aufs internal object.
1758 + - aufs_create() does nothing when the matching TID is registered, but
1759 + registers the mode.
1760 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1761 + TID is registered.
1762 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1764 + - no aufs_atomic_open().
1765 + - aufs_create() registers the TID to an internal object. this info
1766 + represents "this process created this file just now."
1767 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1768 + registered TID and re-try open() with superuser's credential.
1770 +Pros and cons for each approach.
1773 + - straightforward but highly depends upon VFS internal.
1774 + - the atomic behavaiour is kept.
1775 + - some of parameters such as nameidata are hard to reproduce for
1779 + - easy to implement.
1780 + - the atomic behavaiour is lost.
1782 + - the atomic behavaiour is kept.
1783 + - dirty and tricky.
1784 + - VFS checks whether the file is created correctly after calling
1785 + ->create(), which means this approach doesn't work.
1787 + - easy to implement.
1788 + - the atomic behavaiour is lost.
1789 + - to open a file with superuser's credential and give it to a user
1790 + process is a bad idea, since the file object keeps the credential
1791 + in it. It may affect LSM or something. This approach doesn't work
1794 +The approach A is ideal, but it hard to implement. So here is a
1795 +variation of A, which is to be implemented.
1797 +A-1. Introduce aufs_atomic_open()
1798 + - calls branch fs ->atomic_open() if exists. otherwise calls
1799 + vfs_create() and finish_open().
1800 + - the demerit is that the several checks after branch fs
1801 + ->atomic_open() are lost. in the ordinary case, the checks are
1802 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1803 + be implemented in aufs, but not all I am afraid.
1804 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1805 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1806 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2017-07-29 12:14:25.893041746 +0200
1809 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1811 +# This program is free software; you can redistribute it and/or modify
1812 +# it under the terms of the GNU General Public License as published by
1813 +# the Free Software Foundation; either version 2 of the License, or
1814 +# (at your option) any later version.
1816 +# This program is distributed in the hope that it will be useful,
1817 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1818 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1819 +# GNU General Public License for more details.
1821 +# You should have received a copy of the GNU General Public License
1822 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1825 +----------------------------------------------------------------------
1826 +Since aufs has a character of sub-VFS (see Introduction), it operates
1827 +lookup for branches as VFS does. It may be a heavy work. But almost all
1828 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1829 +directly connected to its parent. Digging down the directory hierarchy
1830 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1833 +When a branch is a remote filesystem, aufs basically relies upon its
1834 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1836 +For d_revalidate, aufs implements three levels of revalidate tests. See
1837 +"Revalidate Dentry and UDBA" in detail.
1840 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1841 +----------------------------------------------------------------------
1842 +Let's try case study.
1843 +- aufs has two branches, upper readwrite and lower readonly.
1845 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1846 +- user invoked "chmod a+rx /au/dirA"
1847 +- the internal copy-up is activated and "/rw/dirA" is created and its
1848 + permission bits are set to world readable.
1849 +- then "/au/dirA" becomes world readable?
1851 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1852 +or it may be a natively readonly filesystem. If aufs respects the lower
1853 +branch, it should not respond readdir request from other users. But user
1854 +allowed it by chmod. Should really aufs rejects showing the entries
1857 +To be honest, I don't have a good solution for this case. So aufs
1858 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1860 +When dirperm1 is specified, aufs checks only the highest one for the
1861 +directory permission, and shows the entries. Otherwise, as usual, checks
1862 +every dir existing on all branches and rejects the request.
1864 +As a side effect, dirperm1 option improves the performance of aufs
1865 +because the number of permission check is reduced when the number of
1869 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1870 +----------------------------------------------------------------------
1871 +Generally VFS helpers re-validate a dentry as a part of lookup.
1872 +0. digging down the directory hierarchy.
1873 +1. lock the parent dir by its i_mutex.
1874 +2. lookup the final (child) entry.
1876 +4. call the actual operation (create, unlink, etc.)
1877 +5. unlock the parent dir
1879 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1880 +called. Actually aufs implements it and checks the dentry on a branch is
1882 +But it is not enough. Because aufs has to release the lock for the
1883 +parent dir on a branch at the end of ->lookup() (step 2) and
1884 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1886 +If the file on a branch is changed directly, eg. bypassing aufs, after
1887 +aufs released the lock, then the subsequent operation may cause
1888 +something unpleasant result.
1890 +This situation is a result of VFS architecture, ->lookup() and
1891 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1892 +design from VFS's point of view. It is just not suitable for sub-VFS
1895 +Aufs supports such case by three level of revalidation which is
1896 +selectable by user.
1897 +1. Simple Revalidate
1898 + Addition to the native flow in VFS's, confirm the child-parent
1899 + relationship on the branch just after locking the parent dir on the
1900 + branch in the "actual operation" (step 4). When this validation
1901 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1902 + checks the validation of the dentry on branches.
1903 +2. Monitor Changes Internally by Inotify/Fsnotify
1904 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1905 + the dentry on the branch, and returns EBUSY if it finds different
1907 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1908 + during it is in cache. When the event is notified, aufs registers a
1909 + function to kernel 'events' thread by schedule_work(). And the
1910 + function sets some special status to the cached aufs dentry and inode
1911 + private data. If they are not cached, then aufs has nothing to
1912 + do. When the same file is accessed through aufs (step 0-3) later,
1913 + aufs will detect the status and refresh all necessary data.
1914 + In this mode, aufs has to ignore the event which is fired by aufs
1916 +3. No Extra Validation
1917 + This is the simplest test and doesn't add any additional revalidation
1918 + test, and skip the revalidation in step 4. It is useful and improves
1919 + aufs performance when system surely hide the aufs branches from user,
1920 + by over-mounting something (or another method).
1921 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1922 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1923 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2017-07-29 12:14:25.893041746 +0200
1926 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1928 +# This program is free software; you can redistribute it and/or modify
1929 +# it under the terms of the GNU General Public License as published by
1930 +# the Free Software Foundation; either version 2 of the License, or
1931 +# (at your option) any later version.
1933 +# This program is distributed in the hope that it will be useful,
1934 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1935 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1936 +# GNU General Public License for more details.
1938 +# You should have received a copy of the GNU General Public License
1939 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1941 +Branch Manipulation
1943 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1944 +and changing its permission/attribute, there are a lot of works to do.
1948 +----------------------------------------------------------------------
1949 +o Confirm the adding dir exists outside of aufs, including loopback
1950 + mount, and its various attributes.
1951 +o Initialize the xino file and whiteout bases if necessary.
1954 +o Check the owner/group/mode of the directory
1955 + When the owner/group/mode of the adding directory differs from the
1956 + existing branch, aufs issues a warning because it may impose a
1958 + For example, when a upper writable branch has a world writable empty
1959 + top directory, a malicious user can create any files on the writable
1960 + branch directly, like copy-up and modify manually. If something like
1961 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1962 + writable branch, and the writable branch is world-writable, then a
1963 + malicious guy may create /etc/passwd on the writable branch directly
1964 + and the infected file will be valid in aufs.
1965 + I am afraid it can be a security issue, but aufs can do nothing except
1966 + producing a warning.
1970 +----------------------------------------------------------------------
1971 +o Confirm the deleting branch is not busy
1972 + To be general, there is one merit to adopt "remount" interface to
1973 + manipulate branches. It is to discard caches. At deleting a branch,
1974 + aufs checks the still cached (and connected) dentries and inodes. If
1975 + there are any, then they are all in-use. An inode without its
1976 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1978 + For the cached one, aufs checks whether the same named entry exists on
1980 + If the cached one is a directory, because aufs provides a merged view
1981 + to users, as long as one dir is left on any branch aufs can show the
1982 + dir to users. In this case, the branch can be removed from aufs.
1983 + Otherwise aufs rejects deleting the branch.
1985 + If any file on the deleting branch is opened by aufs, then aufs
1989 +Modify the Permission of a Branch
1990 +----------------------------------------------------------------------
1991 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1994 +o rw --> ro: Confirm the modifying branch is not busy
1995 + Aufs rejects the request if any of these conditions are true.
1996 + - a file on the branch is mmap-ed.
1997 + - a regular file on the branch is opened for write and there is no
1998 + same named entry on the upper branch.
1999 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
2000 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
2001 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2017-07-29 12:14:25.893041746 +0200
2004 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2006 +# This program is free software; you can redistribute it and/or modify
2007 +# it under the terms of the GNU General Public License as published by
2008 +# the Free Software Foundation; either version 2 of the License, or
2009 +# (at your option) any later version.
2011 +# This program is distributed in the hope that it will be useful,
2012 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2013 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2014 +# GNU General Public License for more details.
2016 +# You should have received a copy of the GNU General Public License
2017 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2019 +Policies to Select One among Multiple Writable Branches
2020 +----------------------------------------------------------------------
2021 +When the number of writable branch is more than one, aufs has to decide
2022 +the target branch for file creation or copy-up. By default, the highest
2023 +writable branch which has the parent (or ancestor) dir of the target
2024 +file is chosen (top-down-parent policy).
2025 +By user's request, aufs implements some other policies to select the
2026 +writable branch, for file creation several policies, round-robin,
2027 +most-free-space, and other policies. For copy-up, top-down-parent,
2028 +bottom-up-parent, bottom-up and others.
2030 +As expected, the round-robin policy selects the branch in circular. When
2031 +you have two writable branches and creates 10 new files, 5 files will be
2032 +created for each branch. mkdir(2) systemcall is an exception. When you
2033 +create 10 new directories, all will be created on the same branch.
2034 +And the most-free-space policy selects the one which has most free
2035 +space among the writable branches. The amount of free space will be
2036 +checked by aufs internally, and users can specify its time interval.
2038 +The policies for copy-up is more simple,
2039 +top-down-parent is equivalent to the same named on in create policy,
2040 +bottom-up-parent selects the writable branch where the parent dir
2041 +exists and the nearest upper one from the copyup-source,
2042 +bottom-up selects the nearest upper writable branch from the
2043 +copyup-source, regardless the existence of the parent dir.
2045 +There are some rules or exceptions to apply these policies.
2046 +- If there is a readonly branch above the policy-selected branch and
2047 + the parent dir is marked as opaque (a variation of whiteout), or the
2048 + target (creating) file is whiteout-ed on the upper readonly branch,
2049 + then the result of the policy is ignored and the target file will be
2050 + created on the nearest upper writable branch than the readonly branch.
2051 +- If there is a writable branch above the policy-selected branch and
2052 + the parent dir is marked as opaque or the target file is whiteouted
2053 + on the branch, then the result of the policy is ignored and the target
2054 + file will be created on the highest one among the upper writable
2055 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2057 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2058 + They try selecting the branch where the source exists as possible
2059 + since copyup a large file will take long time. If it can't be,
2060 + ie. the branch where the source exists is readonly, then they will
2061 + follow the copyup policy.
2062 +- There is an exception for rename(2) when the target exists.
2063 + If the rename target exists, aufs compares the index of the branches
2064 + where the source and the target exists and selects the higher
2065 + one. If the selected branch is readonly, then aufs follows the
2067 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2068 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2069 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2017-11-12 22:24:44.694244127 +0100
2072 +// to view this graph, run dot(1) command in GRAPHVIZ.
2076 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2080 +aufs_rename -> whinfo [label="store/remove"];
2083 +inode_list [label="h_inum list in branch\ncache"];
2086 +whinode [label="h_inum list file"];
2089 +brmgmt [label="br_add/del/mod/umount"];
2091 +brmgmt -> inode_list [label="create/remove"];
2092 +brmgmt -> whinode [label="load/store"];
2094 +inode_list -> whinode [style=dashed,dir=both];
2096 +aufs_rename -> inode_list [label="add/del"];
2098 +aufs_lookup -> inode_list [label="search"];
2100 +aufs_lookup -> whinfo [label="load/remove"];
2102 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2103 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2104 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2017-11-12 22:24:44.694244127 +0100
2107 +# Copyright (C) 2017 Junjiro R. Okajima
2109 +# This program is free software; you can redistribute it and/or modify
2110 +# it under the terms of the GNU General Public License as published by
2111 +# the Free Software Foundation; either version 2 of the License, or
2112 +# (at your option) any later version.
2114 +# This program is distributed in the hope that it will be useful,
2115 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2116 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2117 +# GNU General Public License for more details.
2119 +# You should have received a copy of the GNU General Public License
2120 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2122 +Special handling for renaming a directory (DIRREN)
2123 +----------------------------------------------------------------------
2124 +First, let's assume we have a simple usecase.
2128 +- /ro/dirA and /ro/dirA/file exist too
2129 +- there is no dirB on both branches
2130 +- a user issues rename("dirA", "dirB")
2132 +Now, what should aufs behave against this rename(2)?
2133 +There are a few possible cases.
2136 + since dirA exists on a readonly branch which cannot be renamed.
2138 + it is possible to copy-up dirA (only the dir itself), but the child
2139 + entries ("file" in this case) should not be. it must be a bad
2140 + approach to copy-up recursively.
2141 +C. returns a success.
2142 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2143 + is a violation of aufs' policy.
2144 +D. construct an extra information which indicates that /ro/dirA should
2145 + be handled as the name of dirB.
2146 + overlayfs has a similar feature called REDIRECT.
2148 +Until now, aufs implements the case B only which returns EXDEV, and
2149 +expects the userspace application behaves like mv(1) which tries
2150 +issueing rename(2) recursively.
2152 +A new aufs feature called DIRREN is introduced which implements the case
2153 +D. There are several "extra information" added.
2155 +1. detailed info per renamed directory
2156 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2157 +2. the inode-number list of directories on a branch
2158 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2160 +The filename of "detailed info per directory" represents the lower
2161 +branch, and its format is
2162 +- a type of the branch id
2164 + + uuid (not implemented yet)
2167 +- the inode-number of the branch root dir
2169 +And it contains these info in a single regular file.
2171 +- branch's inode-number of the logically renamed dir
2172 +- the name of the before-renamed dir
2174 +The "detailed info per directory" file is created in aufs rename(2), and
2175 +loaded in any lookup.
2176 +The info is considered in lookup for the matching case only. Here
2177 +"matching" means that the root of branch (in the info filename) is same
2178 +to the current looking-up branch. After looking-up the before-renamed
2179 +name, the inode-number is compared. And the matched dentry is used.
2181 +The "inode-number list of directories" is a regular file which contains
2182 +simply the inode-numbers on the branch. The file is created or updated
2183 +in removing the branch, and loaded in adding the branch. Its lifetime is
2184 +equal to the branch.
2185 +The list is refered in lookup, and when the current target inode is
2186 +found in the list, the aufs tries loading the "detailed info per
2187 +directory" and get the changed and valid name of the dir.
2189 +Theoretically these "extra informaiton" may be able to be put into XATTR
2190 +in the dir inode. But aufs doesn't choose this way because
2191 +1. XATTR may not be supported by the branch (or its configuration)
2192 +2. XATTR may have its size limit.
2193 +3. XATTR may be less easy to convert than a regular file, when the
2194 + format of the info is changed in the future.
2195 +At the same time, I agree that the regular file approach is much slower
2196 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2199 +This DIRREN feature is enabled by aufs configuration, and is activated
2200 +by a new mount option.
2202 +For the more complicated case, there is a work with UDBA option, which
2203 +is to dected the direct access to the branches (by-passing aufs) and to
2204 +maintain the cashes in aufs. Since a single cached aufs dentry may
2205 +contains two names, before- and after-rename, the name comparision in
2206 +UDBA handler may not work correctly. In this case, the behaviour will be
2207 +equivalen to udba=reval case.
2208 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2209 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2210 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2017-07-29 12:14:25.896375188 +0200
2213 +# Copyright (C) 2011-2017 Junjiro R. Okajima
2215 +# This program is free software; you can redistribute it and/or modify
2216 +# it under the terms of the GNU General Public License as published by
2217 +# the Free Software Foundation; either version 2 of the License, or
2218 +# (at your option) any later version.
2220 +# This program is distributed in the hope that it will be useful,
2221 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2222 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2223 +# GNU General Public License for more details.
2225 +# You should have received a copy of the GNU General Public License
2226 +# along with this program; if not, write to the Free Software
2227 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2230 +File-based Hierarchical Storage Management (FHSM)
2231 +----------------------------------------------------------------------
2232 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2233 +storage world. Aufs provides this feature as file-based with multiple
2234 +writable branches, based upon the principle of "Colder, the Lower".
2235 +Here the word "colder" means that the less used files, and "lower" means
2236 +that the position in the order of the stacked branches vertically.
2237 +These multiple writable branches are prioritized, ie. the topmost one
2238 +should be the fastest drive and be used heavily.
2240 +o Characters in aufs FHSM story
2241 +- aufs itself and a new branch attribute.
2242 +- a new ioctl interface to move-down and to establish a connection with
2243 + the daemon ("move-down" is a converse of "copy-up").
2244 +- userspace tool and daemon.
2246 +The userspace daemon establishes a connection with aufs and waits for
2247 +the notification. The notified information is very similar to struct
2248 +statfs containing the number of consumed blocks and inodes.
2249 +When the consumed blocks/inodes of a branch exceeds the user-specified
2250 +upper watermark, the daemon activates its move-down process until the
2251 +consumed blocks/inodes reaches the user-specified lower watermark.
2253 +The actual move-down is done by aufs based upon the request from
2254 +user-space since we need to maintain the inode number and the internal
2255 +pointer arrays in aufs.
2257 +Currently aufs FHSM handles the regular files only. Additionally they
2258 +must not be hard-linked nor pseudo-linked.
2261 +o Cowork of aufs and the user-space daemon
2262 + During the userspace daemon established the connection, aufs sends a
2263 + small notification to it whenever aufs writes something into the
2264 + writable branch. But it may cost high since aufs issues statfs(2)
2265 + internally. So user can specify a new option to cache the
2266 + info. Actually the notification is controlled by these factors.
2267 + + the specified cache time.
2268 + + classified as "force" by aufs internally.
2269 + Until the specified time expires, aufs doesn't send the info
2270 + except the forced cases. When aufs decide forcing, the info is always
2271 + notified to userspace.
2272 + For example, the number of free inodes is generally large enough and
2273 + the shortage of it happens rarely. So aufs doesn't force the
2274 + notification when creating a new file, directory and others. This is
2275 + the typical case which aufs doesn't force.
2276 + When aufs writes the actual filedata and the files consumes any of new
2277 + blocks, the aufs forces notifying.
2280 +o Interfaces in aufs
2281 +- New branch attribute.
2283 + Specifies that the branch is managed by FHSM feature. In other word,
2284 + participant in the FHSM.
2285 + When nofhsm is set to the branch, it will not be the source/target
2286 + branch of the move-down operation. This attribute is set
2287 + independently from coo and moo attributes, and if you want full
2288 + FHSM, you should specify them as well.
2289 +- New mount option.
2291 + Specifies a second to suppress many less important info to be
2294 + + AUFS_CTL_FHSM_FD
2295 + create a new file descriptor which userspace can read the notification
2296 + (a subset of struct statfs) from aufs.
2297 +- Module parameter 'brs'
2298 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2300 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2301 + When there are two or more branches with fhsm attributes,
2302 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2303 + terminates it. As a result of remounting and branch-manipulation, the
2304 + number of branches with fhsm attribute can be one. In this case,
2305 + /sbin/mount.aufs will terminate the user-space daemon.
2308 +Finally the operation is done as these steps in kernel-space.
2310 + + no one else is using the file.
2311 + + the file is not hard-linked.
2312 + + the file is not pseudo-linked.
2313 + + the file is a regular file.
2314 + + the parent dir is not opaqued.
2315 +- find the target writable branch.
2316 +- make sure the file is not whiteout-ed by the upper (than the target)
2318 +- make the parent dir on the target branch.
2319 +- mutex lock the inode on the branch.
2320 +- unlink the whiteout on the target branch (if exists).
2321 +- lookup and create the whiteout-ed temporary name on the target branch.
2322 +- copy the file as the whiteout-ed temporary name on the target branch.
2323 +- rename the whiteout-ed temporary name to the original name.
2324 +- unlink the file on the source branch.
2325 +- maintain the internal pointer array and the external inode number
2327 +- maintain the timestamps and other attributes of the parent dir and the
2330 +And of course, in every step, an error may happen. So the operation
2331 +should restore the original file state after an error happens.
2332 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2333 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2334 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2017-07-29 12:14:25.896375188 +0200
2337 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2339 +# This program is free software; you can redistribute it and/or modify
2340 +# it under the terms of the GNU General Public License as published by
2341 +# the Free Software Foundation; either version 2 of the License, or
2342 +# (at your option) any later version.
2344 +# This program is distributed in the hope that it will be useful,
2345 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2346 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2347 +# GNU General Public License for more details.
2349 +# You should have received a copy of the GNU General Public License
2350 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2352 +mmap(2) -- File Memory Mapping
2353 +----------------------------------------------------------------------
2354 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2355 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2357 +This approach is simple and good, but there is one problem.
2358 +Under /proc, several entries show the mmapped files by its path (with
2359 +device and inode number), and the printed path will be the path on the
2360 +branch fs's instead of virtual aufs's.
2361 +This is not a problem in most cases, but some utilities lsof(1) (and its
2362 +user) may expect the path on aufs.
2364 +To address this issue, aufs adds a new member called vm_prfile in struct
2365 +vm_area_struct (and struct vm_region). The original vm_file points to
2366 +the file on the branch fs in order to handle everything correctly as
2367 +usual. The new vm_prfile points to a virtual file in aufs, and the
2368 +show-functions in procfs refers to vm_prfile if it is set.
2369 +Also we need to maintain several other places where touching vm_file
2371 +- fork()/clone() copies vma and the reference count of vm_file is
2373 +- merging vma maintains the ref count too.
2375 +This is not a good approach. It just fakes the printed path. But it
2376 +leaves all behaviour around f_mapping unchanged. This is surely an
2378 +Actually aufs had adopted another complicated approach which calls
2379 +generic_file_mmap() and handles struct vm_operations_struct. In this
2380 +approach, aufs met a hard problem and I could not solve it without
2381 +switching the approach.
2383 +There may be one more another approach which is
2384 +- bind-mount the branch-root onto the aufs-root internally
2385 +- grab the new vfsmount (ie. struct mount)
2386 +- lazy-umount the branch-root internally
2387 +- in open(2) the aufs-file, open the branch-file with the hidden
2388 + vfsmount (instead of the original branch's vfsmount)
2389 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2390 + but it may be possible from userspace by the mount helper.
2392 +Adding the internal hidden vfsmount and using it in opening a file, the
2393 +file path under /proc will be printed correctly. This approach looks
2394 +smarter, but is not possible I am afraid.
2395 +- aufs-root may be bind-mount later. when it happens, another hidden
2396 + vfsmount will be required.
2397 +- it is hard to get the chance to bind-mount and lazy-umount
2398 + + in kernel-space, FS can have vfsmount in open(2) via
2399 + file->f_path, and aufs can know its vfsmount. But several locks are
2400 + already acquired, and if aufs tries to bind-mount and lazy-umount
2401 + here, then it may cause a deadlock.
2402 + + in user-space, bind-mount doesn't invoke the mount helper.
2403 +- since /proc shows dev and ino, aufs has to give vma these info. it
2404 + means a new member vm_prinode will be necessary. this is essentially
2405 + equivalent to vm_prfile described above.
2407 +I have to give up this "looks-smater" approach.
2408 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2409 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2410 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2017-07-29 12:14:25.896375188 +0200
2413 +# Copyright (C) 2014-2017 Junjiro R. Okajima
2415 +# This program is free software; you can redistribute it and/or modify
2416 +# it under the terms of the GNU General Public License as published by
2417 +# the Free Software Foundation; either version 2 of the License, or
2418 +# (at your option) any later version.
2420 +# This program is distributed in the hope that it will be useful,
2421 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2422 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2423 +# GNU General Public License for more details.
2425 +# You should have received a copy of the GNU General Public License
2426 +# along with this program; if not, write to the Free Software
2427 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2430 +Listing XATTR/EA and getting the value
2431 +----------------------------------------------------------------------
2432 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2433 +shows the values from the topmost existing file. This behaviour is good
2434 +for the non-dir entries since the bahaviour exactly matches the shown
2435 +information. But for the directories, aufs considers all the same named
2436 +entries on the lower branches. Which means, if one of the lower entry
2437 +rejects readdir call, then aufs returns an error even if the topmost
2438 +entry allows it. This behaviour is necessary to respect the branch fs's
2439 +security, but can make users confused since the user-visible standard
2440 +attributes don't match the behaviour.
2441 +To address this issue, aufs has a mount option called dirperm1 which
2442 +checks the permission for the topmost entry only, and ignores the lower
2443 +entry's permission.
2445 +A similar issue can happen around XATTR.
2446 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2447 +always set. Otherwise these very unpleasant situation would happen.
2448 +- listxattr(2) may return the duplicated entries.
2449 +- users may not be able to remove or reset the XATTR forever,
2452 +XATTR/EA support in the internal (copy,move)-(up,down)
2453 +----------------------------------------------------------------------
2454 +Generally the extended attributes of inode are categorized as these.
2455 +- "security" for LSM and capability.
2456 +- "system" for posix ACL, 'acl' mount option is required for the branch
2458 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2459 +- "user" for userspace, 'user_xattr' mount option is required for the
2460 + branch fs generally.
2462 +Moreover there are some other categories. Aufs handles these rather
2463 +unpopular categories as the ordinary ones, ie. there is no special
2464 +condition nor exception.
2466 +In copy-up, the support for XATTR on the dst branch may differ from the
2467 +src branch. In this case, the copy-up operation will get an error and
2468 +the original user operation which triggered the copy-up will fail. It
2469 +can happen that even all copy-up will fail.
2470 +When both of src and dst branches support XATTR and if an error occurs
2471 +during copying XATTR, then the copy-up should fail obviously. That is a
2472 +good reason and aufs should return an error to userspace. But when only
2473 +the src branch support that XATTR, aufs should not return an error.
2474 +For example, the src branch supports ACL but the dst branch doesn't
2475 +because the dst branch may natively un-support it or temporary
2476 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2477 +may NOT return an error even if the XATTR is not supported. It is
2478 +totally up to the branch fs.
2480 +Anyway when the aufs internal copy-up gets an error from the dst branch
2481 +fs, then aufs tries removing the just copied entry and returns the error
2482 +to the userspace. The worst case of this situation will be all copy-up
2485 +For the copy-up operation, there two basic approaches.
2486 +- copy the specified XATTR only (by category above), and return the
2487 + error unconditionally if it happens.
2488 +- copy all XATTR, and ignore the error on the specified category only.
2490 +In order to support XATTR and to implement the correct behaviour, aufs
2491 +chooses the latter approach and introduces some new branch attributes,
2492 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2493 +They correspond to the XATTR namespaces (see above). Additionally, to be
2494 +convenient, "icex" is also provided which means all "icex*" attributes
2495 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2497 +The meaning of these attributes is to ignore the error from setting
2498 +XATTR on that branch.
2499 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2500 +error from the dst branch according to the specified attributes.
2502 +Some XATTR may have its default value. The default value may come from
2503 +the parent dir or the environment. If the default value is set at the
2504 +file creating-time, it will be overwritten by copy-up.
2505 +Some contradiction may happen I am afraid.
2506 +Do we need another attribute to stop copying XATTR? I am unsure. For
2507 +now, aufs implements the branch attributes to ignore the error.
2508 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2509 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2510 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2017-07-29 12:14:25.896375188 +0200
2513 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2515 +# This program is free software; you can redistribute it and/or modify
2516 +# it under the terms of the GNU General Public License as published by
2517 +# the Free Software Foundation; either version 2 of the License, or
2518 +# (at your option) any later version.
2520 +# This program is distributed in the hope that it will be useful,
2521 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2522 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2523 +# GNU General Public License for more details.
2525 +# You should have received a copy of the GNU General Public License
2526 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2528 +Export Aufs via NFS
2529 +----------------------------------------------------------------------
2530 +Here is an approach.
2531 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2533 +- iget_locked(): initialize aufs inode generation for a new inode, and
2534 + store it in xigen file.
2535 +- destroy_inode(): increment aufs inode generation and store it in xigen
2536 + file. it is necessary even if it is not unlinked, because any data of
2537 + inode may be changed by UDBA.
2538 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2539 + build file handle by
2540 + + branch id (4 bytes)
2541 + + superblock generation (4 bytes)
2542 + + inode number (4 or 8 bytes)
2543 + + parent dir inode number (4 or 8 bytes)
2544 + + inode generation (4 bytes))
2545 + + return value of exportfs_encode_fh() for the parent on a branch (4
2547 + + file handle for a branch (by exportfs_encode_fh())
2549 + + find the index of a branch from its id in handle, and check it is
2550 + still exist in aufs.
2551 + + 1st level: get the inode number from handle and search it in cache.
2552 + + 2nd level: if not found in cache, get the parent inode number from
2553 + the handle and search it in cache. and then open the found parent
2554 + dir, find the matching inode number by vfs_readdir() and get its
2555 + name, and call lookup_one_len() for the target dentry.
2556 + + 3rd level: if the parent dir is not cached, call
2557 + exportfs_decode_fh() for a branch and get the parent on a branch,
2558 + build a pathname of it, convert it a pathname in aufs, call
2559 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2561 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2562 + for every branch, but not itself. to get this, (currently) aufs
2563 + searches in current->nsproxy->mnt_ns list. it may not be a good
2564 + idea, but I didn't get other approach.
2565 + + test the generation of the gotten inode.
2566 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2567 + convert it into ESTALE for NFSD.
2568 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2569 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2570 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2571 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2572 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2017-07-29 12:14:25.896375188 +0200
2575 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2577 +# This program is free software; you can redistribute it and/or modify
2578 +# it under the terms of the GNU General Public License as published by
2579 +# the Free Software Foundation; either version 2 of the License, or
2580 +# (at your option) any later version.
2582 +# This program is distributed in the hope that it will be useful,
2583 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2584 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2585 +# GNU General Public License for more details.
2587 +# You should have received a copy of the GNU General Public License
2588 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2590 +Show Whiteout Mode (shwh)
2591 +----------------------------------------------------------------------
2592 +Generally aufs hides the name of whiteouts. But in some cases, to show
2593 +them is very useful for users. For instance, creating a new middle layer
2594 +(branch) by merging existing layers.
2596 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2597 +When you have three branches,
2598 +- Bottom: 'system', squashfs (underlying base system), read-only
2599 +- Middle: 'mods', squashfs, read-only
2600 +- Top: 'overlay', ram (tmpfs), read-write
2602 +The top layer is loaded at boot time and saved at shutdown, to preserve
2603 +the changes made to the system during the session.
2604 +When larger changes have been made, or smaller changes have accumulated,
2605 +the size of the saved top layer data grows. At this point, it would be
2606 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2607 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2608 +restoring save and load speed.
2610 +This merging is simplified by the use of another aufs mount, of just the
2611 +two overlay branches using the 'shwh' option.
2612 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2613 + aufs /livesys/merge_union
2615 +A merged view of these two branches is then available at
2616 +/livesys/merge_union, and the new feature is that the whiteouts are
2618 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2619 +writing to all branches. Also the default mode for all branches is 'ro'.
2620 +It is now possible to save the combined contents of the two overlay
2621 +branches to a new squashfs, e.g.:
2622 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2624 +This new squashfs archive can be stored on the boot device and the
2625 +initramfs will use it to replace the old one at the next boot.
2626 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2627 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2628 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2017-07-29 12:14:25.896375188 +0200
2631 +# Copyright (C) 2010-2017 Junjiro R. Okajima
2633 +# This program is free software; you can redistribute it and/or modify
2634 +# it under the terms of the GNU General Public License as published by
2635 +# the Free Software Foundation; either version 2 of the License, or
2636 +# (at your option) any later version.
2638 +# This program is distributed in the hope that it will be useful,
2639 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2640 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2641 +# GNU General Public License for more details.
2643 +# You should have received a copy of the GNU General Public License
2644 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2646 +Dynamically customizable FS operations
2647 +----------------------------------------------------------------------
2648 +Generally FS operations (struct inode_operations, struct
2649 +address_space_operations, struct file_operations, etc.) are defined as
2650 +"static const", but it never means that FS have only one set of
2651 +operation. Some FS have multiple sets of them. For instance, ext2 has
2652 +three sets, one for XIP, for NOBH, and for normal.
2653 +Since aufs overrides and redirects these operations, sometimes aufs has
2654 +to change its behaviour according to the branch FS type. More importantly
2655 +VFS acts differently if a function (member in the struct) is set or
2656 +not. It means aufs should have several sets of operations and select one
2657 +among them according to the branch FS definition.
2659 +In order to solve this problem and not to affect the behaviour of VFS,
2660 +aufs defines these operations dynamically. For instance, aufs defines
2661 +dummy direct_IO function for struct address_space_operations, but it may
2662 +not be set to the address_space_operations actually. When the branch FS
2663 +doesn't have it, aufs doesn't set it to its address_space_operations
2664 +while the function definition itself is still alive. So the behaviour
2665 +itself will not change, and it will return an error when direct_IO is
2668 +The lifetime of these dynamically generated operation object is
2669 +maintained by aufs branch object. When the branch is removed from aufs,
2670 +the reference counter of the object is decremented. When it reaches
2671 +zero, the dynamically generated operation object will be freed.
2673 +This approach is designed to support AIO (io_submit), Direct I/O and
2675 +Currently this approach is applied to address_space_operations for
2676 +regular files only.
2677 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2678 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2679 +++ linux/Documentation/filesystems/aufs/README 2017-07-29 12:14:25.893041746 +0200
2682 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2688 +----------------------------------------
2689 +In the early days, aufs was entirely re-designed and re-implemented
2690 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2691 +improvements and implementations, it becomes totally different from
2692 +Unionfs while keeping the basic features.
2693 +Recently, Unionfs Version 2.x series begin taking some of the same
2694 +approaches to aufs1's.
2695 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2696 +University and his team.
2698 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2699 +If you want older kernel version support, try aufs2-2.6.git or
2700 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2702 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2703 + According to Christoph Hellwig, linux rejects all union-type
2704 + filesystems but UnionMount.
2705 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2707 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2708 + UnionMount, and he pointed out an issue around a directory mutex
2709 + lock and aufs addressed it. But it is still unsure whether aufs will
2710 + be merged (or any other union solution).
2711 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2715 +----------------------------------------
2716 +- unite several directories into a single virtual filesystem. The member
2717 + directory is called as a branch.
2718 +- you can specify the permission flags to the branch, which are 'readonly',
2719 + 'readwrite' and 'whiteout-able.'
2720 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2721 + readonly branch are modifiable logically.
2722 +- dynamic branch manipulation, add, del.
2725 +Also there are many enhancements in aufs, such as:
2726 +- test only the highest one for the directory permission (dirperm1)
2727 +- copyup on open (coo=)
2728 +- 'move' policy for copy-up between two writable branches, after
2729 + checking free space.
2731 +- readdir(3) in userspace.
2732 +- keep inode number by external inode number table
2733 +- keep the timestamps of file/dir in internal copyup operation
2734 +- seekable directory, supporting NFS readdir.
2735 +- whiteout is hardlinked in order to reduce the consumption of inodes
2737 +- do not copyup, nor create a whiteout when it is unnecessary
2738 +- revert a single systemcall when an error occurs in aufs
2739 +- remount interface instead of ioctl
2740 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2741 +- loopback mounted filesystem as a branch
2742 +- kernel thread for removing the dir who has a plenty of whiteouts
2743 +- support copyup sparse file (a file which has a 'hole' in it)
2744 +- default permission flags for branches
2745 +- selectable permission flags for ro branch, whether whiteout can
2748 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2749 +- support multiple writable branches, some policies to select one
2750 + among multiple writable branches.
2751 +- a new semantics for link(2) and rename(2) to support multiple
2752 + writable branches.
2753 +- no glibc changes are required.
2754 +- pseudo hardlink (hardlink over branches)
2755 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2756 + including NFS or remote filesystem branch.
2757 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2760 +Currently these features are dropped temporary from aufs4.
2761 +See design/08plan.txt in detail.
2762 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2764 +- statistics of aufs thread (/sys/fs/aufs/stat)
2766 +Features or just an idea in the future (see also design/*.txt),
2767 +- reorder the branch index without del/re-add.
2768 +- permanent xino files for NFSD
2769 +- an option for refreshing the opened files after add/del branches
2770 +- light version, without branch manipulation. (unnecessary?)
2771 +- copyup in userspace
2772 +- inotify in userspace
2777 +----------------------------------------
2778 +There are three GIT trees for aufs4, aufs4-linux.git,
2779 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2781 +While the aufs-util is always necessary, you need either of aufs4-linux
2782 +or aufs4-standalone.
2784 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2785 +git://git.kernel.org/.../torvalds/linux.git.
2786 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2787 +build aufs4 as an external kernel module.
2788 +Several extra patches are not included in this tree. Only
2789 +aufs4-standalone tree contains them. They are described in the later
2790 +section "Configuration and Compilation."
2792 +On the other hand, the aufs4-standalone tree has only aufs source files
2793 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2794 +But you need to apply all aufs patches manually.
2796 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2797 +represents the linux kernel version, "linux-4.x". For instance,
2798 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2799 +"aufs4.x-rcN" branch.
2802 +$ git clone --reference /your/linux/git/tree \
2803 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2804 +- if you don't have linux GIT tree, then remove "--reference ..."
2805 +$ cd aufs4-linux.git
2806 +$ git checkout origin/aufs4.0
2808 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2809 +leave the patch-work to GIT.
2810 +$ cd /your/linux/git/tree
2811 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2813 +$ git checkout -b my4.0 v4.0
2814 +$ (add your local change...)
2815 +$ git pull aufs4 aufs4.0
2816 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2817 +- you may need to solve some conflicts between your_changes and
2818 + aufs4.0. in this case, git-rerere is recommended so that you can
2819 + solve the similar conflicts automatically when you upgrade to 4.1 or
2820 + later in the future.
2822 +o aufs4-standalone tree
2823 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2824 +$ cd aufs4-standalone.git
2825 +$ git checkout origin/aufs4.0
2828 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2829 +- note that the public aufs-util.git is on SourceForge instead of
2832 +$ git checkout origin/aufs4.0
2834 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2835 +The minor version number, 'x' in '4.x', of aufs may not always
2836 +follow the minor version number of the kernel.
2837 +Because changes in the kernel that cause the use of a new
2838 +minor version number do not always require changes to aufs-util.
2840 +Since aufs-util has its own minor version number, you may not be
2841 +able to find a GIT branch in aufs-util for your kernel's
2842 +exact minor version number.
2843 +In this case, you should git-checkout the branch for the
2844 +nearest lower number.
2846 +For (an unreleased) example:
2847 +If you are using "linux-4.10" and the "aufs4.10" branch
2848 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2849 +or something numerically smaller is the branch for your kernel.
2851 +Also you can view all branches by
2855 +3. Configuration and Compilation
2856 +----------------------------------------
2857 +Make sure you have git-checkout'ed the correct branch.
2859 +For aufs4-linux tree,
2860 +- enable CONFIG_AUFS_FS.
2861 +- set other aufs configurations if necessary.
2863 +For aufs4-standalone tree,
2864 +There are several ways to build.
2867 +- apply ./aufs4-kbuild.patch to your kernel source files.
2868 +- apply ./aufs4-base.patch too.
2869 +- apply ./aufs4-mmap.patch too.
2870 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2871 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2872 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2873 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2874 +- enable CONFIG_AUFS_FS, you can select either
2876 +- and build your kernel as usual.
2877 +- install the built kernel.
2878 + Note: Since linux-3.9, every filesystem module requires an alias
2879 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2880 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2881 +- install the header files too by "make headers_install" to the
2882 + directory where you specify. By default, it is $PWD/usr.
2883 + "make help" shows a brief note for headers_install.
2884 +- and reboot your system.
2887 +- module only (CONFIG_AUFS_FS=m).
2888 +- apply ./aufs4-base.patch to your kernel source files.
2889 +- apply ./aufs4-mmap.patch too.
2890 +- apply ./aufs4-standalone.patch too.
2891 +- build your kernel, don't forget "make headers_install", and reboot.
2892 +- edit ./config.mk and set other aufs configurations if necessary.
2893 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2894 + every aufs configurations.
2895 +- build the module by simple "make".
2896 + Note: Since linux-3.9, every filesystem module requires an alias
2897 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2898 + modules.aliases file.
2899 +- you can specify ${KDIR} make variable which points to your kernel
2901 +- install the files
2902 + + run "make install" to install the aufs module, or copy the built
2903 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2904 + + run "make install_headers" (instead of headers_install) to install
2905 + the modified aufs header file (you can specify DESTDIR which is
2906 + available in aufs standalone version's Makefile only), or copy
2907 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2908 + you like manually. By default, the target directory is $PWD/usr.
2909 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2910 + kernel source tree.
2912 +Note: The header file aufs_type.h is necessary to build aufs-util
2913 + as well as "make headers_install" in the kernel source tree.
2914 + headers_install is subject to be forgotten, but it is essentially
2915 + necessary, not only for building aufs-util.
2916 + You may not meet problems without headers_install in some older
2920 +- read README in aufs-util, build and install it
2921 +- note that your distribution may contain an obsoleted version of
2922 + aufs_type.h in /usr/include/linux or something. When you build aufs
2923 + utilities, make sure that your compiler refers the correct aufs header
2924 + file which is built by "make headers_install."
2925 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2926 + then run "make install_ulib" too. And refer to the aufs manual in
2929 +There several other patches in aufs4-standalone.git. They are all
2930 +optional. When you meet some problems, they will help you.
2931 +- aufs4-loopback.patch
2932 + Supports a nested loopback mount in a branch-fs. This patch is
2933 + unnecessary until aufs produces a message like "you may want to try
2934 + another patch for loopback file".
2936 + Modifies a system global kernel internal function get_next_ino() in
2937 + order to stop assigning 0 for an inode-number. Not directly related to
2938 + aufs, but recommended generally.
2940 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2941 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2942 + duplication of inode number, which is important for backup tools and
2943 + other utilities. When you find aufs XINO files for tmpfs branch
2944 + growing too much, try this patch.
2945 +- lockdep-debug.patch
2946 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2947 + also a caller of VFS functions for branch filesystems, subclassing of
2948 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2949 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2950 + need to apply this debug patch to expand several constant values.
2951 + If don't know what LOCKDEP, then you don't have apply this patch.
2955 +----------------------------------------
2956 +At first, make sure aufs-util are installed, and please read the aufs
2957 +manual, aufs.5 in aufs-util.git tree.
2961 +$ mkdir /tmp/rw /tmp/aufs
2962 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2964 +Here is another example. The result is equivalent.
2965 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2967 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2968 +# mount -o remount,append:${HOME} /tmp/aufs
2970 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2971 +you modify a file under /tmp/aufs, the one on your home directory is
2972 +not affected, instead the same named file will be newly created under
2973 +/tmp/rw. And all of your modification to a file will be applied to
2974 +the one under /tmp/rw. This is called the file based Copy on Write
2976 +Aufs mount options are described in aufs.5.
2977 +If you run chroot or something and make your aufs as a root directory,
2978 +then you need to customize the shutdown script. See the aufs manual in
2981 +Additionally, there are some sample usages of aufs which are a
2982 +diskless system with network booting, and LiveCD over NFS.
2983 +See sample dir in CVS tree on SourceForge.
2987 +----------------------------------------
2988 +When you have any problems or strange behaviour in aufs, please let me
2990 +- /proc/mounts (instead of the output of mount(8))
2991 +- /sys/module/aufs/*
2992 +- /sys/fs/aufs/* (if you have them)
2993 +- /debug/aufs/* (if you have them)
2994 +- linux kernel version
2995 + if your kernel is not plain, for example modified by distributor,
2996 + the url where i can download its source is necessary too.
2997 +- aufs version which was printed at loading the module or booting the
2998 + system, instead of the date you downloaded.
2999 +- configuration (define/undefine CONFIG_AUFS_xxx)
3000 +- kernel configuration or /proc/config.gz (if you have it)
3001 +- behaviour which you think to be incorrect
3002 +- actual operation, reproducible one is better
3003 +- mailto: aufs-users at lists.sourceforge.net
3005 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
3006 +and Feature Requests) on SourceForge. Please join and write to
3010 +6. Acknowledgements
3011 +----------------------------------------
3012 +Thanks to everyone who have tried and are using aufs, whoever
3013 +have reported a bug or any feedback.
3015 +Especially donators:
3016 +Tomas Matejicek(slax.org) made a donation (much more than once).
3017 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
3018 + scripts) is making "doubling" donations.
3019 + Unfortunately I cannot list all of the donators, but I really
3021 + It ends Aug 2010, but the ordinary donation URL is still available.
3022 + <http://sourceforge.net/donate/index.php?group_id=167503>
3023 +Dai Itasaka made a donation (2007/8).
3024 +Chuck Smith made a donation (2008/4, 10 and 12).
3025 +Henk Schoneveld made a donation (2008/9).
3026 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
3027 +Francois Dupoux made a donation (2008/11).
3028 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
3029 + aufs2 GIT tree (2009/2).
3030 +William Grant made a donation (2009/3).
3031 +Patrick Lane made a donation (2009/4).
3032 +The Mail Archive (mail-archive.com) made donations (2009/5).
3033 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
3034 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
3035 +Pavel Pronskiy made a donation (2011/2).
3036 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
3037 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
3038 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
3040 +Sam Liddicott made a donation (2011/9).
3041 +Era Scarecrow made a donation (2013/4).
3042 +Bor Ratajc made a donation (2013/4).
3043 +Alessandro Gorreta made a donation (2013/4).
3044 +POIRETTE Marc made a donation (2013/4).
3045 +Alessandro Gorreta made a donation (2013/4).
3046 +lauri kasvandik made a donation (2013/5).
3047 +"pemasu from Finland" made a donation (2013/7).
3048 +The Parted Magic Project made a donation (2013/9 and 11).
3049 +Pavel Barta made a donation (2013/10).
3050 +Nikolay Pertsev made a donation (2014/5).
3051 +James B made a donation (2014/7 and 2015/7).
3052 +Stefano Di Biase made a donation (2014/8).
3053 +Daniel Epellei made a donation (2015/1).
3054 +OmegaPhil made a donation (2016/1).
3055 +Tomasz Szewczyk made a donation (2016/4).
3056 +James Burry made a donation (2016/12).
3058 +Thank you very much.
3059 +Donations are always, including future donations, very important and
3060 +helpful for me to keep on developing aufs.
3064 +----------------------------------------
3065 +If you are an experienced user, no explanation is needed. Aufs is
3066 +just a linux filesystem.
3071 +# Local variables: ;
3074 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3075 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3076 +++ linux/fs/aufs/aufs.h 2017-11-12 22:24:44.697577553 +0100
3079 + * Copyright (C) 2005-2017 Junjiro R. Okajima
3081 + * This program, aufs is free software; you can redistribute it and/or modify
3082 + * it under the terms of the GNU General Public License as published by
3083 + * the Free Software Foundation; either version 2 of the License, or
3084 + * (at your option) any later version.
3086 + * This program is distributed in the hope that it will be useful,
3087 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3089 + * GNU General Public License for more details.
3091 + * You should have received a copy of the GNU General Public License
3092 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3096 + * all header files
3104 +#define AuStub(type, name, body, ...) \
3105 + static inline type name(__VA_ARGS__) { body; }
3107 +#define AuStubVoid(name, ...) \
3108 + AuStub(void, name, , __VA_ARGS__)
3109 +#define AuStubInt0(name, ...) \
3110 + AuStub(int, name, return 0, __VA_ARGS__)
3114 +#include "branch.h"
3117 +#include "dbgaufs.h"
3118 +#include "dentry.h"
3120 +#include "dirren.h"
3123 +#include "fstype.h"
3127 +#include "module.h"
3131 +#include "sysaufs.h"
3136 +#endif /* __KERNEL__ */
3137 +#endif /* __AUFS_H__ */
3138 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3139 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3140 +++ linux/fs/aufs/branch.c 2017-11-12 22:24:44.697577553 +0100
3143 + * Copyright (C) 2005-2017 Junjiro R. Okajima
3145 + * This program, aufs is free software; you can redistribute it and/or modify
3146 + * it under the terms of the GNU General Public License as published by
3147 + * the Free Software Foundation; either version 2 of the License, or
3148 + * (at your option) any later version.
3150 + * This program is distributed in the hope that it will be useful,
3151 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3152 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3153 + * GNU General Public License for more details.
3155 + * You should have received a copy of the GNU General Public License
3156 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3160 + * branch management
3163 +#include <linux/compat.h>
3164 +#include <linux/statfs.h>
3168 + * free a single branch
3170 +static void au_br_do_free(struct au_branch *br)
3173 + struct au_wbr *wbr;
3174 + struct au_dykey **key;
3176 + au_hnotify_fin_br(br);
3177 + /* always, regardless the mount option */
3178 + au_dr_hino_free(&br->br_dirren);
3180 + if (br->br_xino.xi_file)
3181 + fput(br->br_xino.xi_file);
3182 + for (i = br->br_xino.xi_nondir.total - 1; i >= 0; i--)
3183 + AuDebugOn(br->br_xino.xi_nondir.array[i]);
3184 + kfree(br->br_xino.xi_nondir.array);
3186 + AuDebugOn(au_br_count(br));
3187 + au_br_count_fin(br);
3191 + for (i = 0; i < AuBrWh_Last; i++)
3192 + dput(wbr->wbr_wh[i]);
3193 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3194 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3197 + if (br->br_fhsm) {
3198 + au_br_fhsm_fin(br->br_fhsm);
3199 + kfree(br->br_fhsm);
3202 + key = br->br_dykey;
3203 + for (i = 0; i < AuBrDynOp; i++, key++)
3209 + /* recursive lock, s_umount of branch's */
3211 + path_put(&br->br_path);
3218 + * frees all branches
3220 +void au_br_free(struct au_sbinfo *sbinfo)
3222 + aufs_bindex_t bmax;
3223 + struct au_branch **br;
3225 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3227 + bmax = sbinfo->si_bbot + 1;
3228 + br = sbinfo->si_branch;
3230 + au_br_do_free(*br++);
3234 + * find the index of a branch which is specified by @br_id.
3236 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3238 + aufs_bindex_t bindex, bbot;
3240 + bbot = au_sbbot(sb);
3241 + for (bindex = 0; bindex <= bbot; bindex++)
3242 + if (au_sbr_id(sb, bindex) == br_id)
3247 +/* ---------------------------------------------------------------------- */
3253 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3254 + struct dentry *h_root)
3256 + if (unlikely(h_adding == h_root
3257 + || au_test_loopback_overlap(sb, h_adding)))
3259 + if (h_adding->d_sb != h_root->d_sb)
3261 + return au_test_subdir(h_adding, h_root)
3262 + || au_test_subdir(h_root, h_adding);
3266 + * returns a newly allocated branch. @new_nbranch is a number of branches
3267 + * after adding a branch.
3269 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3272 + struct au_branch *add_branch;
3273 + struct dentry *root;
3274 + struct inode *inode;
3278 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3279 + if (unlikely(!add_branch))
3281 + add_branch->br_xino.xi_nondir.total = 8; /* initial size */
3282 + add_branch->br_xino.xi_nondir.array
3283 + = kcalloc(add_branch->br_xino.xi_nondir.total, sizeof(ino_t),
3285 + if (unlikely(!add_branch->br_xino.xi_nondir.array))
3288 + err = au_hnotify_init_br(add_branch, perm);
3289 + if (unlikely(err))
3290 + goto out_xinondir;
3292 + if (au_br_writable(perm)) {
3293 + /* may be freed separately at changing the branch permission */
3294 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3296 + if (unlikely(!add_branch->br_wbr))
3300 + if (au_br_fhsm(perm)) {
3301 + err = au_fhsm_br_alloc(add_branch);
3302 + if (unlikely(err))
3306 + root = sb->s_root;
3307 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3309 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3311 + inode = d_inode(root);
3312 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3316 + return add_branch; /* success */
3319 + kfree(add_branch->br_wbr);
3321 + au_hnotify_fin_br(add_branch);
3323 + kfree(add_branch->br_xino.xi_nondir.array);
3325 + kfree(add_branch);
3327 + return ERR_PTR(err);
3331 + * test if the branch permission is legal or not.
3333 +static int test_br(struct inode *inode, int brperm, char *path)
3337 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3342 + pr_err("write permission for readonly mount or inode, %s\n", path);
3350 + * 0: success, the caller will add it
3351 + * plus: success, it is already unified, the caller should ignore it
3354 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3357 + aufs_bindex_t bbot, bindex;
3358 + struct dentry *root, *h_dentry;
3359 + struct inode *inode, *h_inode;
3361 + root = sb->s_root;
3362 + bbot = au_sbbot(sb);
3363 + if (unlikely(bbot >= 0
3364 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3368 + pr_err("%s duplicated\n", add->pathname);
3373 + err = -ENOSPC; /* -E2BIG; */
3374 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3375 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3376 + pr_err("number of branches exceeded %s\n", add->pathname);
3381 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3382 + pr_err("bad index %d\n", add->bindex);
3386 + inode = d_inode(add->path.dentry);
3388 + if (unlikely(!inode->i_nlink)) {
3389 + pr_err("no existence %s\n", add->pathname);
3394 + if (unlikely(inode->i_sb == sb)) {
3395 + pr_err("%s must be outside\n", add->pathname);
3399 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3400 + pr_err("unsupported filesystem, %s (%s)\n",
3401 + add->pathname, au_sbtype(inode->i_sb));
3405 + if (unlikely(inode->i_sb->s_stack_depth)) {
3406 + pr_err("already stacked, %s (%s)\n",
3407 + add->pathname, au_sbtype(inode->i_sb));
3411 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3412 + if (unlikely(err))
3416 + return 0; /* success */
3419 + for (bindex = 0; bindex <= bbot; bindex++)
3420 + if (unlikely(test_overlap(sb, add->path.dentry,
3421 + au_h_dptr(root, bindex)))) {
3422 + pr_err("%s is overlapped\n", add->pathname);
3427 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3428 + h_dentry = au_h_dptr(root, 0);
3429 + h_inode = d_inode(h_dentry);
3430 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3431 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3432 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3433 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3435 + i_uid_read(inode), i_gid_read(inode),
3436 + (inode->i_mode & S_IALLUGO),
3437 + i_uid_read(h_inode), i_gid_read(h_inode),
3438 + (h_inode->i_mode & S_IALLUGO));
3446 + * initialize or clean the whiteouts for an adding branch
3448 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3451 + int err, old_perm;
3452 + aufs_bindex_t bindex;
3453 + struct inode *h_inode;
3454 + struct au_wbr *wbr;
3455 + struct au_hinode *hdir;
3456 + struct dentry *h_dentry;
3458 + err = vfsub_mnt_want_write(au_br_mnt(br));
3459 + if (unlikely(err))
3463 + old_perm = br->br_perm;
3464 + br->br_perm = new_perm;
3467 + bindex = au_br_index(sb, br->br_id);
3468 + if (0 <= bindex) {
3469 + hdir = au_hi(d_inode(sb->s_root), bindex);
3470 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3472 + h_dentry = au_br_dentry(br);
3473 + h_inode = d_inode(h_dentry);
3474 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3477 + err = au_wh_init(br, sb);
3479 + wbr_wh_write_lock(wbr);
3480 + err = au_wh_init(br, sb);
3481 + wbr_wh_write_unlock(wbr);
3484 + au_hn_inode_unlock(hdir);
3486 + inode_unlock(h_inode);
3487 + vfsub_mnt_drop_write(au_br_mnt(br));
3488 + br->br_perm = old_perm;
3490 + if (!err && wbr && !au_br_writable(new_perm)) {
3492 + br->br_wbr = NULL;
3499 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3503 + struct kstatfs kst;
3504 + struct au_wbr *wbr;
3507 + au_rw_init(&wbr->wbr_wh_rwsem);
3508 + atomic_set(&wbr->wbr_wh_running, 0);
3511 + * a limit for rmdir/rename a dir
3512 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3514 + err = vfs_statfs(&br->br_path, &kst);
3515 + if (unlikely(err))
3518 + if (kst.f_namelen >= NAME_MAX)
3519 + err = au_br_init_wh(sb, br, perm);
3521 + pr_err("%pd(%s), unsupported namelen %ld\n",
3523 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3529 +/* initialize a new branch */
3530 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3531 + struct au_opt_add *add)
3534 + struct inode *h_inode;
3537 + spin_lock_init(&br->br_xino.xi_nondir.spin);
3538 + init_waitqueue_head(&br->br_xino.xi_nondir.wqh);
3539 + br->br_perm = add->perm;
3540 + br->br_path = add->path; /* set first, path_get() later */
3541 + spin_lock_init(&br->br_dykey_lock);
3542 + au_br_count_init(br);
3543 + atomic_set(&br->br_xino_running, 0);
3544 + br->br_id = au_new_br_id(sb);
3545 + AuDebugOn(br->br_id < 0);
3547 + /* always, regardless the given option */
3548 + err = au_dr_br_init(sb, br, &add->path);
3549 + if (unlikely(err))
3552 + if (au_br_writable(add->perm)) {
3553 + err = au_wbr_init(br, sb, add->perm);
3554 + if (unlikely(err))
3558 + if (au_opt_test(au_mntflags(sb), XINO)) {
3559 + h_inode = d_inode(add->path.dentry);
3560 + err = au_xino_br(sb, br, h_inode->i_ino,
3561 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3562 + if (unlikely(err)) {
3563 + AuDebugOn(br->br_xino.xi_file);
3568 + sysaufs_br_init(br);
3569 + path_get(&br->br_path);
3570 + goto out; /* success */
3573 + memset(&br->br_path, 0, sizeof(br->br_path));
3578 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3579 + struct au_branch *br, aufs_bindex_t bbot,
3580 + aufs_bindex_t amount)
3582 + struct au_branch **brp;
3584 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3586 + brp = sbinfo->si_branch + bindex;
3587 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3589 + sbinfo->si_bbot++;
3590 + if (unlikely(bbot < 0))
3591 + sbinfo->si_bbot = 0;
3594 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3595 + aufs_bindex_t bbot, aufs_bindex_t amount)
3597 + struct au_hdentry *hdp;
3599 + AuRwMustWriteLock(&dinfo->di_rwsem);
3601 + hdp = au_hdentry(dinfo, bindex);
3602 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3603 + au_h_dentry_init(hdp);
3605 + if (unlikely(bbot < 0))
3606 + dinfo->di_btop = 0;
3609 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3610 + aufs_bindex_t bbot, aufs_bindex_t amount)
3612 + struct au_hinode *hip;
3614 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3616 + hip = au_hinode(iinfo, bindex);
3617 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3618 + au_hinode_init(hip);
3620 + if (unlikely(bbot < 0))
3621 + iinfo->ii_btop = 0;
3624 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3625 + aufs_bindex_t bindex)
3627 + struct dentry *root, *h_dentry;
3628 + struct inode *root_inode, *h_inode;
3629 + aufs_bindex_t bbot, amount;
3631 + root = sb->s_root;
3632 + root_inode = d_inode(root);
3633 + bbot = au_sbbot(sb);
3634 + amount = bbot + 1 - bindex;
3635 + h_dentry = au_br_dentry(br);
3636 + au_sbilist_lock();
3637 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3638 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3639 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3640 + au_set_h_dptr(root, bindex, dget(h_dentry));
3641 + h_inode = d_inode(h_dentry);
3642 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3643 + au_sbilist_unlock();
3646 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3649 + aufs_bindex_t bbot, add_bindex;
3650 + struct dentry *root, *h_dentry;
3651 + struct inode *root_inode;
3652 + struct au_branch *add_branch;
3654 + root = sb->s_root;
3655 + root_inode = d_inode(root);
3656 + IMustLock(root_inode);
3657 + IiMustWriteLock(root_inode);
3658 + err = test_add(sb, add, remount);
3659 + if (unlikely(err < 0))
3663 + goto out; /* success */
3666 + bbot = au_sbbot(sb);
3667 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3668 + err = PTR_ERR(add_branch);
3669 + if (IS_ERR(add_branch))
3672 + err = au_br_init(add_branch, sb, add);
3673 + if (unlikely(err)) {
3674 + au_br_do_free(add_branch);
3678 + add_bindex = add->bindex;
3680 + au_br_do_add(sb, add_branch, add_bindex);
3682 + sysaufs_brs_del(sb, add_bindex);
3683 + au_br_do_add(sb, add_branch, add_bindex);
3684 + sysaufs_brs_add(sb, add_bindex);
3687 + h_dentry = add->path.dentry;
3688 + if (!add_bindex) {
3689 + au_cpup_attr_all(root_inode, /*force*/1);
3690 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3692 + au_add_nlink(root_inode, d_inode(h_dentry));
3695 + * this test/set prevents aufs from handling unnecesary notify events
3696 + * of xino files, in case of re-adding a writable branch which was
3697 + * once detached from aufs.
3699 + if (au_xino_brid(sb) < 0
3700 + && au_br_writable(add_branch->br_perm)
3701 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3702 + && add_branch->br_xino.xi_file
3703 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3704 + au_xino_brid_set(sb, add_branch->br_id);
3710 +/* ---------------------------------------------------------------------- */
3712 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3713 + unsigned long long max __maybe_unused,
3716 + unsigned long long n;
3717 + struct file **p, *f;
3718 + struct hlist_bl_head *files;
3719 + struct hlist_bl_node *pos;
3720 + struct au_finfo *finfo;
3724 + files = &au_sbi(sb)->si_files;
3725 + hlist_bl_lock(files);
3726 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3727 + f = finfo->fi_file;
3729 + && !special_file(file_inode(f)->i_mode)) {
3733 + AuDebugOn(n > max);
3736 + hlist_bl_unlock(files);
3741 +static struct file **au_farray_alloc(struct super_block *sb,
3742 + unsigned long long *max)
3744 + *max = au_nfiles(sb);
3745 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3748 +static void au_farray_free(struct file **a, unsigned long long max)
3750 + unsigned long long ull;
3752 + for (ull = 0; ull < max; ull++)
3758 +/* ---------------------------------------------------------------------- */
3764 +/* to show the line number, do not make it inlined function */
3765 +#define AuVerbose(do_info, fmt, ...) do { \
3767 + pr_info(fmt, ##__VA_ARGS__); \
3770 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3771 + aufs_bindex_t bbot)
3773 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3776 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3777 + aufs_bindex_t bbot)
3779 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3783 + * test if the branch is deletable or not.
3785 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3786 + unsigned int sigen, const unsigned int verbose)
3788 + int err, i, j, ndentry;
3789 + aufs_bindex_t btop, bbot;
3790 + struct au_dcsub_pages dpages;
3791 + struct au_dpage *dpage;
3794 + err = au_dpages_init(&dpages, GFP_NOFS);
3795 + if (unlikely(err))
3797 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3798 + if (unlikely(err))
3801 + for (i = 0; !err && i < dpages.ndpage; i++) {
3802 + dpage = dpages.dpages + i;
3803 + ndentry = dpage->ndentry;
3804 + for (j = 0; !err && j < ndentry; j++) {
3805 + d = dpage->dentries[j];
3806 + AuDebugOn(au_dcount(d) <= 0);
3807 + if (!au_digen_test(d, sigen)) {
3808 + di_read_lock_child(d, AuLock_IR);
3809 + if (unlikely(au_dbrange_test(d))) {
3810 + di_read_unlock(d, AuLock_IR);
3814 + di_write_lock_child(d);
3815 + if (unlikely(au_dbrange_test(d))) {
3816 + di_write_unlock(d);
3819 + err = au_reval_dpath(d, sigen);
3821 + di_downgrade_lock(d, AuLock_IR);
3823 + di_write_unlock(d);
3828 + /* AuDbgDentry(d); */
3829 + btop = au_dbtop(d);
3830 + bbot = au_dbbot(d);
3831 + if (btop <= bindex
3833 + && au_h_dptr(d, bindex)
3834 + && au_test_dbusy(d, btop, bbot)) {
3836 + AuVerbose(verbose, "busy %pd\n", d);
3839 + di_read_unlock(d, AuLock_IR);
3844 + au_dpages_free(&dpages);
3849 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3850 + unsigned int sigen, const unsigned int verbose)
3853 + unsigned long long max, ull;
3854 + struct inode *i, **array;
3855 + aufs_bindex_t btop, bbot;
3857 + array = au_iarray_alloc(sb, &max);
3858 + err = PTR_ERR(array);
3859 + if (IS_ERR(array))
3863 + AuDbg("b%d\n", bindex);
3864 + for (ull = 0; !err && ull < max; ull++) {
3868 + if (i->i_ino == AUFS_ROOT_INO)
3871 + /* AuDbgInode(i); */
3872 + if (au_iigen(i, NULL) == sigen)
3873 + ii_read_lock_child(i);
3875 + ii_write_lock_child(i);
3876 + err = au_refresh_hinode_self(i);
3879 + ii_downgrade_lock(i);
3881 + ii_write_unlock(i);
3886 + btop = au_ibtop(i);
3887 + bbot = au_ibbot(i);
3888 + if (btop <= bindex
3890 + && au_h_iptr(i, bindex)
3891 + && au_test_ibusy(i, btop, bbot)) {
3893 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3896 + ii_read_unlock(i);
3898 + au_iarray_free(array, max);
3904 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3905 + const unsigned int verbose)
3908 + unsigned int sigen;
3910 + sigen = au_sigen(root->d_sb);
3911 + DiMustNoWaiters(root);
3912 + IiMustNoWaiters(d_inode(root));
3913 + di_write_unlock(root);
3914 + err = test_dentry_busy(root, bindex, sigen, verbose);
3916 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3917 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3922 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3923 + struct file **to_free, int *idx)
3926 + unsigned char matched, root;
3927 + aufs_bindex_t bindex, bbot;
3928 + struct au_fidir *fidir;
3929 + struct au_hfile *hfile;
3932 + root = IS_ROOT(file->f_path.dentry);
3935 + to_free[*idx] = file;
3941 + fidir = au_fi(file)->fi_hdir;
3942 + AuDebugOn(!fidir);
3943 + bbot = au_fbbot_dir(file);
3944 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3945 + hfile = fidir->fd_hfile + bindex;
3946 + if (!hfile->hf_file)
3949 + if (hfile->hf_br->br_id == br_id) {
3961 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3962 + struct file **to_free, int opened)
3965 + unsigned long long ull, max;
3966 + aufs_bindex_t btop;
3967 + struct file *file, **array;
3968 + struct dentry *root;
3969 + struct au_hfile *hfile;
3971 + array = au_farray_alloc(sb, &max);
3972 + err = PTR_ERR(array);
3973 + if (IS_ERR(array))
3978 + root = sb->s_root;
3979 + di_write_unlock(root);
3980 + for (ull = 0; ull < max; ull++) {
3981 + file = array[ull];
3982 + if (unlikely(!file))
3985 + /* AuDbg("%pD\n", file); */
3986 + fi_read_lock(file);
3987 + btop = au_fbtop(file);
3988 + if (!d_is_dir(file->f_path.dentry)) {
3989 + hfile = &au_fi(file)->fi_htop;
3990 + if (hfile->hf_br->br_id == br_id)
3993 + err = test_dir_busy(file, br_id, to_free, &idx);
3994 + fi_read_unlock(file);
3995 + if (unlikely(err))
3998 + di_write_lock_child(root);
3999 + au_farray_free(array, max);
4000 + AuDebugOn(idx > opened);
4006 +static void br_del_file(struct file **to_free, unsigned long long opened,
4007 + aufs_bindex_t br_id)
4009 + unsigned long long ull;
4010 + aufs_bindex_t bindex, btop, bbot, bfound;
4011 + struct file *file;
4012 + struct au_fidir *fidir;
4013 + struct au_hfile *hfile;
4015 + for (ull = 0; ull < opened; ull++) {
4016 + file = to_free[ull];
4017 + if (unlikely(!file))
4020 + /* AuDbg("%pD\n", file); */
4021 + AuDebugOn(!d_is_dir(file->f_path.dentry));
4023 + fidir = au_fi(file)->fi_hdir;
4024 + AuDebugOn(!fidir);
4025 + fi_write_lock(file);
4026 + btop = au_fbtop(file);
4027 + bbot = au_fbbot_dir(file);
4028 + for (bindex = btop; bindex <= bbot; bindex++) {
4029 + hfile = fidir->fd_hfile + bindex;
4030 + if (!hfile->hf_file)
4033 + if (hfile->hf_br->br_id == br_id) {
4038 + AuDebugOn(bfound < 0);
4039 + au_set_h_fptr(file, bfound, NULL);
4040 + if (bfound == btop) {
4041 + for (btop++; btop <= bbot; btop++)
4042 + if (au_hf_dir(file, btop)) {
4043 + au_set_fbtop(file, btop);
4047 + fi_write_unlock(file);
4051 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4052 + const aufs_bindex_t bindex,
4053 + const aufs_bindex_t bbot)
4055 + struct au_branch **brp, **p;
4057 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4059 + brp = sbinfo->si_branch + bindex;
4060 + if (bindex < bbot)
4061 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4062 + sbinfo->si_branch[0 + bbot] = NULL;
4063 + sbinfo->si_bbot--;
4065 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4068 + sbinfo->si_branch = p;
4069 + /* harmless error */
4072 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4073 + const aufs_bindex_t bbot)
4075 + struct au_hdentry *hdp, *p;
4077 + AuRwMustWriteLock(&dinfo->di_rwsem);
4079 + hdp = au_hdentry(dinfo, bindex);
4080 + if (bindex < bbot)
4081 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4082 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4085 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4088 + dinfo->di_hdentry = p;
4089 + /* harmless error */
4092 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4093 + const aufs_bindex_t bbot)
4095 + struct au_hinode *hip, *p;
4097 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4099 + hip = au_hinode(iinfo, bindex);
4100 + if (bindex < bbot)
4101 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4102 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4105 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4108 + iinfo->ii_hinode = p;
4109 + /* harmless error */
4112 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4113 + struct au_branch *br)
4115 + aufs_bindex_t bbot;
4116 + struct au_sbinfo *sbinfo;
4117 + struct dentry *root, *h_root;
4118 + struct inode *inode, *h_inode;
4119 + struct au_hinode *hinode;
4121 + SiMustWriteLock(sb);
4123 + root = sb->s_root;
4124 + inode = d_inode(root);
4125 + sbinfo = au_sbi(sb);
4126 + bbot = sbinfo->si_bbot;
4128 + h_root = au_h_dptr(root, bindex);
4129 + hinode = au_hi(inode, bindex);
4130 + h_inode = au_igrab(hinode->hi_inode);
4133 + au_sbilist_lock();
4134 + au_br_do_del_brp(sbinfo, bindex, bbot);
4135 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4136 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4137 + au_sbilist_unlock();
4139 + /* ignore an error */
4140 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4144 + au_br_do_free(br);
4147 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4148 + unsigned long long max, void *arg)
4153 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4156 + unsigned long long opened;
4157 + unsigned int mnt_flags;
4158 + aufs_bindex_t bindex, bbot, br_id;
4159 + unsigned char do_wh, verbose;
4160 + struct au_branch *br;
4161 + struct au_wbr *wbr;
4162 + struct dentry *root;
4163 + struct file **to_free;
4168 + root = sb->s_root;
4169 + bindex = au_find_dbindex(root, del->h_path.dentry);
4172 + goto out; /* success */
4174 + pr_err("%s no such branch\n", del->pathname);
4177 + AuDbg("bindex b%d\n", bindex);
4180 + mnt_flags = au_mntflags(sb);
4181 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4182 + bbot = au_sbbot(sb);
4183 + if (unlikely(!bbot)) {
4184 + AuVerbose(verbose, "no more branches left\n");
4187 + br = au_sbr(sb, bindex);
4188 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4190 + br_id = br->br_id;
4191 + opened = au_br_count(br);
4192 + if (unlikely(opened)) {
4193 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4194 + err = PTR_ERR(to_free);
4195 + if (IS_ERR(to_free))
4198 + err = test_file_busy(sb, br_id, to_free, opened);
4199 + if (unlikely(err)) {
4200 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4206 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4208 + /* instead of WbrWhMustWriteLock(wbr) */
4209 + SiMustWriteLock(sb);
4210 + for (i = 0; i < AuBrWh_Last; i++) {
4211 + dput(wbr->wbr_wh[i]);
4212 + wbr->wbr_wh[i] = NULL;
4216 + err = test_children_busy(root, bindex, verbose);
4217 + if (unlikely(err)) {
4226 + * now we confirmed the branch is deletable.
4227 + * let's free the remaining opened dirs on the branch.
4229 + di_write_unlock(root);
4230 + br_del_file(to_free, opened, br_id);
4231 + di_write_lock_child(root);
4235 + au_br_do_del(sb, bindex, br);
4237 + sysaufs_brs_del(sb, bindex);
4238 + au_br_do_del(sb, bindex, br);
4239 + sysaufs_brs_add(sb, bindex);
4243 + au_cpup_attr_all(d_inode(root), /*force*/1);
4244 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4246 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4247 + if (au_opt_test(mnt_flags, PLINK))
4248 + au_plink_half_refresh(sb, br_id);
4250 + if (au_xino_brid(sb) == br_id)
4251 + au_xino_brid_set(sb, -1);
4252 + goto out; /* success */
4256 + rerr = au_br_init_wh(sb, br, br->br_perm);
4258 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4259 + del->pathname, rerr);
4262 + au_farray_free(to_free, opened);
4266 +/* ---------------------------------------------------------------------- */
4268 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4271 + aufs_bindex_t btop, bbot;
4272 + struct aufs_ibusy ibusy;
4273 + struct inode *inode, *h_inode;
4276 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4279 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4281 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4282 + if (unlikely(err)) {
4289 + si_read_lock(sb, AuLock_FLUSH);
4290 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4294 + ibusy.h_ino = 0; /* invalid */
4295 + inode = ilookup(sb, ibusy.ino);
4297 + || inode->i_ino == AUFS_ROOT_INO
4298 + || au_is_bad_inode(inode))
4301 + ii_read_lock_child(inode);
4302 + btop = au_ibtop(inode);
4303 + bbot = au_ibbot(inode);
4304 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4305 + h_inode = au_h_iptr(inode, ibusy.bindex);
4306 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4307 + ibusy.h_ino = h_inode->i_ino;
4309 + ii_read_unlock(inode);
4313 + si_read_unlock(sb);
4315 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4316 + if (unlikely(err)) {
4325 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4327 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4330 +#ifdef CONFIG_COMPAT
4331 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4333 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4337 +/* ---------------------------------------------------------------------- */
4340 + * change a branch permission
4343 +static void au_warn_ima(void)
4346 + /* since it doesn't support mark_files_ro() */
4347 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4351 +static int do_need_sigen_inc(int a, int b)
4353 + return au_br_whable(a) && !au_br_whable(b);
4356 +static int need_sigen_inc(int old, int new)
4358 + return do_need_sigen_inc(old, new)
4359 + || do_need_sigen_inc(new, old);
4362 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4365 + unsigned int mnt_flags;
4366 + unsigned long long ull, max;
4367 + aufs_bindex_t br_id;
4368 + unsigned char verbose, writer;
4369 + struct file *file, *hf, **array;
4370 + struct au_hfile *hfile;
4372 + mnt_flags = au_mntflags(sb);
4373 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4375 + array = au_farray_alloc(sb, &max);
4376 + err = PTR_ERR(array);
4377 + if (IS_ERR(array))
4381 + br_id = au_sbr_id(sb, bindex);
4382 + for (ull = 0; ull < max; ull++) {
4383 + file = array[ull];
4384 + if (unlikely(!file))
4387 + /* AuDbg("%pD\n", file); */
4388 + fi_read_lock(file);
4389 + if (unlikely(au_test_mmapped(file))) {
4391 + AuVerbose(verbose, "mmapped %pD\n", file);
4393 + FiMustNoWaiters(file);
4394 + fi_read_unlock(file);
4398 + hfile = &au_fi(file)->fi_htop;
4399 + hf = hfile->hf_file;
4400 + if (!d_is_reg(file->f_path.dentry)
4401 + || !(file->f_mode & FMODE_WRITE)
4402 + || hfile->hf_br->br_id != br_id
4403 + || !(hf->f_mode & FMODE_WRITE))
4404 + array[ull] = NULL;
4410 + FiMustNoWaiters(file);
4411 + fi_read_unlock(file);
4419 + for (ull = 0; ull < max; ull++) {
4420 + file = array[ull];
4424 + /* todo: already flushed? */
4426 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4427 + * approach which resets f_mode and calls mnt_drop_write() and
4428 + * file_release_write() for each file, because the branch
4429 + * attribute in aufs world is totally different from the native
4432 + /* fi_read_lock(file); */
4433 + hfile = &au_fi(file)->fi_htop;
4434 + hf = hfile->hf_file;
4435 + /* fi_read_unlock(file); */
4436 + spin_lock(&hf->f_lock);
4437 + writer = !!(hf->f_mode & FMODE_WRITER);
4438 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4439 + spin_unlock(&hf->f_lock);
4441 + put_write_access(file_inode(hf));
4442 + __mnt_drop_write(hf->f_path.mnt);
4447 + au_farray_free(array, max);
4453 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4457 + aufs_bindex_t bindex;
4458 + struct dentry *root;
4459 + struct au_branch *br;
4460 + struct au_br_fhsm *bf;
4462 + root = sb->s_root;
4463 + bindex = au_find_dbindex(root, mod->h_root);
4466 + return 0; /* success */
4468 + pr_err("%s no such branch\n", mod->path);
4471 + AuDbg("bindex b%d\n", bindex);
4473 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4474 + if (unlikely(err))
4477 + br = au_sbr(sb, bindex);
4478 + AuDebugOn(mod->h_root != au_br_dentry(br));
4479 + if (br->br_perm == mod->perm)
4480 + return 0; /* success */
4482 + /* pre-allocate for non-fhsm --> fhsm */
4484 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4485 + err = au_fhsm_br_alloc(br);
4486 + if (unlikely(err))
4489 + br->br_fhsm = NULL;
4492 + if (au_br_writable(br->br_perm)) {
4493 + /* remove whiteout base */
4494 + err = au_br_init_wh(sb, br, mod->perm);
4495 + if (unlikely(err))
4498 + if (!au_br_writable(mod->perm)) {
4499 + /* rw --> ro, file might be mmapped */
4500 + DiMustNoWaiters(root);
4501 + IiMustNoWaiters(d_inode(root));
4502 + di_write_unlock(root);
4503 + err = au_br_mod_files_ro(sb, bindex);
4504 + /* aufs_write_lock() calls ..._child() */
4505 + di_write_lock_child(root);
4507 + if (unlikely(err)) {
4509 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4512 + rerr = au_wbr_init(br, sb, br->br_perm);
4513 + if (unlikely(rerr)) {
4514 + AuIOErr("nested error %d (%d)\n",
4516 + br->br_perm = mod->perm;
4520 + } else if (au_br_writable(mod->perm)) {
4523 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4525 + err = au_wbr_init(br, sb, mod->perm);
4526 + if (unlikely(err)) {
4527 + kfree(br->br_wbr);
4528 + br->br_wbr = NULL;
4532 + if (unlikely(err))
4535 + if (au_br_fhsm(br->br_perm)) {
4536 + if (!au_br_fhsm(mod->perm)) {
4537 + /* fhsm --> non-fhsm */
4538 + au_br_fhsm_fin(br->br_fhsm);
4539 + kfree(br->br_fhsm);
4540 + br->br_fhsm = NULL;
4542 + } else if (au_br_fhsm(mod->perm))
4543 + /* non-fhsm --> fhsm */
4546 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4547 + br->br_perm = mod->perm;
4548 + goto out; /* success */
4557 +/* ---------------------------------------------------------------------- */
4559 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4562 + struct kstatfs kstfs;
4564 + err = vfs_statfs(&br->br_path, &kstfs);
4566 + stfs->f_blocks = kstfs.f_blocks;
4567 + stfs->f_bavail = kstfs.f_bavail;
4568 + stfs->f_files = kstfs.f_files;
4569 + stfs->f_ffree = kstfs.f_ffree;
4574 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4575 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4576 +++ linux/fs/aufs/branch.h 2017-11-12 22:24:44.697577553 +0100
4579 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4581 + * This program, aufs is free software; you can redistribute it and/or modify
4582 + * it under the terms of the GNU General Public License as published by
4583 + * the Free Software Foundation; either version 2 of the License, or
4584 + * (at your option) any later version.
4586 + * This program is distributed in the hope that it will be useful,
4587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4589 + * GNU General Public License for more details.
4591 + * You should have received a copy of the GNU General Public License
4592 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4596 + * branch filesystems and xino for them
4599 +#ifndef __AUFS_BRANCH_H__
4600 +#define __AUFS_BRANCH_H__
4604 +#include <linux/mount.h>
4605 +#include "dirren.h"
4610 +/* ---------------------------------------------------------------------- */
4613 +struct au_xino_file {
4614 + struct file *xi_file;
4619 + /* reserved for future use */
4620 + /* unsigned long *bitmap; */
4621 + wait_queue_head_t wqh;
4624 + /* todo: make xino files an array to support huge inode number */
4626 +#ifdef CONFIG_DEBUG_FS
4627 + struct dentry *xi_dbgaufs;
4631 +/* File-based Hierarchical Storage Management */
4632 +struct au_br_fhsm {
4633 +#ifdef CONFIG_AUFS_FHSM
4634 + struct mutex bf_lock;
4635 + unsigned long bf_jiffy;
4636 + struct aufs_stfs bf_stfs;
4641 +/* members for writable branch only */
4642 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4644 + struct au_rwsem wbr_wh_rwsem;
4645 + struct dentry *wbr_wh[AuBrWh_Last];
4646 + atomic_t wbr_wh_running;
4647 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4648 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4649 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4652 + unsigned long long wbr_bytes;
4655 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4656 +#define AuBrDynOp (AuDyLast * 4)
4658 +#ifdef CONFIG_AUFS_HFSNOTIFY
4659 +/* support for asynchronous destruction */
4660 +struct au_br_hfsnotify {
4661 + struct fsnotify_group *hfsn_group;
4665 +/* sysfs entries */
4666 +struct au_brsysfs {
4668 + struct attribute attr;
4677 +/* protected by superblock rwsem */
4679 + struct au_xino_file br_xino;
4681 + aufs_bindex_t br_id;
4684 + struct path br_path;
4685 + spinlock_t br_dykey_lock;
4686 + struct au_dykey *br_dykey[AuBrDynOp];
4687 + struct percpu_counter br_count;
4689 + struct au_wbr *br_wbr;
4690 + struct au_br_fhsm *br_fhsm;
4692 + /* xino truncation */
4693 + atomic_t br_xino_running;
4695 +#ifdef CONFIG_AUFS_HFSNOTIFY
4696 + struct au_br_hfsnotify *br_hfsn;
4699 +#ifdef CONFIG_SYSFS
4700 + /* entries under sysfs per mount-point */
4701 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4704 + struct au_dr_br br_dirren;
4707 +/* ---------------------------------------------------------------------- */
4709 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4711 + return br->br_path.mnt;
4714 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4716 + return br->br_path.dentry;
4719 +static inline struct super_block *au_br_sb(struct au_branch *br)
4721 + return au_br_mnt(br)->mnt_sb;
4724 +static inline void au_br_get(struct au_branch *br)
4726 + percpu_counter_inc(&br->br_count);
4729 +static inline void au_br_put(struct au_branch *br)
4731 + percpu_counter_dec(&br->br_count);
4734 +static inline s64 au_br_count(struct au_branch *br)
4736 + return percpu_counter_sum(&br->br_count);
4739 +static inline void au_br_count_init(struct au_branch *br)
4741 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4744 +static inline void au_br_count_fin(struct au_branch *br)
4746 + percpu_counter_destroy(&br->br_count);
4749 +static inline int au_br_rdonly(struct au_branch *br)
4751 + return (sb_rdonly(au_br_sb(br))
4752 + || !au_br_writable(br->br_perm))
4756 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4758 +#ifdef CONFIG_AUFS_HNOTIFY
4759 + return !(brperm & AuBrPerm_RR);
4765 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4767 + int err, exec_flag;
4770 + exec_flag = oflag & __FMODE_EXEC;
4771 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4777 +/* ---------------------------------------------------------------------- */
4781 +void au_br_free(struct au_sbinfo *sinfo);
4782 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4784 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4786 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4787 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4788 +#ifdef CONFIG_COMPAT
4789 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4792 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4795 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4798 +static const loff_t au_loff_max = LLONG_MAX;
4800 +int au_xib_trunc(struct super_block *sb);
4801 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4803 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4804 + size_t size, loff_t *pos);
4805 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4806 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4807 +ino_t au_xino_new_ino(struct super_block *sb);
4808 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4809 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4811 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4813 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4814 + struct file *base_file, int do_test);
4815 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4817 +struct au_opt_xino;
4818 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4819 +void au_xino_clr(struct super_block *sb);
4820 +struct file *au_xino_def(struct super_block *sb);
4821 +int au_xino_path(struct seq_file *seq, struct file *file);
4823 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4824 + ino_t h_ino, int idx);
4825 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4828 +/* ---------------------------------------------------------------------- */
4830 +/* Superblock to branch */
4832 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4834 + return au_sbr(sb, bindex)->br_id;
4838 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4840 + return au_br_mnt(au_sbr(sb, bindex));
4844 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4846 + return au_br_sb(au_sbr(sb, bindex));
4849 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4851 + au_br_get(au_sbr(sb, bindex));
4854 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4856 + au_br_put(au_sbr(sb, bindex));
4859 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4861 + return au_sbr(sb, bindex)->br_perm;
4864 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4866 + return au_br_whable(au_sbr_perm(sb, bindex));
4869 +/* ---------------------------------------------------------------------- */
4871 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4872 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4873 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4874 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4876 +#define wbr_wh_read_trylock_nested(wbr) \
4877 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4878 +#define wbr_wh_write_trylock_nested(wbr) \
4879 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4882 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4883 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4884 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4886 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4887 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4888 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4890 +/* ---------------------------------------------------------------------- */
4892 +#ifdef CONFIG_AUFS_FHSM
4893 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4895 + mutex_init(&brfhsm->bf_lock);
4896 + brfhsm->bf_jiffy = 0;
4897 + brfhsm->bf_readable = 0;
4900 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4902 + mutex_destroy(&brfhsm->bf_lock);
4905 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4906 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4909 +#endif /* __KERNEL__ */
4910 +#endif /* __AUFS_BRANCH_H__ */
4911 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4912 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4913 +++ linux/fs/aufs/conf.mk 2017-11-12 22:24:44.704244405 +0100
4916 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4920 +AuConfStr += ${1}=${${1}}
4924 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4926 + HNOTIFY HFSNOTIFY \
4938 +$(foreach i, ${AuConfAll}, \
4939 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4941 +AuConfName = ${obj}/conf.str
4942 +${AuConfName}.tmp: FORCE
4943 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4944 +${AuConfName}: ${AuConfName}.tmp
4945 + @diff -q $< $@ > /dev/null 2>&1 || { \
4946 + echo ' GEN ' $@; \
4950 +clean-files += ${AuConfName} ${AuConfName}.tmp
4951 +${obj}/sysfs.o: ${AuConfName}
4953 +-include ${srctree}/${src}/conf_priv.mk
4954 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4955 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4956 +++ linux/fs/aufs/cpup.c 2017-11-12 22:24:44.704244405 +0100
4959 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4961 + * This program, aufs is free software; you can redistribute it and/or modify
4962 + * it under the terms of the GNU General Public License as published by
4963 + * the Free Software Foundation; either version 2 of the License, or
4964 + * (at your option) any later version.
4966 + * This program is distributed in the hope that it will be useful,
4967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4969 + * GNU General Public License for more details.
4971 + * You should have received a copy of the GNU General Public License
4972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4976 + * copy-up functions, see wbr_policy.c for copy-down
4979 +#include <linux/fs_stack.h>
4980 +#include <linux/mm.h>
4981 +#include <linux/task_work.h>
4984 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4986 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4987 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4989 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4991 + dst->i_flags |= iflags & ~mask;
4992 + if (au_test_fs_notime(dst->i_sb))
4993 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4996 +void au_cpup_attr_timesizes(struct inode *inode)
4998 + struct inode *h_inode;
5000 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5001 + fsstack_copy_attr_times(inode, h_inode);
5002 + fsstack_copy_inode_size(inode, h_inode);
5005 +void au_cpup_attr_nlink(struct inode *inode, int force)
5007 + struct inode *h_inode;
5008 + struct super_block *sb;
5009 + aufs_bindex_t bindex, bbot;
5012 + bindex = au_ibtop(inode);
5013 + h_inode = au_h_iptr(inode, bindex);
5015 + && !S_ISDIR(h_inode->i_mode)
5016 + && au_opt_test(au_mntflags(sb), PLINK)
5017 + && au_plink_test(inode))
5021 + * 0 can happen in revalidating.
5022 + * h_inode->i_mutex may not be held here, but it is harmless since once
5023 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5025 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5026 + * the incorrect link count.
5028 + set_nlink(inode, h_inode->i_nlink);
5031 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5032 + * it may includes whplink directory.
5034 + if (S_ISDIR(h_inode->i_mode)) {
5035 + bbot = au_ibbot(inode);
5036 + for (bindex++; bindex <= bbot; bindex++) {
5037 + h_inode = au_h_iptr(inode, bindex);
5039 + au_add_nlink(inode, h_inode);
5044 +void au_cpup_attr_changeable(struct inode *inode)
5046 + struct inode *h_inode;
5048 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5049 + inode->i_mode = h_inode->i_mode;
5050 + inode->i_uid = h_inode->i_uid;
5051 + inode->i_gid = h_inode->i_gid;
5052 + au_cpup_attr_timesizes(inode);
5053 + au_cpup_attr_flags(inode, h_inode->i_flags);
5056 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5058 + struct au_iinfo *iinfo = au_ii(inode);
5060 + IiMustWriteLock(inode);
5062 + iinfo->ii_higen = h_inode->i_generation;
5063 + iinfo->ii_hsb1 = h_inode->i_sb;
5066 +void au_cpup_attr_all(struct inode *inode, int force)
5068 + struct inode *h_inode;
5070 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5071 + au_cpup_attr_changeable(inode);
5072 + if (inode->i_nlink > 0)
5073 + au_cpup_attr_nlink(inode, force);
5074 + inode->i_rdev = h_inode->i_rdev;
5075 + inode->i_blkbits = h_inode->i_blkbits;
5076 + au_cpup_igen(inode, h_inode);
5079 +/* ---------------------------------------------------------------------- */
5081 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5083 +/* keep the timestamps of the parent dir when cpup */
5084 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5085 + struct path *h_path)
5087 + struct inode *h_inode;
5089 + dt->dt_dentry = dentry;
5090 + dt->dt_h_path = *h_path;
5091 + h_inode = d_inode(h_path->dentry);
5092 + dt->dt_atime = h_inode->i_atime;
5093 + dt->dt_mtime = h_inode->i_mtime;
5097 +void au_dtime_revert(struct au_dtime *dt)
5099 + struct iattr attr;
5102 + attr.ia_atime = dt->dt_atime;
5103 + attr.ia_mtime = dt->dt_mtime;
5104 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5105 + | ATTR_ATIME | ATTR_ATIME_SET;
5107 + /* no delegation since this is a directory */
5108 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5109 + if (unlikely(err))
5110 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5113 +/* ---------------------------------------------------------------------- */
5115 +/* internal use only */
5116 +struct au_cpup_reg_attr {
5119 + unsigned int iflags; /* inode->i_flags */
5122 +static noinline_for_stack
5123 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5124 + struct au_cpup_reg_attr *h_src_attr)
5126 + int err, sbits, icex;
5127 + unsigned int mnt_flags;
5128 + unsigned char verbose;
5130 + struct path h_path;
5131 + struct inode *h_isrc, *h_idst;
5132 + struct kstat *h_st;
5133 + struct au_branch *br;
5135 + h_path.dentry = au_h_dptr(dst, bindex);
5136 + h_idst = d_inode(h_path.dentry);
5137 + br = au_sbr(dst->d_sb, bindex);
5138 + h_path.mnt = au_br_mnt(br);
5139 + h_isrc = d_inode(h_src);
5140 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5141 + | ATTR_ATIME | ATTR_MTIME
5142 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5143 + if (h_src_attr && h_src_attr->valid) {
5144 + h_st = &h_src_attr->st;
5145 + ia.ia_uid = h_st->uid;
5146 + ia.ia_gid = h_st->gid;
5147 + ia.ia_atime = h_st->atime;
5148 + ia.ia_mtime = h_st->mtime;
5149 + if (h_idst->i_mode != h_st->mode
5150 + && !S_ISLNK(h_idst->i_mode)) {
5151 + ia.ia_valid |= ATTR_MODE;
5152 + ia.ia_mode = h_st->mode;
5154 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5155 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5157 + ia.ia_uid = h_isrc->i_uid;
5158 + ia.ia_gid = h_isrc->i_gid;
5159 + ia.ia_atime = h_isrc->i_atime;
5160 + ia.ia_mtime = h_isrc->i_mtime;
5161 + if (h_idst->i_mode != h_isrc->i_mode
5162 + && !S_ISLNK(h_idst->i_mode)) {
5163 + ia.ia_valid |= ATTR_MODE;
5164 + ia.ia_mode = h_isrc->i_mode;
5166 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5167 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5169 + /* no delegation since it is just created */
5170 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5172 + /* is this nfs only? */
5173 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5174 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5175 + ia.ia_mode = h_isrc->i_mode;
5176 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5179 + icex = br->br_perm & AuBrAttr_ICEX;
5181 + mnt_flags = au_mntflags(dst->d_sb);
5182 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5183 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5189 +/* ---------------------------------------------------------------------- */
5191 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5192 + char *buf, unsigned long blksize)
5195 + size_t sz, rbytes, wbytes;
5196 + unsigned char all_zero;
5198 + struct inode *h_inode;
5199 + /* reduce stack usage */
5202 + zp = page_address(ZERO_PAGE(0));
5203 + if (unlikely(!zp))
5204 + return -ENOMEM; /* possible? */
5209 + AuDbg("len %lld\n", len);
5211 + if (len < blksize)
5215 + /* todo: signal_pending? */
5216 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5217 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5220 + if (unlikely(err < 0))
5224 + if (len >= rbytes && rbytes == blksize)
5225 + all_zero = !memcmp(buf, zp, rbytes);
5232 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5234 + /* todo: signal_pending? */
5235 + if (unlikely(err == -EAGAIN || err == -EINTR))
5237 + if (unlikely(err < 0))
5242 + if (unlikely(err < 0))
5248 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5250 + if (unlikely(res < 0))
5257 + /* the last block may be a hole */
5258 + if (!err && all_zero) {
5259 + AuLabel(last hole);
5262 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5263 + /* nfs requires this step to make last hole */
5264 + /* is this only nfs? */
5266 + /* todo: signal_pending? */
5267 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5268 + } while (err == -EAGAIN || err == -EINTR);
5275 + ia->ia_size = dst->f_pos;
5276 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5277 + ia->ia_file = dst;
5278 + h_inode = file_inode(dst);
5279 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5280 + /* no delegation since it is just created */
5281 + err = vfsub_notify_change(&dst->f_path, ia,
5282 + /*delegated*/NULL);
5283 + inode_unlock(h_inode);
5290 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5293 + unsigned long blksize;
5294 + unsigned char do_kfree;
5298 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5299 + if (!blksize || PAGE_SIZE < blksize)
5300 + blksize = PAGE_SIZE;
5301 + AuDbg("blksize %lu\n", blksize);
5302 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5304 + buf = kmalloc(blksize, GFP_NOFS);
5306 + buf = (void *)__get_free_page(GFP_NOFS);
5307 + if (unlikely(!buf))
5310 + if (len > (1 << 22))
5311 + AuDbg("copying a large file %lld\n", (long long)len);
5315 + err = au_do_copy_file(dst, src, len, buf, blksize);
5319 + free_page((unsigned long)buf);
5325 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5328 + struct super_block *h_src_sb;
5329 + struct inode *h_src_inode;
5331 + h_src_inode = file_inode(src);
5332 + h_src_sb = h_src_inode->i_sb;
5334 + /* XFS acquires inode_lock */
5335 + if (!au_test_xfs(h_src_sb))
5336 + err = au_copy_file(dst, src, len);
5338 + inode_unlock_shared(h_src_inode);
5339 + err = au_copy_file(dst, src, len);
5340 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5346 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5349 + struct super_block *h_src_sb;
5350 + struct inode *h_src_inode;
5352 + h_src_inode = file_inode(src);
5353 + h_src_sb = h_src_inode->i_sb;
5354 + if (h_src_sb != file_inode(dst)->i_sb
5355 + || !dst->f_op->clone_file_range) {
5356 + err = au_do_copy(dst, src, len);
5360 + if (!au_test_nfs(h_src_sb)) {
5361 + inode_unlock_shared(h_src_inode);
5362 + err = vfsub_clone_file_range(src, dst, len);
5363 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5365 + err = vfsub_clone_file_range(src, dst, len);
5366 + /* older XFS has a condition in cloning */
5367 + if (unlikely(err != -EOPNOTSUPP))
5370 + /* the backend fs on NFS may not support cloning */
5371 + err = au_do_copy(dst, src, len);
5379 + * to support a sparse file which is opened with O_APPEND,
5380 + * we need to close the file.
5382 +static int au_cp_regular(struct au_cp_generic *cpg)
5385 + enum { SRC, DST };
5387 + aufs_bindex_t bindex;
5388 + unsigned int flags;
5389 + struct dentry *dentry;
5391 + struct file *file;
5395 + .bindex = cpg->bsrc,
5396 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5400 + .bindex = cpg->bdst,
5401 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5402 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5403 + .label = &&out_src
5406 + struct super_block *sb, *h_src_sb;
5407 + struct inode *h_src_inode;
5408 + struct task_struct *tsk = current;
5410 + /* bsrc branch can be ro/rw. */
5411 + sb = cpg->dentry->d_sb;
5413 + for (i = 0; i < 2; i++, f++) {
5414 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5415 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5416 + /*file*/NULL, f->force_wr);
5417 + err = PTR_ERR(f->file);
5418 + if (IS_ERR(f->file))
5422 + /* try stopping to update while we copyup */
5423 + h_src_inode = d_inode(file[SRC].dentry);
5424 + h_src_sb = h_src_inode->i_sb;
5425 + if (!au_test_nfs(h_src_sb))
5426 + IMustLock(h_src_inode);
5427 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5429 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5430 + if (tsk->flags & PF_KTHREAD)
5431 + __fput_sync(file[DST].file);
5433 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5435 + fput(file[DST].file);
5438 + * we have to call both since we don't know which place the file
5442 + flush_delayed_fput();
5444 + au_sbr_put(sb, file[DST].bindex);
5447 + fput(file[SRC].file);
5448 + au_sbr_put(sb, file[SRC].bindex);
5453 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5454 + struct au_cpup_reg_attr *h_src_attr)
5458 + struct path h_path;
5459 + struct inode *h_src_inode, *h_dst_inode;
5462 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5463 + l = i_size_read(h_src_inode);
5464 + if (cpg->len == -1 || l < cpg->len)
5467 + /* try stopping to update while we are referencing */
5468 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5469 + au_pin_hdir_unlock(cpg->pin);
5471 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5472 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5473 + h_src_attr->iflags = h_src_inode->i_flags;
5474 + if (!au_test_nfs(h_src_inode->i_sb))
5475 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5477 + inode_unlock_shared(h_src_inode);
5478 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5479 + vfsub_inode_lock_shared_nested(h_src_inode,
5482 + if (unlikely(err)) {
5483 + inode_unlock_shared(h_src_inode);
5486 + h_src_attr->valid = 1;
5487 + if (!au_test_nfs(h_src_inode->i_sb)) {
5488 + err = au_cp_regular(cpg);
5489 + inode_unlock_shared(h_src_inode);
5491 + inode_unlock_shared(h_src_inode);
5492 + err = au_cp_regular(cpg);
5494 + rerr = au_pin_hdir_relock(cpg->pin);
5498 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5499 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5500 + h_dst_inode = d_inode(h_path.dentry);
5501 + spin_lock(&h_dst_inode->i_lock);
5502 + h_dst_inode->i_state |= I_LINKABLE;
5503 + spin_unlock(&h_dst_inode->i_lock);
5510 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5511 + struct inode *h_dir)
5514 + mm_segment_t old_fs;
5521 + sym.k = (void *)__get_free_page(GFP_NOFS);
5522 + if (unlikely(!sym.k))
5525 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5526 + old_fs = get_fs();
5527 + set_fs(KERNEL_DS);
5528 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5533 + sym.k[symlen] = 0;
5534 + err = vfsub_symlink(h_dir, h_path, sym.k);
5536 + free_page((unsigned long)sym.k);
5543 + * regardless 'acl' option, reset all ACL.
5544 + * All ACL will be copied up later from the original entry on the lower branch.
5546 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5549 + struct dentry *h_dentry;
5550 + struct inode *h_inode;
5552 + h_dentry = h_path->dentry;
5553 + h_inode = d_inode(h_dentry);
5554 + /* forget_all_cached_acls(h_inode)); */
5555 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5557 + if (err == -EOPNOTSUPP)
5560 + err = vfsub_acl_chmod(h_inode, mode);
5566 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5567 + struct inode *h_dir, struct path *h_path)
5570 + struct inode *dir, *inode;
5572 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5574 + if (err == -EOPNOTSUPP)
5576 + if (unlikely(err))
5580 + * strange behaviour from the users view,
5581 + * particularry setattr case
5583 + dir = d_inode(dst_parent);
5584 + if (au_ibtop(dir) == cpg->bdst)
5585 + au_cpup_attr_nlink(dir, /*force*/1);
5586 + inode = d_inode(cpg->dentry);
5587 + au_cpup_attr_nlink(inode, /*force*/1);
5593 +static noinline_for_stack
5594 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5595 + struct au_cpup_reg_attr *h_src_attr)
5599 + unsigned int mnt_flags;
5600 + unsigned char isdir, isreg, force;
5601 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5602 + struct au_dtime dt;
5603 + struct path h_path;
5604 + struct dentry *h_src, *h_dst, *h_parent;
5605 + struct inode *h_inode, *h_dir;
5606 + struct super_block *sb;
5608 + /* bsrc branch can be ro/rw. */
5609 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5610 + h_inode = d_inode(h_src);
5611 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5613 + /* try stopping to be referenced while we are creating */
5614 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5615 + if (au_ftest_cpup(cpg->flags, RENAME))
5616 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5617 + AUFS_WH_PFX_LEN));
5618 + h_parent = h_dst->d_parent; /* dir inode is locked */
5619 + h_dir = d_inode(h_parent);
5621 + AuDebugOn(h_parent != h_dst->d_parent);
5623 + sb = cpg->dentry->d_sb;
5624 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5626 + h_path.dentry = h_parent;
5627 + au_dtime_store(&dt, dst_parent, &h_path);
5629 + h_path.dentry = h_dst;
5633 + mode = h_inode->i_mode;
5634 + switch (mode & S_IFMT) {
5637 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5638 + /*want_excl*/true);
5640 + err = au_do_cpup_regular(cpg, h_src_attr);
5644 + err = vfsub_mkdir(h_dir, &h_path, mode);
5646 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5649 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5653 + AuDebugOn(!capable(CAP_MKNOD));
5657 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5660 + AuIOErr("Unknown inode type 0%o\n", mode);
5664 + err = au_reset_acl(h_dir, &h_path, mode);
5666 + mnt_flags = au_mntflags(sb);
5667 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5669 + && au_opt_test(mnt_flags, XINO)
5670 + && (h_inode->i_nlink == 1
5671 + || (h_inode->i_state & I_LINKABLE))
5672 + /* todo: unnecessary? */
5673 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5674 + && cpg->bdst < cpg->bsrc
5675 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5676 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5677 + /* ignore this error */
5682 + force = !!cpg->len;
5683 + if (cpg->len == -1)
5684 + force = !!i_size_read(h_inode);
5686 + au_fhsm_wrote(sb, cpg->bdst, force);
5690 + au_dtime_revert(&dt);
5694 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5697 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5698 + struct inode *h_dir;
5699 + aufs_bindex_t bdst;
5701 + dentry = cpg->dentry;
5703 + h_dentry = au_h_dptr(dentry, bdst);
5704 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5706 + au_set_h_dptr(dentry, bdst, NULL);
5707 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5709 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5710 + au_set_h_dptr(dentry, bdst, h_dentry);
5713 + parent = dget_parent(dentry);
5714 + h_parent = au_h_dptr(parent, bdst);
5716 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5717 + if (IS_ERR(h_path->dentry))
5718 + err = PTR_ERR(h_path->dentry);
5720 + if (unlikely(err))
5723 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5724 + h_dir = d_inode(h_parent);
5726 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5727 + /* no delegation since it is just created */
5728 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5730 + dput(h_path->dentry);
5737 + * copyup the @dentry from @bsrc to @bdst.
5738 + * the caller must set the both of lower dentries.
5739 + * @len is for truncating when it is -1 copyup the entire file.
5740 + * in link/rename cases, @dst_parent may be different from the real one.
5741 + * basic->bsrc can be larger than basic->bdst.
5742 + * aufs doesn't touch the credential so
5743 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5745 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5748 + aufs_bindex_t old_ibtop;
5749 + unsigned char isdir, plink;
5750 + struct dentry *h_src, *h_dst, *h_parent;
5751 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5752 + struct super_block *sb;
5753 + struct au_branch *br;
5754 + /* to reuduce stack size */
5756 + struct au_dtime dt;
5757 + struct path h_path;
5758 + struct au_cpup_reg_attr h_src_attr;
5762 + a = kmalloc(sizeof(*a), GFP_NOFS);
5765 + a->h_src_attr.valid = 0;
5767 + sb = cpg->dentry->d_sb;
5768 + br = au_sbr(sb, cpg->bdst);
5769 + a->h_path.mnt = au_br_mnt(br);
5770 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5771 + h_parent = h_dst->d_parent; /* dir inode is locked */
5772 + h_dir = d_inode(h_parent);
5775 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5776 + inode = d_inode(cpg->dentry);
5779 + dst_parent = dget_parent(cpg->dentry);
5783 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5784 + dst_inode = au_h_iptr(inode, cpg->bdst);
5786 + if (unlikely(!plink)) {
5788 + AuIOErr("hi%lu(i%lu) exists on b%d "
5789 + "but plink is disabled\n",
5790 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5794 + if (dst_inode->i_nlink) {
5795 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5797 + h_src = au_plink_lkup(inode, cpg->bdst);
5798 + err = PTR_ERR(h_src);
5799 + if (IS_ERR(h_src))
5801 + if (unlikely(d_is_negative(h_src))) {
5803 + AuIOErr("i%lu exists on b%d "
5804 + "but not pseudo-linked\n",
5805 + inode->i_ino, cpg->bdst);
5811 + a->h_path.dentry = h_parent;
5812 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5815 + a->h_path.dentry = h_dst;
5817 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5818 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5819 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5821 + au_dtime_revert(&a->dt);
5822 + if (unlikely(err == -EWOULDBLOCK)) {
5823 + pr_warn("cannot retry for NFSv4 delegation"
5824 + " for an internal link\n");
5830 + /* todo: cpup_wh_file? */
5832 + au_update_ibrange(inode, /*do_put_zero*/1);
5835 + isdir = S_ISDIR(inode->i_mode);
5836 + old_ibtop = au_ibtop(inode);
5837 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5838 + if (unlikely(err))
5840 + dst_inode = d_inode(h_dst);
5841 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5842 + /* todo: necessary? */
5843 + /* au_pin_hdir_unlock(cpg->pin); */
5845 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5846 + if (unlikely(err)) {
5847 + /* todo: necessary? */
5848 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5849 + inode_unlock(dst_inode);
5853 + if (cpg->bdst < old_ibtop) {
5854 + if (S_ISREG(inode->i_mode)) {
5855 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5856 + if (unlikely(err)) {
5857 + /* ignore an error */
5858 + /* au_pin_hdir_relock(cpg->pin); */
5859 + inode_unlock(dst_inode);
5863 + au_set_ibtop(inode, cpg->bdst);
5865 + au_set_ibbot(inode, cpg->bdst);
5866 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5867 + au_hi_flags(inode, isdir));
5869 + /* todo: necessary? */
5870 + /* err = au_pin_hdir_relock(cpg->pin); */
5871 + inode_unlock(dst_inode);
5872 + if (unlikely(err))
5875 + src_inode = d_inode(h_src);
5877 + && (src_inode->i_nlink > 1
5878 + || src_inode->i_state & I_LINKABLE)
5880 + au_plink_append(inode, cpg->bdst, h_dst);
5882 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5883 + a->h_path.dentry = h_dst;
5884 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5887 + goto out_parent; /* success */
5891 + a->h_path.dentry = h_parent;
5892 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5893 + a->h_path.dentry = h_dst;
5895 + if (d_is_positive(h_dst)) {
5897 + /* no delegation since it is just created */
5898 + rerr = vfsub_unlink(h_dir, &a->h_path,
5899 + /*delegated*/NULL, /*force*/0);
5901 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5903 + au_dtime_revert(&a->dt);
5905 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5915 +#if 0 /* reserved */
5916 +struct au_cpup_single_args {
5918 + struct au_cp_generic *cpg;
5919 + struct dentry *dst_parent;
5922 +static void au_call_cpup_single(void *args)
5924 + struct au_cpup_single_args *a = args;
5926 + au_pin_hdir_acquire_nest(a->cpg->pin);
5927 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5928 + au_pin_hdir_release(a->cpg->pin);
5933 + * prevent SIGXFSZ in copy-up.
5934 + * testing CAP_MKNOD is for generic fs,
5935 + * but CAP_FSETID is for xfs only, currently.
5937 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5940 + struct super_block *sb;
5941 + struct inode *h_dir;
5944 + sb = au_pinned_parent(pin)->d_sb;
5945 + if (!au_wkq_test()
5946 + && (!au_sbi(sb)->si_plink_maint_pid
5947 + || au_plink_maint(sb, AuLock_NOPLM))) {
5948 + switch (mode & S_IFMT) {
5950 + /* no condition about RLIMIT_FSIZE and the file size */
5955 + do_sio = !capable(CAP_MKNOD);
5959 + do_sio = ((mode & (S_ISUID | S_ISGID))
5960 + && !capable(CAP_FSETID));
5961 + /* this workaround may be removed in the future */
5963 + h_dir = au_pinned_h_dir(pin);
5964 + do_sio = h_dir->i_mode & S_ISVTX;
5971 +#if 0 /* reserved */
5972 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5975 + struct dentry *h_dentry;
5977 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5978 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5979 + err = au_cpup_single(cpg, dst_parent);
5981 + struct au_cpup_single_args args = {
5984 + .dst_parent = dst_parent
5986 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5987 + if (unlikely(wkq_err))
5996 + * copyup the @dentry from the first active lower branch to @bdst,
5997 + * using au_cpup_single().
5999 +static int au_cpup_simple(struct au_cp_generic *cpg)
6002 + unsigned int flags_orig;
6003 + struct dentry *dentry;
6005 + AuDebugOn(cpg->bsrc < 0);
6007 + dentry = cpg->dentry;
6008 + DiMustWriteLock(dentry);
6010 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6012 + flags_orig = cpg->flags;
6013 + au_fset_cpup(cpg->flags, RENAME);
6014 + err = au_cpup_single(cpg, NULL);
6015 + cpg->flags = flags_orig;
6017 + return 0; /* success */
6020 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6021 + au_set_dbtop(dentry, cpg->bsrc);
6027 +struct au_cpup_simple_args {
6029 + struct au_cp_generic *cpg;
6032 +static void au_call_cpup_simple(void *args)
6034 + struct au_cpup_simple_args *a = args;
6036 + au_pin_hdir_acquire_nest(a->cpg->pin);
6037 + *a->errp = au_cpup_simple(a->cpg);
6038 + au_pin_hdir_release(a->cpg->pin);
6041 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6044 + struct dentry *dentry, *parent;
6045 + struct file *h_file;
6046 + struct inode *h_dir;
6048 + dentry = cpg->dentry;
6050 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6051 + AuDebugOn(cpg->bsrc < 0);
6052 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6053 + err = PTR_ERR(h_file);
6054 + if (IS_ERR(h_file))
6058 + parent = dget_parent(dentry);
6059 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6060 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6061 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6062 + err = au_cpup_simple(cpg);
6064 + struct au_cpup_simple_args args = {
6068 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6069 + if (unlikely(wkq_err))
6075 + au_h_open_post(dentry, cpg->bsrc, h_file);
6081 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6083 + aufs_bindex_t bsrc, bbot;
6084 + struct dentry *dentry, *h_dentry;
6086 + if (cpg->bsrc < 0) {
6087 + dentry = cpg->dentry;
6088 + bbot = au_dbbot(dentry);
6089 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6090 + h_dentry = au_h_dptr(dentry, bsrc);
6092 + AuDebugOn(d_is_negative(h_dentry));
6096 + AuDebugOn(bsrc > bbot);
6099 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6100 + return au_do_sio_cpup_simple(cpg);
6103 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6105 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6106 + return au_do_sio_cpup_simple(cpg);
6109 +/* ---------------------------------------------------------------------- */
6112 + * copyup the deleted file for writing.
6114 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6115 + struct file *file)
6118 + unsigned int flags_orig;
6119 + aufs_bindex_t bsrc_orig;
6120 + struct au_dinfo *dinfo;
6122 + struct au_hdentry *hd;
6123 + struct dentry *h_dentry;
6126 + dinfo = au_di(cpg->dentry);
6127 + AuRwMustWriteLock(&dinfo->di_rwsem);
6129 + bsrc_orig = cpg->bsrc;
6130 + cpg->bsrc = dinfo->di_btop;
6131 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6132 + hdst.h_dentry = hdst.hd->hd_dentry;
6133 + hdst.hd->hd_dentry = wh_dentry;
6134 + dinfo->di_btop = cpg->bdst;
6136 + hsrc.h_dentry = NULL;
6138 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6139 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6140 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6142 + flags_orig = cpg->flags;
6143 + cpg->flags = !AuCpup_DTIME;
6144 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6145 + cpg->flags = flags_orig;
6148 + err = au_reopen_nondir(file);
6149 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6151 + hdst.hd->hd_dentry = hdst.h_dentry;
6152 + dinfo->di_btop = cpg->bsrc;
6153 + cpg->bsrc = bsrc_orig;
6158 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6161 + aufs_bindex_t bdst;
6162 + struct au_dtime dt;
6163 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6164 + struct au_branch *br;
6165 + struct path h_path;
6167 + dentry = cpg->dentry;
6169 + br = au_sbr(dentry->d_sb, bdst);
6170 + parent = dget_parent(dentry);
6171 + h_parent = au_h_dptr(parent, bdst);
6172 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6173 + err = PTR_ERR(wh_dentry);
6174 + if (IS_ERR(wh_dentry))
6177 + h_path.dentry = h_parent;
6178 + h_path.mnt = au_br_mnt(br);
6179 + au_dtime_store(&dt, parent, &h_path);
6180 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6181 + if (unlikely(err))
6185 + h_path.dentry = wh_dentry;
6186 + if (!d_is_dir(wh_dentry)) {
6187 + /* no delegation since it is just created */
6188 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6189 + /*delegated*/NULL, /*force*/0);
6191 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6192 + if (unlikely(err)) {
6193 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6197 + au_dtime_revert(&dt);
6198 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6207 +struct au_cpup_wh_args {
6209 + struct au_cp_generic *cpg;
6210 + struct file *file;
6213 +static void au_call_cpup_wh(void *args)
6215 + struct au_cpup_wh_args *a = args;
6217 + au_pin_hdir_acquire_nest(a->cpg->pin);
6218 + *a->errp = au_cpup_wh(a->cpg, a->file);
6219 + au_pin_hdir_release(a->cpg->pin);
6222 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6225 + aufs_bindex_t bdst;
6226 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6227 + struct inode *dir, *h_dir, *h_tmpdir;
6228 + struct au_wbr *wbr;
6229 + struct au_pin wh_pin, *pin_orig;
6231 + dentry = cpg->dentry;
6233 + parent = dget_parent(dentry);
6234 + dir = d_inode(parent);
6237 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6240 + if (!h_dir->i_nlink) {
6241 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6242 + h_orph = wbr->wbr_orph;
6244 + h_parent = dget(au_h_dptr(parent, bdst));
6245 + au_set_h_dptr(parent, bdst, dget(h_orph));
6246 + h_tmpdir = d_inode(h_orph);
6247 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6249 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6250 + /* todo: au_h_open_pre()? */
6252 + pin_orig = cpg->pin;
6253 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6254 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6255 + cpg->pin = &wh_pin;
6258 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6259 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6260 + err = au_cpup_wh(cpg, file);
6262 + struct au_cpup_wh_args args = {
6267 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6268 + if (unlikely(wkq_err))
6273 + inode_unlock(h_tmpdir);
6274 + /* todo: au_h_open_post()? */
6275 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6276 + au_set_h_dptr(parent, bdst, h_parent);
6277 + AuDebugOn(!pin_orig);
6278 + cpg->pin = pin_orig;
6286 +/* ---------------------------------------------------------------------- */
6289 + * generic routine for both of copy-up and copy-down.
6291 +/* cf. revalidate function in file.c */
6292 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6293 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6294 + struct au_pin *pin,
6295 + struct dentry *h_parent, void *arg),
6299 + struct au_pin pin;
6300 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6303 + parent = dget_parent(dentry);
6304 + if (IS_ROOT(parent))
6307 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6308 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6310 + /* do not use au_dpage */
6311 + real_parent = parent;
6314 + parent = dget_parent(dentry);
6315 + h_parent = au_h_dptr(parent, bdst);
6317 + goto out; /* success */
6319 + /* find top dir which is necessary to cpup */
6323 + parent = dget_parent(d);
6324 + di_read_lock_parent3(parent, !AuLock_IR);
6325 + h_parent = au_h_dptr(parent, bdst);
6326 + di_read_unlock(parent, !AuLock_IR);
6327 + } while (!h_parent);
6329 + if (d != real_parent)
6330 + di_write_lock_child3(d);
6332 + /* somebody else might create while we were sleeping */
6333 + h_dentry = au_h_dptr(d, bdst);
6334 + if (!h_dentry || d_is_negative(h_dentry)) {
6336 + au_update_dbtop(d);
6338 + au_pin_set_dentry(&pin, d);
6339 + err = au_do_pin(&pin);
6341 + err = cp(d, bdst, &pin, h_parent, arg);
6346 + if (d != real_parent)
6347 + di_write_unlock(d);
6348 + if (unlikely(err))
6357 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6358 + struct au_pin *pin,
6359 + struct dentry *h_parent __maybe_unused,
6360 + void *arg __maybe_unused)
6362 + struct au_cp_generic cpg = {
6368 + .flags = AuCpup_DTIME
6370 + return au_sio_cpup_simple(&cpg);
6373 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6375 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6378 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6381 + struct dentry *parent;
6382 + struct inode *dir;
6384 + parent = dget_parent(dentry);
6385 + dir = d_inode(parent);
6387 + if (au_h_iptr(dir, bdst))
6390 + di_read_unlock(parent, AuLock_IR);
6391 + di_write_lock_parent(parent);
6392 + /* someone else might change our inode while we were sleeping */
6393 + if (!au_h_iptr(dir, bdst))
6394 + err = au_cpup_dirs(dentry, bdst);
6395 + di_downgrade_lock(parent, AuLock_IR);
6401 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6402 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6403 +++ linux/fs/aufs/cpup.h 2017-11-12 22:24:44.704244405 +0100
6406 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6408 + * This program, aufs is free software; you can redistribute it and/or modify
6409 + * it under the terms of the GNU General Public License as published by
6410 + * the Free Software Foundation; either version 2 of the License, or
6411 + * (at your option) any later version.
6413 + * This program is distributed in the hope that it will be useful,
6414 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6415 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6416 + * GNU General Public License for more details.
6418 + * You should have received a copy of the GNU General Public License
6419 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6423 + * copy-up/down functions
6426 +#ifndef __AUFS_CPUP_H__
6427 +#define __AUFS_CPUP_H__
6431 +#include <linux/path.h>
6437 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6438 +void au_cpup_attr_timesizes(struct inode *inode);
6439 +void au_cpup_attr_nlink(struct inode *inode, int force);
6440 +void au_cpup_attr_changeable(struct inode *inode);
6441 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6442 +void au_cpup_attr_all(struct inode *inode, int force);
6444 +/* ---------------------------------------------------------------------- */
6446 +struct au_cp_generic {
6447 + struct dentry *dentry;
6448 + aufs_bindex_t bdst, bsrc;
6450 + struct au_pin *pin;
6451 + unsigned int flags;
6455 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6456 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6458 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6459 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6461 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6463 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6464 + the branch is marked as RO */
6466 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6467 +#undef AuCpup_HOPEN
6468 +#define AuCpup_HOPEN 0
6471 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6472 +#define au_fset_cpup(flags, name) \
6473 + do { (flags) |= AuCpup_##name; } while (0)
6474 +#define au_fclr_cpup(flags, name) \
6475 + do { (flags) &= ~AuCpup_##name; } while (0)
6477 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6478 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6479 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6480 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6482 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6483 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6484 + struct au_pin *pin,
6485 + struct dentry *h_parent, void *arg),
6487 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6488 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6490 +/* ---------------------------------------------------------------------- */
6492 +/* keep timestamps when copyup */
6494 + struct dentry *dt_dentry;
6495 + struct path dt_h_path;
6496 + struct timespec dt_atime, dt_mtime;
6498 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6499 + struct path *h_path);
6500 +void au_dtime_revert(struct au_dtime *dt);
6502 +#endif /* __KERNEL__ */
6503 +#endif /* __AUFS_CPUP_H__ */
6504 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6505 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6506 +++ linux/fs/aufs/dbgaufs.c 2017-11-12 22:24:44.704244405 +0100
6509 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6511 + * This program, aufs is free software; you can redistribute it and/or modify
6512 + * it under the terms of the GNU General Public License as published by
6513 + * the Free Software Foundation; either version 2 of the License, or
6514 + * (at your option) any later version.
6516 + * This program is distributed in the hope that it will be useful,
6517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6519 + * GNU General Public License for more details.
6521 + * You should have received a copy of the GNU General Public License
6522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6526 + * debugfs interface
6529 +#include <linux/debugfs.h>
6532 +#ifndef CONFIG_SYSFS
6533 +#error DEBUG_FS depends upon SYSFS
6536 +static struct dentry *dbgaufs;
6537 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6539 +/* 20 is max digits length of ulong 64 */
6540 +struct dbgaufs_arg {
6546 + * common function for all XINO files
6548 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6549 + struct file *file)
6551 + kfree(file->private_data);
6555 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6559 + struct dbgaufs_arg *p;
6562 + p = kmalloc(sizeof(*p), GFP_NOFS);
6568 + file->private_data = p;
6572 + err = vfsub_getattr(&xf->f_path, &st);
6576 + (p->a, sizeof(p->a), "%ld, %llux%u %lld\n",
6577 + (long)file_count(xf), st.blocks, st.blksize,
6578 + (long long)st.size);
6580 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6581 + st.blocks, st.blksize,
6582 + (long long)st.size);
6583 + AuDebugOn(p->n >= sizeof(p->a));
6585 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6594 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6595 + size_t count, loff_t *ppos)
6597 + struct dbgaufs_arg *p;
6599 + p = file->private_data;
6600 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6603 +/* ---------------------------------------------------------------------- */
6605 +struct dbgaufs_plink_arg {
6610 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6611 + struct file *file)
6613 + free_page((unsigned long)file->private_data);
6617 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6619 + int err, i, limit;
6620 + unsigned long n, sum;
6621 + struct dbgaufs_plink_arg *p;
6622 + struct au_sbinfo *sbinfo;
6623 + struct super_block *sb;
6624 + struct hlist_bl_head *hbl;
6627 + p = (void *)get_zeroed_page(GFP_NOFS);
6632 + sbinfo = inode->i_private;
6633 + sb = sbinfo->si_sb;
6634 + si_noflush_read_lock(sb);
6635 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6636 + limit = PAGE_SIZE - sizeof(p->n);
6638 + /* the number of buckets */
6639 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6644 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6646 + n = au_hbl_count(hbl);
6649 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6652 + if (unlikely(limit <= 0))
6655 + p->a[p->n - 1] = '\n';
6657 + /* the sum of plinks */
6658 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6661 + if (unlikely(limit <= 0))
6664 +#define str "1\n0\n0\n"
6665 + p->n = sizeof(str) - 1;
6666 + strcpy(p->a, str);
6669 + si_read_unlock(sb);
6672 + file->private_data = p;
6673 + goto out; /* success */
6676 + free_page((unsigned long)p);
6681 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6682 + size_t count, loff_t *ppos)
6684 + struct dbgaufs_plink_arg *p;
6686 + p = file->private_data;
6687 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6690 +static const struct file_operations dbgaufs_plink_fop = {
6691 + .owner = THIS_MODULE,
6692 + .open = dbgaufs_plink_open,
6693 + .release = dbgaufs_plink_release,
6694 + .read = dbgaufs_plink_read
6697 +/* ---------------------------------------------------------------------- */
6699 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6702 + struct au_sbinfo *sbinfo;
6703 + struct super_block *sb;
6705 + sbinfo = inode->i_private;
6706 + sb = sbinfo->si_sb;
6707 + si_noflush_read_lock(sb);
6708 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6709 + si_read_unlock(sb);
6713 +static const struct file_operations dbgaufs_xib_fop = {
6714 + .owner = THIS_MODULE,
6715 + .open = dbgaufs_xib_open,
6716 + .release = dbgaufs_xi_release,
6717 + .read = dbgaufs_xi_read
6720 +/* ---------------------------------------------------------------------- */
6722 +#define DbgaufsXi_PREFIX "xi"
6724 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6728 + struct au_sbinfo *sbinfo;
6729 + struct super_block *sb;
6731 + struct qstr *name;
6735 + name = &file->f_path.dentry->d_name;
6736 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6737 + || memcmp(name->name, DbgaufsXi_PREFIX,
6738 + sizeof(DbgaufsXi_PREFIX) - 1)))
6740 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6741 + if (unlikely(err))
6744 + sbinfo = inode->i_private;
6745 + sb = sbinfo->si_sb;
6746 + si_noflush_read_lock(sb);
6747 + if (l <= au_sbbot(sb)) {
6748 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6749 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6752 + si_read_unlock(sb);
6758 +static const struct file_operations dbgaufs_xino_fop = {
6759 + .owner = THIS_MODULE,
6760 + .open = dbgaufs_xino_open,
6761 + .release = dbgaufs_xi_release,
6762 + .read = dbgaufs_xi_read
6765 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6767 + aufs_bindex_t bbot;
6768 + struct au_branch *br;
6769 + struct au_xino_file *xi;
6771 + if (!au_sbi(sb)->si_dbgaufs)
6774 + bbot = au_sbbot(sb);
6775 + for (; bindex <= bbot; bindex++) {
6776 + br = au_sbr(sb, bindex);
6777 + xi = &br->br_xino;
6778 + /* debugfs acquires the parent i_mutex */
6780 + debugfs_remove(xi->xi_dbgaufs);
6782 + xi->xi_dbgaufs = NULL;
6786 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6788 + struct au_sbinfo *sbinfo;
6789 + struct dentry *parent;
6790 + struct au_branch *br;
6791 + struct au_xino_file *xi;
6792 + aufs_bindex_t bbot;
6793 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6795 + sbinfo = au_sbi(sb);
6796 + parent = sbinfo->si_dbgaufs;
6800 + bbot = au_sbbot(sb);
6801 + for (; bindex <= bbot; bindex++) {
6802 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6803 + br = au_sbr(sb, bindex);
6804 + xi = &br->br_xino;
6805 + AuDebugOn(xi->xi_dbgaufs);
6806 + /* debugfs acquires the parent i_mutex */
6808 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6809 + sbinfo, &dbgaufs_xino_fop);
6811 + /* ignore an error */
6812 + if (unlikely(!xi->xi_dbgaufs))
6813 + AuWarn1("failed %s under debugfs\n", name);
6817 +/* ---------------------------------------------------------------------- */
6819 +#ifdef CONFIG_AUFS_EXPORT
6820 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6823 + struct au_sbinfo *sbinfo;
6824 + struct super_block *sb;
6826 + sbinfo = inode->i_private;
6827 + sb = sbinfo->si_sb;
6828 + si_noflush_read_lock(sb);
6829 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6830 + si_read_unlock(sb);
6834 +static const struct file_operations dbgaufs_xigen_fop = {
6835 + .owner = THIS_MODULE,
6836 + .open = dbgaufs_xigen_open,
6837 + .release = dbgaufs_xi_release,
6838 + .read = dbgaufs_xi_read
6841 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6846 + * This function is a dynamic '__init' function actually,
6847 + * so the tiny check for si_rwsem is unnecessary.
6849 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6852 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6853 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6854 + &dbgaufs_xigen_fop);
6855 + if (sbinfo->si_dbgaufs_xigen)
6861 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6865 +#endif /* CONFIG_AUFS_EXPORT */
6867 +/* ---------------------------------------------------------------------- */
6869 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6872 + * This function is a dynamic '__fin' function actually,
6873 + * so the tiny check for si_rwsem is unnecessary.
6875 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6877 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6878 + sbinfo->si_dbgaufs = NULL;
6879 + kobject_put(&sbinfo->si_kobj);
6882 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6885 + char name[SysaufsSiNameLen];
6888 + * This function is a dynamic '__init' function actually,
6889 + * so the tiny check for si_rwsem is unnecessary.
6891 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6895 + AuErr1("/debug/aufs is uninitialized\n");
6900 + sysaufs_name(sbinfo, name);
6901 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6902 + if (unlikely(!sbinfo->si_dbgaufs))
6904 + kobject_get(&sbinfo->si_kobj);
6906 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6907 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6908 + &dbgaufs_xib_fop);
6909 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6912 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6913 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6914 + &dbgaufs_plink_fop);
6915 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6918 + err = dbgaufs_xigen_init(sbinfo);
6920 + goto out; /* success */
6923 + dbgaufs_si_fin(sbinfo);
6928 +/* ---------------------------------------------------------------------- */
6930 +void dbgaufs_fin(void)
6932 + debugfs_remove(dbgaufs);
6935 +int __init dbgaufs_init(void)
6940 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6945 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6946 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6947 +++ linux/fs/aufs/dbgaufs.h 2017-07-29 12:14:25.899708630 +0200
6950 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6952 + * This program, aufs is free software; you can redistribute it and/or modify
6953 + * it under the terms of the GNU General Public License as published by
6954 + * the Free Software Foundation; either version 2 of the License, or
6955 + * (at your option) any later version.
6957 + * This program is distributed in the hope that it will be useful,
6958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6960 + * GNU General Public License for more details.
6962 + * You should have received a copy of the GNU General Public License
6963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6967 + * debugfs interface
6970 +#ifndef __DBGAUFS_H__
6971 +#define __DBGAUFS_H__
6975 +struct super_block;
6978 +#ifdef CONFIG_DEBUG_FS
6980 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6981 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6982 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6983 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6984 +void dbgaufs_fin(void);
6985 +int __init dbgaufs_init(void);
6987 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6988 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6989 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6990 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6991 +AuStubVoid(dbgaufs_fin, void)
6992 +AuStubInt0(__init dbgaufs_init, void)
6993 +#endif /* CONFIG_DEBUG_FS */
6995 +#endif /* __KERNEL__ */
6996 +#endif /* __DBGAUFS_H__ */
6997 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6998 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6999 +++ linux/fs/aufs/dcsub.c 2017-11-12 22:24:42.267510077 +0100
7002 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7004 + * This program, aufs is free software; you can redistribute it and/or modify
7005 + * it under the terms of the GNU General Public License as published by
7006 + * the Free Software Foundation; either version 2 of the License, or
7007 + * (at your option) any later version.
7009 + * This program is distributed in the hope that it will be useful,
7010 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7011 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7012 + * GNU General Public License for more details.
7014 + * You should have received a copy of the GNU General Public License
7015 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7019 + * sub-routines for dentry cache
7024 +static void au_dpage_free(struct au_dpage *dpage)
7027 + struct dentry **p;
7029 + p = dpage->dentries;
7030 + for (i = 0; i < dpage->ndentry; i++)
7032 + free_page((unsigned long)dpage->dentries);
7035 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7041 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7042 + if (unlikely(!dpages->dpages))
7045 + p = (void *)__get_free_page(gfp);
7049 + dpages->dpages[0].ndentry = 0;
7050 + dpages->dpages[0].dentries = p;
7051 + dpages->ndpage = 1;
7052 + return 0; /* success */
7055 + kfree(dpages->dpages);
7060 +void au_dpages_free(struct au_dcsub_pages *dpages)
7063 + struct au_dpage *p;
7065 + p = dpages->dpages;
7066 + for (i = 0; i < dpages->ndpage; i++)
7067 + au_dpage_free(p++);
7068 + kfree(dpages->dpages);
7071 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7072 + struct dentry *dentry, gfp_t gfp)
7075 + struct au_dpage *dpage;
7078 + dpage = dpages->dpages + dpages->ndpage - 1;
7079 + sz = PAGE_SIZE / sizeof(dentry);
7080 + if (unlikely(dpage->ndentry >= sz)) {
7081 + AuLabel(new dpage);
7083 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7084 + p = au_kzrealloc(dpages->dpages, sz,
7085 + sz + sizeof(*dpages->dpages), gfp,
7090 + dpages->dpages = p;
7091 + dpage = dpages->dpages + dpages->ndpage;
7092 + p = (void *)__get_free_page(gfp);
7096 + dpage->ndentry = 0;
7097 + dpage->dentries = p;
7101 + AuDebugOn(au_dcount(dentry) <= 0);
7102 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7103 + return 0; /* success */
7109 +/* todo: BAD approach */
7110 +/* copied from linux/fs/dcache.c */
7118 +extern void d_walk(struct dentry *parent, void *data,
7119 + enum d_walk_ret (*enter)(void *, struct dentry *),
7120 + void (*finish)(void *));
7122 +struct ac_dpages_arg {
7124 + struct au_dcsub_pages *dpages;
7125 + struct super_block *sb;
7126 + au_dpages_test test;
7130 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7132 + enum d_walk_ret ret;
7133 + struct ac_dpages_arg *arg = _arg;
7135 + ret = D_WALK_CONTINUE;
7136 + if (dentry->d_sb == arg->sb
7137 + && !IS_ROOT(dentry)
7138 + && au_dcount(dentry) > 0
7140 + && (!arg->test || arg->test(dentry, arg->arg))) {
7141 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7142 + if (unlikely(arg->err))
7143 + ret = D_WALK_QUIT;
7149 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7150 + au_dpages_test test, void *arg)
7152 + struct ac_dpages_arg args = {
7160 + d_walk(root, &args, au_call_dpages_append, NULL);
7165 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7166 + int do_include, au_dpages_test test, void *arg)
7171 + write_seqlock(&rename_lock);
7172 + spin_lock(&dentry->d_lock);
7174 + && au_dcount(dentry) > 0
7175 + && (!test || test(dentry, arg)))
7176 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7177 + spin_unlock(&dentry->d_lock);
7178 + if (unlikely(err))
7182 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7185 + while (!IS_ROOT(dentry)) {
7186 + dentry = dentry->d_parent; /* rename_lock is locked */
7187 + spin_lock(&dentry->d_lock);
7188 + if (au_dcount(dentry) > 0
7189 + && (!test || test(dentry, arg)))
7190 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7191 + spin_unlock(&dentry->d_lock);
7192 + if (unlikely(err))
7197 + write_sequnlock(&rename_lock);
7201 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7203 + return au_di(dentry) && dentry->d_sb == arg;
7206 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7207 + struct dentry *dentry, int do_include)
7209 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7210 + au_dcsub_dpages_aufs, dentry->d_sb);
7213 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7215 + struct path path[2] = {
7224 + return path_is_under(path + 0, path + 1);
7226 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7227 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7228 +++ linux/fs/aufs/dcsub.h 2017-07-29 12:14:25.899708630 +0200
7231 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7233 + * This program, aufs is free software; you can redistribute it and/or modify
7234 + * it under the terms of the GNU General Public License as published by
7235 + * the Free Software Foundation; either version 2 of the License, or
7236 + * (at your option) any later version.
7238 + * This program is distributed in the hope that it will be useful,
7239 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7240 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7241 + * GNU General Public License for more details.
7243 + * You should have received a copy of the GNU General Public License
7244 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7248 + * sub-routines for dentry cache
7251 +#ifndef __AUFS_DCSUB_H__
7252 +#define __AUFS_DCSUB_H__
7256 +#include <linux/dcache.h>
7257 +#include <linux/fs.h>
7261 + struct dentry **dentries;
7264 +struct au_dcsub_pages {
7266 + struct au_dpage *dpages;
7269 +/* ---------------------------------------------------------------------- */
7272 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7273 +void au_dpages_free(struct au_dcsub_pages *dpages);
7274 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7275 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7276 + au_dpages_test test, void *arg);
7277 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7278 + int do_include, au_dpages_test test, void *arg);
7279 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7280 + struct dentry *dentry, int do_include);
7281 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7283 +/* ---------------------------------------------------------------------- */
7286 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7287 + * include/linux/dcache.h. Try them (in the future).
7290 +static inline int au_d_hashed_positive(struct dentry *d)
7293 + struct inode *inode = d_inode(d);
7296 + if (unlikely(d_unhashed(d)
7297 + || d_is_negative(d)
7298 + || !inode->i_nlink))
7303 +static inline int au_d_linkable(struct dentry *d)
7306 + struct inode *inode = d_inode(d);
7308 + err = au_d_hashed_positive(d);
7310 + && d_is_positive(d)
7311 + && (inode->i_state & I_LINKABLE))
7316 +static inline int au_d_alive(struct dentry *d)
7319 + struct inode *inode;
7323 + err = au_d_hashed_positive(d);
7325 + inode = d_inode(d);
7326 + if (unlikely(d_unlinked(d)
7327 + || d_is_negative(d)
7328 + || !inode->i_nlink))
7334 +static inline int au_alive_dir(struct dentry *d)
7338 + err = au_d_alive(d);
7339 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7344 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7346 + return a->len == b->len
7347 + && !memcmp(a->name, b->name, a->len);
7352 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7354 + * the type of d_lockref.count became int, but the inlined function d_count()
7355 + * still returns unsigned int.
7356 + * I don't know why. Maybe it is for every d_count() users?
7357 + * Anyway au_dcount() lives on.
7359 +static inline int au_dcount(struct dentry *d)
7361 + return (int)d_count(d);
7364 +#endif /* __KERNEL__ */
7365 +#endif /* __AUFS_DCSUB_H__ */
7366 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7367 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7368 +++ linux/fs/aufs/debug.c 2017-11-12 22:24:42.267510077 +0100
7371 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7373 + * This program, aufs is free software; you can redistribute it and/or modify
7374 + * it under the terms of the GNU General Public License as published by
7375 + * the Free Software Foundation; either version 2 of the License, or
7376 + * (at your option) any later version.
7378 + * This program is distributed in the hope that it will be useful,
7379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7381 + * GNU General Public License for more details.
7383 + * You should have received a copy of the GNU General Public License
7384 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7388 + * debug print functions
7393 +/* Returns 0, or -errno. arg is in kp->arg. */
7394 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7398 + err = kstrtoint(val, 0, &n);
7408 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7409 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7414 + return sprintf(buffer, "%d", atomic_read(a));
7417 +static struct kernel_param_ops param_ops_atomic_t = {
7418 + .set = param_atomic_t_set,
7419 + .get = param_atomic_t_get
7420 + /* void (*free)(void *arg) */
7423 +atomic_t aufs_debug = ATOMIC_INIT(0);
7424 +MODULE_PARM_DESC(debug, "debug print");
7425 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7427 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7428 +char *au_plevel = KERN_DEBUG;
7429 +#define dpri(fmt, ...) do { \
7431 + && strcmp(au_plevel, KERN_DEBUG)) \
7432 + || au_debug_test()) \
7433 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7436 +/* ---------------------------------------------------------------------- */
7438 +void au_dpri_whlist(struct au_nhash *whlist)
7440 + unsigned long ul, n;
7441 + struct hlist_head *head;
7442 + struct au_vdir_wh *pos;
7444 + n = whlist->nh_num;
7445 + head = whlist->nh_head;
7446 + for (ul = 0; ul < n; ul++) {
7447 + hlist_for_each_entry(pos, head, wh_hash)
7448 + dpri("b%d, %.*s, %d\n",
7450 + pos->wh_str.len, pos->wh_str.name,
7456 +void au_dpri_vdir(struct au_vdir *vdir)
7459 + union au_vdir_deblk_p p;
7462 + if (!vdir || IS_ERR(vdir)) {
7463 + dpri("err %ld\n", PTR_ERR(vdir));
7467 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7468 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7469 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7470 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7471 + p.deblk = vdir->vd_deblk[ul];
7473 + dpri("[%lu]: %p\n", ul, o);
7477 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7478 + struct dentry *wh)
7483 + if (!inode || IS_ERR(inode)) {
7484 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7488 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7489 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7490 + && sizeof(inode->i_blocks) != sizeof(u64));
7492 + n = (void *)wh->d_name.name;
7493 + l = wh->d_name.len;
7496 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7497 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7499 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7500 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7501 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7502 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7503 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7504 + inode->i_state, inode->i_flags, inode->i_version,
7505 + inode->i_generation,
7506 + l ? ", wh " : "", l, n);
7510 +void au_dpri_inode(struct inode *inode)
7512 + struct au_iinfo *iinfo;
7513 + struct au_hinode *hi;
7514 + aufs_bindex_t bindex;
7517 + err = do_pri_inode(-1, inode, -1, NULL);
7518 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7521 + iinfo = au_ii(inode);
7522 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7523 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7524 + if (iinfo->ii_btop < 0)
7527 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7528 + hi = au_hinode(iinfo, bindex);
7530 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7534 +void au_dpri_dalias(struct inode *inode)
7538 + spin_lock(&inode->i_lock);
7539 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7540 + au_dpri_dentry(d);
7541 + spin_unlock(&inode->i_lock);
7544 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7546 + struct dentry *wh = NULL;
7548 + struct inode *inode;
7549 + struct au_iinfo *iinfo;
7550 + struct au_hinode *hi;
7552 + if (!dentry || IS_ERR(dentry)) {
7553 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7556 + /* do not call dget_parent() here */
7557 + /* note: access d_xxx without d_lock */
7558 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7559 + bindex, dentry, dentry,
7560 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7561 + au_dcount(dentry), dentry->d_flags,
7562 + d_unhashed(dentry) ? "un" : "");
7565 + if (d_is_positive(dentry))
7566 + inode = d_inode(dentry);
7568 + && au_test_aufs(dentry->d_sb)
7570 + && !au_is_bad_inode(inode)) {
7571 + iinfo = au_ii(inode);
7572 + hi = au_hinode(iinfo, bindex);
7574 + wh = hi->hi_whdentry;
7576 + do_pri_inode(bindex, inode, hn, wh);
7580 +void au_dpri_dentry(struct dentry *dentry)
7582 + struct au_dinfo *dinfo;
7583 + aufs_bindex_t bindex;
7586 + err = do_pri_dentry(-1, dentry);
7587 + if (err || !au_test_aufs(dentry->d_sb))
7590 + dinfo = au_di(dentry);
7593 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7594 + dinfo->di_btop, dinfo->di_bbot,
7595 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7596 + dinfo->di_tmpfile);
7597 + if (dinfo->di_btop < 0)
7599 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7600 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7603 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7607 + if (!file || IS_ERR(file)) {
7608 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7613 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7614 + && au_test_aufs(file->f_path.dentry->d_sb)
7616 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7617 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7618 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7619 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7620 + file->f_version, file->f_pos, a);
7621 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7622 + do_pri_dentry(bindex, file->f_path.dentry);
7626 +void au_dpri_file(struct file *file)
7628 + struct au_finfo *finfo;
7629 + struct au_fidir *fidir;
7630 + struct au_hfile *hfile;
7631 + aufs_bindex_t bindex;
7634 + err = do_pri_file(-1, file);
7636 + || IS_ERR_OR_NULL(file->f_path.dentry)
7637 + || !au_test_aufs(file->f_path.dentry->d_sb))
7640 + finfo = au_fi(file);
7643 + if (finfo->fi_btop < 0)
7645 + fidir = finfo->fi_hdir;
7647 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7649 + for (bindex = finfo->fi_btop;
7650 + bindex >= 0 && bindex <= fidir->fd_bbot;
7652 + hfile = fidir->fd_hfile + bindex;
7653 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7657 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7659 + struct vfsmount *mnt;
7660 + struct super_block *sb;
7662 + if (!br || IS_ERR(br))
7664 + mnt = au_br_mnt(br);
7665 + if (!mnt || IS_ERR(mnt))
7668 + if (!sb || IS_ERR(sb))
7671 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7672 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7674 + bindex, br->br_perm, br->br_id, au_br_count(br),
7675 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7676 + sb->s_flags, sb->s_count,
7677 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7681 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7685 +void au_dpri_sb(struct super_block *sb)
7687 + struct au_sbinfo *sbinfo;
7688 + aufs_bindex_t bindex;
7690 + /* to reuduce stack size */
7692 + struct vfsmount mnt;
7693 + struct au_branch fake;
7696 + /* this function can be called from magic sysrq */
7697 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7698 + if (unlikely(!a)) {
7699 + dpri("no memory\n");
7703 + a->mnt.mnt_sb = sb;
7704 + a->fake.br_path.mnt = &a->mnt;
7705 + au_br_count_init(&a->fake);
7706 + err = do_pri_br(-1, &a->fake);
7707 + au_br_count_fin(&a->fake);
7709 + dpri("dev 0x%x\n", sb->s_dev);
7710 + if (err || !au_test_aufs(sb))
7713 + sbinfo = au_sbi(sb);
7716 + dpri("nw %d, gen %u, kobj %d\n",
7717 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7718 + kref_read(&sbinfo->si_kobj.kref));
7719 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7720 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7723 +/* ---------------------------------------------------------------------- */
7725 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7727 + struct inode *h_inode, *inode = d_inode(dentry);
7728 + struct dentry *h_dentry;
7729 + aufs_bindex_t bindex, bbot, bi;
7731 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7734 + bbot = au_dbbot(dentry);
7735 + bi = au_ibbot(inode);
7738 + bindex = au_dbtop(dentry);
7739 + bi = au_ibtop(inode);
7743 + for (; bindex <= bbot; bindex++) {
7744 + h_dentry = au_h_dptr(dentry, bindex);
7747 + h_inode = au_h_iptr(inode, bindex);
7748 + if (unlikely(h_inode != d_inode(h_dentry))) {
7750 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7751 + AuDbgDentry(dentry);
7752 + AuDbgInode(inode);
7759 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7762 + struct au_dcsub_pages dpages;
7763 + struct au_dpage *dpage;
7764 + struct dentry **dentries;
7766 + err = au_dpages_init(&dpages, GFP_NOFS);
7768 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7770 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7771 + dpage = dpages.dpages + i;
7772 + dentries = dpage->dentries;
7773 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7774 + AuDebugOn(au_digen_test(dentries[j], sigen));
7776 + au_dpages_free(&dpages);
7779 +void au_dbg_verify_kthread(void)
7781 + if (au_wkq_test()) {
7784 + * It may be recursive, but udba=notify between two aufs mounts,
7785 + * where a single ro branch is shared, is not a problem.
7791 +/* ---------------------------------------------------------------------- */
7793 +int __init au_debug_init(void)
7795 + aufs_bindex_t bindex;
7796 + struct au_vdir_destr destr;
7799 + AuDebugOn(bindex >= 0);
7802 + AuDebugOn(destr.len < NAME_MAX);
7804 +#ifdef CONFIG_4KSTACKS
7805 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7810 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7811 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7812 +++ linux/fs/aufs/debug.h 2017-07-29 12:14:25.899708630 +0200
7815 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7817 + * This program, aufs is free software; you can redistribute it and/or modify
7818 + * it under the terms of the GNU General Public License as published by
7819 + * the Free Software Foundation; either version 2 of the License, or
7820 + * (at your option) any later version.
7822 + * This program is distributed in the hope that it will be useful,
7823 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7824 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7825 + * GNU General Public License for more details.
7827 + * You should have received a copy of the GNU General Public License
7828 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7832 + * debug print functions
7835 +#ifndef __AUFS_DEBUG_H__
7836 +#define __AUFS_DEBUG_H__
7840 +#include <linux/atomic.h>
7841 +#include <linux/module.h>
7842 +#include <linux/kallsyms.h>
7843 +#include <linux/sysrq.h>
7845 +#ifdef CONFIG_AUFS_DEBUG
7846 +#define AuDebugOn(a) BUG_ON(a)
7848 +/* module parameter */
7849 +extern atomic_t aufs_debug;
7850 +static inline void au_debug_on(void)
7852 + atomic_inc(&aufs_debug);
7854 +static inline void au_debug_off(void)
7856 + atomic_dec_if_positive(&aufs_debug);
7859 +static inline int au_debug_test(void)
7861 + return atomic_read(&aufs_debug) > 0;
7864 +#define AuDebugOn(a) do {} while (0)
7865 +AuStubVoid(au_debug_on, void)
7866 +AuStubVoid(au_debug_off, void)
7867 +AuStubInt0(au_debug_test, void)
7868 +#endif /* CONFIG_AUFS_DEBUG */
7870 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7872 +/* ---------------------------------------------------------------------- */
7876 +#define AuDbg(fmt, ...) do { \
7877 + if (au_debug_test()) \
7878 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7880 +#define AuLabel(l) AuDbg(#l "\n")
7881 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7882 +#define AuWarn1(fmt, ...) do { \
7883 + static unsigned char _c; \
7885 + pr_warn(fmt, ##__VA_ARGS__); \
7888 +#define AuErr1(fmt, ...) do { \
7889 + static unsigned char _c; \
7891 + pr_err(fmt, ##__VA_ARGS__); \
7894 +#define AuIOErr1(fmt, ...) do { \
7895 + static unsigned char _c; \
7897 + AuIOErr(fmt, ##__VA_ARGS__); \
7900 +#define AuUnsupportMsg "This operation is not supported." \
7901 + " Please report this application to aufs-users ML."
7902 +#define AuUnsupport(fmt, ...) do { \
7903 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7907 +#define AuTraceErr(e) do { \
7908 + if (unlikely((e) < 0)) \
7909 + AuDbg("err %d\n", (int)(e)); \
7912 +#define AuTraceErrPtr(p) do { \
7914 + AuDbg("err %ld\n", PTR_ERR(p)); \
7917 +/* dirty macros for debug print, use with "%.*s" and caution */
7918 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7920 +/* ---------------------------------------------------------------------- */
7923 +#ifdef CONFIG_AUFS_DEBUG
7924 +extern struct mutex au_dbg_mtx;
7925 +extern char *au_plevel;
7927 +void au_dpri_whlist(struct au_nhash *whlist);
7929 +void au_dpri_vdir(struct au_vdir *vdir);
7931 +void au_dpri_inode(struct inode *inode);
7932 +void au_dpri_dalias(struct inode *inode);
7933 +void au_dpri_dentry(struct dentry *dentry);
7935 +void au_dpri_file(struct file *filp);
7936 +struct super_block;
7937 +void au_dpri_sb(struct super_block *sb);
7939 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7940 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7941 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7942 +void au_dbg_verify_kthread(void);
7944 +int __init au_debug_init(void);
7946 +#define AuDbgWhlist(w) do { \
7947 + mutex_lock(&au_dbg_mtx); \
7949 + au_dpri_whlist(w); \
7950 + mutex_unlock(&au_dbg_mtx); \
7953 +#define AuDbgVdir(v) do { \
7954 + mutex_lock(&au_dbg_mtx); \
7956 + au_dpri_vdir(v); \
7957 + mutex_unlock(&au_dbg_mtx); \
7960 +#define AuDbgInode(i) do { \
7961 + mutex_lock(&au_dbg_mtx); \
7963 + au_dpri_inode(i); \
7964 + mutex_unlock(&au_dbg_mtx); \
7967 +#define AuDbgDAlias(i) do { \
7968 + mutex_lock(&au_dbg_mtx); \
7970 + au_dpri_dalias(i); \
7971 + mutex_unlock(&au_dbg_mtx); \
7974 +#define AuDbgDentry(d) do { \
7975 + mutex_lock(&au_dbg_mtx); \
7977 + au_dpri_dentry(d); \
7978 + mutex_unlock(&au_dbg_mtx); \
7981 +#define AuDbgFile(f) do { \
7982 + mutex_lock(&au_dbg_mtx); \
7984 + au_dpri_file(f); \
7985 + mutex_unlock(&au_dbg_mtx); \
7988 +#define AuDbgSb(sb) do { \
7989 + mutex_lock(&au_dbg_mtx); \
7990 + AuDbg(#sb "\n"); \
7992 + mutex_unlock(&au_dbg_mtx); \
7995 +#define AuDbgSym(addr) do { \
7996 + char sym[KSYM_SYMBOL_LEN]; \
7997 + sprint_symbol(sym, (unsigned long)addr); \
7998 + AuDbg("%s\n", sym); \
8001 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8002 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8003 +AuStubVoid(au_dbg_verify_kthread, void)
8004 +AuStubInt0(__init au_debug_init, void)
8006 +#define AuDbgWhlist(w) do {} while (0)
8007 +#define AuDbgVdir(v) do {} while (0)
8008 +#define AuDbgInode(i) do {} while (0)
8009 +#define AuDbgDAlias(i) do {} while (0)
8010 +#define AuDbgDentry(d) do {} while (0)
8011 +#define AuDbgFile(f) do {} while (0)
8012 +#define AuDbgSb(sb) do {} while (0)
8013 +#define AuDbgSym(addr) do {} while (0)
8014 +#endif /* CONFIG_AUFS_DEBUG */
8016 +/* ---------------------------------------------------------------------- */
8018 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8019 +int __init au_sysrq_init(void);
8020 +void au_sysrq_fin(void);
8022 +#ifdef CONFIG_HW_CONSOLE
8023 +#define au_dbg_blocked() do { \
8025 + handle_sysrq('w'); \
8028 +AuStubVoid(au_dbg_blocked, void)
8032 +AuStubInt0(__init au_sysrq_init, void)
8033 +AuStubVoid(au_sysrq_fin, void)
8034 +AuStubVoid(au_dbg_blocked, void)
8035 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8037 +#endif /* __KERNEL__ */
8038 +#endif /* __AUFS_DEBUG_H__ */
8039 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8040 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8041 +++ linux/fs/aufs/dentry.c 2017-11-12 22:24:44.704244405 +0100
8044 + * Copyright (C) 2005-2017 Junjiro R. Okajima
8046 + * This program, aufs is free software; you can redistribute it and/or modify
8047 + * it under the terms of the GNU General Public License as published by
8048 + * the Free Software Foundation; either version 2 of the License, or
8049 + * (at your option) any later version.
8051 + * This program is distributed in the hope that it will be useful,
8052 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8053 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8054 + * GNU General Public License for more details.
8056 + * You should have received a copy of the GNU General Public License
8057 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8061 + * lookup and dentry operations
8064 +#include <linux/namei.h>
8068 + * returns positive/negative dentry, NULL or an error.
8069 + * NULL means whiteout-ed or not-found.
8071 +static struct dentry*
8072 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8073 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8075 + struct dentry *h_dentry;
8076 + struct inode *h_inode;
8077 + struct au_branch *br;
8078 + int wh_found, opq;
8079 + unsigned char wh_able;
8080 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8081 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8085 + br = au_sbr(dentry->d_sb, bindex);
8086 + wh_able = !!au_br_whable(br->br_perm);
8088 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8089 + h_dentry = ERR_PTR(wh_found);
8092 + if (unlikely(wh_found < 0))
8095 + /* We found a whiteout */
8096 + /* au_set_dbbot(dentry, bindex); */
8097 + au_set_dbwh(dentry, bindex);
8099 + return NULL; /* success */
8103 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8105 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8106 + if (IS_ERR(h_dentry)) {
8107 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8113 + h_inode = d_inode(h_dentry);
8114 + if (d_is_negative(h_dentry)) {
8117 + } else if (wh_found
8118 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8120 + else if (au_ftest_lkup(args->flags, DIRREN)
8122 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8123 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8124 + (unsigned long long)h_inode->i_ino);
8128 + if (au_dbbot(dentry) <= bindex)
8129 + au_set_dbbot(dentry, bindex);
8130 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8131 + au_set_dbtop(dentry, bindex);
8132 + au_set_h_dptr(dentry, bindex, h_dentry);
8134 + if (!d_is_dir(h_dentry)
8136 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8137 + goto out; /* success */
8139 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8140 + opq = au_diropq_test(h_dentry);
8141 + inode_unlock_shared(h_inode);
8143 + au_set_dbdiropq(dentry, bindex);
8144 + else if (unlikely(opq < 0)) {
8145 + au_set_h_dptr(dentry, bindex, NULL);
8146 + h_dentry = ERR_PTR(opq);
8157 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8159 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8160 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8166 + * returns the number of lower positive dentries,
8167 + * otherwise an error.
8168 + * can be called at unlinking with @type is zero.
8170 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8171 + unsigned int flags)
8173 + int npositive, err;
8174 + aufs_bindex_t bindex, btail, bdiropq;
8175 + unsigned char isdir, dirperm1, dirren;
8176 + struct au_do_lookup_args args = {
8178 + .name = &dentry->d_name
8180 + struct dentry *parent;
8181 + struct super_block *sb;
8183 + sb = dentry->d_sb;
8184 + err = au_test_shwh(sb, args.name);
8185 + if (unlikely(err))
8188 + err = au_wh_name_alloc(&args.whname, args.name);
8189 + if (unlikely(err))
8192 + isdir = !!d_is_dir(dentry);
8193 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8194 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8196 + au_fset_lkup(args.flags, DIRREN);
8199 + parent = dget_parent(dentry);
8200 + btail = au_dbtaildir(parent);
8201 + for (bindex = btop; bindex <= btail; bindex++) {
8202 + struct dentry *h_parent, *h_dentry;
8203 + struct inode *h_inode, *h_dir;
8204 + struct au_branch *br;
8206 + h_dentry = au_h_dptr(dentry, bindex);
8208 + if (d_is_positive(h_dentry))
8212 + h_parent = au_h_dptr(parent, bindex);
8213 + if (!h_parent || !d_is_dir(h_parent))
8217 + /* if the inum matches, then use the prepared name */
8218 + err = au_dr_lkup_name(&args, bindex);
8219 + if (unlikely(err))
8223 + h_dir = d_inode(h_parent);
8224 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8225 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8226 + inode_unlock_shared(h_dir);
8227 + err = PTR_ERR(h_dentry);
8228 + if (IS_ERR(h_dentry))
8231 + au_fclr_lkup(args.flags, ALLOW_NEG);
8233 + au_fset_lkup(args.flags, IGNORE_PERM);
8235 + if (au_dbwh(dentry) == bindex)
8239 + if (d_is_negative(h_dentry))
8241 + h_inode = d_inode(h_dentry);
8244 + args.type = h_inode->i_mode & S_IFMT;
8245 + if (args.type != S_IFDIR)
8248 + /* the type of lower may be different */
8249 + bdiropq = au_dbdiropq(dentry);
8250 + if (bdiropq >= 0 && bdiropq <= bindex)
8253 + br = au_sbr(sb, bindex);
8255 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8256 + /*add_ent*/NULL)) {
8257 + /* prepare next name to lookup */
8258 + err = au_dr_lkup(&args, dentry, bindex);
8259 + if (unlikely(err))
8265 + AuLabel(positive);
8266 + au_update_dbtop(dentry);
8269 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8270 + && au_dbtop(dentry) < 0)) {
8272 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8278 + kfree(args.whname.name);
8280 + au_dr_lkup_fin(&args);
8285 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8287 + struct dentry *dentry;
8290 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8291 + dentry = vfsub_lkup_one(name, parent);
8293 + struct vfsub_lkup_one_args args = {
8299 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8300 + if (unlikely(wkq_err))
8301 + dentry = ERR_PTR(wkq_err);
8308 + * lookup @dentry on @bindex which should be negative.
8310 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8313 + struct dentry *parent, *h_parent, *h_dentry;
8314 + struct au_branch *br;
8316 + parent = dget_parent(dentry);
8317 + h_parent = au_h_dptr(parent, bindex);
8318 + br = au_sbr(dentry->d_sb, bindex);
8320 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8322 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8323 + err = PTR_ERR(h_dentry);
8324 + if (IS_ERR(h_dentry))
8326 + if (unlikely(d_is_positive(h_dentry))) {
8328 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8334 + if (bindex < au_dbtop(dentry))
8335 + au_set_dbtop(dentry, bindex);
8336 + if (au_dbbot(dentry) < bindex)
8337 + au_set_dbbot(dentry, bindex);
8338 + au_set_h_dptr(dentry, bindex, h_dentry);
8345 +/* ---------------------------------------------------------------------- */
8347 +/* subset of struct inode */
8349 + unsigned long i_ino;
8350 + /* unsigned int i_nlink; */
8356 + blkcnt_t i_blocks;
8361 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8363 + ia->i_ino = h_inode->i_ino;
8364 + /* ia->i_nlink = h_inode->i_nlink; */
8365 + ia->i_uid = h_inode->i_uid;
8366 + ia->i_gid = h_inode->i_gid;
8367 + ia->i_version = h_inode->i_version;
8369 + ia->i_size = h_inode->i_size;
8370 + ia->i_blocks = h_inode->i_blocks;
8372 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8375 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8377 + return ia->i_ino != h_inode->i_ino
8378 + /* || ia->i_nlink != h_inode->i_nlink */
8379 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8380 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8381 + || ia->i_version != h_inode->i_version
8383 + || ia->i_size != h_inode->i_size
8384 + || ia->i_blocks != h_inode->i_blocks
8386 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8389 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8390 + struct au_branch *br)
8393 + struct au_iattr ia;
8394 + struct inode *h_inode;
8395 + struct dentry *h_d;
8396 + struct super_block *h_sb;
8399 + memset(&ia, -1, sizeof(ia));
8400 + h_sb = h_dentry->d_sb;
8402 + if (d_is_positive(h_dentry)) {
8403 + h_inode = d_inode(h_dentry);
8404 + au_iattr_save(&ia, h_inode);
8405 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8406 + /* nfs d_revalidate may return 0 for negative dentry */
8407 + /* fuse d_revalidate always return 0 for negative dentry */
8410 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8411 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8412 + err = PTR_ERR(h_d);
8417 + if (unlikely(h_d != h_dentry
8418 + || d_inode(h_d) != h_inode
8419 + || (h_inode && au_iattr_test(&ia, h_inode))))
8420 + err = au_busy_or_stale();
8428 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8429 + struct dentry *h_parent, struct au_branch *br)
8434 + if (udba == AuOpt_UDBA_REVAL
8435 + && !au_test_fs_remote(h_dentry->d_sb)) {
8437 + err = (d_inode(h_dentry->d_parent) != h_dir);
8438 + } else if (udba != AuOpt_UDBA_NONE)
8439 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8444 +/* ---------------------------------------------------------------------- */
8446 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8449 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8450 + struct au_hdentry tmp, *p, *q;
8451 + struct au_dinfo *dinfo;
8452 + struct super_block *sb;
8454 + DiMustWriteLock(dentry);
8456 + sb = dentry->d_sb;
8457 + dinfo = au_di(dentry);
8458 + bbot = dinfo->di_bbot;
8459 + bwh = dinfo->di_bwh;
8460 + bdiropq = dinfo->di_bdiropq;
8461 + bindex = dinfo->di_btop;
8462 + p = au_hdentry(dinfo, bindex);
8463 + for (; bindex <= bbot; bindex++, p++) {
8464 + if (!p->hd_dentry)
8467 + new_bindex = au_br_index(sb, p->hd_id);
8468 + if (new_bindex == bindex)
8471 + if (dinfo->di_bwh == bindex)
8473 + if (dinfo->di_bdiropq == bindex)
8474 + bdiropq = new_bindex;
8475 + if (new_bindex < 0) {
8477 + p->hd_dentry = NULL;
8481 + /* swap two lower dentries, and loop again */
8482 + q = au_hdentry(dinfo, new_bindex);
8486 + if (tmp.hd_dentry) {
8492 + dinfo->di_bwh = -1;
8493 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8494 + dinfo->di_bwh = bwh;
8496 + dinfo->di_bdiropq = -1;
8498 + && bdiropq <= au_sbbot(sb)
8499 + && au_sbr_whable(sb, bdiropq))
8500 + dinfo->di_bdiropq = bdiropq;
8503 + dinfo->di_btop = -1;
8504 + dinfo->di_bbot = -1;
8505 + bbot = au_dbbot(parent);
8507 + p = au_hdentry(dinfo, bindex);
8508 + for (; bindex <= bbot; bindex++, p++)
8509 + if (p->hd_dentry) {
8510 + dinfo->di_btop = bindex;
8514 + if (dinfo->di_btop >= 0) {
8516 + p = au_hdentry(dinfo, bindex);
8517 + for (; bindex >= 0; bindex--, p--)
8518 + if (p->hd_dentry) {
8519 + dinfo->di_bbot = bindex;
8528 +static void au_do_hide(struct dentry *dentry)
8530 + struct inode *inode;
8532 + if (d_really_is_positive(dentry)) {
8533 + inode = d_inode(dentry);
8534 + if (!d_is_dir(dentry)) {
8535 + if (inode->i_nlink && !d_unhashed(dentry))
8536 + drop_nlink(inode);
8538 + clear_nlink(inode);
8539 + /* stop next lookup */
8540 + inode->i_flags |= S_DEAD;
8542 + smp_mb(); /* necessary? */
8547 +static int au_hide_children(struct dentry *parent)
8549 + int err, i, j, ndentry;
8550 + struct au_dcsub_pages dpages;
8551 + struct au_dpage *dpage;
8552 + struct dentry *dentry;
8554 + err = au_dpages_init(&dpages, GFP_NOFS);
8555 + if (unlikely(err))
8557 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8558 + if (unlikely(err))
8561 + /* in reverse order */
8562 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8563 + dpage = dpages.dpages + i;
8564 + ndentry = dpage->ndentry;
8565 + for (j = ndentry - 1; j >= 0; j--) {
8566 + dentry = dpage->dentries[j];
8567 + if (dentry != parent)
8568 + au_do_hide(dentry);
8573 + au_dpages_free(&dpages);
8578 +static void au_hide(struct dentry *dentry)
8582 + AuDbgDentry(dentry);
8583 + if (d_is_dir(dentry)) {
8584 + /* shrink_dcache_parent(dentry); */
8585 + err = au_hide_children(dentry);
8586 + if (unlikely(err))
8587 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8590 + au_do_hide(dentry);
8594 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8596 + * a dirty branch is added
8597 + * - on the top of layers
8598 + * - in the middle of layers
8599 + * - to the bottom of layers
8601 + * on the added branch there exists
8604 + * - a same named entry
8606 + * * negative --> positive
8607 + * * positive --> positive
8608 + * - type is unchanged
8609 + * - type is changed
8611 + * * negative --> negative
8612 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8615 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8616 + struct au_dinfo *tmp)
8619 + aufs_bindex_t bindex, bbot;
8621 + struct dentry *dentry;
8622 + struct inode *inode;
8624 + } orig_h, tmp_h = {
8627 + struct au_hdentry *hd;
8628 + struct inode *inode, *h_inode;
8629 + struct dentry *h_dentry;
8632 + AuDebugOn(dinfo->di_btop < 0);
8634 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8635 + orig_h.inode = NULL;
8636 + if (d_is_positive(orig_h.dentry)) {
8637 + orig_h.inode = d_inode(orig_h.dentry);
8638 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8640 + if (tmp->di_btop >= 0) {
8641 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8642 + if (d_is_positive(tmp_h.dentry)) {
8643 + tmp_h.inode = d_inode(tmp_h.dentry);
8644 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8649 + if (d_really_is_positive(dentry))
8650 + inode = d_inode(dentry);
8651 + if (!orig_h.inode) {
8652 + AuDbg("nagative originally\n");
8658 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8659 + AuDebugOn(dinfo->di_bdiropq != -1);
8661 + if (!tmp_h.inode) {
8662 + AuDbg("negative --> negative\n");
8663 + /* should have only one negative lower */
8664 + if (tmp->di_btop >= 0
8665 + && tmp->di_btop < dinfo->di_btop) {
8666 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8667 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8668 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8669 + au_di_cp(dinfo, tmp);
8670 + hd = au_hdentry(tmp, tmp->di_btop);
8671 + au_set_h_dptr(dentry, tmp->di_btop,
8672 + dget(hd->hd_dentry));
8674 + au_dbg_verify_dinode(dentry);
8676 + AuDbg("negative --> positive\n");
8678 + * similar to the behaviour of creating with bypassing
8680 + * unhash it in order to force an error in the
8681 + * succeeding create operation.
8682 + * we should not set S_DEAD here.
8685 + /* au_di_swap(tmp, dinfo); */
8686 + au_dbg_verify_dinode(dentry);
8689 + AuDbg("positive originally\n");
8690 + /* inode may be NULL */
8691 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8692 + if (!tmp_h.inode) {
8693 + AuDbg("positive --> negative\n");
8694 + /* or bypassing aufs */
8696 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8697 + dinfo->di_bwh = tmp->di_bwh;
8699 + err = au_refresh_hinode_self(inode);
8700 + au_dbg_verify_dinode(dentry);
8701 + } else if (orig_h.mode == tmp_h.mode) {
8702 + AuDbg("positive --> positive, same type\n");
8703 + if (!S_ISDIR(orig_h.mode)
8704 + && dinfo->di_btop > tmp->di_btop) {
8706 + * similar to the behaviour of removing and
8711 + err = au_refresh_hinode_self(inode);
8712 + au_dbg_verify_dinode(dentry);
8714 + /* fill empty slots */
8715 + if (dinfo->di_btop > tmp->di_btop)
8716 + dinfo->di_btop = tmp->di_btop;
8717 + if (dinfo->di_bbot < tmp->di_bbot)
8718 + dinfo->di_bbot = tmp->di_bbot;
8719 + dinfo->di_bwh = tmp->di_bwh;
8720 + dinfo->di_bdiropq = tmp->di_bdiropq;
8721 + bbot = dinfo->di_bbot;
8722 + bindex = tmp->di_btop;
8723 + hd = au_hdentry(tmp, bindex);
8724 + for (; bindex <= bbot; bindex++, hd++) {
8725 + if (au_h_dptr(dentry, bindex))
8727 + h_dentry = hd->hd_dentry;
8730 + AuDebugOn(d_is_negative(h_dentry));
8731 + h_inode = d_inode(h_dentry);
8732 + AuDebugOn(orig_h.mode
8733 + != (h_inode->i_mode
8735 + au_set_h_dptr(dentry, bindex,
8739 + err = au_refresh_hinode(inode, dentry);
8740 + au_dbg_verify_dinode(dentry);
8743 + AuDbg("positive --> positive, different type\n");
8744 + /* similar to the behaviour of removing and creating */
8747 + err = au_refresh_hinode_self(inode);
8748 + au_dbg_verify_dinode(dentry);
8756 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8758 + const struct dentry_operations *dop
8759 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8760 + static const unsigned int mask
8761 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8763 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8765 + if (dentry->d_op == dop)
8768 + AuDbg("%pd\n", dentry);
8769 + spin_lock(&dentry->d_lock);
8770 + if (dop == &aufs_dop)
8771 + dentry->d_flags |= mask;
8773 + dentry->d_flags &= ~mask;
8774 + dentry->d_op = dop;
8775 + spin_unlock(&dentry->d_lock);
8778 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8780 + int err, ebrange, nbr;
8781 + unsigned int sigen;
8782 + struct au_dinfo *dinfo, *tmp;
8783 + struct super_block *sb;
8784 + struct inode *inode;
8786 + DiMustWriteLock(dentry);
8787 + AuDebugOn(IS_ROOT(dentry));
8788 + AuDebugOn(d_really_is_negative(parent));
8790 + sb = dentry->d_sb;
8791 + sigen = au_sigen(sb);
8792 + err = au_digen_test(parent, sigen);
8793 + if (unlikely(err))
8796 + nbr = au_sbbot(sb) + 1;
8797 + dinfo = au_di(dentry);
8798 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8799 + if (unlikely(err))
8801 + ebrange = au_dbrange_test(dentry);
8803 + ebrange = au_do_refresh_hdentry(dentry, parent);
8805 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8806 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8807 + if (d_really_is_positive(dentry)) {
8808 + inode = d_inode(dentry);
8809 + err = au_refresh_hinode_self(inode);
8811 + au_dbg_verify_dinode(dentry);
8813 + goto out_dgen; /* success */
8817 + /* temporary dinfo */
8818 + AuDbgDentry(dentry);
8820 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8821 + if (unlikely(!tmp))
8823 + au_di_swap(tmp, dinfo);
8824 + /* returns the number of positive dentries */
8826 + * if current working dir is removed, it returns an error.
8827 + * but the dentry is legal.
8829 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8830 + AuDbgDentry(dentry);
8831 + au_di_swap(tmp, dinfo);
8832 + if (err == -ENOENT)
8835 + /* compare/refresh by dinfo */
8836 + AuDbgDentry(dentry);
8837 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8838 + au_dbg_verify_dinode(dentry);
8841 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8842 + au_rw_write_unlock(&tmp->di_rwsem);
8844 + if (unlikely(err))
8848 + au_update_digen(dentry);
8850 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8851 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8852 + AuDbgDentry(dentry);
8858 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8859 + struct dentry *dentry, aufs_bindex_t bindex)
8864 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8867 + AuDbg("b%d\n", bindex);
8869 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8870 + * due to whiteout and branch permission.
8872 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8873 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8874 + /* it may return tri-state */
8875 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8877 + if (unlikely(valid < 0))
8887 +/* todo: remove this */
8888 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8889 + unsigned int flags, int do_udba, int dirren)
8892 + umode_t mode, h_mode;
8893 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8894 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8895 + struct inode *h_inode, *h_cached_inode;
8896 + struct dentry *h_dentry;
8897 + struct qstr *name, *h_name;
8904 + unhashed = !!d_unhashed(dentry);
8905 + is_root = !!IS_ROOT(dentry);
8906 + name = &dentry->d_name;
8907 + tmpfile = au_di(dentry)->di_tmpfile;
8910 + * Theoretically, REVAL test should be unnecessary in case of
8912 + * But {fs,i}notify doesn't fire some necessary events,
8913 + * IN_ATTRIB for atime/nlink/pageio
8914 + * Let's do REVAL test too.
8916 + if (do_udba && inode) {
8917 + mode = (inode->i_mode & S_IFMT);
8918 + plus = (inode->i_nlink > 0);
8919 + ibs = au_ibtop(inode);
8920 + ibe = au_ibbot(inode);
8923 + btop = au_dbtop(dentry);
8925 + if (inode && S_ISDIR(inode->i_mode))
8926 + btail = au_dbtaildir(dentry);
8927 + for (bindex = btop; bindex <= btail; bindex++) {
8928 + h_dentry = au_h_dptr(dentry, bindex);
8932 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8933 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8934 + spin_lock(&h_dentry->d_lock);
8935 + h_name = &h_dentry->d_name;
8936 + if (unlikely(do_udba
8939 + && (unhashed != !!d_unhashed(h_dentry)
8940 + || (!tmpfile && !dirren
8941 + && !au_qstreq(name, h_name))
8944 + && !(flags & LOOKUP_OPEN)
8945 + && (h_dentry->d_flags
8946 + & DCACHE_NFSFS_RENAMED)))
8950 + h_unhashed = d_unhashed(h_dentry);
8951 + spin_unlock(&h_dentry->d_lock);
8952 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8953 + unhashed, h_unhashed, dentry, h_dentry);
8956 + spin_unlock(&h_dentry->d_lock);
8958 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8959 + if (unlikely(err))
8960 + /* do not goto err, to keep the errno */
8963 + /* todo: plink too? */
8968 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8972 + if (d_is_positive(h_dentry))
8973 + h_inode = d_inode(h_dentry);
8976 + h_cached_inode = h_inode;
8978 + h_mode = (h_inode->i_mode & S_IFMT);
8979 + h_plus = (h_inode->i_nlink > 0);
8981 + if (inode && ibs <= bindex && bindex <= ibe)
8982 + h_cached_inode = au_h_iptr(inode, bindex);
8985 + if (unlikely(plus != h_plus && !tmpfile))
8988 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8990 + && !IS_ROOT(h_dentry)
8991 + && unhashed != d_unhashed(h_dentry)))
8994 + if (unlikely(mode != h_mode
8995 + || h_cached_inode != h_inode))
9008 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9009 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9012 + struct dentry *parent;
9014 + if (!au_digen_test(dentry, sigen))
9017 + parent = dget_parent(dentry);
9018 + di_read_lock_parent(parent, AuLock_IR);
9019 + AuDebugOn(au_digen_test(parent, sigen));
9020 + au_dbg_verify_gen(parent, sigen);
9021 + err = au_refresh_dentry(dentry, parent);
9022 + di_read_unlock(parent, AuLock_IR);
9028 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9031 + struct dentry *d, *parent;
9033 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9034 + return simple_reval_dpath(dentry, sigen);
9036 + /* slow loop, keep it simple and stupid */
9037 + /* cf: au_cpup_dirs() */
9040 + while (au_digen_test(dentry, sigen)) {
9044 + parent = dget_parent(d);
9045 + if (!au_digen_test(parent, sigen))
9051 + di_write_lock_child2(d);
9053 + /* someone might update our dentry while we were sleeping */
9054 + if (au_digen_test(d, sigen)) {
9056 + * todo: consolidate with simple_reval_dpath(),
9057 + * do_refresh() and au_reval_for_attr().
9059 + di_read_lock_parent(parent, AuLock_IR);
9060 + err = au_refresh_dentry(d, parent);
9061 + di_read_unlock(parent, AuLock_IR);
9065 + di_write_unlock(d);
9067 + if (unlikely(err))
9075 + * if valid returns 1, otherwise 0.
9077 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9080 + unsigned int sigen;
9081 + unsigned char do_udba, dirren;
9082 + struct super_block *sb;
9083 + struct inode *inode;
9085 + /* todo: support rcu-walk? */
9086 + if (flags & LOOKUP_RCU)
9090 + if (unlikely(!au_di(dentry)))
9094 + sb = dentry->d_sb;
9097 + * i_mutex of parent dir may be held,
9098 + * but we should not return 'invalid' due to busy.
9100 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9101 + if (unlikely(err)) {
9107 + if (d_really_is_positive(dentry))
9108 + inode = d_inode(dentry);
9109 + if (unlikely(inode && au_is_bad_inode(inode))) {
9114 + if (unlikely(au_dbrange_test(dentry))) {
9120 + sigen = au_sigen(sb);
9121 + if (au_digen_test(dentry, sigen)) {
9122 + AuDebugOn(IS_ROOT(dentry));
9123 + err = au_reval_dpath(dentry, sigen);
9124 + if (unlikely(err)) {
9129 + di_downgrade_lock(dentry, AuLock_IR);
9132 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9134 + && !(inode->i_state && I_LINKABLE)
9135 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9140 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9141 + if (do_udba && inode) {
9142 + aufs_bindex_t btop = au_ibtop(inode);
9143 + struct inode *h_inode;
9146 + h_inode = au_h_iptr(inode, btop);
9147 + if (h_inode && au_test_higen(inode, h_inode)) {
9154 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9155 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9156 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9158 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9164 + di_downgrade_lock(dentry, AuLock_IR);
9166 + aufs_read_unlock(dentry, AuLock_IR);
9171 + AuDbg("%pd invalid, %d\n", dentry, valid);
9177 +static void aufs_d_release(struct dentry *dentry)
9179 + if (au_di(dentry)) {
9180 + au_di_fin(dentry);
9181 + au_hn_di_reinit(dentry);
9185 +const struct dentry_operations aufs_dop = {
9186 + .d_revalidate = aufs_d_revalidate,
9187 + .d_weak_revalidate = aufs_d_revalidate,
9188 + .d_release = aufs_d_release
9191 +/* aufs_dop without d_revalidate */
9192 +const struct dentry_operations aufs_dop_noreval = {
9193 + .d_release = aufs_d_release
9195 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9196 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9197 +++ linux/fs/aufs/dentry.h 2017-11-12 22:24:44.704244405 +0100
9200 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9202 + * This program, aufs is free software; you can redistribute it and/or modify
9203 + * it under the terms of the GNU General Public License as published by
9204 + * the Free Software Foundation; either version 2 of the License, or
9205 + * (at your option) any later version.
9207 + * This program is distributed in the hope that it will be useful,
9208 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9209 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9210 + * GNU General Public License for more details.
9212 + * You should have received a copy of the GNU General Public License
9213 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9217 + * lookup and dentry operations
9220 +#ifndef __AUFS_DENTRY_H__
9221 +#define __AUFS_DENTRY_H__
9225 +#include <linux/dcache.h>
9226 +#include "dirren.h"
9229 +struct au_hdentry {
9230 + struct dentry *hd_dentry;
9231 + aufs_bindex_t hd_id;
9235 + atomic_t di_generation;
9237 + struct au_rwsem di_rwsem;
9238 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9239 + unsigned char di_tmpfile; /* to allow the different name */
9240 + struct au_hdentry *di_hdentry;
9241 +} ____cacheline_aligned_in_smp;
9243 +/* ---------------------------------------------------------------------- */
9245 +/* flags for au_lkup_dentry() */
9246 +#define AuLkup_ALLOW_NEG 1
9247 +#define AuLkup_IGNORE_PERM (1 << 1)
9248 +#define AuLkup_DIRREN (1 << 2)
9249 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9250 +#define au_fset_lkup(flags, name) \
9251 + do { (flags) |= AuLkup_##name; } while (0)
9252 +#define au_fclr_lkup(flags, name) \
9253 + do { (flags) &= ~AuLkup_##name; } while (0)
9255 +#ifndef CONFIG_AUFS_DIRREN
9256 +#undef AuLkup_DIRREN
9257 +#define AuLkup_DIRREN 0
9260 +struct au_do_lookup_args {
9261 + unsigned int flags;
9263 + struct qstr whname, *name;
9264 + struct au_dr_lookup dirren;
9267 +/* ---------------------------------------------------------------------- */
9270 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9272 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9273 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9274 + struct dentry *h_parent, struct au_branch *br);
9276 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9277 + unsigned int flags);
9278 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9279 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9280 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9281 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9284 +void au_di_init_once(void *_di);
9285 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9286 +void au_di_free(struct au_dinfo *dinfo);
9287 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9288 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9289 +int au_di_init(struct dentry *dentry);
9290 +void au_di_fin(struct dentry *dentry);
9291 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9293 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9294 +void di_read_unlock(struct dentry *d, int flags);
9295 +void di_downgrade_lock(struct dentry *d, int flags);
9296 +void di_write_lock(struct dentry *d, unsigned int lsc);
9297 +void di_write_unlock(struct dentry *d);
9298 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9299 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9300 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9302 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9303 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9304 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9305 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9307 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9308 + struct dentry *h_dentry);
9309 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9310 +int au_dbrange_test(struct dentry *dentry);
9311 +void au_update_digen(struct dentry *dentry);
9312 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9313 +void au_update_dbtop(struct dentry *dentry);
9314 +void au_update_dbbot(struct dentry *dentry);
9315 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9317 +/* ---------------------------------------------------------------------- */
9319 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9321 + return dentry->d_fsdata;
9324 +/* ---------------------------------------------------------------------- */
9326 +/* lock subclass for dinfo */
9328 + AuLsc_DI_CHILD, /* child first */
9329 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9330 + AuLsc_DI_CHILD3, /* copyup dirs */
9334 + AuLsc_DI_TMP /* temp for replacing dinfo */
9338 + * di_read_lock_child, di_write_lock_child,
9339 + * di_read_lock_child2, di_write_lock_child2,
9340 + * di_read_lock_child3, di_write_lock_child3,
9341 + * di_read_lock_parent, di_write_lock_parent,
9342 + * di_read_lock_parent2, di_write_lock_parent2,
9343 + * di_read_lock_parent3, di_write_lock_parent3,
9345 +#define AuReadLockFunc(name, lsc) \
9346 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9347 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9349 +#define AuWriteLockFunc(name, lsc) \
9350 +static inline void di_write_lock_##name(struct dentry *d) \
9351 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9353 +#define AuRWLockFuncs(name, lsc) \
9354 + AuReadLockFunc(name, lsc) \
9355 + AuWriteLockFunc(name, lsc)
9357 +AuRWLockFuncs(child, CHILD);
9358 +AuRWLockFuncs(child2, CHILD2);
9359 +AuRWLockFuncs(child3, CHILD3);
9360 +AuRWLockFuncs(parent, PARENT);
9361 +AuRWLockFuncs(parent2, PARENT2);
9362 +AuRWLockFuncs(parent3, PARENT3);
9364 +#undef AuReadLockFunc
9365 +#undef AuWriteLockFunc
9366 +#undef AuRWLockFuncs
9368 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9369 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9370 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9372 +/* ---------------------------------------------------------------------- */
9374 +/* todo: memory barrier? */
9375 +static inline unsigned int au_digen(struct dentry *d)
9377 + return atomic_read(&au_di(d)->di_generation);
9380 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9382 + hdentry->hd_dentry = NULL;
9385 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9386 + aufs_bindex_t bindex)
9388 + return di->di_hdentry + bindex;
9391 +static inline void au_hdput(struct au_hdentry *hd)
9394 + dput(hd->hd_dentry);
9397 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9399 + DiMustAnyLock(dentry);
9400 + return au_di(dentry)->di_btop;
9403 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9405 + DiMustAnyLock(dentry);
9406 + return au_di(dentry)->di_bbot;
9409 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9411 + DiMustAnyLock(dentry);
9412 + return au_di(dentry)->di_bwh;
9415 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9417 + DiMustAnyLock(dentry);
9418 + return au_di(dentry)->di_bdiropq;
9421 +/* todo: hard/soft set? */
9422 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9424 + DiMustWriteLock(dentry);
9425 + au_di(dentry)->di_btop = bindex;
9428 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9430 + DiMustWriteLock(dentry);
9431 + au_di(dentry)->di_bbot = bindex;
9434 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9436 + DiMustWriteLock(dentry);
9437 + /* dbwh can be outside of btop - bbot range */
9438 + au_di(dentry)->di_bwh = bindex;
9441 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9443 + DiMustWriteLock(dentry);
9444 + au_di(dentry)->di_bdiropq = bindex;
9447 +/* ---------------------------------------------------------------------- */
9449 +#ifdef CONFIG_AUFS_HNOTIFY
9450 +static inline void au_digen_dec(struct dentry *d)
9452 + atomic_dec(&au_di(d)->di_generation);
9455 +static inline void au_hn_di_reinit(struct dentry *dentry)
9457 + dentry->d_fsdata = NULL;
9460 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9461 +#endif /* CONFIG_AUFS_HNOTIFY */
9463 +#endif /* __KERNEL__ */
9464 +#endif /* __AUFS_DENTRY_H__ */
9465 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9466 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9467 +++ linux/fs/aufs/dinfo.c 2017-11-12 22:24:42.267510077 +0100
9470 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9472 + * This program, aufs is free software; you can redistribute it and/or modify
9473 + * it under the terms of the GNU General Public License as published by
9474 + * the Free Software Foundation; either version 2 of the License, or
9475 + * (at your option) any later version.
9477 + * This program is distributed in the hope that it will be useful,
9478 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9479 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9480 + * GNU General Public License for more details.
9482 + * You should have received a copy of the GNU General Public License
9483 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9487 + * dentry private data
9492 +void au_di_init_once(void *_dinfo)
9494 + struct au_dinfo *dinfo = _dinfo;
9496 + au_rw_init(&dinfo->di_rwsem);
9499 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9501 + struct au_dinfo *dinfo;
9504 + dinfo = au_cache_alloc_dinfo();
9505 + if (unlikely(!dinfo))
9508 + nbr = au_sbbot(sb) + 1;
9511 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9512 + if (dinfo->di_hdentry) {
9513 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9514 + dinfo->di_btop = -1;
9515 + dinfo->di_bbot = -1;
9516 + dinfo->di_bwh = -1;
9517 + dinfo->di_bdiropq = -1;
9518 + dinfo->di_tmpfile = 0;
9519 + for (i = 0; i < nbr; i++)
9520 + dinfo->di_hdentry[i].hd_id = -1;
9524 + au_cache_free_dinfo(dinfo);
9531 +void au_di_free(struct au_dinfo *dinfo)
9533 + struct au_hdentry *p;
9534 + aufs_bindex_t bbot, bindex;
9536 + /* dentry may not be revalidated */
9537 + bindex = dinfo->di_btop;
9538 + if (bindex >= 0) {
9539 + bbot = dinfo->di_bbot;
9540 + p = au_hdentry(dinfo, bindex);
9541 + while (bindex++ <= bbot)
9544 + kfree(dinfo->di_hdentry);
9545 + au_cache_free_dinfo(dinfo);
9548 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9550 + struct au_hdentry *p;
9553 + AuRwMustWriteLock(&a->di_rwsem);
9554 + AuRwMustWriteLock(&b->di_rwsem);
9556 +#define DiSwap(v, name) \
9558 + v = a->di_##name; \
9559 + a->di_##name = b->di_##name; \
9560 + b->di_##name = v; \
9563 + DiSwap(p, hdentry);
9567 + DiSwap(bi, bdiropq);
9573 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9575 + AuRwMustWriteLock(&dst->di_rwsem);
9576 + AuRwMustWriteLock(&src->di_rwsem);
9578 + dst->di_btop = src->di_btop;
9579 + dst->di_bbot = src->di_bbot;
9580 + dst->di_bwh = src->di_bwh;
9581 + dst->di_bdiropq = src->di_bdiropq;
9585 +int au_di_init(struct dentry *dentry)
9588 + struct super_block *sb;
9589 + struct au_dinfo *dinfo;
9592 + sb = dentry->d_sb;
9593 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9595 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9596 + /* smp_mb(); */ /* atomic_set */
9597 + dentry->d_fsdata = dinfo;
9604 +void au_di_fin(struct dentry *dentry)
9606 + struct au_dinfo *dinfo;
9608 + dinfo = au_di(dentry);
9609 + AuRwDestroy(&dinfo->di_rwsem);
9610 + au_di_free(dinfo);
9613 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9616 + struct au_hdentry *hdp;
9618 + AuRwMustWriteLock(&dinfo->di_rwsem);
9621 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9623 + sz = sizeof(*hdp);
9624 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9627 + dinfo->di_hdentry = hdp;
9634 +/* ---------------------------------------------------------------------- */
9636 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9639 + case AuLsc_DI_CHILD:
9640 + ii_write_lock_child(inode);
9642 + case AuLsc_DI_CHILD2:
9643 + ii_write_lock_child2(inode);
9645 + case AuLsc_DI_CHILD3:
9646 + ii_write_lock_child3(inode);
9648 + case AuLsc_DI_PARENT:
9649 + ii_write_lock_parent(inode);
9651 + case AuLsc_DI_PARENT2:
9652 + ii_write_lock_parent2(inode);
9654 + case AuLsc_DI_PARENT3:
9655 + ii_write_lock_parent3(inode);
9662 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9665 + case AuLsc_DI_CHILD:
9666 + ii_read_lock_child(inode);
9668 + case AuLsc_DI_CHILD2:
9669 + ii_read_lock_child2(inode);
9671 + case AuLsc_DI_CHILD3:
9672 + ii_read_lock_child3(inode);
9674 + case AuLsc_DI_PARENT:
9675 + ii_read_lock_parent(inode);
9677 + case AuLsc_DI_PARENT2:
9678 + ii_read_lock_parent2(inode);
9680 + case AuLsc_DI_PARENT3:
9681 + ii_read_lock_parent3(inode);
9688 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9690 + struct inode *inode;
9692 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9693 + if (d_really_is_positive(d)) {
9694 + inode = d_inode(d);
9695 + if (au_ftest_lock(flags, IW))
9696 + do_ii_write_lock(inode, lsc);
9697 + else if (au_ftest_lock(flags, IR))
9698 + do_ii_read_lock(inode, lsc);
9702 +void di_read_unlock(struct dentry *d, int flags)
9704 + struct inode *inode;
9706 + if (d_really_is_positive(d)) {
9707 + inode = d_inode(d);
9708 + if (au_ftest_lock(flags, IW)) {
9709 + au_dbg_verify_dinode(d);
9710 + ii_write_unlock(inode);
9711 + } else if (au_ftest_lock(flags, IR)) {
9712 + au_dbg_verify_dinode(d);
9713 + ii_read_unlock(inode);
9716 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9719 +void di_downgrade_lock(struct dentry *d, int flags)
9721 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9722 + ii_downgrade_lock(d_inode(d));
9723 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9726 +void di_write_lock(struct dentry *d, unsigned int lsc)
9728 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9729 + if (d_really_is_positive(d))
9730 + do_ii_write_lock(d_inode(d), lsc);
9733 +void di_write_unlock(struct dentry *d)
9735 + au_dbg_verify_dinode(d);
9736 + if (d_really_is_positive(d))
9737 + ii_write_unlock(d_inode(d));
9738 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9741 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9743 + AuDebugOn(d1 == d2
9744 + || d_inode(d1) == d_inode(d2)
9745 + || d1->d_sb != d2->d_sb);
9747 + if ((isdir && au_test_subdir(d1, d2))
9749 + di_write_lock_child(d1);
9750 + di_write_lock_child2(d2);
9752 + di_write_lock_child(d2);
9753 + di_write_lock_child2(d1);
9757 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9759 + AuDebugOn(d1 == d2
9760 + || d_inode(d1) == d_inode(d2)
9761 + || d1->d_sb != d2->d_sb);
9763 + if ((isdir && au_test_subdir(d1, d2))
9765 + di_write_lock_parent(d1);
9766 + di_write_lock_parent2(d2);
9768 + di_write_lock_parent(d2);
9769 + di_write_lock_parent2(d1);
9773 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9775 + di_write_unlock(d1);
9776 + if (d_inode(d1) == d_inode(d2))
9777 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9779 + di_write_unlock(d2);
9782 +/* ---------------------------------------------------------------------- */
9784 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9788 + DiMustAnyLock(dentry);
9790 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9792 + AuDebugOn(bindex < 0);
9793 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9794 + AuDebugOn(d && au_dcount(d) <= 0);
9799 + * extended version of au_h_dptr().
9800 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9803 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9805 + struct dentry *h_dentry;
9806 + struct inode *inode, *h_inode;
9808 + AuDebugOn(d_really_is_negative(dentry));
9811 + if (au_dbtop(dentry) <= bindex
9812 + && bindex <= au_dbbot(dentry))
9813 + h_dentry = au_h_dptr(dentry, bindex);
9814 + if (h_dentry && !au_d_linkable(h_dentry)) {
9816 + goto out; /* success */
9819 + inode = d_inode(dentry);
9820 + AuDebugOn(bindex < au_ibtop(inode));
9821 + AuDebugOn(au_ibbot(inode) < bindex);
9822 + h_inode = au_h_iptr(inode, bindex);
9823 + h_dentry = d_find_alias(h_inode);
9825 + if (!IS_ERR(h_dentry)) {
9826 + if (!au_d_linkable(h_dentry))
9827 + goto out; /* success */
9833 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9834 + h_dentry = au_plink_lkup(inode, bindex);
9835 + AuDebugOn(!h_dentry);
9836 + if (!IS_ERR(h_dentry)) {
9837 + if (!au_d_hashed_positive(h_dentry))
9838 + goto out; /* success */
9845 + AuDbgDentry(h_dentry);
9849 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9851 + aufs_bindex_t bbot, bwh;
9853 + bbot = au_dbbot(dentry);
9855 + bwh = au_dbwh(dentry);
9858 + if (0 < bwh && bwh < bbot)
9864 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9866 + aufs_bindex_t bbot, bopq;
9868 + bbot = au_dbtail(dentry);
9870 + bopq = au_dbdiropq(dentry);
9871 + if (0 <= bopq && bopq < bbot)
9877 +/* ---------------------------------------------------------------------- */
9879 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9880 + struct dentry *h_dentry)
9882 + struct au_dinfo *dinfo;
9883 + struct au_hdentry *hd;
9884 + struct au_branch *br;
9886 + DiMustWriteLock(dentry);
9888 + dinfo = au_di(dentry);
9889 + hd = au_hdentry(dinfo, bindex);
9891 + hd->hd_dentry = h_dentry;
9893 + br = au_sbr(dentry->d_sb, bindex);
9894 + hd->hd_id = br->br_id;
9898 +int au_dbrange_test(struct dentry *dentry)
9901 + aufs_bindex_t btop, bbot;
9904 + btop = au_dbtop(dentry);
9905 + bbot = au_dbbot(dentry);
9907 + AuDebugOn(bbot < 0 && btop > bbot);
9910 + AuDebugOn(bbot >= 0);
9916 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9921 + if (unlikely(au_digen(dentry) != sigen
9922 + || au_iigen_test(d_inode(dentry), sigen)))
9928 +void au_update_digen(struct dentry *dentry)
9930 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9931 + /* smp_mb(); */ /* atomic_set */
9934 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9936 + struct au_dinfo *dinfo;
9937 + struct dentry *h_d;
9938 + struct au_hdentry *hdp;
9939 + aufs_bindex_t bindex, bbot;
9941 + DiMustWriteLock(dentry);
9943 + dinfo = au_di(dentry);
9944 + if (!dinfo || dinfo->di_btop < 0)
9947 + if (do_put_zero) {
9948 + bbot = dinfo->di_bbot;
9949 + bindex = dinfo->di_btop;
9950 + hdp = au_hdentry(dinfo, bindex);
9951 + for (; bindex <= bbot; bindex++, hdp++) {
9952 + h_d = hdp->hd_dentry;
9953 + if (h_d && d_is_negative(h_d))
9954 + au_set_h_dptr(dentry, bindex, NULL);
9958 + dinfo->di_btop = 0;
9959 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9960 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9961 + if (hdp->hd_dentry)
9963 + if (dinfo->di_btop > dinfo->di_bbot) {
9964 + dinfo->di_btop = -1;
9965 + dinfo->di_bbot = -1;
9969 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9970 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9971 + if (hdp->hd_dentry)
9973 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9976 +void au_update_dbtop(struct dentry *dentry)
9978 + aufs_bindex_t bindex, bbot;
9979 + struct dentry *h_dentry;
9981 + bbot = au_dbbot(dentry);
9982 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9983 + h_dentry = au_h_dptr(dentry, bindex);
9986 + if (d_is_positive(h_dentry)) {
9987 + au_set_dbtop(dentry, bindex);
9990 + au_set_h_dptr(dentry, bindex, NULL);
9994 +void au_update_dbbot(struct dentry *dentry)
9996 + aufs_bindex_t bindex, btop;
9997 + struct dentry *h_dentry;
9999 + btop = au_dbtop(dentry);
10000 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10001 + h_dentry = au_h_dptr(dentry, bindex);
10004 + if (d_is_positive(h_dentry)) {
10005 + au_set_dbbot(dentry, bindex);
10008 + au_set_h_dptr(dentry, bindex, NULL);
10012 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10014 + aufs_bindex_t bindex, bbot;
10016 + bbot = au_dbbot(dentry);
10017 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10018 + if (au_h_dptr(dentry, bindex) == h_dentry)
10022 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10023 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10024 +++ linux/fs/aufs/dir.c 2017-11-12 22:24:44.704244405 +0100
10027 + * Copyright (C) 2005-2017 Junjiro R. Okajima
10029 + * This program, aufs is free software; you can redistribute it and/or modify
10030 + * it under the terms of the GNU General Public License as published by
10031 + * the Free Software Foundation; either version 2 of the License, or
10032 + * (at your option) any later version.
10034 + * This program is distributed in the hope that it will be useful,
10035 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10036 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10037 + * GNU General Public License for more details.
10039 + * You should have received a copy of the GNU General Public License
10040 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10044 + * directory operations
10047 +#include <linux/fs_stack.h>
10050 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10052 + unsigned int nlink;
10054 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10056 + nlink = dir->i_nlink;
10057 + nlink += h_dir->i_nlink - 2;
10058 + if (h_dir->i_nlink < 2)
10060 + smp_mb(); /* for i_nlink */
10061 + /* 0 can happen in revaliding */
10062 + set_nlink(dir, nlink);
10065 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10067 + unsigned int nlink;
10069 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10071 + nlink = dir->i_nlink;
10072 + nlink -= h_dir->i_nlink - 2;
10073 + if (h_dir->i_nlink < 2)
10075 + smp_mb(); /* for i_nlink */
10076 + /* nlink == 0 means the branch-fs is broken */
10077 + set_nlink(dir, nlink);
10080 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10083 + aufs_bindex_t bindex, bbot;
10084 + struct file *h_file;
10085 + struct dentry *h_dentry;
10089 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10091 + bbot = au_fbbot_dir(file);
10092 + for (bindex = au_fbtop(file);
10093 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10095 + h_file = au_hf_dir(file, bindex);
10096 + if (h_file && file_inode(h_file))
10097 + sz += vfsub_f_size_read(h_file);
10100 + AuDebugOn(!dentry);
10101 + AuDebugOn(!d_is_dir(dentry));
10103 + bbot = au_dbtaildir(dentry);
10104 + for (bindex = au_dbtop(dentry);
10105 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10107 + h_dentry = au_h_dptr(dentry, bindex);
10108 + if (h_dentry && d_is_positive(h_dentry))
10109 + sz += i_size_read(d_inode(h_dentry));
10112 + if (sz < KMALLOC_MAX_SIZE)
10113 + sz = roundup_pow_of_two(sz);
10114 + if (sz > KMALLOC_MAX_SIZE)
10115 + sz = KMALLOC_MAX_SIZE;
10116 + else if (sz < NAME_MAX) {
10117 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10118 + sz = AUFS_RDBLK_DEF;
10123 +struct au_dir_ts_arg {
10124 + struct dentry *dentry;
10125 + aufs_bindex_t brid;
10128 +static void au_do_dir_ts(void *arg)
10130 + struct au_dir_ts_arg *a = arg;
10131 + struct au_dtime dt;
10132 + struct path h_path;
10133 + struct inode *dir, *h_dir;
10134 + struct super_block *sb;
10135 + struct au_branch *br;
10136 + struct au_hinode *hdir;
10138 + aufs_bindex_t btop, bindex;
10140 + sb = a->dentry->d_sb;
10141 + if (d_really_is_negative(a->dentry))
10143 + /* no dir->i_mutex lock */
10144 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10146 + dir = d_inode(a->dentry);
10147 + btop = au_ibtop(dir);
10148 + bindex = au_br_index(sb, a->brid);
10149 + if (bindex < btop)
10152 + br = au_sbr(sb, bindex);
10153 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10154 + if (!h_path.dentry)
10156 + h_path.mnt = au_br_mnt(br);
10157 + au_dtime_store(&dt, a->dentry, &h_path);
10159 + br = au_sbr(sb, btop);
10160 + if (!au_br_writable(br->br_perm))
10162 + h_path.dentry = au_h_dptr(a->dentry, btop);
10163 + h_path.mnt = au_br_mnt(br);
10164 + err = vfsub_mnt_want_write(h_path.mnt);
10167 + hdir = au_hi(dir, btop);
10168 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10169 + h_dir = au_h_iptr(dir, btop);
10170 + if (h_dir->i_nlink
10171 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10172 + dt.dt_h_path = h_path;
10173 + au_dtime_revert(&dt);
10175 + au_hn_inode_unlock(hdir);
10176 + vfsub_mnt_drop_write(h_path.mnt);
10177 + au_cpup_attr_timesizes(dir);
10180 + aufs_read_unlock(a->dentry, AuLock_DW);
10183 + au_nwt_done(&au_sbi(sb)->si_nowait);
10187 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10189 + int perm, wkq_err;
10190 + aufs_bindex_t btop;
10191 + struct au_dir_ts_arg *arg;
10192 + struct dentry *dentry;
10193 + struct super_block *sb;
10197 + dentry = d_find_any_alias(dir);
10198 + AuDebugOn(!dentry);
10199 + sb = dentry->d_sb;
10200 + btop = au_ibtop(dir);
10201 + if (btop == bindex) {
10202 + au_cpup_attr_timesizes(dir);
10206 + perm = au_sbr_perm(sb, btop);
10207 + if (!au_br_writable(perm))
10210 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10214 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10215 + arg->brid = au_sbr_id(sb, bindex);
10216 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10217 + if (unlikely(wkq_err)) {
10218 + pr_err("wkq %d\n", wkq_err);
10227 +/* ---------------------------------------------------------------------- */
10229 +static int reopen_dir(struct file *file)
10232 + unsigned int flags;
10233 + aufs_bindex_t bindex, btail, btop;
10234 + struct dentry *dentry, *h_dentry;
10235 + struct file *h_file;
10237 + /* open all lower dirs */
10238 + dentry = file->f_path.dentry;
10239 + btop = au_dbtop(dentry);
10240 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10241 + au_set_h_fptr(file, bindex, NULL);
10242 + au_set_fbtop(file, btop);
10244 + btail = au_dbtaildir(dentry);
10245 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10246 + au_set_h_fptr(file, bindex, NULL);
10247 + au_set_fbbot_dir(file, btail);
10249 + flags = vfsub_file_flags(file);
10250 + for (bindex = btop; bindex <= btail; bindex++) {
10251 + h_dentry = au_h_dptr(dentry, bindex);
10254 + h_file = au_hf_dir(file, bindex);
10258 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10259 + err = PTR_ERR(h_file);
10260 + if (IS_ERR(h_file))
10261 + goto out; /* close all? */
10262 + au_set_h_fptr(file, bindex, h_file);
10264 + au_update_figen(file);
10265 + /* todo: necessary? */
10266 + /* file->f_ra = h_file->f_ra; */
10273 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10276 + aufs_bindex_t bindex, btail;
10277 + struct dentry *dentry, *h_dentry;
10278 + struct vfsmount *mnt;
10280 + FiMustWriteLock(file);
10281 + AuDebugOn(h_file);
10284 + mnt = file->f_path.mnt;
10285 + dentry = file->f_path.dentry;
10286 + file->f_version = d_inode(dentry)->i_version;
10287 + bindex = au_dbtop(dentry);
10288 + au_set_fbtop(file, bindex);
10289 + btail = au_dbtaildir(dentry);
10290 + au_set_fbbot_dir(file, btail);
10291 + for (; !err && bindex <= btail; bindex++) {
10292 + h_dentry = au_h_dptr(dentry, bindex);
10296 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10297 + if (unlikely(err))
10299 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10300 + if (IS_ERR(h_file)) {
10301 + err = PTR_ERR(h_file);
10304 + au_set_h_fptr(file, bindex, h_file);
10306 + au_update_figen(file);
10307 + /* todo: necessary? */
10308 + /* file->f_ra = h_file->f_ra; */
10310 + return 0; /* success */
10313 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10314 + au_set_h_fptr(file, bindex, NULL);
10315 + au_set_fbtop(file, -1);
10316 + au_set_fbbot_dir(file, -1);
10321 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10322 + struct file *file)
10325 + struct super_block *sb;
10326 + struct au_fidir *fidir;
10329 + sb = file->f_path.dentry->d_sb;
10330 + si_read_lock(sb, AuLock_FLUSH);
10331 + fidir = au_fidir_alloc(sb);
10333 + struct au_do_open_args args = {
10334 + .open = do_open_dir,
10337 + err = au_do_open(file, &args);
10338 + if (unlikely(err))
10341 + si_read_unlock(sb);
10345 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10346 + struct file *file)
10348 + struct au_vdir *vdir_cache;
10349 + struct au_finfo *finfo;
10350 + struct au_fidir *fidir;
10351 + struct au_hfile *hf;
10352 + aufs_bindex_t bindex, bbot;
10354 + finfo = au_fi(file);
10355 + fidir = finfo->fi_hdir;
10357 + au_hbl_del(&finfo->fi_hlist,
10358 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10359 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10361 + au_vdir_free(vdir_cache);
10363 + bindex = finfo->fi_btop;
10364 + if (bindex >= 0) {
10365 + hf = fidir->fd_hfile + bindex;
10367 + * calls fput() instead of filp_close(),
10368 + * since no dnotify or lock for the lower file.
10370 + bbot = fidir->fd_bbot;
10371 + for (; bindex <= bbot; bindex++, hf++)
10373 + au_hfput(hf, /*execed*/0);
10376 + finfo->fi_hdir = NULL;
10378 + au_finfo_fin(file);
10382 +/* ---------------------------------------------------------------------- */
10384 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10387 + aufs_bindex_t bindex, bbot;
10388 + struct file *h_file;
10391 + bbot = au_fbbot_dir(file);
10392 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10393 + h_file = au_hf_dir(file, bindex);
10395 + err = vfsub_flush(h_file, id);
10400 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10402 + return au_do_flush(file, id, au_do_flush_dir);
10405 +/* ---------------------------------------------------------------------- */
10407 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10410 + aufs_bindex_t bbot, bindex;
10411 + struct inode *inode;
10412 + struct super_block *sb;
10415 + sb = dentry->d_sb;
10416 + inode = d_inode(dentry);
10417 + IMustLock(inode);
10418 + bbot = au_dbbot(dentry);
10419 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10420 + struct path h_path;
10422 + if (au_test_ro(sb, bindex, inode))
10424 + h_path.dentry = au_h_dptr(dentry, bindex);
10425 + if (!h_path.dentry)
10428 + h_path.mnt = au_sbr_mnt(sb, bindex);
10429 + err = vfsub_fsync(NULL, &h_path, datasync);
10435 +static int au_do_fsync_dir(struct file *file, int datasync)
10438 + aufs_bindex_t bbot, bindex;
10439 + struct file *h_file;
10440 + struct super_block *sb;
10441 + struct inode *inode;
10443 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10444 + if (unlikely(err))
10447 + inode = file_inode(file);
10448 + sb = inode->i_sb;
10449 + bbot = au_fbbot_dir(file);
10450 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10451 + h_file = au_hf_dir(file, bindex);
10452 + if (!h_file || au_test_ro(sb, bindex, inode))
10455 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10463 + * @file may be NULL
10465 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10469 + struct dentry *dentry;
10470 + struct inode *inode;
10471 + struct super_block *sb;
10474 + dentry = file->f_path.dentry;
10475 + inode = d_inode(dentry);
10476 + inode_lock(inode);
10477 + sb = dentry->d_sb;
10478 + si_noflush_read_lock(sb);
10480 + err = au_do_fsync_dir(file, datasync);
10482 + di_write_lock_child(dentry);
10483 + err = au_do_fsync_dir_no_file(dentry, datasync);
10485 + au_cpup_attr_timesizes(inode);
10486 + di_write_unlock(dentry);
10488 + fi_write_unlock(file);
10490 + si_read_unlock(sb);
10491 + inode_unlock(inode);
10495 +/* ---------------------------------------------------------------------- */
10497 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10500 + struct dentry *dentry;
10501 + struct inode *inode, *h_inode;
10502 + struct super_block *sb;
10504 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10506 + dentry = file->f_path.dentry;
10507 + inode = d_inode(dentry);
10508 + IMustLock(inode);
10510 + sb = dentry->d_sb;
10511 + si_read_lock(sb, AuLock_FLUSH);
10512 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10513 + if (unlikely(err))
10515 + err = au_alive_dir(dentry);
10517 + err = au_vdir_init(file);
10518 + di_downgrade_lock(dentry, AuLock_IR);
10519 + if (unlikely(err))
10522 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10523 + if (!au_test_nfsd()) {
10524 + err = au_vdir_fill_de(file, ctx);
10525 + fsstack_copy_attr_atime(inode, h_inode);
10528 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10529 + * encode_fh() and others.
10531 + atomic_inc(&h_inode->i_count);
10532 + di_read_unlock(dentry, AuLock_IR);
10533 + si_read_unlock(sb);
10534 + err = au_vdir_fill_de(file, ctx);
10535 + fsstack_copy_attr_atime(inode, h_inode);
10536 + fi_write_unlock(file);
10544 + di_read_unlock(dentry, AuLock_IR);
10545 + fi_write_unlock(file);
10547 + si_read_unlock(sb);
10551 +/* ---------------------------------------------------------------------- */
10553 +#define AuTestEmpty_WHONLY 1
10554 +#define AuTestEmpty_CALLED (1 << 1)
10555 +#define AuTestEmpty_SHWH (1 << 2)
10556 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10557 +#define au_fset_testempty(flags, name) \
10558 + do { (flags) |= AuTestEmpty_##name; } while (0)
10559 +#define au_fclr_testempty(flags, name) \
10560 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10562 +#ifndef CONFIG_AUFS_SHWH
10563 +#undef AuTestEmpty_SHWH
10564 +#define AuTestEmpty_SHWH 0
10567 +struct test_empty_arg {
10568 + struct dir_context ctx;
10569 + struct au_nhash *whlist;
10570 + unsigned int flags;
10572 + aufs_bindex_t bindex;
10575 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10576 + int namelen, loff_t offset __maybe_unused, u64 ino,
10577 + unsigned int d_type)
10579 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10581 + char *name = (void *)__name;
10584 + au_fset_testempty(arg->flags, CALLED);
10586 + if (name[0] == '.'
10587 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10588 + goto out; /* success */
10590 + if (namelen <= AUFS_WH_PFX_LEN
10591 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10592 + if (au_ftest_testempty(arg->flags, WHONLY)
10593 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10594 + arg->err = -ENOTEMPTY;
10598 + name += AUFS_WH_PFX_LEN;
10599 + namelen -= AUFS_WH_PFX_LEN;
10600 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10601 + arg->err = au_nhash_append_wh
10602 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10603 + au_ftest_testempty(arg->flags, SHWH));
10607 + AuTraceErr(arg->err);
10611 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10614 + struct file *h_file;
10616 + h_file = au_h_open(dentry, arg->bindex,
10617 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10618 + /*file*/NULL, /*force_wr*/0);
10619 + err = PTR_ERR(h_file);
10620 + if (IS_ERR(h_file))
10624 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10625 + && !file_inode(h_file)->i_nlink)
10630 + au_fclr_testempty(arg->flags, CALLED);
10632 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10635 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10639 + au_sbr_put(dentry->d_sb, arg->bindex);
10644 +struct do_test_empty_args {
10646 + struct dentry *dentry;
10647 + struct test_empty_arg *arg;
10650 +static void call_do_test_empty(void *args)
10652 + struct do_test_empty_args *a = args;
10653 + *a->errp = do_test_empty(a->dentry, a->arg);
10656 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10658 + int err, wkq_err;
10659 + struct dentry *h_dentry;
10660 + struct inode *h_inode;
10662 + h_dentry = au_h_dptr(dentry, arg->bindex);
10663 + h_inode = d_inode(h_dentry);
10664 + /* todo: i_mode changes anytime? */
10665 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10666 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10667 + inode_unlock_shared(h_inode);
10669 + err = do_test_empty(dentry, arg);
10671 + struct do_test_empty_args args = {
10673 + .dentry = dentry,
10676 + unsigned int flags = arg->flags;
10678 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10679 + if (unlikely(wkq_err))
10681 + arg->flags = flags;
10687 +int au_test_empty_lower(struct dentry *dentry)
10690 + unsigned int rdhash;
10691 + aufs_bindex_t bindex, btop, btail;
10692 + struct au_nhash whlist;
10693 + struct test_empty_arg arg = {
10695 + .actor = test_empty_cb
10698 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10700 + SiMustAnyLock(dentry->d_sb);
10702 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10704 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10705 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10706 + if (unlikely(err))
10710 + arg.whlist = &whlist;
10711 + btop = au_dbtop(dentry);
10712 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10713 + au_fset_testempty(arg.flags, SHWH);
10714 + test_empty = do_test_empty;
10715 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10716 + test_empty = sio_test_empty;
10717 + arg.bindex = btop;
10718 + err = test_empty(dentry, &arg);
10719 + if (unlikely(err))
10722 + au_fset_testempty(arg.flags, WHONLY);
10723 + btail = au_dbtaildir(dentry);
10724 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10725 + struct dentry *h_dentry;
10727 + h_dentry = au_h_dptr(dentry, bindex);
10728 + if (h_dentry && d_is_positive(h_dentry)) {
10729 + arg.bindex = bindex;
10730 + err = test_empty(dentry, &arg);
10735 + au_nhash_wh_free(&whlist);
10740 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10743 + struct test_empty_arg arg = {
10745 + .actor = test_empty_cb
10748 + aufs_bindex_t bindex, btail;
10751 + arg.whlist = whlist;
10752 + arg.flags = AuTestEmpty_WHONLY;
10753 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10754 + au_fset_testempty(arg.flags, SHWH);
10755 + btail = au_dbtaildir(dentry);
10756 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10757 + struct dentry *h_dentry;
10759 + h_dentry = au_h_dptr(dentry, bindex);
10760 + if (h_dentry && d_is_positive(h_dentry)) {
10761 + arg.bindex = bindex;
10762 + err = sio_test_empty(dentry, &arg);
10769 +/* ---------------------------------------------------------------------- */
10771 +const struct file_operations aufs_dir_fop = {
10772 + .owner = THIS_MODULE,
10773 + .llseek = default_llseek,
10774 + .read = generic_read_dir,
10775 + .iterate_shared = aufs_iterate_shared,
10776 + .unlocked_ioctl = aufs_ioctl_dir,
10777 +#ifdef CONFIG_COMPAT
10778 + .compat_ioctl = aufs_compat_ioctl_dir,
10780 + .open = aufs_open_dir,
10781 + .release = aufs_release_dir,
10782 + .flush = aufs_flush_dir,
10783 + .fsync = aufs_fsync_dir
10785 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10786 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10787 +++ linux/fs/aufs/dir.h 2017-11-12 22:24:42.267510077 +0100
10790 + * Copyright (C) 2005-2017 Junjiro R. Okajima
10792 + * This program, aufs is free software; you can redistribute it and/or modify
10793 + * it under the terms of the GNU General Public License as published by
10794 + * the Free Software Foundation; either version 2 of the License, or
10795 + * (at your option) any later version.
10797 + * This program is distributed in the hope that it will be useful,
10798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10800 + * GNU General Public License for more details.
10802 + * You should have received a copy of the GNU General Public License
10803 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10807 + * directory operations
10810 +#ifndef __AUFS_DIR_H__
10811 +#define __AUFS_DIR_H__
10815 +#include <linux/fs.h>
10817 +/* ---------------------------------------------------------------------- */
10819 +/* need to be faster and smaller */
10822 + unsigned int nh_num;
10823 + struct hlist_head *nh_head;
10826 +struct au_vdir_destr {
10827 + unsigned char len;
10828 + unsigned char name[0];
10831 +struct au_vdir_dehstr {
10832 + struct hlist_node hash;
10833 + struct au_vdir_destr *str;
10834 +} ____cacheline_aligned_in_smp;
10836 +struct au_vdir_de {
10838 + unsigned char de_type;
10839 + /* caution: packed */
10840 + struct au_vdir_destr de_str;
10843 +struct au_vdir_wh {
10844 + struct hlist_node wh_hash;
10845 +#ifdef CONFIG_AUFS_SHWH
10847 + aufs_bindex_t wh_bindex;
10848 + unsigned char wh_type;
10850 + aufs_bindex_t wh_bindex;
10852 + /* caution: packed */
10853 + struct au_vdir_destr wh_str;
10856 +union au_vdir_deblk_p {
10857 + unsigned char *deblk;
10858 + struct au_vdir_de *de;
10862 + unsigned char **vd_deblk;
10863 + unsigned long vd_nblk;
10865 + unsigned long ul;
10866 + union au_vdir_deblk_p p;
10869 + unsigned long vd_version;
10870 + unsigned int vd_deblk_sz;
10871 + unsigned long vd_jiffy;
10872 +} ____cacheline_aligned_in_smp;
10874 +/* ---------------------------------------------------------------------- */
10877 +extern const struct file_operations aufs_dir_fop;
10878 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10879 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10880 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10881 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10882 +int au_test_empty_lower(struct dentry *dentry);
10883 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10886 +unsigned int au_rdhash_est(loff_t sz);
10887 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10888 +void au_nhash_wh_free(struct au_nhash *whlist);
10889 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10891 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10892 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10893 + unsigned int d_type, aufs_bindex_t bindex,
10894 + unsigned char shwh);
10895 +void au_vdir_free(struct au_vdir *vdir);
10896 +int au_vdir_init(struct file *file);
10897 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10900 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10902 +#ifdef CONFIG_AUFS_RDU
10904 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10905 +#ifdef CONFIG_COMPAT
10906 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10907 + unsigned long arg);
10910 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10911 + unsigned int cmd, unsigned long arg)
10912 +#ifdef CONFIG_COMPAT
10913 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10914 + unsigned int cmd, unsigned long arg)
10918 +#endif /* __KERNEL__ */
10919 +#endif /* __AUFS_DIR_H__ */
10920 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10921 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10922 +++ linux/fs/aufs/dirren.c 2017-11-12 22:24:44.704244405 +0100
10925 + * Copyright (C) 2017 Junjiro R. Okajima
10927 + * This program, aufs is free software; you can redistribute it and/or modify
10928 + * it under the terms of the GNU General Public License as published by
10929 + * the Free Software Foundation; either version 2 of the License, or
10930 + * (at your option) any later version.
10932 + * This program is distributed in the hope that it will be useful,
10933 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10934 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10935 + * GNU General Public License for more details.
10937 + * You should have received a copy of the GNU General Public License
10938 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10942 + * special handling in renaming a directoy
10943 + * in order to support looking-up the before-renamed name on the lower readonly
10947 +#include <linux/byteorder/generic.h>
10950 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10954 + idx = au_dr_ihash(ent->dr_h_ino);
10955 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10958 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10961 + struct hlist_bl_head *hbl;
10964 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10965 + hbl = dr->dr_h_ino + i;
10966 + hlist_bl_lock(hbl);
10967 + ret &= hlist_bl_empty(hbl);
10968 + hlist_bl_unlock(hbl);
10974 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10976 + struct au_dr_hino *found, *ent;
10977 + struct hlist_bl_head *hbl;
10978 + struct hlist_bl_node *pos;
10982 + idx = au_dr_ihash(ino);
10983 + hbl = dr->dr_h_ino + idx;
10984 + hlist_bl_lock(hbl);
10985 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10986 + if (ent->dr_h_ino == ino) {
10990 + hlist_bl_unlock(hbl);
10995 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10996 + struct au_dr_hino *add_ent)
10999 + struct hlist_bl_head *hbl;
11000 + struct hlist_bl_node *pos;
11001 + struct au_dr_hino *ent;
11004 + idx = au_dr_ihash(ino);
11005 + hbl = dr->dr_h_ino + idx;
11008 + struct hlist_bl_node *tmp;
11010 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11011 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11014 + hlist_bl_lock(hbl);
11015 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11016 + if (ent->dr_h_ino == ino) {
11020 + if (!found && add_ent)
11021 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11022 + hlist_bl_unlock(hbl);
11024 + if (!found && add_ent)
11025 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11030 +void au_dr_hino_free(struct au_dr_br *dr)
11033 + struct hlist_bl_head *hbl;
11034 + struct hlist_bl_node *pos, *tmp;
11035 + struct au_dr_hino *ent;
11037 + /* SiMustWriteLock(sb); */
11039 + for (i = 0; i < AuDirren_NHASH; i++) {
11040 + hbl = dr->dr_h_ino + i;
11041 + /* no spinlock since sbinfo must be write-locked */
11042 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11044 + INIT_HLIST_BL_HEAD(hbl);
11048 +/* returns the number of inodes or an error */
11049 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11050 + struct file *hinofile)
11054 + loff_t pos, oldsize;
11056 + struct inode *hinoinode;
11057 + struct hlist_bl_head *hbl;
11058 + struct hlist_bl_node *n1, *n2;
11059 + struct au_dr_hino *ent;
11061 + SiMustWriteLock(sb);
11062 + AuDebugOn(!au_br_writable(br->br_perm));
11064 + hinoinode = file_inode(hinofile);
11065 + oldsize = i_size_read(hinoinode);
11069 + hbl = br->br_dirren.dr_h_ino;
11070 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11071 + /* no bit-lock since sbinfo must be write-locked */
11072 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11073 + AuDbg("hi%llu, %pD2\n",
11074 + (unsigned long long)ent->dr_h_ino, hinofile);
11075 + u64 = cpu_to_be64(ent->dr_h_ino);
11076 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11077 + if (ssz == sizeof(u64))
11080 + /* write error */
11081 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11088 + /* regardless the error */
11089 + if (pos < oldsize) {
11090 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11098 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11105 + struct au_dr_hino *ent;
11106 + struct inode *hinoinode;
11107 + struct hlist_bl_head *hbl;
11111 + hbl = dr->dr_h_ino;
11112 + hinoinode = file_inode(hinofile);
11113 + sz = i_size_read(hinoinode);
11114 + AuDebugOn(sz % sizeof(u64));
11115 + n = sz / sizeof(u64);
11117 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11118 + if (unlikely(ssz != sizeof(u64))) {
11119 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11126 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11132 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11133 + AuDbg("hi%llu, %pD2\n",
11134 + (unsigned long long)ent->dr_h_ino, hinofile);
11135 + hidx = au_dr_ihash(ent->dr_h_ino);
11136 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11138 + goto out; /* success */
11141 + au_dr_hino_free(dr);
11148 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11149 + * @path is a switch to distinguish load and store.
11151 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11152 + struct au_branch *br, const struct path *path)
11155 + unsigned char load, suspend;
11156 + struct file *hinofile;
11157 + struct au_hinode *hdir;
11158 + struct inode *dir, *delegated;
11159 + struct path hinopath;
11160 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11161 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11163 + AuDebugOn(bindex < 0 && !br);
11164 + AuDebugOn(bindex >= 0 && br);
11169 + br = au_sbr(sb, bindex);
11172 + path = &br->br_path;
11173 + AuDebugOn(!au_br_writable(br->br_perm));
11174 + if (unlikely(!au_br_writable(br->br_perm)))
11180 + dir = d_inode(sb->s_root);
11181 + hdir = au_hinode(au_ii(dir), bindex);
11182 + dir = hdir->hi_inode;
11183 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11185 + dir = d_inode(path->dentry);
11186 + inode_lock_nested(dir, AuLsc_I_CHILD);
11188 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11189 + err = PTR_ERR(hinopath.dentry);
11190 + if (IS_ERR(hinopath.dentry))
11194 + flags = O_RDONLY;
11196 + if (d_is_negative(hinopath.dentry))
11197 + goto out_dput; /* success */
11199 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11200 + if (d_is_positive(hinopath.dentry)) {
11201 + delegated = NULL;
11202 + err = vfsub_unlink(dir, &hinopath, &delegated,
11205 + if (unlikely(err))
11206 + pr_err("ignored err %d, %pd2\n",
11207 + err, hinopath.dentry);
11208 + if (unlikely(err == -EWOULDBLOCK))
11213 + } else if (!d_is_positive(hinopath.dentry)) {
11214 + err = vfsub_create(dir, &hinopath, 0600,
11215 + /*want_excl*/false);
11217 + if (unlikely(err))
11220 + flags = O_WRONLY;
11222 + hinopath.mnt = path->mnt;
11223 + hinofile = vfsub_dentry_open(&hinopath, flags);
11225 + au_hn_inode_unlock(hdir);
11227 + inode_unlock(dir);
11228 + dput(hinopath.dentry);
11229 + AuTraceErrPtr(hinofile);
11230 + if (IS_ERR(hinofile)) {
11231 + err = PTR_ERR(hinofile);
11236 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11238 + err = au_dr_hino_store(sb, br, hinofile);
11243 + dput(hinopath.dentry);
11246 + au_hn_inode_unlock(hdir);
11248 + inode_unlock(dir);
11254 +/* ---------------------------------------------------------------------- */
11256 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11259 + struct kstatfs kstfs;
11261 + struct dentry *dentry;
11262 + struct super_block *sb;
11264 + err = vfs_statfs((void *)path, &kstfs);
11266 + if (unlikely(err))
11269 + /* todo: support for UUID */
11271 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11272 + brid->type = AuBrid_FSID;
11273 + brid->fsid = kstfs.f_fsid;
11275 + dentry = path->dentry;
11276 + sb = dentry->d_sb;
11279 + brid->type = AuBrid_DEV;
11288 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11289 + const struct path *path)
11292 + struct au_dr_br *dr;
11293 + struct hlist_bl_head *hbl;
11295 + dr = &br->br_dirren;
11296 + hbl = dr->dr_h_ino;
11297 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11298 + INIT_HLIST_BL_HEAD(hbl);
11300 + err = au_dr_brid_init(&dr->dr_brid, path);
11301 + if (unlikely(err))
11304 + if (au_opt_test(au_mntflags(sb), DIRREN))
11305 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11312 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11317 + if (au_br_writable(br->br_perm))
11318 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11320 + au_dr_hino_free(&br->br_dirren);
11325 +/* ---------------------------------------------------------------------- */
11327 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11328 + char *buf, size_t sz)
11331 + unsigned int major, minor;
11335 + err = snprintf(p, sz, "%d_", brid->type);
11336 + AuDebugOn(err > sz);
11339 + switch (brid->type) {
11340 + case AuBrid_Unset:
11342 + case AuBrid_UUID:
11343 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11345 + case AuBrid_FSID:
11346 + err = snprintf(p, sz, "%08x-%08x",
11347 + brid->fsid.val[0], brid->fsid.val[1]);
11350 + major = MAJOR(brid->dev);
11351 + minor = MINOR(brid->dev);
11352 + if (major <= 0xff && minor <= 0xff)
11353 + err = snprintf(p, sz, "%02x%02x", major, minor);
11355 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11358 + AuDebugOn(err > sz);
11361 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11362 + AuDebugOn(err > sz);
11369 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11372 + struct dentry *br_dentry;
11373 + struct inode *br_inode;
11375 + br_dentry = au_br_dentry(br);
11376 + br_inode = d_inode(br_dentry);
11377 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11378 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11379 + AuDebugOn(rlen > len);
11384 +/* ---------------------------------------------------------------------- */
11387 + * from the given @h_dentry, construct drinfo at @*fdata.
11388 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11391 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11392 + struct dentry *h_dentry,
11393 + unsigned char *allocated)
11396 + struct au_drinfo_fdata *f, *p;
11397 + struct au_drinfo *drinfo;
11398 + struct inode *h_inode;
11399 + struct qstr *qname;
11403 + h_inode = d_inode(h_dentry);
11404 + qname = &h_dentry->d_name;
11405 + drinfo = &f->drinfo;
11406 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11407 + drinfo->oldnamelen = qname->len;
11408 + if (*allocated < sizeof(*f) + qname->len) {
11409 + v = roundup_pow_of_two(*allocated + qname->len);
11410 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11411 + if (unlikely(!p)) {
11419 + drinfo = &f->drinfo;
11421 + memcpy(drinfo->oldname, qname->name, qname->len);
11422 + AuDbg("i%llu, %.*s\n",
11423 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11424 + drinfo->oldname);
11431 +/* callers have to free the return value */
11432 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11434 + struct au_drinfo *ret, *drinfo;
11435 + struct au_drinfo_fdata fdata;
11440 + ret = ERR_PTR(-EIO);
11442 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11443 + if (unlikely(ssz != sizeof(fdata))) {
11444 + AuIOErr("ssz %zd, %u, %pD2\n",
11445 + ssz, (unsigned int)sizeof(fdata), file);
11449 + fdata.magic = ntohl((__force __be32)fdata.magic);
11450 + switch (fdata.magic) {
11451 + case AUFS_DRINFO_MAGIC_V1:
11454 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11455 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11459 + drinfo = &fdata.drinfo;
11460 + len = drinfo->oldnamelen;
11462 + AuIOErr("broken drinfo %pD2\n", file);
11467 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11468 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11469 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11470 + (unsigned long long)drinfo->ino,
11471 + (unsigned long long)h_ino, file);
11472 + goto out; /* success */
11475 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11476 + if (unlikely(!ret)) {
11477 + ret = ERR_PTR(-ENOMEM);
11478 + AuTraceErrPtr(ret);
11483 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11484 + if (unlikely(ssz != len)) {
11486 + ret = ERR_PTR(-EIO);
11487 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11491 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11497 +/* ---------------------------------------------------------------------- */
11499 +/* in order to be revertible */
11500 +struct au_drinfo_rev_elm {
11502 + struct dentry *info_dentry;
11503 + struct au_drinfo *info_last;
11506 +struct au_drinfo_rev {
11507 + unsigned char already;
11508 + aufs_bindex_t nelm;
11509 + struct au_drinfo_rev_elm elm[0];
11512 +/* todo: isn't it too large? */
11513 +struct au_drinfo_store {
11514 + struct path h_ppath;
11515 + struct dentry *h_dentry;
11516 + struct au_drinfo_fdata *fdata;
11517 + char *infoname; /* inside of whname, just after PFX */
11518 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11519 + aufs_bindex_t btgt, btail;
11520 + unsigned char no_sio,
11521 + allocated, /* current size of *fdata */
11522 + infonamelen, /* room size for p */
11523 + whnamelen, /* length of the genarated name */
11524 + renameback; /* renamed back */
11527 +/* on rename(2) error, the caller should revert it using @elm */
11528 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11529 + struct au_drinfo_rev_elm *elm)
11534 + struct path infopath = {
11535 + .mnt = w->h_ppath.mnt
11537 + struct inode *h_dir, *h_inode, *delegated;
11538 + struct file *infofile;
11539 + struct qstr *qname;
11542 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11544 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11546 + AuTraceErrPtr(infopath.dentry);
11547 + if (IS_ERR(infopath.dentry)) {
11548 + err = PTR_ERR(infopath.dentry);
11553 + h_dir = d_inode(w->h_ppath.dentry);
11554 + if (elm && d_is_negative(infopath.dentry)) {
11555 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11557 + if (unlikely(err))
11559 + elm->created = 1;
11560 + elm->info_dentry = dget(infopath.dentry);
11563 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11564 + AuTraceErrPtr(infofile);
11565 + if (IS_ERR(infofile)) {
11566 + err = PTR_ERR(infofile);
11570 + h_inode = d_inode(infopath.dentry);
11571 + if (elm && i_size_read(h_inode)) {
11572 + h_inode = d_inode(w->h_dentry);
11573 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11574 + AuTraceErrPtr(elm->info_last);
11575 + if (IS_ERR(elm->info_last)) {
11576 + err = PTR_ERR(elm->info_last);
11577 + elm->info_last = NULL;
11578 + AuDebugOn(elm->info_dentry);
11583 + if (elm && w->renameback) {
11584 + delegated = NULL;
11585 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11587 + if (unlikely(err == -EWOULDBLOCK))
11593 + qname = &w->h_dentry->d_name;
11594 + len = sizeof(*w->fdata) + qname->len;
11596 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11597 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11598 + if (ssz == len) {
11599 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11600 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11601 + goto out_fput; /* success */
11606 + /* the caller should revert it using @elm */
11612 + dput(infopath.dentry);
11618 +struct au_call_drinfo_do_store_args {
11620 + struct au_drinfo_store *w;
11621 + struct au_drinfo_rev_elm *elm;
11624 +static void au_call_drinfo_do_store(void *args)
11626 + struct au_call_drinfo_do_store_args *a = args;
11628 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11631 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11632 + struct au_drinfo_rev_elm *elm)
11634 + int err, wkq_err;
11637 + err = au_drinfo_do_store(w, elm);
11639 + struct au_call_drinfo_do_store_args a = {
11644 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11645 + if (unlikely(wkq_err))
11653 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11654 + aufs_bindex_t btgt)
11658 + memset(w, 0, sizeof(*w));
11659 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11660 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11661 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11662 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11664 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11667 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11668 + if (unlikely(!w->fdata)) {
11672 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11679 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11684 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11685 + struct au_drinfo_store *w)
11687 + struct au_drinfo_rev_elm *elm;
11688 + struct inode *h_dir, *delegated;
11690 + struct path infopath = {
11691 + .mnt = w->h_ppath.mnt
11694 + h_dir = d_inode(w->h_ppath.dentry);
11695 + IMustLock(h_dir);
11699 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11700 + AuDebugOn(elm->created && elm->info_last);
11701 + if (elm->created) {
11703 + delegated = NULL;
11704 + infopath.dentry = elm->info_dentry;
11705 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11708 + if (unlikely(err == -EWOULDBLOCK))
11710 + dput(elm->info_dentry);
11711 + } else if (elm->info_last) {
11713 + w->fdata->drinfo = *elm->info_last;
11714 + memcpy(w->fdata->drinfo.oldname,
11715 + elm->info_last->oldname,
11716 + elm->info_last->oldnamelen);
11717 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11718 + kfree(elm->info_last);
11720 + if (unlikely(err))
11721 + AuIOErr("%d, %s\n", err, w->whname);
11722 + /* go on even if err */
11726 +/* caller has to call au_dr_rename_fin() later */
11727 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11728 + struct qstr *dst_name, void *_rev)
11730 + int err, sz, nelm;
11731 + aufs_bindex_t bindex, btail;
11732 + struct au_drinfo_store work;
11733 + struct au_drinfo_rev *rev, **p;
11734 + struct au_drinfo_rev_elm *elm;
11735 + struct super_block *sb;
11736 + struct au_branch *br;
11737 + struct au_hinode *hdir;
11739 + err = au_drinfo_store_work_init(&work, btgt);
11741 + if (unlikely(err))
11745 + btail = au_dbtaildir(dentry);
11746 + nelm = btail - btgt;
11747 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11748 + rev = kcalloc(1, sz, GFP_NOFS);
11749 + if (unlikely(!rev)) {
11753 + rev->nelm = nelm;
11759 + sb = dentry->d_sb;
11760 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11761 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11762 + hdir = au_hi(d_inode(dentry), btgt);
11763 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11764 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11765 + work.h_dentry = au_h_dptr(dentry, bindex);
11766 + if (!work.h_dentry)
11769 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11770 + &work.allocated);
11772 + if (unlikely(err))
11775 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11776 + br = au_sbr(sb, bindex);
11777 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11778 + work.whnamelen += au_drinfo_name(br, work.infoname,
11779 + work.infonamelen);
11780 + AuDbg("whname %.*s, i%llu, %.*s\n",
11781 + work.whnamelen, work.whname,
11782 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11783 + work.fdata->drinfo.oldnamelen,
11784 + work.fdata->drinfo.oldname);
11786 + err = au_drinfo_store_sio(&work, elm);
11788 + if (unlikely(err))
11791 + if (unlikely(err)) {
11792 + /* revert all drinfo */
11793 + au_drinfo_store_rev(rev, &work);
11797 + au_hn_inode_unlock(hdir);
11800 + au_drinfo_store_work_fin(&work);
11805 +/* ---------------------------------------------------------------------- */
11807 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11808 + struct qstr *dst_name, void *_rev)
11810 + int err, already;
11812 + struct super_block *sb;
11813 + struct au_branch *br;
11814 + struct au_dr_br *dr;
11815 + struct dentry *h_dentry;
11816 + struct inode *h_inode;
11817 + struct au_dr_hino *ent;
11818 + struct au_drinfo_rev *rev, **p;
11820 + AuDbg("bindex %d\n", bindex);
11823 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11824 + if (unlikely(!ent))
11828 + br = au_sbr(sb, bindex);
11829 + dr = &br->br_dirren;
11830 + h_dentry = au_h_dptr(src, bindex);
11831 + h_inode = d_inode(h_dentry);
11832 + ino = h_inode->i_ino;
11833 + ent->dr_h_ino = ino;
11834 + already = au_dr_hino_test_add(dr, ino, ent);
11835 + AuDbg("b%d, hi%llu, already %d\n",
11836 + bindex, (unsigned long long)ino, already);
11838 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11843 + rev->already = already;
11844 + goto out; /* success */
11849 + au_dr_hino_del(dr, ent);
11857 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11859 + struct au_drinfo_rev *rev;
11860 + struct au_drinfo_rev_elm *elm;
11865 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11866 + dput(elm->info_dentry);
11867 + kfree(elm->info_last);
11872 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11875 + struct au_drinfo_store work;
11876 + struct au_drinfo_rev *rev = _rev;
11877 + struct super_block *sb;
11878 + struct au_branch *br;
11879 + struct inode *h_inode;
11880 + struct au_dr_br *dr;
11881 + struct au_dr_hino *ent;
11883 + err = au_drinfo_store_work_init(&work, btgt);
11884 + if (unlikely(err))
11888 + br = au_sbr(sb, btgt);
11889 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11890 + work.h_ppath.mnt = au_br_mnt(br);
11891 + au_drinfo_store_rev(rev, &work);
11892 + au_drinfo_store_work_fin(&work);
11893 + if (rev->already)
11896 + dr = &br->br_dirren;
11897 + h_inode = d_inode(work.h_ppath.dentry);
11898 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11900 + au_dr_hino_del(dr, ent);
11905 + if (unlikely(err))
11906 + pr_err("failed to remove dirren info\n");
11909 +/* ---------------------------------------------------------------------- */
11911 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11912 + char *whname, int whnamelen,
11913 + struct dentry **info_dentry)
11915 + struct au_drinfo *drinfo;
11917 + struct inode *h_dir;
11918 + struct path infopath;
11921 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11923 + *info_dentry = NULL;
11926 + h_dir = d_inode(h_ppath->dentry);
11927 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11928 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11930 + if (IS_ERR(infopath.dentry)) {
11931 + drinfo = (void *)infopath.dentry;
11935 + if (d_is_negative(infopath.dentry))
11936 + goto out_dput; /* success */
11938 + infopath.mnt = h_ppath->mnt;
11939 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11940 + inode_unlock_shared(h_dir);
11943 + drinfo = (void *)f;
11947 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11948 + if (IS_ERR_OR_NULL(drinfo))
11951 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11952 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11957 + dput(infopath.dentry);
11960 + inode_unlock_shared(h_dir);
11961 + AuTraceErrPtr(drinfo);
11965 +struct au_drinfo_do_load_args {
11966 + struct au_drinfo **drinfop;
11967 + struct path *h_ppath;
11970 + struct dentry **info_dentry;
11973 +static void au_call_drinfo_do_load(void *args)
11975 + struct au_drinfo_do_load_args *a = args;
11977 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11981 +struct au_drinfo_load {
11982 + struct path h_ppath;
11983 + struct qstr *qname;
11984 + unsigned char no_sio;
11986 + aufs_bindex_t ninfo;
11987 + struct au_drinfo **drinfo;
11990 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11991 + struct au_branch *br)
11993 + int err, wkq_err, whnamelen, e;
11994 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11995 + = AUFS_WH_DR_INFO_PFX;
11996 + struct au_drinfo *drinfo;
11997 + struct qstr oldname;
11998 + struct inode *h_dir, *delegated;
11999 + struct dentry *info_dentry;
12000 + struct path infopath;
12002 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12003 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12004 + sizeof(whname) - whnamelen);
12006 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12009 + struct au_drinfo_do_load_args args = {
12010 + .drinfop = &drinfo,
12011 + .h_ppath = &w->h_ppath,
12012 + .whname = whname,
12013 + .whnamelen = whnamelen,
12014 + .info_dentry = &info_dentry
12016 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12017 + if (unlikely(wkq_err))
12018 + drinfo = ERR_PTR(wkq_err);
12020 + err = PTR_ERR(drinfo);
12021 + if (IS_ERR_OR_NULL(drinfo))
12025 + oldname.len = drinfo->oldnamelen;
12026 + oldname.name = drinfo->oldname;
12027 + if (au_qstreq(w->qname, &oldname)) {
12028 + /* the name is renamed back */
12032 + infopath.dentry = info_dentry;
12033 + infopath.mnt = w->h_ppath.mnt;
12034 + h_dir = d_inode(w->h_ppath.dentry);
12035 + delegated = NULL;
12036 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12037 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12038 + inode_unlock(h_dir);
12040 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12041 + if (unlikely(e == -EWOULDBLOCK))
12044 + kfree(w->drinfo[bindex]);
12045 + w->drinfo[bindex] = drinfo;
12046 + dput(info_dentry);
12053 +/* ---------------------------------------------------------------------- */
12055 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12057 + struct au_drinfo **p = drinfo;
12060 + kfree(*drinfo++);
12064 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12065 + aufs_bindex_t btgt)
12068 + struct au_drinfo_load w;
12069 + aufs_bindex_t bindex, bbot;
12070 + struct au_branch *br;
12071 + struct inode *h_dir;
12072 + struct au_dr_hino *ent;
12073 + struct super_block *sb;
12075 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12076 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12077 + AuLNPair(&lkup->whname), btgt);
12079 + sb = dentry->d_sb;
12080 + bbot = au_sbbot(sb);
12081 + w.ninfo = bbot + 1;
12082 + if (!lkup->dirren.drinfo) {
12083 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12084 + sizeof(*lkup->dirren.drinfo),
12086 + if (unlikely(!lkup->dirren.drinfo)) {
12090 + lkup->dirren.ninfo = w.ninfo;
12092 + w.drinfo = lkup->dirren.drinfo;
12093 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12094 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12095 + AuDebugOn(!w.h_ppath.dentry);
12096 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12097 + w.qname = &dentry->d_name;
12100 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12101 + br = au_sbr(sb, bindex);
12102 + err = au_drinfo_load(&w, bindex, br);
12103 + if (unlikely(err))
12105 + if (w.drinfo[bindex])
12109 + br = au_sbr(sb, btgt);
12110 + h_dir = d_inode(w.h_ppath.dentry);
12111 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12113 + au_dr_hino_del(&br->br_dirren, ent);
12116 + goto out; /* success */
12119 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12120 + lkup->dirren.ninfo = 0;
12121 + lkup->dirren.drinfo = NULL;
12127 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12129 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12132 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12135 + struct au_drinfo *drinfo;
12138 + if (!lkup->dirren.drinfo)
12140 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12141 + drinfo = lkup->dirren.drinfo[btgt + 1];
12145 + kfree(lkup->whname.name);
12146 + lkup->whname.name = NULL;
12147 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12148 + lkup->dirren.dr_name.name = drinfo->oldname;
12149 + lkup->name = &lkup->dirren.dr_name;
12150 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12152 + AuDbg("name %.*s, whname %.*s, b%d\n",
12153 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12161 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12165 + struct au_drinfo *drinfo;
12168 + if (!lkup->dirren.drinfo)
12170 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12171 + drinfo = lkup->dirren.drinfo[bindex + 1];
12175 + match = (drinfo->ino == h_ino);
12176 + AuDbg("match %d\n", match);
12182 +/* ---------------------------------------------------------------------- */
12184 +int au_dr_opt_set(struct super_block *sb)
12187 + aufs_bindex_t bindex, bbot;
12188 + struct au_branch *br;
12191 + bbot = au_sbbot(sb);
12192 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12193 + br = au_sbr(sb, bindex);
12194 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12200 +int au_dr_opt_flush(struct super_block *sb)
12203 + aufs_bindex_t bindex, bbot;
12204 + struct au_branch *br;
12207 + bbot = au_sbbot(sb);
12208 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12209 + br = au_sbr(sb, bindex);
12210 + if (au_br_writable(br->br_perm))
12211 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12217 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12220 + aufs_bindex_t bindex, bbot;
12221 + struct au_branch *br;
12225 + err = au_dr_opt_flush(sb);
12226 + if (unlikely(err))
12230 + bbot = au_sbbot(sb);
12231 + for (bindex = 0; bindex <= bbot; bindex++) {
12232 + br = au_sbr(sb, bindex);
12233 + au_dr_hino_free(&br->br_dirren);
12239 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12240 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12241 +++ linux/fs/aufs/dirren.h 2017-11-12 22:24:44.704244405 +0100
12244 + * Copyright (C) 2017 Junjiro R. Okajima
12246 + * This program, aufs is free software; you can redistribute it and/or modify
12247 + * it under the terms of the GNU General Public License as published by
12248 + * the Free Software Foundation; either version 2 of the License, or
12249 + * (at your option) any later version.
12251 + * This program is distributed in the hope that it will be useful,
12252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12254 + * GNU General Public License for more details.
12256 + * You should have received a copy of the GNU General Public License
12257 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12261 + * renamed dir info
12264 +#ifndef __AUFS_DIRREN_H__
12265 +#define __AUFS_DIRREN_H__
12269 +#include <linux/dcache.h>
12270 +#include <linux/statfs.h>
12271 +#include <linux/uuid.h>
12274 +#define AuDirren_NHASH 100
12276 +#ifdef CONFIG_AUFS_DIRREN
12277 +enum au_brid_type {
12284 +struct au_dr_brid {
12285 + enum au_brid_type type;
12287 + uuid_t uuid; /* unimplemented yet */
12293 +/* 20 is the max digits length of ulong 64 */
12294 +/* brid-type "_" uuid "_" inum */
12295 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12296 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12298 +struct au_dr_hino {
12299 + struct hlist_bl_node dr_hnode;
12304 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12305 + struct au_dr_brid dr_brid;
12308 +struct au_dr_lookup {
12309 + /* dr_name is pointed by struct au_do_lookup_args.name */
12310 + struct qstr dr_name; /* subset of dr_info */
12311 + aufs_bindex_t ninfo;
12312 + struct au_drinfo **drinfo;
12315 +struct au_dr_hino;
12317 +struct au_dr_br { };
12318 +struct au_dr_lookup { };
12321 +/* ---------------------------------------------------------------------- */
12324 +struct au_do_lookup_args;
12326 +#ifdef CONFIG_AUFS_DIRREN
12327 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12328 + struct au_dr_hino *add_ent);
12329 +void au_dr_hino_free(struct au_dr_br *dr);
12330 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12331 + const struct path *path);
12332 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12333 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12334 + struct qstr *dst_name, void *_rev);
12335 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12336 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12337 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12338 + aufs_bindex_t bindex);
12339 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12340 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12342 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12343 +int au_dr_opt_set(struct super_block *sb);
12344 +int au_dr_opt_flush(struct super_block *sb);
12345 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12347 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12348 + struct au_dr_hino *add_ent);
12349 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12350 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12351 + const struct path *path);
12352 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12353 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12354 + struct qstr *dst_name, void *_rev);
12355 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12356 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12358 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12359 + aufs_bindex_t bindex);
12360 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12361 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12362 + aufs_bindex_t bindex, ino_t h_ino);
12363 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12364 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12365 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12366 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12369 +/* ---------------------------------------------------------------------- */
12371 +#ifdef CONFIG_AUFS_DIRREN
12372 +static inline int au_dr_ihash(ino_t h_ino)
12374 + return h_ino % AuDirren_NHASH;
12377 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12380 +#endif /* __KERNEL__ */
12381 +#endif /* __AUFS_DIRREN_H__ */
12382 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12383 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12384 +++ linux/fs/aufs/dynop.c 2017-11-12 22:24:44.704244405 +0100
12387 + * Copyright (C) 2010-2017 Junjiro R. Okajima
12389 + * This program, aufs is free software; you can redistribute it and/or modify
12390 + * it under the terms of the GNU General Public License as published by
12391 + * the Free Software Foundation; either version 2 of the License, or
12392 + * (at your option) any later version.
12394 + * This program is distributed in the hope that it will be useful,
12395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12397 + * GNU General Public License for more details.
12399 + * You should have received a copy of the GNU General Public License
12400 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12404 + * dynamically customizable operations for regular files
12409 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12412 + * How large will these lists be?
12413 + * Usually just a few elements, 20-30 at most for each, I guess.
12415 +static struct hlist_bl_head dynop[AuDyLast];
12417 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12418 + const void *h_op)
12420 + struct au_dykey *key, *tmp;
12421 + struct hlist_bl_node *pos;
12424 + hlist_bl_lock(hbl);
12425 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12426 + if (tmp->dk_op.dy_hop == h_op) {
12428 + kref_get(&key->dk_kref);
12431 + hlist_bl_unlock(hbl);
12436 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12438 + struct au_dykey **k, *found;
12439 + const void *h_op = key->dk_op.dy_hop;
12443 + k = br->br_dykey;
12444 + for (i = 0; i < AuBrDynOp; i++)
12446 + if (k[i]->dk_op.dy_hop == h_op) {
12453 + spin_lock(&br->br_dykey_lock);
12454 + for (; i < AuBrDynOp; i++)
12456 + if (k[i]->dk_op.dy_hop == h_op) {
12464 + spin_unlock(&br->br_dykey_lock);
12465 + BUG_ON(i == AuBrDynOp); /* expand the array */
12471 +/* kref_get() if @key is already added */
12472 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12474 + struct au_dykey *tmp, *found;
12475 + struct hlist_bl_node *pos;
12476 + const void *h_op = key->dk_op.dy_hop;
12479 + hlist_bl_lock(hbl);
12480 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12481 + if (tmp->dk_op.dy_hop == h_op) {
12482 + kref_get(&tmp->dk_kref);
12487 + hlist_bl_add_head(&key->dk_hnode, hbl);
12488 + hlist_bl_unlock(hbl);
12495 +static void dy_free_rcu(struct rcu_head *rcu)
12497 + struct au_dykey *key;
12499 + key = container_of(rcu, struct au_dykey, dk_rcu);
12504 +static void dy_free(struct kref *kref)
12506 + struct au_dykey *key;
12507 + struct hlist_bl_head *hbl;
12509 + key = container_of(kref, struct au_dykey, dk_kref);
12510 + hbl = dynop + key->dk_op.dy_type;
12511 + au_hbl_del(&key->dk_hnode, hbl);
12512 + call_rcu(&key->dk_rcu, dy_free_rcu);
12515 +void au_dy_put(struct au_dykey *key)
12517 + kref_put(&key->dk_kref, dy_free);
12520 +/* ---------------------------------------------------------------------- */
12522 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12524 +#ifdef CONFIG_AUFS_DEBUG
12525 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12526 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12528 +#define DyDbgDeclare(cnt) do {} while (0)
12529 +#define DyDbgInc(cnt) do {} while (0)
12532 +#define DySet(func, dst, src, h_op, h_sb) do { \
12534 + if (h_op->func) { \
12536 + dst.func = src.func; \
12538 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12542 +#define DySetForce(func, dst, src) do { \
12543 + AuDebugOn(!src.func); \
12545 + dst.func = src.func; \
12548 +#define DySetAop(func) \
12549 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12550 +#define DySetAopForce(func) \
12551 + DySetForce(func, dyaop->da_op, aufs_aop)
12553 +static void dy_aop(struct au_dykey *key, const void *h_op,
12554 + struct super_block *h_sb __maybe_unused)
12556 + struct au_dyaop *dyaop = (void *)key;
12557 + const struct address_space_operations *h_aop = h_op;
12558 + DyDbgDeclare(cnt);
12560 + AuDbg("%s\n", au_sbtype(h_sb));
12562 + DySetAop(writepage);
12563 + DySetAopForce(readpage); /* force */
12564 + DySetAop(writepages);
12565 + DySetAop(set_page_dirty);
12566 + DySetAop(readpages);
12567 + DySetAop(write_begin);
12568 + DySetAop(write_end);
12570 + DySetAop(invalidatepage);
12571 + DySetAop(releasepage);
12572 + DySetAop(freepage);
12573 + /* this one will be changed according to an aufs mount option */
12574 + DySetAop(direct_IO);
12575 + DySetAop(migratepage);
12576 + DySetAop(isolate_page);
12577 + DySetAop(putback_page);
12578 + DySetAop(launder_page);
12579 + DySetAop(is_partially_uptodate);
12580 + DySetAop(is_dirty_writeback);
12581 + DySetAop(error_remove_page);
12582 + DySetAop(swap_activate);
12583 + DySetAop(swap_deactivate);
12585 + DyDbgSize(cnt, *h_aop);
12588 +/* ---------------------------------------------------------------------- */
12590 +static void dy_bug(struct kref *kref)
12595 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12597 + struct au_dykey *key, *old;
12598 + struct hlist_bl_head *hbl;
12601 + void (*set)(struct au_dykey *key, const void *h_op,
12602 + struct super_block *h_sb __maybe_unused);
12604 + static const struct op a[] = {
12606 + .sz = sizeof(struct au_dyaop),
12610 + const struct op *p;
12612 + hbl = dynop + op->dy_type;
12613 + key = dy_gfind_get(hbl, op->dy_hop);
12615 + goto out_add; /* success */
12617 + p = a + op->dy_type;
12618 + key = kzalloc(p->sz, GFP_NOFS);
12619 + if (unlikely(!key)) {
12620 + key = ERR_PTR(-ENOMEM);
12624 + key->dk_op.dy_hop = op->dy_hop;
12625 + kref_init(&key->dk_kref);
12626 + p->set(key, op->dy_hop, au_br_sb(br));
12627 + old = dy_gadd(hbl, key);
12634 + old = dy_bradd(br, key);
12636 + /* its ref-count should never be zero here */
12637 + kref_put(&key->dk_kref, dy_bug);
12642 +/* ---------------------------------------------------------------------- */
12644 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
12645 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12646 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12647 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12648 + * See the aufs manual in detail.
12650 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12653 + dyaop->da_op.direct_IO = NULL;
12655 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12658 +static struct au_dyaop *dy_aget(struct au_branch *br,
12659 + const struct address_space_operations *h_aop,
12662 + struct au_dyaop *dyaop;
12663 + struct au_dynop op;
12665 + op.dy_type = AuDy_AOP;
12666 + op.dy_haop = h_aop;
12667 + dyaop = (void *)dy_get(&op, br);
12668 + if (IS_ERR(dyaop))
12670 + dy_adx(dyaop, do_dx);
12676 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12677 + struct inode *h_inode)
12680 + struct super_block *sb;
12681 + struct au_branch *br;
12682 + struct au_dyaop *dyaop;
12684 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12685 + IiMustWriteLock(inode);
12687 + sb = inode->i_sb;
12688 + br = au_sbr(sb, bindex);
12689 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12690 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12691 + err = PTR_ERR(dyaop);
12692 + if (IS_ERR(dyaop))
12693 + /* unnecessary to call dy_fput() */
12697 + inode->i_mapping->a_ops = &dyaop->da_op;
12704 + * Is it safe to replace a_ops during the inode/file is in operation?
12705 + * Yes, I hope so.
12707 +int au_dy_irefresh(struct inode *inode)
12710 + aufs_bindex_t btop;
12711 + struct inode *h_inode;
12714 + if (S_ISREG(inode->i_mode)) {
12715 + btop = au_ibtop(inode);
12716 + h_inode = au_h_iptr(inode, btop);
12717 + err = au_dy_iaop(inode, btop, h_inode);
12722 +void au_dy_arefresh(int do_dx)
12724 + struct hlist_bl_head *hbl;
12725 + struct hlist_bl_node *pos;
12726 + struct au_dykey *key;
12728 + hbl = dynop + AuDy_AOP;
12729 + hlist_bl_lock(hbl);
12730 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12731 + dy_adx((void *)key, do_dx);
12732 + hlist_bl_unlock(hbl);
12735 +/* ---------------------------------------------------------------------- */
12737 +void __init au_dy_init(void)
12741 + /* make sure that 'struct au_dykey *' can be any type */
12742 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12744 + for (i = 0; i < AuDyLast; i++)
12745 + INIT_HLIST_BL_HEAD(dynop + i);
12748 +void au_dy_fin(void)
12752 + for (i = 0; i < AuDyLast; i++)
12753 + WARN_ON(!hlist_bl_empty(dynop + i));
12755 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12756 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12757 +++ linux/fs/aufs/dynop.h 2017-11-12 22:24:44.704244405 +0100
12760 + * Copyright (C) 2010-2017 Junjiro R. Okajima
12762 + * This program, aufs is free software; you can redistribute it and/or modify
12763 + * it under the terms of the GNU General Public License as published by
12764 + * the Free Software Foundation; either version 2 of the License, or
12765 + * (at your option) any later version.
12767 + * This program is distributed in the hope that it will be useful,
12768 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12769 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12770 + * GNU General Public License for more details.
12772 + * You should have received a copy of the GNU General Public License
12773 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12777 + * dynamically customizable operations (for regular files only)
12780 +#ifndef __AUFS_DYNOP_H__
12781 +#define __AUFS_DYNOP_H__
12785 +#include <linux/fs.h>
12786 +#include <linux/kref.h>
12788 +enum {AuDy_AOP, AuDyLast};
12793 + const void *dy_hop;
12794 + const struct address_space_operations *dy_haop;
12800 + struct hlist_bl_node dk_hnode;
12801 + struct rcu_head dk_rcu;
12803 + struct au_dynop dk_op;
12806 + * during I am in the branch local array, kref is gotten. when the
12807 + * branch is removed, kref is put.
12809 + struct kref dk_kref;
12812 +/* stop unioning since their sizes are very different from each other */
12814 + struct au_dykey da_key;
12815 + struct address_space_operations da_op; /* not const */
12818 +/* ---------------------------------------------------------------------- */
12822 +void au_dy_put(struct au_dykey *key);
12823 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12824 + struct inode *h_inode);
12825 +int au_dy_irefresh(struct inode *inode);
12826 +void au_dy_arefresh(int do_dio);
12828 +void __init au_dy_init(void);
12829 +void au_dy_fin(void);
12831 +#endif /* __KERNEL__ */
12832 +#endif /* __AUFS_DYNOP_H__ */
12833 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12834 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12835 +++ linux/fs/aufs/export.c 2017-11-12 22:24:42.267510077 +0100
12838 + * Copyright (C) 2005-2017 Junjiro R. Okajima
12840 + * This program, aufs is free software; you can redistribute it and/or modify
12841 + * it under the terms of the GNU General Public License as published by
12842 + * the Free Software Foundation; either version 2 of the License, or
12843 + * (at your option) any later version.
12845 + * This program is distributed in the hope that it will be useful,
12846 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12847 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12848 + * GNU General Public License for more details.
12850 + * You should have received a copy of the GNU General Public License
12851 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12858 +#include <linux/exportfs.h>
12859 +#include <linux/fs_struct.h>
12860 +#include <linux/namei.h>
12861 +#include <linux/nsproxy.h>
12862 +#include <linux/random.h>
12863 +#include <linux/writeback.h>
12867 +#ifdef CONFIG_AUFS_INO_T_64
12875 +static ino_t decode_ino(__u32 *a)
12879 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12881 +#ifdef CONFIG_AUFS_INO_T_64
12887 +static void encode_ino(__u32 *a, ino_t ino)
12893 +#ifdef CONFIG_AUFS_INO_T_64
12898 +/* NFS file handle */
12902 +#ifdef CONFIG_AUFS_INO_T_64
12903 + /* support 64bit inode number */
12916 + Fh_ino = Fh_ino1,
12917 + Fh_dir_ino = Fh_dir_ino1
12920 +static int au_test_anon(struct dentry *dentry)
12922 + /* note: read d_flags without d_lock */
12923 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12926 +int au_test_nfsd(void)
12929 + struct task_struct *tsk = current;
12930 + char comm[sizeof(tsk->comm)];
12933 + if (tsk->flags & PF_KTHREAD) {
12934 + get_task_comm(comm, tsk);
12935 + ret = !strcmp(comm, "nfsd");
12941 +/* ---------------------------------------------------------------------- */
12942 +/* inode generation external table */
12944 +void au_xigen_inc(struct inode *inode)
12949 + struct super_block *sb;
12950 + struct au_sbinfo *sbinfo;
12952 + sb = inode->i_sb;
12953 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12955 + sbinfo = au_sbi(sb);
12956 + pos = inode->i_ino;
12957 + pos *= sizeof(igen);
12958 + igen = inode->i_generation + 1;
12959 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12960 + sizeof(igen), &pos);
12961 + if (sz == sizeof(igen))
12962 + return; /* success */
12964 + if (unlikely(sz >= 0))
12965 + AuIOErr("xigen error (%zd)\n", sz);
12968 +int au_xigen_new(struct inode *inode)
12973 + struct super_block *sb;
12974 + struct au_sbinfo *sbinfo;
12975 + struct file *file;
12978 + /* todo: dirty, at mount time */
12979 + if (inode->i_ino == AUFS_ROOT_INO)
12981 + sb = inode->i_sb;
12982 + SiMustAnyLock(sb);
12983 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12987 + pos = inode->i_ino;
12988 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12989 + AuIOErr1("too large i%lld\n", pos);
12992 + pos *= sizeof(inode->i_generation);
12995 + sbinfo = au_sbi(sb);
12996 + file = sbinfo->si_xigen;
12999 + if (vfsub_f_size_read(file)
13000 + < pos + sizeof(inode->i_generation)) {
13001 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13002 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13003 + sizeof(inode->i_generation), &pos);
13005 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13006 + sizeof(inode->i_generation), &pos);
13007 + if (sz == sizeof(inode->i_generation))
13008 + goto out; /* success */
13011 + if (unlikely(sz >= 0)) {
13013 + AuIOErr("xigen error (%zd)\n", sz);
13020 +int au_xigen_set(struct super_block *sb, struct file *base)
13023 + struct au_sbinfo *sbinfo;
13024 + struct file *file;
13026 + SiMustWriteLock(sb);
13028 + sbinfo = au_sbi(sb);
13029 + file = au_xino_create2(base, sbinfo->si_xigen);
13030 + err = PTR_ERR(file);
13031 + if (IS_ERR(file))
13034 + if (sbinfo->si_xigen)
13035 + fput(sbinfo->si_xigen);
13036 + sbinfo->si_xigen = file;
13042 +void au_xigen_clr(struct super_block *sb)
13044 + struct au_sbinfo *sbinfo;
13046 + SiMustWriteLock(sb);
13048 + sbinfo = au_sbi(sb);
13049 + if (sbinfo->si_xigen) {
13050 + fput(sbinfo->si_xigen);
13051 + sbinfo->si_xigen = NULL;
13055 +/* ---------------------------------------------------------------------- */
13057 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13060 + struct dentry *dentry, *d;
13061 + struct inode *inode;
13062 + unsigned int sigen;
13065 + inode = ilookup(sb, ino);
13069 + dentry = ERR_PTR(-ESTALE);
13070 + sigen = au_sigen(sb);
13071 + if (unlikely(au_is_bad_inode(inode)
13072 + || IS_DEADDIR(inode)
13073 + || sigen != au_iigen(inode, NULL)))
13077 + if (!dir_ino || S_ISDIR(inode->i_mode))
13078 + dentry = d_find_alias(inode);
13080 + spin_lock(&inode->i_lock);
13081 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13082 + spin_lock(&d->d_lock);
13083 + if (!au_test_anon(d)
13084 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13085 + dentry = dget_dlock(d);
13086 + spin_unlock(&d->d_lock);
13089 + spin_unlock(&d->d_lock);
13091 + spin_unlock(&inode->i_lock);
13093 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13094 + /* need to refresh */
13102 + AuTraceErrPtr(dentry);
13106 +/* ---------------------------------------------------------------------- */
13108 +/* todo: dirty? */
13109 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13111 +struct au_compare_mnt_args {
13113 + struct super_block *sb;
13116 + struct vfsmount *mnt;
13119 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13121 + struct au_compare_mnt_args *a = arg;
13123 + if (mnt->mnt_sb != a->sb)
13125 + a->mnt = mntget(mnt);
13129 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13132 + struct path root;
13133 + struct au_compare_mnt_args args = {
13137 + get_fs_root(current->fs, &root);
13139 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13140 + rcu_read_unlock();
13143 + AuDebugOn(!args.mnt);
13147 +struct au_nfsd_si_lock {
13148 + unsigned int sigen;
13149 + aufs_bindex_t bindex, br_id;
13150 + unsigned char force_lock;
13153 +static int si_nfsd_read_lock(struct super_block *sb,
13154 + struct au_nfsd_si_lock *nsi_lock)
13157 + aufs_bindex_t bindex;
13159 + si_read_lock(sb, AuLock_FLUSH);
13161 + /* branch id may be wrapped around */
13163 + bindex = au_br_index(sb, nsi_lock->br_id);
13164 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13165 + goto out; /* success */
13169 + if (!nsi_lock->force_lock)
13170 + si_read_unlock(sb);
13173 + nsi_lock->bindex = bindex;
13177 +struct find_name_by_ino {
13178 + struct dir_context ctx;
13179 + int called, found;
13186 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13187 + loff_t offset, u64 ino, unsigned int d_type)
13189 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13193 + if (a->ino != ino)
13196 + memcpy(a->name, name, namelen);
13197 + a->namelen = namelen;
13202 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13203 + struct au_nfsd_si_lock *nsi_lock)
13205 + struct dentry *dentry, *parent;
13206 + struct file *file;
13207 + struct inode *dir;
13208 + struct find_name_by_ino arg = {
13210 + .actor = find_name_by_ino
13215 + parent = path->dentry;
13217 + si_read_unlock(parent->d_sb);
13218 + file = vfsub_dentry_open(path, au_dir_roflags);
13219 + dentry = (void *)file;
13220 + if (IS_ERR(file))
13223 + dentry = ERR_PTR(-ENOMEM);
13224 + arg.name = (void *)__get_free_page(GFP_NOFS);
13225 + if (unlikely(!arg.name))
13232 + err = vfsub_iterate_dir(file, &arg.ctx);
13233 + } while (!err && !arg.found && arg.called);
13234 + dentry = ERR_PTR(err);
13235 + if (unlikely(err))
13237 + /* instead of ENOENT */
13238 + dentry = ERR_PTR(-ESTALE);
13242 + /* do not call vfsub_lkup_one() */
13243 + dir = d_inode(parent);
13244 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13245 + AuTraceErrPtr(dentry);
13246 + if (IS_ERR(dentry))
13248 + AuDebugOn(au_test_anon(dentry));
13249 + if (unlikely(d_really_is_negative(dentry))) {
13251 + dentry = ERR_PTR(-ENOENT);
13255 + free_page((unsigned long)arg.name);
13259 + if (unlikely(nsi_lock
13260 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13261 + if (!IS_ERR(dentry)) {
13263 + dentry = ERR_PTR(-ESTALE);
13265 + AuTraceErrPtr(dentry);
13269 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13271 + struct au_nfsd_si_lock *nsi_lock)
13273 + struct dentry *dentry;
13274 + struct path path;
13276 + if (dir_ino != AUFS_ROOT_INO) {
13277 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13278 + dentry = path.dentry;
13279 + if (!path.dentry || IS_ERR(path.dentry))
13281 + AuDebugOn(au_test_anon(path.dentry));
13283 + path.dentry = dget(sb->s_root);
13285 + path.mnt = au_mnt_get(sb);
13286 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13290 + AuTraceErrPtr(dentry);
13294 +/* ---------------------------------------------------------------------- */
13296 +static int h_acceptable(void *expv, struct dentry *dentry)
13301 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13302 + char *buf, int len, struct super_block *sb)
13306 + struct path path;
13308 + p = d_path(h_rootpath, buf, len);
13313 + path.mnt = h_rootpath->mnt;
13314 + path.dentry = h_parent;
13315 + p = d_path(&path, buf, len);
13321 + path.mnt = au_mnt_get(sb);
13322 + path.dentry = sb->s_root;
13323 + p = d_path(&path, buf, len - strlen(p));
13324 + mntput(path.mnt);
13328 + p[strlen(p)] = '/';
13331 + AuTraceErrPtr(p);
13336 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13337 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13339 + struct dentry *dentry, *h_parent, *root;
13340 + struct super_block *h_sb;
13341 + char *pathname, *p;
13342 + struct vfsmount *h_mnt;
13343 + struct au_branch *br;
13345 + struct path path;
13347 + br = au_sbr(sb, nsi_lock->bindex);
13348 + h_mnt = au_br_mnt(br);
13349 + h_sb = h_mnt->mnt_sb;
13350 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13352 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13353 + fh_len - Fh_tail, fh[Fh_h_type],
13354 + h_acceptable, /*context*/NULL);
13356 + dentry = h_parent;
13357 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13358 + AuWarn1("%s decode_fh failed, %ld\n",
13359 + au_sbtype(h_sb), PTR_ERR(h_parent));
13363 + if (unlikely(au_test_anon(h_parent))) {
13364 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13365 + au_sbtype(h_sb));
13366 + goto out_h_parent;
13369 + dentry = ERR_PTR(-ENOMEM);
13370 + pathname = (void *)__get_free_page(GFP_NOFS);
13371 + if (unlikely(!pathname))
13372 + goto out_h_parent;
13374 + root = sb->s_root;
13375 + path.mnt = h_mnt;
13376 + di_read_lock_parent(root, !AuLock_IR);
13377 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13378 + di_read_unlock(root, !AuLock_IR);
13379 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13380 + dentry = (void *)p;
13382 + goto out_pathname;
13384 + si_read_unlock(sb);
13385 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13386 + dentry = ERR_PTR(err);
13387 + if (unlikely(err))
13390 + dentry = ERR_PTR(-ENOENT);
13391 + AuDebugOn(au_test_anon(path.dentry));
13392 + if (unlikely(d_really_is_negative(path.dentry)))
13395 + if (ino != d_inode(path.dentry)->i_ino)
13396 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13398 + dentry = dget(path.dentry);
13403 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13404 + if (!IS_ERR(dentry)) {
13406 + dentry = ERR_PTR(-ESTALE);
13409 + free_page((unsigned long)pathname);
13413 + AuTraceErrPtr(dentry);
13417 +/* ---------------------------------------------------------------------- */
13419 +static struct dentry *
13420 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13423 + struct dentry *dentry;
13424 + __u32 *fh = fid->raw;
13425 + struct au_branch *br;
13426 + ino_t ino, dir_ino;
13427 + struct au_nfsd_si_lock nsi_lock = {
13431 + dentry = ERR_PTR(-ESTALE);
13432 + /* it should never happen, but the file handle is unreliable */
13433 + if (unlikely(fh_len < Fh_tail))
13435 + nsi_lock.sigen = fh[Fh_sigen];
13436 + nsi_lock.br_id = fh[Fh_br_id];
13438 + /* branch id may be wrapped around */
13440 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13442 + nsi_lock.force_lock = 1;
13444 + /* is this inode still cached? */
13445 + ino = decode_ino(fh + Fh_ino);
13446 + /* it should never happen */
13447 + if (unlikely(ino == AUFS_ROOT_INO))
13450 + dir_ino = decode_ino(fh + Fh_dir_ino);
13451 + dentry = decode_by_ino(sb, ino, dir_ino);
13452 + if (IS_ERR(dentry))
13457 + /* is the parent dir cached? */
13458 + br = au_sbr(sb, nsi_lock.bindex);
13460 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13461 + if (IS_ERR(dentry))
13466 + /* lookup path */
13467 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13468 + if (IS_ERR(dentry))
13470 + if (unlikely(!dentry))
13471 + /* todo?: make it ESTALE */
13475 + if (!au_digen_test(dentry, au_sigen(sb))
13476 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13477 + goto out_unlock; /* success */
13480 + dentry = ERR_PTR(-ESTALE);
13484 + si_read_unlock(sb);
13486 + AuTraceErrPtr(dentry);
13490 +#if 0 /* reserved for future use */
13491 +/* support subtreecheck option */
13492 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13493 + int fh_len, int fh_type)
13495 + struct dentry *parent;
13496 + __u32 *fh = fid->raw;
13499 + dir_ino = decode_ino(fh + Fh_dir_ino);
13500 + parent = decode_by_ino(sb, dir_ino, 0);
13501 + if (IS_ERR(parent))
13504 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13505 + dir_ino, fh, fh_len);
13508 + AuTraceErrPtr(parent);
13513 +/* ---------------------------------------------------------------------- */
13515 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13516 + struct inode *dir)
13519 + aufs_bindex_t bindex;
13520 + struct super_block *sb, *h_sb;
13521 + struct dentry *dentry, *parent, *h_parent;
13522 + struct inode *h_dir;
13523 + struct au_branch *br;
13526 + if (unlikely(*max_len <= Fh_tail)) {
13527 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13531 + err = FILEID_ROOT;
13532 + if (inode->i_ino == AUFS_ROOT_INO) {
13533 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13538 + sb = inode->i_sb;
13539 + err = si_read_lock(sb, AuLock_FLUSH);
13540 + if (unlikely(err))
13543 +#ifdef CONFIG_AUFS_DEBUG
13544 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13545 + AuWarn1("NFS-exporting requires xino\n");
13549 + ii_read_lock_child(inode);
13550 + bindex = au_ibtop(inode);
13552 + dentry = d_find_any_alias(inode);
13553 + if (unlikely(!dentry))
13555 + AuDebugOn(au_test_anon(dentry));
13556 + parent = dget_parent(dentry);
13558 + if (unlikely(!parent))
13560 + if (d_really_is_positive(parent))
13561 + dir = d_inode(parent);
13564 + ii_read_lock_parent(dir);
13565 + h_dir = au_h_iptr(dir, bindex);
13566 + ii_read_unlock(dir);
13567 + if (unlikely(!h_dir))
13569 + h_parent = d_find_any_alias(h_dir);
13570 + if (unlikely(!h_parent))
13571 + goto out_hparent;
13574 + br = au_sbr(sb, bindex);
13575 + h_sb = au_br_sb(br);
13576 + if (unlikely(!h_sb->s_export_op)) {
13577 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13578 + goto out_hparent;
13581 + fh[Fh_br_id] = br->br_id;
13582 + fh[Fh_sigen] = au_sigen(sb);
13583 + encode_ino(fh + Fh_ino, inode->i_ino);
13584 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13585 + fh[Fh_igen] = inode->i_generation;
13587 + *max_len -= Fh_tail;
13588 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13590 + /*connectable or subtreecheck*/0);
13591 + err = fh[Fh_h_type];
13592 + *max_len += Fh_tail;
13593 + /* todo: macros? */
13594 + if (err != FILEID_INVALID)
13597 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13604 + ii_read_unlock(inode);
13605 + si_read_unlock(sb);
13607 + if (unlikely(err < 0))
13608 + err = FILEID_INVALID;
13612 +/* ---------------------------------------------------------------------- */
13614 +static int aufs_commit_metadata(struct inode *inode)
13617 + aufs_bindex_t bindex;
13618 + struct super_block *sb;
13619 + struct inode *h_inode;
13620 + int (*f)(struct inode *inode);
13622 + sb = inode->i_sb;
13623 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13624 + ii_write_lock_child(inode);
13625 + bindex = au_ibtop(inode);
13626 + AuDebugOn(bindex < 0);
13627 + h_inode = au_h_iptr(inode, bindex);
13629 + f = h_inode->i_sb->s_export_op->commit_metadata;
13631 + err = f(h_inode);
13633 + struct writeback_control wbc = {
13634 + .sync_mode = WB_SYNC_ALL,
13635 + .nr_to_write = 0 /* metadata only */
13638 + err = sync_inode(h_inode, &wbc);
13641 + au_cpup_attr_timesizes(inode);
13642 + ii_write_unlock(inode);
13643 + si_read_unlock(sb);
13647 +/* ---------------------------------------------------------------------- */
13649 +static struct export_operations aufs_export_op = {
13650 + .fh_to_dentry = aufs_fh_to_dentry,
13651 + /* .fh_to_parent = aufs_fh_to_parent, */
13652 + .encode_fh = aufs_encode_fh,
13653 + .commit_metadata = aufs_commit_metadata
13656 +void au_export_init(struct super_block *sb)
13658 + struct au_sbinfo *sbinfo;
13661 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13662 + && IS_MODULE(CONFIG_EXPORTFS),
13663 + AUFS_NAME ": unsupported configuration "
13664 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13666 + sb->s_export_op = &aufs_export_op;
13667 + sbinfo = au_sbi(sb);
13668 + sbinfo->si_xigen = NULL;
13669 + get_random_bytes(&u, sizeof(u));
13670 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13671 + atomic_set(&sbinfo->si_xigen_next, u);
13673 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13674 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13675 +++ linux/fs/aufs/fhsm.c 2017-07-29 12:14:25.903042072 +0200
13678 + * Copyright (C) 2011-2017 Junjiro R. Okajima
13680 + * This program, aufs is free software; you can redistribute it and/or modify
13681 + * it under the terms of the GNU General Public License as published by
13682 + * the Free Software Foundation; either version 2 of the License, or
13683 + * (at your option) any later version.
13685 + * This program is distributed in the hope that it will be useful,
13686 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13687 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13688 + * GNU General Public License for more details.
13690 + * You should have received a copy of the GNU General Public License
13691 + * along with this program; if not, write to the Free Software
13692 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13696 + * File-based Hierarchy Storage Management
13699 +#include <linux/anon_inodes.h>
13700 +#include <linux/poll.h>
13701 +#include <linux/seq_file.h>
13702 +#include <linux/statfs.h>
13705 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13707 + struct au_sbinfo *sbinfo;
13708 + struct au_fhsm *fhsm;
13710 + SiMustAnyLock(sb);
13712 + sbinfo = au_sbi(sb);
13713 + fhsm = &sbinfo->si_fhsm;
13714 + AuDebugOn(!fhsm);
13715 + return fhsm->fhsm_bottom;
13718 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13720 + struct au_sbinfo *sbinfo;
13721 + struct au_fhsm *fhsm;
13723 + SiMustWriteLock(sb);
13725 + sbinfo = au_sbi(sb);
13726 + fhsm = &sbinfo->si_fhsm;
13727 + AuDebugOn(!fhsm);
13728 + fhsm->fhsm_bottom = bindex;
13731 +/* ---------------------------------------------------------------------- */
13733 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13735 + struct au_br_fhsm *bf;
13737 + bf = br->br_fhsm;
13738 + MtxMustLock(&bf->bf_lock);
13740 + return !bf->bf_readable
13741 + || time_after(jiffies,
13742 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13745 +/* ---------------------------------------------------------------------- */
13747 +static void au_fhsm_notify(struct super_block *sb, int val)
13749 + struct au_sbinfo *sbinfo;
13750 + struct au_fhsm *fhsm;
13752 + SiMustAnyLock(sb);
13754 + sbinfo = au_sbi(sb);
13755 + fhsm = &sbinfo->si_fhsm;
13756 + if (au_fhsm_pid(fhsm)
13757 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13758 + atomic_set(&fhsm->fhsm_readable, val);
13760 + wake_up(&fhsm->fhsm_wqh);
13764 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13765 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13768 + struct au_branch *br;
13769 + struct au_br_fhsm *bf;
13771 + br = au_sbr(sb, bindex);
13772 + AuDebugOn(au_br_rdonly(br));
13773 + bf = br->br_fhsm;
13777 + mutex_lock(&bf->bf_lock);
13779 + MtxMustLock(&bf->bf_lock);
13781 + /* sb->s_root for NFS is unreliable */
13782 + err = au_br_stfs(br, &bf->bf_stfs);
13783 + if (unlikely(err)) {
13784 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13788 + bf->bf_jiffy = jiffies;
13789 + bf->bf_readable = 1;
13791 + au_fhsm_notify(sb, /*val*/1);
13793 + *rstfs = bf->bf_stfs;
13797 + mutex_unlock(&bf->bf_lock);
13798 + au_fhsm_notify(sb, /*val*/1);
13803 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13806 + struct au_sbinfo *sbinfo;
13807 + struct au_fhsm *fhsm;
13808 + struct au_branch *br;
13809 + struct au_br_fhsm *bf;
13811 + AuDbg("b%d, force %d\n", bindex, force);
13812 + SiMustAnyLock(sb);
13814 + sbinfo = au_sbi(sb);
13815 + fhsm = &sbinfo->si_fhsm;
13816 + if (!au_ftest_si(sbinfo, FHSM)
13817 + || fhsm->fhsm_bottom == bindex)
13820 + br = au_sbr(sb, bindex);
13821 + bf = br->br_fhsm;
13823 + mutex_lock(&bf->bf_lock);
13825 + || au_fhsm_pid(fhsm)
13826 + || au_fhsm_test_jiffy(sbinfo, br))
13827 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13829 + mutex_unlock(&bf->bf_lock);
13832 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13834 + aufs_bindex_t bindex, bbot;
13835 + struct au_branch *br;
13837 + /* exclude the bottom */
13838 + bbot = au_fhsm_bottom(sb);
13839 + for (bindex = 0; bindex < bbot; bindex++) {
13840 + br = au_sbr(sb, bindex);
13841 + if (au_br_fhsm(br->br_perm))
13842 + au_fhsm_wrote(sb, bindex, force);
13846 +/* ---------------------------------------------------------------------- */
13848 +static unsigned int au_fhsm_poll(struct file *file,
13849 + struct poll_table_struct *wait)
13851 + unsigned int mask;
13852 + struct au_sbinfo *sbinfo;
13853 + struct au_fhsm *fhsm;
13856 + sbinfo = file->private_data;
13857 + fhsm = &sbinfo->si_fhsm;
13858 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13859 + if (atomic_read(&fhsm->fhsm_readable))
13860 + mask = POLLIN /* | POLLRDNORM */;
13862 + AuTraceErr((int)mask);
13866 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13867 + struct aufs_stfs *stfs, __s16 brid)
13871 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13873 + err = __put_user(brid, &stbr->brid);
13874 + if (unlikely(err))
13880 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13881 + struct aufs_stbr __user *stbr, size_t count)
13885 + aufs_bindex_t bindex, bbot;
13886 + struct au_branch *br;
13887 + struct au_br_fhsm *bf;
13889 + /* except the bottom branch */
13892 + bbot = au_fhsm_bottom(sb);
13893 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13894 + br = au_sbr(sb, bindex);
13895 + if (!au_br_fhsm(br->br_perm))
13898 + bf = br->br_fhsm;
13899 + mutex_lock(&bf->bf_lock);
13900 + if (bf->bf_readable) {
13902 + if (count >= sizeof(*stbr))
13903 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13906 + bf->bf_readable = 0;
13907 + count -= sizeof(*stbr);
13911 + mutex_unlock(&bf->bf_lock);
13914 + err = sizeof(*stbr) * nstbr;
13919 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13924 + aufs_bindex_t nfhsm, bindex, bbot;
13925 + struct au_sbinfo *sbinfo;
13926 + struct au_fhsm *fhsm;
13927 + struct au_branch *br;
13928 + struct super_block *sb;
13931 + sbinfo = file->private_data;
13932 + fhsm = &sbinfo->si_fhsm;
13934 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13935 + if (!atomic_read(&fhsm->fhsm_readable)) {
13936 + if (vfsub_file_flags(file) & O_NONBLOCK)
13939 + err = wait_event_interruptible_locked_irq
13941 + atomic_read(&fhsm->fhsm_readable));
13943 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13944 + if (unlikely(err))
13947 + /* sb may already be dead */
13948 + au_rw_read_lock(&sbinfo->si_rwsem);
13949 + readable = atomic_read(&fhsm->fhsm_readable);
13950 + if (readable > 0) {
13951 + sb = sbinfo->si_sb;
13953 + /* exclude the bottom branch */
13955 + bbot = au_fhsm_bottom(sb);
13956 + for (bindex = 0; bindex < bbot; bindex++) {
13957 + br = au_sbr(sb, bindex);
13958 + if (au_br_fhsm(br->br_perm))
13962 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13963 + atomic_set(&fhsm->fhsm_readable, 0);
13964 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13968 + au_rw_read_unlock(&sbinfo->si_rwsem);
13976 +static int au_fhsm_release(struct inode *inode, struct file *file)
13978 + struct au_sbinfo *sbinfo;
13979 + struct au_fhsm *fhsm;
13981 + /* sb may already be dead */
13982 + sbinfo = file->private_data;
13983 + fhsm = &sbinfo->si_fhsm;
13984 + spin_lock(&fhsm->fhsm_spin);
13985 + fhsm->fhsm_pid = 0;
13986 + spin_unlock(&fhsm->fhsm_spin);
13987 + kobject_put(&sbinfo->si_kobj);
13992 +static const struct file_operations au_fhsm_fops = {
13993 + .owner = THIS_MODULE,
13994 + .llseek = noop_llseek,
13995 + .read = au_fhsm_read,
13996 + .poll = au_fhsm_poll,
13997 + .release = au_fhsm_release
14000 +int au_fhsm_fd(struct super_block *sb, int oflags)
14003 + struct au_sbinfo *sbinfo;
14004 + struct au_fhsm *fhsm;
14007 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14011 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14015 + sbinfo = au_sbi(sb);
14016 + fhsm = &sbinfo->si_fhsm;
14017 + spin_lock(&fhsm->fhsm_spin);
14018 + if (!fhsm->fhsm_pid)
14019 + fhsm->fhsm_pid = current->pid;
14022 + spin_unlock(&fhsm->fhsm_spin);
14023 + if (unlikely(err))
14026 + oflags |= O_RDONLY;
14027 + /* oflags |= FMODE_NONOTIFY; */
14028 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14030 + if (unlikely(fd < 0))
14033 + /* succeed reglardless 'fhsm' status */
14034 + kobject_get(&sbinfo->si_kobj);
14035 + si_noflush_read_lock(sb);
14036 + if (au_ftest_si(sbinfo, FHSM))
14037 + au_fhsm_wrote_all(sb, /*force*/0);
14038 + si_read_unlock(sb);
14039 + goto out; /* success */
14042 + spin_lock(&fhsm->fhsm_spin);
14043 + fhsm->fhsm_pid = 0;
14044 + spin_unlock(&fhsm->fhsm_spin);
14050 +/* ---------------------------------------------------------------------- */
14052 +int au_fhsm_br_alloc(struct au_branch *br)
14057 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14059 + au_br_fhsm_init(br->br_fhsm);
14066 +/* ---------------------------------------------------------------------- */
14068 +void au_fhsm_fin(struct super_block *sb)
14070 + au_fhsm_notify(sb, /*val*/-1);
14073 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14075 + struct au_fhsm *fhsm;
14077 + fhsm = &sbinfo->si_fhsm;
14078 + spin_lock_init(&fhsm->fhsm_spin);
14079 + init_waitqueue_head(&fhsm->fhsm_wqh);
14080 + atomic_set(&fhsm->fhsm_readable, 0);
14081 + fhsm->fhsm_expire
14082 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14083 + fhsm->fhsm_bottom = -1;
14086 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14088 + sbinfo->si_fhsm.fhsm_expire
14089 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14092 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14096 + if (!au_ftest_si(sbinfo, FHSM))
14099 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14100 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14101 + seq_printf(seq, ",fhsm_sec=%u", u);
14103 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14104 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14105 +++ linux/fs/aufs/file.c 2017-11-12 22:24:44.704244405 +0100
14108 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14110 + * This program, aufs is free software; you can redistribute it and/or modify
14111 + * it under the terms of the GNU General Public License as published by
14112 + * the Free Software Foundation; either version 2 of the License, or
14113 + * (at your option) any later version.
14115 + * This program is distributed in the hope that it will be useful,
14116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14118 + * GNU General Public License for more details.
14120 + * You should have received a copy of the GNU General Public License
14121 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14125 + * handling file/dir, and address_space operation
14128 +#ifdef CONFIG_AUFS_DEBUG
14129 +#include <linux/migrate.h>
14131 +#include <linux/pagemap.h>
14134 +/* drop flags for writing */
14135 +unsigned int au_file_roflags(unsigned int flags)
14137 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14138 + flags |= O_RDONLY | O_NOATIME;
14142 +/* common functions to regular file and dir */
14143 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14144 + struct file *file, int force_wr)
14146 + struct file *h_file;
14147 + struct dentry *h_dentry;
14148 + struct inode *h_inode;
14149 + struct super_block *sb;
14150 + struct au_branch *br;
14151 + struct path h_path;
14154 + /* a race condition can happen between open and unlink/rmdir */
14155 + h_file = ERR_PTR(-ENOENT);
14156 + h_dentry = au_h_dptr(dentry, bindex);
14157 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14159 + h_inode = d_inode(h_dentry);
14160 + spin_lock(&h_dentry->d_lock);
14161 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14162 + /* || !d_inode(dentry)->i_nlink */
14164 + spin_unlock(&h_dentry->d_lock);
14165 + if (unlikely(err))
14168 + sb = dentry->d_sb;
14169 + br = au_sbr(sb, bindex);
14170 + err = au_br_test_oflag(flags, br);
14171 + h_file = ERR_PTR(err);
14172 + if (unlikely(err))
14175 + /* drop flags for writing */
14176 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14177 + if (force_wr && !(flags & O_WRONLY))
14179 + flags = au_file_roflags(flags);
14181 + h_file = ERR_PTR(-EROFS);
14182 + flags = au_file_roflags(flags);
14183 + if (unlikely(vfsub_native_ro(h_inode)
14184 + || IS_APPEND(h_inode)))
14186 + flags &= ~O_ACCMODE;
14187 + flags |= O_WRONLY;
14190 + flags &= ~O_CREAT;
14192 + h_path.dentry = h_dentry;
14193 + h_path.mnt = au_br_mnt(br);
14194 + h_file = vfsub_dentry_open(&h_path, flags);
14195 + if (IS_ERR(h_file))
14198 + if (flags & __FMODE_EXEC) {
14199 + err = deny_write_access(h_file);
14200 + if (unlikely(err)) {
14202 + h_file = ERR_PTR(err);
14206 + fsnotify_open(h_file);
14207 + goto out; /* success */
14215 +static int au_cmoo(struct dentry *dentry)
14217 + int err, cmoo, matched;
14218 + unsigned int udba;
14219 + struct path h_path;
14220 + struct au_pin pin;
14221 + struct au_cp_generic cpg = {
14222 + .dentry = dentry,
14227 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14229 + struct inode *delegated;
14230 + struct super_block *sb;
14231 + struct au_sbinfo *sbinfo;
14232 + struct au_fhsm *fhsm;
14234 + struct au_branch *br;
14235 + struct dentry *parent;
14236 + struct au_hinode *hdir;
14238 + DiMustWriteLock(dentry);
14239 + IiMustWriteLock(d_inode(dentry));
14242 + if (IS_ROOT(dentry))
14244 + cpg.bsrc = au_dbtop(dentry);
14248 + sb = dentry->d_sb;
14249 + sbinfo = au_sbi(sb);
14250 + fhsm = &sbinfo->si_fhsm;
14251 + pid = au_fhsm_pid(fhsm);
14254 + && (current->pid == pid
14255 + || rcu_dereference(current->real_parent)->pid == pid));
14256 + rcu_read_unlock();
14260 + br = au_sbr(sb, cpg.bsrc);
14261 + cmoo = au_br_cmoo(br->br_perm);
14264 + if (!d_is_reg(dentry))
14265 + cmoo &= AuBrAttr_COO_ALL;
14269 + parent = dget_parent(dentry);
14270 + di_write_lock_parent(parent);
14271 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14273 + if (unlikely(err < 0)) {
14274 + err = 0; /* there is no upper writable branch */
14277 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14279 + /* do not respect the coo attrib for the target branch */
14280 + err = au_cpup_dirs(dentry, cpg.bdst);
14281 + if (unlikely(err))
14284 + di_downgrade_lock(parent, AuLock_IR);
14285 + udba = au_opt_udba(sb);
14286 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14287 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14288 + if (unlikely(err))
14291 + err = au_sio_cpup_simple(&cpg);
14293 + if (unlikely(err))
14295 + if (!(cmoo & AuBrWAttr_MOO))
14296 + goto out_parent; /* success */
14298 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14299 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14300 + if (unlikely(err))
14303 + h_path.mnt = au_br_mnt(br);
14304 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14305 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14306 + delegated = NULL;
14307 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14309 + /* todo: keep h_dentry or not? */
14310 + if (unlikely(err == -EWOULDBLOCK)) {
14311 + pr_warn("cannot retry for NFSv4 delegation"
14312 + " for an internal unlink\n");
14315 + if (unlikely(err)) {
14316 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14320 + goto out_parent; /* success */
14323 + di_downgrade_lock(parent, AuLock_IR);
14325 + di_read_unlock(parent, AuLock_IR);
14332 +int au_do_open(struct file *file, struct au_do_open_args *args)
14334 + int err, aopen = args->aopen;
14335 + struct dentry *dentry;
14336 + struct au_finfo *finfo;
14339 + err = au_finfo_init(file, args->fidir);
14342 + err = au_finfo_init(file, args->fidir);
14345 + if (unlikely(err))
14348 + dentry = file->f_path.dentry;
14349 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14350 + di_write_lock_child(dentry);
14351 + err = au_cmoo(dentry);
14352 + di_downgrade_lock(dentry, AuLock_IR);
14355 + err = args->open(file, vfsub_file_flags(file), NULL);
14358 + err = args->open(file, vfsub_file_flags(file), NULL);
14362 + di_read_unlock(dentry, AuLock_IR);
14364 + finfo = au_fi(file);
14366 + finfo->fi_file = file;
14367 + au_hbl_add(&finfo->fi_hlist,
14368 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14371 + fi_write_unlock(file);
14374 + fi_write_unlock(file);
14377 + if (unlikely(err)) {
14378 + finfo->fi_hdir = NULL;
14379 + au_finfo_fin(file);
14387 +int au_reopen_nondir(struct file *file)
14390 + aufs_bindex_t btop;
14391 + struct dentry *dentry;
14392 + struct file *h_file, *h_file_tmp;
14394 + dentry = file->f_path.dentry;
14395 + btop = au_dbtop(dentry);
14396 + h_file_tmp = NULL;
14397 + if (au_fbtop(file) == btop) {
14398 + h_file = au_hf_top(file);
14399 + if (file->f_mode == h_file->f_mode)
14400 + return 0; /* success */
14401 + h_file_tmp = h_file;
14402 + get_file(h_file_tmp);
14403 + au_set_h_fptr(file, btop, NULL);
14405 + AuDebugOn(au_fi(file)->fi_hdir);
14408 + * file exists on both of rw and ro
14409 + * open --> dbtop and fbtop are both 0
14410 + * prepend a branch as rw, "rw" become ro
14412 + * delete the top branch, "rw" becomes rw again
14413 + * --> dbtop is 1, fbtop is still 0
14414 + * write --> fbtop is 0 but dbtop is 1
14416 + /* AuDebugOn(au_fbtop(file) < btop); */
14418 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14419 + file, /*force_wr*/0);
14420 + err = PTR_ERR(h_file);
14421 + if (IS_ERR(h_file)) {
14422 + if (h_file_tmp) {
14423 + au_sbr_get(dentry->d_sb, btop);
14424 + au_set_h_fptr(file, btop, h_file_tmp);
14425 + h_file_tmp = NULL;
14427 + goto out; /* todo: close all? */
14431 + au_set_fbtop(file, btop);
14432 + au_set_h_fptr(file, btop, h_file);
14433 + au_update_figen(file);
14434 + /* todo: necessary? */
14435 + /* file->f_ra = h_file->f_ra; */
14439 + fput(h_file_tmp);
14443 +/* ---------------------------------------------------------------------- */
14445 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14446 + struct dentry *hi_wh)
14449 + aufs_bindex_t btop;
14450 + struct au_dinfo *dinfo;
14451 + struct dentry *h_dentry;
14452 + struct au_hdentry *hdp;
14454 + dinfo = au_di(file->f_path.dentry);
14455 + AuRwMustWriteLock(&dinfo->di_rwsem);
14457 + btop = dinfo->di_btop;
14458 + dinfo->di_btop = btgt;
14459 + hdp = au_hdentry(dinfo, btgt);
14460 + h_dentry = hdp->hd_dentry;
14461 + hdp->hd_dentry = hi_wh;
14462 + err = au_reopen_nondir(file);
14463 + hdp->hd_dentry = h_dentry;
14464 + dinfo->di_btop = btop;
14469 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14470 + aufs_bindex_t bcpup, struct au_pin *pin)
14473 + struct inode *inode, *h_inode;
14474 + struct dentry *h_dentry, *hi_wh;
14475 + struct au_cp_generic cpg = {
14476 + .dentry = file->f_path.dentry,
14483 + au_update_dbtop(cpg.dentry);
14484 + inode = d_inode(cpg.dentry);
14486 + if (au_dbtop(cpg.dentry) <= bcpup
14487 + && au_dbbot(cpg.dentry) >= bcpup) {
14488 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14489 + if (h_dentry && d_is_positive(h_dentry))
14490 + h_inode = d_inode(h_dentry);
14492 + hi_wh = au_hi_wh(inode, bcpup);
14493 + if (!hi_wh && !h_inode)
14494 + err = au_sio_cpup_wh(&cpg, file);
14496 + /* already copied-up after unlink */
14497 + err = au_reopen_wh(file, bcpup, hi_wh);
14500 + && (inode->i_nlink > 1
14501 + || (inode->i_state & I_LINKABLE))
14502 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14503 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14509 + * prepare the @file for writing.
14511 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14514 + aufs_bindex_t dbtop;
14515 + struct dentry *parent;
14516 + struct inode *inode;
14517 + struct super_block *sb;
14518 + struct file *h_file;
14519 + struct au_cp_generic cpg = {
14520 + .dentry = file->f_path.dentry,
14525 + .flags = AuCpup_DTIME
14528 + sb = cpg.dentry->d_sb;
14529 + inode = d_inode(cpg.dentry);
14530 + cpg.bsrc = au_fbtop(file);
14531 + err = au_test_ro(sb, cpg.bsrc, inode);
14532 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14533 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14538 + /* need to cpup or reopen */
14539 + parent = dget_parent(cpg.dentry);
14540 + di_write_lock_parent(parent);
14541 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14543 + if (unlikely(err < 0))
14547 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14548 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14549 + if (unlikely(err))
14553 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14554 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14555 + if (unlikely(err))
14558 + dbtop = au_dbtop(cpg.dentry);
14559 + if (dbtop <= cpg.bdst)
14560 + cpg.bsrc = cpg.bdst;
14562 + if (dbtop <= cpg.bdst /* just reopen */
14563 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14565 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14566 + if (IS_ERR(h_file))
14567 + err = PTR_ERR(h_file);
14569 + di_downgrade_lock(parent, AuLock_IR);
14570 + if (dbtop > cpg.bdst)
14571 + err = au_sio_cpup_simple(&cpg);
14573 + err = au_reopen_nondir(file);
14574 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14576 + } else { /* copyup as wh and reopen */
14578 + * since writable hfsplus branch is not supported,
14579 + * h_open_pre/post() are unnecessary.
14581 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14582 + di_downgrade_lock(parent, AuLock_IR);
14586 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14587 + goto out_dput; /* success */
14593 + di_downgrade_lock(parent, AuLock_IR);
14595 + di_read_unlock(parent, AuLock_IR);
14602 +/* ---------------------------------------------------------------------- */
14604 +int au_do_flush(struct file *file, fl_owner_t id,
14605 + int (*flush)(struct file *file, fl_owner_t id))
14608 + struct super_block *sb;
14609 + struct inode *inode;
14611 + inode = file_inode(file);
14612 + sb = inode->i_sb;
14613 + si_noflush_read_lock(sb);
14614 + fi_read_lock(file);
14615 + ii_read_lock_child(inode);
14617 + err = flush(file, id);
14618 + au_cpup_attr_timesizes(inode);
14620 + ii_read_unlock(inode);
14621 + fi_read_unlock(file);
14622 + si_read_unlock(sb);
14626 +/* ---------------------------------------------------------------------- */
14628 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14631 + struct au_pin pin;
14632 + struct au_finfo *finfo;
14633 + struct dentry *parent, *hi_wh;
14634 + struct inode *inode;
14635 + struct super_block *sb;
14636 + struct au_cp_generic cpg = {
14637 + .dentry = file->f_path.dentry,
14642 + .flags = AuCpup_DTIME
14645 + FiMustWriteLock(file);
14648 + finfo = au_fi(file);
14649 + sb = cpg.dentry->d_sb;
14650 + inode = d_inode(cpg.dentry);
14651 + cpg.bdst = au_ibtop(inode);
14652 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14655 + parent = dget_parent(cpg.dentry);
14656 + if (au_test_ro(sb, cpg.bdst, inode)) {
14657 + di_read_lock_parent(parent, !AuLock_IR);
14658 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14660 + di_read_unlock(parent, !AuLock_IR);
14661 + if (unlikely(err < 0))
14666 + di_read_lock_parent(parent, AuLock_IR);
14667 + hi_wh = au_hi_wh(inode, cpg.bdst);
14668 + if (!S_ISDIR(inode->i_mode)
14669 + && au_opt_test(au_mntflags(sb), PLINK)
14670 + && au_plink_test(inode)
14671 + && !d_unhashed(cpg.dentry)
14672 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14673 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14674 + if (unlikely(err))
14677 + /* always superio. */
14678 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14679 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14681 + err = au_sio_cpup_simple(&cpg);
14684 + } else if (hi_wh) {
14685 + /* already copied-up after unlink */
14686 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14687 + *need_reopen = 0;
14691 + di_read_unlock(parent, AuLock_IR);
14698 +static void au_do_refresh_dir(struct file *file)
14700 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14701 + struct au_hfile *p, tmp, *q;
14702 + struct au_finfo *finfo;
14703 + struct super_block *sb;
14704 + struct au_fidir *fidir;
14706 + FiMustWriteLock(file);
14708 + sb = file->f_path.dentry->d_sb;
14709 + finfo = au_fi(file);
14710 + fidir = finfo->fi_hdir;
14711 + AuDebugOn(!fidir);
14712 + p = fidir->fd_hfile + finfo->fi_btop;
14713 + brid = p->hf_br->br_id;
14714 + bbot = fidir->fd_bbot;
14715 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14719 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14720 + if (new_bindex == bindex)
14722 + if (new_bindex < 0) {
14723 + au_set_h_fptr(file, bindex, NULL);
14727 + /* swap two lower inode, and loop again */
14728 + q = fidir->fd_hfile + new_bindex;
14732 + if (tmp.hf_file) {
14738 + p = fidir->fd_hfile;
14739 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14740 + bbot = au_sbbot(sb);
14741 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14742 + finfo->fi_btop++, p++)
14743 + if (p->hf_file) {
14744 + if (file_inode(p->hf_file))
14746 + au_hfput(p, /*execed*/0);
14749 + bbot = au_br_index(sb, brid);
14750 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14751 + finfo->fi_btop++, p++)
14753 + au_hfput(p, /*execed*/0);
14754 + bbot = au_sbbot(sb);
14757 + p = fidir->fd_hfile + bbot;
14758 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14759 + fidir->fd_bbot--, p--)
14760 + if (p->hf_file) {
14761 + if (file_inode(p->hf_file))
14763 + au_hfput(p, /*execed*/0);
14765 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14769 + * after branch manipulating, refresh the file.
14771 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14773 + int err, need_reopen, nbr;
14774 + aufs_bindex_t bbot, bindex;
14775 + struct dentry *dentry;
14776 + struct super_block *sb;
14777 + struct au_finfo *finfo;
14778 + struct au_hfile *hfile;
14780 + dentry = file->f_path.dentry;
14781 + sb = dentry->d_sb;
14782 + nbr = au_sbbot(sb) + 1;
14783 + finfo = au_fi(file);
14784 + if (!finfo->fi_hdir) {
14785 + hfile = &finfo->fi_htop;
14786 + AuDebugOn(!hfile->hf_file);
14787 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14788 + AuDebugOn(bindex < 0);
14789 + if (bindex != finfo->fi_btop)
14790 + au_set_fbtop(file, bindex);
14792 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14793 + if (unlikely(err))
14795 + au_do_refresh_dir(file);
14800 + if (!au_test_mmapped(file))
14801 + err = au_file_refresh_by_inode(file, &need_reopen);
14802 + if (finfo->fi_hdir)
14803 + /* harmless if err */
14804 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14805 + if (!err && need_reopen && !d_unlinked(dentry))
14806 + err = reopen(file);
14808 + au_update_figen(file);
14809 + goto out; /* success */
14812 + /* error, close all lower files */
14813 + if (finfo->fi_hdir) {
14814 + bbot = au_fbbot_dir(file);
14815 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14816 + au_set_h_fptr(file, bindex, NULL);
14823 +/* common function to regular file and dir */
14824 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14825 + int wlock, unsigned int fi_lsc)
14828 + unsigned int sigen, figen;
14829 + aufs_bindex_t btop;
14830 + unsigned char pseudo_link;
14831 + struct dentry *dentry;
14832 + struct inode *inode;
14835 + dentry = file->f_path.dentry;
14836 + inode = d_inode(dentry);
14837 + sigen = au_sigen(dentry->d_sb);
14838 + fi_write_lock_nested(file, fi_lsc);
14839 + figen = au_figen(file);
14841 + di_write_lock_child(dentry);
14843 + di_write_lock_child2(dentry);
14844 + btop = au_dbtop(dentry);
14845 + pseudo_link = (btop != au_ibtop(inode));
14846 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14848 + di_downgrade_lock(dentry, AuLock_IR);
14849 + fi_downgrade_lock(file);
14851 + goto out; /* success */
14854 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14855 + if (au_digen_test(dentry, sigen)) {
14856 + err = au_reval_dpath(dentry, sigen);
14857 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14861 + err = refresh_file(file, reopen);
14864 + di_downgrade_lock(dentry, AuLock_IR);
14865 + fi_downgrade_lock(file);
14868 + di_write_unlock(dentry);
14869 + fi_write_unlock(file);
14876 +/* ---------------------------------------------------------------------- */
14878 +/* cf. aufs_nopage() */
14879 +/* for madvise(2) */
14880 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14882 + unlock_page(page);
14886 +/* it will never be called, but necessary to support O_DIRECT */
14887 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14888 +{ BUG(); return 0; }
14890 +/* they will never be called. */
14891 +#ifdef CONFIG_AUFS_DEBUG
14892 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14893 + loff_t pos, unsigned len, unsigned flags,
14894 + struct page **pagep, void **fsdata)
14895 +{ AuUnsupport(); return 0; }
14896 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14897 + loff_t pos, unsigned len, unsigned copied,
14898 + struct page *page, void *fsdata)
14899 +{ AuUnsupport(); return 0; }
14900 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14901 +{ AuUnsupport(); return 0; }
14903 +static int aufs_set_page_dirty(struct page *page)
14904 +{ AuUnsupport(); return 0; }
14905 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14906 + unsigned int length)
14907 +{ AuUnsupport(); }
14908 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14909 +{ AuUnsupport(); return 0; }
14910 +#if 0 /* called by memory compaction regardless file */
14911 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14912 + struct page *page, enum migrate_mode mode)
14913 +{ AuUnsupport(); return 0; }
14915 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14916 +{ AuUnsupport(); return true; }
14917 +static void aufs_putback_page(struct page *page)
14918 +{ AuUnsupport(); }
14919 +static int aufs_launder_page(struct page *page)
14920 +{ AuUnsupport(); return 0; }
14921 +static int aufs_is_partially_uptodate(struct page *page,
14922 + unsigned long from,
14923 + unsigned long count)
14924 +{ AuUnsupport(); return 0; }
14925 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14927 +{ AuUnsupport(); }
14928 +static int aufs_error_remove_page(struct address_space *mapping,
14929 + struct page *page)
14930 +{ AuUnsupport(); return 0; }
14931 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14933 +{ AuUnsupport(); return 0; }
14934 +static void aufs_swap_deactivate(struct file *file)
14935 +{ AuUnsupport(); }
14936 +#endif /* CONFIG_AUFS_DEBUG */
14938 +const struct address_space_operations aufs_aop = {
14939 + .readpage = aufs_readpage,
14940 + .direct_IO = aufs_direct_IO,
14941 +#ifdef CONFIG_AUFS_DEBUG
14942 + .writepage = aufs_writepage,
14943 + /* no writepages, because of writepage */
14944 + .set_page_dirty = aufs_set_page_dirty,
14945 + /* no readpages, because of readpage */
14946 + .write_begin = aufs_write_begin,
14947 + .write_end = aufs_write_end,
14948 + /* no bmap, no block device */
14949 + .invalidatepage = aufs_invalidatepage,
14950 + .releasepage = aufs_releasepage,
14951 + /* is fallback_migrate_page ok? */
14952 + /* .migratepage = aufs_migratepage, */
14953 + .isolate_page = aufs_isolate_page,
14954 + .putback_page = aufs_putback_page,
14955 + .launder_page = aufs_launder_page,
14956 + .is_partially_uptodate = aufs_is_partially_uptodate,
14957 + .is_dirty_writeback = aufs_is_dirty_writeback,
14958 + .error_remove_page = aufs_error_remove_page,
14959 + .swap_activate = aufs_swap_activate,
14960 + .swap_deactivate = aufs_swap_deactivate
14961 +#endif /* CONFIG_AUFS_DEBUG */
14963 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14964 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14965 +++ linux/fs/aufs/file.h 2017-11-12 22:24:44.704244405 +0100
14968 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14970 + * This program, aufs is free software; you can redistribute it and/or modify
14971 + * it under the terms of the GNU General Public License as published by
14972 + * the Free Software Foundation; either version 2 of the License, or
14973 + * (at your option) any later version.
14975 + * This program is distributed in the hope that it will be useful,
14976 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14977 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14978 + * GNU General Public License for more details.
14980 + * You should have received a copy of the GNU General Public License
14981 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14985 + * file operations
14988 +#ifndef __AUFS_FILE_H__
14989 +#define __AUFS_FILE_H__
14993 +#include <linux/file.h>
14994 +#include <linux/fs.h>
14995 +#include <linux/mm_types.h>
14996 +#include <linux/poll.h>
14997 +#include "rwsem.h"
15001 + struct file *hf_file;
15002 + struct au_branch *hf_br;
15007 + aufs_bindex_t fd_bbot;
15008 + aufs_bindex_t fd_nent;
15009 + struct au_vdir *fd_vdir_cache;
15010 + struct au_hfile fd_hfile[];
15013 +static inline int au_fidir_sz(int nent)
15015 + AuDebugOn(nent < 0);
15016 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15020 + atomic_t fi_generation;
15022 + struct au_rwsem fi_rwsem;
15023 + aufs_bindex_t fi_btop;
15025 + /* do not union them */
15026 + struct { /* for non-dir */
15027 + struct au_hfile fi_htop;
15028 + atomic_t fi_mmapped;
15030 + struct au_fidir *fi_hdir; /* for dir only */
15032 + struct hlist_bl_node fi_hlist;
15033 + struct file *fi_file; /* very ugly */
15034 +} ____cacheline_aligned_in_smp;
15036 +/* ---------------------------------------------------------------------- */
15039 +extern const struct address_space_operations aufs_aop;
15040 +unsigned int au_file_roflags(unsigned int flags);
15041 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15042 + struct file *file, int force_wr);
15043 +struct au_do_open_args {
15045 + int (*open)(struct file *file, int flags,
15046 + struct file *h_file);
15047 + struct au_fidir *fidir;
15048 + struct file *h_file;
15050 +int au_do_open(struct file *file, struct au_do_open_args *args);
15051 +int au_reopen_nondir(struct file *file);
15053 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15054 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15055 + int wlock, unsigned int fi_lsc);
15056 +int au_do_flush(struct file *file, fl_owner_t id,
15057 + int (*flush)(struct file *file, fl_owner_t id));
15060 +#ifdef CONFIG_AUFS_POLL
15061 +unsigned int aufs_poll(struct file *file, poll_table *wait);
15064 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15066 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15068 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15069 + struct file *h_file);
15071 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15072 + aufs_bindex_t bindex, int force_wr)
15073 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15074 + struct file *h_file);
15078 +extern const struct file_operations aufs_file_fop;
15079 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15080 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15081 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15084 +void au_hfput(struct au_hfile *hf, int execed);
15085 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15086 + struct file *h_file);
15088 +void au_update_figen(struct file *file);
15089 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15090 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15092 +void au_fi_init_once(void *_fi);
15093 +void au_finfo_fin(struct file *file);
15094 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15097 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15098 +#ifdef CONFIG_COMPAT
15099 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15100 + unsigned long arg);
15101 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15102 + unsigned long arg);
15105 +/* ---------------------------------------------------------------------- */
15107 +static inline struct au_finfo *au_fi(struct file *file)
15109 + return file->private_data;
15112 +/* ---------------------------------------------------------------------- */
15114 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15115 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15116 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15117 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15119 +#define fi_read_trylock_nested(f) \
15120 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15121 +#define fi_write_trylock_nested(f) \
15122 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15125 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15126 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15127 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15129 +/* lock subclass for finfo */
15135 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15137 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15140 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15142 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15146 + * fi_read_lock_1, fi_write_lock_1,
15147 + * fi_read_lock_2, fi_write_lock_2
15149 +#define AuReadLockFunc(name) \
15150 +static inline void fi_read_lock_##name(struct file *f) \
15151 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15153 +#define AuWriteLockFunc(name) \
15154 +static inline void fi_write_lock_##name(struct file *f) \
15155 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15157 +#define AuRWLockFuncs(name) \
15158 + AuReadLockFunc(name) \
15159 + AuWriteLockFunc(name)
15164 +#undef AuReadLockFunc
15165 +#undef AuWriteLockFunc
15166 +#undef AuRWLockFuncs
15168 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15169 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15170 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15172 +/* ---------------------------------------------------------------------- */
15174 +/* todo: hard/soft set? */
15175 +static inline aufs_bindex_t au_fbtop(struct file *file)
15177 + FiMustAnyLock(file);
15178 + return au_fi(file)->fi_btop;
15181 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15183 + FiMustAnyLock(file);
15184 + AuDebugOn(!au_fi(file)->fi_hdir);
15185 + return au_fi(file)->fi_hdir->fd_bbot;
15188 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15190 + FiMustAnyLock(file);
15191 + AuDebugOn(!au_fi(file)->fi_hdir);
15192 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15195 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15197 + FiMustWriteLock(file);
15198 + au_fi(file)->fi_btop = bindex;
15201 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15203 + FiMustWriteLock(file);
15204 + AuDebugOn(!au_fi(file)->fi_hdir);
15205 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15208 +static inline void au_set_fvdir_cache(struct file *file,
15209 + struct au_vdir *vdir_cache)
15211 + FiMustWriteLock(file);
15212 + AuDebugOn(!au_fi(file)->fi_hdir);
15213 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15216 +static inline struct file *au_hf_top(struct file *file)
15218 + FiMustAnyLock(file);
15219 + AuDebugOn(au_fi(file)->fi_hdir);
15220 + return au_fi(file)->fi_htop.hf_file;
15223 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15225 + FiMustAnyLock(file);
15226 + AuDebugOn(!au_fi(file)->fi_hdir);
15227 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15230 +/* todo: memory barrier? */
15231 +static inline unsigned int au_figen(struct file *f)
15233 + return atomic_read(&au_fi(f)->fi_generation);
15236 +static inline void au_set_mmapped(struct file *f)
15238 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15240 + pr_warn("fi_mmapped wrapped around\n");
15241 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15245 +static inline void au_unset_mmapped(struct file *f)
15247 + atomic_dec(&au_fi(f)->fi_mmapped);
15250 +static inline int au_test_mmapped(struct file *f)
15252 + return atomic_read(&au_fi(f)->fi_mmapped);
15255 +/* customize vma->vm_file */
15257 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15258 + struct file *file)
15262 + f = vma->vm_file;
15264 + vma->vm_file = file;
15269 +#define AuDbgVmRegion(file, vma) do {} while (0)
15271 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15272 + struct file *file)
15274 + au_do_vm_file_reset(vma, file);
15277 +#define AuDbgVmRegion(file, vma) \
15278 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15280 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15281 + struct file *file)
15285 + au_do_vm_file_reset(vma, file);
15286 + f = vma->vm_region->vm_file;
15288 + vma->vm_region->vm_file = file;
15291 +#endif /* CONFIG_MMU */
15293 +/* handle vma->vm_prfile */
15294 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15295 + struct file *file)
15298 + vma->vm_prfile = file;
15299 +#ifndef CONFIG_MMU
15301 + vma->vm_region->vm_prfile = file;
15305 +#endif /* __KERNEL__ */
15306 +#endif /* __AUFS_FILE_H__ */
15307 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15308 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15309 +++ linux/fs/aufs/finfo.c 2017-11-12 22:24:42.270843503 +0100
15312 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15314 + * This program, aufs is free software; you can redistribute it and/or modify
15315 + * it under the terms of the GNU General Public License as published by
15316 + * the Free Software Foundation; either version 2 of the License, or
15317 + * (at your option) any later version.
15319 + * This program is distributed in the hope that it will be useful,
15320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15322 + * GNU General Public License for more details.
15324 + * You should have received a copy of the GNU General Public License
15325 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15329 + * file private data
15334 +void au_hfput(struct au_hfile *hf, int execed)
15337 + allow_write_access(hf->hf_file);
15338 + fput(hf->hf_file);
15339 + hf->hf_file = NULL;
15340 + au_br_put(hf->hf_br);
15341 + hf->hf_br = NULL;
15344 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15346 + struct au_finfo *finfo = au_fi(file);
15347 + struct au_hfile *hf;
15348 + struct au_fidir *fidir;
15350 + fidir = finfo->fi_hdir;
15352 + AuDebugOn(finfo->fi_btop != bindex);
15353 + hf = &finfo->fi_htop;
15355 + hf = fidir->fd_hfile + bindex;
15357 + if (hf && hf->hf_file)
15358 + au_hfput(hf, vfsub_file_execed(file));
15360 + FiMustWriteLock(file);
15361 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15362 + hf->hf_file = val;
15363 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15367 +void au_update_figen(struct file *file)
15369 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15370 + /* smp_mb(); */ /* atomic_set */
15373 +/* ---------------------------------------------------------------------- */
15375 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15377 + struct au_fidir *fidir;
15380 + nbr = au_sbbot(sb) + 1;
15382 + nbr = 2; /* initial allocate for 2 branches */
15383 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15385 + fidir->fd_bbot = -1;
15386 + fidir->fd_nent = nbr;
15392 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15395 + struct au_fidir *fidir, *p;
15397 + AuRwMustWriteLock(&finfo->fi_rwsem);
15398 + fidir = finfo->fi_hdir;
15399 + AuDebugOn(!fidir);
15402 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15403 + GFP_NOFS, may_shrink);
15405 + p->fd_nent = nbr;
15406 + finfo->fi_hdir = p;
15413 +/* ---------------------------------------------------------------------- */
15415 +void au_finfo_fin(struct file *file)
15417 + struct au_finfo *finfo;
15419 + au_nfiles_dec(file->f_path.dentry->d_sb);
15421 + finfo = au_fi(file);
15422 + AuDebugOn(finfo->fi_hdir);
15423 + AuRwDestroy(&finfo->fi_rwsem);
15424 + au_cache_free_finfo(finfo);
15427 +void au_fi_init_once(void *_finfo)
15429 + struct au_finfo *finfo = _finfo;
15431 + au_rw_init(&finfo->fi_rwsem);
15434 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15437 + struct au_finfo *finfo;
15438 + struct dentry *dentry;
15441 + dentry = file->f_path.dentry;
15442 + finfo = au_cache_alloc_finfo();
15443 + if (unlikely(!finfo))
15447 + au_nfiles_inc(dentry->d_sb);
15448 + au_rw_write_lock(&finfo->fi_rwsem);
15449 + finfo->fi_btop = -1;
15450 + finfo->fi_hdir = fidir;
15451 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15452 + /* smp_mb(); */ /* atomic_set */
15454 + file->private_data = finfo;
15459 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15460 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15461 +++ linux/fs/aufs/f_op.c 2017-11-12 22:24:44.704244405 +0100
15464 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15466 + * This program, aufs is free software; you can redistribute it and/or modify
15467 + * it under the terms of the GNU General Public License as published by
15468 + * the Free Software Foundation; either version 2 of the License, or
15469 + * (at your option) any later version.
15471 + * This program is distributed in the hope that it will be useful,
15472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15474 + * GNU General Public License for more details.
15476 + * You should have received a copy of the GNU General Public License
15477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15481 + * file and vm operations
15484 +#include <linux/aio.h>
15485 +#include <linux/fs_stack.h>
15486 +#include <linux/mman.h>
15487 +#include <linux/security.h>
15490 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15493 + aufs_bindex_t bindex;
15494 + struct dentry *dentry, *h_dentry;
15495 + struct au_finfo *finfo;
15496 + struct inode *h_inode;
15498 + FiMustWriteLock(file);
15501 + dentry = file->f_path.dentry;
15502 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15503 + finfo = au_fi(file);
15504 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15505 + atomic_set(&finfo->fi_mmapped, 0);
15506 + bindex = au_dbtop(dentry);
15508 + h_dentry = au_h_dptr(dentry, bindex);
15509 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15510 + if (unlikely(err))
15512 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15514 + h_dentry = h_file->f_path.dentry;
15515 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15516 + if (unlikely(err))
15518 + get_file(h_file);
15520 + if (IS_ERR(h_file))
15521 + err = PTR_ERR(h_file);
15523 + if ((flags & __O_TMPFILE)
15524 + && !(flags & O_EXCL)) {
15525 + h_inode = file_inode(h_file);
15526 + spin_lock(&h_inode->i_lock);
15527 + h_inode->i_state |= I_LINKABLE;
15528 + spin_unlock(&h_inode->i_lock);
15530 + au_set_fbtop(file, bindex);
15531 + au_set_h_fptr(file, bindex, h_file);
15532 + au_update_figen(file);
15533 + /* todo: necessary? */
15534 + /* file->f_ra = h_file->f_ra; */
15541 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15542 + struct file *file)
15545 + struct super_block *sb;
15546 + struct au_do_open_args args = {
15547 + .open = au_do_open_nondir
15550 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15551 + file, vfsub_file_flags(file), file->f_mode);
15553 + sb = file->f_path.dentry->d_sb;
15554 + si_read_lock(sb, AuLock_FLUSH);
15555 + err = au_do_open(file, &args);
15556 + si_read_unlock(sb);
15560 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15562 + struct au_finfo *finfo;
15563 + aufs_bindex_t bindex;
15565 + finfo = au_fi(file);
15566 + au_hbl_del(&finfo->fi_hlist,
15567 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15568 + bindex = finfo->fi_btop;
15570 + au_set_h_fptr(file, bindex, NULL);
15572 + au_finfo_fin(file);
15576 +/* ---------------------------------------------------------------------- */
15578 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15581 + struct file *h_file;
15584 + h_file = au_hf_top(file);
15586 + err = vfsub_flush(h_file, id);
15590 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15592 + return au_do_flush(file, id, au_do_flush_nondir);
15595 +/* ---------------------------------------------------------------------- */
15597 + * read and write functions acquire [fdi]_rwsem once, but release before
15598 + * mmap_sem. This is because to stop a race condition between mmap(2).
15599 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
15600 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15601 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15604 +/* Callers should call au_read_post() or fput() in the end */
15605 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15607 + struct file *h_file;
15610 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15612 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15613 + h_file = au_hf_top(file);
15614 + get_file(h_file);
15616 + fi_read_unlock(file);
15618 + h_file = ERR_PTR(err);
15623 +static void au_read_post(struct inode *inode, struct file *h_file)
15625 + /* update without lock, I don't think it a problem */
15626 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15630 +struct au_write_pre {
15632 + unsigned int lsc;
15636 + aufs_bindex_t btop;
15640 + * return with iinfo is write-locked
15641 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15644 +static struct file *au_write_pre(struct file *file, int do_ready,
15645 + struct au_write_pre *wpre)
15647 + struct file *h_file;
15648 + struct dentry *dentry;
15650 + unsigned int lsc;
15651 + struct au_pin pin;
15656 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15657 + h_file = ERR_PTR(err);
15658 + if (unlikely(err))
15661 + dentry = file->f_path.dentry;
15663 + err = au_ready_to_write(file, -1, &pin);
15664 + if (unlikely(err)) {
15665 + h_file = ERR_PTR(err);
15666 + di_write_unlock(dentry);
15671 + di_downgrade_lock(dentry, /*flags*/0);
15673 + wpre->btop = au_fbtop(file);
15674 + h_file = au_hf_top(file);
15675 + get_file(h_file);
15677 + wpre->blks = file_inode(h_file)->i_blocks;
15680 + di_read_unlock(dentry, /*flags*/0);
15683 + fi_write_unlock(file);
15688 +static void au_write_post(struct inode *inode, struct file *h_file,
15689 + struct au_write_pre *wpre, ssize_t written)
15691 + struct inode *h_inode;
15693 + au_cpup_attr_timesizes(inode);
15694 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15695 + h_inode = file_inode(h_file);
15696 + inode->i_mode = h_inode->i_mode;
15697 + ii_write_unlock(inode);
15698 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15700 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15701 + /*force*/h_inode->i_blocks > wpre->blks);
15705 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15709 + struct inode *inode;
15710 + struct file *h_file;
15711 + struct super_block *sb;
15713 + inode = file_inode(file);
15714 + sb = inode->i_sb;
15715 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15717 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15718 + err = PTR_ERR(h_file);
15719 + if (IS_ERR(h_file))
15722 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15723 + err = vfsub_read_u(h_file, buf, count, ppos);
15724 + /* todo: necessary? */
15725 + /* file->f_ra = h_file->f_ra; */
15726 + au_read_post(inode, h_file);
15729 + si_read_unlock(sb);
15734 + * todo: very ugly
15735 + * it locks both of i_mutex and si_rwsem for read in safe.
15736 + * if the plink maintenance mode continues forever (that is the problem),
15737 + * may loop forever.
15739 +static void au_mtx_and_read_lock(struct inode *inode)
15742 + struct super_block *sb = inode->i_sb;
15745 + inode_lock(inode);
15746 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15749 + inode_unlock(inode);
15750 + si_read_lock(sb, AuLock_NOPLMW);
15751 + si_read_unlock(sb);
15755 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15756 + size_t count, loff_t *ppos)
15759 + struct au_write_pre wpre;
15760 + struct inode *inode;
15761 + struct file *h_file;
15762 + char __user *buf = (char __user *)ubuf;
15764 + inode = file_inode(file);
15765 + au_mtx_and_read_lock(inode);
15768 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15769 + err = PTR_ERR(h_file);
15770 + if (IS_ERR(h_file))
15773 + err = vfsub_write_u(h_file, buf, count, ppos);
15774 + au_write_post(inode, h_file, &wpre, err);
15777 + si_read_unlock(inode->i_sb);
15778 + inode_unlock(inode);
15782 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15783 + struct iov_iter *iov_iter)
15786 + struct file *file;
15787 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15789 + err = security_file_permission(h_file, rw);
15790 + if (unlikely(err))
15795 + if (rw == MAY_READ)
15796 + iter = h_file->f_op->read_iter;
15797 + else if (rw == MAY_WRITE)
15798 + iter = h_file->f_op->write_iter;
15800 + file = kio->ki_filp;
15801 + kio->ki_filp = h_file;
15804 + err = iter(kio, iov_iter);
15807 + /* currently there is no such fs */
15809 + kio->ki_filp = file;
15815 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15818 + struct file *file, *h_file;
15819 + struct inode *inode;
15820 + struct super_block *sb;
15822 + file = kio->ki_filp;
15823 + inode = file_inode(file);
15824 + sb = inode->i_sb;
15825 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15827 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15828 + err = PTR_ERR(h_file);
15829 + if (IS_ERR(h_file))
15832 + if (au_test_loopback_kthread()) {
15833 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15834 + if (file->f_mapping != h_file->f_mapping) {
15835 + file->f_mapping = h_file->f_mapping;
15836 + smp_mb(); /* unnecessary? */
15839 + fi_read_unlock(file);
15841 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15842 + /* todo: necessary? */
15843 + /* file->f_ra = h_file->f_ra; */
15844 + au_read_post(inode, h_file);
15847 + si_read_unlock(sb);
15851 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15854 + struct au_write_pre wpre;
15855 + struct inode *inode;
15856 + struct file *file, *h_file;
15858 + file = kio->ki_filp;
15859 + inode = file_inode(file);
15860 + au_mtx_and_read_lock(inode);
15863 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15864 + err = PTR_ERR(h_file);
15865 + if (IS_ERR(h_file))
15868 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15869 + au_write_post(inode, h_file, &wpre, err);
15872 + si_read_unlock(inode->i_sb);
15873 + inode_unlock(inode);
15877 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15878 + struct pipe_inode_info *pipe, size_t len,
15879 + unsigned int flags)
15882 + struct file *h_file;
15883 + struct inode *inode;
15884 + struct super_block *sb;
15886 + inode = file_inode(file);
15887 + sb = inode->i_sb;
15888 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15890 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15891 + err = PTR_ERR(h_file);
15892 + if (IS_ERR(h_file))
15895 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15896 + /* todo: necessasry? */
15897 + /* file->f_ra = h_file->f_ra; */
15898 + au_read_post(inode, h_file);
15901 + si_read_unlock(sb);
15906 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15907 + size_t len, unsigned int flags)
15910 + struct au_write_pre wpre;
15911 + struct inode *inode;
15912 + struct file *h_file;
15914 + inode = file_inode(file);
15915 + au_mtx_and_read_lock(inode);
15918 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15919 + err = PTR_ERR(h_file);
15920 + if (IS_ERR(h_file))
15923 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15924 + au_write_post(inode, h_file, &wpre, err);
15927 + si_read_unlock(inode->i_sb);
15928 + inode_unlock(inode);
15932 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15936 + struct au_write_pre wpre;
15937 + struct inode *inode;
15938 + struct file *h_file;
15940 + inode = file_inode(file);
15941 + au_mtx_and_read_lock(inode);
15944 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15945 + err = PTR_ERR(h_file);
15946 + if (IS_ERR(h_file))
15950 + err = vfs_fallocate(h_file, mode, offset, len);
15952 + au_write_post(inode, h_file, &wpre, /*written*/1);
15955 + si_read_unlock(inode->i_sb);
15956 + inode_unlock(inode);
15960 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15961 + struct file *dst, loff_t dst_pos,
15962 + size_t len, unsigned int flags)
15965 + struct au_write_pre wpre;
15966 + enum { SRC, DST };
15968 + struct inode *inode;
15969 + struct file *h_file;
15970 + struct super_block *h_sb;
15972 +#define a_src a[SRC]
15973 +#define a_dst a[DST]
15976 + a_src.inode = file_inode(src);
15977 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15979 + a_dst.inode = file_inode(dst);
15980 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15983 + au_mtx_and_read_lock(a_dst.inode);
15985 + * in order to match the order in di_write_lock2_{child,parent}(),
15986 + * use f_path.dentry for this comparision.
15988 + if (src->f_path.dentry < dst->f_path.dentry) {
15989 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15990 + err = PTR_ERR(a_src.h_file);
15991 + if (IS_ERR(a_src.h_file))
15994 + wpre.lsc = AuLsc_FI_2;
15995 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15996 + err = PTR_ERR(a_dst.h_file);
15997 + if (IS_ERR(a_dst.h_file)) {
15998 + au_read_post(a_src.inode, a_src.h_file);
16002 + wpre.lsc = AuLsc_FI_1;
16003 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16004 + err = PTR_ERR(a_dst.h_file);
16005 + if (IS_ERR(a_dst.h_file))
16008 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16009 + err = PTR_ERR(a_src.h_file);
16010 + if (IS_ERR(a_src.h_file)) {
16011 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16018 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16019 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16020 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16026 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16027 + dst_pos, len, flags);
16030 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16031 + fi_read_unlock(src);
16032 + au_read_post(a_src.inode, a_src.h_file);
16034 + si_read_unlock(a_dst.inode->i_sb);
16035 + inode_unlock(a_dst.inode);
16042 +/* ---------------------------------------------------------------------- */
16045 + * The locking order around current->mmap_sem.
16046 + * - in most and regular cases
16047 + * file I/O syscall -- aufs_read() or something
16048 + * -- si_rwsem for read -- mmap_sem
16049 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16051 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16052 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
16053 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
16054 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16055 + * It means that when aufs acquires si_rwsem for write, the process should never
16056 + * acquire mmap_sem.
16058 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16059 + * problem either since any directory is not able to be mmap-ed.
16060 + * The similar scenario is applied to aufs_readlink() too.
16063 +#if 0 /* stop calling security_file_mmap() */
16064 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16065 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16067 +static unsigned long au_arch_prot_conv(unsigned long flags)
16069 + /* currently ppc64 only */
16070 +#ifdef CONFIG_PPC64
16071 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16072 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16073 + return AuConv_VM_PROT(flags, SAO);
16075 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16080 +static unsigned long au_prot_conv(unsigned long flags)
16082 + return AuConv_VM_PROT(flags, READ)
16083 + | AuConv_VM_PROT(flags, WRITE)
16084 + | AuConv_VM_PROT(flags, EXEC)
16085 + | au_arch_prot_conv(flags);
16088 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16089 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16091 +static unsigned long au_flag_conv(unsigned long flags)
16093 + return AuConv_VM_MAP(flags, GROWSDOWN)
16094 + | AuConv_VM_MAP(flags, DENYWRITE)
16095 + | AuConv_VM_MAP(flags, LOCKED);
16099 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16102 + const unsigned char wlock
16103 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16104 + struct super_block *sb;
16105 + struct file *h_file;
16106 + struct inode *inode;
16108 + AuDbgVmRegion(file, vma);
16110 + inode = file_inode(file);
16111 + sb = inode->i_sb;
16113 + si_read_lock(sb, AuLock_NOPLMW);
16115 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16117 + err = PTR_ERR(h_file);
16118 + if (IS_ERR(h_file))
16122 + au_set_mmapped(file);
16123 + au_vm_file_reset(vma, h_file);
16125 + * we cannot call security_mmap_file() here since it may acquire
16126 + * mmap_sem or i_mutex.
16128 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16129 + * au_flag_conv(vma->vm_flags));
16132 + err = call_mmap(h_file, vma);
16134 + au_vm_prfile_set(vma, file);
16135 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16136 + goto out_fput; /* success */
16138 + au_unset_mmapped(file);
16139 + au_vm_file_reset(vma, file);
16143 + ii_write_unlock(inode);
16148 + si_read_unlock(sb);
16154 +/* ---------------------------------------------------------------------- */
16156 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16160 + struct au_write_pre wpre;
16161 + struct inode *inode;
16162 + struct file *h_file;
16164 + err = 0; /* -EBADF; */ /* posix? */
16165 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16168 + inode = file_inode(file);
16169 + au_mtx_and_read_lock(inode);
16172 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16173 + err = PTR_ERR(h_file);
16174 + if (IS_ERR(h_file))
16177 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16178 + au_write_post(inode, h_file, &wpre, /*written*/0);
16181 + si_read_unlock(inode->i_sb);
16182 + inode_unlock(inode);
16187 +static int aufs_fasync(int fd, struct file *file, int flag)
16190 + struct file *h_file;
16191 + struct super_block *sb;
16193 + sb = file->f_path.dentry->d_sb;
16194 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16196 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16197 + err = PTR_ERR(h_file);
16198 + if (IS_ERR(h_file))
16201 + if (h_file->f_op->fasync)
16202 + err = h_file->f_op->fasync(fd, h_file, flag);
16203 + fput(h_file); /* instead of au_read_post() */
16206 + si_read_unlock(sb);
16210 +static int aufs_setfl(struct file *file, unsigned long arg)
16213 + struct file *h_file;
16214 + struct super_block *sb;
16216 + sb = file->f_path.dentry->d_sb;
16217 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16219 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16220 + err = PTR_ERR(h_file);
16221 + if (IS_ERR(h_file))
16224 + /* stop calling h_file->fasync */
16225 + arg |= vfsub_file_flags(file) & FASYNC;
16226 + err = setfl(/*unused fd*/-1, h_file, arg);
16227 + fput(h_file); /* instead of au_read_post() */
16230 + si_read_unlock(sb);
16234 +/* ---------------------------------------------------------------------- */
16236 +/* no one supports this operation, currently */
16238 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16239 + size_t len, loff_t *pos, int more)
16244 +/* ---------------------------------------------------------------------- */
16246 +const struct file_operations aufs_file_fop = {
16247 + .owner = THIS_MODULE,
16249 + .llseek = default_llseek,
16251 + .read = aufs_read,
16252 + .write = aufs_write,
16253 + .read_iter = aufs_read_iter,
16254 + .write_iter = aufs_write_iter,
16256 +#ifdef CONFIG_AUFS_POLL
16257 + .poll = aufs_poll,
16259 + .unlocked_ioctl = aufs_ioctl_nondir,
16260 +#ifdef CONFIG_COMPAT
16261 + .compat_ioctl = aufs_compat_ioctl_nondir,
16263 + .mmap = aufs_mmap,
16264 + .open = aufs_open_nondir,
16265 + .flush = aufs_flush_nondir,
16266 + .release = aufs_release_nondir,
16267 + .fsync = aufs_fsync_nondir,
16268 + .fasync = aufs_fasync,
16269 + /* .sendpage = aufs_sendpage, */
16270 + .setfl = aufs_setfl,
16271 + .splice_write = aufs_splice_write,
16272 + .splice_read = aufs_splice_read,
16274 + .aio_splice_write = aufs_aio_splice_write,
16275 + .aio_splice_read = aufs_aio_splice_read,
16277 + .fallocate = aufs_fallocate,
16278 + .copy_file_range = aufs_copy_file_range
16280 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16281 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16282 +++ linux/fs/aufs/fstype.h 2017-07-29 12:14:25.903042072 +0200
16285 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16287 + * This program, aufs is free software; you can redistribute it and/or modify
16288 + * it under the terms of the GNU General Public License as published by
16289 + * the Free Software Foundation; either version 2 of the License, or
16290 + * (at your option) any later version.
16292 + * This program is distributed in the hope that it will be useful,
16293 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16294 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16295 + * GNU General Public License for more details.
16297 + * You should have received a copy of the GNU General Public License
16298 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16302 + * judging filesystem type
16305 +#ifndef __AUFS_FSTYPE_H__
16306 +#define __AUFS_FSTYPE_H__
16310 +#include <linux/fs.h>
16311 +#include <linux/magic.h>
16312 +#include <linux/nfs_fs.h>
16313 +#include <linux/romfs_fs.h>
16315 +static inline int au_test_aufs(struct super_block *sb)
16317 + return sb->s_magic == AUFS_SUPER_MAGIC;
16320 +static inline const char *au_sbtype(struct super_block *sb)
16322 + return sb->s_type->name;
16325 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16327 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16328 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16334 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16336 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16337 + return sb->s_magic == ROMFS_MAGIC;
16343 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16345 +#if IS_ENABLED(CONFIG_CRAMFS)
16346 + return sb->s_magic == CRAMFS_MAGIC;
16351 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16353 +#if IS_ENABLED(CONFIG_NFS_FS)
16354 + return sb->s_magic == NFS_SUPER_MAGIC;
16360 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16362 +#if IS_ENABLED(CONFIG_FUSE_FS)
16363 + return sb->s_magic == FUSE_SUPER_MAGIC;
16369 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16371 +#if IS_ENABLED(CONFIG_XFS_FS)
16372 + return sb->s_magic == XFS_SB_MAGIC;
16378 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16380 +#ifdef CONFIG_TMPFS
16381 + return sb->s_magic == TMPFS_MAGIC;
16387 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16389 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16390 + return !strcmp(au_sbtype(sb), "ecryptfs");
16396 +static inline int au_test_ramfs(struct super_block *sb)
16398 + return sb->s_magic == RAMFS_MAGIC;
16401 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16403 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16404 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16410 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16412 +#ifdef CONFIG_PROC_FS
16413 + return sb->s_magic == PROC_SUPER_MAGIC;
16419 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16421 +#ifdef CONFIG_SYSFS
16422 + return sb->s_magic == SYSFS_MAGIC;
16428 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16430 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16431 + return sb->s_magic == CONFIGFS_MAGIC;
16437 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16439 +#if IS_ENABLED(CONFIG_MINIX_FS)
16440 + return sb->s_magic == MINIX3_SUPER_MAGIC
16441 + || sb->s_magic == MINIX2_SUPER_MAGIC
16442 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16443 + || sb->s_magic == MINIX_SUPER_MAGIC
16444 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16450 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16452 +#if IS_ENABLED(CONFIG_FAT_FS)
16453 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16459 +static inline int au_test_msdos(struct super_block *sb)
16461 + return au_test_fat(sb);
16464 +static inline int au_test_vfat(struct super_block *sb)
16466 + return au_test_fat(sb);
16469 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16471 +#ifdef CONFIG_SECURITYFS
16472 + return sb->s_magic == SECURITYFS_MAGIC;
16478 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16480 +#if IS_ENABLED(CONFIG_SQUASHFS)
16481 + return sb->s_magic == SQUASHFS_MAGIC;
16487 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16489 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16490 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16496 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16498 +#if IS_ENABLED(CONFIG_XENFS)
16499 + return sb->s_magic == XENFS_SUPER_MAGIC;
16505 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16507 +#ifdef CONFIG_DEBUG_FS
16508 + return sb->s_magic == DEBUGFS_MAGIC;
16514 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16516 +#if IS_ENABLED(CONFIG_NILFS)
16517 + return sb->s_magic == NILFS_SUPER_MAGIC;
16523 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16525 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16526 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16532 +/* ---------------------------------------------------------------------- */
16534 + * they can't be an aufs branch.
16536 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16539 +#ifndef CONFIG_AUFS_BR_RAMFS
16540 + au_test_ramfs(sb) ||
16542 + au_test_procfs(sb)
16543 + || au_test_sysfs(sb)
16544 + || au_test_configfs(sb)
16545 + || au_test_debugfs(sb)
16546 + || au_test_securityfs(sb)
16547 + || au_test_xenfs(sb)
16548 + || au_test_ecryptfs(sb)
16549 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16550 + || au_test_aufs(sb); /* will be supported in next version */
16553 +static inline int au_test_fs_remote(struct super_block *sb)
16555 + return !au_test_tmpfs(sb)
16556 +#ifdef CONFIG_AUFS_BR_RAMFS
16557 + && !au_test_ramfs(sb)
16559 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16562 +/* ---------------------------------------------------------------------- */
16565 + * Note: these functions (below) are created after reading ->getattr() in all
16566 + * filesystems under linux/fs. it means we have to do so in every update...
16570 + * some filesystems require getattr to refresh the inode attributes before
16572 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16573 + * and leave the work for d_revalidate()
16575 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16577 + return au_test_nfs(sb)
16578 + || au_test_fuse(sb)
16579 + /* || au_test_btrfs(sb) */ /* untested */
16584 + * filesystems which don't maintain i_size or i_blocks.
16586 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16588 + return au_test_xfs(sb)
16589 + || au_test_btrfs(sb)
16590 + || au_test_ubifs(sb)
16591 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16592 + /* || au_test_minix(sb) */ /* untested */
16597 + * filesystems which don't store the correct value in some of their inode
16600 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16602 + return au_test_fs_bad_iattr_size(sb)
16603 + || au_test_fat(sb)
16604 + || au_test_msdos(sb)
16605 + || au_test_vfat(sb);
16608 +/* they don't check i_nlink in link(2) */
16609 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16611 + return au_test_tmpfs(sb)
16612 +#ifdef CONFIG_AUFS_BR_RAMFS
16613 + || au_test_ramfs(sb)
16615 + || au_test_ubifs(sb)
16616 + || au_test_hfsplus(sb);
16620 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16622 +static inline int au_test_fs_notime(struct super_block *sb)
16624 + return au_test_nfs(sb)
16625 + || au_test_fuse(sb)
16626 + || au_test_ubifs(sb)
16630 +/* temporary support for i#1 in cramfs */
16631 +static inline int au_test_fs_unique_ino(struct inode *inode)
16633 + if (au_test_cramfs(inode->i_sb))
16634 + return inode->i_ino != 1;
16638 +/* ---------------------------------------------------------------------- */
16641 + * the filesystem where the xino files placed must support i/o after unlink and
16642 + * maintain i_size and i_blocks.
16644 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16646 + return au_test_fs_remote(sb)
16647 + || au_test_fs_bad_iattr_size(sb)
16648 + /* don't want unnecessary work for xino */
16649 + || au_test_aufs(sb)
16650 + || au_test_ecryptfs(sb)
16651 + || au_test_nilfs(sb);
16654 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16656 + return au_test_tmpfs(sb)
16657 + || au_test_ramfs(sb);
16661 + * test if the @sb is real-readonly.
16663 +static inline int au_test_fs_rr(struct super_block *sb)
16665 + return au_test_squashfs(sb)
16666 + || au_test_iso9660(sb)
16667 + || au_test_cramfs(sb)
16668 + || au_test_romfs(sb);
16672 + * test if the @inode is nfs with 'noacl' option
16673 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
16675 +static inline int au_test_nfs_noacl(struct inode *inode)
16677 + return au_test_nfs(inode->i_sb)
16678 + /* && IS_POSIXACL(inode) */
16679 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16682 +#endif /* __KERNEL__ */
16683 +#endif /* __AUFS_FSTYPE_H__ */
16684 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16685 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16686 +++ linux/fs/aufs/hbl.h 2017-11-12 22:24:44.707577830 +0100
16689 + * Copyright (C) 2017 Junjiro R. Okajima
16691 + * This program, aufs is free software; you can redistribute it and/or modify
16692 + * it under the terms of the GNU General Public License as published by
16693 + * the Free Software Foundation; either version 2 of the License, or
16694 + * (at your option) any later version.
16696 + * This program is distributed in the hope that it will be useful,
16697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16699 + * GNU General Public License for more details.
16701 + * You should have received a copy of the GNU General Public License
16702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16706 + * helpers for hlist_bl.h
16709 +#ifndef __AUFS_HBL_H__
16710 +#define __AUFS_HBL_H__
16714 +#include <linux/list_bl.h>
16716 +static inline void au_hbl_add(struct hlist_bl_node *node,
16717 + struct hlist_bl_head *hbl)
16719 + hlist_bl_lock(hbl);
16720 + hlist_bl_add_head(node, hbl);
16721 + hlist_bl_unlock(hbl);
16724 +static inline void au_hbl_del(struct hlist_bl_node *node,
16725 + struct hlist_bl_head *hbl)
16727 + hlist_bl_lock(hbl);
16728 + hlist_bl_del(node);
16729 + hlist_bl_unlock(hbl);
16732 +#define au_hbl_for_each(pos, head) \
16733 + for (pos = hlist_bl_first(head); \
16737 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16739 + unsigned long cnt;
16740 + struct hlist_bl_node *pos;
16743 + hlist_bl_lock(hbl);
16744 + au_hbl_for_each(pos, hbl)
16746 + hlist_bl_unlock(hbl);
16750 +#endif /* __KERNEL__ */
16751 +#endif /* __AUFS_HBL_H__ */
16752 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16753 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16754 +++ linux/fs/aufs/hfsnotify.c 2017-11-12 22:24:44.707577830 +0100
16757 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16759 + * This program, aufs is free software; you can redistribute it and/or modify
16760 + * it under the terms of the GNU General Public License as published by
16761 + * the Free Software Foundation; either version 2 of the License, or
16762 + * (at your option) any later version.
16764 + * This program is distributed in the hope that it will be useful,
16765 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16766 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16767 + * GNU General Public License for more details.
16769 + * You should have received a copy of the GNU General Public License
16770 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16774 + * fsnotify for the lower directories
16779 +/* FS_IN_IGNORED is unnecessary */
16780 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16781 + | FS_CREATE | FS_EVENT_ON_CHILD);
16782 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16783 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16785 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16787 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16789 + /* AuDbg("here\n"); */
16790 + au_cache_free_hnotify(hn);
16791 + smp_mb__before_atomic(); /* for atomic64_dec */
16792 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16793 + wake_up(&au_hfsn_wq);
16796 +static int au_hfsn_alloc(struct au_hinode *hinode)
16799 + struct au_hnotify *hn;
16800 + struct super_block *sb;
16801 + struct au_branch *br;
16802 + struct fsnotify_mark *mark;
16803 + aufs_bindex_t bindex;
16805 + hn = hinode->hi_notify;
16806 + sb = hn->hn_aufs_inode->i_sb;
16807 + bindex = au_br_index(sb, hinode->hi_id);
16808 + br = au_sbr(sb, bindex);
16809 + AuDebugOn(!br->br_hfsn);
16811 + mark = &hn->hn_mark;
16812 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16813 + mark->mask = AuHfsnMask;
16815 + * by udba rename or rmdir, aufs assign a new inode to the known
16816 + * h_inode, so specify 1 to allow dups.
16819 + err = fsnotify_add_mark(mark, hinode->hi_inode, /*mnt*/NULL,
16820 + /*allow_dups*/1);
16826 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16828 + struct fsnotify_mark *mark;
16829 + unsigned long long ull;
16830 + struct fsnotify_group *group;
16832 + ull = atomic64_inc_return(&au_hfsn_ifree);
16835 + mark = &hn->hn_mark;
16836 + spin_lock(&mark->lock);
16837 + group = mark->group;
16838 + fsnotify_get_group(group);
16839 + spin_unlock(&mark->lock);
16841 + fsnotify_destroy_mark(mark, group);
16842 + fsnotify_put_mark(mark);
16843 + fsnotify_put_group(group);
16846 + /* free hn by myself */
16850 +/* ---------------------------------------------------------------------- */
16852 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16854 + struct fsnotify_mark *mark;
16856 + mark = &hinode->hi_notify->hn_mark;
16857 + spin_lock(&mark->lock);
16859 + AuDebugOn(mark->mask & AuHfsnMask);
16860 + mark->mask |= AuHfsnMask;
16862 + AuDebugOn(!(mark->mask & AuHfsnMask));
16863 + mark->mask &= ~AuHfsnMask;
16865 + spin_unlock(&mark->lock);
16866 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16869 +/* ---------------------------------------------------------------------- */
16871 +/* #define AuDbgHnotify */
16872 +#ifdef AuDbgHnotify
16873 +static char *au_hfsn_name(u32 mask)
16875 +#ifdef CONFIG_AUFS_DEBUG
16876 +#define test_ret(flag) \
16878 + if (mask & flag) \
16881 + test_ret(FS_ACCESS);
16882 + test_ret(FS_MODIFY);
16883 + test_ret(FS_ATTRIB);
16884 + test_ret(FS_CLOSE_WRITE);
16885 + test_ret(FS_CLOSE_NOWRITE);
16886 + test_ret(FS_OPEN);
16887 + test_ret(FS_MOVED_FROM);
16888 + test_ret(FS_MOVED_TO);
16889 + test_ret(FS_CREATE);
16890 + test_ret(FS_DELETE);
16891 + test_ret(FS_DELETE_SELF);
16892 + test_ret(FS_MOVE_SELF);
16893 + test_ret(FS_UNMOUNT);
16894 + test_ret(FS_Q_OVERFLOW);
16895 + test_ret(FS_IN_IGNORED);
16896 + test_ret(FS_ISDIR);
16897 + test_ret(FS_IN_ONESHOT);
16898 + test_ret(FS_EVENT_ON_CHILD);
16907 +/* ---------------------------------------------------------------------- */
16909 +static void au_hfsn_free_group(struct fsnotify_group *group)
16911 + struct au_br_hfsnotify *hfsn = group->private;
16913 + /* AuDbg("here\n"); */
16917 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16918 + struct inode *inode,
16919 + struct fsnotify_mark *inode_mark,
16920 + struct fsnotify_mark *vfsmount_mark,
16921 + u32 mask, const void *data, int data_type,
16922 + const unsigned char *file_name, u32 cookie,
16923 + struct fsnotify_iter_info *iter_info)
16926 + struct au_hnotify *hnotify;
16927 + struct inode *h_dir, *h_inode;
16928 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
16930 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16933 + /* if FS_UNMOUNT happens, there must be another bug */
16934 + AuDebugOn(mask & FS_UNMOUNT);
16935 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16940 +#ifdef AuDbgHnotify
16942 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16943 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16944 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16945 + h_dir->i_ino, mask, au_hfsn_name(mask),
16946 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16947 + /* WARN_ON(1); */
16952 + AuDebugOn(!inode_mark);
16953 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16954 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
16960 +static struct fsnotify_ops au_hfsn_ops = {
16961 + .handle_event = au_hfsn_handle_event,
16962 + .free_group_priv = au_hfsn_free_group,
16963 + .free_mark = au_hfsn_free_mark
16966 +/* ---------------------------------------------------------------------- */
16968 +static void au_hfsn_fin_br(struct au_branch *br)
16970 + struct au_br_hfsnotify *hfsn;
16972 + hfsn = br->br_hfsn;
16975 + fsnotify_put_group(hfsn->hfsn_group);
16980 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16983 + struct fsnotify_group *group;
16984 + struct au_br_hfsnotify *hfsn;
16987 + br->br_hfsn = NULL;
16988 + if (!au_br_hnotifyable(perm))
16992 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16993 + if (unlikely(!hfsn))
16997 + group = fsnotify_alloc_group(&au_hfsn_ops);
16998 + if (IS_ERR(group)) {
16999 + err = PTR_ERR(group);
17000 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17004 + group->private = hfsn;
17005 + hfsn->hfsn_group = group;
17006 + br->br_hfsn = hfsn;
17007 + goto out; /* success */
17015 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17020 + if (!br->br_hfsn)
17021 + err = au_hfsn_init_br(br, perm);
17026 +/* ---------------------------------------------------------------------- */
17028 +static void au_hfsn_fin(void)
17030 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17031 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17034 +const struct au_hnotify_op au_hnotify_op = {
17035 + .ctl = au_hfsn_ctl,
17036 + .alloc = au_hfsn_alloc,
17037 + .free = au_hfsn_free,
17039 + .fin = au_hfsn_fin,
17041 + .reset_br = au_hfsn_reset_br,
17042 + .fin_br = au_hfsn_fin_br,
17043 + .init_br = au_hfsn_init_br
17045 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17046 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17047 +++ linux/fs/aufs/hfsplus.c 2017-07-29 12:14:25.903042072 +0200
17050 + * Copyright (C) 2010-2017 Junjiro R. Okajima
17052 + * This program, aufs is free software; you can redistribute it and/or modify
17053 + * it under the terms of the GNU General Public License as published by
17054 + * the Free Software Foundation; either version 2 of the License, or
17055 + * (at your option) any later version.
17057 + * This program is distributed in the hope that it will be useful,
17058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17060 + * GNU General Public License for more details.
17062 + * You should have received a copy of the GNU General Public License
17063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17067 + * special support for filesystems which aqucires an inode mutex
17068 + * at final closing a file, eg, hfsplus.
17070 + * This trick is very simple and stupid, just to open the file before really
17071 + * neceeary open to tell hfsplus that this is not the final closing.
17072 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17073 + * and au_h_open_post() after releasing it.
17078 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17081 + struct file *h_file;
17082 + struct dentry *h_dentry;
17084 + h_dentry = au_h_dptr(dentry, bindex);
17085 + AuDebugOn(!h_dentry);
17086 + AuDebugOn(d_is_negative(h_dentry));
17089 + if (au_test_hfsplus(h_dentry->d_sb)
17090 + && d_is_reg(h_dentry))
17091 + h_file = au_h_open(dentry, bindex,
17092 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17093 + /*file*/NULL, force_wr);
17097 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17098 + struct file *h_file)
17102 + au_sbr_put(dentry->d_sb, bindex);
17105 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17106 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17107 +++ linux/fs/aufs/hnotify.c 2017-11-12 22:24:44.707577830 +0100
17110 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17112 + * This program, aufs is free software; you can redistribute it and/or modify
17113 + * it under the terms of the GNU General Public License as published by
17114 + * the Free Software Foundation; either version 2 of the License, or
17115 + * (at your option) any later version.
17117 + * This program is distributed in the hope that it will be useful,
17118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17120 + * GNU General Public License for more details.
17122 + * You should have received a copy of the GNU General Public License
17123 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17127 + * abstraction to notify the direct changes on lower directories
17132 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17135 + struct au_hnotify *hn;
17138 + hn = au_cache_alloc_hnotify();
17140 + hn->hn_aufs_inode = inode;
17141 + hinode->hi_notify = hn;
17142 + err = au_hnotify_op.alloc(hinode);
17144 + if (unlikely(err)) {
17145 + hinode->hi_notify = NULL;
17146 + au_cache_free_hnotify(hn);
17148 + * The upper dir was removed by udba, but the same named
17149 + * dir left. In this case, aufs assignes a new inode
17150 + * number and set the monitor again.
17151 + * For the lower dir, the old monitnor is still left.
17153 + if (err == -EEXIST)
17162 +void au_hn_free(struct au_hinode *hinode)
17164 + struct au_hnotify *hn;
17166 + hn = hinode->hi_notify;
17168 + hinode->hi_notify = NULL;
17169 + if (au_hnotify_op.free(hinode, hn))
17170 + au_cache_free_hnotify(hn);
17174 +/* ---------------------------------------------------------------------- */
17176 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17178 + if (hinode->hi_notify)
17179 + au_hnotify_op.ctl(hinode, do_set);
17182 +void au_hn_reset(struct inode *inode, unsigned int flags)
17184 + aufs_bindex_t bindex, bbot;
17185 + struct inode *hi;
17186 + struct dentry *iwhdentry;
17188 + bbot = au_ibbot(inode);
17189 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17190 + hi = au_h_iptr(inode, bindex);
17194 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17195 + iwhdentry = au_hi_wh(inode, bindex);
17199 + au_set_h_iptr(inode, bindex, NULL, 0);
17200 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17201 + flags & ~AuHi_XINO);
17204 + /* inode_unlock(hi); */
17208 +/* ---------------------------------------------------------------------- */
17210 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17213 + aufs_bindex_t bindex, bbot, bfound, btop;
17214 + struct inode *h_i;
17217 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17218 + pr_warn("branch root dir was changed\n");
17223 + bbot = au_ibbot(inode);
17224 + btop = au_ibtop(inode);
17225 +#if 0 /* reserved for future use */
17226 + if (bindex == bbot) {
17227 + /* keep this ino in rename case */
17231 + for (bindex = btop; bindex <= bbot; bindex++)
17232 + if (au_h_iptr(inode, bindex) == h_inode) {
17239 + for (bindex = btop; bindex <= bbot; bindex++) {
17240 + h_i = au_h_iptr(inode, bindex);
17244 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17245 + /* ignore this error */
17246 + /* bad action? */
17249 + /* children inode number will be broken */
17256 +static int hn_gen_tree(struct dentry *dentry)
17258 + int err, i, j, ndentry;
17259 + struct au_dcsub_pages dpages;
17260 + struct au_dpage *dpage;
17261 + struct dentry **dentries;
17263 + err = au_dpages_init(&dpages, GFP_NOFS);
17264 + if (unlikely(err))
17266 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17267 + if (unlikely(err))
17270 + for (i = 0; i < dpages.ndpage; i++) {
17271 + dpage = dpages.dpages + i;
17272 + dentries = dpage->dentries;
17273 + ndentry = dpage->ndentry;
17274 + for (j = 0; j < ndentry; j++) {
17275 + struct dentry *d;
17282 + if (d_really_is_positive(d))
17283 + /* todo: reset children xino?
17284 + cached children only? */
17285 + au_iigen_dec(d_inode(d));
17290 + au_dpages_free(&dpages);
17293 + /* discard children */
17294 + dentry_unhash(dentry);
17302 + * return 0 if processed.
17304 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17305 + const unsigned int isdir)
17308 + struct dentry *d;
17309 + struct qstr *dname;
17312 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17313 + pr_warn("branch root dir was changed\n");
17319 + AuDebugOn(!name);
17320 + au_iigen_dec(inode);
17321 + spin_lock(&inode->i_lock);
17322 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17323 + spin_lock(&d->d_lock);
17324 + dname = &d->d_name;
17325 + if (dname->len != nlen
17326 + && memcmp(dname->name, name, nlen)) {
17327 + spin_unlock(&d->d_lock);
17332 + spin_unlock(&d->d_lock);
17335 + spin_unlock(&inode->i_lock);
17337 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17338 + d = d_find_any_alias(inode);
17340 + au_iigen_dec(inode);
17344 + spin_lock(&d->d_lock);
17345 + dname = &d->d_name;
17346 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17347 + spin_unlock(&d->d_lock);
17348 + err = hn_gen_tree(d);
17349 + spin_lock(&d->d_lock);
17351 + spin_unlock(&d->d_lock);
17360 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17364 + if (IS_ROOT(dentry)) {
17365 + pr_warn("branch root dir was changed\n");
17371 + au_digen_dec(dentry);
17372 + if (d_really_is_positive(dentry))
17373 + au_iigen_dec(d_inode(dentry));
17375 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17376 + if (d_really_is_positive(dentry))
17377 + err = hn_gen_tree(dentry);
17384 +/* ---------------------------------------------------------------------- */
17386 +/* hnotify job flags */
17387 +#define AuHnJob_XINO0 1
17388 +#define AuHnJob_GEN (1 << 1)
17389 +#define AuHnJob_DIRENT (1 << 2)
17390 +#define AuHnJob_ISDIR (1 << 3)
17391 +#define AuHnJob_TRYXINO0 (1 << 4)
17392 +#define AuHnJob_MNTPNT (1 << 5)
17393 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17394 +#define au_fset_hnjob(flags, name) \
17395 + do { (flags) |= AuHnJob_##name; } while (0)
17396 +#define au_fclr_hnjob(flags, name) \
17397 + do { (flags) &= ~AuHnJob_##name; } while (0)
17405 +struct au_hnotify_args {
17406 + struct inode *h_dir, *dir, *h_child_inode;
17408 + unsigned int flags[AuHnLast];
17409 + unsigned int h_child_nlen;
17410 + char h_child_name[];
17413 +struct hn_job_args {
17414 + unsigned int flags;
17415 + struct inode *inode, *h_inode, *dir, *h_dir;
17416 + struct dentry *dentry;
17421 +static int hn_job(struct hn_job_args *a)
17423 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17427 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17428 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17430 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17433 + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17434 + if (!a->h_inode->i_nlink
17435 + && !(a->h_inode->i_state & I_LINKABLE))
17436 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17437 + inode_unlock_shared(a->h_inode);
17440 + /* make the generation obsolete */
17441 + if (au_ftest_hnjob(a->flags, GEN)) {
17444 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17446 + if (e && a->dentry)
17447 + hn_gen_by_name(a->dentry, isdir);
17448 + /* ignore this error */
17451 + /* make dir entries obsolete */
17452 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17453 + struct au_vdir *vdir;
17455 + vdir = au_ivdir(a->inode);
17457 + vdir->vd_jiffy = 0;
17458 + /* IMustLock(a->inode); */
17459 + /* a->inode->i_version++; */
17462 + /* can do nothing but warn */
17463 + if (au_ftest_hnjob(a->flags, MNTPNT)
17465 + && d_mountpoint(a->dentry))
17466 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17471 +/* ---------------------------------------------------------------------- */
17473 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17474 + struct inode *dir)
17476 + struct dentry *dentry, *d, *parent;
17477 + struct qstr *dname;
17479 + parent = d_find_any_alias(dir);
17484 + spin_lock(&parent->d_lock);
17485 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17486 + /* AuDbg("%pd\n", d); */
17487 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17488 + dname = &d->d_name;
17489 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17490 + goto cont_unlock;
17494 + goto cont_unlock;
17495 + if (au_dcount(d) > 0) {
17496 + dentry = dget_dlock(d);
17497 + spin_unlock(&d->d_lock);
17502 + spin_unlock(&d->d_lock);
17504 + spin_unlock(&parent->d_lock);
17508 + di_write_lock_child(dentry);
17513 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17514 + aufs_bindex_t bindex, ino_t h_ino)
17516 + struct inode *inode;
17521 + err = au_xino_read(sb, bindex, h_ino, &ino);
17523 + inode = ilookup(sb, ino);
17527 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17528 + pr_warn("wrong root branch\n");
17534 + ii_write_lock_child(inode);
17540 +static void au_hn_bh(void *_args)
17542 + struct au_hnotify_args *a = _args;
17543 + struct super_block *sb;
17544 + aufs_bindex_t bindex, bbot, bfound;
17545 + unsigned char xino, try_iput;
17547 + struct inode *inode;
17549 + struct hn_job_args args;
17550 + struct dentry *dentry;
17551 + struct au_sbinfo *sbinfo;
17553 + AuDebugOn(!_args);
17554 + AuDebugOn(!a->h_dir);
17555 + AuDebugOn(!a->dir);
17556 + AuDebugOn(!a->mask);
17557 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17558 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17559 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17564 + * do not lock a->dir->i_mutex here
17565 + * because of d_revalidate() may cause a deadlock.
17567 + sb = a->dir->i_sb;
17569 + sbinfo = au_sbi(sb);
17570 + AuDebugOn(!sbinfo);
17571 + si_write_lock(sb, AuLock_NOPLMW);
17573 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17574 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17575 + case FS_MOVED_FROM:
17576 + case FS_MOVED_TO:
17577 + AuWarn1("DIRREN with UDBA may not work correctly "
17578 + "for the direct rename(2)\n");
17581 + ii_read_lock_parent(a->dir);
17583 + bbot = au_ibbot(a->dir);
17584 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17585 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17589 + ii_read_unlock(a->dir);
17590 + if (unlikely(bfound < 0))
17593 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17595 + if (a->h_child_inode)
17596 + h_ino = a->h_child_inode->i_ino;
17598 + if (a->h_child_nlen
17599 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17600 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17601 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17604 + if (dentry && d_really_is_positive(dentry))
17605 + inode = d_inode(dentry);
17606 + if (xino && !inode && h_ino
17607 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17608 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17609 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17610 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17614 + args.flags = a->flags[AuHn_CHILD];
17615 + args.dentry = dentry;
17616 + args.inode = inode;
17617 + args.h_inode = a->h_child_inode;
17618 + args.dir = a->dir;
17619 + args.h_dir = a->h_dir;
17620 + args.h_name = a->h_child_name;
17621 + args.h_nlen = a->h_child_nlen;
17622 + err = hn_job(&args);
17624 + if (au_di(dentry))
17625 + di_write_unlock(dentry);
17628 + if (inode && try_iput) {
17629 + ii_write_unlock(inode);
17633 + ii_write_lock_parent(a->dir);
17634 + args.flags = a->flags[AuHn_PARENT];
17635 + args.dentry = NULL;
17636 + args.inode = a->dir;
17637 + args.h_inode = a->h_dir;
17639 + args.h_dir = NULL;
17640 + args.h_name = NULL;
17642 + err = hn_job(&args);
17643 + ii_write_unlock(a->dir);
17646 + iput(a->h_child_inode);
17649 + si_write_unlock(sb);
17650 + au_nwt_done(&sbinfo->si_nowait);
17654 +/* ---------------------------------------------------------------------- */
17656 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17657 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17660 + unsigned int flags[AuHnLast], f;
17661 + unsigned char isdir, isroot, wh;
17662 + struct inode *dir;
17663 + struct au_hnotify_args *args;
17664 + char *p, *h_child_name;
17667 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17668 + dir = igrab(hnotify->hn_aufs_inode);
17672 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17674 + h_child_name = (void *)h_child_qstr->name;
17675 + len = h_child_qstr->len;
17676 + if (h_child_name) {
17677 + if (len > AUFS_WH_PFX_LEN
17678 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17679 + h_child_name += AUFS_WH_PFX_LEN;
17680 + len -= AUFS_WH_PFX_LEN;
17686 + if (h_child_inode)
17687 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17688 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17689 + flags[AuHn_CHILD] = 0;
17691 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17692 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17693 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17694 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17695 + case FS_MOVED_FROM:
17696 + case FS_MOVED_TO:
17697 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17698 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17701 + AuDebugOn(!h_child_name);
17706 + * aufs never be able to get this child inode.
17707 + * revalidation should be in d_revalidate()
17708 + * by checking i_nlink, i_generation or d_unhashed().
17710 + AuDebugOn(!h_child_name);
17711 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17712 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17720 + h_child_inode = NULL;
17723 + /* iput() and kfree() will be called in au_hnotify() */
17724 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17725 + if (unlikely(!args)) {
17726 + AuErr1("no memory\n");
17730 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17731 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17732 + args->mask = mask;
17734 + args->h_dir = igrab(h_dir);
17735 + if (h_child_inode)
17736 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17737 + args->h_child_inode = h_child_inode;
17738 + args->h_child_nlen = len;
17740 + p = (void *)args;
17741 + p += sizeof(*args);
17742 + memcpy(p, h_child_name, len);
17746 + /* NFS fires the event for silly-renamed one from kworker */
17748 + if (!dir->i_nlink
17749 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17751 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17752 + if (unlikely(err)) {
17753 + pr_err("wkq %d\n", err);
17754 + iput(args->h_child_inode);
17755 + iput(args->h_dir);
17764 +/* ---------------------------------------------------------------------- */
17766 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17770 + AuDebugOn(!(udba & AuOptMask_UDBA));
17773 + if (au_hnotify_op.reset_br)
17774 + err = au_hnotify_op.reset_br(udba, br, perm);
17779 +int au_hnotify_init_br(struct au_branch *br, int perm)
17784 + if (au_hnotify_op.init_br)
17785 + err = au_hnotify_op.init_br(br, perm);
17790 +void au_hnotify_fin_br(struct au_branch *br)
17792 + if (au_hnotify_op.fin_br)
17793 + au_hnotify_op.fin_br(br);
17796 +static void au_hn_destroy_cache(void)
17798 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17799 + au_cache[AuCache_HNOTIFY] = NULL;
17802 +int __init au_hnotify_init(void)
17807 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17808 + if (au_cache[AuCache_HNOTIFY]) {
17810 + if (au_hnotify_op.init)
17811 + err = au_hnotify_op.init();
17812 + if (unlikely(err))
17813 + au_hn_destroy_cache();
17819 +void au_hnotify_fin(void)
17821 + if (au_hnotify_op.fin)
17822 + au_hnotify_op.fin();
17824 + /* cf. au_cache_fin() */
17825 + if (au_cache[AuCache_HNOTIFY])
17826 + au_hn_destroy_cache();
17828 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17829 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17830 +++ linux/fs/aufs/iinfo.c 2017-11-12 22:24:42.270843503 +0100
17833 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17835 + * This program, aufs is free software; you can redistribute it and/or modify
17836 + * it under the terms of the GNU General Public License as published by
17837 + * the Free Software Foundation; either version 2 of the License, or
17838 + * (at your option) any later version.
17840 + * This program is distributed in the hope that it will be useful,
17841 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17842 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17843 + * GNU General Public License for more details.
17845 + * You should have received a copy of the GNU General Public License
17846 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17850 + * inode private data
17855 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17857 + struct inode *h_inode;
17858 + struct au_hinode *hinode;
17860 + IiMustAnyLock(inode);
17862 + hinode = au_hinode(au_ii(inode), bindex);
17863 + h_inode = hinode->hi_inode;
17864 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17868 +/* todo: hard/soft set? */
17869 +void au_hiput(struct au_hinode *hinode)
17871 + au_hn_free(hinode);
17872 + dput(hinode->hi_whdentry);
17873 + iput(hinode->hi_inode);
17876 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17878 + unsigned int flags;
17879 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17882 + if (au_opt_test(mnt_flags, XINO))
17883 + au_fset_hi(flags, XINO);
17884 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17885 + au_fset_hi(flags, HNOTIFY);
17889 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17890 + struct inode *h_inode, unsigned int flags)
17892 + struct au_hinode *hinode;
17893 + struct inode *hi;
17894 + struct au_iinfo *iinfo = au_ii(inode);
17896 + IiMustWriteLock(inode);
17898 + hinode = au_hinode(iinfo, bindex);
17899 + hi = hinode->hi_inode;
17900 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17903 + au_hiput(hinode);
17904 + hinode->hi_inode = h_inode;
17907 + struct super_block *sb = inode->i_sb;
17908 + struct au_branch *br;
17910 + AuDebugOn(inode->i_mode
17911 + && (h_inode->i_mode & S_IFMT)
17912 + != (inode->i_mode & S_IFMT));
17913 + if (bindex == iinfo->ii_btop)
17914 + au_cpup_igen(inode, h_inode);
17915 + br = au_sbr(sb, bindex);
17916 + hinode->hi_id = br->br_id;
17917 + if (au_ftest_hi(flags, XINO)) {
17918 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17920 + if (unlikely(err))
17921 + AuIOErr1("failed au_xino_write() %d\n", err);
17924 + if (au_ftest_hi(flags, HNOTIFY)
17925 + && au_br_hnotifyable(br->br_perm)) {
17926 + err = au_hn_alloc(hinode, inode);
17927 + if (unlikely(err))
17928 + AuIOErr1("au_hn_alloc() %d\n", err);
17933 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17934 + struct dentry *h_wh)
17936 + struct au_hinode *hinode;
17938 + IiMustWriteLock(inode);
17940 + hinode = au_hinode(au_ii(inode), bindex);
17941 + AuDebugOn(hinode->hi_whdentry);
17942 + hinode->hi_whdentry = h_wh;
17945 +void au_update_iigen(struct inode *inode, int half)
17947 + struct au_iinfo *iinfo;
17948 + struct au_iigen *iigen;
17949 + unsigned int sigen;
17951 + sigen = au_sigen(inode->i_sb);
17952 + iinfo = au_ii(inode);
17953 + iigen = &iinfo->ii_generation;
17954 + spin_lock(&iigen->ig_spin);
17955 + iigen->ig_generation = sigen;
17957 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17959 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17960 + spin_unlock(&iigen->ig_spin);
17963 +/* it may be called at remount time, too */
17964 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17966 + struct au_iinfo *iinfo;
17967 + aufs_bindex_t bindex, bbot;
17969 + AuDebugOn(au_is_bad_inode(inode));
17970 + IiMustWriteLock(inode);
17972 + iinfo = au_ii(inode);
17973 + if (do_put_zero && iinfo->ii_btop >= 0) {
17974 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17976 + struct inode *h_i;
17978 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17981 + && !(h_i->i_state & I_LINKABLE))
17982 + au_set_h_iptr(inode, bindex, NULL, 0);
17986 + iinfo->ii_btop = -1;
17987 + iinfo->ii_bbot = -1;
17988 + bbot = au_sbbot(inode->i_sb);
17989 + for (bindex = 0; bindex <= bbot; bindex++)
17990 + if (au_hinode(iinfo, bindex)->hi_inode) {
17991 + iinfo->ii_btop = bindex;
17994 + if (iinfo->ii_btop >= 0)
17995 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17996 + if (au_hinode(iinfo, bindex)->hi_inode) {
17997 + iinfo->ii_bbot = bindex;
18000 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18003 +/* ---------------------------------------------------------------------- */
18005 +void au_icntnr_init_once(void *_c)
18007 + struct au_icntnr *c = _c;
18008 + struct au_iinfo *iinfo = &c->iinfo;
18010 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18011 + au_rw_init(&iinfo->ii_rwsem);
18012 + inode_init_once(&c->vfs_inode);
18015 +void au_hinode_init(struct au_hinode *hinode)
18017 + hinode->hi_inode = NULL;
18018 + hinode->hi_id = -1;
18019 + au_hn_init(hinode);
18020 + hinode->hi_whdentry = NULL;
18023 +int au_iinfo_init(struct inode *inode)
18025 + struct au_iinfo *iinfo;
18026 + struct super_block *sb;
18027 + struct au_hinode *hi;
18030 + sb = inode->i_sb;
18031 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18032 + nbr = au_sbbot(sb) + 1;
18033 + if (unlikely(nbr <= 0))
18035 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18037 + au_ninodes_inc(sb);
18039 + iinfo->ii_hinode = hi;
18040 + for (i = 0; i < nbr; i++, hi++)
18041 + au_hinode_init(hi);
18043 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18044 + iinfo->ii_btop = -1;
18045 + iinfo->ii_bbot = -1;
18046 + iinfo->ii_vdir = NULL;
18052 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18055 + struct au_hinode *hip;
18057 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18060 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18063 + iinfo->ii_hinode = hip;
18064 + i = iinfo->ii_bbot + 1;
18066 + for (; i < nbr; i++, hip++)
18067 + au_hinode_init(hip);
18074 +void au_iinfo_fin(struct inode *inode)
18076 + struct au_iinfo *iinfo;
18077 + struct au_hinode *hi;
18078 + struct super_block *sb;
18079 + aufs_bindex_t bindex, bbot;
18080 + const unsigned char unlinked = !inode->i_nlink;
18082 + AuDebugOn(au_is_bad_inode(inode));
18084 + sb = inode->i_sb;
18085 + au_ninodes_dec(sb);
18086 + if (si_pid_test(sb))
18087 + au_xino_delete_inode(inode, unlinked);
18090 + * it is safe to hide the dependency between sbinfo and
18094 + si_noflush_read_lock(sb);
18095 + au_xino_delete_inode(inode, unlinked);
18096 + si_read_unlock(sb);
18100 + iinfo = au_ii(inode);
18101 + if (iinfo->ii_vdir)
18102 + au_vdir_free(iinfo->ii_vdir);
18104 + bindex = iinfo->ii_btop;
18105 + if (bindex >= 0) {
18106 + hi = au_hinode(iinfo, bindex);
18107 + bbot = iinfo->ii_bbot;
18108 + while (bindex++ <= bbot) {
18109 + if (hi->hi_inode)
18114 + kfree(iinfo->ii_hinode);
18115 + AuRwDestroy(&iinfo->ii_rwsem);
18117 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18118 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18119 +++ linux/fs/aufs/inode.c 2017-11-12 22:24:42.270843503 +0100
18122 + * Copyright (C) 2005-2017 Junjiro R. Okajima
18124 + * This program, aufs is free software; you can redistribute it and/or modify
18125 + * it under the terms of the GNU General Public License as published by
18126 + * the Free Software Foundation; either version 2 of the License, or
18127 + * (at your option) any later version.
18129 + * This program is distributed in the hope that it will be useful,
18130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18132 + * GNU General Public License for more details.
18134 + * You should have received a copy of the GNU General Public License
18135 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18139 + * inode functions
18144 +struct inode *au_igrab(struct inode *inode)
18147 + AuDebugOn(!atomic_read(&inode->i_count));
18153 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18155 + au_cpup_attr_all(inode, /*force*/0);
18156 + au_update_iigen(inode, /*half*/1);
18158 + inode->i_version++;
18161 +static int au_ii_refresh(struct inode *inode, int *update)
18165 + aufs_bindex_t bindex, new_bindex;
18166 + struct super_block *sb;
18167 + struct au_iinfo *iinfo;
18168 + struct au_hinode *p, *q, tmp;
18170 + AuDebugOn(au_is_bad_inode(inode));
18171 + IiMustWriteLock(inode);
18174 + sb = inode->i_sb;
18175 + nbr = au_sbbot(sb) + 1;
18176 + type = inode->i_mode & S_IFMT;
18177 + iinfo = au_ii(inode);
18178 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18179 + if (unlikely(err))
18182 + AuDebugOn(iinfo->ii_btop < 0);
18183 + p = au_hinode(iinfo, iinfo->ii_btop);
18184 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18186 + if (!p->hi_inode)
18189 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18190 + new_bindex = au_br_index(sb, p->hi_id);
18191 + if (new_bindex == bindex)
18194 + if (new_bindex < 0) {
18197 + p->hi_inode = NULL;
18201 + if (new_bindex < iinfo->ii_btop)
18202 + iinfo->ii_btop = new_bindex;
18203 + if (iinfo->ii_bbot < new_bindex)
18204 + iinfo->ii_bbot = new_bindex;
18205 + /* swap two lower inode, and loop again */
18206 + q = au_hinode(iinfo, new_bindex);
18210 + if (tmp.hi_inode) {
18215 + au_update_ibrange(inode, /*do_put_zero*/0);
18216 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18217 + e = au_dy_irefresh(inode);
18218 + if (unlikely(e && !err))
18226 +void au_refresh_iop(struct inode *inode, int force_getattr)
18229 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18230 + const struct inode_operations *iop
18231 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18233 + if (inode->i_op == iop)
18236 + switch (inode->i_mode & S_IFMT) {
18238 + type = AuIop_DIR;
18241 + type = AuIop_SYMLINK;
18244 + type = AuIop_OTHER;
18248 + inode->i_op = iop + type;
18249 + /* unnecessary smp_wmb() */
18252 +int au_refresh_hinode_self(struct inode *inode)
18256 + err = au_ii_refresh(inode, &update);
18258 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18264 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18266 + int err, e, update;
18267 + unsigned int flags;
18269 + aufs_bindex_t bindex, bbot;
18270 + unsigned char isdir;
18271 + struct au_hinode *p;
18272 + struct au_iinfo *iinfo;
18274 + err = au_ii_refresh(inode, &update);
18275 + if (unlikely(err))
18279 + iinfo = au_ii(inode);
18280 + p = au_hinode(iinfo, iinfo->ii_btop);
18281 + mode = (inode->i_mode & S_IFMT);
18282 + isdir = S_ISDIR(mode);
18283 + flags = au_hi_flags(inode, isdir);
18284 + bbot = au_dbbot(dentry);
18285 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18286 + struct inode *h_i, *h_inode;
18287 + struct dentry *h_d;
18289 + h_d = au_h_dptr(dentry, bindex);
18290 + if (!h_d || d_is_negative(h_d))
18293 + h_inode = d_inode(h_d);
18294 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18295 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18296 + h_i = au_h_iptr(inode, bindex);
18298 + if (h_i == h_inode)
18304 + if (bindex < iinfo->ii_btop)
18305 + iinfo->ii_btop = bindex;
18306 + if (iinfo->ii_bbot < bindex)
18307 + iinfo->ii_bbot = bindex;
18308 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18311 + au_update_ibrange(inode, /*do_put_zero*/0);
18312 + e = au_dy_irefresh(inode);
18313 + if (unlikely(e && !err))
18316 + au_refresh_hinode_attr(inode, update && isdir);
18323 +static int set_inode(struct inode *inode, struct dentry *dentry)
18326 + unsigned int flags;
18328 + aufs_bindex_t bindex, btop, btail;
18329 + unsigned char isdir;
18330 + struct dentry *h_dentry;
18331 + struct inode *h_inode;
18332 + struct au_iinfo *iinfo;
18333 + struct inode_operations *iop;
18335 + IiMustWriteLock(inode);
18339 + iop = au_sbi(inode->i_sb)->si_iop_array;
18340 + btop = au_dbtop(dentry);
18341 + h_dentry = au_h_dptr(dentry, btop);
18342 + h_inode = d_inode(h_dentry);
18343 + mode = h_inode->i_mode;
18344 + switch (mode & S_IFMT) {
18346 + btail = au_dbtail(dentry);
18347 + inode->i_op = iop + AuIop_OTHER;
18348 + inode->i_fop = &aufs_file_fop;
18349 + err = au_dy_iaop(inode, btop, h_inode);
18350 + if (unlikely(err))
18355 + btail = au_dbtaildir(dentry);
18356 + inode->i_op = iop + AuIop_DIR;
18357 + inode->i_fop = &aufs_dir_fop;
18360 + btail = au_dbtail(dentry);
18361 + inode->i_op = iop + AuIop_SYMLINK;
18367 + btail = au_dbtail(dentry);
18368 + inode->i_op = iop + AuIop_OTHER;
18369 + init_special_inode(inode, mode, h_inode->i_rdev);
18372 + AuIOErr("Unknown file type 0%o\n", mode);
18377 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18378 + flags = au_hi_flags(inode, isdir);
18379 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18380 + && au_ftest_hi(flags, HNOTIFY)
18381 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18382 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18383 + au_fclr_hi(flags, HNOTIFY);
18384 + iinfo = au_ii(inode);
18385 + iinfo->ii_btop = btop;
18386 + iinfo->ii_bbot = btail;
18387 + for (bindex = btop; bindex <= btail; bindex++) {
18388 + h_dentry = au_h_dptr(dentry, bindex);
18390 + au_set_h_iptr(inode, bindex,
18391 + au_igrab(d_inode(h_dentry)), flags);
18393 + au_cpup_attr_all(inode, /*force*/1);
18395 + * to force calling aufs_get_acl() every time,
18396 + * do not call cache_no_acl() for aufs inode.
18404 + * successful returns with iinfo write_locked
18406 + * zero: success, matched
18407 + * plus: no error, but unmatched
18409 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18412 + unsigned int gen, igflags;
18413 + aufs_bindex_t bindex, bbot;
18414 + struct inode *h_inode, *h_dinode;
18415 + struct dentry *h_dentry;
18418 + * before this function, if aufs got any iinfo lock, it must be only
18419 + * one, the parent dir.
18420 + * it can happen by UDBA and the obsoleted inode number.
18423 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18427 + ii_write_lock_new_child(inode);
18428 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18429 + h_dinode = d_inode(h_dentry);
18430 + bbot = au_ibbot(inode);
18431 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18432 + h_inode = au_h_iptr(inode, bindex);
18433 + if (!h_inode || h_inode != h_dinode)
18437 + gen = au_iigen(inode, &igflags);
18438 + if (gen == au_digen(dentry)
18439 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18442 + /* fully refresh inode using dentry */
18443 + err = au_refresh_hinode(inode, dentry);
18445 + au_update_iigen(inode, /*half*/0);
18449 + if (unlikely(err))
18450 + ii_write_unlock(inode);
18455 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18456 + unsigned int d_type, ino_t *ino)
18459 + const int isnondir = d_type != DT_DIR;
18461 + /* prevent hardlinked inode number from race condition */
18463 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18464 + if (unlikely(err))
18468 + err = au_xino_read(sb, bindex, h_ino, ino);
18469 + if (unlikely(err))
18470 + goto out_xinondir;
18474 + *ino = au_xino_new_ino(sb);
18475 + if (unlikely(!*ino))
18476 + goto out_xinondir;
18477 + err = au_xino_write(sb, bindex, h_ino, *ino);
18478 + if (unlikely(err))
18479 + goto out_xinondir;
18483 + if (isnondir && idx >= 0)
18484 + au_xinondir_leave(sb, bindex, h_ino, idx);
18489 +/* successful returns with iinfo write_locked */
18490 +/* todo: return with unlocked? */
18491 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18493 + struct inode *inode, *h_inode;
18494 + struct dentry *h_dentry;
18495 + struct super_block *sb;
18496 + ino_t h_ino, ino;
18497 + int err, idx, hlinked;
18498 + aufs_bindex_t btop;
18500 + sb = dentry->d_sb;
18501 + btop = au_dbtop(dentry);
18502 + h_dentry = au_h_dptr(dentry, btop);
18503 + h_inode = d_inode(h_dentry);
18504 + h_ino = h_inode->i_ino;
18505 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18509 + * stop 'race'-ing between hardlinks under different
18513 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18514 + inode = ERR_PTR(err);
18515 + if (unlikely(err))
18519 + err = au_xino_read(sb, btop, h_ino, &ino);
18520 + inode = ERR_PTR(err);
18521 + if (unlikely(err))
18522 + goto out_xinondir;
18525 + ino = au_xino_new_ino(sb);
18526 + if (unlikely(!ino)) {
18527 + inode = ERR_PTR(-EIO);
18528 + goto out_xinondir;
18532 + AuDbg("i%lu\n", (unsigned long)ino);
18533 + inode = au_iget_locked(sb, ino);
18534 + err = PTR_ERR(inode);
18535 + if (IS_ERR(inode))
18536 + goto out_xinondir;
18538 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18539 + if (inode->i_state & I_NEW) {
18540 + ii_write_lock_new_child(inode);
18541 + err = set_inode(inode, dentry);
18543 + unlock_new_inode(inode);
18544 + goto out_xinondir; /* success */
18548 + * iget_failed() calls iput(), but we need to call
18549 + * ii_write_unlock() after iget_failed(). so dirty hack for
18552 + atomic_inc(&inode->i_count);
18553 + iget_failed(inode);
18554 + ii_write_unlock(inode);
18555 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18556 + /* ignore this error */
18558 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18560 + * horrible race condition between lookup, readdir and copyup
18561 + * (or something).
18563 + if (hlinked && idx >= 0)
18564 + au_xinondir_leave(sb, btop, h_ino, idx);
18565 + err = reval_inode(inode, dentry);
18566 + if (unlikely(err < 0)) {
18571 + goto out; /* success */
18572 + else if (hlinked && idx >= 0) {
18573 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18574 + if (unlikely(err)) {
18576 + inode = ERR_PTR(err);
18582 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18583 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18584 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18585 + btop, au_sbtype(h_dentry->d_sb), dentry,
18586 + (unsigned long)h_ino, (unsigned long)ino);
18588 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18591 + if (hlinked && idx >= 0)
18592 + au_xinondir_leave(sb, btop, h_ino, idx);
18598 + inode = ERR_PTR(err);
18600 + if (hlinked && idx >= 0)
18601 + au_xinondir_leave(sb, btop, h_ino, idx);
18606 +/* ---------------------------------------------------------------------- */
18608 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18609 + struct inode *inode)
18612 + struct inode *hi;
18614 + err = au_br_rdonly(au_sbr(sb, bindex));
18616 + /* pseudo-link after flushed may happen out of bounds */
18619 + && au_ibtop(inode) <= bindex
18620 + && bindex <= au_ibbot(inode)) {
18622 + * permission check is unnecessary since vfsub routine
18623 + * will be called later
18625 + hi = au_h_iptr(inode, bindex);
18627 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18633 +int au_test_h_perm(struct inode *h_inode, int mask)
18635 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18637 + return inode_permission(h_inode, mask);
18640 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18642 + if (au_test_nfs(h_inode->i_sb)
18643 + && (mask & MAY_WRITE)
18644 + && S_ISDIR(h_inode->i_mode))
18645 + mask |= MAY_READ; /* force permission check */
18646 + return au_test_h_perm(h_inode, mask);
18648 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18649 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18650 +++ linux/fs/aufs/inode.h 2017-11-12 22:24:44.707577830 +0100
18653 + * Copyright (C) 2005-2017 Junjiro R. Okajima
18655 + * This program, aufs is free software; you can redistribute it and/or modify
18656 + * it under the terms of the GNU General Public License as published by
18657 + * the Free Software Foundation; either version 2 of the License, or
18658 + * (at your option) any later version.
18660 + * This program is distributed in the hope that it will be useful,
18661 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18662 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18663 + * GNU General Public License for more details.
18665 + * You should have received a copy of the GNU General Public License
18666 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18670 + * inode operations
18673 +#ifndef __AUFS_INODE_H__
18674 +#define __AUFS_INODE_H__
18678 +#include <linux/fsnotify.h>
18679 +#include "rwsem.h"
18683 +struct au_hnotify {
18684 +#ifdef CONFIG_AUFS_HNOTIFY
18685 +#ifdef CONFIG_AUFS_HFSNOTIFY
18686 + /* never use fsnotify_add_vfsmount_mark() */
18687 + struct fsnotify_mark hn_mark;
18689 + struct inode *hn_aufs_inode; /* no get/put */
18691 +} ____cacheline_aligned_in_smp;
18693 +struct au_hinode {
18694 + struct inode *hi_inode;
18695 + aufs_bindex_t hi_id;
18696 +#ifdef CONFIG_AUFS_HNOTIFY
18697 + struct au_hnotify *hi_notify;
18700 + /* reference to the copied-up whiteout with get/put */
18701 + struct dentry *hi_whdentry;
18705 +#define AuIG_HALF_REFRESHED 1
18706 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18707 +#define au_ig_fset(flags, name) \
18708 + do { (flags) |= AuIG_##name; } while (0)
18709 +#define au_ig_fclr(flags, name) \
18710 + do { (flags) &= ~AuIG_##name; } while (0)
18713 + spinlock_t ig_spin;
18714 + __u32 ig_generation, ig_flags;
18719 + struct au_iigen ii_generation;
18720 + struct super_block *ii_hsb1; /* no get/put */
18722 + struct au_rwsem ii_rwsem;
18723 + aufs_bindex_t ii_btop, ii_bbot;
18725 + struct au_hinode *ii_hinode;
18726 + struct au_vdir *ii_vdir;
18729 +struct au_icntnr {
18730 + struct au_iinfo iinfo;
18731 + struct inode vfs_inode;
18732 + struct hlist_bl_node plink;
18733 +} ____cacheline_aligned_in_smp;
18735 +/* au_pin flags */
18736 +#define AuPin_DI_LOCKED 1
18737 +#define AuPin_MNT_WRITE (1 << 1)
18738 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18739 +#define au_fset_pin(flags, name) \
18740 + do { (flags) |= AuPin_##name; } while (0)
18741 +#define au_fclr_pin(flags, name) \
18742 + do { (flags) &= ~AuPin_##name; } while (0)
18746 + struct dentry *dentry;
18747 + unsigned int udba;
18748 + unsigned char lsc_di, lsc_hi, flags;
18749 + aufs_bindex_t bindex;
18752 + struct dentry *parent;
18753 + struct au_hinode *hdir;
18754 + struct vfsmount *h_mnt;
18756 + /* temporary unlock/relock for copyup */
18757 + struct dentry *h_dentry, *h_parent;
18758 + struct au_branch *br;
18759 + struct task_struct *task;
18762 +void au_pin_hdir_unlock(struct au_pin *p);
18763 +int au_pin_hdir_lock(struct au_pin *p);
18764 +int au_pin_hdir_relock(struct au_pin *p);
18765 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18766 +void au_pin_hdir_release(struct au_pin *p);
18768 +/* ---------------------------------------------------------------------- */
18770 +static inline struct au_iinfo *au_ii(struct inode *inode)
18772 + BUG_ON(is_bad_inode(inode));
18773 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18776 +/* ---------------------------------------------------------------------- */
18779 +struct inode *au_igrab(struct inode *inode);
18780 +void au_refresh_iop(struct inode *inode, int force_getattr);
18781 +int au_refresh_hinode_self(struct inode *inode);
18782 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18783 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18784 + unsigned int d_type, ino_t *ino);
18785 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18786 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18787 + struct inode *inode);
18788 +int au_test_h_perm(struct inode *h_inode, int mask);
18789 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18791 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18792 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18794 +#ifdef CONFIG_AUFS_SHWH
18795 + return au_ino(sb, bindex, h_ino, d_type, ino);
18808 +extern struct inode_operations aufs_iop[AuIop_Last],
18809 + aufs_iop_nogetattr[AuIop_Last];
18811 +/* au_wr_dir flags */
18812 +#define AuWrDir_ADD_ENTRY 1
18813 +#define AuWrDir_ISDIR (1 << 1)
18814 +#define AuWrDir_TMPFILE (1 << 2)
18815 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18816 +#define au_fset_wrdir(flags, name) \
18817 + do { (flags) |= AuWrDir_##name; } while (0)
18818 +#define au_fclr_wrdir(flags, name) \
18819 + do { (flags) &= ~AuWrDir_##name; } while (0)
18821 +struct au_wr_dir_args {
18822 + aufs_bindex_t force_btgt;
18823 + unsigned char flags;
18825 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18826 + struct au_wr_dir_args *args);
18828 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18829 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18830 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18831 + unsigned int udba, unsigned char flags);
18832 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18833 + unsigned int udba, unsigned char flags) __must_check;
18834 +int au_do_pin(struct au_pin *pin) __must_check;
18835 +void au_unpin(struct au_pin *pin);
18836 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18838 +#define AuIcpup_DID_CPUP 1
18839 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18840 +#define au_fset_icpup(flags, name) \
18841 + do { (flags) |= AuIcpup_##name; } while (0)
18842 +#define au_fclr_icpup(flags, name) \
18843 + do { (flags) &= ~AuIcpup_##name; } while (0)
18845 +struct au_icpup_args {
18846 + unsigned char flags;
18847 + unsigned char pin_flags;
18848 + aufs_bindex_t btgt;
18849 + unsigned int udba;
18850 + struct au_pin pin;
18851 + struct path h_path;
18852 + struct inode *h_inode;
18855 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18856 + struct au_icpup_args *a);
18858 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18862 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18863 + struct dentry *h_parent, int isdir);
18864 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18866 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18867 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18869 +struct vfsub_aopen_args;
18870 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18871 + struct vfsub_aopen_args *args);
18872 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18873 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18874 + struct dentry *dentry);
18875 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18878 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18879 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18880 + struct dentry *h_parent, int isdir);
18881 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18882 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18885 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18886 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18887 + struct inode *dir, struct dentry *dentry,
18888 + unsigned int flags);
18891 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18892 +void au_hiput(struct au_hinode *hinode);
18893 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18894 + struct dentry *h_wh);
18895 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18897 +/* hinode flags */
18898 +#define AuHi_XINO 1
18899 +#define AuHi_HNOTIFY (1 << 1)
18900 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18901 +#define au_fset_hi(flags, name) \
18902 + do { (flags) |= AuHi_##name; } while (0)
18903 +#define au_fclr_hi(flags, name) \
18904 + do { (flags) &= ~AuHi_##name; } while (0)
18906 +#ifndef CONFIG_AUFS_HNOTIFY
18907 +#undef AuHi_HNOTIFY
18908 +#define AuHi_HNOTIFY 0
18911 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18912 + struct inode *h_inode, unsigned int flags);
18914 +void au_update_iigen(struct inode *inode, int half);
18915 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18917 +void au_icntnr_init_once(void *_c);
18918 +void au_hinode_init(struct au_hinode *hinode);
18919 +int au_iinfo_init(struct inode *inode);
18920 +void au_iinfo_fin(struct inode *inode);
18921 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18923 +#ifdef CONFIG_PROC_FS
18925 +int au_plink_maint(struct super_block *sb, int flags);
18927 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18928 +int au_plink_maint_enter(struct super_block *sb);
18929 +#ifdef CONFIG_AUFS_DEBUG
18930 +void au_plink_list(struct super_block *sb);
18932 +AuStubVoid(au_plink_list, struct super_block *sb)
18934 +int au_plink_test(struct inode *inode);
18935 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18936 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18937 + struct dentry *h_dentry);
18938 +void au_plink_put(struct super_block *sb, int verbose);
18939 +void au_plink_clean(struct super_block *sb, int verbose);
18940 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18942 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18943 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18944 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18945 +AuStubVoid(au_plink_list, struct super_block *sb);
18946 +AuStubInt0(au_plink_test, struct inode *inode);
18947 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18948 + struct inode *inode, aufs_bindex_t bindex);
18949 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18950 + struct dentry *h_dentry);
18951 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18952 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18953 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18954 +#endif /* CONFIG_PROC_FS */
18956 +#ifdef CONFIG_AUFS_XATTR
18958 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18959 + unsigned int verbose);
18960 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18961 +void au_xattr_init(struct super_block *sb);
18963 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18964 + int ignore_flags, unsigned int verbose);
18965 +AuStubVoid(au_xattr_init, struct super_block *sb);
18968 +#ifdef CONFIG_FS_POSIX_ACL
18969 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18970 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18973 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18979 +struct au_sxattr {
18983 + const char *name;
18984 + const void *value;
18989 + struct posix_acl *acl;
18994 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18995 + struct au_sxattr *arg);
18998 +/* ---------------------------------------------------------------------- */
19000 +/* lock subclass for iinfo */
19002 + AuLsc_II_CHILD, /* child first */
19003 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19004 + AuLsc_II_CHILD3, /* copyup dirs */
19005 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19006 + AuLsc_II_PARENT2,
19007 + AuLsc_II_PARENT3, /* copyup dirs */
19008 + AuLsc_II_NEW_CHILD
19012 + * ii_read_lock_child, ii_write_lock_child,
19013 + * ii_read_lock_child2, ii_write_lock_child2,
19014 + * ii_read_lock_child3, ii_write_lock_child3,
19015 + * ii_read_lock_parent, ii_write_lock_parent,
19016 + * ii_read_lock_parent2, ii_write_lock_parent2,
19017 + * ii_read_lock_parent3, ii_write_lock_parent3,
19018 + * ii_read_lock_new_child, ii_write_lock_new_child,
19020 +#define AuReadLockFunc(name, lsc) \
19021 +static inline void ii_read_lock_##name(struct inode *i) \
19023 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19026 +#define AuWriteLockFunc(name, lsc) \
19027 +static inline void ii_write_lock_##name(struct inode *i) \
19029 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19032 +#define AuRWLockFuncs(name, lsc) \
19033 + AuReadLockFunc(name, lsc) \
19034 + AuWriteLockFunc(name, lsc)
19036 +AuRWLockFuncs(child, CHILD);
19037 +AuRWLockFuncs(child2, CHILD2);
19038 +AuRWLockFuncs(child3, CHILD3);
19039 +AuRWLockFuncs(parent, PARENT);
19040 +AuRWLockFuncs(parent2, PARENT2);
19041 +AuRWLockFuncs(parent3, PARENT3);
19042 +AuRWLockFuncs(new_child, NEW_CHILD);
19044 +#undef AuReadLockFunc
19045 +#undef AuWriteLockFunc
19046 +#undef AuRWLockFuncs
19048 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19049 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19050 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19052 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19053 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19054 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19056 +/* ---------------------------------------------------------------------- */
19058 +static inline void au_icntnr_init(struct au_icntnr *c)
19060 +#ifdef CONFIG_AUFS_DEBUG
19061 + c->vfs_inode.i_mode = 0;
19065 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19067 + unsigned int gen;
19068 + struct au_iinfo *iinfo;
19069 + struct au_iigen *iigen;
19071 + iinfo = au_ii(inode);
19072 + iigen = &iinfo->ii_generation;
19073 + spin_lock(&iigen->ig_spin);
19075 + *igflags = iigen->ig_flags;
19076 + gen = iigen->ig_generation;
19077 + spin_unlock(&iigen->ig_spin);
19082 +/* tiny test for inode number */
19083 +/* tmpfs generation is too rough */
19084 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19086 + struct au_iinfo *iinfo;
19088 + iinfo = au_ii(inode);
19089 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19090 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19091 + && iinfo->ii_higen == h_inode->i_generation);
19094 +static inline void au_iigen_dec(struct inode *inode)
19096 + struct au_iinfo *iinfo;
19097 + struct au_iigen *iigen;
19099 + iinfo = au_ii(inode);
19100 + iigen = &iinfo->ii_generation;
19101 + spin_lock(&iigen->ig_spin);
19102 + iigen->ig_generation--;
19103 + spin_unlock(&iigen->ig_spin);
19106 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19111 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19117 +/* ---------------------------------------------------------------------- */
19119 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19120 + aufs_bindex_t bindex)
19122 + return iinfo->ii_hinode + bindex;
19125 +static inline int au_is_bad_inode(struct inode *inode)
19127 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19130 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19131 + aufs_bindex_t bindex)
19133 + IiMustAnyLock(inode);
19134 + return au_hinode(au_ii(inode), bindex)->hi_id;
19137 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19139 + IiMustAnyLock(inode);
19140 + return au_ii(inode)->ii_btop;
19143 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19145 + IiMustAnyLock(inode);
19146 + return au_ii(inode)->ii_bbot;
19149 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19151 + IiMustAnyLock(inode);
19152 + return au_ii(inode)->ii_vdir;
19155 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19157 + IiMustAnyLock(inode);
19158 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19161 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19163 + IiMustWriteLock(inode);
19164 + au_ii(inode)->ii_btop = bindex;
19167 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19169 + IiMustWriteLock(inode);
19170 + au_ii(inode)->ii_bbot = bindex;
19173 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19175 + IiMustWriteLock(inode);
19176 + au_ii(inode)->ii_vdir = vdir;
19179 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19181 + IiMustAnyLock(inode);
19182 + return au_hinode(au_ii(inode), bindex);
19185 +/* ---------------------------------------------------------------------- */
19187 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19190 + return pin->parent;
19194 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19196 + if (pin && pin->hdir)
19197 + return pin->hdir->hi_inode;
19201 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19204 + return pin->hdir;
19208 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19211 + pin->dentry = dentry;
19214 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19215 + unsigned char lflag)
19219 + au_fset_pin(pin->flags, DI_LOCKED);
19221 + au_fclr_pin(pin->flags, DI_LOCKED);
19225 +#if 0 /* reserved */
19226 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19229 + dput(pin->parent);
19230 + pin->parent = dget(parent);
19235 +/* ---------------------------------------------------------------------- */
19238 +#ifdef CONFIG_AUFS_HNOTIFY
19239 +struct au_hnotify_op {
19240 + void (*ctl)(struct au_hinode *hinode, int do_set);
19241 + int (*alloc)(struct au_hinode *hinode);
19244 + * if it returns true, the the caller should free hinode->hi_notify,
19245 + * otherwise ->free() frees it.
19247 + int (*free)(struct au_hinode *hinode,
19248 + struct au_hnotify *hn) __must_check;
19250 + void (*fin)(void);
19251 + int (*init)(void);
19253 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19254 + void (*fin_br)(struct au_branch *br);
19255 + int (*init_br)(struct au_branch *br, int perm);
19259 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19260 +void au_hn_free(struct au_hinode *hinode);
19261 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19262 +void au_hn_reset(struct inode *inode, unsigned int flags);
19263 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19264 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19265 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19266 +int au_hnotify_init_br(struct au_branch *br, int perm);
19267 +void au_hnotify_fin_br(struct au_branch *br);
19268 +int __init au_hnotify_init(void);
19269 +void au_hnotify_fin(void);
19272 +extern const struct au_hnotify_op au_hnotify_op;
19275 +void au_hn_init(struct au_hinode *hinode)
19277 + hinode->hi_notify = NULL;
19280 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19282 + return hinode->hi_notify;
19286 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19287 + struct au_hinode *hinode __maybe_unused,
19288 + struct inode *inode __maybe_unused)
19289 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19290 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19291 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19292 + int do_set __maybe_unused)
19293 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19294 + unsigned int flags __maybe_unused)
19295 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19296 + struct au_branch *br __maybe_unused,
19297 + int perm __maybe_unused)
19298 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19299 + int perm __maybe_unused)
19300 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19301 +AuStubInt0(__init au_hnotify_init, void)
19302 +AuStubVoid(au_hnotify_fin, void)
19303 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19304 +#endif /* CONFIG_AUFS_HNOTIFY */
19306 +static inline void au_hn_suspend(struct au_hinode *hdir)
19308 + au_hn_ctl(hdir, /*do_set*/0);
19311 +static inline void au_hn_resume(struct au_hinode *hdir)
19313 + au_hn_ctl(hdir, /*do_set*/1);
19316 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19318 + inode_lock(hdir->hi_inode);
19319 + au_hn_suspend(hdir);
19322 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19323 + unsigned int sc __maybe_unused)
19325 + inode_lock_nested(hdir->hi_inode, sc);
19326 + au_hn_suspend(hdir);
19329 +#if 0 /* unused */
19330 +#include "vfsub.h"
19331 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19334 + vfsub_inode_lock_shared_nested(hdir->hi_inode, sc);
19335 + au_hn_suspend(hdir);
19339 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19341 + au_hn_resume(hdir);
19342 + inode_unlock(hdir->hi_inode);
19345 +#endif /* __KERNEL__ */
19346 +#endif /* __AUFS_INODE_H__ */
19347 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19348 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19349 +++ linux/fs/aufs/ioctl.c 2017-07-29 12:14:25.903042072 +0200
19352 + * Copyright (C) 2005-2017 Junjiro R. Okajima
19354 + * This program, aufs is free software; you can redistribute it and/or modify
19355 + * it under the terms of the GNU General Public License as published by
19356 + * the Free Software Foundation; either version 2 of the License, or
19357 + * (at your option) any later version.
19359 + * This program is distributed in the hope that it will be useful,
19360 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19362 + * GNU General Public License for more details.
19364 + * You should have received a copy of the GNU General Public License
19365 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19370 + * plink-management and readdir in userspace.
19371 + * assist the pathconf(3) wrapper library.
19373 + * File-based Hierarchical Storage Management.
19376 +#include <linux/compat.h>
19377 +#include <linux/file.h>
19380 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19383 + aufs_bindex_t wbi, bindex, bbot;
19384 + struct file *h_file;
19385 + struct super_block *sb;
19386 + struct dentry *root;
19387 + struct au_branch *br;
19388 + struct aufs_wbr_fd wbrfd = {
19389 + .oflags = au_dir_roflags,
19392 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19393 + | O_NOATIME | O_CLOEXEC;
19395 + AuDebugOn(wbrfd.oflags & ~valid);
19398 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19399 + if (unlikely(err)) {
19405 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19406 + wbrfd.oflags |= au_dir_roflags;
19407 + AuDbg("0%o\n", wbrfd.oflags);
19408 + if (unlikely(wbrfd.oflags & ~valid))
19412 + fd = get_unused_fd_flags(0);
19414 + if (unlikely(fd < 0))
19417 + h_file = ERR_PTR(-EINVAL);
19420 + sb = path->dentry->d_sb;
19421 + root = sb->s_root;
19422 + aufs_read_lock(root, AuLock_IR);
19423 + bbot = au_sbbot(sb);
19424 + if (wbrfd.brid >= 0) {
19425 + wbi = au_br_index(sb, wbrfd.brid);
19426 + if (unlikely(wbi < 0 || wbi > bbot))
19430 + h_file = ERR_PTR(-ENOENT);
19431 + br = au_sbr(sb, wbi);
19432 + if (!au_br_writable(br->br_perm)) {
19436 + bindex = wbi + 1;
19438 + for (; bindex <= bbot; bindex++) {
19439 + br = au_sbr(sb, bindex);
19440 + if (au_br_writable(br->br_perm)) {
19442 + br = au_sbr(sb, wbi);
19447 + AuDbg("wbi %d\n", wbi);
19449 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19453 + aufs_read_unlock(root, AuLock_IR);
19454 + err = PTR_ERR(h_file);
19455 + if (IS_ERR(h_file))
19458 + au_br_put(br); /* cf. au_h_open() */
19459 + fd_install(fd, h_file);
19461 + goto out; /* success */
19464 + put_unused_fd(fd);
19470 +/* ---------------------------------------------------------------------- */
19472 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19475 + struct dentry *dentry;
19478 + case AUFS_CTL_RDU:
19479 + case AUFS_CTL_RDU_INO:
19480 + err = au_rdu_ioctl(file, cmd, arg);
19483 + case AUFS_CTL_WBR_FD:
19484 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19487 + case AUFS_CTL_IBUSY:
19488 + err = au_ibusy_ioctl(file, arg);
19491 + case AUFS_CTL_BRINFO:
19492 + err = au_brinfo_ioctl(file, arg);
19495 + case AUFS_CTL_FHSM_FD:
19496 + dentry = file->f_path.dentry;
19497 + if (IS_ROOT(dentry))
19498 + err = au_fhsm_fd(dentry->d_sb, arg);
19504 + /* do not call the lower */
19505 + AuDbg("0x%x\n", cmd);
19513 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19518 + case AUFS_CTL_MVDOWN:
19519 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19522 + case AUFS_CTL_WBR_FD:
19523 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19527 + /* do not call the lower */
19528 + AuDbg("0x%x\n", cmd);
19536 +#ifdef CONFIG_COMPAT
19537 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19538 + unsigned long arg)
19543 + case AUFS_CTL_RDU:
19544 + case AUFS_CTL_RDU_INO:
19545 + err = au_rdu_compat_ioctl(file, cmd, arg);
19548 + case AUFS_CTL_IBUSY:
19549 + err = au_ibusy_compat_ioctl(file, arg);
19552 + case AUFS_CTL_BRINFO:
19553 + err = au_brinfo_compat_ioctl(file, arg);
19557 + err = aufs_ioctl_dir(file, cmd, arg);
19564 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19565 + unsigned long arg)
19567 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19570 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19571 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19572 +++ linux/fs/aufs/i_op_add.c 2017-11-12 22:24:42.270843503 +0100
19575 + * Copyright (C) 2005-2017 Junjiro R. Okajima
19577 + * This program, aufs is free software; you can redistribute it and/or modify
19578 + * it under the terms of the GNU General Public License as published by
19579 + * the Free Software Foundation; either version 2 of the License, or
19580 + * (at your option) any later version.
19582 + * This program is distributed in the hope that it will be useful,
19583 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19584 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19585 + * GNU General Public License for more details.
19587 + * You should have received a copy of the GNU General Public License
19588 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19592 + * inode operations (add entry)
19598 + * final procedure of adding a new entry, except link(2).
19599 + * remove whiteout, instantiate, copyup the parent dir's times and size
19600 + * and update version.
19601 + * if it failed, re-create the removed whiteout.
19603 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19604 + struct dentry *wh_dentry, struct dentry *dentry)
19607 + aufs_bindex_t bwh;
19608 + struct path h_path;
19609 + struct super_block *sb;
19610 + struct inode *inode, *h_dir;
19611 + struct dentry *wh;
19616 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19617 + IMustLock(h_dir);
19618 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19619 + bwh = au_dbwh(dentry);
19620 + h_path.dentry = wh_dentry;
19621 + h_path.mnt = au_sbr_mnt(sb, bindex);
19622 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19624 + if (unlikely(err))
19628 + inode = au_new_inode(dentry, /*must_new*/1);
19629 + if (!IS_ERR(inode)) {
19630 + d_instantiate(dentry, inode);
19631 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19633 + au_dir_ts(dir, bindex);
19634 + dir->i_version++;
19635 + au_fhsm_wrote(sb, bindex, /*force*/0);
19636 + return 0; /* success */
19639 + err = PTR_ERR(inode);
19644 + /* dir inode is locked */
19645 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19646 + rerr = PTR_ERR(wh);
19647 + if (IS_ERR(wh)) {
19648 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19649 + dentry, err, rerr);
19658 +static int au_d_may_add(struct dentry *dentry)
19663 + if (unlikely(d_unhashed(dentry)))
19665 + if (unlikely(d_really_is_positive(dentry)))
19671 + * simple tests for the adding inode operations.
19672 + * following the checks in vfs, plus the parent-child relationship.
19674 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19675 + struct dentry *h_parent, int isdir)
19679 + struct dentry *h_dentry;
19680 + struct inode *h_inode;
19682 + err = -ENAMETOOLONG;
19683 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19686 + h_dentry = au_h_dptr(dentry, bindex);
19687 + if (d_really_is_negative(dentry)) {
19689 + if (unlikely(d_is_positive(h_dentry)))
19692 + /* rename(2) case */
19694 + if (unlikely(d_is_negative(h_dentry)))
19696 + h_inode = d_inode(h_dentry);
19697 + if (unlikely(!h_inode->i_nlink))
19700 + h_mode = h_inode->i_mode;
19703 + if (unlikely(S_ISDIR(h_mode)))
19705 + } else if (unlikely(!S_ISDIR(h_mode))) {
19712 + /* expected parent dir is locked */
19713 + if (unlikely(h_parent != h_dentry->d_parent))
19722 + * initial procedure of adding a new entry.
19723 + * prepare writable branch and the parent dir, lock it,
19724 + * and lookup whiteout for the new entry.
19726 +static struct dentry*
19727 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19728 + struct dentry *src_dentry, struct au_pin *pin,
19729 + struct au_wr_dir_args *wr_dir_args)
19731 + struct dentry *wh_dentry, *h_parent;
19732 + struct super_block *sb;
19733 + struct au_branch *br;
19735 + unsigned int udba;
19736 + aufs_bindex_t bcpup;
19738 + AuDbg("%pd\n", dentry);
19740 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19742 + wh_dentry = ERR_PTR(err);
19743 + if (unlikely(err < 0))
19746 + sb = dentry->d_sb;
19747 + udba = au_opt_udba(sb);
19748 + err = au_pin(pin, dentry, bcpup, udba,
19749 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19750 + wh_dentry = ERR_PTR(err);
19751 + if (unlikely(err))
19754 + h_parent = au_pinned_h_parent(pin);
19755 + if (udba != AuOpt_UDBA_NONE
19756 + && au_dbtop(dentry) == bcpup)
19757 + err = au_may_add(dentry, bcpup, h_parent,
19758 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19759 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19760 + err = -ENAMETOOLONG;
19761 + wh_dentry = ERR_PTR(err);
19762 + if (unlikely(err))
19765 + br = au_sbr(sb, bcpup);
19767 + struct path tmp = {
19768 + .dentry = h_parent,
19769 + .mnt = au_br_mnt(br)
19771 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19774 + wh_dentry = NULL;
19775 + if (bcpup != au_dbwh(dentry))
19776 + goto out; /* success */
19779 + * ENAMETOOLONG here means that if we allowed create such name, then it
19780 + * would not be able to removed in the future. So we don't allow such
19781 + * name here and we don't handle ENAMETOOLONG differently here.
19783 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19786 + if (IS_ERR(wh_dentry))
19789 + return wh_dentry;
19792 +/* ---------------------------------------------------------------------- */
19794 +enum { Mknod, Symlink, Creat };
19795 +struct simple_arg {
19802 + struct vfsub_aopen_args *aopen;
19805 + const char *symname;
19814 +static int add_simple(struct inode *dir, struct dentry *dentry,
19815 + struct simple_arg *arg)
19818 + aufs_bindex_t btop;
19819 + unsigned char created;
19820 + const unsigned char try_aopen
19821 + = (arg->type == Creat && arg->u.c.try_aopen);
19822 + struct dentry *wh_dentry, *parent;
19823 + struct inode *h_dir;
19824 + struct super_block *sb;
19825 + struct au_branch *br;
19826 + /* to reuduce stack size */
19828 + struct au_dtime dt;
19829 + struct au_pin pin;
19830 + struct path h_path;
19831 + struct au_wr_dir_args wr_dir_args;
19834 + AuDbg("%pd\n", dentry);
19838 + a = kmalloc(sizeof(*a), GFP_NOFS);
19839 + if (unlikely(!a))
19841 + a->wr_dir_args.force_btgt = -1;
19842 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19844 + parent = dentry->d_parent; /* dir inode is locked */
19845 + if (!try_aopen) {
19846 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19847 + if (unlikely(err))
19850 + err = au_d_may_add(dentry);
19851 + if (unlikely(err))
19854 + di_write_lock_parent(parent);
19855 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19856 + &a->pin, &a->wr_dir_args);
19857 + err = PTR_ERR(wh_dentry);
19858 + if (IS_ERR(wh_dentry))
19861 + btop = au_dbtop(dentry);
19862 + sb = dentry->d_sb;
19863 + br = au_sbr(sb, btop);
19864 + a->h_path.dentry = au_h_dptr(dentry, btop);
19865 + a->h_path.mnt = au_br_mnt(br);
19866 + h_dir = au_pinned_h_dir(&a->pin);
19867 + switch (arg->type) {
19870 + if (!try_aopen || !h_dir->i_op->atomic_open)
19871 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19872 + arg->u.c.want_excl);
19874 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
19875 + arg->u.c.aopen, br);
19878 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19881 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19889 + err = epilog(dir, btop, wh_dentry, dentry);
19892 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
19893 + /* no delegation since it is just created */
19894 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19897 + AuIOErr("%pd revert failure(%d, %d)\n",
19898 + dentry, err, rerr);
19901 + au_dtime_revert(&a->dt);
19904 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
19905 + *arg->u.c.aopen->opened |= FILE_CREATED;
19907 + au_unpin(&a->pin);
19912 + di_write_unlock(parent);
19914 + if (unlikely(err)) {
19915 + au_update_dbtop(dentry);
19919 + aufs_read_unlock(dentry, AuLock_DW);
19926 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19929 + struct simple_arg arg = {
19936 + return add_simple(dir, dentry, &arg);
19939 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19941 + struct simple_arg arg = {
19943 + .u.s.symname = symname
19945 + return add_simple(dir, dentry, &arg);
19948 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19951 + struct simple_arg arg = {
19955 + .want_excl = want_excl
19958 + return add_simple(dir, dentry, &arg);
19961 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19962 + struct vfsub_aopen_args *aopen_args)
19964 + struct simple_arg arg = {
19967 + .mode = aopen_args->create_mode,
19968 + .want_excl = aopen_args->open_flag & O_EXCL,
19969 + .try_aopen = true,
19970 + .aopen = aopen_args
19973 + return add_simple(dir, dentry, &arg);
19976 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19979 + aufs_bindex_t bindex;
19980 + struct super_block *sb;
19981 + struct dentry *parent, *h_parent, *h_dentry;
19982 + struct inode *h_dir, *inode;
19983 + struct vfsmount *h_mnt;
19984 + struct au_wr_dir_args wr_dir_args = {
19985 + .force_btgt = -1,
19986 + .flags = AuWrDir_TMPFILE
19989 + /* copy-up may happen */
19993 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19994 + if (unlikely(err))
19997 + err = au_di_init(dentry);
19998 + if (unlikely(err))
20002 + parent = d_find_any_alias(dir);
20003 + AuDebugOn(!parent);
20004 + di_write_lock_parent(parent);
20005 + if (unlikely(d_inode(parent) != dir))
20008 + err = au_digen_test(parent, au_sigen(sb));
20009 + if (unlikely(err))
20012 + bindex = au_dbtop(parent);
20013 + au_set_dbtop(dentry, bindex);
20014 + au_set_dbbot(dentry, bindex);
20015 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20017 + if (unlikely(err < 0))
20020 + err = -EOPNOTSUPP;
20021 + h_dir = au_h_iptr(dir, bindex);
20022 + if (unlikely(!h_dir->i_op->tmpfile))
20025 + h_mnt = au_sbr_mnt(sb, bindex);
20026 + err = vfsub_mnt_want_write(h_mnt);
20027 + if (unlikely(err))
20030 + h_parent = au_h_dptr(parent, bindex);
20031 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20032 + if (IS_ERR(h_dentry)) {
20033 + err = PTR_ERR(h_dentry);
20037 + au_set_dbtop(dentry, bindex);
20038 + au_set_dbbot(dentry, bindex);
20039 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20040 + inode = au_new_inode(dentry, /*must_new*/1);
20041 + if (IS_ERR(inode)) {
20042 + err = PTR_ERR(inode);
20043 + au_set_h_dptr(dentry, bindex, NULL);
20044 + au_set_dbtop(dentry, -1);
20045 + au_set_dbbot(dentry, -1);
20047 + if (!inode->i_nlink)
20048 + set_nlink(inode, 1);
20049 + d_tmpfile(dentry, inode);
20050 + au_di(dentry)->di_tmpfile = 1;
20052 + /* update without i_mutex */
20053 + if (au_ibtop(dir) == au_dbtop(dentry))
20054 + au_cpup_attr_timesizes(dir);
20059 + vfsub_mnt_drop_write(h_mnt);
20061 + di_write_unlock(parent);
20063 + di_write_unlock(dentry);
20064 + if (unlikely(err)) {
20065 + au_di_fin(dentry);
20066 + dentry->d_fsdata = NULL;
20069 + si_read_unlock(sb);
20071 + inode_unlock(dir);
20075 +/* ---------------------------------------------------------------------- */
20077 +struct au_link_args {
20078 + aufs_bindex_t bdst, bsrc;
20079 + struct au_pin pin;
20080 + struct path h_path;
20081 + struct dentry *src_parent, *parent;
20084 +static int au_cpup_before_link(struct dentry *src_dentry,
20085 + struct au_link_args *a)
20088 + struct dentry *h_src_dentry;
20089 + struct au_cp_generic cpg = {
20090 + .dentry = src_dentry,
20095 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20098 + di_read_lock_parent(a->src_parent, AuLock_IR);
20099 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20100 + if (unlikely(err))
20103 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20104 + err = au_pin(&a->pin, src_dentry, a->bdst,
20105 + au_opt_udba(src_dentry->d_sb),
20106 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20107 + if (unlikely(err))
20110 + err = au_sio_cpup_simple(&cpg);
20111 + au_unpin(&a->pin);
20114 + di_read_unlock(a->src_parent, AuLock_IR);
20118 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20119 + struct au_link_args *a)
20122 + unsigned char plink;
20123 + aufs_bindex_t bbot;
20124 + struct dentry *h_src_dentry;
20125 + struct inode *h_inode, *inode, *delegated;
20126 + struct super_block *sb;
20127 + struct file *h_file;
20131 + sb = src_dentry->d_sb;
20132 + inode = d_inode(src_dentry);
20133 + if (au_ibtop(inode) <= a->bdst)
20134 + h_inode = au_h_iptr(inode, a->bdst);
20135 + if (!h_inode || !h_inode->i_nlink) {
20136 + /* copyup src_dentry as the name of dentry. */
20137 + bbot = au_dbbot(dentry);
20138 + if (bbot < a->bsrc)
20139 + au_set_dbbot(dentry, a->bsrc);
20140 + au_set_h_dptr(dentry, a->bsrc,
20141 + dget(au_h_dptr(src_dentry, a->bsrc)));
20142 + dget(a->h_path.dentry);
20143 + au_set_h_dptr(dentry, a->bdst, NULL);
20144 + AuDbg("temporary d_inode...\n");
20145 + spin_lock(&dentry->d_lock);
20146 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20147 + spin_unlock(&dentry->d_lock);
20148 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20149 + if (IS_ERR(h_file))
20150 + err = PTR_ERR(h_file);
20152 + struct au_cp_generic cpg = {
20153 + .dentry = dentry,
20158 + .flags = AuCpup_KEEPLINO
20160 + err = au_sio_cpup_simple(&cpg);
20161 + au_h_open_post(dentry, a->bsrc, h_file);
20163 + dput(a->h_path.dentry);
20164 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20166 + au_set_h_dptr(dentry, a->bdst,
20167 + a->h_path.dentry);
20169 + spin_lock(&dentry->d_lock);
20170 + dentry->d_inode = NULL; /* restore */
20171 + spin_unlock(&dentry->d_lock);
20172 + AuDbg("temporary d_inode...done\n");
20173 + au_set_h_dptr(dentry, a->bsrc, NULL);
20174 + au_set_dbbot(dentry, bbot);
20176 + /* the inode of src_dentry already exists on a.bdst branch */
20177 + h_src_dentry = d_find_alias(h_inode);
20178 + if (!h_src_dentry && au_plink_test(inode)) {
20180 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20181 + err = PTR_ERR(h_src_dentry);
20182 + if (IS_ERR(h_src_dentry))
20185 + if (unlikely(d_is_negative(h_src_dentry))) {
20186 + dput(h_src_dentry);
20187 + h_src_dentry = NULL;
20191 + if (h_src_dentry) {
20192 + delegated = NULL;
20193 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20194 + &a->h_path, &delegated);
20195 + if (unlikely(err == -EWOULDBLOCK)) {
20196 + pr_warn("cannot retry for NFSv4 delegation"
20197 + " for an internal link\n");
20200 + dput(h_src_dentry);
20202 + AuIOErr("no dentry found for hi%lu on b%d\n",
20203 + h_inode->i_ino, a->bdst);
20208 + if (!err && !plink)
20209 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20216 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20217 + struct dentry *dentry)
20220 + struct au_dtime dt;
20221 + struct au_link_args *a;
20222 + struct dentry *wh_dentry, *h_src_dentry;
20223 + struct inode *inode, *delegated;
20224 + struct super_block *sb;
20225 + struct au_wr_dir_args wr_dir_args = {
20226 + /* .force_btgt = -1, */
20227 + .flags = AuWrDir_ADD_ENTRY
20231 + inode = d_inode(src_dentry);
20232 + IMustLock(inode);
20235 + a = kzalloc(sizeof(*a), GFP_NOFS);
20236 + if (unlikely(!a))
20239 + a->parent = dentry->d_parent; /* dir inode is locked */
20240 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20241 + AuLock_NOPLM | AuLock_GEN);
20242 + if (unlikely(err))
20244 + err = au_d_linkable(src_dentry);
20245 + if (unlikely(err))
20247 + err = au_d_may_add(dentry);
20248 + if (unlikely(err))
20251 + a->src_parent = dget_parent(src_dentry);
20252 + wr_dir_args.force_btgt = au_ibtop(inode);
20254 + di_write_lock_parent(a->parent);
20255 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20256 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20258 + err = PTR_ERR(wh_dentry);
20259 + if (IS_ERR(wh_dentry))
20263 + sb = dentry->d_sb;
20264 + a->bdst = au_dbtop(dentry);
20265 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20266 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20267 + a->bsrc = au_ibtop(inode);
20268 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20269 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20270 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20271 + if (!h_src_dentry) {
20272 + a->bsrc = au_dbtop(src_dentry);
20273 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20274 + AuDebugOn(!h_src_dentry);
20275 + } else if (IS_ERR(h_src_dentry)) {
20276 + err = PTR_ERR(h_src_dentry);
20281 + * aufs doesn't touch the credential so
20282 + * security_dentry_create_files_as() is unnecrssary.
20284 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20285 + if (a->bdst < a->bsrc
20286 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20287 + err = au_cpup_or_link(src_dentry, dentry, a);
20289 + delegated = NULL;
20290 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20291 + &a->h_path, &delegated);
20292 + if (unlikely(err == -EWOULDBLOCK)) {
20293 + pr_warn("cannot retry for NFSv4 delegation"
20294 + " for an internal link\n");
20298 + dput(h_src_dentry);
20301 + * copyup src_dentry to the branch we process,
20302 + * and then link(2) to it.
20304 + dput(h_src_dentry);
20305 + if (a->bdst < a->bsrc
20306 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20307 + au_unpin(&a->pin);
20308 + di_write_unlock(a->parent);
20309 + err = au_cpup_before_link(src_dentry, a);
20310 + di_write_lock_parent(a->parent);
20312 + err = au_pin(&a->pin, dentry, a->bdst,
20314 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20315 + if (unlikely(err))
20319 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20321 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20322 + delegated = NULL;
20323 + err = vfsub_link(h_src_dentry,
20324 + au_pinned_h_dir(&a->pin),
20325 + &a->h_path, &delegated);
20326 + if (unlikely(err == -EWOULDBLOCK)) {
20327 + pr_warn("cannot retry"
20328 + " for NFSv4 delegation"
20329 + " for an internal link\n");
20335 + if (unlikely(err))
20339 + a->h_path.dentry = wh_dentry;
20340 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20342 + if (unlikely(err))
20346 + au_dir_ts(dir, a->bdst);
20347 + dir->i_version++;
20348 + inc_nlink(inode);
20349 + inode->i_ctime = dir->i_ctime;
20350 + d_instantiate(dentry, au_igrab(inode));
20351 + if (d_unhashed(a->h_path.dentry))
20352 + /* some filesystem calls d_drop() */
20354 + /* some filesystems consume an inode even hardlink */
20355 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20356 + goto out_unpin; /* success */
20359 + /* no delegation since it is just created */
20360 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20361 + /*delegated*/NULL, /*force*/0);
20362 + if (unlikely(rerr)) {
20363 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20366 + au_dtime_revert(&dt);
20368 + au_unpin(&a->pin);
20372 + di_write_unlock(a->parent);
20373 + dput(a->src_parent);
20375 + if (unlikely(err)) {
20376 + au_update_dbtop(dentry);
20379 + aufs_read_and_write_unlock2(dentry, src_dentry);
20387 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20390 + aufs_bindex_t bindex;
20391 + unsigned char diropq;
20392 + struct path h_path;
20393 + struct dentry *wh_dentry, *parent, *opq_dentry;
20394 + struct inode *h_inode;
20395 + struct super_block *sb;
20397 + struct au_pin pin;
20398 + struct au_dtime dt;
20399 + } *a; /* reduce the stack usage */
20400 + struct au_wr_dir_args wr_dir_args = {
20401 + .force_btgt = -1,
20402 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20408 + a = kmalloc(sizeof(*a), GFP_NOFS);
20409 + if (unlikely(!a))
20412 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20413 + if (unlikely(err))
20415 + err = au_d_may_add(dentry);
20416 + if (unlikely(err))
20419 + parent = dentry->d_parent; /* dir inode is locked */
20420 + di_write_lock_parent(parent);
20421 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20422 + &a->pin, &wr_dir_args);
20423 + err = PTR_ERR(wh_dentry);
20424 + if (IS_ERR(wh_dentry))
20427 + sb = dentry->d_sb;
20428 + bindex = au_dbtop(dentry);
20429 + h_path.dentry = au_h_dptr(dentry, bindex);
20430 + h_path.mnt = au_sbr_mnt(sb, bindex);
20431 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20432 + if (unlikely(err))
20435 + /* make the dir opaque */
20437 + h_inode = d_inode(h_path.dentry);
20439 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20440 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20441 + opq_dentry = au_diropq_create(dentry, bindex);
20442 + inode_unlock(h_inode);
20443 + err = PTR_ERR(opq_dentry);
20444 + if (IS_ERR(opq_dentry))
20446 + dput(opq_dentry);
20450 + err = epilog(dir, bindex, wh_dentry, dentry);
20453 + goto out_unpin; /* success */
20458 + AuLabel(revert opq);
20459 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20460 + rerr = au_diropq_remove(dentry, bindex);
20461 + inode_unlock(h_inode);
20463 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20464 + dentry, err, rerr);
20470 + AuLabel(revert dir);
20471 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20473 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20474 + dentry, err, rerr);
20477 + au_dtime_revert(&a->dt);
20479 + au_unpin(&a->pin);
20482 + di_write_unlock(parent);
20484 + if (unlikely(err)) {
20485 + au_update_dbtop(dentry);
20488 + aufs_read_unlock(dentry, AuLock_DW);
20494 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20495 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20496 +++ linux/fs/aufs/i_op.c 2017-11-12 22:24:44.707577830 +0100
20499 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20501 + * This program, aufs is free software; you can redistribute it and/or modify
20502 + * it under the terms of the GNU General Public License as published by
20503 + * the Free Software Foundation; either version 2 of the License, or
20504 + * (at your option) any later version.
20506 + * This program is distributed in the hope that it will be useful,
20507 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20508 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20509 + * GNU General Public License for more details.
20511 + * You should have received a copy of the GNU General Public License
20512 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20516 + * inode operations (except add/del/rename)
20519 +#include <linux/device_cgroup.h>
20520 +#include <linux/fs_stack.h>
20521 +#include <linux/namei.h>
20522 +#include <linux/security.h>
20525 +static int h_permission(struct inode *h_inode, int mask,
20526 + struct path *h_path, int brperm)
20529 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20532 + if (write_mask && IS_IMMUTABLE(h_inode))
20536 + if (((mask & MAY_EXEC)
20537 + && S_ISREG(h_inode->i_mode)
20538 + && (path_noexec(h_path)
20539 + || !(h_inode->i_mode & S_IXUGO))))
20543 + * - skip the lower fs test in the case of write to ro branch.
20544 + * - nfs dir permission write check is optimized, but a policy for
20545 + * link/rename requires a real check.
20546 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
20547 + * in this case, generic_permission() returns -EOPNOTSUPP.
20549 + if ((write_mask && !au_br_writable(brperm))
20550 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20551 + && write_mask && !(mask & MAY_READ))
20552 + || !h_inode->i_op->permission) {
20553 + /* AuLabel(generic_permission); */
20554 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
20555 + err = generic_permission(h_inode, mask);
20556 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20557 + err = h_inode->i_op->permission(h_inode, mask);
20560 + /* AuLabel(h_inode->permission); */
20561 + err = h_inode->i_op->permission(h_inode, mask);
20566 + err = devcgroup_inode_permission(h_inode, mask);
20568 + err = security_inode_permission(h_inode, mask);
20572 + /* todo: do we need to call ima_path_check()? */
20573 + struct path h_path = {
20577 + err = ima_path_check(&h_path,
20578 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20579 + IMA_COUNT_LEAVE);
20587 +static int aufs_permission(struct inode *inode, int mask)
20590 + aufs_bindex_t bindex, bbot;
20591 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20592 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20593 + struct inode *h_inode;
20594 + struct super_block *sb;
20595 + struct au_branch *br;
20597 + /* todo: support rcu-walk? */
20598 + if (mask & MAY_NOT_BLOCK)
20601 + sb = inode->i_sb;
20602 + si_read_lock(sb, AuLock_FLUSH);
20603 + ii_read_lock_child(inode);
20605 + err = au_iigen_test(inode, au_sigen(sb));
20606 + if (unlikely(err))
20612 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20613 + err = au_busy_or_stale();
20614 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20615 + if (unlikely(!h_inode
20616 + || (h_inode->i_mode & S_IFMT)
20617 + != (inode->i_mode & S_IFMT)))
20621 + bindex = au_ibtop(inode);
20622 + br = au_sbr(sb, bindex);
20623 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20626 + && !special_file(h_inode->i_mode)) {
20627 + /* test whether the upper writable branch exists */
20629 + for (; bindex >= 0; bindex--)
20630 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20638 + /* non-write to dir */
20640 + bbot = au_ibbot(inode);
20641 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20642 + h_inode = au_h_iptr(inode, bindex);
20644 + err = au_busy_or_stale();
20645 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20648 + br = au_sbr(sb, bindex);
20649 + err = h_permission(h_inode, mask, &br->br_path,
20655 + ii_read_unlock(inode);
20656 + si_read_unlock(sb);
20660 +/* ---------------------------------------------------------------------- */
20662 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20663 + unsigned int flags)
20665 + struct dentry *ret, *parent;
20666 + struct inode *inode;
20667 + struct super_block *sb;
20668 + int err, npositive;
20672 + /* todo: support rcu-walk? */
20673 + ret = ERR_PTR(-ECHILD);
20674 + if (flags & LOOKUP_RCU)
20677 + ret = ERR_PTR(-ENAMETOOLONG);
20678 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20682 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20683 + ret = ERR_PTR(err);
20684 + if (unlikely(err))
20687 + err = au_di_init(dentry);
20688 + ret = ERR_PTR(err);
20689 + if (unlikely(err))
20693 + npositive = 0; /* suppress a warning */
20694 + parent = dentry->d_parent; /* dir inode is locked */
20695 + di_read_lock_parent(parent, AuLock_IR);
20696 + err = au_alive_dir(parent);
20698 + err = au_digen_test(parent, au_sigen(sb));
20700 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20701 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20702 + AuLkup_ALLOW_NEG);
20705 + di_read_unlock(parent, AuLock_IR);
20706 + ret = ERR_PTR(err);
20707 + if (unlikely(err < 0))
20711 + inode = au_new_inode(dentry, /*must_new*/0);
20712 + if (IS_ERR(inode)) {
20713 + ret = (void *)inode;
20720 + atomic_inc(&inode->i_count);
20721 + ret = d_splice_alias(inode, dentry);
20723 + if (unlikely(d_need_lookup(dentry))) {
20724 + spin_lock(&dentry->d_lock);
20725 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20726 + spin_unlock(&dentry->d_lock);
20730 + if (!IS_ERR(ret)) {
20732 + if (ret && ret != dentry)
20733 + ii_write_unlock(inode);
20735 + ii_write_unlock(inode);
20742 + di_write_unlock(dentry);
20744 + si_read_unlock(sb);
20749 +/* ---------------------------------------------------------------------- */
20751 +struct aopen_node {
20752 + struct hlist_bl_node hblist;
20753 + struct file *file, *h_file;
20756 +static int au_do_aopen(struct inode *inode, struct file *file)
20758 + struct hlist_bl_head *aopen;
20759 + struct hlist_bl_node *pos;
20760 + struct aopen_node *node;
20761 + struct au_do_open_args args = {
20763 + .open = au_do_open_nondir
20766 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20767 + hlist_bl_lock(aopen);
20768 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20769 + if (node->file == file) {
20770 + args.h_file = node->h_file;
20773 + hlist_bl_unlock(aopen);
20774 + /* AuDebugOn(!args.h_file); */
20776 + return au_do_open(file, &args);
20779 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20780 + struct file *file, unsigned int open_flag,
20781 + umode_t create_mode, int *opened)
20783 + int err, unlocked, h_opened = *opened;
20784 + unsigned int lkup_flags;
20785 + struct dentry *parent, *d;
20786 + struct hlist_bl_head *aopen;
20787 + struct vfsub_aopen_args args = {
20788 + .open_flag = open_flag,
20789 + .create_mode = create_mode,
20790 + .opened = &h_opened
20792 + struct aopen_node aopen_node = {
20797 + AuDbg("open_flag 0%o\n", open_flag);
20798 + AuDbgDentry(dentry);
20801 + if (!au_di(dentry)) {
20802 + lkup_flags = LOOKUP_OPEN;
20803 + if (open_flag & O_CREAT)
20804 + lkup_flags |= LOOKUP_CREATE;
20805 + d = aufs_lookup(dir, dentry, lkup_flags);
20807 + err = PTR_ERR(d);
20812 + * obsoleted dentry found.
20813 + * another error will be returned later.
20819 + AuDbgDentry(dentry);
20822 + if (d_is_positive(dentry)
20823 + || d_unhashed(dentry)
20824 + || d_unlinked(dentry)
20825 + || !(open_flag & O_CREAT))
20826 + goto out_no_open;
20829 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20830 + if (unlikely(err))
20833 + parent = dentry->d_parent; /* dir is locked */
20834 + di_write_lock_parent(parent);
20835 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20836 + if (unlikely(err))
20839 + AuDbgDentry(dentry);
20840 + if (d_is_positive(dentry))
20843 + args.file = get_empty_filp();
20844 + err = PTR_ERR(args.file);
20845 + if (IS_ERR(args.file))
20848 + args.file->f_flags = file->f_flags;
20849 + err = au_aopen_or_create(dir, dentry, &args);
20851 + AuDbgFile(args.file);
20852 + if (unlikely(err < 0)) {
20853 + if (h_opened & FILE_OPENED)
20856 + put_filp(args.file);
20859 + di_write_unlock(parent);
20860 + di_write_unlock(dentry);
20863 + /* some filesystems don't set FILE_CREATED while succeeded? */
20864 + *opened |= FILE_CREATED;
20865 + if (h_opened & FILE_OPENED)
20866 + aopen_node.h_file = args.file;
20868 + put_filp(args.file);
20869 + args.file = NULL;
20871 + aopen = &au_sbi(dir->i_sb)->si_aopen;
20872 + au_hbl_add(&aopen_node.hblist, aopen);
20873 + err = finish_open(file, dentry, au_do_aopen, opened);
20874 + au_hbl_del(&aopen_node.hblist, aopen);
20877 + if (aopen_node.h_file)
20878 + fput(aopen_node.h_file);
20882 + si_read_unlock(dentry->d_sb);
20884 + di_write_unlock(parent);
20885 + aufs_read_unlock(dentry, AuLock_DW);
20887 + AuDbgDentry(dentry);
20888 + if (unlikely(err < 0))
20891 + if (err >= 0 && !(*opened & FILE_CREATED)) {
20892 + AuLabel(out_no_open);
20894 + err = finish_no_open(file, dentry);
20897 + AuDbg("%pd%s%s\n", dentry,
20898 + (*opened & FILE_CREATED) ? " created" : "",
20899 + (*opened & FILE_OPENED) ? " opened" : "");
20905 +/* ---------------------------------------------------------------------- */
20907 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20908 + const unsigned char add_entry, aufs_bindex_t bcpup,
20909 + aufs_bindex_t btop)
20912 + struct dentry *h_parent;
20913 + struct inode *h_dir;
20916 + IMustLock(d_inode(parent));
20918 + di_write_lock_parent(parent);
20921 + if (!au_h_dptr(parent, bcpup)) {
20922 + if (btop > bcpup)
20923 + err = au_cpup_dirs(dentry, bcpup);
20924 + else if (btop < bcpup)
20925 + err = au_cpdown_dirs(dentry, bcpup);
20929 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20930 + h_parent = au_h_dptr(parent, bcpup);
20931 + h_dir = d_inode(h_parent);
20932 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20933 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20934 + /* todo: no unlock here */
20935 + inode_unlock_shared(h_dir);
20937 + AuDbg("bcpup %d\n", bcpup);
20939 + if (d_really_is_negative(dentry))
20940 + au_set_h_dptr(dentry, btop, NULL);
20941 + au_update_dbrange(dentry, /*do_put_zero*/0);
20946 + di_write_unlock(parent);
20948 + err = bcpup; /* success */
20955 + * decide the branch and the parent dir where we will create a new entry.
20956 + * returns new bindex or an error.
20957 + * copyup the parent dir if needed.
20959 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20960 + struct au_wr_dir_args *args)
20963 + unsigned int flags;
20964 + aufs_bindex_t bcpup, btop, src_btop;
20965 + const unsigned char add_entry
20966 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20967 + | au_ftest_wrdir(args->flags, TMPFILE);
20968 + struct super_block *sb;
20969 + struct dentry *parent;
20970 + struct au_sbinfo *sbinfo;
20972 + sb = dentry->d_sb;
20973 + sbinfo = au_sbi(sb);
20974 + parent = dget_parent(dentry);
20975 + btop = au_dbtop(dentry);
20977 + if (args->force_btgt < 0) {
20978 + if (src_dentry) {
20979 + src_btop = au_dbtop(src_dentry);
20980 + if (src_btop < btop)
20981 + bcpup = src_btop;
20982 + } else if (add_entry) {
20984 + if (au_ftest_wrdir(args->flags, ISDIR))
20985 + au_fset_wbr(flags, DIR);
20986 + err = AuWbrCreate(sbinfo, dentry, flags);
20990 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20992 + err = AuWbrCopyup(sbinfo, dentry);
20994 + if (!IS_ROOT(dentry)) {
20995 + di_read_lock_parent(parent, !AuLock_IR);
20996 + err = AuWbrCopyup(sbinfo, dentry);
20997 + di_read_unlock(parent, !AuLock_IR);
20999 + err = AuWbrCopyup(sbinfo, dentry);
21002 + if (unlikely(err < 0))
21006 + bcpup = args->force_btgt;
21007 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21010 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21012 + if (bcpup == btop)
21013 + goto out; /* success */
21015 + /* copyup the new parent into the branch we process */
21016 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21018 + if (d_really_is_negative(dentry)) {
21019 + au_set_h_dptr(dentry, btop, NULL);
21020 + au_set_dbtop(dentry, bcpup);
21021 + au_set_dbbot(dentry, bcpup);
21023 + AuDebugOn(add_entry
21024 + && !au_ftest_wrdir(args->flags, TMPFILE)
21025 + && !au_h_dptr(dentry, bcpup));
21033 +/* ---------------------------------------------------------------------- */
21035 +void au_pin_hdir_unlock(struct au_pin *p)
21038 + au_hn_inode_unlock(p->hdir);
21041 +int au_pin_hdir_lock(struct au_pin *p)
21049 + /* even if an error happens later, keep this lock */
21050 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21053 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21058 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21059 + p->h_parent, p->br);
21065 +int au_pin_hdir_relock(struct au_pin *p)
21068 + struct inode *h_i;
21069 + struct dentry *h_d[] = {
21074 + err = au_pin_hdir_lock(p);
21075 + if (unlikely(err))
21078 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21081 + if (d_is_positive(h_d[i])) {
21082 + h_i = d_inode(h_d[i]);
21083 + err = !h_i->i_nlink;
21091 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21093 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21094 + p->hdir->hi_inode->i_rwsem.owner = task;
21098 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21101 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21102 + p->lsc_hi, 0, NULL, _RET_IP_);
21103 + au_pin_hdir_set_owner(p, current);
21107 +void au_pin_hdir_release(struct au_pin *p)
21110 + au_pin_hdir_set_owner(p, p->task);
21111 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21115 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21117 + if (pin && pin->parent)
21118 + return au_h_dptr(pin->parent, pin->bindex);
21122 +void au_unpin(struct au_pin *p)
21125 + au_pin_hdir_unlock(p);
21126 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21127 + vfsub_mnt_drop_write(p->h_mnt);
21131 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21132 + di_read_unlock(p->parent, AuLock_IR);
21133 + iput(p->hdir->hi_inode);
21135 + p->parent = NULL;
21138 + /* do not clear p->task */
21141 +int au_do_pin(struct au_pin *p)
21144 + struct super_block *sb;
21145 + struct inode *h_dir;
21148 + sb = p->dentry->d_sb;
21149 + p->br = au_sbr(sb, p->bindex);
21150 + if (IS_ROOT(p->dentry)) {
21151 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21152 + p->h_mnt = au_br_mnt(p->br);
21153 + err = vfsub_mnt_want_write(p->h_mnt);
21154 + if (unlikely(err)) {
21155 + au_fclr_pin(p->flags, MNT_WRITE);
21162 + p->h_dentry = NULL;
21163 + if (p->bindex <= au_dbbot(p->dentry))
21164 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21166 + p->parent = dget_parent(p->dentry);
21167 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21168 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21171 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21172 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21174 + h_dir = p->hdir->hi_inode;
21178 + * if DI_LOCKED is not set, then p->parent may be different
21179 + * and h_parent can be NULL.
21181 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21183 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21184 + di_read_unlock(p->parent, AuLock_IR);
21186 + p->parent = NULL;
21190 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21191 + p->h_mnt = au_br_mnt(p->br);
21192 + err = vfsub_mnt_want_write(p->h_mnt);
21193 + if (unlikely(err)) {
21194 + au_fclr_pin(p->flags, MNT_WRITE);
21195 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21196 + di_read_unlock(p->parent, AuLock_IR);
21198 + p->parent = NULL;
21204 + err = au_pin_hdir_lock(p);
21206 + goto out; /* success */
21211 + pr_err("err %d\n", err);
21212 + err = au_busy_or_stale();
21217 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21218 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21219 + unsigned int udba, unsigned char flags)
21221 + p->dentry = dentry;
21223 + p->lsc_di = lsc_di;
21224 + p->lsc_hi = lsc_hi;
21225 + p->flags = flags;
21226 + p->bindex = bindex;
21228 + p->parent = NULL;
21232 + p->h_dentry = NULL;
21233 + p->h_parent = NULL;
21235 + p->task = current;
21238 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21239 + unsigned int udba, unsigned char flags)
21241 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21243 + return au_do_pin(pin);
21246 +/* ---------------------------------------------------------------------- */
21249 + * ->setattr() and ->getattr() are called in various cases.
21250 + * chmod, stat: dentry is revalidated.
21251 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21253 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21255 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21256 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21259 + struct dentry *parent;
21262 + if (au_digen_test(dentry, sigen)) {
21263 + parent = dget_parent(dentry);
21264 + di_read_lock_parent(parent, AuLock_IR);
21265 + err = au_refresh_dentry(dentry, parent);
21266 + di_read_unlock(parent, AuLock_IR);
21274 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21275 + struct au_icpup_args *a)
21279 + aufs_bindex_t btop, ibtop;
21280 + struct dentry *hi_wh, *parent;
21281 + struct inode *inode;
21282 + struct au_wr_dir_args wr_dir_args = {
21283 + .force_btgt = -1,
21287 + if (d_is_dir(dentry))
21288 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21289 + /* plink or hi_wh() case */
21290 + btop = au_dbtop(dentry);
21291 + inode = d_inode(dentry);
21292 + ibtop = au_ibtop(inode);
21293 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21294 + wr_dir_args.force_btgt = ibtop;
21295 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21296 + if (unlikely(err < 0))
21300 + au_fset_icpup(a->flags, DID_CPUP);
21303 + a->pin_flags = AuPin_MNT_WRITE;
21305 + if (!IS_ROOT(dentry)) {
21306 + au_fset_pin(a->pin_flags, DI_LOCKED);
21307 + parent = dget_parent(dentry);
21308 + di_write_lock_parent(parent);
21311 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21312 + if (unlikely(err))
21316 + a->h_path.dentry = au_h_dptr(dentry, btop);
21317 + a->h_inode = d_inode(a->h_path.dentry);
21318 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21319 + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21320 + if (ia->ia_size < i_size_read(a->h_inode))
21321 + sz = ia->ia_size;
21322 + inode_unlock_shared(a->h_inode);
21326 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21327 + hi_wh = au_hi_wh(inode, a->btgt);
21329 + struct au_cp_generic cpg = {
21330 + .dentry = dentry,
21336 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21337 + if (unlikely(err))
21339 + hi_wh = au_hi_wh(inode, a->btgt);
21340 + /* todo: revalidate hi_wh? */
21345 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21346 + di_downgrade_lock(parent, AuLock_IR);
21350 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21351 + goto out; /* success */
21353 + if (!d_unhashed(dentry)) {
21354 + struct au_cp_generic cpg = {
21355 + .dentry = dentry,
21360 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21362 + err = au_sio_cpup_simple(&cpg);
21364 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21365 + } else if (!hi_wh)
21366 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21368 + a->h_path.dentry = hi_wh; /* do not dget here */
21371 + a->h_inode = d_inode(a->h_path.dentry);
21373 + goto out; /* success */
21374 + au_unpin(&a->pin);
21377 + di_write_unlock(parent);
21382 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21386 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21389 + struct inode *inode, *delegated;
21390 + struct super_block *sb;
21391 + struct file *file;
21392 + struct au_icpup_args *a;
21394 + inode = d_inode(dentry);
21395 + IMustLock(inode);
21397 + err = setattr_prepare(dentry, ia);
21398 + if (unlikely(err))
21402 + a = kzalloc(sizeof(*a), GFP_NOFS);
21403 + if (unlikely(!a))
21406 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21407 + ia->ia_valid &= ~ATTR_MODE;
21410 + sb = dentry->d_sb;
21411 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21412 + if (unlikely(err))
21415 + if (ia->ia_valid & ATTR_FILE) {
21416 + /* currently ftruncate(2) only */
21417 + AuDebugOn(!d_is_reg(dentry));
21418 + file = ia->ia_file;
21419 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21421 + if (unlikely(err))
21423 + ia->ia_file = au_hf_top(file);
21424 + a->udba = AuOpt_UDBA_NONE;
21426 + /* fchmod() doesn't pass ia_file */
21427 + a->udba = au_opt_udba(sb);
21428 + di_write_lock_child(dentry);
21429 + /* no d_unlinked(), to set UDBA_NONE for root */
21430 + if (d_unhashed(dentry))
21431 + a->udba = AuOpt_UDBA_NONE;
21432 + if (a->udba != AuOpt_UDBA_NONE) {
21433 + AuDebugOn(IS_ROOT(dentry));
21434 + err = au_reval_for_attr(dentry, au_sigen(sb));
21435 + if (unlikely(err))
21440 + err = au_pin_and_icpup(dentry, ia, a);
21441 + if (unlikely(err < 0))
21443 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21444 + ia->ia_file = NULL;
21445 + ia->ia_valid &= ~ATTR_FILE;
21448 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21449 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21450 + == (ATTR_MODE | ATTR_CTIME)) {
21451 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21452 + if (unlikely(err))
21454 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21455 + && (ia->ia_valid & ATTR_CTIME)) {
21456 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21457 + if (unlikely(err))
21461 + if (ia->ia_valid & ATTR_SIZE) {
21464 + if (ia->ia_size < i_size_read(inode))
21466 + truncate_setsize(inode, ia->ia_size);
21469 + if (ia->ia_valid & ATTR_FILE)
21471 + inode_unlock(a->h_inode);
21472 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21473 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21475 + delegated = NULL;
21477 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21479 + err = break_deleg_wait(&delegated);
21487 + * regardless aufs 'acl' option setting.
21488 + * why don't all acl-aware fs call this func from their ->setattr()?
21490 + if (!err && (ia->ia_valid & ATTR_MODE))
21491 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21493 + au_cpup_attr_changeable(inode);
21496 + inode_unlock(a->h_inode);
21497 + au_unpin(&a->pin);
21498 + if (unlikely(err))
21499 + au_update_dbtop(dentry);
21501 + di_write_unlock(dentry);
21503 + fi_write_unlock(file);
21504 + ia->ia_file = file;
21505 + ia->ia_valid |= ATTR_FILE;
21508 + si_read_unlock(sb);
21516 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21517 +static int au_h_path_to_set_attr(struct dentry *dentry,
21518 + struct au_icpup_args *a, struct path *h_path)
21521 + struct super_block *sb;
21523 + sb = dentry->d_sb;
21524 + a->udba = au_opt_udba(sb);
21525 + /* no d_unlinked(), to set UDBA_NONE for root */
21526 + if (d_unhashed(dentry))
21527 + a->udba = AuOpt_UDBA_NONE;
21528 + if (a->udba != AuOpt_UDBA_NONE) {
21529 + AuDebugOn(IS_ROOT(dentry));
21530 + err = au_reval_for_attr(dentry, au_sigen(sb));
21531 + if (unlikely(err))
21534 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21535 + if (unlikely(err < 0))
21538 + h_path->dentry = a->h_path.dentry;
21539 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21545 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21546 + struct au_sxattr *arg)
21549 + struct path h_path;
21550 + struct super_block *sb;
21551 + struct au_icpup_args *a;
21552 + struct inode *h_inode;
21554 + IMustLock(inode);
21557 + a = kzalloc(sizeof(*a), GFP_NOFS);
21558 + if (unlikely(!a))
21561 + sb = dentry->d_sb;
21562 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21563 + if (unlikely(err))
21566 + h_path.dentry = NULL; /* silence gcc */
21567 + di_write_lock_child(dentry);
21568 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21569 + if (unlikely(err))
21572 + inode_unlock(a->h_inode);
21573 + switch (arg->type) {
21574 + case AU_XATTR_SET:
21575 + AuDebugOn(d_is_negative(h_path.dentry));
21576 + err = vfsub_setxattr(h_path.dentry,
21577 + arg->u.set.name, arg->u.set.value,
21578 + arg->u.set.size, arg->u.set.flags);
21581 + err = -EOPNOTSUPP;
21582 + h_inode = d_inode(h_path.dentry);
21583 + if (h_inode->i_op->set_acl)
21584 + /* this will call posix_acl_update_mode */
21585 + err = h_inode->i_op->set_acl(h_inode,
21586 + arg->u.acl_set.acl,
21587 + arg->u.acl_set.type);
21591 + au_cpup_attr_timesizes(inode);
21593 + au_unpin(&a->pin);
21594 + if (unlikely(err))
21595 + au_update_dbtop(dentry);
21598 + di_write_unlock(dentry);
21599 + si_read_unlock(sb);
21608 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21609 + unsigned int nlink)
21613 + inode->i_mode = st->mode;
21614 + /* don't i_[ug]id_write() here */
21615 + inode->i_uid = st->uid;
21616 + inode->i_gid = st->gid;
21617 + inode->i_atime = st->atime;
21618 + inode->i_mtime = st->mtime;
21619 + inode->i_ctime = st->ctime;
21621 + au_cpup_attr_nlink(inode, /*force*/0);
21622 + if (S_ISDIR(inode->i_mode)) {
21623 + n = inode->i_nlink;
21626 + smp_mb(); /* for i_nlink */
21627 + /* 0 can happen */
21628 + set_nlink(inode, n);
21631 + spin_lock(&inode->i_lock);
21632 + inode->i_blocks = st->blocks;
21633 + i_size_write(inode, st->size);
21634 + spin_unlock(&inode->i_lock);
21638 + * common routine for aufs_getattr() and au_getxattr().
21639 + * returns zero or negative (an error).
21640 + * @dentry will be read-locked in success.
21642 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21646 + unsigned int mnt_flags, sigen;
21647 + unsigned char udba_none;
21648 + aufs_bindex_t bindex;
21649 + struct super_block *sb, *h_sb;
21650 + struct inode *inode;
21652 + h_path->mnt = NULL;
21653 + h_path->dentry = NULL;
21656 + sb = dentry->d_sb;
21657 + mnt_flags = au_mntflags(sb);
21658 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21660 + if (unlikely(locked))
21661 + goto body; /* skip locking dinfo */
21663 + /* support fstat(2) */
21664 + if (!d_unlinked(dentry) && !udba_none) {
21665 + sigen = au_sigen(sb);
21666 + err = au_digen_test(dentry, sigen);
21668 + di_read_lock_child(dentry, AuLock_IR);
21669 + err = au_dbrange_test(dentry);
21670 + if (unlikely(err)) {
21671 + di_read_unlock(dentry, AuLock_IR);
21675 + AuDebugOn(IS_ROOT(dentry));
21676 + di_write_lock_child(dentry);
21677 + err = au_dbrange_test(dentry);
21679 + err = au_reval_for_attr(dentry, sigen);
21681 + di_downgrade_lock(dentry, AuLock_IR);
21683 + di_write_unlock(dentry);
21688 + di_read_lock_child(dentry, AuLock_IR);
21691 + inode = d_inode(dentry);
21692 + bindex = au_ibtop(inode);
21693 + h_path->mnt = au_sbr_mnt(sb, bindex);
21694 + h_sb = h_path->mnt->mnt_sb;
21696 + && !au_test_fs_bad_iattr(h_sb)
21698 + goto out; /* success */
21700 + if (au_dbtop(dentry) == bindex)
21701 + h_path->dentry = au_h_dptr(dentry, bindex);
21702 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21703 + h_path->dentry = au_plink_lkup(inode, bindex);
21704 + if (IS_ERR(h_path->dentry))
21705 + /* pretending success */
21706 + h_path->dentry = NULL;
21708 + dput(h_path->dentry);
21715 +static int aufs_getattr(const struct path *path, struct kstat *st,
21716 + u32 request, unsigned int query)
21719 + unsigned char positive;
21720 + struct path h_path;
21721 + struct dentry *dentry;
21722 + struct inode *inode;
21723 + struct super_block *sb;
21725 + dentry = path->dentry;
21726 + inode = d_inode(dentry);
21727 + sb = dentry->d_sb;
21728 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21729 + if (unlikely(err))
21731 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21732 + if (unlikely(err))
21734 + if (unlikely(!h_path.dentry))
21735 + /* illegally overlapped or something */
21736 + goto out_fill; /* pretending success */
21738 + positive = d_is_positive(h_path.dentry);
21740 + /* no vfsub version */
21741 + err = vfs_getattr(&h_path, st, request, query);
21744 + au_refresh_iattr(inode, st,
21745 + d_inode(h_path.dentry)->i_nlink);
21746 + goto out_fill; /* success */
21752 + generic_fillattr(inode, st);
21754 + di_read_unlock(dentry, AuLock_IR);
21756 + si_read_unlock(sb);
21762 +/* ---------------------------------------------------------------------- */
21764 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21765 + struct delayed_call *done)
21768 + struct dentry *h_dentry;
21769 + struct inode *h_inode;
21771 + aufs_bindex_t bindex;
21773 + ret = NULL; /* suppress a warning */
21778 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21779 + if (unlikely(err))
21782 + err = au_d_hashed_positive(dentry);
21783 + if (unlikely(err))
21787 + inode = d_inode(dentry);
21788 + bindex = au_ibtop(inode);
21789 + h_inode = au_h_iptr(inode, bindex);
21790 + if (unlikely(!h_inode->i_op->get_link))
21795 + if (au_dbtop(dentry) <= bindex) {
21796 + h_dentry = au_h_dptr(dentry, bindex);
21801 + h_dentry = d_find_any_alias(h_inode);
21802 + if (IS_ERR(h_dentry)) {
21803 + err = PTR_ERR(h_dentry);
21807 + if (unlikely(!h_dentry))
21811 + AuDbg("%pf\n", h_inode->i_op->get_link);
21812 + AuDbgDentry(h_dentry);
21813 + ret = vfs_get_link(h_dentry, done);
21816 + err = PTR_ERR(ret);
21819 + aufs_read_unlock(dentry, AuLock_IR);
21821 + if (unlikely(err))
21822 + ret = ERR_PTR(err);
21823 + AuTraceErrPtr(ret);
21827 +/* ---------------------------------------------------------------------- */
21829 +static int au_is_special(struct inode *inode)
21831 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21834 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
21837 + aufs_bindex_t bindex;
21838 + struct super_block *sb;
21839 + struct inode *h_inode;
21840 + struct vfsmount *h_mnt;
21842 + sb = inode->i_sb;
21843 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21844 + "unexpected s_flags 0x%lx", sb->s_flags);
21846 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21848 + si_read_lock(sb, AuLock_FLUSH);
21849 + ii_write_lock_child(inode);
21852 + bindex = au_ibtop(inode);
21853 + h_inode = au_h_iptr(inode, bindex);
21854 + if (!au_test_ro(sb, bindex, inode)) {
21855 + h_mnt = au_sbr_mnt(sb, bindex);
21856 + err = vfsub_mnt_want_write(h_mnt);
21858 + err = vfsub_update_time(h_inode, ts, flags);
21859 + vfsub_mnt_drop_write(h_mnt);
21861 + } else if (au_is_special(h_inode)) {
21863 + * Never copy-up here.
21864 + * These special files may already be opened and used for
21865 + * communicating. If we copied it up, then the communication
21866 + * would be corrupted.
21868 + AuWarn1("timestamps for i%lu are ignored "
21869 + "since it is on readonly branch (hi%lu).\n",
21870 + inode->i_ino, h_inode->i_ino);
21871 + } else if (flags & ~S_ATIME) {
21873 + AuIOErr1("unexpected flags 0x%x\n", flags);
21878 + au_cpup_attr_timesizes(inode);
21879 + ii_write_unlock(inode);
21880 + si_read_unlock(sb);
21883 + if (!err && (flags & S_VERSION))
21884 + inode_inc_iversion(inode);
21889 +/* ---------------------------------------------------------------------- */
21891 +/* no getattr version will be set by module.c:aufs_init() */
21892 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21894 + [AuIop_SYMLINK] = {
21895 + .permission = aufs_permission,
21896 +#ifdef CONFIG_FS_POSIX_ACL
21897 + .get_acl = aufs_get_acl,
21898 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21901 + .setattr = aufs_setattr,
21902 + .getattr = aufs_getattr,
21904 +#ifdef CONFIG_AUFS_XATTR
21905 + .listxattr = aufs_listxattr,
21908 + .get_link = aufs_get_link,
21910 + /* .update_time = aufs_update_time */
21913 + .create = aufs_create,
21914 + .lookup = aufs_lookup,
21915 + .link = aufs_link,
21916 + .unlink = aufs_unlink,
21917 + .symlink = aufs_symlink,
21918 + .mkdir = aufs_mkdir,
21919 + .rmdir = aufs_rmdir,
21920 + .mknod = aufs_mknod,
21921 + .rename = aufs_rename,
21923 + .permission = aufs_permission,
21924 +#ifdef CONFIG_FS_POSIX_ACL
21925 + .get_acl = aufs_get_acl,
21926 + .set_acl = aufs_set_acl,
21929 + .setattr = aufs_setattr,
21930 + .getattr = aufs_getattr,
21932 +#ifdef CONFIG_AUFS_XATTR
21933 + .listxattr = aufs_listxattr,
21936 + .update_time = aufs_update_time,
21937 + .atomic_open = aufs_atomic_open,
21938 + .tmpfile = aufs_tmpfile
21940 + [AuIop_OTHER] = {
21941 + .permission = aufs_permission,
21942 +#ifdef CONFIG_FS_POSIX_ACL
21943 + .get_acl = aufs_get_acl,
21944 + .set_acl = aufs_set_acl,
21947 + .setattr = aufs_setattr,
21948 + .getattr = aufs_getattr,
21950 +#ifdef CONFIG_AUFS_XATTR
21951 + .listxattr = aufs_listxattr,
21954 + .update_time = aufs_update_time
21957 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21958 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21959 +++ linux/fs/aufs/i_op_del.c 2017-11-12 22:24:42.270843503 +0100
21962 + * Copyright (C) 2005-2017 Junjiro R. Okajima
21964 + * This program, aufs is free software; you can redistribute it and/or modify
21965 + * it under the terms of the GNU General Public License as published by
21966 + * the Free Software Foundation; either version 2 of the License, or
21967 + * (at your option) any later version.
21969 + * This program is distributed in the hope that it will be useful,
21970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21972 + * GNU General Public License for more details.
21974 + * You should have received a copy of the GNU General Public License
21975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21979 + * inode operations (del entry)
21985 + * decide if a new whiteout for @dentry is necessary or not.
21986 + * when it is necessary, prepare the parent dir for the upper branch whose
21987 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21988 + * be done by caller.
21990 + * 0: wh is unnecessary
21991 + * plus: wh is necessary
21994 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21996 + int need_wh, err;
21997 + aufs_bindex_t btop;
21998 + struct super_block *sb;
22000 + sb = dentry->d_sb;
22001 + btop = au_dbtop(dentry);
22002 + if (*bcpup < 0) {
22004 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22005 + err = AuWbrCopyup(au_sbi(sb), dentry);
22007 + if (unlikely(err < 0))
22011 + AuDebugOn(btop < *bcpup
22012 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22013 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22015 + if (*bcpup != btop) {
22016 + err = au_cpup_dirs(dentry, *bcpup);
22017 + if (unlikely(err))
22021 + struct au_dinfo *dinfo, *tmp;
22023 + need_wh = -ENOMEM;
22024 + dinfo = au_di(dentry);
22025 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22027 + au_di_cp(tmp, dinfo);
22028 + au_di_swap(tmp, dinfo);
22029 + /* returns the number of positive dentries */
22030 + need_wh = au_lkup_dentry(dentry, btop + 1,
22031 + /* AuLkup_IGNORE_PERM */ 0);
22032 + au_di_swap(tmp, dinfo);
22033 + au_rw_write_unlock(&tmp->di_rwsem);
22037 + AuDbg("need_wh %d\n", need_wh);
22045 + * simple tests for the del-entry operations.
22046 + * following the checks in vfs, plus the parent-child relationship.
22048 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22049 + struct dentry *h_parent, int isdir)
22053 + struct dentry *h_dentry, *h_latest;
22054 + struct inode *h_inode;
22056 + h_dentry = au_h_dptr(dentry, bindex);
22057 + if (d_really_is_positive(dentry)) {
22059 + if (unlikely(d_is_negative(h_dentry)))
22061 + h_inode = d_inode(h_dentry);
22062 + if (unlikely(!h_inode->i_nlink))
22065 + h_mode = h_inode->i_mode;
22068 + if (unlikely(S_ISDIR(h_mode)))
22070 + } else if (unlikely(!S_ISDIR(h_mode))) {
22075 + /* rename(2) case */
22077 + if (unlikely(d_is_positive(h_dentry)))
22082 + /* expected parent dir is locked */
22083 + if (unlikely(h_parent != h_dentry->d_parent))
22088 + * rmdir a dir may break the consistency on some filesystem.
22089 + * let's try heavy test.
22092 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22093 + && au_test_h_perm(d_inode(h_parent),
22094 + MAY_EXEC | MAY_WRITE)))
22097 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22099 + if (IS_ERR(h_latest))
22101 + if (h_latest == h_dentry)
22110 + * decide the branch where we operate for @dentry. the branch index will be set
22111 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
22112 + * dir for reverting.
22113 + * when a new whiteout is necessary, create it.
22115 +static struct dentry*
22116 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22117 + struct au_dtime *dt, struct au_pin *pin)
22119 + struct dentry *wh_dentry;
22120 + struct super_block *sb;
22121 + struct path h_path;
22122 + int err, need_wh;
22123 + unsigned int udba;
22124 + aufs_bindex_t bcpup;
22126 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22127 + wh_dentry = ERR_PTR(need_wh);
22128 + if (unlikely(need_wh < 0))
22131 + sb = dentry->d_sb;
22132 + udba = au_opt_udba(sb);
22134 + err = au_pin(pin, dentry, bcpup, udba,
22135 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22136 + wh_dentry = ERR_PTR(err);
22137 + if (unlikely(err))
22140 + h_path.dentry = au_pinned_h_parent(pin);
22141 + if (udba != AuOpt_UDBA_NONE
22142 + && au_dbtop(dentry) == bcpup) {
22143 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22144 + wh_dentry = ERR_PTR(err);
22145 + if (unlikely(err))
22149 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22150 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22151 + wh_dentry = NULL;
22153 + goto out; /* success, no need to create whiteout */
22155 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22156 + if (IS_ERR(wh_dentry))
22159 + /* returns with the parent is locked and wh_dentry is dget-ed */
22160 + goto out; /* success */
22165 + return wh_dentry;
22169 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22170 + * in order to be revertible and save time for removing many child whiteouts
22172 + * returns 1 when there are too many child whiteout and caller should remove
22173 + * them asynchronously. returns 0 when the number of children is enough small to
22174 + * remove now or the branch fs is a remote fs.
22175 + * otherwise return an error.
22177 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22178 + struct au_nhash *whlist, struct inode *dir)
22180 + int rmdir_later, err, dirwh;
22181 + struct dentry *h_dentry;
22182 + struct super_block *sb;
22183 + struct inode *inode;
22185 + sb = dentry->d_sb;
22186 + SiMustAnyLock(sb);
22187 + h_dentry = au_h_dptr(dentry, bindex);
22188 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22189 + if (unlikely(err))
22192 + /* stop monitoring */
22193 + inode = d_inode(dentry);
22194 + au_hn_free(au_hi(inode, bindex));
22196 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22197 + dirwh = au_sbi(sb)->si_dirwh;
22198 + rmdir_later = (dirwh <= 1);
22199 + if (!rmdir_later)
22200 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22203 + return rmdir_later;
22206 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22207 + if (unlikely(err)) {
22208 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22209 + h_dentry, bindex, err);
22219 + * final procedure for deleting a entry.
22220 + * maintain dentry and iattr.
22222 +static void epilog(struct inode *dir, struct dentry *dentry,
22223 + aufs_bindex_t bindex)
22225 + struct inode *inode;
22227 + inode = d_inode(dentry);
22229 + inode->i_ctime = dir->i_ctime;
22231 + au_dir_ts(dir, bindex);
22232 + dir->i_version++;
22236 + * when an error happened, remove the created whiteout and revert everything.
22238 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22239 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22240 + struct dentry *dentry, struct au_dtime *dt)
22243 + struct path h_path = {
22244 + .dentry = wh_dentry,
22245 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22248 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22250 + au_set_dbwh(dentry, bwh);
22251 + au_dtime_revert(dt);
22255 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22259 +/* ---------------------------------------------------------------------- */
22261 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22264 + aufs_bindex_t bwh, bindex, btop;
22265 + struct inode *inode, *h_dir, *delegated;
22266 + struct dentry *parent, *wh_dentry;
22267 + /* to reuduce stack size */
22269 + struct au_dtime dt;
22270 + struct au_pin pin;
22271 + struct path h_path;
22277 + a = kmalloc(sizeof(*a), GFP_NOFS);
22278 + if (unlikely(!a))
22281 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22282 + if (unlikely(err))
22284 + err = au_d_hashed_positive(dentry);
22285 + if (unlikely(err))
22287 + inode = d_inode(dentry);
22288 + IMustLock(inode);
22290 + if (unlikely(d_is_dir(dentry)))
22291 + goto out_unlock; /* possible? */
22293 + btop = au_dbtop(dentry);
22294 + bwh = au_dbwh(dentry);
22296 + parent = dentry->d_parent; /* dir inode is locked */
22297 + di_write_lock_parent(parent);
22298 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22300 + err = PTR_ERR(wh_dentry);
22301 + if (IS_ERR(wh_dentry))
22304 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22305 + a->h_path.dentry = au_h_dptr(dentry, btop);
22306 + dget(a->h_path.dentry);
22307 + if (bindex == btop) {
22308 + h_dir = au_pinned_h_dir(&a->pin);
22309 + delegated = NULL;
22310 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22311 + if (unlikely(err == -EWOULDBLOCK)) {
22312 + pr_warn("cannot retry for NFSv4 delegation"
22313 + " for an internal unlink\n");
22317 + /* dir inode is locked */
22318 + h_dir = d_inode(wh_dentry->d_parent);
22319 + IMustLock(h_dir);
22324 + vfsub_drop_nlink(inode);
22325 + epilog(dir, dentry, bindex);
22327 + /* update target timestamps */
22328 + if (bindex == btop) {
22329 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22331 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22333 + /* todo: this timestamp may be reverted later */
22334 + inode->i_ctime = h_dir->i_ctime;
22335 + goto out_unpin; /* success */
22342 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22349 + au_unpin(&a->pin);
22351 + dput(a->h_path.dentry);
22353 + di_write_unlock(parent);
22355 + aufs_read_unlock(dentry, AuLock_DW);
22362 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22364 + int err, rmdir_later;
22365 + aufs_bindex_t bwh, bindex, btop;
22366 + struct inode *inode;
22367 + struct dentry *parent, *wh_dentry, *h_dentry;
22368 + struct au_whtmp_rmdir *args;
22369 + /* to reuduce stack size */
22371 + struct au_dtime dt;
22372 + struct au_pin pin;
22378 + a = kmalloc(sizeof(*a), GFP_NOFS);
22379 + if (unlikely(!a))
22382 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22383 + if (unlikely(err))
22385 + err = au_alive_dir(dentry);
22386 + if (unlikely(err))
22388 + inode = d_inode(dentry);
22389 + IMustLock(inode);
22391 + if (unlikely(!d_is_dir(dentry)))
22392 + goto out_unlock; /* possible? */
22395 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22396 + if (unlikely(!args))
22399 + parent = dentry->d_parent; /* dir inode is locked */
22400 + di_write_lock_parent(parent);
22401 + err = au_test_empty(dentry, &args->whlist);
22402 + if (unlikely(err))
22405 + btop = au_dbtop(dentry);
22406 + bwh = au_dbwh(dentry);
22408 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22410 + err = PTR_ERR(wh_dentry);
22411 + if (IS_ERR(wh_dentry))
22414 + h_dentry = au_h_dptr(dentry, btop);
22417 + if (bindex == btop) {
22418 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22420 + rmdir_later = err;
22424 + /* stop monitoring */
22425 + au_hn_free(au_hi(inode, btop));
22427 + /* dir inode is locked */
22428 + IMustLock(d_inode(wh_dentry->d_parent));
22433 + vfsub_dead_dir(inode);
22434 + au_set_dbdiropq(dentry, -1);
22435 + epilog(dir, dentry, bindex);
22437 + if (rmdir_later) {
22438 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22442 + goto out_unpin; /* success */
22450 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22457 + au_unpin(&a->pin);
22461 + di_write_unlock(parent);
22463 + au_whtmp_rmdir_free(args);
22465 + aufs_read_unlock(dentry, AuLock_DW);
22472 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22473 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22474 +++ linux/fs/aufs/i_op_ren.c 2017-11-12 22:24:44.707577830 +0100
22477 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22479 + * This program, aufs is free software; you can redistribute it and/or modify
22480 + * it under the terms of the GNU General Public License as published by
22481 + * the Free Software Foundation; either version 2 of the License, or
22482 + * (at your option) any later version.
22484 + * This program is distributed in the hope that it will be useful,
22485 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22486 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22487 + * GNU General Public License for more details.
22489 + * You should have received a copy of the GNU General Public License
22490 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22494 + * inode operation (rename entry)
22495 + * todo: this is crazy monster
22500 +enum { AuSRC, AuDST, AuSrcDst };
22501 +enum { AuPARENT, AuCHILD, AuParentChild };
22503 +#define AuRen_ISDIR_SRC 1
22504 +#define AuRen_ISDIR_DST (1 << 1)
22505 +#define AuRen_ISSAMEDIR (1 << 2)
22506 +#define AuRen_WHSRC (1 << 3)
22507 +#define AuRen_WHDST (1 << 4)
22508 +#define AuRen_MNT_WRITE (1 << 5)
22509 +#define AuRen_DT_DSTDIR (1 << 6)
22510 +#define AuRen_DIROPQ_SRC (1 << 7)
22511 +#define AuRen_DIROPQ_DST (1 << 8)
22512 +#define AuRen_DIRREN (1 << 9)
22513 +#define AuRen_DROPPED_SRC (1 << 10)
22514 +#define AuRen_DROPPED_DST (1 << 11)
22515 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22516 +#define au_fset_ren(flags, name) \
22517 + do { (flags) |= AuRen_##name; } while (0)
22518 +#define au_fclr_ren(flags, name) \
22519 + do { (flags) &= ~AuRen_##name; } while (0)
22521 +#ifndef CONFIG_AUFS_DIRREN
22522 +#undef AuRen_DIRREN
22523 +#define AuRen_DIRREN 0
22526 +struct au_ren_args {
22528 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22530 + struct inode *dir, *inode;
22531 + struct au_hinode *hdir, *hinode;
22532 + struct au_dtime dt[AuParentChild];
22533 + aufs_bindex_t btop, bdiropq;
22536 +#define src_dentry sd[AuSRC].dentry
22537 +#define src_dir sd[AuSRC].dir
22538 +#define src_inode sd[AuSRC].inode
22539 +#define src_h_dentry sd[AuSRC].h_dentry
22540 +#define src_parent sd[AuSRC].parent
22541 +#define src_h_parent sd[AuSRC].h_parent
22542 +#define src_wh_dentry sd[AuSRC].wh_dentry
22543 +#define src_hdir sd[AuSRC].hdir
22544 +#define src_hinode sd[AuSRC].hinode
22545 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22546 +#define src_dt sd[AuSRC].dt
22547 +#define src_btop sd[AuSRC].btop
22548 +#define src_bdiropq sd[AuSRC].bdiropq
22550 +#define dst_dentry sd[AuDST].dentry
22551 +#define dst_dir sd[AuDST].dir
22552 +#define dst_inode sd[AuDST].inode
22553 +#define dst_h_dentry sd[AuDST].h_dentry
22554 +#define dst_parent sd[AuDST].parent
22555 +#define dst_h_parent sd[AuDST].h_parent
22556 +#define dst_wh_dentry sd[AuDST].wh_dentry
22557 +#define dst_hdir sd[AuDST].hdir
22558 +#define dst_hinode sd[AuDST].hinode
22559 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22560 +#define dst_dt sd[AuDST].dt
22561 +#define dst_btop sd[AuDST].btop
22562 +#define dst_bdiropq sd[AuDST].bdiropq
22564 + struct dentry *h_trap;
22565 + struct au_branch *br;
22566 + struct path h_path;
22567 + struct au_nhash whlist;
22568 + aufs_bindex_t btgt, src_bwh;
22571 + unsigned short auren_flags;
22572 + unsigned char flags; /* syscall parameter */
22573 + unsigned char exchange;
22576 + struct au_whtmp_rmdir *thargs;
22577 + struct dentry *h_dst;
22578 + struct au_hinode *h_root;
22581 +/* ---------------------------------------------------------------------- */
22584 + * functions for reverting.
22585 + * when an error happened in a single rename systemcall, we should revert
22586 + * everything as if nothing happened.
22587 + * we don't need to revert the copied-up/down the parent dir since they are
22591 +#define RevertFailure(fmt, ...) do { \
22592 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22593 + ##__VA_ARGS__, err, rerr); \
22597 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22600 + struct dentry *d;
22601 +#define src_or_dst(member) a->sd[idx].member
22603 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22604 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22605 + rerr = au_diropq_remove(d, a->btgt);
22606 + au_hn_inode_unlock(src_or_dst(hinode));
22607 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22609 + RevertFailure("remove diropq %pd", d);
22611 +#undef src_or_dst_
22614 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22616 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22617 + au_ren_do_rev_diropq(err, a, AuSRC);
22618 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22619 + au_ren_do_rev_diropq(err, a, AuDST);
22622 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22625 + struct inode *delegated;
22627 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22628 + a->src_h_parent);
22629 + rerr = PTR_ERR(a->h_path.dentry);
22630 + if (IS_ERR(a->h_path.dentry)) {
22631 + RevertFailure("lkup one %pd", a->src_dentry);
22635 + delegated = NULL;
22636 + rerr = vfsub_rename(a->dst_h_dir,
22637 + au_h_dptr(a->src_dentry, a->btgt),
22638 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22639 + if (unlikely(rerr == -EWOULDBLOCK)) {
22640 + pr_warn("cannot retry for NFSv4 delegation"
22641 + " for an internal rename\n");
22644 + d_drop(a->h_path.dentry);
22645 + dput(a->h_path.dentry);
22646 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22648 + RevertFailure("rename %pd", a->src_dentry);
22651 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22654 + struct inode *delegated;
22656 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22657 + a->dst_h_parent);
22658 + rerr = PTR_ERR(a->h_path.dentry);
22659 + if (IS_ERR(a->h_path.dentry)) {
22660 + RevertFailure("lkup one %pd", a->dst_dentry);
22663 + if (d_is_positive(a->h_path.dentry)) {
22664 + d_drop(a->h_path.dentry);
22665 + dput(a->h_path.dentry);
22669 + delegated = NULL;
22670 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22671 + &delegated, a->flags);
22672 + if (unlikely(rerr == -EWOULDBLOCK)) {
22673 + pr_warn("cannot retry for NFSv4 delegation"
22674 + " for an internal rename\n");
22677 + d_drop(a->h_path.dentry);
22678 + dput(a->h_path.dentry);
22680 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22682 + RevertFailure("rename %pd", a->h_dst);
22685 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22689 + a->h_path.dentry = a->src_wh_dentry;
22690 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22691 + au_set_dbwh(a->src_dentry, a->src_bwh);
22693 + RevertFailure("unlink %pd", a->src_wh_dentry);
22695 +#undef RevertFailure
22697 +/* ---------------------------------------------------------------------- */
22700 + * when we have to copyup the renaming entry, do it with the rename-target name
22701 + * in order to minimize the cost (the later actual rename is unnecessary).
22702 + * otherwise rename it on the target branch.
22704 +static int au_ren_or_cpup(struct au_ren_args *a)
22707 + struct dentry *d;
22708 + struct inode *delegated;
22710 + d = a->src_dentry;
22711 + if (au_dbtop(d) == a->btgt) {
22712 + a->h_path.dentry = a->dst_h_dentry;
22713 + AuDebugOn(au_dbtop(d) != a->btgt);
22714 + delegated = NULL;
22715 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22716 + a->dst_h_dir, &a->h_path, &delegated,
22718 + if (unlikely(err == -EWOULDBLOCK)) {
22719 + pr_warn("cannot retry for NFSv4 delegation"
22720 + " for an internal rename\n");
22726 + if (!err && a->h_dst)
22727 + /* it will be set to dinfo later */
22733 +/* cf. aufs_rmdir() */
22734 +static int au_ren_del_whtmp(struct au_ren_args *a)
22737 + struct inode *dir;
22739 + dir = a->dst_dir;
22740 + SiMustAnyLock(dir->i_sb);
22741 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22742 + au_sbi(dir->i_sb)->si_dirwh)
22743 + || au_test_fs_remote(a->h_dst->d_sb)) {
22744 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22745 + if (unlikely(err))
22746 + pr_warn("failed removing whtmp dir %pd (%d), "
22747 + "ignored.\n", a->h_dst, err);
22749 + au_nhash_wh_free(&a->thargs->whlist);
22750 + a->thargs->whlist = a->whlist;
22751 + a->whlist.nh_num = 0;
22752 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22754 + a->thargs = NULL;
22760 +/* make it 'opaque' dir. */
22761 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22764 + struct dentry *d, *diropq;
22765 +#define src_or_dst(member) a->sd[idx].member
22768 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22769 + src_or_dst(bdiropq) = au_dbdiropq(d);
22770 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22771 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22772 + diropq = au_diropq_create(d, a->btgt);
22773 + au_hn_inode_unlock(src_or_dst(hinode));
22774 + if (IS_ERR(diropq))
22775 + err = PTR_ERR(diropq);
22779 +#undef src_or_dst_
22783 +static int au_ren_diropq(struct au_ren_args *a)
22786 + unsigned char always;
22787 + struct dentry *d;
22790 + d = a->dst_dentry; /* already renamed on the branch */
22791 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22792 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22793 + && !au_ftest_ren(a->auren_flags, DIRREN)
22794 + && a->btgt != au_dbdiropq(a->src_dentry)
22795 + && (a->dst_wh_dentry
22796 + || a->btgt <= au_dbdiropq(d)
22797 + /* hide the lower to keep xino */
22798 + /* the lowers may not be a dir, but we hide them anyway */
22799 + || a->btgt < au_dbbot(d)
22802 + err = au_ren_do_diropq(a, AuSRC);
22803 + if (unlikely(err))
22805 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22807 + if (!a->exchange)
22808 + goto out; /* success */
22810 + d = a->src_dentry; /* already renamed on the branch */
22811 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22812 + && a->btgt != au_dbdiropq(a->dst_dentry)
22813 + && (a->btgt < au_dbdiropq(d)
22814 + || a->btgt < au_dbbot(d)
22816 + AuDbgDentry(a->src_dentry);
22817 + AuDbgDentry(a->dst_dentry);
22818 + err = au_ren_do_diropq(a, AuDST);
22819 + if (unlikely(err))
22820 + goto out_rev_src;
22821 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22823 + goto out; /* success */
22826 + AuDbg("err %d, reverting src\n", err);
22827 + au_ren_rev_diropq(err, a);
22832 +static int do_rename(struct au_ren_args *a)
22835 + struct dentry *d, *h_d;
22837 + if (!a->exchange) {
22838 + /* prepare workqueue args for asynchronous rmdir */
22839 + h_d = a->dst_h_dentry;
22840 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22841 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22842 + && d_is_positive(h_d)) {
22844 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22846 + if (unlikely(!a->thargs))
22848 + a->h_dst = dget(h_d);
22851 + /* create whiteout for src_dentry */
22852 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22853 + a->src_bwh = au_dbwh(a->src_dentry);
22854 + AuDebugOn(a->src_bwh >= 0);
22855 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22856 + a->src_h_parent);
22857 + err = PTR_ERR(a->src_wh_dentry);
22858 + if (IS_ERR(a->src_wh_dentry))
22862 + /* lookup whiteout for dentry */
22863 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22864 + h_d = au_wh_lkup(a->dst_h_parent,
22865 + &a->dst_dentry->d_name, a->br);
22866 + err = PTR_ERR(h_d);
22869 + if (d_is_negative(h_d))
22872 + a->dst_wh_dentry = h_d;
22875 + /* rename dentry to tmpwh */
22877 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22878 + if (unlikely(err))
22881 + d = a->dst_dentry;
22882 + au_set_h_dptr(d, a->btgt, NULL);
22883 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22884 + if (unlikely(err))
22886 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22890 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22892 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22893 + && d_is_positive(a->dst_h_dentry)
22894 + && a->src_btop != a->btgt);
22897 + /* rename by vfs_rename or cpup */
22898 + err = au_ren_or_cpup(a);
22899 + if (unlikely(err))
22900 + /* leave the copied-up one */
22903 + /* make dir opaque */
22904 + err = au_ren_diropq(a);
22905 + if (unlikely(err))
22908 + /* update target timestamps */
22909 + if (a->exchange) {
22910 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22911 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22912 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22913 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22915 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22916 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22917 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22918 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22920 + if (!a->exchange) {
22921 + /* remove whiteout for dentry */
22922 + if (a->dst_wh_dentry) {
22923 + a->h_path.dentry = a->dst_wh_dentry;
22924 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22926 + if (unlikely(err))
22930 + /* remove whtmp */
22932 + au_ren_del_whtmp(a); /* ignore this error */
22934 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22937 + goto out_success;
22940 + au_ren_rev_diropq(err, a);
22942 + au_ren_rev_rename(err, a);
22946 + au_ren_rev_whtmp(err, a);
22948 + dput(a->dst_wh_dentry);
22949 + a->dst_wh_dentry = NULL;
22951 + if (a->src_wh_dentry)
22952 + au_ren_rev_whsrc(err, a);
22954 + dput(a->src_wh_dentry);
22955 + dput(a->dst_wh_dentry);
22959 + au_whtmp_rmdir_free(a->thargs);
22960 + a->thargs = NULL;
22966 +/* ---------------------------------------------------------------------- */
22969 + * test if @dentry dir can be rename destination or not.
22970 + * success means, it is a logically empty dir.
22972 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22974 + return au_test_empty(dentry, whlist);
22978 + * test if @a->src_dentry dir can be rename source or not.
22979 + * if it can, return 0.
22981 + * - it is a logically empty dir.
22982 + * - or, it exists on writable branch and has no children including whiteouts
22983 + * on the lower branch unless DIRREN is on.
22985 +static int may_rename_srcdir(struct au_ren_args *a)
22988 + unsigned int rdhash;
22989 + aufs_bindex_t btop, btgt;
22990 + struct dentry *dentry;
22991 + struct super_block *sb;
22992 + struct au_sbinfo *sbinfo;
22994 + dentry = a->src_dentry;
22995 + sb = dentry->d_sb;
22996 + sbinfo = au_sbi(sb);
22997 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22998 + au_fset_ren(a->auren_flags, DIRREN);
23001 + btop = au_dbtop(dentry);
23002 + if (btop != btgt) {
23003 + struct au_nhash whlist;
23005 + SiMustAnyLock(sb);
23006 + rdhash = sbinfo->si_rdhash;
23008 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23010 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23011 + if (unlikely(err))
23013 + err = au_test_empty(dentry, &whlist);
23014 + au_nhash_wh_free(&whlist);
23018 + if (btop == au_dbtaildir(dentry))
23019 + return 0; /* success */
23021 + err = au_test_empty_lower(dentry);
23024 + if (err == -ENOTEMPTY) {
23025 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23028 + AuWarn1("renaming dir who has child(ren) on multiple "
23029 + "branches, is not supported\n");
23036 +/* side effect: sets whlist and h_dentry */
23037 +static int au_ren_may_dir(struct au_ren_args *a)
23040 + unsigned int rdhash;
23041 + struct dentry *d;
23043 + d = a->dst_dentry;
23044 + SiMustAnyLock(d->d_sb);
23047 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23048 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23050 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23051 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23052 + if (unlikely(err))
23055 + if (!a->exchange) {
23056 + au_set_dbtop(d, a->dst_btop);
23057 + err = may_rename_dstdir(d, &a->whlist);
23058 + au_set_dbtop(d, a->btgt);
23060 + err = may_rename_srcdir(a);
23062 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23063 + if (unlikely(err))
23066 + d = a->src_dentry;
23067 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23068 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23069 + err = may_rename_srcdir(a);
23070 + if (unlikely(err)) {
23071 + au_nhash_wh_free(&a->whlist);
23072 + a->whlist.nh_num = 0;
23079 +/* ---------------------------------------------------------------------- */
23082 + * simple tests for rename.
23083 + * following the checks in vfs, plus the parent-child relationship.
23085 +static int au_may_ren(struct au_ren_args *a)
23088 + struct inode *h_inode;
23090 + if (a->src_btop == a->btgt) {
23091 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23092 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23093 + if (unlikely(err))
23096 + if (unlikely(a->src_h_dentry == a->h_trap))
23101 + if (a->dst_btop != a->btgt)
23104 + err = -ENOTEMPTY;
23105 + if (unlikely(a->dst_h_dentry == a->h_trap))
23109 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23110 + if (d_really_is_negative(a->dst_dentry)) {
23111 + if (d_is_negative(a->dst_h_dentry))
23112 + err = au_may_add(a->dst_dentry, a->btgt,
23113 + a->dst_h_parent, isdir);
23115 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23117 + h_inode = d_inode(a->dst_h_dentry);
23118 + if (h_inode->i_nlink)
23119 + err = au_may_del(a->dst_dentry, a->btgt,
23120 + a->dst_h_parent, isdir);
23124 + if (unlikely(err == -ENOENT || err == -EEXIST))
23130 +/* ---------------------------------------------------------------------- */
23135 + * - src_dir and dir by lock_rename()
23136 + * - inode if exitsts
23139 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23141 + * + di_write_lock2_child()
23142 + * + di_write_lock_child()
23143 + * + ii_write_lock_child()
23144 + * + di_write_lock_child2()
23145 + * + ii_write_lock_child2()
23146 + * + src_parent and parent
23147 + * + di_write_lock_parent()
23148 + * + ii_write_lock_parent()
23149 + * + di_write_lock_parent2()
23150 + * + ii_write_lock_parent2()
23151 + * + lower src_dir and dir by vfsub_lock_rename()
23152 + * + verify the every relationships between child and parent. if any
23153 + * of them failed, unlock all and return -EBUSY.
23155 +static void au_ren_unlock(struct au_ren_args *a)
23157 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23158 + a->dst_h_parent, a->dst_hdir);
23159 + if (au_ftest_ren(a->auren_flags, DIRREN)
23161 + au_hn_inode_unlock(a->h_root);
23162 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23163 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23166 +static int au_ren_lock(struct au_ren_args *a)
23169 + unsigned int udba;
23172 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23173 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23174 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23175 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23177 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23178 + if (unlikely(err))
23180 + au_fset_ren(a->auren_flags, MNT_WRITE);
23181 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23182 + struct dentry *root;
23183 + struct inode *dir;
23186 + * sbinfo is already locked, so this ii_read_lock is
23187 + * unnecessary. but our debugging feature checks it.
23189 + root = a->src_inode->i_sb->s_root;
23190 + if (root != a->src_parent && root != a->dst_parent) {
23191 + dir = d_inode(root);
23192 + ii_read_lock_parent3(dir);
23193 + a->h_root = au_hi(dir, a->btgt);
23194 + ii_read_unlock(dir);
23195 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23198 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23199 + a->dst_h_parent, a->dst_hdir);
23200 + udba = au_opt_udba(a->src_dentry->d_sb);
23201 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23202 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23203 + err = au_busy_or_stale();
23204 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23205 + err = au_h_verify(a->src_h_dentry, udba,
23206 + d_inode(a->src_h_parent), a->src_h_parent,
23208 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23209 + err = au_h_verify(a->dst_h_dentry, udba,
23210 + d_inode(a->dst_h_parent), a->dst_h_parent,
23213 + goto out; /* success */
23215 + err = au_busy_or_stale();
23216 + au_ren_unlock(a);
23222 +/* ---------------------------------------------------------------------- */
23224 +static void au_ren_refresh_dir(struct au_ren_args *a)
23226 + struct inode *dir;
23228 + dir = a->dst_dir;
23229 + dir->i_version++;
23230 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23231 + /* is this updating defined in POSIX? */
23232 + au_cpup_attr_timesizes(a->src_inode);
23233 + au_cpup_attr_nlink(dir, /*force*/1);
23235 + au_dir_ts(dir, a->btgt);
23237 + if (a->exchange) {
23238 + dir = a->src_dir;
23239 + dir->i_version++;
23240 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23241 + /* is this updating defined in POSIX? */
23242 + au_cpup_attr_timesizes(a->dst_inode);
23243 + au_cpup_attr_nlink(dir, /*force*/1);
23245 + au_dir_ts(dir, a->btgt);
23248 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23251 + dir = a->src_dir;
23252 + dir->i_version++;
23253 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23254 + au_cpup_attr_nlink(dir, /*force*/1);
23255 + au_dir_ts(dir, a->btgt);
23258 +static void au_ren_refresh(struct au_ren_args *a)
23260 + aufs_bindex_t bbot, bindex;
23261 + struct dentry *d, *h_d;
23262 + struct inode *i, *h_i;
23263 + struct super_block *sb;
23265 + d = a->dst_dentry;
23268 + /* already dget-ed by au_ren_or_cpup() */
23269 + au_set_h_dptr(d, a->btgt, a->h_dst);
23271 + i = a->dst_inode;
23273 + if (!a->exchange) {
23274 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23275 + vfsub_drop_nlink(i);
23277 + vfsub_dead_dir(i);
23278 + au_cpup_attr_timesizes(i);
23280 + au_update_dbrange(d, /*do_put_zero*/1);
23282 + au_cpup_attr_nlink(i, /*force*/1);
23285 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23286 + au_set_h_dptr(d, bindex, NULL);
23287 + bbot = au_dbbot(d);
23288 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23289 + au_set_h_dptr(d, bindex, NULL);
23290 + au_update_dbrange(d, /*do_put_zero*/0);
23294 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23295 + d_drop(a->src_dentry);
23296 + if (au_ftest_ren(a->auren_flags, DIRREN))
23297 + au_set_dbwh(a->src_dentry, -1);
23301 + d = a->src_dentry;
23302 + au_set_dbwh(d, -1);
23303 + bbot = au_dbbot(d);
23304 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23305 + h_d = au_h_dptr(d, bindex);
23307 + au_set_h_dptr(d, bindex, NULL);
23309 + au_set_dbbot(d, a->btgt);
23312 + i = a->src_inode;
23313 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23314 + return; /* success */
23316 + bbot = au_ibbot(i);
23317 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23318 + h_i = au_h_iptr(i, bindex);
23320 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23321 + /* ignore this error */
23322 + au_set_h_iptr(i, bindex, NULL, 0);
23325 + au_set_ibbot(i, a->btgt);
23328 +/* ---------------------------------------------------------------------- */
23330 +/* mainly for link(2) and rename(2) */
23331 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23333 + aufs_bindex_t bdiropq, bwh;
23334 + struct dentry *parent;
23335 + struct au_branch *br;
23337 + parent = dentry->d_parent;
23338 + IMustLock(d_inode(parent)); /* dir is locked */
23340 + bdiropq = au_dbdiropq(parent);
23341 + bwh = au_dbwh(dentry);
23342 + br = au_sbr(dentry->d_sb, btgt);
23343 + if (au_br_rdonly(br)
23344 + || (0 <= bdiropq && bdiropq < btgt)
23345 + || (0 <= bwh && bwh < btgt))
23348 + AuDbg("btgt %d\n", btgt);
23352 +/* sets src_btop, dst_btop and btgt */
23353 +static int au_ren_wbr(struct au_ren_args *a)
23356 + struct au_wr_dir_args wr_dir_args = {
23357 + /* .force_btgt = -1, */
23358 + .flags = AuWrDir_ADD_ENTRY
23361 + a->src_btop = au_dbtop(a->src_dentry);
23362 + a->dst_btop = au_dbtop(a->dst_dentry);
23363 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23364 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23365 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23366 + wr_dir_args.force_btgt = a->src_btop;
23367 + if (a->dst_inode && a->dst_btop < a->src_btop)
23368 + wr_dir_args.force_btgt = a->dst_btop;
23369 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23370 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23373 + au_update_dbtop(a->dst_dentry);
23378 +static void au_ren_dt(struct au_ren_args *a)
23380 + a->h_path.dentry = a->src_h_parent;
23381 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23382 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23383 + a->h_path.dentry = a->dst_h_parent;
23384 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23387 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23388 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23392 + a->h_path.dentry = a->src_h_dentry;
23393 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23394 + if (d_is_positive(a->dst_h_dentry)) {
23395 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23396 + a->h_path.dentry = a->dst_h_dentry;
23397 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23401 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23403 + struct dentry *h_d;
23404 + struct inode *h_inode;
23406 + au_dtime_revert(a->src_dt + AuPARENT);
23407 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23408 + au_dtime_revert(a->dst_dt + AuPARENT);
23410 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23411 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23412 + h_inode = d_inode(h_d);
23413 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23414 + au_dtime_revert(a->src_dt + AuCHILD);
23415 + inode_unlock(h_inode);
23417 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23418 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23419 + h_inode = d_inode(h_d);
23420 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23421 + au_dtime_revert(a->dst_dt + AuCHILD);
23422 + inode_unlock(h_inode);
23427 +/* ---------------------------------------------------------------------- */
23429 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23430 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23431 + unsigned int _flags)
23433 + int err, lock_flags;
23435 + /* reduce stack space */
23436 + struct au_ren_args *a;
23437 + struct au_pin pin;
23439 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23440 + IMustLock(_src_dir);
23441 + IMustLock(_dst_dir);
23444 + if (unlikely(_flags & RENAME_WHITEOUT))
23448 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23449 + a = kzalloc(sizeof(*a), GFP_NOFS);
23450 + if (unlikely(!a))
23453 + a->flags = _flags;
23454 + a->exchange = _flags & RENAME_EXCHANGE;
23455 + a->src_dir = _src_dir;
23456 + a->src_dentry = _src_dentry;
23457 + a->src_inode = NULL;
23458 + if (d_really_is_positive(a->src_dentry))
23459 + a->src_inode = d_inode(a->src_dentry);
23460 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23461 + a->dst_dir = _dst_dir;
23462 + a->dst_dentry = _dst_dentry;
23463 + a->dst_inode = NULL;
23464 + if (d_really_is_positive(a->dst_dentry))
23465 + a->dst_inode = d_inode(a->dst_dentry);
23466 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23467 + if (a->dst_inode) {
23469 + * if EXCHANGE && src is non-dir && dst is dir,
23470 + * dst is not locked.
23472 + /* IMustLock(a->dst_inode); */
23473 + au_igrab(a->dst_inode);
23477 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23478 + if (d_is_dir(a->src_dentry)) {
23479 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23480 + if (unlikely(!a->exchange
23481 + && d_really_is_positive(a->dst_dentry)
23482 + && !d_is_dir(a->dst_dentry)))
23484 + lock_flags |= AuLock_DIRS;
23486 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23487 + au_fset_ren(a->auren_flags, ISDIR_DST);
23488 + if (unlikely(!a->exchange
23489 + && d_really_is_positive(a->src_dentry)
23490 + && !d_is_dir(a->src_dentry)))
23492 + lock_flags |= AuLock_DIRS;
23494 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23496 + if (unlikely(err))
23499 + err = au_d_hashed_positive(a->src_dentry);
23500 + if (unlikely(err))
23503 + if (a->dst_inode) {
23505 + * If it is a dir, VFS unhash it before this
23506 + * function. It means we cannot rely upon d_unhashed().
23508 + if (unlikely(!a->dst_inode->i_nlink))
23510 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23511 + err = au_d_hashed_positive(a->dst_dentry);
23512 + if (unlikely(err && !a->exchange))
23514 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23516 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23520 + * is it possible?
23521 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23522 + * there may exist a problem somewhere else.
23525 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23528 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23529 + di_write_lock_parent(a->dst_parent);
23531 + /* which branch we process */
23532 + err = au_ren_wbr(a);
23533 + if (unlikely(err < 0))
23535 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23536 + a->h_path.mnt = au_br_mnt(a->br);
23538 + /* are they available to be renamed */
23539 + err = au_ren_may_dir(a);
23540 + if (unlikely(err))
23541 + goto out_children;
23543 + /* prepare the writable parent dir on the same branch */
23544 + if (a->dst_btop == a->btgt) {
23545 + au_fset_ren(a->auren_flags, WHDST);
23547 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23548 + if (unlikely(err))
23549 + goto out_children;
23553 + if (!a->exchange) {
23554 + if (a->src_dir != a->dst_dir) {
23556 + * this temporary unlock is safe,
23557 + * because both dir->i_mutex are locked.
23559 + di_write_unlock(a->dst_parent);
23560 + di_write_lock_parent(a->src_parent);
23561 + err = au_wr_dir_need_wh(a->src_dentry,
23562 + au_ftest_ren(a->auren_flags,
23565 + di_write_unlock(a->src_parent);
23566 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23568 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23570 + err = au_wr_dir_need_wh(a->src_dentry,
23571 + au_ftest_ren(a->auren_flags,
23575 + if (unlikely(err < 0))
23576 + goto out_children;
23578 + au_fset_ren(a->auren_flags, WHSRC);
23581 + if (a->src_btop != a->btgt) {
23582 + err = au_pin(&pin, a->src_dentry, a->btgt,
23583 + au_opt_udba(a->src_dentry->d_sb),
23584 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23586 + struct au_cp_generic cpg = {
23587 + .dentry = a->src_dentry,
23589 + .bsrc = a->src_btop,
23592 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23594 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23595 + err = au_sio_cpup_simple(&cpg);
23598 + if (unlikely(err))
23599 + goto out_children;
23600 + a->src_btop = a->btgt;
23601 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23602 + if (!a->exchange)
23603 + au_fset_ren(a->auren_flags, WHSRC);
23607 + if (a->exchange && a->dst_inode
23608 + && a->dst_btop != a->btgt) {
23609 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23610 + au_opt_udba(a->dst_dentry->d_sb),
23611 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23613 + struct au_cp_generic cpg = {
23614 + .dentry = a->dst_dentry,
23616 + .bsrc = a->dst_btop,
23619 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23621 + err = au_sio_cpup_simple(&cpg);
23624 + if (unlikely(err))
23625 + goto out_children;
23626 + a->dst_btop = a->btgt;
23627 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23630 + /* lock them all */
23631 + err = au_ren_lock(a);
23632 + if (unlikely(err))
23633 + /* leave the copied-up one */
23634 + goto out_children;
23636 + if (!a->exchange) {
23637 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23638 + err = au_may_ren(a);
23639 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23640 + err = -ENAMETOOLONG;
23641 + if (unlikely(err))
23645 + /* store timestamps to be revertible */
23648 + /* store dirren info */
23649 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23650 + err = au_dr_rename(a->src_dentry, a->btgt,
23651 + &a->dst_dentry->d_name, &rev);
23653 + if (unlikely(err))
23658 + err = do_rename(a);
23659 + if (unlikely(err))
23662 + if (au_ftest_ren(a->auren_flags, DIRREN))
23663 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23665 + /* update dir attributes */
23666 + au_ren_refresh_dir(a);
23668 + /* dput/iput all lower dentries */
23669 + au_ren_refresh(a);
23671 + goto out_hdir; /* success */
23674 + if (au_ftest_ren(a->auren_flags, DIRREN))
23675 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23677 + au_ren_rev_dt(err, a);
23679 + au_ren_unlock(a);
23681 + au_nhash_wh_free(&a->whlist);
23682 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23683 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23684 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23685 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23689 + if (d_unhashed(a->src_dentry))
23690 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23691 + if (d_unhashed(a->dst_dentry))
23692 + au_fset_ren(a->auren_flags, DROPPED_DST);
23693 + if (!a->exchange)
23694 + d_move(a->src_dentry, a->dst_dentry);
23696 + d_exchange(a->src_dentry, a->dst_dentry);
23697 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23698 + d_drop(a->dst_dentry);
23700 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23701 + d_drop(a->src_dentry);
23703 + au_update_dbtop(a->dst_dentry);
23704 + if (!a->dst_inode)
23705 + d_drop(a->dst_dentry);
23707 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23708 + di_write_unlock(a->dst_parent);
23710 + di_write_unlock2(a->src_parent, a->dst_parent);
23712 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23714 + iput(a->dst_inode);
23716 + au_whtmp_rmdir_free(a->thargs);
23722 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23723 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23724 +++ linux/fs/aufs/Kconfig 2017-11-12 22:24:44.697577553 +0100
23727 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23729 + Aufs is a stackable unification filesystem such as Unionfs,
23730 + which unifies several directories and provides a merged single
23732 + In the early days, aufs was entirely re-designed and
23733 + re-implemented Unionfs Version 1.x series. Introducing many
23734 + original ideas, approaches and improvements, it becomes totally
23735 + different from Unionfs while keeping the basic features.
23739 + prompt "Maximum number of branches"
23740 + default AUFS_BRANCH_MAX_127
23742 + Specifies the maximum number of branches (or member directories)
23743 + in a single aufs. The larger value consumes more system
23744 + resources and has a minor impact to performance.
23745 +config AUFS_BRANCH_MAX_127
23748 + Specifies the maximum number of branches (or member directories)
23749 + in a single aufs. The larger value consumes more system
23750 + resources and has a minor impact to performance.
23751 +config AUFS_BRANCH_MAX_511
23754 + Specifies the maximum number of branches (or member directories)
23755 + in a single aufs. The larger value consumes more system
23756 + resources and has a minor impact to performance.
23757 +config AUFS_BRANCH_MAX_1023
23760 + Specifies the maximum number of branches (or member directories)
23761 + in a single aufs. The larger value consumes more system
23762 + resources and has a minor impact to performance.
23763 +config AUFS_BRANCH_MAX_32767
23766 + Specifies the maximum number of branches (or member directories)
23767 + in a single aufs. The larger value consumes more system
23768 + resources and has a minor impact to performance.
23771 +config AUFS_SBILIST
23773 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23776 + Automatic configuration for internal use.
23777 + When aufs supports Magic SysRq or /proc, enabled automatically.
23779 +config AUFS_HNOTIFY
23780 + bool "Detect direct branch access (bypassing aufs)"
23782 + If you want to modify files on branches directly, eg. bypassing aufs,
23783 + and want aufs to detect the changes of them fully, then enable this
23784 + option and use 'udba=notify' mount option.
23785 + Currently there is only one available configuration, "fsnotify".
23786 + It will have a negative impact to the performance.
23787 + See detail in aufs.5.
23790 + prompt "method" if AUFS_HNOTIFY
23791 + default AUFS_HFSNOTIFY
23792 +config AUFS_HFSNOTIFY
23797 +config AUFS_EXPORT
23798 + bool "NFS-exportable aufs"
23799 + depends on EXPORTFS
23801 + If you want to export your mounted aufs via NFS, then enable this
23802 + option. There are several requirements for this configuration.
23803 + See detail in aufs.5.
23805 +config AUFS_INO_T_64
23807 + depends on AUFS_EXPORT
23808 + depends on 64BIT && !(ALPHA || S390)
23811 + Automatic configuration for internal use.
23812 + /* typedef unsigned long/int __kernel_ino_t */
23813 + /* alpha and s390x are int */
23816 + bool "support for XATTR/EA (including Security Labels)"
23818 + If your branch fs supports XATTR/EA and you want to make them
23819 + available in aufs too, then enable this opsion and specify the
23820 + branch attributes for EA.
23821 + See detail in aufs.5.
23824 + bool "File-based Hierarchical Storage Management"
23826 + Hierarchical Storage Management (or HSM) is a well-known feature
23827 + in the storage world. Aufs provides this feature as file-based.
23828 + with multiple branches.
23829 + These multiple branches are prioritized, ie. the topmost one
23830 + should be the fastest drive and be used heavily.
23833 + bool "Readdir in userspace"
23835 + Aufs has two methods to provide a merged view for a directory,
23836 + by a user-space library and by kernel-space natively. The latter
23837 + is always enabled but sometimes large and slow.
23838 + If you enable this option, install the library in aufs2-util
23839 + package, and set some environment variables for your readdir(3),
23840 + then the work will be handled in user-space which generally
23841 + shows better performance in most cases.
23842 + See detail in aufs.5.
23844 +config AUFS_DIRREN
23845 + bool "Workaround for rename(2)-ing a directory"
23847 + By default, aufs returns EXDEV error in renameing a dir who has
23848 + his child on the lower branch, since it is a bad idea to issue
23849 + rename(2) internally for every lower branch. But user may not
23850 + accept this behaviour. So here is a workaround to allow such
23851 + rename(2) and store some extra infromation on the writable
23852 + branch. Obviously this costs high (and I don't like it).
23853 + To use this feature, you need to enable this configuration AND
23854 + to specify the mount option `dirren.'
23855 + See details in aufs.5 and the design documents.
23858 + bool "Show whiteouts"
23860 + If you want to make the whiteouts in aufs visible, then enable
23861 + this option and specify 'shwh' mount option. Although it may
23862 + sounds like philosophy or something, but in technically it
23863 + simply shows the name of whiteout with keeping its behaviour.
23865 +config AUFS_BR_RAMFS
23866 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23868 + If you want to use ramfs as an aufs branch fs, then enable this
23869 + option. Generally tmpfs is recommended.
23870 + Aufs prohibited them to be a branch fs by default, because
23871 + initramfs becomes unusable after switch_root or something
23872 + generally. If you sets initramfs as an aufs branch and boot your
23873 + system by switch_root, you will meet a problem easily since the
23874 + files in initramfs may be inaccessible.
23875 + Unless you are going to use ramfs as an aufs branch fs without
23876 + switch_root or something, leave it N.
23878 +config AUFS_BR_FUSE
23879 + bool "Fuse fs as an aufs branch"
23880 + depends on FUSE_FS
23883 + If you want to use fuse-based userspace filesystem as an aufs
23884 + branch fs, then enable this option.
23885 + It implements the internal poll(2) operation which is
23886 + implemented by fuse only (curretnly).
23891 + Automatic configuration for internal use.
23893 +config AUFS_BR_HFSPLUS
23894 + bool "Hfsplus as an aufs branch"
23895 + depends on HFSPLUS_FS
23898 + If you want to use hfsplus fs as an aufs branch fs, then enable
23899 + this option. This option introduces a small overhead at
23900 + copying-up a file on hfsplus.
23902 +config AUFS_BDEV_LOOP
23904 + depends on BLK_DEV_LOOP
23907 + Automatic configuration for internal use.
23908 + Convert =[ym] into =y.
23911 + bool "Debug aufs"
23913 + Enable this to compile aufs internal debug code.
23914 + It will have a negative impact to the performance.
23916 +config AUFS_MAGIC_SYSRQ
23918 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23921 + Automatic configuration for internal use.
23922 + When aufs supports Magic SysRq, enabled automatically.
23924 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
23925 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
23926 +++ linux/fs/aufs/loop.c 2017-11-12 22:24:42.270843503 +0100
23929 + * Copyright (C) 2005-2017 Junjiro R. Okajima
23931 + * This program, aufs is free software; you can redistribute it and/or modify
23932 + * it under the terms of the GNU General Public License as published by
23933 + * the Free Software Foundation; either version 2 of the License, or
23934 + * (at your option) any later version.
23936 + * This program is distributed in the hope that it will be useful,
23937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23939 + * GNU General Public License for more details.
23941 + * You should have received a copy of the GNU General Public License
23942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23946 + * support for loopback block device as a branch
23951 +/* added into drivers/block/loop.c */
23952 +static struct file *(*backing_file_func)(struct super_block *sb);
23955 + * test if two lower dentries have overlapping branches.
23957 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
23959 + struct super_block *h_sb;
23960 + struct file *backing_file;
23962 + if (unlikely(!backing_file_func)) {
23963 + /* don't load "loop" module here */
23964 + backing_file_func = symbol_get(loop_backing_file);
23965 + if (unlikely(!backing_file_func))
23966 + /* "loop" module is not loaded */
23970 + h_sb = h_adding->d_sb;
23971 + backing_file = backing_file_func(h_sb);
23972 + if (!backing_file)
23975 + h_adding = backing_file->f_path.dentry;
23977 + * h_adding can be local NFS.
23978 + * in this case aufs cannot detect the loop.
23980 + if (unlikely(h_adding->d_sb == sb))
23982 + return !!au_test_subdir(h_adding, sb->s_root);
23985 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
23986 +int au_test_loopback_kthread(void)
23989 + struct task_struct *tsk = current;
23990 + char c, comm[sizeof(tsk->comm)];
23993 + if (tsk->flags & PF_KTHREAD) {
23994 + get_task_comm(comm, tsk);
23996 + ret = ('0' <= c && c <= '9'
23997 + && !strncmp(comm, "loop", 4));
24003 +/* ---------------------------------------------------------------------- */
24005 +#define au_warn_loopback_step 16
24006 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24007 +static unsigned long *au_warn_loopback_array;
24009 +void au_warn_loopback(struct super_block *h_sb)
24011 + int i, new_nelem;
24012 + unsigned long *a, magic;
24013 + static DEFINE_SPINLOCK(spin);
24015 + magic = h_sb->s_magic;
24016 + spin_lock(&spin);
24017 + a = au_warn_loopback_array;
24018 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24019 + if (a[i] == magic) {
24020 + spin_unlock(&spin);
24024 + /* h_sb is new to us, print it */
24025 + if (i < au_warn_loopback_nelem) {
24030 + /* expand the array */
24031 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24032 + a = au_kzrealloc(au_warn_loopback_array,
24033 + au_warn_loopback_nelem * sizeof(unsigned long),
24034 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24035 + /*may_shrink*/0);
24037 + au_warn_loopback_nelem = new_nelem;
24038 + au_warn_loopback_array = a;
24043 + spin_unlock(&spin);
24044 + AuWarn1("realloc failed, ignored\n");
24048 + spin_unlock(&spin);
24049 + pr_warn("you may want to try another patch for loopback file "
24050 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24053 +int au_loopback_init(void)
24056 + struct super_block *sb __maybe_unused;
24058 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24061 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24062 + sizeof(unsigned long), GFP_NOFS);
24063 + if (unlikely(!au_warn_loopback_array))
24069 +void au_loopback_fin(void)
24071 + if (backing_file_func)
24072 + symbol_put(loop_backing_file);
24073 + kfree(au_warn_loopback_array);
24075 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24076 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24077 +++ linux/fs/aufs/loop.h 2017-07-29 12:14:25.903042072 +0200
24080 + * Copyright (C) 2005-2017 Junjiro R. Okajima
24082 + * This program, aufs is free software; you can redistribute it and/or modify
24083 + * it under the terms of the GNU General Public License as published by
24084 + * the Free Software Foundation; either version 2 of the License, or
24085 + * (at your option) any later version.
24087 + * This program is distributed in the hope that it will be useful,
24088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24090 + * GNU General Public License for more details.
24092 + * You should have received a copy of the GNU General Public License
24093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24097 + * support for loopback mount as a branch
24100 +#ifndef __AUFS_LOOP_H__
24101 +#define __AUFS_LOOP_H__
24106 +struct super_block;
24108 +#ifdef CONFIG_AUFS_BDEV_LOOP
24109 +/* drivers/block/loop.c */
24110 +struct file *loop_backing_file(struct super_block *sb);
24113 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24114 +int au_test_loopback_kthread(void);
24115 +void au_warn_loopback(struct super_block *h_sb);
24117 +int au_loopback_init(void);
24118 +void au_loopback_fin(void);
24120 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24121 + struct dentry *h_adding)
24122 +AuStubInt0(au_test_loopback_kthread, void)
24123 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24125 +AuStubInt0(au_loopback_init, void)
24126 +AuStubVoid(au_loopback_fin, void)
24127 +#endif /* BLK_DEV_LOOP */
24129 +#endif /* __KERNEL__ */
24130 +#endif /* __AUFS_LOOP_H__ */
24131 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24132 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24133 +++ linux/fs/aufs/magic.mk 2017-07-29 12:14:25.903042072 +0200
24136 +# defined in ${srctree}/fs/fuse/inode.c
24138 +ifdef CONFIG_FUSE_FS
24139 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24142 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24144 +ifdef CONFIG_XFS_FS
24145 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24148 +# defined in ${srctree}/fs/configfs/mount.c
24150 +ifdef CONFIG_CONFIGFS_FS
24151 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24154 +# defined in ${srctree}/fs/ubifs/ubifs.h
24156 +ifdef CONFIG_UBIFS_FS
24157 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24160 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24162 +ifdef CONFIG_HFSPLUS_FS
24163 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24165 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24166 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24167 +++ linux/fs/aufs/Makefile 2017-11-12 22:24:44.697577553 +0100
24170 +include ${src}/magic.mk
24171 +ifeq (${CONFIG_AUFS_FS},m)
24172 +include ${src}/conf.mk
24174 +-include ${src}/priv_def.mk
24176 +# cf. include/linux/kernel.h
24178 +ccflags-y += -DDEBUG
24179 +# sparse requires the full pathname
24181 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24183 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24186 +obj-$(CONFIG_AUFS_FS) += aufs.o
24187 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24188 + wkq.o vfsub.o dcsub.o \
24189 + cpup.o whout.o wbr_policy.o \
24190 + dinfo.o dentry.o \
24192 + finfo.o file.o f_op.o \
24194 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24198 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24199 +aufs-$(CONFIG_SYSFS) += sysfs.o
24200 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24201 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24202 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24203 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24204 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24205 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24206 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24207 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24208 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24209 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24210 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24211 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24212 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24213 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24214 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24215 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24216 +++ linux/fs/aufs/module.c 2017-11-12 22:24:44.707577830 +0100
24219 + * Copyright (C) 2005-2017 Junjiro R. Okajima
24221 + * This program, aufs is free software; you can redistribute it and/or modify
24222 + * it under the terms of the GNU General Public License as published by
24223 + * the Free Software Foundation; either version 2 of the License, or
24224 + * (at your option) any later version.
24226 + * This program is distributed in the hope that it will be useful,
24227 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24228 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24229 + * GNU General Public License for more details.
24231 + * You should have received a copy of the GNU General Public License
24232 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24236 + * module global variables and operations
24239 +#include <linux/module.h>
24240 +#include <linux/seq_file.h>
24243 +/* shrinkable realloc */
24244 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24252 +#if 0 /* unused */
24259 + AuDebugOn(!new_sz);
24262 + diff = au_kmidx_sub(sz, new_sz);
24268 + /* expand or SLOB */
24269 + p = krealloc(p, new_sz, gfp);
24270 + else if (new_sz < sz && may_shrink) {
24274 + q = kmalloc(new_sz, gfp);
24277 + memcpy(q, p, new_sz);
24289 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24292 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24293 + if (p && new_sz > nused)
24294 + memset(p + nused, 0, new_sz - nused);
24298 +/* ---------------------------------------------------------------------- */
24302 +struct kmem_cache *au_cache[AuCache_Last];
24304 +static void au_cache_fin(void)
24309 + * Make sure all delayed rcu free inodes are flushed before we
24314 + /* excluding AuCache_HNOTIFY */
24315 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24316 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24317 + kmem_cache_destroy(au_cache[i]);
24318 + au_cache[i] = NULL;
24322 +static int __init au_cache_init(void)
24324 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24325 + if (au_cache[AuCache_DINFO])
24326 + /* SLAB_DESTROY_BY_RCU */
24327 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24328 + au_icntnr_init_once);
24329 + if (au_cache[AuCache_ICNTNR])
24330 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24331 + au_fi_init_once);
24332 + if (au_cache[AuCache_FINFO])
24333 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24334 + if (au_cache[AuCache_VDIR])
24335 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24336 + if (au_cache[AuCache_DEHSTR])
24343 +/* ---------------------------------------------------------------------- */
24345 +int au_dir_roflags;
24347 +#ifdef CONFIG_AUFS_SBILIST
24349 + * iterate_supers_type() doesn't protect us from
24350 + * remounting (branch management)
24352 +struct hlist_bl_head au_sbilist;
24356 + * functions for module interface.
24358 +MODULE_LICENSE("GPL");
24359 +/* MODULE_LICENSE("GPL v2"); */
24360 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24361 +MODULE_DESCRIPTION(AUFS_NAME
24362 + " -- Advanced multi layered unification filesystem");
24363 +MODULE_VERSION(AUFS_VERSION);
24364 +MODULE_ALIAS_FS(AUFS_NAME);
24366 +/* this module parameter has no meaning when SYSFS is disabled */
24367 +int sysaufs_brs = 1;
24368 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24369 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
24371 +/* this module parameter has no meaning when USER_NS is disabled */
24373 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24374 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
24376 +/* ---------------------------------------------------------------------- */
24378 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24380 +int au_seq_path(struct seq_file *seq, struct path *path)
24384 + err = seq_path(seq, path, au_esc_chars);
24393 +/* ---------------------------------------------------------------------- */
24395 +static int __init aufs_init(void)
24400 + p = au_esc_chars;
24401 + for (i = 1; i <= ' '; i++)
24407 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24409 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24410 + for (i = 0; i < AuIop_Last; i++)
24411 + aufs_iop_nogetattr[i].getattr = NULL;
24413 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24415 + au_sbilist_init();
24416 + sysaufs_brs_init();
24419 + err = sysaufs_init();
24420 + if (unlikely(err))
24422 + err = au_procfs_init();
24423 + if (unlikely(err))
24424 + goto out_sysaufs;
24425 + err = au_wkq_init();
24426 + if (unlikely(err))
24428 + err = au_loopback_init();
24429 + if (unlikely(err))
24431 + err = au_hnotify_init();
24432 + if (unlikely(err))
24433 + goto out_loopback;
24434 + err = au_sysrq_init();
24435 + if (unlikely(err))
24437 + err = au_cache_init();
24438 + if (unlikely(err))
24441 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24442 + err = register_filesystem(&aufs_fs_type);
24443 + if (unlikely(err))
24446 + /* since we define pr_fmt, call printk directly */
24447 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24448 + goto out; /* success */
24455 + au_hnotify_fin();
24457 + au_loopback_fin();
24469 +static void __exit aufs_exit(void)
24471 + unregister_filesystem(&aufs_fs_type);
24474 + au_hnotify_fin();
24475 + au_loopback_fin();
24482 +module_init(aufs_init);
24483 +module_exit(aufs_exit);
24484 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24485 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24486 +++ linux/fs/aufs/module.h 2017-11-12 22:24:42.270843503 +0100
24489 + * Copyright (C) 2005-2017 Junjiro R. Okajima
24491 + * This program, aufs is free software; you can redistribute it and/or modify
24492 + * it under the terms of the GNU General Public License as published by
24493 + * the Free Software Foundation; either version 2 of the License, or
24494 + * (at your option) any later version.
24496 + * This program is distributed in the hope that it will be useful,
24497 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24499 + * GNU General Public License for more details.
24501 + * You should have received a copy of the GNU General Public License
24502 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24506 + * module initialization and module-global
24509 +#ifndef __AUFS_MODULE_H__
24510 +#define __AUFS_MODULE_H__
24514 +#include <linux/slab.h>
24519 +/* module parameters */
24520 +extern int sysaufs_brs;
24521 +extern bool au_userns;
24523 +/* ---------------------------------------------------------------------- */
24525 +extern int au_dir_roflags;
24527 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24528 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24531 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24533 +#ifndef CONFIG_SLOB
24534 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24536 + return -1; /* SLOB is untested */
24540 +int au_seq_path(struct seq_file *seq, struct path *path);
24542 +#ifdef CONFIG_PROC_FS
24544 +int __init au_procfs_init(void);
24545 +void au_procfs_fin(void);
24547 +AuStubInt0(au_procfs_init, void);
24548 +AuStubVoid(au_procfs_fin, void);
24551 +/* ---------------------------------------------------------------------- */
24560 + AuCache_HNOTIFY, /* must be last */
24564 +extern struct kmem_cache *au_cache[AuCache_Last];
24566 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24567 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24568 +#define AuCacheCtor(type, ctor) \
24569 + kmem_cache_create(#type, sizeof(struct type), \
24570 + __alignof__(struct type), AuCacheFlags, ctor)
24572 +#define AuCacheFuncs(name, index) \
24573 +static inline struct au_##name *au_cache_alloc_##name(void) \
24574 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24575 +static inline void au_cache_free_##name(struct au_##name *p) \
24576 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
24578 +AuCacheFuncs(dinfo, DINFO);
24579 +AuCacheFuncs(icntnr, ICNTNR);
24580 +AuCacheFuncs(finfo, FINFO);
24581 +AuCacheFuncs(vdir, VDIR);
24582 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24583 +#ifdef CONFIG_AUFS_HNOTIFY
24584 +AuCacheFuncs(hnotify, HNOTIFY);
24587 +#endif /* __KERNEL__ */
24588 +#endif /* __AUFS_MODULE_H__ */
24589 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24590 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24591 +++ linux/fs/aufs/mvdown.c 2017-11-12 22:24:44.707577830 +0100
24594 + * Copyright (C) 2011-2017 Junjiro R. Okajima
24596 + * This program, aufs is free software; you can redistribute it and/or modify
24597 + * it under the terms of the GNU General Public License as published by
24598 + * the Free Software Foundation; either version 2 of the License, or
24599 + * (at your option) any later version.
24601 + * This program is distributed in the hope that it will be useful,
24602 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24603 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24604 + * GNU General Public License for more details.
24606 + * You should have received a copy of the GNU General Public License
24607 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24611 + * move-down, opposite of copy-up
24616 +struct au_mvd_args {
24618 + struct super_block *h_sb;
24619 + struct dentry *h_parent;
24620 + struct au_hinode *hdir;
24621 + struct inode *h_dir, *h_inode;
24622 + struct au_pin pin;
24623 + } info[AUFS_MVDOWN_NARRAY];
24625 + struct aufs_mvdown mvdown;
24626 + struct dentry *dentry, *parent;
24627 + struct inode *inode, *dir;
24628 + struct super_block *sb;
24629 + aufs_bindex_t bopq, bwh, bfound;
24630 + unsigned char rename_lock;
24633 +#define mvd_errno mvdown.au_errno
24634 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24635 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24636 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24637 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24639 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24640 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24641 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24642 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24643 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24644 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24646 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24647 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24648 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24649 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24650 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24651 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24653 +#define AU_MVD_PR(flag, ...) do { \
24655 + pr_err(__VA_ARGS__); \
24658 +static int find_lower_writable(struct au_mvd_args *a)
24660 + struct super_block *sb;
24661 + aufs_bindex_t bindex, bbot;
24662 + struct au_branch *br;
24665 + bindex = a->mvd_bsrc;
24666 + bbot = au_sbbot(sb);
24667 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24668 + for (bindex++; bindex <= bbot; bindex++) {
24669 + br = au_sbr(sb, bindex);
24670 + if (au_br_fhsm(br->br_perm)
24671 + && !sb_rdonly(au_br_sb(br)))
24674 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24675 + for (bindex++; bindex <= bbot; bindex++) {
24676 + br = au_sbr(sb, bindex);
24677 + if (!au_br_rdonly(br))
24681 + for (bindex++; bindex <= bbot; bindex++) {
24682 + br = au_sbr(sb, bindex);
24683 + if (!sb_rdonly(au_br_sb(br))) {
24684 + if (au_br_rdonly(br))
24686 + |= AUFS_MVDOWN_ROLOWER_R;
24694 +/* make the parent dir on bdst */
24695 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24700 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24701 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24702 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24703 + a->mvd_h_dst_parent = NULL;
24704 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24705 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24706 + if (!a->mvd_h_dst_parent) {
24707 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24708 + if (unlikely(err)) {
24709 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24712 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24720 +/* lock them all */
24721 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24724 + struct dentry *h_trap;
24726 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24727 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24728 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24729 + au_opt_udba(a->sb),
24730 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24732 + if (unlikely(err)) {
24733 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24737 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24738 + a->rename_lock = 0;
24739 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24740 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24741 + au_opt_udba(a->sb),
24742 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24743 + err = au_do_pin(&a->mvd_pin_src);
24745 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24746 + if (unlikely(err)) {
24747 + AU_MVD_PR(dmsg, "pin_src failed\n");
24750 + goto out; /* success */
24753 + a->rename_lock = 1;
24754 + au_pin_hdir_unlock(&a->mvd_pin_dst);
24755 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24756 + au_opt_udba(a->sb),
24757 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24759 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24760 + if (unlikely(err)) {
24761 + AU_MVD_PR(dmsg, "pin_src failed\n");
24762 + au_pin_hdir_lock(&a->mvd_pin_dst);
24765 + au_pin_hdir_unlock(&a->mvd_pin_src);
24766 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24767 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24769 + err = (h_trap != a->mvd_h_src_parent);
24771 + err = (h_trap != a->mvd_h_dst_parent);
24773 + BUG_ON(err); /* it should never happen */
24774 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
24777 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24778 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24779 + au_pin_hdir_lock(&a->mvd_pin_src);
24780 + au_unpin(&a->mvd_pin_src);
24781 + au_pin_hdir_lock(&a->mvd_pin_dst);
24784 + goto out; /* success */
24787 + au_unpin(&a->mvd_pin_dst);
24793 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
24795 + if (!a->rename_lock)
24796 + au_unpin(&a->mvd_pin_src);
24798 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24799 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24800 + au_pin_hdir_lock(&a->mvd_pin_src);
24801 + au_unpin(&a->mvd_pin_src);
24802 + au_pin_hdir_lock(&a->mvd_pin_dst);
24804 + au_unpin(&a->mvd_pin_dst);
24807 +/* copy-down the file */
24808 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
24811 + struct au_cp_generic cpg = {
24812 + .dentry = a->dentry,
24813 + .bdst = a->mvd_bdst,
24814 + .bsrc = a->mvd_bsrc,
24816 + .pin = &a->mvd_pin_dst,
24817 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24820 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
24821 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
24822 + au_fset_cpup(cpg.flags, OVERWRITE);
24823 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
24824 + au_fset_cpup(cpg.flags, RWDST);
24825 + err = au_sio_cpdown_simple(&cpg);
24826 + if (unlikely(err))
24827 + AU_MVD_PR(dmsg, "cpdown failed\n");
24834 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
24837 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
24840 + struct path h_path;
24841 + struct au_branch *br;
24842 + struct inode *delegated;
24844 + br = au_sbr(a->sb, a->mvd_bdst);
24845 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
24846 + err = PTR_ERR(h_path.dentry);
24847 + if (IS_ERR(h_path.dentry)) {
24848 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
24853 + if (d_is_positive(h_path.dentry)) {
24854 + h_path.mnt = au_br_mnt(br);
24855 + delegated = NULL;
24856 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
24857 + &delegated, /*force*/0);
24858 + if (unlikely(err == -EWOULDBLOCK)) {
24859 + pr_warn("cannot retry for NFSv4 delegation"
24860 + " for an internal unlink\n");
24863 + if (unlikely(err))
24864 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
24866 + dput(h_path.dentry);
24874 + * unlink the topmost h_dentry
24876 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
24879 + struct path h_path;
24880 + struct inode *delegated;
24882 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
24883 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
24884 + delegated = NULL;
24885 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
24886 + if (unlikely(err == -EWOULDBLOCK)) {
24887 + pr_warn("cannot retry for NFSv4 delegation"
24888 + " for an internal unlink\n");
24891 + if (unlikely(err))
24892 + AU_MVD_PR(dmsg, "unlink failed\n");
24898 +/* Since mvdown succeeded, we ignore an error of this function */
24899 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
24902 + struct au_branch *br;
24904 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
24905 + br = au_sbr(a->sb, a->mvd_bsrc);
24906 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
24908 + br = au_sbr(a->sb, a->mvd_bdst);
24909 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
24910 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
24913 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
24915 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
24919 + * copy-down the file and unlink the bsrc file.
24920 + * - unlink the bdst whout if exist
24921 + * - copy-down the file (with whtmp name and rename)
24922 + * - unlink the bsrc file
24924 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
24928 + err = au_do_mkdir(dmsg, a);
24930 + err = au_do_lock(dmsg, a);
24931 + if (unlikely(err))
24935 + * do not revert the activities we made on bdst since they should be
24936 + * harmless in aufs.
24939 + err = au_do_cpdown(dmsg, a);
24941 + err = au_do_unlink_wh(dmsg, a);
24942 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
24943 + err = au_do_unlink(dmsg, a);
24944 + if (unlikely(err))
24947 + AuDbg("%pd2, 0x%x, %d --> %d\n",
24948 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
24949 + if (find_lower_writable(a) < 0)
24950 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
24952 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
24953 + au_do_stfs(dmsg, a);
24955 + /* maintain internal array */
24956 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
24957 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
24958 + au_set_dbtop(a->dentry, a->mvd_bdst);
24959 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
24960 + au_set_ibtop(a->inode, a->mvd_bdst);
24962 + /* hide the lower */
24963 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
24964 + au_set_dbbot(a->dentry, a->mvd_bsrc);
24965 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
24966 + au_set_ibbot(a->inode, a->mvd_bsrc);
24968 + if (au_dbbot(a->dentry) < a->mvd_bdst)
24969 + au_set_dbbot(a->dentry, a->mvd_bdst);
24970 + if (au_ibbot(a->inode) < a->mvd_bdst)
24971 + au_set_ibbot(a->inode, a->mvd_bdst);
24974 + au_do_unlock(dmsg, a);
24980 +/* ---------------------------------------------------------------------- */
24982 +/* make sure the file is idle */
24983 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
24985 + int err, plinked;
24988 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
24989 + if (au_dbtop(a->dentry) == a->mvd_bsrc
24990 + && au_dcount(a->dentry) == 1
24991 + && atomic_read(&a->inode->i_count) == 1
24992 + /* && a->mvd_h_src_inode->i_nlink == 1 */
24993 + && (!plinked || !au_plink_test(a->inode))
24994 + && a->inode->i_nlink == 1)
24999 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25000 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25001 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25002 + a->mvd_h_src_inode->i_nlink,
25003 + plinked, plinked ? au_plink_test(a->inode) : 0);
25010 +/* make sure the parent dir is fine */
25011 +static int au_mvd_args_parent(const unsigned char dmsg,
25012 + struct au_mvd_args *a)
25015 + aufs_bindex_t bindex;
25018 + if (unlikely(au_alive_dir(a->parent))) {
25020 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25024 + a->bopq = au_dbdiropq(a->parent);
25025 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25026 + AuDbg("b%d\n", bindex);
25027 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25028 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25030 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25031 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25032 + a->bopq, a->mvd_bdst);
25040 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25041 + struct au_mvd_args *a)
25044 + struct au_dinfo *dinfo, *tmp;
25046 + /* lookup the next lower positive entry */
25048 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25049 + if (unlikely(!tmp))
25054 + dinfo = au_di(a->dentry);
25055 + au_di_cp(tmp, dinfo);
25056 + au_di_swap(tmp, dinfo);
25058 + /* returns the number of positive dentries */
25059 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25060 + /* AuLkup_IGNORE_PERM */ 0);
25062 + a->bwh = au_dbwh(a->dentry);
25063 + else if (err > 0)
25064 + a->bfound = au_dbtop(a->dentry);
25066 + au_di_swap(tmp, dinfo);
25067 + au_rw_write_unlock(&tmp->di_rwsem);
25069 + if (unlikely(err < 0))
25070 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25073 + * here, we have these cases.
25075 + * no positive dentry under bsrc. there are more sub-cases.
25077 + * there no whiteout, we can safely move-down.
25080 + * bsrc < bwh && bwh < bdst
25081 + * there is a whiteout on RO branch. cannot proceed.
25083 + * there is a whiteout on the RW target branch. it should
25086 + * there is a whiteout somewhere unrelated branch.
25087 + * -1 < bfound && bfound <= bsrc
25090 + * found, but it is on RO branch between bsrc and bdst. cannot
25093 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25096 + * found, after we create the file on bdst, it will be hidden.
25099 + AuDebugOn(a->bfound == -1
25101 + && a->bwh <= a->mvd_bsrc);
25102 + AuDebugOn(-1 < a->bfound
25103 + && a->bfound <= a->mvd_bsrc);
25106 + if (a->bfound == -1
25107 + && a->mvd_bsrc < a->bwh
25109 + && a->bwh < a->mvd_bdst) {
25110 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25111 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25112 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25114 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25115 + a->mvd_errno = EAU_MVDOWN_UPPER;
25116 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25117 + a->mvd_bdst, a->bfound);
25121 + err = 0; /* success */
25128 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25133 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25134 + && a->bfound == a->mvd_bdst)
25140 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25143 + struct au_branch *br;
25146 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25150 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25151 + a->mvd_bsrc = au_ibtop(a->inode);
25153 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25154 + if (unlikely(a->mvd_bsrc < 0
25155 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25156 + || au_dbbot(a->dentry) < a->mvd_bsrc
25157 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25158 + || (a->mvd_bsrc < au_ibtop(a->inode)
25159 + || au_ibbot(a->inode) < a->mvd_bsrc
25160 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25161 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25162 + AU_MVD_PR(dmsg, "no upper\n");
25166 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25167 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25168 + AU_MVD_PR(dmsg, "on the bottom\n");
25171 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25172 + br = au_sbr(a->sb, a->mvd_bsrc);
25173 + err = au_br_rdonly(br);
25174 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25175 + if (unlikely(err))
25177 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25178 + || IS_APPEND(a->mvd_h_src_inode))) {
25180 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25186 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25187 + a->mvd_bdst = find_lower_writable(a);
25188 + if (unlikely(a->mvd_bdst < 0)) {
25189 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25190 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25194 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25195 + if (unlikely(a->mvd_bdst < 0
25196 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25197 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25198 + AU_MVD_PR(dmsg, "no lower brid\n");
25203 + err = au_mvd_args_busy(dmsg, a);
25205 + err = au_mvd_args_parent(dmsg, a);
25207 + err = au_mvd_args_intermediate(dmsg, a);
25209 + err = au_mvd_args_exist(dmsg, a);
25211 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25218 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25221 + unsigned char dmsg;
25222 + struct au_mvd_args *args;
25223 + struct inode *inode;
25225 + inode = d_inode(dentry);
25227 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25231 + args = kmalloc(sizeof(*args), GFP_NOFS);
25232 + if (unlikely(!args))
25235 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25237 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25238 + if (unlikely(err)) {
25243 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25244 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25245 + args->mvdown.au_errno = 0;
25246 + args->dentry = dentry;
25247 + args->inode = inode;
25248 + args->sb = dentry->d_sb;
25251 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25252 + args->parent = dget_parent(dentry);
25253 + args->dir = d_inode(args->parent);
25254 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25255 + dput(args->parent);
25256 + if (unlikely(args->parent != dentry->d_parent)) {
25257 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25261 + inode_lock_nested(inode, I_MUTEX_CHILD);
25262 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25263 + if (unlikely(err))
25266 + di_write_lock_parent(args->parent);
25267 + err = au_mvd_args(dmsg, args);
25268 + if (unlikely(err))
25271 + err = au_do_mvdown(dmsg, args);
25272 + if (unlikely(err))
25275 + au_cpup_attr_timesizes(args->dir);
25276 + au_cpup_attr_timesizes(inode);
25277 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25278 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25279 + /* au_digen_dec(dentry); */
25282 + di_write_unlock(args->parent);
25283 + aufs_read_unlock(dentry, AuLock_DW);
25285 + inode_unlock(inode);
25287 + inode_unlock(args->dir);
25289 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25297 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25298 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25299 +++ linux/fs/aufs/opts.c 2017-11-12 22:24:44.707577830 +0100
25302 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25304 + * This program, aufs is free software; you can redistribute it and/or modify
25305 + * it under the terms of the GNU General Public License as published by
25306 + * the Free Software Foundation; either version 2 of the License, or
25307 + * (at your option) any later version.
25309 + * This program is distributed in the hope that it will be useful,
25310 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25311 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25312 + * GNU General Public License for more details.
25314 + * You should have received a copy of the GNU General Public License
25315 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25319 + * mount options/flags
25322 +#include <linux/namei.h>
25323 +#include <linux/types.h> /* a distribution requires */
25324 +#include <linux/parser.h>
25327 +/* ---------------------------------------------------------------------- */
25331 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25332 + Opt_idel, Opt_imod,
25333 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25334 + Opt_rdblk_def, Opt_rdhash_def,
25335 + Opt_xino, Opt_noxino,
25336 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25337 + Opt_trunc_xino_path, Opt_itrunc_xino,
25338 + Opt_trunc_xib, Opt_notrunc_xib,
25339 + Opt_shwh, Opt_noshwh,
25340 + Opt_plink, Opt_noplink, Opt_list_plink,
25342 + Opt_dio, Opt_nodio,
25343 + Opt_diropq_a, Opt_diropq_w,
25344 + Opt_warn_perm, Opt_nowarn_perm,
25345 + Opt_wbr_copyup, Opt_wbr_create,
25347 + Opt_verbose, Opt_noverbose,
25348 + Opt_sum, Opt_nosum, Opt_wsum,
25349 + Opt_dirperm1, Opt_nodirperm1,
25350 + Opt_dirren, Opt_nodirren,
25351 + Opt_acl, Opt_noacl,
25352 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25355 +static match_table_t options = {
25356 + {Opt_br, "br=%s"},
25357 + {Opt_br, "br:%s"},
25359 + {Opt_add, "add=%d:%s"},
25360 + {Opt_add, "add:%d:%s"},
25361 + {Opt_add, "ins=%d:%s"},
25362 + {Opt_add, "ins:%d:%s"},
25363 + {Opt_append, "append=%s"},
25364 + {Opt_append, "append:%s"},
25365 + {Opt_prepend, "prepend=%s"},
25366 + {Opt_prepend, "prepend:%s"},
25368 + {Opt_del, "del=%s"},
25369 + {Opt_del, "del:%s"},
25370 + /* {Opt_idel, "idel:%d"}, */
25371 + {Opt_mod, "mod=%s"},
25372 + {Opt_mod, "mod:%s"},
25373 + /* {Opt_imod, "imod:%d:%s"}, */
25375 + {Opt_dirwh, "dirwh=%d"},
25377 + {Opt_xino, "xino=%s"},
25378 + {Opt_noxino, "noxino"},
25379 + {Opt_trunc_xino, "trunc_xino"},
25380 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25381 + {Opt_notrunc_xino, "notrunc_xino"},
25382 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25383 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25384 + /* {Opt_zxino, "zxino=%s"}, */
25385 + {Opt_trunc_xib, "trunc_xib"},
25386 + {Opt_notrunc_xib, "notrunc_xib"},
25388 +#ifdef CONFIG_PROC_FS
25389 + {Opt_plink, "plink"},
25391 + {Opt_ignore_silent, "plink"},
25394 + {Opt_noplink, "noplink"},
25396 +#ifdef CONFIG_AUFS_DEBUG
25397 + {Opt_list_plink, "list_plink"},
25400 + {Opt_udba, "udba=%s"},
25402 + {Opt_dio, "dio"},
25403 + {Opt_nodio, "nodio"},
25405 +#ifdef CONFIG_AUFS_DIRREN
25406 + {Opt_dirren, "dirren"},
25407 + {Opt_nodirren, "nodirren"},
25409 + {Opt_ignore, "dirren"},
25410 + {Opt_ignore_silent, "nodirren"},
25413 +#ifdef CONFIG_AUFS_FHSM
25414 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25416 + {Opt_ignore, "fhsm_sec=%d"},
25419 + {Opt_diropq_a, "diropq=always"},
25420 + {Opt_diropq_a, "diropq=a"},
25421 + {Opt_diropq_w, "diropq=whiteouted"},
25422 + {Opt_diropq_w, "diropq=w"},
25424 + {Opt_warn_perm, "warn_perm"},
25425 + {Opt_nowarn_perm, "nowarn_perm"},
25427 + /* keep them temporary */
25428 + {Opt_ignore_silent, "nodlgt"},
25429 + {Opt_ignore, "clean_plink"},
25431 +#ifdef CONFIG_AUFS_SHWH
25432 + {Opt_shwh, "shwh"},
25434 + {Opt_noshwh, "noshwh"},
25436 + {Opt_dirperm1, "dirperm1"},
25437 + {Opt_nodirperm1, "nodirperm1"},
25439 + {Opt_verbose, "verbose"},
25440 + {Opt_verbose, "v"},
25441 + {Opt_noverbose, "noverbose"},
25442 + {Opt_noverbose, "quiet"},
25443 + {Opt_noverbose, "q"},
25444 + {Opt_noverbose, "silent"},
25446 + {Opt_sum, "sum"},
25447 + {Opt_nosum, "nosum"},
25448 + {Opt_wsum, "wsum"},
25450 + {Opt_rdcache, "rdcache=%d"},
25451 + {Opt_rdblk, "rdblk=%d"},
25452 + {Opt_rdblk_def, "rdblk=def"},
25453 + {Opt_rdhash, "rdhash=%d"},
25454 + {Opt_rdhash_def, "rdhash=def"},
25456 + {Opt_wbr_create, "create=%s"},
25457 + {Opt_wbr_create, "create_policy=%s"},
25458 + {Opt_wbr_copyup, "cpup=%s"},
25459 + {Opt_wbr_copyup, "copyup=%s"},
25460 + {Opt_wbr_copyup, "copyup_policy=%s"},
25462 + /* generic VFS flag */
25463 +#ifdef CONFIG_FS_POSIX_ACL
25464 + {Opt_acl, "acl"},
25465 + {Opt_noacl, "noacl"},
25467 + {Opt_ignore, "acl"},
25468 + {Opt_ignore_silent, "noacl"},
25471 + /* internal use for the scripts */
25472 + {Opt_ignore_silent, "si=%s"},
25474 + {Opt_br, "dirs=%s"},
25475 + {Opt_ignore, "debug=%d"},
25476 + {Opt_ignore, "delete=whiteout"},
25477 + {Opt_ignore, "delete=all"},
25478 + {Opt_ignore, "imap=%s"},
25480 + /* temporary workaround, due to old mount(8)? */
25481 + {Opt_ignore_silent, "relatime"},
25486 +/* ---------------------------------------------------------------------- */
25488 +static const char *au_parser_pattern(int val, match_table_t tbl)
25490 + struct match_token *p;
25493 + while (p->pattern) {
25494 + if (p->token == val)
25495 + return p->pattern;
25502 +static const char *au_optstr(int *val, match_table_t tbl)
25504 + struct match_token *p;
25511 + while (p->pattern) {
25513 + && (v & p->token) == p->token) {
25514 + *val &= ~p->token;
25515 + return p->pattern;
25524 +/* ---------------------------------------------------------------------- */
25526 +static match_table_t brperm = {
25527 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25528 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25529 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25533 +static match_table_t brattr = {
25535 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25536 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25537 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25538 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25539 +#ifdef CONFIG_AUFS_FHSM
25540 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25542 +#ifdef CONFIG_AUFS_XATTR
25543 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25544 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25545 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25546 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25547 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25548 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25551 + /* ro/rr branch */
25552 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25555 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25556 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25561 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25568 + p = strchr(str, '+');
25571 + v = match_token(str, table, args);
25573 + if (v & AuBrAttr_CMOO_Mask)
25574 + attr &= ~AuBrAttr_CMOO_Mask;
25579 + pr_warn("ignored branch attribute %s\n", str);
25589 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25597 + p = au_optstr(&perm, brattr);
25600 + memcpy(q, p, sz + 1);
25606 + p = au_optstr(&perm, brattr);
25610 + memcpy(q, p, sz + 1);
25616 + return q - str->a;
25619 +static int noinline_for_stack br_perm_val(char *perm)
25621 + int val, bad, sz;
25623 + substring_t args[MAX_OPT_ARGS];
25624 + au_br_perm_str_t attr;
25626 + p = strchr(perm, '+');
25629 + val = match_token(perm, brperm, args);
25633 + pr_warn("ignored branch permission %s\n", perm);
25634 + val = AuBrPerm_RO;
25640 + val |= br_attr_val(p + 1, brattr, args);
25643 + switch (val & AuBrPerm_Mask) {
25644 + case AuBrPerm_RO:
25645 + case AuBrPerm_RR:
25646 + bad = val & AuBrWAttr_Mask;
25647 + val &= ~AuBrWAttr_Mask;
25649 + case AuBrPerm_RW:
25650 + bad = val & AuBrRAttr_Mask;
25651 + val &= ~AuBrRAttr_Mask;
25656 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25657 + * does not treat it as an error, just warning.
25658 + * this is a tiny guard for the user operation.
25660 + if (val & AuBrAttr_UNPIN) {
25661 + bad |= AuBrAttr_UNPIN;
25662 + val &= ~AuBrAttr_UNPIN;
25665 + if (unlikely(bad)) {
25666 + sz = au_do_optstr_br_attr(&attr, bad);
25668 + pr_warn("ignored branch attribute %s\n", attr.a);
25675 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25677 + au_br_perm_str_t attr;
25683 + p = au_optstr(&perm, brperm);
25684 + AuDebugOn(!p || !*p);
25686 + memcpy(q, p, sz + 1);
25689 + sz = au_do_optstr_br_attr(&attr, perm);
25692 + memcpy(q, attr.a, sz + 1);
25695 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25698 +/* ---------------------------------------------------------------------- */
25700 +static match_table_t udbalevel = {
25701 + {AuOpt_UDBA_REVAL, "reval"},
25702 + {AuOpt_UDBA_NONE, "none"},
25703 +#ifdef CONFIG_AUFS_HNOTIFY
25704 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25705 +#ifdef CONFIG_AUFS_HFSNOTIFY
25706 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25712 +static int noinline_for_stack udba_val(char *str)
25714 + substring_t args[MAX_OPT_ARGS];
25716 + return match_token(str, udbalevel, args);
25719 +const char *au_optstr_udba(int udba)
25721 + return au_parser_pattern(udba, udbalevel);
25724 +/* ---------------------------------------------------------------------- */
25726 +static match_table_t au_wbr_create_policy = {
25727 + {AuWbrCreate_TDP, "tdp"},
25728 + {AuWbrCreate_TDP, "top-down-parent"},
25729 + {AuWbrCreate_RR, "rr"},
25730 + {AuWbrCreate_RR, "round-robin"},
25731 + {AuWbrCreate_MFS, "mfs"},
25732 + {AuWbrCreate_MFS, "most-free-space"},
25733 + {AuWbrCreate_MFSV, "mfs:%d"},
25734 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25736 + /* top-down regardless the parent, and then mfs */
25737 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25738 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25740 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25741 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25742 + {AuWbrCreate_PMFS, "pmfs"},
25743 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25744 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25745 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
25750 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
25751 + struct au_opt_wbr_create *create)
25754 + unsigned long long ull;
25757 + if (!match_u64(arg, &ull))
25758 + create->mfsrr_watermark = ull;
25760 + pr_err("bad integer in %s\n", str);
25767 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
25768 + struct au_opt_wbr_create *create)
25773 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
25774 + create->mfs_second = n;
25776 + pr_err("bad integer in %s\n", str);
25783 +static int noinline_for_stack
25784 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
25787 + substring_t args[MAX_OPT_ARGS];
25789 + err = match_token(str, au_wbr_create_policy, args);
25790 + create->wbr_create = err;
25792 + case AuWbrCreate_MFSRRV:
25793 + case AuWbrCreate_TDMFSV:
25794 + case AuWbrCreate_PMFSRRV:
25795 + e = au_wbr_mfs_wmark(&args[0], str, create);
25797 + e = au_wbr_mfs_sec(&args[1], str, create);
25801 + case AuWbrCreate_MFSRR:
25802 + case AuWbrCreate_TDMFS:
25803 + case AuWbrCreate_PMFSRR:
25804 + e = au_wbr_mfs_wmark(&args[0], str, create);
25805 + if (unlikely(e)) {
25810 + case AuWbrCreate_MFS:
25811 + case AuWbrCreate_PMFS:
25812 + create->mfs_second = AUFS_MFS_DEF_SEC;
25814 + case AuWbrCreate_MFSV:
25815 + case AuWbrCreate_PMFSV:
25816 + e = au_wbr_mfs_sec(&args[0], str, create);
25825 +const char *au_optstr_wbr_create(int wbr_create)
25827 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
25830 +static match_table_t au_wbr_copyup_policy = {
25831 + {AuWbrCopyup_TDP, "tdp"},
25832 + {AuWbrCopyup_TDP, "top-down-parent"},
25833 + {AuWbrCopyup_BUP, "bup"},
25834 + {AuWbrCopyup_BUP, "bottom-up-parent"},
25835 + {AuWbrCopyup_BU, "bu"},
25836 + {AuWbrCopyup_BU, "bottom-up"},
25840 +static int noinline_for_stack au_wbr_copyup_val(char *str)
25842 + substring_t args[MAX_OPT_ARGS];
25844 + return match_token(str, au_wbr_copyup_policy, args);
25847 +const char *au_optstr_wbr_copyup(int wbr_copyup)
25849 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
25852 +/* ---------------------------------------------------------------------- */
25854 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
25856 +static void dump_opts(struct au_opts *opts)
25858 +#ifdef CONFIG_AUFS_DEBUG
25859 + /* reduce stack space */
25861 + struct au_opt_add *add;
25862 + struct au_opt_del *del;
25863 + struct au_opt_mod *mod;
25864 + struct au_opt_xino *xino;
25865 + struct au_opt_xino_itrunc *xino_itrunc;
25866 + struct au_opt_wbr_create *create;
25868 + struct au_opt *opt;
25871 + while (opt->type != Opt_tail) {
25872 + switch (opt->type) {
25874 + u.add = &opt->add;
25875 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
25876 + u.add->bindex, u.add->pathname, u.add->perm,
25877 + u.add->path.dentry);
25881 + u.del = &opt->del;
25882 + AuDbg("del {%s, %p}\n",
25883 + u.del->pathname, u.del->h_path.dentry);
25887 + u.mod = &opt->mod;
25888 + AuDbg("mod {%s, 0x%x, %p}\n",
25889 + u.mod->path, u.mod->perm, u.mod->h_root);
25892 + u.add = &opt->add;
25893 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
25894 + u.add->bindex, u.add->pathname, u.add->perm,
25895 + u.add->path.dentry);
25897 + case Opt_prepend:
25898 + u.add = &opt->add;
25899 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
25900 + u.add->bindex, u.add->pathname, u.add->perm,
25901 + u.add->path.dentry);
25904 + AuDbg("dirwh %d\n", opt->dirwh);
25906 + case Opt_rdcache:
25907 + AuDbg("rdcache %d\n", opt->rdcache);
25910 + AuDbg("rdblk %u\n", opt->rdblk);
25912 + case Opt_rdblk_def:
25913 + AuDbg("rdblk_def\n");
25916 + AuDbg("rdhash %u\n", opt->rdhash);
25918 + case Opt_rdhash_def:
25919 + AuDbg("rdhash_def\n");
25922 + u.xino = &opt->xino;
25923 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
25925 + case Opt_trunc_xino:
25926 + AuLabel(trunc_xino);
25928 + case Opt_notrunc_xino:
25929 + AuLabel(notrunc_xino);
25931 + case Opt_trunc_xino_path:
25932 + case Opt_itrunc_xino:
25933 + u.xino_itrunc = &opt->xino_itrunc;
25934 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
25939 + case Opt_trunc_xib:
25940 + AuLabel(trunc_xib);
25942 + case Opt_notrunc_xib:
25943 + AuLabel(notrunc_xib);
25951 + case Opt_dirperm1:
25952 + AuLabel(dirperm1);
25954 + case Opt_nodirperm1:
25955 + AuLabel(nodirperm1);
25960 + case Opt_noplink:
25961 + AuLabel(noplink);
25963 + case Opt_list_plink:
25964 + AuLabel(list_plink);
25967 + AuDbg("udba %d, %s\n",
25968 + opt->udba, au_optstr_udba(opt->udba));
25976 + case Opt_diropq_a:
25977 + AuLabel(diropq_a);
25979 + case Opt_diropq_w:
25980 + AuLabel(diropq_w);
25982 + case Opt_warn_perm:
25983 + AuLabel(warn_perm);
25985 + case Opt_nowarn_perm:
25986 + AuLabel(nowarn_perm);
25988 + case Opt_verbose:
25989 + AuLabel(verbose);
25991 + case Opt_noverbose:
25992 + AuLabel(noverbose);
26003 + case Opt_wbr_create:
26004 + u.create = &opt->wbr_create;
26005 + AuDbg("create %d, %s\n", u.create->wbr_create,
26006 + au_optstr_wbr_create(u.create->wbr_create));
26007 + switch (u.create->wbr_create) {
26008 + case AuWbrCreate_MFSV:
26009 + case AuWbrCreate_PMFSV:
26010 + AuDbg("%d sec\n", u.create->mfs_second);
26012 + case AuWbrCreate_MFSRR:
26013 + case AuWbrCreate_TDMFS:
26014 + AuDbg("%llu watermark\n",
26015 + u.create->mfsrr_watermark);
26017 + case AuWbrCreate_MFSRRV:
26018 + case AuWbrCreate_TDMFSV:
26019 + case AuWbrCreate_PMFSRRV:
26020 + AuDbg("%llu watermark, %d sec\n",
26021 + u.create->mfsrr_watermark,
26022 + u.create->mfs_second);
26026 + case Opt_wbr_copyup:
26027 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26028 + au_optstr_wbr_copyup(opt->wbr_copyup));
26030 + case Opt_fhsm_sec:
26031 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26036 + case Opt_nodirren:
26037 + AuLabel(nodirren);
26053 +void au_opts_free(struct au_opts *opts)
26055 + struct au_opt *opt;
26058 + while (opt->type != Opt_tail) {
26059 + switch (opt->type) {
26062 + case Opt_prepend:
26063 + path_put(&opt->add.path);
26067 + path_put(&opt->del.h_path);
26071 + dput(opt->mod.h_root);
26074 + fput(opt->xino.file);
26081 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26082 + aufs_bindex_t bindex)
26085 + struct au_opt_add *add = &opt->add;
26088 + add->bindex = bindex;
26089 + add->perm = AuBrPerm_RO;
26090 + add->pathname = opt_str;
26091 + p = strchr(opt_str, '=');
26095 + add->perm = br_perm_val(p);
26098 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26101 + add->perm = AuBrPerm_RO;
26102 + if (au_test_fs_rr(add->path.dentry->d_sb))
26103 + add->perm = AuBrPerm_RR;
26104 + else if (!bindex && !(sb_flags & MS_RDONLY))
26105 + add->perm = AuBrPerm_RW;
26107 + opt->type = Opt_add;
26110 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26117 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26121 + del->pathname = args[0].from;
26122 + AuDbg("del path %s\n", del->pathname);
26124 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26125 + if (unlikely(err))
26126 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26131 +#if 0 /* reserved for future use */
26132 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26133 + struct au_opt_del *del, substring_t args[])
26136 + struct dentry *root;
26139 + root = sb->s_root;
26140 + aufs_read_lock(root, AuLock_FLUSH);
26141 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26142 + pr_err("out of bounds, %d\n", bindex);
26147 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26148 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26151 + aufs_read_unlock(root, !AuLock_IR);
26156 +static int noinline_for_stack
26157 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26160 + struct path path;
26164 + mod->path = args[0].from;
26165 + p = strchr(mod->path, '=');
26166 + if (unlikely(!p)) {
26167 + pr_err("no permssion %s\n", args[0].from);
26172 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26173 + if (unlikely(err)) {
26174 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26178 + mod->perm = br_perm_val(p);
26179 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26180 + mod->h_root = dget(path.dentry);
26187 +#if 0 /* reserved for future use */
26188 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26189 + struct au_opt_mod *mod, substring_t args[])
26192 + struct dentry *root;
26195 + root = sb->s_root;
26196 + aufs_read_lock(root, AuLock_FLUSH);
26197 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26198 + pr_err("out of bounds, %d\n", bindex);
26203 + mod->perm = br_perm_val(args[1].from);
26204 + AuDbg("mod path %s, perm 0x%x, %s\n",
26205 + mod->path, mod->perm, args[1].from);
26206 + mod->h_root = dget(au_h_dptr(root, bindex));
26209 + aufs_read_unlock(root, !AuLock_IR);
26214 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26215 + substring_t args[])
26218 + struct file *file;
26220 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26221 + err = PTR_ERR(file);
26222 + if (IS_ERR(file))
26226 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26228 + pr_err("%s must be outside\n", args[0].from);
26233 + xino->file = file;
26234 + xino->path = args[0].from;
26240 +static int noinline_for_stack
26241 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26242 + struct au_opt_xino_itrunc *xino_itrunc,
26243 + substring_t args[])
26246 + aufs_bindex_t bbot, bindex;
26247 + struct path path;
26248 + struct dentry *root;
26250 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26251 + if (unlikely(err)) {
26252 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26256 + xino_itrunc->bindex = -1;
26257 + root = sb->s_root;
26258 + aufs_read_lock(root, AuLock_FLUSH);
26259 + bbot = au_sbbot(sb);
26260 + for (bindex = 0; bindex <= bbot; bindex++) {
26261 + if (au_h_dptr(root, bindex) == path.dentry) {
26262 + xino_itrunc->bindex = bindex;
26266 + aufs_read_unlock(root, !AuLock_IR);
26269 + if (unlikely(xino_itrunc->bindex < 0)) {
26270 + pr_err("no such branch %s\n", args[0].from);
26278 +/* called without aufs lock */
26279 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26281 + int err, n, token;
26282 + aufs_bindex_t bindex;
26283 + unsigned char skipped;
26284 + struct dentry *root;
26285 + struct au_opt *opt, *opt_tail;
26287 + /* reduce the stack space */
26289 + struct au_opt_xino_itrunc *xino_itrunc;
26290 + struct au_opt_wbr_create *create;
26293 + substring_t args[MAX_OPT_ARGS];
26297 + a = kmalloc(sizeof(*a), GFP_NOFS);
26298 + if (unlikely(!a))
26301 + root = sb->s_root;
26305 + opt_tail = opt + opts->max_opt - 1;
26306 + opt->type = Opt_tail;
26307 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26310 + token = match_token(opt_str, options, a->args);
26314 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26316 + err = opt_add(opt, opt_str, opts->sb_flags,
26318 + if (unlikely(!err && ++opt > opt_tail)) {
26322 + opt->type = Opt_tail;
26327 + if (unlikely(match_int(&a->args[0], &n))) {
26328 + pr_err("bad integer in %s\n", opt_str);
26332 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26335 + opt->type = token;
26338 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26339 + /*dummy bindex*/1);
26341 + opt->type = token;
26343 + case Opt_prepend:
26344 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26347 + opt->type = token;
26350 + err = au_opts_parse_del(&opt->del, a->args);
26352 + opt->type = token;
26354 +#if 0 /* reserved for future use */
26356 + del->pathname = "(indexed)";
26357 + if (unlikely(match_int(&args[0], &n))) {
26358 + pr_err("bad integer in %s\n", opt_str);
26361 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26363 + opt->type = token;
26367 + err = au_opts_parse_mod(&opt->mod, a->args);
26369 + opt->type = token;
26371 +#ifdef IMOD /* reserved for future use */
26373 + u.mod->path = "(indexed)";
26374 + if (unlikely(match_int(&a->args[0], &n))) {
26375 + pr_err("bad integer in %s\n", opt_str);
26378 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26380 + opt->type = token;
26384 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26386 + opt->type = token;
26389 + case Opt_trunc_xino_path:
26390 + err = au_opts_parse_xino_itrunc_path
26391 + (sb, &opt->xino_itrunc, a->args);
26393 + opt->type = token;
26396 + case Opt_itrunc_xino:
26397 + u.xino_itrunc = &opt->xino_itrunc;
26398 + if (unlikely(match_int(&a->args[0], &n))) {
26399 + pr_err("bad integer in %s\n", opt_str);
26402 + u.xino_itrunc->bindex = n;
26403 + aufs_read_lock(root, AuLock_FLUSH);
26404 + if (n < 0 || au_sbbot(sb) < n) {
26405 + pr_err("out of bounds, %d\n", n);
26406 + aufs_read_unlock(root, !AuLock_IR);
26409 + aufs_read_unlock(root, !AuLock_IR);
26411 + opt->type = token;
26415 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26418 + opt->type = token;
26421 + case Opt_rdcache:
26422 + if (unlikely(match_int(&a->args[0], &n))) {
26423 + pr_err("bad integer in %s\n", opt_str);
26426 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26427 + pr_err("rdcache must be smaller than %d\n",
26428 + AUFS_RDCACHE_MAX);
26431 + opt->rdcache = n;
26433 + opt->type = token;
26436 + if (unlikely(match_int(&a->args[0], &n)
26438 + || n > KMALLOC_MAX_SIZE)) {
26439 + pr_err("bad integer in %s\n", opt_str);
26442 + if (unlikely(n && n < NAME_MAX)) {
26443 + pr_err("rdblk must be larger than %d\n",
26449 + opt->type = token;
26452 + if (unlikely(match_int(&a->args[0], &n)
26454 + || n * sizeof(struct hlist_head)
26455 + > KMALLOC_MAX_SIZE)) {
26456 + pr_err("bad integer in %s\n", opt_str);
26461 + opt->type = token;
26464 + case Opt_trunc_xino:
26465 + case Opt_notrunc_xino:
26467 + case Opt_trunc_xib:
26468 + case Opt_notrunc_xib:
26471 + case Opt_dirperm1:
26472 + case Opt_nodirperm1:
26474 + case Opt_noplink:
26475 + case Opt_list_plink:
26478 + case Opt_diropq_a:
26479 + case Opt_diropq_w:
26480 + case Opt_warn_perm:
26481 + case Opt_nowarn_perm:
26482 + case Opt_verbose:
26483 + case Opt_noverbose:
26487 + case Opt_rdblk_def:
26488 + case Opt_rdhash_def:
26490 + case Opt_nodirren:
26494 + opt->type = token;
26498 + opt->udba = udba_val(a->args[0].from);
26499 + if (opt->udba >= 0) {
26501 + opt->type = token;
26503 + pr_err("wrong value, %s\n", opt_str);
26506 + case Opt_wbr_create:
26507 + u.create = &opt->wbr_create;
26508 + u.create->wbr_create
26509 + = au_wbr_create_val(a->args[0].from, u.create);
26510 + if (u.create->wbr_create >= 0) {
26512 + opt->type = token;
26514 + pr_err("wrong value, %s\n", opt_str);
26516 + case Opt_wbr_copyup:
26517 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26518 + if (opt->wbr_copyup >= 0) {
26520 + opt->type = token;
26522 + pr_err("wrong value, %s\n", opt_str);
26525 + case Opt_fhsm_sec:
26526 + if (unlikely(match_int(&a->args[0], &n)
26528 + pr_err("bad integer in %s\n", opt_str);
26531 + if (sysaufs_brs) {
26532 + opt->fhsm_second = n;
26533 + opt->type = token;
26535 + pr_warn("ignored %s\n", opt_str);
26540 + pr_warn("ignored %s\n", opt_str);
26542 + case Opt_ignore_silent:
26547 + pr_err("unknown option %s\n", opt_str);
26551 + if (!err && !skipped) {
26552 + if (unlikely(++opt > opt_tail)) {
26555 + opt->type = Opt_tail;
26558 + opt->type = Opt_tail;
26564 + if (unlikely(err))
26565 + au_opts_free(opts);
26571 +static int au_opt_wbr_create(struct super_block *sb,
26572 + struct au_opt_wbr_create *create)
26575 + struct au_sbinfo *sbinfo;
26577 + SiMustWriteLock(sb);
26579 + err = 1; /* handled */
26580 + sbinfo = au_sbi(sb);
26581 + if (sbinfo->si_wbr_create_ops->fin) {
26582 + err = sbinfo->si_wbr_create_ops->fin(sb);
26587 + sbinfo->si_wbr_create = create->wbr_create;
26588 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26589 + switch (create->wbr_create) {
26590 + case AuWbrCreate_MFSRRV:
26591 + case AuWbrCreate_MFSRR:
26592 + case AuWbrCreate_TDMFS:
26593 + case AuWbrCreate_TDMFSV:
26594 + case AuWbrCreate_PMFSRR:
26595 + case AuWbrCreate_PMFSRRV:
26596 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26598 + case AuWbrCreate_MFS:
26599 + case AuWbrCreate_MFSV:
26600 + case AuWbrCreate_PMFS:
26601 + case AuWbrCreate_PMFSV:
26602 + sbinfo->si_wbr_mfs.mfs_expire
26603 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26607 + if (sbinfo->si_wbr_create_ops->init)
26608 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26615 + * plus: processed without an error
26616 + * zero: unprocessed
26618 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26619 + struct au_opts *opts)
26622 + struct au_sbinfo *sbinfo;
26624 + SiMustWriteLock(sb);
26626 + err = 1; /* handled */
26627 + sbinfo = au_sbi(sb);
26628 + switch (opt->type) {
26630 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26631 + sbinfo->si_mntflags |= opt->udba;
26632 + opts->given_udba |= opt->udba;
26636 + au_opt_set(sbinfo->si_mntflags, PLINK);
26638 + case Opt_noplink:
26639 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26640 + au_plink_put(sb, /*verbose*/1);
26641 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26643 + case Opt_list_plink:
26644 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26645 + au_plink_list(sb);
26649 + au_opt_set(sbinfo->si_mntflags, DIO);
26650 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26653 + au_opt_clr(sbinfo->si_mntflags, DIO);
26654 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26657 + case Opt_fhsm_sec:
26658 + au_fhsm_set(sbinfo, opt->fhsm_second);
26661 + case Opt_diropq_a:
26662 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26664 + case Opt_diropq_w:
26665 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26668 + case Opt_warn_perm:
26669 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26671 + case Opt_nowarn_perm:
26672 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26675 + case Opt_verbose:
26676 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26678 + case Opt_noverbose:
26679 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26683 + au_opt_set(sbinfo->si_mntflags, SUM);
26686 + au_opt_clr(sbinfo->si_mntflags, SUM);
26687 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26689 + au_opt_clr(sbinfo->si_mntflags, SUM);
26690 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26693 + case Opt_wbr_create:
26694 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26696 + case Opt_wbr_copyup:
26697 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26698 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26702 + sbinfo->si_dirwh = opt->dirwh;
26705 + case Opt_rdcache:
26706 + sbinfo->si_rdcache
26707 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26710 + sbinfo->si_rdblk = opt->rdblk;
26712 + case Opt_rdblk_def:
26713 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26716 + sbinfo->si_rdhash = opt->rdhash;
26718 + case Opt_rdhash_def:
26719 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26723 + au_opt_set(sbinfo->si_mntflags, SHWH);
26726 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26729 + case Opt_dirperm1:
26730 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26732 + case Opt_nodirperm1:
26733 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26736 + case Opt_trunc_xino:
26737 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26739 + case Opt_notrunc_xino:
26740 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26743 + case Opt_trunc_xino_path:
26744 + case Opt_itrunc_xino:
26745 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
26750 + case Opt_trunc_xib:
26751 + au_fset_opts(opts->flags, TRUNC_XIB);
26753 + case Opt_notrunc_xib:
26754 + au_fclr_opts(opts->flags, TRUNC_XIB);
26759 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26760 + err = au_dr_opt_set(sb);
26765 + au_opt_set(sbinfo->si_mntflags, DIRREN);
26767 + case Opt_nodirren:
26769 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26770 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
26776 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
26780 + sb->s_flags |= MS_POSIXACL;
26783 + sb->s_flags &= ~MS_POSIXACL;
26795 + * returns tri-state.
26796 + * plus: processed without an error
26797 + * zero: unprocessed
26800 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
26801 + struct au_opts *opts)
26803 + int err, do_refresh;
26806 + switch (opt->type) {
26808 + opt->add.bindex = au_sbbot(sb) + 1;
26809 + if (opt->add.bindex < 0)
26810 + opt->add.bindex = 0;
26812 + case Opt_prepend:
26813 + opt->add.bindex = 0;
26814 + add: /* indented label */
26816 + err = au_br_add(sb, &opt->add,
26817 + au_ftest_opts(opts->flags, REMOUNT));
26820 + au_fset_opts(opts->flags, REFRESH);
26826 + err = au_br_del(sb, &opt->del,
26827 + au_ftest_opts(opts->flags, REMOUNT));
26830 + au_fset_opts(opts->flags, TRUNC_XIB);
26831 + au_fset_opts(opts->flags, REFRESH);
26837 + err = au_br_mod(sb, &opt->mod,
26838 + au_ftest_opts(opts->flags, REMOUNT),
26843 + au_fset_opts(opts->flags, REFRESH);
26850 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
26851 + struct au_opt_xino **opt_xino,
26852 + struct au_opts *opts)
26855 + aufs_bindex_t bbot, bindex;
26856 + struct dentry *root, *parent, *h_root;
26859 + switch (opt->type) {
26861 + err = au_xino_set(sb, &opt->xino,
26862 + !!au_ftest_opts(opts->flags, REMOUNT));
26863 + if (unlikely(err))
26866 + *opt_xino = &opt->xino;
26867 + au_xino_brid_set(sb, -1);
26869 + /* safe d_parent access */
26870 + parent = opt->xino.file->f_path.dentry->d_parent;
26871 + root = sb->s_root;
26872 + bbot = au_sbbot(sb);
26873 + for (bindex = 0; bindex <= bbot; bindex++) {
26874 + h_root = au_h_dptr(root, bindex);
26875 + if (h_root == parent) {
26876 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
26884 + au_xino_brid_set(sb, -1);
26885 + *opt_xino = (void *)-1;
26892 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
26893 + unsigned int pending)
26896 + aufs_bindex_t bindex, bbot;
26897 + unsigned char do_plink, skip, do_free, can_no_dreval;
26898 + struct au_branch *br;
26899 + struct au_wbr *wbr;
26900 + struct dentry *root, *dentry;
26901 + struct inode *dir, *h_dir;
26902 + struct au_sbinfo *sbinfo;
26903 + struct au_hinode *hdir;
26905 + SiMustAnyLock(sb);
26907 + sbinfo = au_sbi(sb);
26908 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
26910 + if (!(sb_flags & MS_RDONLY)) {
26911 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
26912 + pr_warn("first branch should be rw\n");
26913 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
26914 + pr_warn_once("shwh should be used with ro\n");
26917 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
26918 + && !au_opt_test(sbinfo->si_mntflags, XINO))
26919 + pr_warn_once("udba=*notify requires xino\n");
26921 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
26922 + pr_warn_once("dirperm1 breaks the protection"
26923 + " by the permission bits on the lower branch\n");
26927 + root = sb->s_root;
26928 + dir = d_inode(root);
26929 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
26930 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
26932 + bbot = au_sbbot(sb);
26933 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
26935 + h_dir = au_h_iptr(dir, bindex);
26936 + br = au_sbr(sb, bindex);
26938 + if ((br->br_perm & AuBrAttr_ICEX)
26939 + && !h_dir->i_op->listxattr)
26940 + br->br_perm &= ~AuBrAttr_ICEX;
26942 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
26943 + && (au_br_sb(br)->s_flags & MS_NOSEC))
26944 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
26948 + wbr = br->br_wbr;
26950 + wbr_wh_read_lock(wbr);
26952 + if (!au_br_writable(br->br_perm)) {
26955 + || (!wbr->wbr_whbase
26956 + && !wbr->wbr_plink
26957 + && !wbr->wbr_orph));
26958 + } else if (!au_br_wh_linkable(br->br_perm)) {
26959 + /* skip = (!br->br_whbase && !br->br_orph); */
26960 + skip = (!wbr || !wbr->wbr_whbase);
26961 + if (skip && wbr) {
26963 + skip = !!wbr->wbr_plink;
26965 + skip = !wbr->wbr_plink;
26968 + /* skip = (br->br_whbase && br->br_ohph); */
26969 + skip = (wbr && wbr->wbr_whbase);
26972 + skip = !!wbr->wbr_plink;
26974 + skip = !wbr->wbr_plink;
26978 + wbr_wh_read_unlock(wbr);
26980 + if (can_no_dreval) {
26981 + dentry = br->br_path.dentry;
26982 + spin_lock(&dentry->d_lock);
26983 + if (dentry->d_flags &
26984 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
26985 + can_no_dreval = 0;
26986 + spin_unlock(&dentry->d_lock);
26989 + if (au_br_fhsm(br->br_perm)) {
26991 + AuDebugOn(!br->br_fhsm);
26997 + hdir = au_hi(dir, bindex);
26998 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27000 + wbr_wh_write_lock(wbr);
27001 + err = au_wh_init(br, sb);
27003 + wbr_wh_write_unlock(wbr);
27004 + au_hn_inode_unlock(hdir);
27006 + if (!err && do_free) {
27008 + br->br_wbr = NULL;
27012 + if (can_no_dreval)
27013 + au_fset_si(sbinfo, NO_DREVAL);
27015 + au_fclr_si(sbinfo, NO_DREVAL);
27018 + au_fset_si(sbinfo, FHSM);
27019 + for (bindex = bbot; bindex >= 0; bindex--) {
27020 + br = au_sbr(sb, bindex);
27021 + if (au_br_fhsm(br->br_perm)) {
27022 + au_fhsm_set_bottom(sb, bindex);
27027 + au_fclr_si(sbinfo, FHSM);
27028 + au_fhsm_set_bottom(sb, -1);
27034 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27037 + unsigned int tmp;
27038 + aufs_bindex_t bindex, bbot;
27039 + struct au_opt *opt;
27040 + struct au_opt_xino *opt_xino, xino;
27041 + struct au_sbinfo *sbinfo;
27042 + struct au_branch *br;
27043 + struct inode *dir;
27045 + SiMustWriteLock(sb);
27050 + while (err >= 0 && opt->type != Opt_tail)
27051 + err = au_opt_simple(sb, opt++, opts);
27054 + else if (unlikely(err < 0))
27057 + /* disable xino and udba temporary */
27058 + sbinfo = au_sbi(sb);
27059 + tmp = sbinfo->si_mntflags;
27060 + au_opt_clr(sbinfo->si_mntflags, XINO);
27061 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27064 + while (err >= 0 && opt->type != Opt_tail)
27065 + err = au_opt_br(sb, opt++, opts);
27068 + else if (unlikely(err < 0))
27071 + bbot = au_sbbot(sb);
27072 + if (unlikely(bbot < 0)) {
27074 + pr_err("no branches\n");
27078 + if (au_opt_test(tmp, XINO))
27079 + au_opt_set(sbinfo->si_mntflags, XINO);
27081 + while (!err && opt->type != Opt_tail)
27082 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27083 + if (unlikely(err))
27086 + err = au_opts_verify(sb, sb->s_flags, tmp);
27087 + if (unlikely(err))
27090 + /* restore xino */
27091 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27092 + xino.file = au_xino_def(sb);
27093 + err = PTR_ERR(xino.file);
27094 + if (IS_ERR(xino.file))
27097 + err = au_xino_set(sb, &xino, /*remount*/0);
27099 + if (unlikely(err))
27103 + /* restore udba */
27104 + tmp &= AuOptMask_UDBA;
27105 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27106 + sbinfo->si_mntflags |= tmp;
27107 + bbot = au_sbbot(sb);
27108 + for (bindex = 0; bindex <= bbot; bindex++) {
27109 + br = au_sbr(sb, bindex);
27110 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27111 + if (unlikely(err))
27112 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27114 + /* go on even if err */
27116 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27117 + dir = d_inode(sb->s_root);
27118 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27125 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27128 + unsigned char no_dreval;
27129 + struct inode *dir;
27130 + struct au_opt_xino *opt_xino;
27131 + struct au_opt *opt;
27132 + struct au_sbinfo *sbinfo;
27134 + SiMustWriteLock(sb);
27136 + err = au_dr_opt_flush(sb);
27137 + if (unlikely(err))
27139 + au_fset_opts(opts->flags, DR_FLUSHED);
27141 + dir = d_inode(sb->s_root);
27142 + sbinfo = au_sbi(sb);
27145 + while (err >= 0 && opt->type != Opt_tail) {
27146 + err = au_opt_simple(sb, opt, opts);
27148 + err = au_opt_br(sb, opt, opts);
27150 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27156 + /* go on even err */
27158 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27159 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27160 + if (unlikely(rerr && !err))
27163 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27164 + au_fset_opts(opts->flags, REFRESH_IDOP);
27166 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27167 + rerr = au_xib_trunc(sb);
27168 + if (unlikely(rerr && !err))
27172 + /* will be handled by the caller */
27173 + if (!au_ftest_opts(opts->flags, REFRESH)
27174 + && (opts->given_udba
27175 + || au_opt_test(sbinfo->si_mntflags, XINO)
27176 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27178 + au_fset_opts(opts->flags, REFRESH);
27180 + AuDbg("status 0x%x\n", opts->flags);
27186 +/* ---------------------------------------------------------------------- */
27188 +unsigned int au_opt_udba(struct super_block *sb)
27190 + return au_mntflags(sb) & AuOptMask_UDBA;
27192 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27193 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27194 +++ linux/fs/aufs/opts.h 2017-11-12 22:24:44.707577830 +0100
27197 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27199 + * This program, aufs is free software; you can redistribute it and/or modify
27200 + * it under the terms of the GNU General Public License as published by
27201 + * the Free Software Foundation; either version 2 of the License, or
27202 + * (at your option) any later version.
27204 + * This program is distributed in the hope that it will be useful,
27205 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27206 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27207 + * GNU General Public License for more details.
27209 + * You should have received a copy of the GNU General Public License
27210 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27214 + * mount options/flags
27217 +#ifndef __AUFS_OPTS_H__
27218 +#define __AUFS_OPTS_H__
27222 +#include <linux/path.h>
27226 +/* ---------------------------------------------------------------------- */
27229 +#define AuOpt_XINO 1 /* external inode number bitmap
27230 + and translation table */
27231 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27232 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27233 +#define AuOpt_UDBA_REVAL (1 << 3)
27234 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27235 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27236 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27237 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27239 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27240 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27241 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27242 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27243 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27244 +#define AuOpt_DIO (1 << 14) /* direct io */
27245 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27247 +#ifndef CONFIG_AUFS_HNOTIFY
27248 +#undef AuOpt_UDBA_HNOTIFY
27249 +#define AuOpt_UDBA_HNOTIFY 0
27251 +#ifndef CONFIG_AUFS_DIRREN
27252 +#undef AuOpt_DIRREN
27253 +#define AuOpt_DIRREN 0
27255 +#ifndef CONFIG_AUFS_SHWH
27257 +#define AuOpt_SHWH 0
27260 +#define AuOpt_Def (AuOpt_XINO \
27261 + | AuOpt_UDBA_REVAL \
27263 + /* | AuOpt_DIRPERM1 */ \
27264 + | AuOpt_WARN_PERM)
27265 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27266 + | AuOpt_UDBA_REVAL \
27267 + | AuOpt_UDBA_HNOTIFY)
27269 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27270 +#define au_opt_set(flags, name) do { \
27271 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27272 + ((flags) |= AuOpt_##name); \
27274 +#define au_opt_set_udba(flags, name) do { \
27275 + (flags) &= ~AuOptMask_UDBA; \
27276 + ((flags) |= AuOpt_##name); \
27278 +#define au_opt_clr(flags, name) do { \
27279 + ((flags) &= ~AuOpt_##name); \
27282 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27284 +#ifdef CONFIG_PROC_FS
27287 + return mntflags & ~AuOpt_PLINK;
27291 +/* ---------------------------------------------------------------------- */
27293 +/* policies to select one among multiple writable branches */
27295 + AuWbrCreate_TDP, /* top down parent */
27296 + AuWbrCreate_RR, /* round robin */
27297 + AuWbrCreate_MFS, /* most free space */
27298 + AuWbrCreate_MFSV, /* mfs with seconds */
27299 + AuWbrCreate_MFSRR, /* mfs then rr */
27300 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27301 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27302 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27303 + AuWbrCreate_PMFS, /* parent and mfs */
27304 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27305 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27306 + AuWbrCreate_PMFSRRV, /* plus seconds */
27308 + AuWbrCreate_Def = AuWbrCreate_TDP
27312 + AuWbrCopyup_TDP, /* top down parent */
27313 + AuWbrCopyup_BUP, /* bottom up parent */
27314 + AuWbrCopyup_BU, /* bottom up */
27316 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27319 +/* ---------------------------------------------------------------------- */
27321 +struct au_opt_add {
27322 + aufs_bindex_t bindex;
27325 + struct path path;
27328 +struct au_opt_del {
27330 + struct path h_path;
27333 +struct au_opt_mod {
27336 + struct dentry *h_root;
27339 +struct au_opt_xino {
27341 + struct file *file;
27344 +struct au_opt_xino_itrunc {
27345 + aufs_bindex_t bindex;
27348 +struct au_opt_wbr_create {
27351 + unsigned long long mfsrr_watermark;
27357 + struct au_opt_xino xino;
27358 + struct au_opt_xino_itrunc xino_itrunc;
27359 + struct au_opt_add add;
27360 + struct au_opt_del del;
27361 + struct au_opt_mod mod;
27364 + unsigned int rdblk;
27365 + unsigned int rdhash;
27367 + struct au_opt_wbr_create wbr_create;
27369 + unsigned int fhsm_second;
27374 +#define AuOpts_REMOUNT 1
27375 +#define AuOpts_REFRESH (1 << 1)
27376 +#define AuOpts_TRUNC_XIB (1 << 2)
27377 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27378 +#define AuOpts_REFRESH_IDOP (1 << 4)
27379 +#define AuOpts_DR_FLUSHED (1 << 5)
27380 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27381 +#define au_fset_opts(flags, name) \
27382 + do { (flags) |= AuOpts_##name; } while (0)
27383 +#define au_fclr_opts(flags, name) \
27384 + do { (flags) &= ~AuOpts_##name; } while (0)
27386 +#ifndef CONFIG_AUFS_DIRREN
27387 +#undef AuOpts_DR_FLUSHED
27388 +#define AuOpts_DR_FLUSHED 0
27392 + struct au_opt *opt;
27395 + unsigned int given_udba;
27396 + unsigned int flags;
27397 + unsigned long sb_flags;
27400 +/* ---------------------------------------------------------------------- */
27403 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27404 +const char *au_optstr_udba(int udba);
27405 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27406 +const char *au_optstr_wbr_create(int wbr_create);
27408 +void au_opts_free(struct au_opts *opts);
27409 +struct super_block;
27410 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27411 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27412 + unsigned int pending);
27413 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27414 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27416 +unsigned int au_opt_udba(struct super_block *sb);
27418 +#endif /* __KERNEL__ */
27419 +#endif /* __AUFS_OPTS_H__ */
27420 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27421 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27422 +++ linux/fs/aufs/plink.c 2017-11-12 22:24:44.707577830 +0100
27425 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27427 + * This program, aufs is free software; you can redistribute it and/or modify
27428 + * it under the terms of the GNU General Public License as published by
27429 + * the Free Software Foundation; either version 2 of the License, or
27430 + * (at your option) any later version.
27432 + * This program is distributed in the hope that it will be useful,
27433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27435 + * GNU General Public License for more details.
27437 + * You should have received a copy of the GNU General Public License
27438 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27448 + * the pseudo-link maintenance mode.
27449 + * during a user process maintains the pseudo-links,
27450 + * prohibit adding a new plink and branch manipulation.
27454 + * For entry functions which will handle plink, and i_mutex is already held
27456 + * They cannot wait and should return an error at once.
27457 + * Callers has to check the error.
27459 + * For entry functions which will handle plink, but i_mutex is not held
27461 + * They can wait the plink maintenance mode to finish.
27463 + * They behave like F_SETLK and F_SETLKW.
27464 + * If the caller never handle plink, then both flags are unnecessary.
27467 +int au_plink_maint(struct super_block *sb, int flags)
27471 + struct task_struct *parent, *prev;
27472 + struct au_sbinfo *sbi;
27474 + SiMustAnyLock(sb);
27477 + if (!au_opt_test(au_mntflags(sb), PLINK))
27480 + sbi = au_sbi(sb);
27481 + pid = sbi->si_plink_maint_pid;
27482 + if (!pid || pid == current->pid)
27485 + /* todo: it highly depends upon /sbin/mount.aufs */
27487 + parent = current;
27491 + parent = rcu_dereference(parent->real_parent);
27492 + if (parent == prev)
27494 + ppid = task_pid_vnr(parent);
27495 + if (pid == ppid) {
27496 + rcu_read_unlock();
27501 + rcu_read_unlock();
27503 + if (au_ftest_lock(flags, NOPLMW)) {
27504 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27505 + /* AuDebugOn(!lockdep_depth(current)); */
27506 + while (sbi->si_plink_maint_pid) {
27507 + si_read_unlock(sb);
27508 + /* gave up wake_up_bit() */
27509 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27511 + if (au_ftest_lock(flags, FLUSH))
27512 + au_nwt_flush(&sbi->si_nowait);
27513 + si_noflush_read_lock(sb);
27515 + } else if (au_ftest_lock(flags, NOPLM)) {
27516 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27524 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27526 + spin_lock(&sbinfo->si_plink_maint_lock);
27527 + sbinfo->si_plink_maint_pid = 0;
27528 + spin_unlock(&sbinfo->si_plink_maint_lock);
27529 + wake_up_all(&sbinfo->si_plink_wq);
27532 +int au_plink_maint_enter(struct super_block *sb)
27535 + struct au_sbinfo *sbinfo;
27538 + sbinfo = au_sbi(sb);
27539 + /* make sure i am the only one in this fs */
27540 + si_write_lock(sb, AuLock_FLUSH);
27541 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27542 + spin_lock(&sbinfo->si_plink_maint_lock);
27543 + if (!sbinfo->si_plink_maint_pid)
27544 + sbinfo->si_plink_maint_pid = current->pid;
27547 + spin_unlock(&sbinfo->si_plink_maint_lock);
27549 + si_write_unlock(sb);
27554 +/* ---------------------------------------------------------------------- */
27556 +#ifdef CONFIG_AUFS_DEBUG
27557 +void au_plink_list(struct super_block *sb)
27560 + struct au_sbinfo *sbinfo;
27561 + struct hlist_bl_head *hbl;
27562 + struct hlist_bl_node *pos;
27563 + struct au_icntnr *icntnr;
27565 + SiMustAnyLock(sb);
27567 + sbinfo = au_sbi(sb);
27568 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27569 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27571 + for (i = 0; i < AuPlink_NHASH; i++) {
27572 + hbl = sbinfo->si_plink + i;
27573 + hlist_bl_lock(hbl);
27574 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27575 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27576 + hlist_bl_unlock(hbl);
27581 +/* is the inode pseudo-linked? */
27582 +int au_plink_test(struct inode *inode)
27585 + struct au_sbinfo *sbinfo;
27586 + struct hlist_bl_head *hbl;
27587 + struct hlist_bl_node *pos;
27588 + struct au_icntnr *icntnr;
27590 + sbinfo = au_sbi(inode->i_sb);
27591 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27592 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27593 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27596 + i = au_plink_hash(inode->i_ino);
27597 + hbl = sbinfo->si_plink + i;
27598 + hlist_bl_lock(hbl);
27599 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27600 + if (&icntnr->vfs_inode == inode) {
27604 + hlist_bl_unlock(hbl);
27608 +/* ---------------------------------------------------------------------- */
27611 + * generate a name for plink.
27612 + * the file will be stored under AUFS_WH_PLINKDIR.
27614 +/* 20 is max digits length of ulong 64 */
27615 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27617 +static int plink_name(char *name, int len, struct inode *inode,
27618 + aufs_bindex_t bindex)
27621 + struct inode *h_inode;
27623 + h_inode = au_h_iptr(inode, bindex);
27624 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27628 +struct au_do_plink_lkup_args {
27629 + struct dentry **errp;
27630 + struct qstr *tgtname;
27631 + struct dentry *h_parent;
27632 + struct au_branch *br;
27635 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27636 + struct dentry *h_parent,
27637 + struct au_branch *br)
27639 + struct dentry *h_dentry;
27640 + struct inode *h_inode;
27642 + h_inode = d_inode(h_parent);
27643 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27644 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27645 + inode_unlock_shared(h_inode);
27649 +static void au_call_do_plink_lkup(void *args)
27651 + struct au_do_plink_lkup_args *a = args;
27652 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27655 +/* lookup the plink-ed @inode under the branch at @bindex */
27656 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27658 + struct dentry *h_dentry, *h_parent;
27659 + struct au_branch *br;
27661 + char a[PLINK_NAME_LEN];
27662 + struct qstr tgtname = QSTR_INIT(a, 0);
27664 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27666 + br = au_sbr(inode->i_sb, bindex);
27667 + h_parent = br->br_wbr->wbr_plink;
27668 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27670 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27671 + struct au_do_plink_lkup_args args = {
27672 + .errp = &h_dentry,
27673 + .tgtname = &tgtname,
27674 + .h_parent = h_parent,
27678 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27679 + if (unlikely(wkq_err))
27680 + h_dentry = ERR_PTR(wkq_err);
27682 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27687 +/* create a pseudo-link */
27688 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27689 + struct dentry *h_dentry, struct au_branch *br)
27692 + struct path h_path = {
27693 + .mnt = au_br_mnt(br)
27695 + struct inode *h_dir, *delegated;
27697 + h_dir = d_inode(h_parent);
27698 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27700 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27701 + err = PTR_ERR(h_path.dentry);
27702 + if (IS_ERR(h_path.dentry))
27706 + /* wh.plink dir is not monitored */
27707 + /* todo: is it really safe? */
27708 + if (d_is_positive(h_path.dentry)
27709 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27710 + delegated = NULL;
27711 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27712 + if (unlikely(err == -EWOULDBLOCK)) {
27713 + pr_warn("cannot retry for NFSv4 delegation"
27714 + " for an internal unlink\n");
27717 + dput(h_path.dentry);
27718 + h_path.dentry = NULL;
27722 + if (!err && d_is_negative(h_path.dentry)) {
27723 + delegated = NULL;
27724 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27725 + if (unlikely(err == -EWOULDBLOCK)) {
27726 + pr_warn("cannot retry for NFSv4 delegation"
27727 + " for an internal link\n");
27731 + dput(h_path.dentry);
27734 + inode_unlock(h_dir);
27738 +struct do_whplink_args {
27740 + struct qstr *tgt;
27741 + struct dentry *h_parent;
27742 + struct dentry *h_dentry;
27743 + struct au_branch *br;
27746 +static void call_do_whplink(void *args)
27748 + struct do_whplink_args *a = args;
27749 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27752 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27753 + aufs_bindex_t bindex, struct au_branch *br)
27755 + int err, wkq_err;
27756 + struct au_wbr *wbr;
27757 + struct dentry *h_parent;
27758 + char a[PLINK_NAME_LEN];
27759 + struct qstr tgtname = QSTR_INIT(a, 0);
27761 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
27762 + h_parent = wbr->wbr_plink;
27763 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27765 + /* always superio. */
27766 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27767 + struct do_whplink_args args = {
27770 + .h_parent = h_parent,
27771 + .h_dentry = h_dentry,
27774 + wkq_err = au_wkq_wait(call_do_whplink, &args);
27775 + if (unlikely(wkq_err))
27778 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
27784 + * create a new pseudo-link for @h_dentry on @bindex.
27785 + * the linked inode is held in aufs @inode.
27787 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
27788 + struct dentry *h_dentry)
27790 + struct super_block *sb;
27791 + struct au_sbinfo *sbinfo;
27792 + struct hlist_bl_head *hbl;
27793 + struct hlist_bl_node *pos;
27794 + struct au_icntnr *icntnr;
27795 + int found, err, cnt, i;
27797 + sb = inode->i_sb;
27798 + sbinfo = au_sbi(sb);
27799 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27800 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27802 + found = au_plink_test(inode);
27806 + i = au_plink_hash(inode->i_ino);
27807 + hbl = sbinfo->si_plink + i;
27810 + hlist_bl_lock(hbl);
27811 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
27812 + if (&icntnr->vfs_inode == inode) {
27818 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
27819 + hlist_bl_add_head(&icntnr->plink, hbl);
27821 + hlist_bl_unlock(hbl);
27823 + cnt = au_hbl_count(hbl);
27824 +#define msg "unexpectedly unblanced or too many pseudo-links"
27825 + if (cnt > AUFS_PLINK_WARN)
27826 + AuWarn1(msg ", %d\n", cnt);
27828 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
27829 + if (unlikely(err)) {
27830 + pr_warn("err %d, damaged pseudo link.\n", err);
27831 + au_hbl_del(&icntnr->plink, hbl);
27832 + iput(&icntnr->vfs_inode);
27835 + iput(&icntnr->vfs_inode);
27838 +/* free all plinks */
27839 +void au_plink_put(struct super_block *sb, int verbose)
27842 + struct au_sbinfo *sbinfo;
27843 + struct hlist_bl_head *hbl;
27844 + struct hlist_bl_node *pos, *tmp;
27845 + struct au_icntnr *icntnr;
27847 + SiMustWriteLock(sb);
27849 + sbinfo = au_sbi(sb);
27850 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27851 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27853 + /* no spin_lock since sbinfo is write-locked */
27855 + for (i = 0; i < AuPlink_NHASH; i++) {
27856 + hbl = sbinfo->si_plink + i;
27857 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
27858 + pr_warn("pseudo-link is not flushed");
27861 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
27862 + iput(&icntnr->vfs_inode);
27863 + INIT_HLIST_BL_HEAD(hbl);
27867 +void au_plink_clean(struct super_block *sb, int verbose)
27869 + struct dentry *root;
27871 + root = sb->s_root;
27872 + aufs_write_lock(root);
27873 + if (au_opt_test(au_mntflags(sb), PLINK))
27874 + au_plink_put(sb, verbose);
27875 + aufs_write_unlock(root);
27878 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
27881 + aufs_bindex_t btop, bbot, bindex;
27884 + btop = au_ibtop(inode);
27885 + bbot = au_ibbot(inode);
27887 + for (bindex = btop; bindex <= bbot; bindex++) {
27888 + if (!au_h_iptr(inode, bindex)
27889 + || au_ii_br_id(inode, bindex) != br_id)
27891 + au_set_h_iptr(inode, bindex, NULL, 0);
27896 + for (bindex = btop; bindex <= bbot; bindex++)
27897 + if (au_h_iptr(inode, bindex)) {
27907 +/* free the plinks on a branch specified by @br_id */
27908 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
27910 + struct au_sbinfo *sbinfo;
27911 + struct hlist_bl_head *hbl;
27912 + struct hlist_bl_node *pos, *tmp;
27913 + struct au_icntnr *icntnr;
27914 + struct inode *inode;
27917 + SiMustWriteLock(sb);
27919 + sbinfo = au_sbi(sb);
27920 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27921 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27923 + /* no bit_lock since sbinfo is write-locked */
27924 + for (i = 0; i < AuPlink_NHASH; i++) {
27925 + hbl = sbinfo->si_plink + i;
27926 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
27927 + inode = au_igrab(&icntnr->vfs_inode);
27928 + ii_write_lock_child(inode);
27929 + do_put = au_plink_do_half_refresh(inode, br_id);
27931 + hlist_bl_del(&icntnr->plink);
27934 + ii_write_unlock(inode);
27939 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
27940 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
27941 +++ linux/fs/aufs/poll.c 2017-11-12 22:24:42.274176929 +0100
27944 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27946 + * This program, aufs is free software; you can redistribute it and/or modify
27947 + * it under the terms of the GNU General Public License as published by
27948 + * the Free Software Foundation; either version 2 of the License, or
27949 + * (at your option) any later version.
27951 + * This program is distributed in the hope that it will be useful,
27952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27954 + * GNU General Public License for more details.
27956 + * You should have received a copy of the GNU General Public License
27957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27962 + * There is only one filesystem which implements ->poll operation, currently.
27967 +unsigned int aufs_poll(struct file *file, poll_table *wait)
27969 + unsigned int mask;
27971 + struct file *h_file;
27972 + struct super_block *sb;
27974 + /* We should pretend an error happened. */
27975 + mask = POLLERR /* | POLLIN | POLLOUT */;
27976 + sb = file->f_path.dentry->d_sb;
27977 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
27979 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
27980 + err = PTR_ERR(h_file);
27981 + if (IS_ERR(h_file))
27984 + /* it is not an error if h_file has no operation */
27985 + mask = DEFAULT_POLLMASK;
27986 + if (h_file->f_op->poll)
27987 + mask = h_file->f_op->poll(h_file, wait);
27988 + fput(h_file); /* instead of au_read_post() */
27991 + si_read_unlock(sb);
27992 + AuTraceErr((int)mask);
27995 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
27996 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
27997 +++ linux/fs/aufs/posix_acl.c 2017-11-12 22:24:42.274176929 +0100
28000 + * Copyright (C) 2014-2017 Junjiro R. Okajima
28002 + * This program, aufs is free software; you can redistribute it and/or modify
28003 + * it under the terms of the GNU General Public License as published by
28004 + * the Free Software Foundation; either version 2 of the License, or
28005 + * (at your option) any later version.
28007 + * This program is distributed in the hope that it will be useful,
28008 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28009 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28010 + * GNU General Public License for more details.
28012 + * You should have received a copy of the GNU General Public License
28013 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28017 + * posix acl operations
28020 +#include <linux/fs.h>
28023 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28025 + struct posix_acl *acl;
28027 + aufs_bindex_t bindex;
28028 + struct inode *h_inode;
28029 + struct super_block *sb;
28032 + sb = inode->i_sb;
28033 + si_read_lock(sb, AuLock_FLUSH);
28034 + ii_read_lock_child(inode);
28035 + if (!(sb->s_flags & MS_POSIXACL))
28038 + bindex = au_ibtop(inode);
28039 + h_inode = au_h_iptr(inode, bindex);
28040 + if (unlikely(!h_inode
28041 + || ((h_inode->i_mode & S_IFMT)
28042 + != (inode->i_mode & S_IFMT)))) {
28043 + err = au_busy_or_stale();
28044 + acl = ERR_PTR(err);
28048 + /* always topmost only */
28049 + acl = get_acl(h_inode, type);
28050 + if (!IS_ERR_OR_NULL(acl))
28051 + set_cached_acl(inode, type, acl);
28054 + ii_read_unlock(inode);
28055 + si_read_unlock(sb);
28057 + AuTraceErrPtr(acl);
28061 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28065 + struct dentry *dentry;
28066 + struct au_sxattr arg = {
28067 + .type = AU_ACL_SET,
28074 + IMustLock(inode);
28076 + if (inode->i_ino == AUFS_ROOT_INO)
28077 + dentry = dget(inode->i_sb->s_root);
28079 + dentry = d_find_alias(inode);
28081 + dentry = d_find_any_alias(inode);
28083 + pr_warn("cannot handle this inode, "
28084 + "please report to aufs-users ML\n");
28090 + ssz = au_sxattr(dentry, inode, &arg);
28095 + set_cached_acl(inode, type, acl);
28101 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28102 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28103 +++ linux/fs/aufs/procfs.c 2017-11-12 22:24:44.707577830 +0100
28106 + * Copyright (C) 2010-2017 Junjiro R. Okajima
28108 + * This program, aufs is free software; you can redistribute it and/or modify
28109 + * it under the terms of the GNU General Public License as published by
28110 + * the Free Software Foundation; either version 2 of the License, or
28111 + * (at your option) any later version.
28113 + * This program is distributed in the hope that it will be useful,
28114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28116 + * GNU General Public License for more details.
28118 + * You should have received a copy of the GNU General Public License
28119 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28123 + * procfs interfaces
28126 +#include <linux/proc_fs.h>
28129 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28131 + struct au_sbinfo *sbinfo;
28133 + sbinfo = file->private_data;
28135 + au_plink_maint_leave(sbinfo);
28136 + kobject_put(&sbinfo->si_kobj);
28142 +static void au_procfs_plm_write_clean(struct file *file)
28144 + struct au_sbinfo *sbinfo;
28146 + sbinfo = file->private_data;
28148 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28151 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28154 + struct super_block *sb;
28155 + struct au_sbinfo *sbinfo;
28156 + struct hlist_bl_node *pos;
28159 + if (unlikely(file->private_data))
28163 + /* don't use au_sbilist_lock() here */
28164 + hlist_bl_lock(&au_sbilist);
28165 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28166 + if (id == sysaufs_si_id(sbinfo)) {
28167 + kobject_get(&sbinfo->si_kobj);
28168 + sb = sbinfo->si_sb;
28171 + hlist_bl_unlock(&au_sbilist);
28174 + if (unlikely(!sb))
28177 + err = au_plink_maint_enter(sb);
28179 + /* keep kobject_get() */
28180 + file->private_data = sbinfo;
28182 + kobject_put(&sbinfo->si_kobj);
28188 + * Accept a valid "si=xxxx" only.
28189 + * Once it is accepted successfully, accept "clean" too.
28191 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28192 + size_t count, loff_t *ppos)
28195 + unsigned long id;
28196 + /* last newline is allowed */
28197 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28200 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28204 + if (unlikely(count > sizeof(buf)))
28207 + err = copy_from_user(buf, ubuf, count);
28208 + if (unlikely(err)) {
28215 + if (!strcmp("clean", buf)) {
28216 + au_procfs_plm_write_clean(file);
28217 + goto out_success;
28218 + } else if (unlikely(strncmp("si=", buf, 3)))
28221 + err = kstrtoul(buf + 3, 16, &id);
28222 + if (unlikely(err))
28225 + err = au_procfs_plm_write_si(file, id);
28226 + if (unlikely(err))
28230 + err = count; /* success */
28235 +static const struct file_operations au_procfs_plm_fop = {
28236 + .write = au_procfs_plm_write,
28237 + .release = au_procfs_plm_release,
28238 + .owner = THIS_MODULE
28241 +/* ---------------------------------------------------------------------- */
28243 +static struct proc_dir_entry *au_procfs_dir;
28245 +void au_procfs_fin(void)
28247 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28248 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28251 +int __init au_procfs_init(void)
28254 + struct proc_dir_entry *entry;
28257 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28258 + if (unlikely(!au_procfs_dir))
28261 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
28262 + au_procfs_dir, &au_procfs_plm_fop);
28263 + if (unlikely(!entry))
28267 + goto out; /* success */
28271 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28275 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28276 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28277 +++ linux/fs/aufs/rdu.c 2017-11-12 22:24:42.274176929 +0100
28280 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28282 + * This program, aufs is free software; you can redistribute it and/or modify
28283 + * it under the terms of the GNU General Public License as published by
28284 + * the Free Software Foundation; either version 2 of the License, or
28285 + * (at your option) any later version.
28287 + * This program is distributed in the hope that it will be useful,
28288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28290 + * GNU General Public License for more details.
28292 + * You should have received a copy of the GNU General Public License
28293 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28297 + * readdir in userspace.
28300 +#include <linux/compat.h>
28301 +#include <linux/fs_stack.h>
28302 +#include <linux/security.h>
28305 +/* bits for struct aufs_rdu.flags */
28306 +#define AuRdu_CALLED 1
28307 +#define AuRdu_CONT (1 << 1)
28308 +#define AuRdu_FULL (1 << 2)
28309 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28310 +#define au_fset_rdu(flags, name) \
28311 + do { (flags) |= AuRdu_##name; } while (0)
28312 +#define au_fclr_rdu(flags, name) \
28313 + do { (flags) &= ~AuRdu_##name; } while (0)
28315 +struct au_rdu_arg {
28316 + struct dir_context ctx;
28317 + struct aufs_rdu *rdu;
28318 + union au_rdu_ent_ul ent;
28319 + unsigned long end;
28321 + struct super_block *sb;
28325 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28326 + loff_t offset, u64 h_ino, unsigned int d_type)
28329 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28330 + struct aufs_rdu *rdu = arg->rdu;
28331 + struct au_rdu_ent ent;
28335 + au_fset_rdu(rdu->cookie.flags, CALLED);
28336 + len = au_rdu_len(nlen);
28337 + if (arg->ent.ul + len < arg->end) {
28339 + ent.bindex = rdu->cookie.bindex;
28340 + ent.type = d_type;
28342 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28343 + ent.type = DT_UNKNOWN;
28345 + /* unnecessary to support mmap_sem since this is a dir */
28347 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28349 + if (copy_to_user(arg->ent.e->name, name, nlen))
28351 + /* the terminating NULL */
28352 + if (__put_user(0, arg->ent.e->name + nlen))
28355 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28356 + arg->ent.ul += len;
28360 + au_fset_rdu(rdu->cookie.flags, FULL);
28362 + rdu->tail = arg->ent;
28366 + /* AuTraceErr(err); */
28370 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28374 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28376 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28377 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28379 + if (unlikely(offset != cookie->h_pos))
28385 + au_fclr_rdu(cookie->flags, CALLED);
28387 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28391 + && au_ftest_rdu(cookie->flags, CALLED)
28392 + && !au_ftest_rdu(cookie->flags, FULL));
28393 + cookie->h_pos = h_file->f_pos;
28400 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28403 + aufs_bindex_t bbot;
28404 + struct au_rdu_arg arg = {
28406 + .actor = au_rdu_fill
28409 + struct dentry *dentry;
28410 + struct inode *inode;
28411 + struct file *h_file;
28412 + struct au_rdu_cookie *cookie = &rdu->cookie;
28414 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28415 + if (unlikely(err)) {
28421 + rdu->tail = rdu->ent;
28424 + arg.ent = rdu->ent;
28425 + arg.end = arg.ent.ul;
28426 + arg.end += rdu->sz;
28429 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28432 + err = security_file_permission(file, MAY_READ);
28434 + if (unlikely(err))
28437 + dentry = file->f_path.dentry;
28438 + inode = d_inode(dentry);
28439 + inode_lock_shared(inode);
28441 + arg.sb = inode->i_sb;
28442 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28443 + if (unlikely(err))
28445 + err = au_alive_dir(dentry);
28446 + if (unlikely(err))
28448 + /* todo: reval? */
28449 + fi_read_lock(file);
28452 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28453 + && cookie->generation != au_figen(file)))
28458 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28460 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28462 + bbot = au_fbtop(file);
28463 + if (cookie->bindex < bbot)
28464 + cookie->bindex = bbot;
28465 + bbot = au_fbbot_dir(file);
28466 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28467 + for (; !err && cookie->bindex <= bbot;
28468 + cookie->bindex++, cookie->h_pos = 0) {
28469 + h_file = au_hf_dir(file, cookie->bindex);
28473 + au_fclr_rdu(cookie->flags, FULL);
28474 + err = au_rdu_do(h_file, &arg);
28476 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28479 + AuDbg("rent %llu\n", rdu->rent);
28481 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28482 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28483 + au_fset_rdu(cookie->flags, CONT);
28484 + cookie->generation = au_figen(file);
28487 + ii_read_lock_child(inode);
28488 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28489 + ii_read_unlock(inode);
28492 + fi_read_unlock(file);
28494 + si_read_unlock(arg.sb);
28496 + inode_unlock_shared(inode);
28502 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28506 + unsigned long long nent;
28507 + union au_rdu_ent_ul *u;
28508 + struct au_rdu_ent ent;
28509 + struct super_block *sb;
28512 + nent = rdu->nent;
28514 + sb = file->f_path.dentry->d_sb;
28515 + si_read_lock(sb, AuLock_FLUSH);
28516 + while (nent-- > 0) {
28517 + /* unnecessary to support mmap_sem since this is a dir */
28518 + err = copy_from_user(&ent, u->e, sizeof(ent));
28520 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28521 + if (unlikely(err)) {
28527 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28529 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28531 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28533 + if (unlikely(err)) {
28538 + err = __put_user(ino, &u->e->ino);
28539 + if (unlikely(err)) {
28544 + u->ul += au_rdu_len(ent.nlen);
28546 + si_read_unlock(sb);
28551 +/* ---------------------------------------------------------------------- */
28553 +static int au_rdu_verify(struct aufs_rdu *rdu)
28555 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28556 + "%llu, b%d, 0x%x, g%u}\n",
28557 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28559 + rdu->rent, rdu->shwh, rdu->full,
28560 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28561 + rdu->cookie.generation);
28563 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28567 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28571 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28574 + struct aufs_rdu rdu;
28575 + void __user *p = (void __user *)arg;
28577 + err = copy_from_user(&rdu, p, sizeof(rdu));
28578 + if (unlikely(err)) {
28583 + err = au_rdu_verify(&rdu);
28584 + if (unlikely(err))
28588 + case AUFS_CTL_RDU:
28589 + err = au_rdu(file, &rdu);
28590 + if (unlikely(err))
28593 + e = copy_to_user(p, &rdu, sizeof(rdu));
28594 + if (unlikely(e)) {
28599 + case AUFS_CTL_RDU_INO:
28600 + err = au_rdu_ino(file, &rdu);
28604 + /* err = -ENOTTY; */
28613 +#ifdef CONFIG_COMPAT
28614 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28617 + struct aufs_rdu rdu;
28618 + void __user *p = compat_ptr(arg);
28620 + /* todo: get_user()? */
28621 + err = copy_from_user(&rdu, p, sizeof(rdu));
28622 + if (unlikely(err)) {
28627 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28628 + err = au_rdu_verify(&rdu);
28629 + if (unlikely(err))
28633 + case AUFS_CTL_RDU:
28634 + err = au_rdu(file, &rdu);
28635 + if (unlikely(err))
28638 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28639 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28640 + e = copy_to_user(p, &rdu, sizeof(rdu));
28641 + if (unlikely(e)) {
28646 + case AUFS_CTL_RDU_INO:
28647 + err = au_rdu_ino(file, &rdu);
28651 + /* err = -ENOTTY; */
28660 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28661 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28662 +++ linux/fs/aufs/rwsem.h 2017-11-12 22:24:44.707577830 +0100
28665 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28667 + * This program, aufs is free software; you can redistribute it and/or modify
28668 + * it under the terms of the GNU General Public License as published by
28669 + * the Free Software Foundation; either version 2 of the License, or
28670 + * (at your option) any later version.
28672 + * This program is distributed in the hope that it will be useful,
28673 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28674 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28675 + * GNU General Public License for more details.
28677 + * You should have received a copy of the GNU General Public License
28678 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28682 + * simple read-write semaphore wrappers
28685 +#ifndef __AUFS_RWSEM_H__
28686 +#define __AUFS_RWSEM_H__
28690 +#include "debug.h"
28692 +/* in the futre, the name 'au_rwsem' will be totally gone */
28693 +#define au_rwsem rw_semaphore
28695 +/* to debug easier, do not make them inlined functions */
28696 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28697 +/* rwsem_is_locked() is unusable */
28698 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
28700 + && !lockdep_is_held_type(rw, 1))
28701 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
28703 + && !lockdep_is_held_type(rw, 0))
28704 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
28706 + && !lockdep_is_held(rw))
28707 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
28709 + && lockdep_is_held(rw))
28711 +#define au_rw_init(rw) init_rwsem(rw)
28713 +#define au_rw_init_wlock(rw) do { \
28714 + au_rw_init(rw); \
28715 + down_write(rw); \
28718 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28719 + au_rw_init(rw); \
28720 + down_write_nested(rw, lsc); \
28723 +#define au_rw_read_lock(rw) down_read(rw)
28724 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28725 +#define au_rw_read_unlock(rw) up_read(rw)
28726 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28727 +#define au_rw_write_lock(rw) down_write(rw)
28728 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28729 +#define au_rw_write_unlock(rw) up_write(rw)
28730 +/* why is not _nested version defined? */
28731 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28732 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28734 +#endif /* __KERNEL__ */
28735 +#endif /* __AUFS_RWSEM_H__ */
28736 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28737 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28738 +++ linux/fs/aufs/sbinfo.c 2017-11-12 22:24:44.707577830 +0100
28741 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28743 + * This program, aufs is free software; you can redistribute it and/or modify
28744 + * it under the terms of the GNU General Public License as published by
28745 + * the Free Software Foundation; either version 2 of the License, or
28746 + * (at your option) any later version.
28748 + * This program is distributed in the hope that it will be useful,
28749 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28750 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28751 + * GNU General Public License for more details.
28753 + * You should have received a copy of the GNU General Public License
28754 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28758 + * superblock private data
28764 + * they are necessary regardless sysfs is disabled.
28766 +void au_si_free(struct kobject *kobj)
28769 + struct au_sbinfo *sbinfo;
28770 + char *locked __maybe_unused; /* debug only */
28772 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28773 + for (i = 0; i < AuPlink_NHASH; i++)
28774 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
28775 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
28777 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
28778 + percpu_counter_destroy(&sbinfo->si_ninodes);
28779 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
28780 + percpu_counter_destroy(&sbinfo->si_nfiles);
28782 + au_rw_write_lock(&sbinfo->si_rwsem);
28783 + au_br_free(sbinfo);
28784 + au_rw_write_unlock(&sbinfo->si_rwsem);
28786 + kfree(sbinfo->si_branch);
28787 + mutex_destroy(&sbinfo->si_xib_mtx);
28788 + AuRwDestroy(&sbinfo->si_rwsem);
28793 +int au_si_alloc(struct super_block *sb)
28796 + struct au_sbinfo *sbinfo;
28799 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
28800 + if (unlikely(!sbinfo))
28803 + /* will be reallocated separately */
28804 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
28805 + if (unlikely(!sbinfo->si_branch))
28808 + err = sysaufs_si_init(sbinfo);
28809 + if (unlikely(err))
28812 + au_nwt_init(&sbinfo->si_nowait);
28813 + au_rw_init_wlock(&sbinfo->si_rwsem);
28815 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
28816 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
28818 + sbinfo->si_bbot = -1;
28819 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
28821 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
28822 + sbinfo->si_wbr_create = AuWbrCreate_Def;
28823 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
28824 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
28826 + au_fhsm_init(sbinfo);
28828 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
28830 + sbinfo->si_xino_jiffy = jiffies;
28831 + sbinfo->si_xino_expire
28832 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
28833 + mutex_init(&sbinfo->si_xib_mtx);
28834 + sbinfo->si_xino_brid = -1;
28835 + /* leave si_xib_last_pindex and si_xib_next_bit */
28837 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
28839 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
28840 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
28841 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
28842 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
28844 + for (i = 0; i < AuPlink_NHASH; i++)
28845 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
28846 + init_waitqueue_head(&sbinfo->si_plink_wq);
28847 + spin_lock_init(&sbinfo->si_plink_maint_lock);
28849 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
28851 + /* with getattr by default */
28852 + sbinfo->si_iop_array = aufs_iop;
28854 + /* leave other members for sysaufs and si_mnt. */
28855 + sbinfo->si_sb = sb;
28856 + sb->s_fs_info = sbinfo;
28858 + return 0; /* success */
28861 + kfree(sbinfo->si_branch);
28868 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
28871 + struct au_branch **brp;
28873 + AuRwMustWriteLock(&sbinfo->si_rwsem);
28876 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
28877 + if (unlikely(!sz))
28878 + sz = sizeof(*brp);
28879 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
28882 + sbinfo->si_branch = brp;
28889 +/* ---------------------------------------------------------------------- */
28891 +unsigned int au_sigen_inc(struct super_block *sb)
28893 + unsigned int gen;
28894 + struct inode *inode;
28896 + SiMustWriteLock(sb);
28898 + gen = ++au_sbi(sb)->si_generation;
28899 + au_update_digen(sb->s_root);
28900 + inode = d_inode(sb->s_root);
28901 + au_update_iigen(inode, /*half*/0);
28902 + inode->i_version++;
28906 +aufs_bindex_t au_new_br_id(struct super_block *sb)
28908 + aufs_bindex_t br_id;
28910 + struct au_sbinfo *sbinfo;
28912 + SiMustWriteLock(sb);
28914 + sbinfo = au_sbi(sb);
28915 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
28916 + br_id = ++sbinfo->si_last_br_id;
28917 + AuDebugOn(br_id < 0);
28918 + if (br_id && au_br_index(sb, br_id) < 0)
28925 +/* ---------------------------------------------------------------------- */
28927 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
28928 +int si_read_lock(struct super_block *sb, int flags)
28933 + if (au_ftest_lock(flags, FLUSH))
28934 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28936 + si_noflush_read_lock(sb);
28937 + err = au_plink_maint(sb, flags);
28938 + if (unlikely(err))
28939 + si_read_unlock(sb);
28944 +int si_write_lock(struct super_block *sb, int flags)
28948 + if (au_ftest_lock(flags, FLUSH))
28949 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28951 + si_noflush_write_lock(sb);
28952 + err = au_plink_maint(sb, flags);
28953 + if (unlikely(err))
28954 + si_write_unlock(sb);
28959 +/* dentry and super_block lock. call at entry point */
28960 +int aufs_read_lock(struct dentry *dentry, int flags)
28963 + struct super_block *sb;
28965 + sb = dentry->d_sb;
28966 + err = si_read_lock(sb, flags);
28967 + if (unlikely(err))
28970 + if (au_ftest_lock(flags, DW))
28971 + di_write_lock_child(dentry);
28973 + di_read_lock_child(dentry, flags);
28975 + if (au_ftest_lock(flags, GEN)) {
28976 + err = au_digen_test(dentry, au_sigen(sb));
28977 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
28978 + AuDebugOn(!err && au_dbrange_test(dentry));
28980 + err = au_dbrange_test(dentry);
28981 + if (unlikely(err))
28982 + aufs_read_unlock(dentry, flags);
28989 +void aufs_read_unlock(struct dentry *dentry, int flags)
28991 + if (au_ftest_lock(flags, DW))
28992 + di_write_unlock(dentry);
28994 + di_read_unlock(dentry, flags);
28995 + si_read_unlock(dentry->d_sb);
28998 +void aufs_write_lock(struct dentry *dentry)
29000 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29001 + di_write_lock_child(dentry);
29004 +void aufs_write_unlock(struct dentry *dentry)
29006 + di_write_unlock(dentry);
29007 + si_write_unlock(dentry->d_sb);
29010 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29013 + unsigned int sigen;
29014 + struct super_block *sb;
29017 + err = si_read_lock(sb, flags);
29018 + if (unlikely(err))
29021 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29023 + if (au_ftest_lock(flags, GEN)) {
29024 + sigen = au_sigen(sb);
29025 + err = au_digen_test(d1, sigen);
29026 + AuDebugOn(!err && au_dbrange_test(d1));
29028 + err = au_digen_test(d2, sigen);
29029 + AuDebugOn(!err && au_dbrange_test(d2));
29031 + if (unlikely(err))
29032 + aufs_read_and_write_unlock2(d1, d2);
29039 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29041 + di_write_unlock2(d1, d2);
29042 + si_read_unlock(d1->d_sb);
29044 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29045 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29046 +++ linux/fs/aufs/super.c 2017-11-12 22:24:44.707577830 +0100
29049 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29051 + * This program, aufs is free software; you can redistribute it and/or modify
29052 + * it under the terms of the GNU General Public License as published by
29053 + * the Free Software Foundation; either version 2 of the License, or
29054 + * (at your option) any later version.
29056 + * This program is distributed in the hope that it will be useful,
29057 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29058 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29059 + * GNU General Public License for more details.
29061 + * You should have received a copy of the GNU General Public License
29062 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29066 + * mount and super_block operations
29069 +#include <linux/mm.h>
29070 +#include <linux/seq_file.h>
29071 +#include <linux/statfs.h>
29072 +#include <linux/vmalloc.h>
29076 + * super_operations
29078 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29080 + struct au_icntnr *c;
29082 + c = au_cache_alloc_icntnr();
29084 + au_icntnr_init(c);
29085 + c->vfs_inode.i_version = 1; /* sigen(sb); */
29086 + c->iinfo.ii_hinode = NULL;
29087 + return &c->vfs_inode;
29092 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29094 + struct inode *inode = container_of(head, struct inode, i_rcu);
29096 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29099 +static void aufs_destroy_inode(struct inode *inode)
29101 + if (!au_is_bad_inode(inode))
29102 + au_iinfo_fin(inode);
29103 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29106 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29108 + struct inode *inode;
29111 + inode = iget_locked(sb, ino);
29112 + if (unlikely(!inode)) {
29113 + inode = ERR_PTR(-ENOMEM);
29116 + if (!(inode->i_state & I_NEW))
29119 + err = au_xigen_new(inode);
29121 + err = au_iinfo_init(inode);
29123 + inode->i_version++;
29125 + iget_failed(inode);
29126 + inode = ERR_PTR(err);
29130 + /* never return NULL */
29131 + AuDebugOn(!inode);
29132 + AuTraceErrPtr(inode);
29136 +/* lock free root dinfo */
29137 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29140 + aufs_bindex_t bindex, bbot;
29141 + struct path path;
29142 + struct au_hdentry *hdp;
29143 + struct au_branch *br;
29144 + au_br_perm_str_t perm;
29147 + bbot = au_sbbot(sb);
29149 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29150 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29151 + br = au_sbr(sb, bindex);
29152 + path.mnt = au_br_mnt(br);
29153 + path.dentry = hdp->hd_dentry;
29154 + err = au_seq_path(seq, &path);
29156 + au_optstr_br_perm(&perm, br->br_perm);
29157 + seq_printf(seq, "=%s", perm.a);
29158 + if (bindex != bbot)
29159 + seq_putc(seq, ':');
29162 + if (unlikely(err || seq_has_overflowed(seq)))
29168 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29169 + const char *append)
29174 + while (*pat != ':')
29177 + strcpy(p, append);
29178 + AuDebugOn(strlen(fmt) >= len);
29181 +static void au_show_wbr_create(struct seq_file *m, int v,
29182 + struct au_sbinfo *sbinfo)
29186 + struct au_wbr_mfs *mfs;
29188 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29190 + seq_puts(m, ",create=");
29191 + pat = au_optstr_wbr_create(v);
29192 + mfs = &sbinfo->si_wbr_mfs;
29194 + case AuWbrCreate_TDP:
29195 + case AuWbrCreate_RR:
29196 + case AuWbrCreate_MFS:
29197 + case AuWbrCreate_PMFS:
29198 + seq_puts(m, pat);
29200 + case AuWbrCreate_MFSRR:
29201 + case AuWbrCreate_TDMFS:
29202 + case AuWbrCreate_PMFSRR:
29203 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29204 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29206 + case AuWbrCreate_MFSV:
29207 + case AuWbrCreate_PMFSV:
29208 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29209 + seq_printf(m, fmt,
29210 + jiffies_to_msecs(mfs->mfs_expire)
29213 + case AuWbrCreate_MFSRRV:
29214 + case AuWbrCreate_TDMFSV:
29215 + case AuWbrCreate_PMFSRRV:
29216 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29217 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29218 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29225 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29227 +#ifdef CONFIG_SYSFS
29231 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29232 + aufs_bindex_t bindex, brid;
29233 + struct qstr *name;
29235 + struct dentry *d, *h_root;
29237 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29240 + f = au_sbi(sb)->si_xib;
29244 + /* stop printing the default xino path on the first writable branch */
29246 + brid = au_xino_brid(sb);
29248 + bindex = au_br_index(sb, brid);
29249 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
29251 + d = f->f_path.dentry;
29252 + name = &d->d_name;
29253 + /* safe ->d_parent because the file is unlinked */
29254 + if (d->d_parent == h_root
29255 + && name->len == len
29256 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29259 + seq_puts(seq, ",xino=");
29260 + err = au_xino_path(seq, f);
29267 +/* seq_file will re-call me in case of too long string */
29268 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29271 + unsigned int mnt_flags, v;
29272 + struct super_block *sb;
29273 + struct au_sbinfo *sbinfo;
29275 +#define AuBool(name, str) do { \
29276 + v = au_opt_test(mnt_flags, name); \
29277 + if (v != au_opt_test(AuOpt_Def, name)) \
29278 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29281 +#define AuStr(name, str) do { \
29282 + v = mnt_flags & AuOptMask_##name; \
29283 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29284 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29287 +#define AuUInt(name, str, val) do { \
29288 + if (val != AUFS_##name##_DEF) \
29289 + seq_printf(m, "," #str "=%u", val); \
29292 + sb = dentry->d_sb;
29293 + if (sb->s_flags & MS_POSIXACL)
29294 + seq_puts(m, ",acl");
29296 + /* lock free root dinfo */
29297 + si_noflush_read_lock(sb);
29298 + sbinfo = au_sbi(sb);
29299 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29301 + mnt_flags = au_mntflags(sb);
29302 + if (au_opt_test(mnt_flags, XINO)) {
29303 + err = au_show_xino(m, sb);
29304 + if (unlikely(err))
29307 + seq_puts(m, ",noxino");
29309 + AuBool(TRUNC_XINO, trunc_xino);
29310 + AuStr(UDBA, udba);
29311 + AuBool(SHWH, shwh);
29312 + AuBool(PLINK, plink);
29313 + AuBool(DIO, dio);
29314 + AuBool(DIRPERM1, dirperm1);
29316 + v = sbinfo->si_wbr_create;
29317 + if (v != AuWbrCreate_Def)
29318 + au_show_wbr_create(m, v, sbinfo);
29320 + v = sbinfo->si_wbr_copyup;
29321 + if (v != AuWbrCopyup_Def)
29322 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29324 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29325 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29326 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29328 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29330 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29331 + AuUInt(RDCACHE, rdcache, v);
29333 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29334 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29336 + au_fhsm_show(m, sbinfo);
29338 + AuBool(DIRREN, dirren);
29339 + AuBool(SUM, sum);
29340 + /* AuBool(SUM_W, wsum); */
29341 + AuBool(WARN_PERM, warn_perm);
29342 + AuBool(VERBOSE, verbose);
29345 + /* be sure to print "br:" last */
29346 + if (!sysaufs_brs) {
29347 + seq_puts(m, ",br:");
29348 + au_show_brs(m, sb);
29350 + si_read_unlock(sb);
29358 +/* ---------------------------------------------------------------------- */
29360 +/* sum mode which returns the summation for statfs(2) */
29362 +static u64 au_add_till_max(u64 a, u64 b)
29370 + return ULLONG_MAX;
29373 +static u64 au_mul_till_max(u64 a, long mul)
29381 + return ULLONG_MAX;
29384 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29387 + long bsize, factor;
29388 + u64 blocks, bfree, bavail, files, ffree;
29389 + aufs_bindex_t bbot, bindex, i;
29390 + unsigned char shared;
29391 + struct path h_path;
29392 + struct super_block *h_sb;
29395 + bsize = LONG_MAX;
29401 + bbot = au_sbbot(sb);
29402 + for (bindex = 0; bindex <= bbot; bindex++) {
29403 + h_path.mnt = au_sbr_mnt(sb, bindex);
29404 + h_sb = h_path.mnt->mnt_sb;
29406 + for (i = 0; !shared && i < bindex; i++)
29407 + shared = (au_sbr_sb(sb, i) == h_sb);
29411 + /* sb->s_root for NFS is unreliable */
29412 + h_path.dentry = h_path.mnt->mnt_root;
29413 + err = vfs_statfs(&h_path, buf);
29414 + if (unlikely(err))
29417 + if (bsize > buf->f_bsize) {
29419 + * we will reduce bsize, so we have to expand blocks
29420 + * etc. to match them again
29422 + factor = (bsize / buf->f_bsize);
29423 + blocks = au_mul_till_max(blocks, factor);
29424 + bfree = au_mul_till_max(bfree, factor);
29425 + bavail = au_mul_till_max(bavail, factor);
29426 + bsize = buf->f_bsize;
29429 + factor = (buf->f_bsize / bsize);
29430 + blocks = au_add_till_max(blocks,
29431 + au_mul_till_max(buf->f_blocks, factor));
29432 + bfree = au_add_till_max(bfree,
29433 + au_mul_till_max(buf->f_bfree, factor));
29434 + bavail = au_add_till_max(bavail,
29435 + au_mul_till_max(buf->f_bavail, factor));
29436 + files = au_add_till_max(files, buf->f_files);
29437 + ffree = au_add_till_max(ffree, buf->f_ffree);
29440 + buf->f_bsize = bsize;
29441 + buf->f_blocks = blocks;
29442 + buf->f_bfree = bfree;
29443 + buf->f_bavail = bavail;
29444 + buf->f_files = files;
29445 + buf->f_ffree = ffree;
29446 + buf->f_frsize = 0;
29452 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29455 + struct path h_path;
29456 + struct super_block *sb;
29458 + /* lock free root dinfo */
29459 + sb = dentry->d_sb;
29460 + si_noflush_read_lock(sb);
29461 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29462 + /* sb->s_root for NFS is unreliable */
29463 + h_path.mnt = au_sbr_mnt(sb, 0);
29464 + h_path.dentry = h_path.mnt->mnt_root;
29465 + err = vfs_statfs(&h_path, buf);
29467 + err = au_statfs_sum(sb, buf);
29468 + si_read_unlock(sb);
29471 + buf->f_type = AUFS_SUPER_MAGIC;
29472 + buf->f_namelen = AUFS_MAX_NAMELEN;
29473 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29475 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29480 +/* ---------------------------------------------------------------------- */
29482 +static int aufs_sync_fs(struct super_block *sb, int wait)
29485 + aufs_bindex_t bbot, bindex;
29486 + struct au_branch *br;
29487 + struct super_block *h_sb;
29490 + si_noflush_read_lock(sb);
29491 + bbot = au_sbbot(sb);
29492 + for (bindex = 0; bindex <= bbot; bindex++) {
29493 + br = au_sbr(sb, bindex);
29494 + if (!au_br_writable(br->br_perm))
29497 + h_sb = au_sbr_sb(sb, bindex);
29498 + e = vfsub_sync_filesystem(h_sb, wait);
29499 + if (unlikely(e && !err))
29501 + /* go on even if an error happens */
29503 + si_read_unlock(sb);
29508 +/* ---------------------------------------------------------------------- */
29510 +/* final actions when unmounting a file system */
29511 +static void aufs_put_super(struct super_block *sb)
29513 + struct au_sbinfo *sbinfo;
29515 + sbinfo = au_sbi(sb);
29519 + dbgaufs_si_fin(sbinfo);
29520 + kobject_put(&sbinfo->si_kobj);
29523 +/* ---------------------------------------------------------------------- */
29525 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29526 + struct super_block *sb, void *arg)
29529 + unsigned long long n, sz;
29536 + if (*hint > ULLONG_MAX / sizeof(array)) {
29537 + array = ERR_PTR(-EMFILE);
29538 + pr_err("hint %llu\n", *hint);
29542 + sz = sizeof(array) * *hint;
29543 + array = kzalloc(sz, GFP_NOFS);
29544 + if (unlikely(!array))
29545 + array = vzalloc(sz);
29546 + if (unlikely(!array)) {
29547 + array = ERR_PTR(-ENOMEM);
29551 + n = cb(sb, array, *hint, arg);
29552 + AuDebugOn(n > *hint);
29559 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29560 + unsigned long long max __maybe_unused,
29563 + unsigned long long n;
29564 + struct inode **p, *inode;
29565 + struct list_head *head;
29570 + spin_lock(&sb->s_inode_list_lock);
29571 + list_for_each_entry(inode, head, i_sb_list) {
29572 + if (!au_is_bad_inode(inode)
29573 + && au_ii(inode)->ii_btop >= 0) {
29574 + spin_lock(&inode->i_lock);
29575 + if (atomic_read(&inode->i_count)) {
29579 + AuDebugOn(n > max);
29581 + spin_unlock(&inode->i_lock);
29584 + spin_unlock(&sb->s_inode_list_lock);
29589 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29591 + *max = au_ninodes(sb);
29592 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29595 +void au_iarray_free(struct inode **a, unsigned long long max)
29597 + unsigned long long ull;
29599 + for (ull = 0; ull < max; ull++)
29604 +/* ---------------------------------------------------------------------- */
29607 + * refresh dentry and inode at remount time.
29609 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29610 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29611 + struct dentry *parent)
29615 + di_write_lock_child(dentry);
29616 + di_read_lock_parent(parent, AuLock_IR);
29617 + err = au_refresh_dentry(dentry, parent);
29618 + if (!err && dir_flags)
29619 + au_hn_reset(d_inode(dentry), dir_flags);
29620 + di_read_unlock(parent, AuLock_IR);
29621 + di_write_unlock(dentry);
29626 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29627 + struct au_sbinfo *sbinfo,
29628 + const unsigned int dir_flags, unsigned int do_idop)
29631 + struct dentry *parent;
29634 + parent = dget_parent(dentry);
29635 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29636 + if (d_really_is_positive(dentry)) {
29637 + if (!d_is_dir(dentry))
29638 + err = au_do_refresh(dentry, /*dir_flags*/0,
29641 + err = au_do_refresh(dentry, dir_flags, parent);
29642 + if (unlikely(err))
29643 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29646 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29647 + AuDbgDentry(dentry);
29653 + au_refresh_dop(dentry, /*force_reval*/0);
29655 + au_refresh_dop(dentry, /*force_reval*/1);
29661 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29663 + int err, i, j, ndentry, e;
29664 + unsigned int sigen;
29665 + struct au_dcsub_pages dpages;
29666 + struct au_dpage *dpage;
29667 + struct dentry **dentries, *d;
29668 + struct au_sbinfo *sbinfo;
29669 + struct dentry *root = sb->s_root;
29670 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29673 + au_refresh_dop(root, /*force_reval*/0);
29675 + err = au_dpages_init(&dpages, GFP_NOFS);
29676 + if (unlikely(err))
29678 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29679 + if (unlikely(err))
29682 + sigen = au_sigen(sb);
29683 + sbinfo = au_sbi(sb);
29684 + for (i = 0; i < dpages.ndpage; i++) {
29685 + dpage = dpages.dpages + i;
29686 + dentries = dpage->dentries;
29687 + ndentry = dpage->ndentry;
29688 + for (j = 0; j < ndentry; j++) {
29690 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29692 + if (unlikely(e && !err))
29694 + /* go on even err */
29699 + au_dpages_free(&dpages);
29704 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29707 + unsigned int sigen;
29708 + unsigned long long max, ull;
29709 + struct inode *inode, **array;
29711 + array = au_iarray_alloc(sb, &max);
29712 + err = PTR_ERR(array);
29713 + if (IS_ERR(array))
29717 + sigen = au_sigen(sb);
29718 + for (ull = 0; ull < max; ull++) {
29719 + inode = array[ull];
29720 + if (unlikely(!inode))
29724 + ii_write_lock_child(inode);
29725 + if (au_iigen(inode, NULL) != sigen) {
29726 + e = au_refresh_hinode_self(inode);
29727 + if (unlikely(e)) {
29728 + au_refresh_iop(inode, /*force_getattr*/1);
29729 + pr_err("error %d, i%lu\n", e, inode->i_ino);
29732 + /* go on even if err */
29735 + if (!e && do_idop)
29736 + au_refresh_iop(inode, /*force_getattr*/0);
29737 + ii_write_unlock(inode);
29740 + au_iarray_free(array, max);
29746 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
29749 + unsigned int udba;
29750 + aufs_bindex_t bindex, bbot;
29751 + struct dentry *root;
29752 + struct inode *inode;
29753 + struct au_branch *br;
29754 + struct au_sbinfo *sbi;
29756 + au_sigen_inc(sb);
29757 + sbi = au_sbi(sb);
29758 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
29760 + root = sb->s_root;
29761 + DiMustNoWaiters(root);
29762 + inode = d_inode(root);
29763 + IiMustNoWaiters(inode);
29765 + udba = au_opt_udba(sb);
29766 + bbot = au_sbbot(sb);
29767 + for (bindex = 0; bindex <= bbot; bindex++) {
29768 + br = au_sbr(sb, bindex);
29769 + err = au_hnotify_reset_br(udba, br, br->br_perm);
29770 + if (unlikely(err))
29771 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
29773 + /* go on even if err */
29775 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
29778 + if (au_ftest_si(sbi, NO_DREVAL)) {
29779 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
29780 + sb->s_d_op = &aufs_dop_noreval;
29781 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
29782 + sbi->si_iop_array = aufs_iop_nogetattr;
29784 + AuDebugOn(sb->s_d_op == &aufs_dop);
29785 + sb->s_d_op = &aufs_dop;
29786 + AuDebugOn(sbi->si_iop_array == aufs_iop);
29787 + sbi->si_iop_array = aufs_iop;
29789 + pr_info("reset to %pf and %pf\n",
29790 + sb->s_d_op, sbi->si_iop_array);
29793 + di_write_unlock(root);
29794 + err = au_refresh_d(sb, do_idop);
29795 + e = au_refresh_i(sb, do_idop);
29796 + if (unlikely(e && !err))
29798 + /* aufs_write_lock() calls ..._child() */
29799 + di_write_lock_child(root);
29801 + au_cpup_attr_all(inode, /*force*/1);
29803 + if (unlikely(err))
29804 + AuIOErr("refresh failed, ignored, %d\n", err);
29807 +/* stop extra interpretation of errno in mount(8), and strange error messages */
29808 +static int cvt_err(int err)
29822 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
29825 + unsigned int mntflags;
29826 + struct au_opts opts = {
29829 + struct dentry *root;
29830 + struct inode *inode;
29831 + struct au_sbinfo *sbinfo;
29834 + root = sb->s_root;
29835 + if (!data || !*data) {
29836 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29838 + di_write_lock_child(root);
29839 + err = au_opts_verify(sb, *flags, /*pending*/0);
29840 + aufs_write_unlock(root);
29846 + opts.opt = (void *)__get_free_page(GFP_NOFS);
29847 + if (unlikely(!opts.opt))
29849 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
29850 + opts.flags = AuOpts_REMOUNT;
29851 + opts.sb_flags = *flags;
29853 + /* parse it before aufs lock */
29854 + err = au_opts_parse(sb, data, &opts);
29855 + if (unlikely(err))
29858 + sbinfo = au_sbi(sb);
29859 + inode = d_inode(root);
29860 + inode_lock(inode);
29861 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29862 + if (unlikely(err))
29864 + di_write_lock_child(root);
29866 + /* au_opts_remount() may return an error */
29867 + err = au_opts_remount(sb, &opts);
29868 + au_opts_free(&opts);
29870 + if (au_ftest_opts(opts.flags, REFRESH))
29871 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
29873 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
29874 + mntflags = au_mntflags(sb);
29875 + do_dx = !!au_opt_test(mntflags, DIO);
29876 + au_dy_arefresh(do_dx);
29879 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
29880 + aufs_write_unlock(root);
29883 + inode_unlock(inode);
29885 + free_page((unsigned long)opts.opt);
29887 + err = cvt_err(err);
29892 +static const struct super_operations aufs_sop = {
29893 + .alloc_inode = aufs_alloc_inode,
29894 + .destroy_inode = aufs_destroy_inode,
29895 + /* always deleting, no clearing */
29896 + .drop_inode = generic_delete_inode,
29897 + .show_options = aufs_show_options,
29898 + .statfs = aufs_statfs,
29899 + .put_super = aufs_put_super,
29900 + .sync_fs = aufs_sync_fs,
29901 + .remount_fs = aufs_remount_fs
29904 +/* ---------------------------------------------------------------------- */
29906 +static int alloc_root(struct super_block *sb)
29909 + struct inode *inode;
29910 + struct dentry *root;
29913 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
29914 + err = PTR_ERR(inode);
29915 + if (IS_ERR(inode))
29918 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
29919 + inode->i_fop = &aufs_dir_fop;
29920 + inode->i_mode = S_IFDIR;
29921 + set_nlink(inode, 2);
29922 + unlock_new_inode(inode);
29924 + root = d_make_root(inode);
29925 + if (unlikely(!root))
29927 + err = PTR_ERR(root);
29928 + if (IS_ERR(root))
29931 + err = au_di_init(root);
29933 + sb->s_root = root;
29934 + return 0; /* success */
29942 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
29943 + int silent __maybe_unused)
29946 + struct au_opts opts = {
29949 + struct au_sbinfo *sbinfo;
29950 + struct dentry *root;
29951 + struct inode *inode;
29952 + char *arg = raw_data;
29954 + if (unlikely(!arg || !*arg)) {
29956 + pr_err("no arg\n");
29961 + opts.opt = (void *)__get_free_page(GFP_NOFS);
29962 + if (unlikely(!opts.opt))
29964 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
29965 + opts.sb_flags = sb->s_flags;
29967 + err = au_si_alloc(sb);
29968 + if (unlikely(err))
29970 + sbinfo = au_sbi(sb);
29972 + /* all timestamps always follow the ones on the branch */
29973 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
29974 + sb->s_op = &aufs_sop;
29975 + sb->s_d_op = &aufs_dop;
29976 + sb->s_magic = AUFS_SUPER_MAGIC;
29977 + sb->s_maxbytes = 0;
29978 + sb->s_stack_depth = 1;
29979 + au_export_init(sb);
29980 + au_xattr_init(sb);
29982 + err = alloc_root(sb);
29983 + if (unlikely(err)) {
29984 + si_write_unlock(sb);
29987 + root = sb->s_root;
29988 + inode = d_inode(root);
29991 + * actually we can parse options regardless aufs lock here.
29992 + * but at remount time, parsing must be done before aufs lock.
29993 + * so we follow the same rule.
29995 + ii_write_lock_parent(inode);
29996 + aufs_write_unlock(root);
29997 + err = au_opts_parse(sb, arg, &opts);
29998 + if (unlikely(err))
30001 + /* lock vfs_inode first, then aufs. */
30002 + inode_lock(inode);
30003 + aufs_write_lock(root);
30004 + err = au_opts_mount(sb, &opts);
30005 + au_opts_free(&opts);
30006 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30007 + sb->s_d_op = &aufs_dop_noreval;
30008 + pr_info("%pf\n", sb->s_d_op);
30009 + au_refresh_dop(root, /*force_reval*/0);
30010 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30011 + au_refresh_iop(inode, /*force_getattr*/0);
30013 + aufs_write_unlock(root);
30014 + inode_unlock(inode);
30016 + goto out_opts; /* success */
30020 + sb->s_root = NULL;
30022 + dbgaufs_si_fin(sbinfo);
30023 + kobject_put(&sbinfo->si_kobj);
30024 + sb->s_fs_info = NULL;
30026 + free_page((unsigned long)opts.opt);
30029 + err = cvt_err(err);
30034 +/* ---------------------------------------------------------------------- */
30036 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30037 + const char *dev_name __maybe_unused,
30040 + struct dentry *root;
30041 + struct super_block *sb;
30043 + /* all timestamps always follow the ones on the branch */
30044 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30045 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30046 + if (IS_ERR(root))
30050 + si_write_lock(sb, !AuLock_FLUSH);
30051 + sysaufs_brs_add(sb, 0);
30052 + si_write_unlock(sb);
30053 + au_sbilist_add(sb);
30059 +static void aufs_kill_sb(struct super_block *sb)
30061 + struct au_sbinfo *sbinfo;
30063 + sbinfo = au_sbi(sb);
30065 + au_sbilist_del(sb);
30066 + aufs_write_lock(sb->s_root);
30068 + if (sbinfo->si_wbr_create_ops->fin)
30069 + sbinfo->si_wbr_create_ops->fin(sb);
30070 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30071 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30072 + au_remount_refresh(sb, /*do_idop*/0);
30074 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30075 + au_plink_put(sb, /*verbose*/1);
30077 + au_dr_opt_flush(sb);
30078 + sbinfo->si_sb = NULL;
30079 + aufs_write_unlock(sb->s_root);
30080 + au_nwt_flush(&sbinfo->si_nowait);
30082 + kill_anon_super(sb);
30085 +struct file_system_type aufs_fs_type = {
30086 + .name = AUFS_FSTYPE,
30087 + /* a race between rename and others */
30088 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30089 + .mount = aufs_mount,
30090 + .kill_sb = aufs_kill_sb,
30091 + /* no need to __module_get() and module_put(). */
30092 + .owner = THIS_MODULE,
30094 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30095 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30096 +++ linux/fs/aufs/super.h 2017-11-12 22:24:44.707577830 +0100
30099 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30101 + * This program, aufs is free software; you can redistribute it and/or modify
30102 + * it under the terms of the GNU General Public License as published by
30103 + * the Free Software Foundation; either version 2 of the License, or
30104 + * (at your option) any later version.
30106 + * This program is distributed in the hope that it will be useful,
30107 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30109 + * GNU General Public License for more details.
30111 + * You should have received a copy of the GNU General Public License
30112 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30116 + * super_block operations
30119 +#ifndef __AUFS_SUPER_H__
30120 +#define __AUFS_SUPER_H__
30124 +#include <linux/fs.h>
30125 +#include <linux/kobject.h>
30127 +#include "rwsem.h"
30130 +/* policies to select one among multiple writable branches */
30131 +struct au_wbr_copyup_operations {
30132 + int (*copyup)(struct dentry *dentry);
30135 +#define AuWbr_DIR 1 /* target is a dir */
30136 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30138 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30139 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30140 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30142 +struct au_wbr_create_operations {
30143 + int (*create)(struct dentry *dentry, unsigned int flags);
30144 + int (*init)(struct super_block *sb);
30145 + int (*fin)(struct super_block *sb);
30148 +struct au_wbr_mfs {
30149 + struct mutex mfs_lock; /* protect this structure */
30150 + unsigned long mfs_jiffy;
30151 + unsigned long mfs_expire;
30152 + aufs_bindex_t mfs_bindex;
30154 + unsigned long long mfsrr_bytes;
30155 + unsigned long long mfsrr_watermark;
30158 +#define AuPlink_NHASH 100
30159 +static inline int au_plink_hash(ino_t ino)
30161 + return ino % AuPlink_NHASH;
30164 +/* File-based Hierarchical Storage Management */
30166 +#ifdef CONFIG_AUFS_FHSM
30167 + /* allow only one process who can receive the notification */
30168 + spinlock_t fhsm_spin;
30170 + wait_queue_head_t fhsm_wqh;
30171 + atomic_t fhsm_readable;
30173 + /* these are protected by si_rwsem */
30174 + unsigned long fhsm_expire;
30175 + aufs_bindex_t fhsm_bottom;
30180 +struct au_sbinfo {
30181 + /* nowait tasks in the system-wide workqueue */
30182 + struct au_nowait_tasks si_nowait;
30185 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
30186 + * rwsem for au_sbinfo is necessary.
30188 + struct au_rwsem si_rwsem;
30191 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30194 + struct percpu_counter si_ninodes, si_nfiles;
30196 + /* branch management */
30197 + unsigned int si_generation;
30199 + /* see AuSi_ flags */
30200 + unsigned char au_si_status;
30202 + aufs_bindex_t si_bbot;
30204 + /* dirty trick to keep br_id plus */
30205 + unsigned int si_last_br_id :
30206 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30207 + struct au_branch **si_branch;
30209 + /* policy to select a writable branch */
30210 + unsigned char si_wbr_copyup;
30211 + unsigned char si_wbr_create;
30212 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30213 + struct au_wbr_create_operations *si_wbr_create_ops;
30215 + /* round robin */
30216 + atomic_t si_wbr_rr_next;
30218 + /* most free space */
30219 + struct au_wbr_mfs si_wbr_mfs;
30221 + /* File-based Hierarchical Storage Management */
30222 + struct au_fhsm si_fhsm;
30224 + /* mount flags */
30225 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30226 + unsigned int si_mntflags;
30228 + /* external inode number (bitmap and translation table) */
30229 + vfs_readf_t si_xread;
30230 + vfs_writef_t si_xwrite;
30231 + struct file *si_xib;
30232 + struct mutex si_xib_mtx; /* protect xib members */
30233 + unsigned long *si_xib_buf;
30234 + unsigned long si_xib_last_pindex;
30235 + int si_xib_next_bit;
30236 + aufs_bindex_t si_xino_brid;
30237 + unsigned long si_xino_jiffy;
30238 + unsigned long si_xino_expire;
30239 + /* reserved for future use */
30240 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30242 +#ifdef CONFIG_AUFS_EXPORT
30243 + /* i_generation */
30244 + struct file *si_xigen;
30245 + atomic_t si_xigen_next;
30248 + /* dirty trick to suppoer atomic_open */
30249 + struct hlist_bl_head si_aopen;
30251 + /* vdir parameters */
30252 + unsigned long si_rdcache; /* max cache time in jiffies */
30253 + unsigned int si_rdblk; /* deblk size */
30254 + unsigned int si_rdhash; /* hash size */
30257 + * If the number of whiteouts are larger than si_dirwh, leave all of
30258 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30259 + * future fsck.aufs or kernel thread will remove them later.
30260 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30262 + unsigned int si_dirwh;
30264 + /* pseudo_link list */
30265 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30266 + wait_queue_head_t si_plink_wq;
30267 + spinlock_t si_plink_maint_lock;
30268 + pid_t si_plink_maint_pid;
30271 + struct hlist_bl_head si_files;
30273 + /* with/without getattr, brother of sb->s_d_op */
30274 + struct inode_operations *si_iop_array;
30277 + * sysfs and lifetime management.
30278 + * this is not a small structure and it may be a waste of memory in case
30279 + * of sysfs is disabled, particulary when many aufs-es are mounted.
30280 + * but using sysfs is majority.
30282 + struct kobject si_kobj;
30283 +#ifdef CONFIG_DEBUG_FS
30284 + struct dentry *si_dbgaufs;
30285 + struct dentry *si_dbgaufs_plink;
30286 + struct dentry *si_dbgaufs_xib;
30287 +#ifdef CONFIG_AUFS_EXPORT
30288 + struct dentry *si_dbgaufs_xigen;
30292 +#ifdef CONFIG_AUFS_SBILIST
30293 + struct hlist_bl_node si_list;
30296 + /* dirty, necessary for unmounting, sysfs and sysrq */
30297 + struct super_block *si_sb;
30300 +/* sbinfo status flags */
30302 + * set true when refresh_dirs() failed at remount time.
30303 + * then try refreshing dirs at access time again.
30304 + * if it is false, refreshing dirs at access time is unnecesary
30306 +#define AuSi_FAILED_REFRESH_DIR 1
30307 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30308 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30310 +#ifndef CONFIG_AUFS_FHSM
30312 +#define AuSi_FHSM 0
30315 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30316 + unsigned int flag)
30318 + AuRwMustAnyLock(&sbi->si_rwsem);
30319 + return sbi->au_si_status & flag;
30321 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30322 +#define au_fset_si(sbinfo, name) do { \
30323 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30324 + (sbinfo)->au_si_status |= AuSi_##name; \
30326 +#define au_fclr_si(sbinfo, name) do { \
30327 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30328 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30331 +/* ---------------------------------------------------------------------- */
30333 +/* policy to select one among writable branches */
30334 +#define AuWbrCopyup(sbinfo, ...) \
30335 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30336 +#define AuWbrCreate(sbinfo, ...) \
30337 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30339 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30340 +#define AuLock_DW 1 /* write-lock dentry */
30341 +#define AuLock_IR (1 << 1) /* read-lock inode */
30342 +#define AuLock_IW (1 << 2) /* write-lock inode */
30343 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30344 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30345 + /* except RENAME_EXCHANGE */
30346 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30347 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30348 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30349 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30350 +#define au_fset_lock(flags, name) \
30351 + do { (flags) |= AuLock_##name; } while (0)
30352 +#define au_fclr_lock(flags, name) \
30353 + do { (flags) &= ~AuLock_##name; } while (0)
30355 +/* ---------------------------------------------------------------------- */
30358 +extern struct file_system_type aufs_fs_type;
30359 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30360 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30361 + unsigned long long max, void *arg);
30362 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30363 + struct super_block *sb, void *arg);
30364 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30365 +void au_iarray_free(struct inode **a, unsigned long long max);
30368 +void au_si_free(struct kobject *kobj);
30369 +int au_si_alloc(struct super_block *sb);
30370 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30372 +unsigned int au_sigen_inc(struct super_block *sb);
30373 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30375 +int si_read_lock(struct super_block *sb, int flags);
30376 +int si_write_lock(struct super_block *sb, int flags);
30377 +int aufs_read_lock(struct dentry *dentry, int flags);
30378 +void aufs_read_unlock(struct dentry *dentry, int flags);
30379 +void aufs_write_lock(struct dentry *dentry);
30380 +void aufs_write_unlock(struct dentry *dentry);
30381 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30382 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30384 +/* wbr_policy.c */
30385 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30386 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30387 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30388 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30389 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30392 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30394 +#ifdef CONFIG_AUFS_FHSM
30397 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30401 + spin_lock(&fhsm->fhsm_spin);
30402 + pid = fhsm->fhsm_pid;
30403 + spin_unlock(&fhsm->fhsm_spin);
30408 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30409 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30410 +int au_fhsm_fd(struct super_block *sb, int oflags);
30411 +int au_fhsm_br_alloc(struct au_branch *br);
30412 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30413 +void au_fhsm_fin(struct super_block *sb);
30414 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30415 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30416 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30418 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30420 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30421 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30422 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30423 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30424 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30425 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30426 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30427 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30428 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30431 +/* ---------------------------------------------------------------------- */
30433 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30435 + return sb->s_fs_info;
30438 +/* ---------------------------------------------------------------------- */
30440 +#ifdef CONFIG_AUFS_EXPORT
30441 +int au_test_nfsd(void);
30442 +void au_export_init(struct super_block *sb);
30443 +void au_xigen_inc(struct inode *inode);
30444 +int au_xigen_new(struct inode *inode);
30445 +int au_xigen_set(struct super_block *sb, struct file *base);
30446 +void au_xigen_clr(struct super_block *sb);
30448 +static inline int au_busy_or_stale(void)
30450 + if (!au_test_nfsd())
30455 +AuStubInt0(au_test_nfsd, void)
30456 +AuStubVoid(au_export_init, struct super_block *sb)
30457 +AuStubVoid(au_xigen_inc, struct inode *inode)
30458 +AuStubInt0(au_xigen_new, struct inode *inode)
30459 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
30460 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30461 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30462 +#endif /* CONFIG_AUFS_EXPORT */
30464 +/* ---------------------------------------------------------------------- */
30466 +#ifdef CONFIG_AUFS_SBILIST
30468 +extern struct hlist_bl_head au_sbilist;
30470 +static inline void au_sbilist_init(void)
30472 + INIT_HLIST_BL_HEAD(&au_sbilist);
30475 +static inline void au_sbilist_add(struct super_block *sb)
30477 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30480 +static inline void au_sbilist_del(struct super_block *sb)
30482 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30485 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30486 +static inline void au_sbilist_lock(void)
30488 + hlist_bl_lock(&au_sbilist);
30491 +static inline void au_sbilist_unlock(void)
30493 + hlist_bl_unlock(&au_sbilist);
30495 +#define AuGFP_SBILIST GFP_ATOMIC
30497 +AuStubVoid(au_sbilist_lock, void)
30498 +AuStubVoid(au_sbilist_unlock, void)
30499 +#define AuGFP_SBILIST GFP_NOFS
30500 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30502 +AuStubVoid(au_sbilist_init, void)
30503 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30504 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30505 +AuStubVoid(au_sbilist_lock, void)
30506 +AuStubVoid(au_sbilist_unlock, void)
30507 +#define AuGFP_SBILIST GFP_NOFS
30510 +/* ---------------------------------------------------------------------- */
30512 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30515 + * This function is a dynamic '__init' function actually,
30516 + * so the tiny check for si_rwsem is unnecessary.
30518 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30519 +#ifdef CONFIG_DEBUG_FS
30520 + sbinfo->si_dbgaufs = NULL;
30521 + sbinfo->si_dbgaufs_plink = NULL;
30522 + sbinfo->si_dbgaufs_xib = NULL;
30523 +#ifdef CONFIG_AUFS_EXPORT
30524 + sbinfo->si_dbgaufs_xigen = NULL;
30529 +/* ---------------------------------------------------------------------- */
30531 +/* current->atomic_flags */
30532 +/* this value should never corrupt the ones defined in linux/sched.h */
30533 +#define PFA_AUFS 7
30535 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30536 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30537 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30539 +static inline int si_pid_test(struct super_block *sb)
30541 + return !!task_test_aufs(current);
30544 +static inline void si_pid_clr(struct super_block *sb)
30546 + AuDebugOn(!task_test_aufs(current));
30547 + task_clear_aufs(current);
30550 +static inline void si_pid_set(struct super_block *sb)
30552 + AuDebugOn(task_test_aufs(current));
30553 + task_set_aufs(current);
30556 +/* ---------------------------------------------------------------------- */
30558 +/* lock superblock. mainly for entry point functions */
30559 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30560 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30561 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30562 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30564 +#define __si_read_trylock_nested(sb) \
30565 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30566 +#define __si_write_trylock_nested(sb) \
30567 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30570 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30571 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30572 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30574 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30575 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30576 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30578 +static inline void si_noflush_read_lock(struct super_block *sb)
30580 + __si_read_lock(sb);
30584 +static inline int si_noflush_read_trylock(struct super_block *sb)
30588 + locked = __si_read_trylock(sb);
30594 +static inline void si_noflush_write_lock(struct super_block *sb)
30596 + __si_write_lock(sb);
30600 +static inline int si_noflush_write_trylock(struct super_block *sb)
30604 + locked = __si_write_trylock(sb);
30610 +#if 0 /* reserved */
30611 +static inline int si_read_trylock(struct super_block *sb, int flags)
30613 + if (au_ftest_lock(flags, FLUSH))
30614 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30615 + return si_noflush_read_trylock(sb);
30619 +static inline void si_read_unlock(struct super_block *sb)
30622 + __si_read_unlock(sb);
30625 +#if 0 /* reserved */
30626 +static inline int si_write_trylock(struct super_block *sb, int flags)
30628 + if (au_ftest_lock(flags, FLUSH))
30629 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30630 + return si_noflush_write_trylock(sb);
30634 +static inline void si_write_unlock(struct super_block *sb)
30637 + __si_write_unlock(sb);
30640 +#if 0 /* reserved */
30641 +static inline void si_downgrade_lock(struct super_block *sb)
30643 + __si_downgrade_lock(sb);
30647 +/* ---------------------------------------------------------------------- */
30649 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30651 + SiMustAnyLock(sb);
30652 + return au_sbi(sb)->si_bbot;
30655 +static inline unsigned int au_mntflags(struct super_block *sb)
30657 + SiMustAnyLock(sb);
30658 + return au_sbi(sb)->si_mntflags;
30661 +static inline unsigned int au_sigen(struct super_block *sb)
30663 + SiMustAnyLock(sb);
30664 + return au_sbi(sb)->si_generation;
30667 +static inline unsigned long long au_ninodes(struct super_block *sb)
30669 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
30675 +static inline void au_ninodes_inc(struct super_block *sb)
30677 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
30680 +static inline void au_ninodes_dec(struct super_block *sb)
30682 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
30685 +static inline unsigned long long au_nfiles(struct super_block *sb)
30687 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
30693 +static inline void au_nfiles_inc(struct super_block *sb)
30695 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
30698 +static inline void au_nfiles_dec(struct super_block *sb)
30700 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
30703 +static inline struct au_branch *au_sbr(struct super_block *sb,
30704 + aufs_bindex_t bindex)
30706 + SiMustAnyLock(sb);
30707 + return au_sbi(sb)->si_branch[0 + bindex];
30710 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
30712 + SiMustWriteLock(sb);
30713 + au_sbi(sb)->si_xino_brid = brid;
30716 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
30718 + SiMustAnyLock(sb);
30719 + return au_sbi(sb)->si_xino_brid;
30722 +#endif /* __KERNEL__ */
30723 +#endif /* __AUFS_SUPER_H__ */
30724 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30725 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30726 +++ linux/fs/aufs/sysaufs.c 2017-07-29 12:14:25.906375514 +0200
30729 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30731 + * This program, aufs is free software; you can redistribute it and/or modify
30732 + * it under the terms of the GNU General Public License as published by
30733 + * the Free Software Foundation; either version 2 of the License, or
30734 + * (at your option) any later version.
30736 + * This program is distributed in the hope that it will be useful,
30737 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30738 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30739 + * GNU General Public License for more details.
30741 + * You should have received a copy of the GNU General Public License
30742 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30746 + * sysfs interface and lifetime management
30747 + * they are necessary regardless sysfs is disabled.
30750 +#include <linux/random.h>
30753 +unsigned long sysaufs_si_mask;
30754 +struct kset *sysaufs_kset;
30756 +#define AuSiAttr(_name) { \
30757 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30758 + .show = sysaufs_si_##_name, \
30761 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30762 +struct attribute *sysaufs_si_attrs[] = {
30763 + &sysaufs_si_attr_xi_path.attr,
30767 +static const struct sysfs_ops au_sbi_ops = {
30768 + .show = sysaufs_si_show
30771 +static struct kobj_type au_sbi_ktype = {
30772 + .release = au_si_free,
30773 + .sysfs_ops = &au_sbi_ops,
30774 + .default_attrs = sysaufs_si_attrs
30777 +/* ---------------------------------------------------------------------- */
30779 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
30783 + sbinfo->si_kobj.kset = sysaufs_kset;
30784 + /* cf. sysaufs_name() */
30785 + err = kobject_init_and_add
30786 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
30787 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
30789 + dbgaufs_si_null(sbinfo);
30791 + err = dbgaufs_si_init(sbinfo);
30792 + if (unlikely(err))
30793 + kobject_put(&sbinfo->si_kobj);
30798 +void sysaufs_fin(void)
30801 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30802 + kset_unregister(sysaufs_kset);
30805 +int __init sysaufs_init(void)
30810 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
30811 + } while (!sysaufs_si_mask);
30814 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
30815 + if (unlikely(!sysaufs_kset))
30817 + err = PTR_ERR(sysaufs_kset);
30818 + if (IS_ERR(sysaufs_kset))
30820 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30821 + if (unlikely(err)) {
30822 + kset_unregister(sysaufs_kset);
30826 + err = dbgaufs_init();
30827 + if (unlikely(err))
30832 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
30833 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
30834 +++ linux/fs/aufs/sysaufs.h 2017-07-29 12:14:25.906375514 +0200
30837 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30839 + * This program, aufs is free software; you can redistribute it and/or modify
30840 + * it under the terms of the GNU General Public License as published by
30841 + * the Free Software Foundation; either version 2 of the License, or
30842 + * (at your option) any later version.
30844 + * This program is distributed in the hope that it will be useful,
30845 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30846 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30847 + * GNU General Public License for more details.
30849 + * You should have received a copy of the GNU General Public License
30850 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30854 + * sysfs interface and mount lifetime management
30857 +#ifndef __SYSAUFS_H__
30858 +#define __SYSAUFS_H__
30862 +#include <linux/sysfs.h>
30863 +#include "module.h"
30865 +struct super_block;
30868 +struct sysaufs_si_attr {
30869 + struct attribute attr;
30870 + int (*show)(struct seq_file *seq, struct super_block *sb);
30873 +/* ---------------------------------------------------------------------- */
30876 +extern unsigned long sysaufs_si_mask;
30877 +extern struct kset *sysaufs_kset;
30878 +extern struct attribute *sysaufs_si_attrs[];
30879 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
30880 +int __init sysaufs_init(void);
30881 +void sysaufs_fin(void);
30883 +/* ---------------------------------------------------------------------- */
30885 +/* some people doesn't like to show a pointer in kernel */
30886 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
30888 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
30891 +#define SysaufsSiNamePrefix "si_"
30892 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
30893 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
30895 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
30896 + sysaufs_si_id(sbinfo));
30900 +#ifdef CONFIG_SYSFS
30902 +extern struct attribute_group *sysaufs_attr_group;
30904 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
30905 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
30907 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
30908 +#ifdef CONFIG_COMPAT
30909 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
30912 +void sysaufs_br_init(struct au_branch *br);
30913 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
30914 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
30916 +#define sysaufs_brs_init() do {} while (0)
30919 +#define sysaufs_attr_group NULL
30921 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
30922 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
30923 + struct attribute *attr, char *buf)
30924 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
30925 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
30926 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
30928 +static inline void sysaufs_brs_init(void)
30933 +#endif /* CONFIG_SYSFS */
30935 +#endif /* __KERNEL__ */
30936 +#endif /* __SYSAUFS_H__ */
30937 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
30938 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
30939 +++ linux/fs/aufs/sysfs.c 2017-11-12 22:24:42.274176929 +0100
30942 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30944 + * This program, aufs is free software; you can redistribute it and/or modify
30945 + * it under the terms of the GNU General Public License as published by
30946 + * the Free Software Foundation; either version 2 of the License, or
30947 + * (at your option) any later version.
30949 + * This program is distributed in the hope that it will be useful,
30950 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30951 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30952 + * GNU General Public License for more details.
30954 + * You should have received a copy of the GNU General Public License
30955 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30959 + * sysfs interface
30962 +#include <linux/compat.h>
30963 +#include <linux/seq_file.h>
30966 +#ifdef CONFIG_AUFS_FS_MODULE
30967 +/* this entry violates the "one line per file" policy of sysfs */
30968 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
30972 + static char *conf =
30973 +/* this file is generated at compiling */
30974 +#include "conf.str"
30977 + err = snprintf(buf, PAGE_SIZE, conf);
30978 + if (unlikely(err >= PAGE_SIZE))
30983 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
30986 +static struct attribute *au_attr[] = {
30987 +#ifdef CONFIG_AUFS_FS_MODULE
30988 + &au_config_attr.attr,
30990 + NULL, /* need to NULL terminate the list of attributes */
30993 +static struct attribute_group sysaufs_attr_group_body = {
30997 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
30999 +/* ---------------------------------------------------------------------- */
31001 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31005 + SiMustAnyLock(sb);
31008 + if (au_opt_test(au_mntflags(sb), XINO)) {
31009 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31010 + seq_putc(seq, '\n');
31016 + * the lifetime of branch is independent from the entry under sysfs.
31017 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31020 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31021 + aufs_bindex_t bindex, int idx)
31024 + struct path path;
31025 + struct dentry *root;
31026 + struct au_branch *br;
31027 + au_br_perm_str_t perm;
31029 + AuDbg("b%d\n", bindex);
31032 + root = sb->s_root;
31033 + di_read_lock_parent(root, !AuLock_IR);
31034 + br = au_sbr(sb, bindex);
31037 + case AuBrSysfs_BR:
31038 + path.mnt = au_br_mnt(br);
31039 + path.dentry = au_h_dptr(root, bindex);
31040 + err = au_seq_path(seq, &path);
31042 + au_optstr_br_perm(&perm, br->br_perm);
31043 + seq_printf(seq, "=%s\n", perm.a);
31046 + case AuBrSysfs_BRID:
31047 + seq_printf(seq, "%d\n", br->br_id);
31050 + di_read_unlock(root, !AuLock_IR);
31051 + if (unlikely(err || seq_has_overflowed(seq)))
31057 +/* ---------------------------------------------------------------------- */
31059 +static struct seq_file *au_seq(char *p, ssize_t len)
31061 + struct seq_file *seq;
31063 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31065 + /* mutex_init(&seq.lock); */
31068 + return seq; /* success */
31071 + seq = ERR_PTR(-ENOMEM);
31075 +#define SysaufsBr_PREFIX "br"
31076 +#define SysaufsBrid_PREFIX "brid"
31078 +/* todo: file size may exceed PAGE_SIZE */
31079 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31085 + aufs_bindex_t bbot;
31086 + struct au_sbinfo *sbinfo;
31087 + struct super_block *sb;
31088 + struct seq_file *seq;
31090 + struct attribute **cattr;
31092 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31093 + sb = sbinfo->si_sb;
31096 + * prevent a race condition between sysfs and aufs.
31097 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31098 + * prohibits maintaining the sysfs entries.
31099 + * hew we acquire read lock after sysfs_get_active_two().
31100 + * on the other hand, the remount process may maintain the sysfs/aufs
31101 + * entries after acquiring write lock.
31102 + * it can cause a deadlock.
31103 + * simply we gave up processing read here.
31106 + if (unlikely(!si_noflush_read_trylock(sb)))
31109 + seq = au_seq(buf, PAGE_SIZE);
31110 + err = PTR_ERR(seq);
31114 + name = (void *)attr->name;
31115 + cattr = sysaufs_si_attrs;
31117 + if (!strcmp(name, (*cattr)->name)) {
31118 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31125 + if (!strncmp(name, SysaufsBrid_PREFIX,
31126 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31127 + idx = AuBrSysfs_BRID;
31128 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31129 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31130 + sizeof(SysaufsBr_PREFIX) - 1)) {
31131 + idx = AuBrSysfs_BR;
31132 + name += sizeof(SysaufsBr_PREFIX) - 1;
31136 + err = kstrtol(name, 10, &l);
31138 + bbot = au_sbbot(sb);
31140 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31147 + err = seq->count;
31148 + /* sysfs limit */
31149 + if (unlikely(err == PAGE_SIZE))
31154 + si_read_unlock(sb);
31159 +/* ---------------------------------------------------------------------- */
31161 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31165 + aufs_bindex_t bindex, bbot;
31168 + struct seq_file *seq;
31169 + struct au_branch *br;
31171 + si_read_lock(sb, AuLock_FLUSH);
31172 + bbot = au_sbbot(sb);
31178 + buf = (void *)__get_free_page(GFP_NOFS);
31179 + if (unlikely(!buf))
31182 + seq = au_seq(buf, PAGE_SIZE);
31183 + err = PTR_ERR(seq);
31187 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31188 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31189 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31190 + if (unlikely(err))
31193 + br = au_sbr(sb, bindex);
31194 + brid = br->br_id;
31195 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31196 + err = __put_user(brid, &arg->id);
31197 + if (unlikely(err))
31200 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31201 + err = __put_user(br->br_perm, &arg->perm);
31202 + if (unlikely(err))
31205 + err = au_seq_path(seq, &br->br_path);
31206 + if (unlikely(err))
31208 + seq_putc(seq, '\0');
31209 + if (!seq_has_overflowed(seq)) {
31210 + err = copy_to_user(arg->path, seq->buf, seq->count);
31212 + if (unlikely(err))
31219 + if (unlikely(err))
31225 + free_page((unsigned long)buf);
31227 + si_read_unlock(sb);
31231 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31233 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31236 +#ifdef CONFIG_COMPAT
31237 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31239 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31243 +/* ---------------------------------------------------------------------- */
31245 +void sysaufs_br_init(struct au_branch *br)
31248 + struct au_brsysfs *br_sysfs;
31249 + struct attribute *attr;
31251 + br_sysfs = br->br_sysfs;
31252 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31253 + attr = &br_sysfs->attr;
31254 + sysfs_attr_init(attr);
31255 + attr->name = br_sysfs->name;
31256 + attr->mode = S_IRUGO;
31261 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31263 + struct au_branch *br;
31264 + struct kobject *kobj;
31265 + struct au_brsysfs *br_sysfs;
31267 + aufs_bindex_t bbot;
31269 + dbgaufs_brs_del(sb, bindex);
31271 + if (!sysaufs_brs)
31274 + kobj = &au_sbi(sb)->si_kobj;
31275 + bbot = au_sbbot(sb);
31276 + for (; bindex <= bbot; bindex++) {
31277 + br = au_sbr(sb, bindex);
31278 + br_sysfs = br->br_sysfs;
31279 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31280 + sysfs_remove_file(kobj, &br_sysfs->attr);
31286 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31289 + aufs_bindex_t bbot;
31290 + struct kobject *kobj;
31291 + struct au_branch *br;
31292 + struct au_brsysfs *br_sysfs;
31294 + dbgaufs_brs_add(sb, bindex);
31296 + if (!sysaufs_brs)
31299 + kobj = &au_sbi(sb)->si_kobj;
31300 + bbot = au_sbbot(sb);
31301 + for (; bindex <= bbot; bindex++) {
31302 + br = au_sbr(sb, bindex);
31303 + br_sysfs = br->br_sysfs;
31304 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31305 + SysaufsBr_PREFIX "%d", bindex);
31306 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31307 + SysaufsBrid_PREFIX "%d", bindex);
31308 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31309 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31310 + if (unlikely(err))
31311 + pr_warn("failed %s under sysfs(%d)\n",
31312 + br_sysfs->name, err);
31317 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31318 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31319 +++ linux/fs/aufs/sysrq.c 2017-11-12 22:24:44.707577830 +0100
31322 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31324 + * This program, aufs is free software; you can redistribute it and/or modify
31325 + * it under the terms of the GNU General Public License as published by
31326 + * the Free Software Foundation; either version 2 of the License, or
31327 + * (at your option) any later version.
31329 + * This program is distributed in the hope that it will be useful,
31330 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31331 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31332 + * GNU General Public License for more details.
31334 + * You should have received a copy of the GNU General Public License
31335 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31339 + * magic sysrq hanlder
31342 +/* #include <linux/sysrq.h> */
31343 +#include <linux/writeback.h>
31346 +/* ---------------------------------------------------------------------- */
31348 +static void sysrq_sb(struct super_block *sb)
31351 + struct au_sbinfo *sbinfo;
31352 + struct file *file;
31353 + struct hlist_bl_head *files;
31354 + struct hlist_bl_node *pos;
31355 + struct au_finfo *finfo;
31357 + plevel = au_plevel;
31358 + au_plevel = KERN_WARNING;
31360 + /* since we define pr_fmt, call printk directly */
31361 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31363 + sbinfo = au_sbi(sb);
31364 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31365 + pr("superblock\n");
31369 + pr("root dentry\n");
31370 + au_dpri_dentry(sb->s_root);
31371 + pr("root inode\n");
31372 + au_dpri_inode(d_inode(sb->s_root));
31377 + int err, i, j, ndentry;
31378 + struct au_dcsub_pages dpages;
31379 + struct au_dpage *dpage;
31381 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31382 + if (unlikely(err))
31384 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31386 + for (i = 0; i < dpages.ndpage; i++) {
31387 + dpage = dpages.dpages + i;
31388 + ndentry = dpage->ndentry;
31389 + for (j = 0; j < ndentry; j++)
31390 + au_dpri_dentry(dpage->dentries[j]);
31392 + au_dpages_free(&dpages);
31400 + pr("isolated inode\n");
31401 + spin_lock(&sb->s_inode_list_lock);
31402 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31403 + spin_lock(&i->i_lock);
31404 + if (1 || hlist_empty(&i->i_dentry))
31405 + au_dpri_inode(i);
31406 + spin_unlock(&i->i_lock);
31408 + spin_unlock(&sb->s_inode_list_lock);
31412 + files = &au_sbi(sb)->si_files;
31413 + hlist_bl_lock(files);
31414 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31417 + file = finfo->fi_file;
31418 + mode = file_inode(file)->i_mode;
31419 + if (!special_file(mode))
31420 + au_dpri_file(file);
31422 + hlist_bl_unlock(files);
31426 + au_plevel = plevel;
31429 +/* ---------------------------------------------------------------------- */
31431 +/* module parameter */
31432 +static char *aufs_sysrq_key = "a";
31433 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
31434 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31436 +static void au_sysrq(int key __maybe_unused)
31438 + struct au_sbinfo *sbinfo;
31439 + struct hlist_bl_node *pos;
31442 + au_sbilist_lock();
31443 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31444 + sysrq_sb(sbinfo->si_sb);
31445 + au_sbilist_unlock();
31449 +static struct sysrq_key_op au_sysrq_op = {
31450 + .handler = au_sysrq,
31451 + .help_msg = "Aufs",
31452 + .action_msg = "Aufs",
31453 + .enable_mask = SYSRQ_ENABLE_DUMP
31456 +/* ---------------------------------------------------------------------- */
31458 +int __init au_sysrq_init(void)
31464 + key = *aufs_sysrq_key;
31465 + if ('a' <= key && key <= 'z')
31466 + err = register_sysrq_key(key, &au_sysrq_op);
31467 + if (unlikely(err))
31468 + pr_err("err %d, sysrq=%c\n", err, key);
31472 +void au_sysrq_fin(void)
31476 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31477 + if (unlikely(err))
31478 + pr_err("err %d (ignored)\n", err);
31480 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31481 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31482 +++ linux/fs/aufs/vdir.c 2017-11-12 22:24:42.274176929 +0100
31485 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31487 + * This program, aufs is free software; you can redistribute it and/or modify
31488 + * it under the terms of the GNU General Public License as published by
31489 + * the Free Software Foundation; either version 2 of the License, or
31490 + * (at your option) any later version.
31492 + * This program is distributed in the hope that it will be useful,
31493 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31494 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31495 + * GNU General Public License for more details.
31497 + * You should have received a copy of the GNU General Public License
31498 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31502 + * virtual or vertical directory
31507 +static unsigned int calc_size(int nlen)
31509 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31512 +static int set_deblk_end(union au_vdir_deblk_p *p,
31513 + union au_vdir_deblk_p *deblk_end)
31515 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31516 + p->de->de_str.len = 0;
31520 + return -1; /* error */
31523 +/* returns true or false */
31524 +static int is_deblk_end(union au_vdir_deblk_p *p,
31525 + union au_vdir_deblk_p *deblk_end)
31527 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31528 + return !p->de->de_str.len;
31532 +static unsigned char *last_deblk(struct au_vdir *vdir)
31534 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31537 +/* ---------------------------------------------------------------------- */
31539 +/* estimate the appropriate size for name hash table */
31540 +unsigned int au_rdhash_est(loff_t sz)
31548 + if (sz < AUFS_RDHASH_DEF)
31549 + n = AUFS_RDHASH_DEF;
31550 + /* pr_info("n %u\n", n); */
31555 + * the allocated memory has to be freed by
31556 + * au_nhash_wh_free() or au_nhash_de_free().
31558 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31560 + struct hlist_head *head;
31564 + sz = sizeof(*nhash->nh_head) * num_hash;
31565 + head = kmalloc(sz, gfp);
31567 + nhash->nh_num = num_hash;
31568 + nhash->nh_head = head;
31569 + for (u = 0; u < num_hash; u++)
31570 + INIT_HLIST_HEAD(head++);
31571 + return 0; /* success */
31577 +static void nhash_count(struct hlist_head *head)
31581 + struct hlist_node *pos;
31584 + hlist_for_each(pos, head)
31586 + pr_info("%lu\n", n);
31590 +static void au_nhash_wh_do_free(struct hlist_head *head)
31592 + struct au_vdir_wh *pos;
31593 + struct hlist_node *node;
31595 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31599 +static void au_nhash_de_do_free(struct hlist_head *head)
31601 + struct au_vdir_dehstr *pos;
31602 + struct hlist_node *node;
31604 + hlist_for_each_entry_safe(pos, node, head, hash)
31605 + au_cache_free_vdir_dehstr(pos);
31608 +static void au_nhash_do_free(struct au_nhash *nhash,
31609 + void (*free)(struct hlist_head *head))
31612 + struct hlist_head *head;
31614 + n = nhash->nh_num;
31618 + head = nhash->nh_head;
31619 + while (n-- > 0) {
31620 + nhash_count(head);
31623 + kfree(nhash->nh_head);
31626 +void au_nhash_wh_free(struct au_nhash *whlist)
31628 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31631 +static void au_nhash_de_free(struct au_nhash *delist)
31633 + au_nhash_do_free(delist, au_nhash_de_do_free);
31636 +/* ---------------------------------------------------------------------- */
31638 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31642 + unsigned int u, n;
31643 + struct hlist_head *head;
31644 + struct au_vdir_wh *pos;
31647 + n = whlist->nh_num;
31648 + head = whlist->nh_head;
31649 + for (u = 0; u < n; u++, head++)
31650 + hlist_for_each_entry(pos, head, wh_hash)
31651 + if (pos->wh_bindex == btgt && ++num > limit)
31656 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31657 + unsigned char *name,
31658 + unsigned int len)
31661 + /* const unsigned int magic_bit = 12; */
31663 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31670 + /* v = hash_long(v, magic_bit); */
31671 + v %= nhash->nh_num;
31672 + return nhash->nh_head + v;
31675 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31678 + return str->len == nlen && !memcmp(str->name, name, nlen);
31681 +/* returns found or not */
31682 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31684 + struct hlist_head *head;
31685 + struct au_vdir_wh *pos;
31686 + struct au_vdir_destr *str;
31688 + head = au_name_hash(whlist, name, nlen);
31689 + hlist_for_each_entry(pos, head, wh_hash) {
31690 + str = &pos->wh_str;
31691 + AuDbg("%.*s\n", str->len, str->name);
31692 + if (au_nhash_test_name(str, name, nlen))
31698 +/* returns found(true) or not */
31699 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31701 + struct hlist_head *head;
31702 + struct au_vdir_dehstr *pos;
31703 + struct au_vdir_destr *str;
31705 + head = au_name_hash(delist, name, nlen);
31706 + hlist_for_each_entry(pos, head, hash) {
31708 + AuDbg("%.*s\n", str->len, str->name);
31709 + if (au_nhash_test_name(str, name, nlen))
31715 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31716 + unsigned char d_type)
31718 +#ifdef CONFIG_AUFS_SHWH
31719 + wh->wh_ino = ino;
31720 + wh->wh_type = d_type;
31724 +/* ---------------------------------------------------------------------- */
31726 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31727 + unsigned int d_type, aufs_bindex_t bindex,
31728 + unsigned char shwh)
31731 + struct au_vdir_destr *str;
31732 + struct au_vdir_wh *wh;
31734 + AuDbg("%.*s\n", nlen, name);
31735 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31738 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31739 + if (unlikely(!wh))
31743 + wh->wh_bindex = bindex;
31745 + au_shwh_init_wh(wh, ino, d_type);
31746 + str = &wh->wh_str;
31748 + memcpy(str->name, name, nlen);
31749 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31756 +static int append_deblk(struct au_vdir *vdir)
31759 + unsigned long ul;
31760 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31761 + union au_vdir_deblk_p p, deblk_end;
31762 + unsigned char **o;
31765 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31766 + GFP_NOFS, /*may_shrink*/0);
31767 + if (unlikely(!o))
31770 + vdir->vd_deblk = o;
31771 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31773 + ul = vdir->vd_nblk++;
31774 + vdir->vd_deblk[ul] = p.deblk;
31775 + vdir->vd_last.ul = ul;
31776 + vdir->vd_last.p.deblk = p.deblk;
31777 + deblk_end.deblk = p.deblk + deblk_sz;
31778 + err = set_deblk_end(&p, &deblk_end);
31785 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31786 + unsigned int d_type, struct au_nhash *delist)
31790 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31791 + union au_vdir_deblk_p p, *room, deblk_end;
31792 + struct au_vdir_dehstr *dehstr;
31794 + p.deblk = last_deblk(vdir);
31795 + deblk_end.deblk = p.deblk + deblk_sz;
31796 + room = &vdir->vd_last.p;
31797 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
31798 + || !is_deblk_end(room, &deblk_end));
31800 + sz = calc_size(nlen);
31801 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
31802 + err = append_deblk(vdir);
31803 + if (unlikely(err))
31806 + p.deblk = last_deblk(vdir);
31807 + deblk_end.deblk = p.deblk + deblk_sz;
31809 + AuDebugOn(room->deblk != p.deblk);
31813 + dehstr = au_cache_alloc_vdir_dehstr();
31814 + if (unlikely(!dehstr))
31817 + dehstr->str = &room->de->de_str;
31818 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
31819 + room->de->de_ino = ino;
31820 + room->de->de_type = d_type;
31821 + room->de->de_str.len = nlen;
31822 + memcpy(room->de->de_str.name, name, nlen);
31825 + room->deblk += sz;
31826 + if (unlikely(set_deblk_end(room, &deblk_end)))
31827 + err = append_deblk(vdir);
31834 +/* ---------------------------------------------------------------------- */
31836 +void au_vdir_free(struct au_vdir *vdir)
31838 + unsigned char **deblk;
31840 + deblk = vdir->vd_deblk;
31841 + while (vdir->vd_nblk--)
31843 + kfree(vdir->vd_deblk);
31844 + au_cache_free_vdir(vdir);
31847 +static struct au_vdir *alloc_vdir(struct file *file)
31849 + struct au_vdir *vdir;
31850 + struct super_block *sb;
31853 + sb = file->f_path.dentry->d_sb;
31854 + SiMustAnyLock(sb);
31857 + vdir = au_cache_alloc_vdir();
31858 + if (unlikely(!vdir))
31861 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
31862 + if (unlikely(!vdir->vd_deblk))
31865 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
31866 + if (!vdir->vd_deblk_sz) {
31867 + /* estimate the appropriate size for deblk */
31868 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
31869 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
31871 + vdir->vd_nblk = 0;
31872 + vdir->vd_version = 0;
31873 + vdir->vd_jiffy = 0;
31874 + err = append_deblk(vdir);
31876 + return vdir; /* success */
31878 + kfree(vdir->vd_deblk);
31881 + au_cache_free_vdir(vdir);
31883 + vdir = ERR_PTR(err);
31887 +static int reinit_vdir(struct au_vdir *vdir)
31890 + union au_vdir_deblk_p p, deblk_end;
31892 + while (vdir->vd_nblk > 1) {
31893 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
31894 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
31897 + p.deblk = vdir->vd_deblk[0];
31898 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
31899 + err = set_deblk_end(&p, &deblk_end);
31900 + /* keep vd_dblk_sz */
31901 + vdir->vd_last.ul = 0;
31902 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
31903 + vdir->vd_version = 0;
31904 + vdir->vd_jiffy = 0;
31909 +/* ---------------------------------------------------------------------- */
31911 +#define AuFillVdir_CALLED 1
31912 +#define AuFillVdir_WHABLE (1 << 1)
31913 +#define AuFillVdir_SHWH (1 << 2)
31914 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
31915 +#define au_fset_fillvdir(flags, name) \
31916 + do { (flags) |= AuFillVdir_##name; } while (0)
31917 +#define au_fclr_fillvdir(flags, name) \
31918 + do { (flags) &= ~AuFillVdir_##name; } while (0)
31920 +#ifndef CONFIG_AUFS_SHWH
31921 +#undef AuFillVdir_SHWH
31922 +#define AuFillVdir_SHWH 0
31925 +struct fillvdir_arg {
31926 + struct dir_context ctx;
31927 + struct file *file;
31928 + struct au_vdir *vdir;
31929 + struct au_nhash delist;
31930 + struct au_nhash whlist;
31931 + aufs_bindex_t bindex;
31932 + unsigned int flags;
31936 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
31937 + loff_t offset __maybe_unused, u64 h_ino,
31938 + unsigned int d_type)
31940 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
31941 + char *name = (void *)__name;
31942 + struct super_block *sb;
31944 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
31947 + sb = arg->file->f_path.dentry->d_sb;
31948 + au_fset_fillvdir(arg->flags, CALLED);
31950 + if (nlen <= AUFS_WH_PFX_LEN
31951 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
31952 + if (test_known(&arg->delist, name, nlen)
31953 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
31954 + goto out; /* already exists or whiteouted */
31956 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
31958 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
31959 + d_type = DT_UNKNOWN;
31960 + arg->err = append_de(arg->vdir, name, nlen, ino,
31961 + d_type, &arg->delist);
31963 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
31964 + name += AUFS_WH_PFX_LEN;
31965 + nlen -= AUFS_WH_PFX_LEN;
31966 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
31967 + goto out; /* already whiteouted */
31970 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
31973 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
31974 + d_type = DT_UNKNOWN;
31975 + arg->err = au_nhash_append_wh
31976 + (&arg->whlist, name, nlen, ino, d_type,
31977 + arg->bindex, shwh);
31983 + arg->vdir->vd_jiffy = jiffies;
31985 + AuTraceErr(arg->err);
31989 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
31990 + struct au_nhash *whlist, struct au_nhash *delist)
31992 +#ifdef CONFIG_AUFS_SHWH
31994 + unsigned int nh, u;
31995 + struct hlist_head *head;
31996 + struct au_vdir_wh *pos;
31997 + struct hlist_node *n;
31999 + struct au_vdir_destr *destr;
32001 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32004 + o = p = (void *)__get_free_page(GFP_NOFS);
32005 + if (unlikely(!p))
32009 + nh = whlist->nh_num;
32010 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32011 + p += AUFS_WH_PFX_LEN;
32012 + for (u = 0; u < nh; u++) {
32013 + head = whlist->nh_head + u;
32014 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32015 + destr = &pos->wh_str;
32016 + memcpy(p, destr->name, destr->len);
32017 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32018 + pos->wh_ino, pos->wh_type, delist);
32019 + if (unlikely(err))
32024 + free_page((unsigned long)o);
32034 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32037 + unsigned int rdhash;
32039 + aufs_bindex_t bbot, bindex, btop;
32040 + unsigned char shwh;
32041 + struct file *hf, *file;
32042 + struct super_block *sb;
32044 + file = arg->file;
32045 + sb = file->f_path.dentry->d_sb;
32046 + SiMustAnyLock(sb);
32048 + rdhash = au_sbi(sb)->si_rdhash;
32050 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32051 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32052 + if (unlikely(err))
32054 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32055 + if (unlikely(err))
32061 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32063 + au_fset_fillvdir(arg->flags, SHWH);
32065 + btop = au_fbtop(file);
32066 + bbot = au_fbbot_dir(file);
32067 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32068 + hf = au_hf_dir(file, bindex);
32072 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32074 + if (unlikely(offset))
32077 + arg->bindex = bindex;
32078 + au_fclr_fillvdir(arg->flags, WHABLE);
32080 + || (bindex != bbot
32081 + && au_br_whable(au_sbr_perm(sb, bindex))))
32082 + au_fset_fillvdir(arg->flags, WHABLE);
32085 + au_fclr_fillvdir(arg->flags, CALLED);
32087 + err = vfsub_iterate_dir(hf, &arg->ctx);
32090 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32093 + * dir_relax() may be good for concurrency, but aufs should not
32094 + * use it since it will cause a lockdep problem.
32098 + if (!err && shwh)
32099 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32101 + au_nhash_wh_free(&arg->whlist);
32104 + au_nhash_de_free(&arg->delist);
32109 +static int read_vdir(struct file *file, int may_read)
32112 + unsigned long expire;
32113 + unsigned char do_read;
32114 + struct fillvdir_arg arg = {
32116 + .actor = fillvdir
32119 + struct inode *inode;
32120 + struct au_vdir *vdir, *allocated;
32123 + inode = file_inode(file);
32124 + IMustLock(inode);
32125 + IiMustWriteLock(inode);
32126 + SiMustAnyLock(inode->i_sb);
32128 + allocated = NULL;
32130 + expire = au_sbi(inode->i_sb)->si_rdcache;
32131 + vdir = au_ivdir(inode);
32134 + vdir = alloc_vdir(file);
32135 + err = PTR_ERR(vdir);
32136 + if (IS_ERR(vdir))
32139 + allocated = vdir;
32140 + } else if (may_read
32141 + && (inode->i_version != vdir->vd_version
32142 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32144 + err = reinit_vdir(vdir);
32145 + if (unlikely(err))
32150 + return 0; /* success */
32154 + err = au_do_read_vdir(&arg);
32156 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32157 + vdir->vd_version = inode->i_version;
32158 + vdir->vd_last.ul = 0;
32159 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32161 + au_set_ivdir(inode, allocated);
32162 + } else if (allocated)
32163 + au_vdir_free(allocated);
32169 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32172 + unsigned long ul, n;
32173 + const unsigned int deblk_sz = src->vd_deblk_sz;
32175 + AuDebugOn(tgt->vd_nblk != 1);
32178 + if (tgt->vd_nblk < src->vd_nblk) {
32179 + unsigned char **p;
32181 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32182 + GFP_NOFS, /*may_shrink*/0);
32183 + if (unlikely(!p))
32185 + tgt->vd_deblk = p;
32188 + if (tgt->vd_deblk_sz != deblk_sz) {
32189 + unsigned char *p;
32191 + tgt->vd_deblk_sz = deblk_sz;
32192 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32193 + /*may_shrink*/1);
32194 + if (unlikely(!p))
32196 + tgt->vd_deblk[0] = p;
32198 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32199 + tgt->vd_version = src->vd_version;
32200 + tgt->vd_jiffy = src->vd_jiffy;
32202 + n = src->vd_nblk;
32203 + for (ul = 1; ul < n; ul++) {
32204 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32206 + if (unlikely(!tgt->vd_deblk[ul]))
32210 + tgt->vd_nblk = n;
32211 + tgt->vd_last.ul = tgt->vd_last.ul;
32212 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32213 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32214 + - src->vd_deblk[src->vd_last.ul];
32216 + return 0; /* success */
32219 + rerr = reinit_vdir(tgt);
32224 +int au_vdir_init(struct file *file)
32227 + struct inode *inode;
32228 + struct au_vdir *vdir_cache, *allocated;
32230 + /* test file->f_pos here instead of ctx->pos */
32231 + err = read_vdir(file, !file->f_pos);
32232 + if (unlikely(err))
32235 + allocated = NULL;
32236 + vdir_cache = au_fvdir_cache(file);
32237 + if (!vdir_cache) {
32238 + vdir_cache = alloc_vdir(file);
32239 + err = PTR_ERR(vdir_cache);
32240 + if (IS_ERR(vdir_cache))
32242 + allocated = vdir_cache;
32243 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32244 + /* test file->f_pos here instead of ctx->pos */
32245 + err = reinit_vdir(vdir_cache);
32246 + if (unlikely(err))
32249 + return 0; /* success */
32251 + inode = file_inode(file);
32252 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32254 + file->f_version = inode->i_version;
32256 + au_set_fvdir_cache(file, allocated);
32257 + } else if (allocated)
32258 + au_vdir_free(allocated);
32264 +static loff_t calc_offset(struct au_vdir *vdir)
32267 + union au_vdir_deblk_p p;
32269 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32270 + offset = vdir->vd_last.p.deblk - p.deblk;
32271 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32275 +/* returns true or false */
32276 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32279 + unsigned int deblk_sz;
32280 + unsigned long ul, n;
32282 + union au_vdir_deblk_p p, deblk_end;
32283 + struct au_vdir *vdir_cache;
32286 + vdir_cache = au_fvdir_cache(file);
32287 + offset = calc_offset(vdir_cache);
32288 + AuDbg("offset %lld\n", offset);
32289 + if (ctx->pos == offset)
32292 + vdir_cache->vd_last.ul = 0;
32293 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32298 + deblk_sz = vdir_cache->vd_deblk_sz;
32299 + ul = div64_u64(ctx->pos, deblk_sz);
32300 + AuDbg("ul %lu\n", ul);
32301 + if (ul >= vdir_cache->vd_nblk)
32304 + n = vdir_cache->vd_nblk;
32305 + for (; ul < n; ul++) {
32306 + p.deblk = vdir_cache->vd_deblk[ul];
32307 + deblk_end.deblk = p.deblk + deblk_sz;
32309 + offset *= deblk_sz;
32310 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32313 + l = calc_size(p.de->de_str.len);
32317 + if (!is_deblk_end(&p, &deblk_end)) {
32319 + vdir_cache->vd_last.ul = ul;
32320 + vdir_cache->vd_last.p = p;
32327 + AuTraceErr(!valid);
32331 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32333 + unsigned int l, deblk_sz;
32334 + union au_vdir_deblk_p deblk_end;
32335 + struct au_vdir *vdir_cache;
32336 + struct au_vdir_de *de;
32338 + vdir_cache = au_fvdir_cache(file);
32339 + if (!seek_vdir(file, ctx))
32342 + deblk_sz = vdir_cache->vd_deblk_sz;
32344 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32345 + deblk_end.deblk += deblk_sz;
32346 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32347 + de = vdir_cache->vd_last.p.de;
32348 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32349 + de->de_str.len, de->de_str.name, ctx->pos,
32350 + (unsigned long)de->de_ino, de->de_type);
32351 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32352 + de->de_str.len, de->de_ino,
32354 + /* todo: ignore the error caused by udba? */
32355 + /* return err; */
32359 + l = calc_size(de->de_str.len);
32360 + vdir_cache->vd_last.p.deblk += l;
32363 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32364 + vdir_cache->vd_last.ul++;
32365 + vdir_cache->vd_last.p.deblk
32366 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32367 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32376 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32377 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32378 +++ linux/fs/aufs/vfsub.c 2017-11-12 22:24:44.707577830 +0100
32381 + * Copyright (C) 2005-2017 Junjiro R. Okajima
32383 + * This program, aufs is free software; you can redistribute it and/or modify
32384 + * it under the terms of the GNU General Public License as published by
32385 + * the Free Software Foundation; either version 2 of the License, or
32386 + * (at your option) any later version.
32388 + * This program is distributed in the hope that it will be useful,
32389 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32390 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32391 + * GNU General Public License for more details.
32393 + * You should have received a copy of the GNU General Public License
32394 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32398 + * sub-routines for VFS
32401 +#include <linux/mnt_namespace.h>
32402 +#include <linux/namei.h>
32403 +#include <linux/nsproxy.h>
32404 +#include <linux/security.h>
32405 +#include <linux/splice.h>
32408 +#ifdef CONFIG_AUFS_BR_FUSE
32409 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32411 + if (!au_test_fuse(h_sb) || !au_userns)
32414 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32418 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32423 + down_read(&h_sb->s_umount);
32424 + err = __sync_filesystem(h_sb, wait);
32425 + up_read(&h_sb->s_umount);
32431 +/* ---------------------------------------------------------------------- */
32433 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32437 + struct super_block *h_sb;
32439 + /* for remote fs, leave work for its getattr or d_revalidate */
32440 + /* for bad i_attr fs, handle them in aufs_getattr() */
32441 + /* still some fs may acquire i_mutex. we need to skip them */
32445 + h_sb = h_path->dentry->d_sb;
32446 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32448 + err = vfsub_getattr(h_path, &st);
32453 +/* ---------------------------------------------------------------------- */
32455 +struct file *vfsub_dentry_open(struct path *path, int flags)
32457 + struct file *file;
32459 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32461 + if (!IS_ERR_OR_NULL(file)
32462 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32463 + i_readcount_inc(d_inode(path->dentry));
32468 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32470 + struct file *file;
32473 + file = filp_open(path,
32474 + oflags /* | __FMODE_NONOTIFY */,
32477 + if (IS_ERR(file))
32479 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32486 + * Ideally this function should call VFS:do_last() in order to keep all its
32487 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32488 + * structure such as nameidata. This is a second (or third) best approach.
32489 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32491 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32492 + struct vfsub_aopen_args *args, struct au_branch *br)
32495 + struct file *file = args->file;
32496 + /* copied from linux/fs/namei.c:atomic_open() */
32497 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32500 + AuDebugOn(!dir->i_op->atomic_open);
32502 + err = au_br_test_oflag(args->open_flag, br);
32503 + if (unlikely(err))
32506 + args->file->f_path.dentry = DENTRY_NOT_SET;
32507 + args->file->f_path.mnt = au_br_mnt(br);
32508 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32509 + args->create_mode, args->opened);
32511 + /* some filesystems don't set FILE_CREATED while succeeded? */
32512 + if (*args->opened & FILE_CREATED)
32513 + fsnotify_create(dir, dentry);
32519 + /* todo: call VFS:may_open() here */
32520 + err = open_check_o_direct(file);
32521 + /* todo: ima_file_check() too? */
32522 + if (!err && (args->open_flag & __FMODE_EXEC))
32523 + err = deny_write_access(file);
32524 + if (unlikely(err))
32525 + /* note that the file is created and still opened */
32530 + fsnotify_open(file);
32536 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32540 + err = kern_path(name, flags, path);
32541 + if (!err && d_is_positive(path->dentry))
32542 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32546 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32547 + struct dentry *parent, int len)
32549 + struct path path = {
32553 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32554 + if (IS_ERR(path.dentry))
32556 + if (d_is_positive(path.dentry))
32557 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32560 + AuTraceErrPtr(path.dentry);
32561 + return path.dentry;
32564 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32567 + struct path path = {
32571 + /* VFS checks it too, but by WARN_ON_ONCE() */
32572 + IMustLock(d_inode(parent));
32574 + path.dentry = lookup_one_len(name, parent, len);
32575 + if (IS_ERR(path.dentry))
32577 + if (d_is_positive(path.dentry))
32578 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32581 + AuTraceErrPtr(path.dentry);
32582 + return path.dentry;
32585 +void vfsub_call_lkup_one(void *args)
32587 + struct vfsub_lkup_one_args *a = args;
32588 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32591 +/* ---------------------------------------------------------------------- */
32593 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32594 + struct dentry *d2, struct au_hinode *hdir2)
32596 + struct dentry *d;
32599 + d = lock_rename(d1, d2);
32601 + au_hn_suspend(hdir1);
32602 + if (hdir1 != hdir2)
32603 + au_hn_suspend(hdir2);
32608 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32609 + struct dentry *d2, struct au_hinode *hdir2)
32611 + au_hn_resume(hdir1);
32612 + if (hdir1 != hdir2)
32613 + au_hn_resume(hdir2);
32615 + unlock_rename(d1, d2);
32619 +/* ---------------------------------------------------------------------- */
32621 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32624 + struct dentry *d;
32628 + d = path->dentry;
32629 + path->dentry = d->d_parent;
32630 + err = security_path_mknod(path, d, mode, 0);
32631 + path->dentry = d;
32632 + if (unlikely(err))
32636 + err = vfs_create(dir, path->dentry, mode, want_excl);
32639 + struct path tmp = *path;
32642 + vfsub_update_h_iattr(&tmp, &did);
32644 + tmp.dentry = path->dentry->d_parent;
32645 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32654 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32657 + struct dentry *d;
32661 + d = path->dentry;
32662 + path->dentry = d->d_parent;
32663 + err = security_path_symlink(path, d, symname);
32664 + path->dentry = d;
32665 + if (unlikely(err))
32669 + err = vfs_symlink(dir, path->dentry, symname);
32672 + struct path tmp = *path;
32675 + vfsub_update_h_iattr(&tmp, &did);
32677 + tmp.dentry = path->dentry->d_parent;
32678 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32687 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32690 + struct dentry *d;
32694 + d = path->dentry;
32695 + path->dentry = d->d_parent;
32696 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32697 + path->dentry = d;
32698 + if (unlikely(err))
32702 + err = vfs_mknod(dir, path->dentry, mode, dev);
32705 + struct path tmp = *path;
32708 + vfsub_update_h_iattr(&tmp, &did);
32710 + tmp.dentry = path->dentry->d_parent;
32711 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32720 +static int au_test_nlink(struct inode *inode)
32722 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32724 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32725 + || inode->i_nlink < link_max)
32730 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32731 + struct inode **delegated_inode)
32734 + struct dentry *d;
32738 + err = au_test_nlink(d_inode(src_dentry));
32739 + if (unlikely(err))
32742 + /* we don't call may_linkat() */
32743 + d = path->dentry;
32744 + path->dentry = d->d_parent;
32745 + err = security_path_link(src_dentry, path, d);
32746 + path->dentry = d;
32747 + if (unlikely(err))
32751 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32754 + struct path tmp = *path;
32757 + /* fuse has different memory inode for the same inumber */
32758 + vfsub_update_h_iattr(&tmp, &did);
32760 + tmp.dentry = path->dentry->d_parent;
32761 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32762 + tmp.dentry = src_dentry;
32763 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32772 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32773 + struct inode *dir, struct path *path,
32774 + struct inode **delegated_inode, unsigned int flags)
32777 + struct path tmp = {
32780 + struct dentry *d;
32783 + IMustLock(src_dir);
32785 + d = path->dentry;
32786 + path->dentry = d->d_parent;
32787 + tmp.dentry = src_dentry->d_parent;
32788 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32789 + path->dentry = d;
32790 + if (unlikely(err))
32794 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
32795 + delegated_inode, flags);
32800 + tmp.dentry = d->d_parent;
32801 + vfsub_update_h_iattr(&tmp, &did);
32803 + tmp.dentry = src_dentry;
32804 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32805 + tmp.dentry = src_dentry->d_parent;
32806 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32815 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
32818 + struct dentry *d;
32822 + d = path->dentry;
32823 + path->dentry = d->d_parent;
32824 + err = security_path_mkdir(path, d, mode);
32825 + path->dentry = d;
32826 + if (unlikely(err))
32830 + err = vfs_mkdir(dir, path->dentry, mode);
32833 + struct path tmp = *path;
32836 + vfsub_update_h_iattr(&tmp, &did);
32838 + tmp.dentry = path->dentry->d_parent;
32839 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32848 +int vfsub_rmdir(struct inode *dir, struct path *path)
32851 + struct dentry *d;
32855 + d = path->dentry;
32856 + path->dentry = d->d_parent;
32857 + err = security_path_rmdir(path, d);
32858 + path->dentry = d;
32859 + if (unlikely(err))
32863 + err = vfs_rmdir(dir, path->dentry);
32866 + struct path tmp = {
32867 + .dentry = path->dentry->d_parent,
32871 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
32878 +/* ---------------------------------------------------------------------- */
32880 +/* todo: support mmap_sem? */
32881 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
32887 + err = vfs_read(file, ubuf, count, ppos);
32890 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32894 +/* todo: kernel_read()? */
32895 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
32899 + mm_segment_t oldfs;
32906 + oldfs = get_fs();
32907 + set_fs(KERNEL_DS);
32908 + err = vfsub_read_u(file, buf.u, count, ppos);
32913 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
32919 + err = vfs_write(file, ubuf, count, ppos);
32922 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32926 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
32929 + mm_segment_t oldfs;
32932 + const char __user *u;
32936 + oldfs = get_fs();
32937 + set_fs(KERNEL_DS);
32938 + err = vfsub_write_u(file, buf.u, count, ppos);
32943 +int vfsub_flush(struct file *file, fl_owner_t id)
32948 + if (file->f_op->flush) {
32949 + if (!au_test_nfs(file->f_path.dentry->d_sb))
32950 + err = file->f_op->flush(file, id);
32953 + err = file->f_op->flush(file, id);
32957 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
32963 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
32967 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
32970 + err = iterate_dir(file, ctx);
32973 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32978 +long vfsub_splice_to(struct file *in, loff_t *ppos,
32979 + struct pipe_inode_info *pipe, size_t len,
32980 + unsigned int flags)
32985 + err = do_splice_to(in, ppos, pipe, len, flags);
32987 + file_accessed(in);
32989 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
32993 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
32994 + loff_t *ppos, size_t len, unsigned int flags)
32999 + err = do_splice_from(pipe, out, ppos, len, flags);
33002 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33006 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33010 + /* file can be NULL */
33012 + err = vfs_fsync(file, datasync);
33016 + AuDebugOn(!file);
33017 + path = &file->f_path;
33019 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33024 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33025 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33026 + struct file *h_file)
33029 + struct inode *h_inode;
33030 + struct super_block *h_sb;
33033 + err = vfsub_truncate(h_path, length);
33037 + h_inode = d_inode(h_path->dentry);
33038 + h_sb = h_inode->i_sb;
33040 + sb_start_write(h_sb);
33042 + err = locks_verify_truncate(h_inode, h_file, length);
33044 + err = security_path_truncate(h_path);
33047 + err = do_truncate(h_path->dentry, length, attr, h_file);
33051 + sb_end_write(h_sb);
33058 +/* ---------------------------------------------------------------------- */
33060 +struct au_vfsub_mkdir_args {
33062 + struct inode *dir;
33063 + struct path *path;
33067 +static void au_call_vfsub_mkdir(void *args)
33069 + struct au_vfsub_mkdir_args *a = args;
33070 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33073 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33075 + int err, do_sio, wkq_err;
33077 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33080 + err = vfsub_mkdir(dir, path, mode);
33083 + struct au_vfsub_mkdir_args args = {
33089 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33090 + if (unlikely(wkq_err))
33097 +struct au_vfsub_rmdir_args {
33099 + struct inode *dir;
33100 + struct path *path;
33103 +static void au_call_vfsub_rmdir(void *args)
33105 + struct au_vfsub_rmdir_args *a = args;
33106 + *a->errp = vfsub_rmdir(a->dir, a->path);
33109 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33111 + int err, do_sio, wkq_err;
33113 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33116 + err = vfsub_rmdir(dir, path);
33119 + struct au_vfsub_rmdir_args args = {
33124 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33125 + if (unlikely(wkq_err))
33132 +/* ---------------------------------------------------------------------- */
33134 +struct notify_change_args {
33136 + struct path *path;
33137 + struct iattr *ia;
33138 + struct inode **delegated_inode;
33141 +static void call_notify_change(void *args)
33143 + struct notify_change_args *a = args;
33144 + struct inode *h_inode;
33146 + h_inode = d_inode(a->path->dentry);
33147 + IMustLock(h_inode);
33149 + *a->errp = -EPERM;
33150 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33152 + *a->errp = notify_change(a->path->dentry, a->ia,
33153 + a->delegated_inode);
33156 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33158 + AuTraceErr(*a->errp);
33161 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33162 + struct inode **delegated_inode)
33165 + struct notify_change_args args = {
33169 + .delegated_inode = delegated_inode
33172 + call_notify_change(&args);
33177 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33178 + struct inode **delegated_inode)
33180 + int err, wkq_err;
33181 + struct notify_change_args args = {
33185 + .delegated_inode = delegated_inode
33188 + wkq_err = au_wkq_wait(call_notify_change, &args);
33189 + if (unlikely(wkq_err))
33195 +/* ---------------------------------------------------------------------- */
33197 +struct unlink_args {
33199 + struct inode *dir;
33200 + struct path *path;
33201 + struct inode **delegated_inode;
33204 +static void call_unlink(void *args)
33206 + struct unlink_args *a = args;
33207 + struct dentry *d = a->path->dentry;
33208 + struct inode *h_inode;
33209 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33210 + && au_dcount(d) == 1);
33212 + IMustLock(a->dir);
33214 + a->path->dentry = d->d_parent;
33215 + *a->errp = security_path_unlink(a->path, d);
33216 + a->path->dentry = d;
33217 + if (unlikely(*a->errp))
33220 + if (!stop_sillyrename)
33223 + if (d_is_positive(d)) {
33224 + h_inode = d_inode(d);
33229 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33232 + struct path tmp = {
33233 + .dentry = d->d_parent,
33234 + .mnt = a->path->mnt
33236 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33239 + if (!stop_sillyrename)
33244 + AuTraceErr(*a->errp);
33248 + * @dir: must be locked.
33249 + * @dentry: target dentry.
33251 +int vfsub_unlink(struct inode *dir, struct path *path,
33252 + struct inode **delegated_inode, int force)
33255 + struct unlink_args args = {
33259 + .delegated_inode = delegated_inode
33263 + call_unlink(&args);
33267 + wkq_err = au_wkq_wait(call_unlink, &args);
33268 + if (unlikely(wkq_err))
33274 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33275 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33276 +++ linux/fs/aufs/vfsub.h 2017-11-12 22:24:44.707577830 +0100
33279 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33281 + * This program, aufs is free software; you can redistribute it and/or modify
33282 + * it under the terms of the GNU General Public License as published by
33283 + * the Free Software Foundation; either version 2 of the License, or
33284 + * (at your option) any later version.
33286 + * This program is distributed in the hope that it will be useful,
33287 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33288 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33289 + * GNU General Public License for more details.
33291 + * You should have received a copy of the GNU General Public License
33292 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33296 + * sub-routines for VFS
33299 +#ifndef __AUFS_VFSUB_H__
33300 +#define __AUFS_VFSUB_H__
33304 +#include <linux/fs.h>
33305 +#include <linux/mount.h>
33306 +#include <linux/posix_acl.h>
33307 +#include <linux/xattr.h>
33308 +#include "debug.h"
33310 +/* copied from linux/fs/internal.h */
33311 +/* todo: BAD approach!! */
33312 +extern void __mnt_drop_write(struct vfsmount *);
33313 +extern int open_check_o_direct(struct file *f);
33315 +/* ---------------------------------------------------------------------- */
33317 +/* lock subclass for lower inode */
33318 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33319 +/* reduce? gave up. */
33321 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33322 + AuLsc_I_PARENT, /* lower inode, parent first */
33323 + AuLsc_I_PARENT2, /* copyup dirs */
33324 + AuLsc_I_PARENT3, /* copyup wh */
33330 +/* to debug easier, do not make them inlined functions */
33331 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33332 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33334 +/* why VFS doesn't define it? */
33336 +void vfsub_inode_lock_shared_nested(struct inode *inode, unsigned int sc)
33338 + down_read_nested(&inode->i_rwsem, sc);
33341 +/* ---------------------------------------------------------------------- */
33343 +static inline void vfsub_drop_nlink(struct inode *inode)
33345 + AuDebugOn(!inode->i_nlink);
33346 + drop_nlink(inode);
33349 +static inline void vfsub_dead_dir(struct inode *inode)
33351 + AuDebugOn(!S_ISDIR(inode->i_mode));
33352 + inode->i_flags |= S_DEAD;
33353 + clear_nlink(inode);
33356 +static inline int vfsub_native_ro(struct inode *inode)
33358 + return sb_rdonly(inode->i_sb)
33359 + || IS_RDONLY(inode)
33360 + /* || IS_APPEND(inode) */
33361 + || IS_IMMUTABLE(inode);
33364 +#ifdef CONFIG_AUFS_BR_FUSE
33365 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33367 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33370 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33372 +/* ---------------------------------------------------------------------- */
33374 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33375 +struct file *vfsub_dentry_open(struct path *path, int flags);
33376 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33377 +struct vfsub_aopen_args {
33378 + struct file *file;
33379 + unsigned int open_flag;
33380 + umode_t create_mode;
33384 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33385 + struct vfsub_aopen_args *args, struct au_branch *br);
33386 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33388 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33389 + struct dentry *parent, int len);
33390 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33393 +struct vfsub_lkup_one_args {
33394 + struct dentry **errp;
33395 + struct qstr *name;
33396 + struct dentry *parent;
33399 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33400 + struct dentry *parent)
33402 + return vfsub_lookup_one_len(name->name, parent, name->len);
33405 +void vfsub_call_lkup_one(void *args);
33407 +/* ---------------------------------------------------------------------- */
33409 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33414 + err = mnt_want_write(mnt);
33419 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33422 + mnt_drop_write(mnt);
33426 +#if 0 /* reserved */
33427 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33430 + mnt_drop_write_file(file);
33435 +/* ---------------------------------------------------------------------- */
33438 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33439 + struct dentry *d2, struct au_hinode *hdir2);
33440 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33441 + struct dentry *d2, struct au_hinode *hdir2);
33443 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33445 +int vfsub_symlink(struct inode *dir, struct path *path,
33446 + const char *symname);
33447 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33448 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33449 + struct path *path, struct inode **delegated_inode);
33450 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33451 + struct inode *hdir, struct path *path,
33452 + struct inode **delegated_inode, unsigned int flags);
33453 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33454 +int vfsub_rmdir(struct inode *dir, struct path *path);
33456 +/* ---------------------------------------------------------------------- */
33458 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33460 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33462 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33464 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33466 +int vfsub_flush(struct file *file, fl_owner_t id);
33467 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33469 +static inline loff_t vfsub_f_size_read(struct file *file)
33471 + return i_size_read(file_inode(file));
33474 +static inline unsigned int vfsub_file_flags(struct file *file)
33476 + unsigned int flags;
33478 + spin_lock(&file->f_lock);
33479 + flags = file->f_flags;
33480 + spin_unlock(&file->f_lock);
33485 +static inline int vfsub_file_execed(struct file *file)
33487 + /* todo: direct access f_flags */
33488 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33491 +#if 0 /* reserved */
33492 +static inline void vfsub_file_accessed(struct file *h_file)
33494 + file_accessed(h_file);
33495 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33499 +#if 0 /* reserved */
33500 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33501 + struct dentry *h_dentry)
33503 + struct path h_path = {
33504 + .dentry = h_dentry,
33507 + touch_atime(&h_path);
33508 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33512 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
33515 + return update_time(h_inode, ts, flags);
33516 + /* no vfsub_update_h_iattr() since we don't have struct path */
33519 +#ifdef CONFIG_FS_POSIX_ACL
33520 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33524 + err = posix_acl_chmod(h_inode, h_mode);
33525 + if (err == -EOPNOTSUPP)
33530 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33533 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33534 + struct pipe_inode_info *pipe, size_t len,
33535 + unsigned int flags);
33536 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33537 + loff_t *ppos, size_t len, unsigned int flags);
33539 +static inline long vfsub_truncate(struct path *path, loff_t length)
33544 + err = vfs_truncate(path, length);
33549 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33550 + struct file *h_file);
33551 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33554 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33557 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
33563 + err = vfs_clone_file_range(src, 0, dst, 0, len);
33569 +/* copy_file_range(2) is a systemcall */
33570 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33571 + struct file *dst, loff_t dst_pos,
33572 + size_t len, unsigned int flags)
33577 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33583 +/* ---------------------------------------------------------------------- */
33585 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33590 + err = vfs_llseek(file, offset, origin);
33595 +/* ---------------------------------------------------------------------- */
33597 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33598 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33599 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33600 + struct inode **delegated_inode);
33601 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33602 + struct inode **delegated_inode);
33603 +int vfsub_unlink(struct inode *dir, struct path *path,
33604 + struct inode **delegated_inode, int force);
33606 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33608 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33611 +/* ---------------------------------------------------------------------- */
33613 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33614 + const void *value, size_t size, int flags)
33619 + err = vfs_setxattr(dentry, name, value, size, flags);
33625 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33630 + err = vfs_removexattr(dentry, name);
33636 +#endif /* __KERNEL__ */
33637 +#endif /* __AUFS_VFSUB_H__ */
33638 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33639 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33640 +++ linux/fs/aufs/wbr_policy.c 2017-11-12 22:24:42.274176929 +0100
33643 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33645 + * This program, aufs is free software; you can redistribute it and/or modify
33646 + * it under the terms of the GNU General Public License as published by
33647 + * the Free Software Foundation; either version 2 of the License, or
33648 + * (at your option) any later version.
33650 + * This program is distributed in the hope that it will be useful,
33651 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33652 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33653 + * GNU General Public License for more details.
33655 + * You should have received a copy of the GNU General Public License
33656 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33660 + * policies for selecting one among multiple writable branches
33663 +#include <linux/statfs.h>
33666 +/* subset of cpup_attr() */
33667 +static noinline_for_stack
33668 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33672 + struct inode *h_isrc;
33674 + h_isrc = d_inode(h_src);
33675 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33676 + ia.ia_mode = h_isrc->i_mode;
33677 + ia.ia_uid = h_isrc->i_uid;
33678 + ia.ia_gid = h_isrc->i_gid;
33679 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33680 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33681 + /* no delegation since it is just created */
33682 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33684 + /* is this nfs only? */
33685 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33686 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33687 + ia.ia_mode = h_isrc->i_mode;
33688 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33694 +#define AuCpdown_PARENT_OPQ 1
33695 +#define AuCpdown_WHED (1 << 1)
33696 +#define AuCpdown_MADE_DIR (1 << 2)
33697 +#define AuCpdown_DIROPQ (1 << 3)
33698 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33699 +#define au_fset_cpdown(flags, name) \
33700 + do { (flags) |= AuCpdown_##name; } while (0)
33701 +#define au_fclr_cpdown(flags, name) \
33702 + do { (flags) &= ~AuCpdown_##name; } while (0)
33704 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33705 + unsigned int *flags)
33708 + struct dentry *opq_dentry;
33710 + opq_dentry = au_diropq_create(dentry, bdst);
33711 + err = PTR_ERR(opq_dentry);
33712 + if (IS_ERR(opq_dentry))
33714 + dput(opq_dentry);
33715 + au_fset_cpdown(*flags, DIROPQ);
33721 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33722 + struct inode *dir, aufs_bindex_t bdst)
33725 + struct path h_path;
33726 + struct au_branch *br;
33728 + br = au_sbr(dentry->d_sb, bdst);
33729 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33730 + err = PTR_ERR(h_path.dentry);
33731 + if (IS_ERR(h_path.dentry))
33735 + if (d_is_positive(h_path.dentry)) {
33736 + h_path.mnt = au_br_mnt(br);
33737 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33740 + dput(h_path.dentry);
33746 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33747 + struct au_pin *pin,
33748 + struct dentry *h_parent, void *arg)
33751 + aufs_bindex_t bopq, btop;
33752 + struct path h_path;
33753 + struct dentry *parent;
33754 + struct inode *h_dir, *h_inode, *inode, *dir;
33755 + unsigned int *flags = arg;
33757 + btop = au_dbtop(dentry);
33758 + /* dentry is di-locked */
33759 + parent = dget_parent(dentry);
33760 + dir = d_inode(parent);
33761 + h_dir = d_inode(h_parent);
33762 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33763 + IMustLock(h_dir);
33765 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33766 + if (unlikely(err < 0))
33768 + h_path.dentry = au_h_dptr(dentry, bdst);
33769 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33770 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
33771 + S_IRWXU | S_IRUGO | S_IXUGO);
33772 + if (unlikely(err))
33774 + au_fset_cpdown(*flags, MADE_DIR);
33776 + bopq = au_dbdiropq(dentry);
33777 + au_fclr_cpdown(*flags, WHED);
33778 + au_fclr_cpdown(*flags, DIROPQ);
33779 + if (au_dbwh(dentry) == bdst)
33780 + au_fset_cpdown(*flags, WHED);
33781 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33782 + au_fset_cpdown(*flags, PARENT_OPQ);
33783 + h_inode = d_inode(h_path.dentry);
33784 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33785 + if (au_ftest_cpdown(*flags, WHED)) {
33786 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33787 + if (unlikely(err)) {
33788 + inode_unlock(h_inode);
33793 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33794 + inode_unlock(h_inode);
33795 + if (unlikely(err))
33798 + if (au_ftest_cpdown(*flags, WHED)) {
33799 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33800 + if (unlikely(err))
33804 + inode = d_inode(dentry);
33805 + if (au_ibbot(inode) < bdst)
33806 + au_set_ibbot(inode, bdst);
33807 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
33808 + au_hi_flags(inode, /*isdir*/1));
33809 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
33810 + goto out; /* success */
33814 + if (au_ftest_cpdown(*flags, DIROPQ)) {
33815 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33816 + rerr = au_diropq_remove(dentry, bdst);
33817 + inode_unlock(h_inode);
33818 + if (unlikely(rerr)) {
33819 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
33820 + dentry, bdst, rerr);
33826 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
33827 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
33828 + if (unlikely(rerr)) {
33829 + AuIOErr("failed removing %pd b%d (%d)\n",
33830 + dentry, bdst, rerr);
33835 + au_set_h_dptr(dentry, bdst, NULL);
33836 + if (au_dbbot(dentry) == bdst)
33837 + au_update_dbbot(dentry);
33843 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
33846 + unsigned int flags;
33849 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
33854 +/* ---------------------------------------------------------------------- */
33856 +/* policies for create */
33858 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
33860 + int err, i, j, ndentry;
33861 + aufs_bindex_t bopq;
33862 + struct au_dcsub_pages dpages;
33863 + struct au_dpage *dpage;
33864 + struct dentry **dentries, *parent, *d;
33866 + err = au_dpages_init(&dpages, GFP_NOFS);
33867 + if (unlikely(err))
33869 + parent = dget_parent(dentry);
33870 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
33871 + if (unlikely(err))
33875 + for (i = 0; i < dpages.ndpage; i++) {
33876 + dpage = dpages.dpages + i;
33877 + dentries = dpage->dentries;
33878 + ndentry = dpage->ndentry;
33879 + for (j = 0; j < ndentry; j++) {
33881 + di_read_lock_parent2(d, !AuLock_IR);
33882 + bopq = au_dbdiropq(d);
33883 + di_read_unlock(d, !AuLock_IR);
33884 + if (bopq >= 0 && bopq < err)
33891 + au_dpages_free(&dpages);
33896 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
33898 + for (; bindex >= 0; bindex--)
33899 + if (!au_br_rdonly(au_sbr(sb, bindex)))
33904 +/* top down parent */
33905 +static int au_wbr_create_tdp(struct dentry *dentry,
33906 + unsigned int flags __maybe_unused)
33909 + aufs_bindex_t btop, bindex;
33910 + struct super_block *sb;
33911 + struct dentry *parent, *h_parent;
33913 + sb = dentry->d_sb;
33914 + btop = au_dbtop(dentry);
33916 + if (!au_br_rdonly(au_sbr(sb, btop)))
33920 + parent = dget_parent(dentry);
33921 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
33922 + h_parent = au_h_dptr(parent, bindex);
33923 + if (!h_parent || d_is_negative(h_parent))
33926 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
33933 + /* bottom up here */
33934 + if (unlikely(err < 0)) {
33935 + err = au_wbr_bu(sb, btop - 1);
33937 + err = au_wbr_nonopq(dentry, err);
33941 + AuDbg("b%d\n", err);
33945 +/* ---------------------------------------------------------------------- */
33947 +/* an exception for the policy other than tdp */
33948 +static int au_wbr_create_exp(struct dentry *dentry)
33951 + aufs_bindex_t bwh, bdiropq;
33952 + struct dentry *parent;
33955 + bwh = au_dbwh(dentry);
33956 + parent = dget_parent(dentry);
33957 + bdiropq = au_dbdiropq(parent);
33959 + if (bdiropq >= 0)
33960 + err = min(bdiropq, bwh);
33963 + AuDbg("%d\n", err);
33964 + } else if (bdiropq >= 0) {
33966 + AuDbg("%d\n", err);
33971 + err = au_wbr_nonopq(dentry, err);
33973 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
33976 + AuDbg("%d\n", err);
33980 +/* ---------------------------------------------------------------------- */
33983 +static int au_wbr_create_init_rr(struct super_block *sb)
33987 + err = au_wbr_bu(sb, au_sbbot(sb));
33988 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
33991 + AuDbg("b%d\n", err);
33995 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
33999 + aufs_bindex_t bindex, bbot;
34000 + struct super_block *sb;
34003 + err = au_wbr_create_exp(dentry);
34007 + sb = dentry->d_sb;
34008 + next = &au_sbi(sb)->si_wbr_rr_next;
34009 + bbot = au_sbbot(sb);
34011 + for (bindex = 0; bindex <= bbot; bindex++) {
34012 + if (!au_ftest_wbr(flags, DIR)) {
34013 + err = atomic_dec_return(next) + 1;
34014 + /* modulo for 0 is meaningless */
34015 + if (unlikely(!err))
34016 + err = atomic_dec_return(next) + 1;
34018 + err = atomic_read(next);
34019 + AuDbg("%d\n", err);
34022 + AuDbg("%d\n", err);
34023 + if (!au_br_rdonly(au_sbr(sb, err)))
34029 + err = au_wbr_nonopq(dentry, err);
34032 + AuDbg("%d\n", err);
34036 +/* ---------------------------------------------------------------------- */
34038 +/* most free space */
34039 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34041 + struct super_block *sb;
34042 + struct au_branch *br;
34043 + struct au_wbr_mfs *mfs;
34044 + struct dentry *h_parent;
34045 + aufs_bindex_t bindex, bbot;
34047 + unsigned long long b, bavail;
34048 + struct path h_path;
34049 + /* reduce the stack usage */
34050 + struct kstatfs *st;
34052 + st = kmalloc(sizeof(*st), GFP_NOFS);
34053 + if (unlikely(!st)) {
34054 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34059 + sb = dentry->d_sb;
34060 + mfs = &au_sbi(sb)->si_wbr_mfs;
34061 + MtxMustLock(&mfs->mfs_lock);
34062 + mfs->mfs_bindex = -EROFS;
34063 + mfs->mfsrr_bytes = 0;
34066 + bbot = au_sbbot(sb);
34068 + bindex = au_dbtop(parent);
34069 + bbot = au_dbtaildir(parent);
34072 + for (; bindex <= bbot; bindex++) {
34074 + h_parent = au_h_dptr(parent, bindex);
34075 + if (!h_parent || d_is_negative(h_parent))
34078 + br = au_sbr(sb, bindex);
34079 + if (au_br_rdonly(br))
34082 + /* sb->s_root for NFS is unreliable */
34083 + h_path.mnt = au_br_mnt(br);
34084 + h_path.dentry = h_path.mnt->mnt_root;
34085 + err = vfs_statfs(&h_path, st);
34086 + if (unlikely(err)) {
34087 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34091 + /* when the available size is equal, select the lower one */
34092 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34093 + || sizeof(b) < sizeof(st->f_bsize));
34094 + b = st->f_bavail * st->f_bsize;
34095 + br->br_wbr->wbr_bytes = b;
34096 + if (b >= bavail) {
34098 + mfs->mfs_bindex = bindex;
34099 + mfs->mfs_jiffy = jiffies;
34103 + mfs->mfsrr_bytes = bavail;
34104 + AuDbg("b%d\n", mfs->mfs_bindex);
34108 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34111 + struct dentry *parent;
34112 + struct super_block *sb;
34113 + struct au_wbr_mfs *mfs;
34115 + err = au_wbr_create_exp(dentry);
34119 + sb = dentry->d_sb;
34121 + if (au_ftest_wbr(flags, PARENT))
34122 + parent = dget_parent(dentry);
34123 + mfs = &au_sbi(sb)->si_wbr_mfs;
34124 + mutex_lock(&mfs->mfs_lock);
34125 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34126 + || mfs->mfs_bindex < 0
34127 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34128 + au_mfs(dentry, parent);
34129 + mutex_unlock(&mfs->mfs_lock);
34130 + err = mfs->mfs_bindex;
34134 + err = au_wbr_nonopq(dentry, err);
34137 + AuDbg("b%d\n", err);
34141 +static int au_wbr_create_init_mfs(struct super_block *sb)
34143 + struct au_wbr_mfs *mfs;
34145 + mfs = &au_sbi(sb)->si_wbr_mfs;
34146 + mutex_init(&mfs->mfs_lock);
34147 + mfs->mfs_jiffy = 0;
34148 + mfs->mfs_bindex = -EROFS;
34153 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34155 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34159 +/* ---------------------------------------------------------------------- */
34161 +/* top down regardless parent, and then mfs */
34162 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34163 + unsigned int flags __maybe_unused)
34166 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34167 + unsigned long long watermark;
34168 + struct super_block *sb;
34169 + struct au_wbr_mfs *mfs;
34170 + struct au_branch *br;
34171 + struct dentry *parent;
34173 + sb = dentry->d_sb;
34174 + mfs = &au_sbi(sb)->si_wbr_mfs;
34175 + mutex_lock(&mfs->mfs_lock);
34176 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34177 + || mfs->mfs_bindex < 0)
34178 + au_mfs(dentry, /*parent*/NULL);
34179 + watermark = mfs->mfsrr_watermark;
34180 + bmfs = mfs->mfs_bindex;
34181 + mutex_unlock(&mfs->mfs_lock);
34183 + /* another style of au_wbr_create_exp() */
34184 + bwh = au_dbwh(dentry);
34185 + parent = dget_parent(dentry);
34186 + btail = au_dbtaildir(parent);
34187 + if (bwh >= 0 && bwh < btail)
34190 + err = au_wbr_nonopq(dentry, btail);
34191 + if (unlikely(err < 0))
34195 + for (bindex = 0; bindex <= btail; bindex++) {
34196 + br = au_sbr(sb, bindex);
34197 + if (au_br_rdonly(br))
34199 + if (br->br_wbr->wbr_bytes > watermark) {
34210 + AuDbg("b%d\n", err);
34214 +/* ---------------------------------------------------------------------- */
34216 +/* most free space and then round robin */
34217 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34220 + struct au_wbr_mfs *mfs;
34222 + err = au_wbr_create_mfs(dentry, flags);
34224 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34225 + mutex_lock(&mfs->mfs_lock);
34226 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34227 + err = au_wbr_create_rr(dentry, flags);
34228 + mutex_unlock(&mfs->mfs_lock);
34231 + AuDbg("b%d\n", err);
34235 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34239 + au_wbr_create_init_mfs(sb); /* ignore */
34240 + err = au_wbr_create_init_rr(sb);
34245 +/* ---------------------------------------------------------------------- */
34247 +/* top down parent and most free space */
34248 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34251 + unsigned long long b;
34252 + aufs_bindex_t bindex, btop, bbot;
34253 + struct super_block *sb;
34254 + struct dentry *parent, *h_parent;
34255 + struct au_branch *br;
34257 + err = au_wbr_create_tdp(dentry, flags);
34258 + if (unlikely(err < 0))
34260 + parent = dget_parent(dentry);
34261 + btop = au_dbtop(parent);
34262 + bbot = au_dbtaildir(parent);
34263 + if (btop == bbot)
34264 + goto out_parent; /* success */
34266 + e2 = au_wbr_create_mfs(dentry, flags);
34268 + goto out_parent; /* success */
34270 + /* when the available size is equal, select upper one */
34271 + sb = dentry->d_sb;
34272 + br = au_sbr(sb, err);
34273 + b = br->br_wbr->wbr_bytes;
34274 + AuDbg("b%d, %llu\n", err, b);
34276 + for (bindex = btop; bindex <= bbot; bindex++) {
34277 + h_parent = au_h_dptr(parent, bindex);
34278 + if (!h_parent || d_is_negative(h_parent))
34281 + br = au_sbr(sb, bindex);
34282 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34283 + b = br->br_wbr->wbr_bytes;
34285 + AuDbg("b%d, %llu\n", err, b);
34290 + err = au_wbr_nonopq(dentry, err);
34295 + AuDbg("b%d\n", err);
34299 +/* ---------------------------------------------------------------------- */
34302 + * - top down parent
34303 + * - most free space with parent
34304 + * - most free space round-robin regardless parent
34306 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34309 + unsigned long long watermark;
34310 + struct super_block *sb;
34311 + struct au_branch *br;
34312 + struct au_wbr_mfs *mfs;
34314 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34315 + if (unlikely(err < 0))
34318 + sb = dentry->d_sb;
34319 + br = au_sbr(sb, err);
34320 + mfs = &au_sbi(sb)->si_wbr_mfs;
34321 + mutex_lock(&mfs->mfs_lock);
34322 + watermark = mfs->mfsrr_watermark;
34323 + mutex_unlock(&mfs->mfs_lock);
34324 + if (br->br_wbr->wbr_bytes < watermark)
34325 + /* regardless the parent dir */
34326 + err = au_wbr_create_mfsrr(dentry, flags);
34329 + AuDbg("b%d\n", err);
34333 +/* ---------------------------------------------------------------------- */
34335 +/* policies for copyup */
34337 +/* top down parent */
34338 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34340 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34343 +/* bottom up parent */
34344 +static int au_wbr_copyup_bup(struct dentry *dentry)
34347 + aufs_bindex_t bindex, btop;
34348 + struct dentry *parent, *h_parent;
34349 + struct super_block *sb;
34352 + sb = dentry->d_sb;
34353 + parent = dget_parent(dentry);
34354 + btop = au_dbtop(parent);
34355 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34356 + h_parent = au_h_dptr(parent, bindex);
34357 + if (!h_parent || d_is_negative(h_parent))
34360 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34367 + /* bottom up here */
34368 + if (unlikely(err < 0))
34369 + err = au_wbr_bu(sb, btop - 1);
34371 + AuDbg("b%d\n", err);
34376 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34380 + err = au_wbr_bu(dentry->d_sb, btop);
34381 + AuDbg("b%d\n", err);
34383 + err = au_wbr_nonopq(dentry, err);
34385 + AuDbg("b%d\n", err);
34389 +static int au_wbr_copyup_bu(struct dentry *dentry)
34392 + aufs_bindex_t btop;
34394 + btop = au_dbtop(dentry);
34395 + err = au_wbr_do_copyup_bu(dentry, btop);
34399 +/* ---------------------------------------------------------------------- */
34401 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34402 + [AuWbrCopyup_TDP] = {
34403 + .copyup = au_wbr_copyup_tdp
34405 + [AuWbrCopyup_BUP] = {
34406 + .copyup = au_wbr_copyup_bup
34408 + [AuWbrCopyup_BU] = {
34409 + .copyup = au_wbr_copyup_bu
34413 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34414 + [AuWbrCreate_TDP] = {
34415 + .create = au_wbr_create_tdp
34417 + [AuWbrCreate_RR] = {
34418 + .create = au_wbr_create_rr,
34419 + .init = au_wbr_create_init_rr
34421 + [AuWbrCreate_MFS] = {
34422 + .create = au_wbr_create_mfs,
34423 + .init = au_wbr_create_init_mfs,
34424 + .fin = au_wbr_create_fin_mfs
34426 + [AuWbrCreate_MFSV] = {
34427 + .create = au_wbr_create_mfs,
34428 + .init = au_wbr_create_init_mfs,
34429 + .fin = au_wbr_create_fin_mfs
34431 + [AuWbrCreate_MFSRR] = {
34432 + .create = au_wbr_create_mfsrr,
34433 + .init = au_wbr_create_init_mfsrr,
34434 + .fin = au_wbr_create_fin_mfs
34436 + [AuWbrCreate_MFSRRV] = {
34437 + .create = au_wbr_create_mfsrr,
34438 + .init = au_wbr_create_init_mfsrr,
34439 + .fin = au_wbr_create_fin_mfs
34441 + [AuWbrCreate_TDMFS] = {
34442 + .create = au_wbr_create_tdmfs,
34443 + .init = au_wbr_create_init_mfs,
34444 + .fin = au_wbr_create_fin_mfs
34446 + [AuWbrCreate_TDMFSV] = {
34447 + .create = au_wbr_create_tdmfs,
34448 + .init = au_wbr_create_init_mfs,
34449 + .fin = au_wbr_create_fin_mfs
34451 + [AuWbrCreate_PMFS] = {
34452 + .create = au_wbr_create_pmfs,
34453 + .init = au_wbr_create_init_mfs,
34454 + .fin = au_wbr_create_fin_mfs
34456 + [AuWbrCreate_PMFSV] = {
34457 + .create = au_wbr_create_pmfs,
34458 + .init = au_wbr_create_init_mfs,
34459 + .fin = au_wbr_create_fin_mfs
34461 + [AuWbrCreate_PMFSRR] = {
34462 + .create = au_wbr_create_pmfsrr,
34463 + .init = au_wbr_create_init_mfsrr,
34464 + .fin = au_wbr_create_fin_mfs
34466 + [AuWbrCreate_PMFSRRV] = {
34467 + .create = au_wbr_create_pmfsrr,
34468 + .init = au_wbr_create_init_mfsrr,
34469 + .fin = au_wbr_create_fin_mfs
34472 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34473 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34474 +++ linux/fs/aufs/whout.c 2017-11-12 22:24:42.274176929 +0100
34477 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34479 + * This program, aufs is free software; you can redistribute it and/or modify
34480 + * it under the terms of the GNU General Public License as published by
34481 + * the Free Software Foundation; either version 2 of the License, or
34482 + * (at your option) any later version.
34484 + * This program is distributed in the hope that it will be useful,
34485 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34486 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34487 + * GNU General Public License for more details.
34489 + * You should have received a copy of the GNU General Public License
34490 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34494 + * whiteout for logical deletion and opaque directory
34499 +#define WH_MASK S_IRUGO
34502 + * If a directory contains this file, then it is opaque. We start with the
34503 + * .wh. flag so that it is blocked by lookup.
34505 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34506 + sizeof(AUFS_WH_DIROPQ) - 1);
34509 + * generate whiteout name, which is NOT terminated by NULL.
34510 + * @name: original d_name.name
34511 + * @len: original d_name.len
34512 + * @wh: whiteout qstr
34513 + * returns zero when succeeds, otherwise error.
34514 + * succeeded value as wh->name should be freed by kfree().
34516 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34520 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34521 + return -ENAMETOOLONG;
34523 + wh->len = name->len + AUFS_WH_PFX_LEN;
34524 + p = kmalloc(wh->len, GFP_NOFS);
34527 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34528 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34535 +/* ---------------------------------------------------------------------- */
34538 + * test if the @wh_name exists under @h_parent.
34539 + * @try_sio specifies the necessary of super-io.
34541 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34544 + struct dentry *wh_dentry;
34547 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34549 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34550 + err = PTR_ERR(wh_dentry);
34551 + if (IS_ERR(wh_dentry)) {
34552 + if (err == -ENAMETOOLONG)
34558 + if (d_is_negative(wh_dentry))
34559 + goto out_wh; /* success */
34562 + if (d_is_reg(wh_dentry))
34563 + goto out_wh; /* success */
34566 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34567 + wh_dentry, d_inode(wh_dentry)->i_mode);
34576 + * test if the @h_dentry sets opaque or not.
34578 +int au_diropq_test(struct dentry *h_dentry)
34581 + struct inode *h_dir;
34583 + h_dir = d_inode(h_dentry);
34584 + err = au_wh_test(h_dentry, &diropq_name,
34585 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34590 + * returns a negative dentry whose name is unique and temporary.
34592 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34593 + struct qstr *prefix)
34595 + struct dentry *dentry;
34597 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34599 + /* strict atomic_t is unnecessary here */
34600 + static unsigned short cnt;
34603 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34606 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34607 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34608 + dentry = ERR_PTR(-ENAMETOOLONG);
34609 + if (unlikely(qs.len > NAME_MAX))
34611 + dentry = ERR_PTR(-ENOMEM);
34612 + name = kmalloc(qs.len + 1, GFP_NOFS);
34613 + if (unlikely(!name))
34617 + /* doubly whiteout-ed */
34618 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34619 + p = name + AUFS_WH_PFX_LEN * 2;
34620 + memcpy(p, prefix->name, prefix->len);
34621 + p += prefix->len;
34623 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34626 + for (i = 0; i < 3; i++) {
34627 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34628 + dentry = au_sio_lkup_one(&qs, h_parent);
34629 + if (IS_ERR(dentry) || d_is_negative(dentry))
34633 + /* pr_warn("could not get random name\n"); */
34634 + dentry = ERR_PTR(-EEXIST);
34635 + AuDbg("%.*s\n", AuLNPair(&qs));
34639 + if (name != defname)
34642 + AuTraceErrPtr(dentry);
34647 + * rename the @h_dentry on @br to the whiteouted temporary name.
34649 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34652 + struct path h_path = {
34653 + .mnt = au_br_mnt(br)
34655 + struct inode *h_dir, *delegated;
34656 + struct dentry *h_parent;
34658 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34659 + h_dir = d_inode(h_parent);
34660 + IMustLock(h_dir);
34662 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34663 + err = PTR_ERR(h_path.dentry);
34664 + if (IS_ERR(h_path.dentry))
34667 + /* under the same dir, no need to lock_rename() */
34668 + delegated = NULL;
34669 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34672 + if (unlikely(err == -EWOULDBLOCK)) {
34673 + pr_warn("cannot retry for NFSv4 delegation"
34674 + " for an internal rename\n");
34677 + dput(h_path.dentry);
34684 +/* ---------------------------------------------------------------------- */
34686 + * functions for removing a whiteout
34689 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34692 + struct inode *delegated;
34695 + * forces superio when the dir has a sticky bit.
34696 + * this may be a violation of unix fs semantics.
34698 + force = (h_dir->i_mode & S_ISVTX)
34699 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34700 + delegated = NULL;
34701 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34702 + if (unlikely(err == -EWOULDBLOCK)) {
34703 + pr_warn("cannot retry for NFSv4 delegation"
34704 + " for an internal unlink\n");
34710 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34711 + struct dentry *dentry)
34715 + err = do_unlink_wh(h_dir, h_path);
34716 + if (!err && dentry)
34717 + au_set_dbwh(dentry, -1);
34722 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34723 + struct au_branch *br)
34726 + struct path h_path = {
34727 + .mnt = au_br_mnt(br)
34731 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34732 + if (IS_ERR(h_path.dentry))
34733 + err = PTR_ERR(h_path.dentry);
34735 + if (d_is_reg(h_path.dentry))
34736 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34737 + dput(h_path.dentry);
34743 +/* ---------------------------------------------------------------------- */
34745 + * initialize/clean whiteout for a branch
34748 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34752 + struct inode *delegated;
34754 + if (d_is_negative(whpath->dentry))
34758 + err = vfsub_rmdir(h_dir, whpath);
34760 + delegated = NULL;
34761 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34762 + if (unlikely(err == -EWOULDBLOCK)) {
34763 + pr_warn("cannot retry for NFSv4 delegation"
34764 + " for an internal unlink\n");
34768 + if (unlikely(err))
34769 + pr_warn("failed removing %pd (%d), ignored.\n",
34770 + whpath->dentry, err);
34773 +static int test_linkable(struct dentry *h_root)
34775 + struct inode *h_dir = d_inode(h_root);
34777 + if (h_dir->i_op->link)
34780 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34781 + h_root, au_sbtype(h_root->d_sb));
34785 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34786 +static int au_whdir(struct inode *h_dir, struct path *path)
34791 + if (d_is_negative(path->dentry)) {
34792 + int mode = S_IRWXU;
34794 + if (au_test_nfs(path->dentry->d_sb))
34796 + err = vfsub_mkdir(h_dir, path, mode);
34797 + } else if (d_is_dir(path->dentry))
34800 + pr_err("unknown %pd exists\n", path->dentry);
34805 +struct au_wh_base {
34806 + const struct qstr *name;
34807 + struct dentry *dentry;
34810 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
34811 + struct path *h_path)
34813 + h_path->dentry = base[AuBrWh_BASE].dentry;
34814 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34815 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34816 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34817 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34818 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34822 + * returns tri-state,
34823 + * minus: error, caller should print the message
34825 + * plus: error, caller should NOT print the message
34827 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
34828 + int do_plink, struct au_wh_base base[],
34829 + struct path *h_path)
34832 + struct inode *h_dir;
34834 + h_dir = d_inode(h_root);
34835 + h_path->dentry = base[AuBrWh_BASE].dentry;
34836 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34837 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34839 + err = test_linkable(h_root);
34840 + if (unlikely(err)) {
34845 + err = au_whdir(h_dir, h_path);
34846 + if (unlikely(err))
34848 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34850 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34851 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34852 + err = au_whdir(h_dir, h_path);
34853 + if (unlikely(err))
34855 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34862 + * for the moment, aufs supports the branch filesystem which does not support
34863 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
34864 + * copyup failed. finally, such filesystem will not be used as the writable
34867 + * returns tri-state, see above.
34869 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
34870 + int do_plink, struct au_wh_base base[],
34871 + struct path *h_path)
34874 + struct inode *h_dir;
34876 + WbrWhMustWriteLock(wbr);
34878 + err = test_linkable(h_root);
34879 + if (unlikely(err)) {
34885 + * todo: should this create be done in /sbin/mount.aufs helper?
34888 + h_dir = d_inode(h_root);
34889 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
34890 + h_path->dentry = base[AuBrWh_BASE].dentry;
34891 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
34892 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
34895 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
34896 + if (unlikely(err))
34899 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34901 + err = au_whdir(h_dir, h_path);
34902 + if (unlikely(err))
34904 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34906 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34907 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
34909 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34910 + err = au_whdir(h_dir, h_path);
34911 + if (unlikely(err))
34913 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34920 + * initialize the whiteout base file/dir for @br.
34922 +int au_wh_init(struct au_branch *br, struct super_block *sb)
34925 + const unsigned char do_plink
34926 + = !!au_opt_test(au_mntflags(sb), PLINK);
34927 + struct inode *h_dir;
34928 + struct path path = br->br_path;
34929 + struct dentry *h_root = path.dentry;
34930 + struct au_wbr *wbr = br->br_wbr;
34931 + static const struct qstr base_name[] = {
34932 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
34933 + sizeof(AUFS_BASE_NAME) - 1),
34934 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
34935 + sizeof(AUFS_PLINKDIR_NAME) - 1),
34936 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
34937 + sizeof(AUFS_ORPHDIR_NAME) - 1)
34939 + struct au_wh_base base[] = {
34940 + [AuBrWh_BASE] = {
34941 + .name = base_name + AuBrWh_BASE,
34944 + [AuBrWh_PLINK] = {
34945 + .name = base_name + AuBrWh_PLINK,
34948 + [AuBrWh_ORPH] = {
34949 + .name = base_name + AuBrWh_ORPH,
34955 + WbrWhMustWriteLock(wbr);
34957 + for (i = 0; i < AuBrWh_Last; i++) {
34958 + /* doubly whiteouted */
34959 + struct dentry *d;
34961 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
34962 + err = PTR_ERR(d);
34966 + base[i].dentry = d;
34968 + && wbr->wbr_wh[i]
34969 + && wbr->wbr_wh[i] != base[i].dentry);
34973 + for (i = 0; i < AuBrWh_Last; i++) {
34974 + dput(wbr->wbr_wh[i]);
34975 + wbr->wbr_wh[i] = NULL;
34979 + if (!au_br_writable(br->br_perm)) {
34980 + h_dir = d_inode(h_root);
34981 + au_wh_init_ro(h_dir, base, &path);
34982 + } else if (!au_br_wh_linkable(br->br_perm)) {
34983 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
34989 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
34995 + goto out; /* success */
34998 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
34999 + err, h_root, au_sbtype(h_root->d_sb));
35001 + for (i = 0; i < AuBrWh_Last; i++)
35002 + dput(base[i].dentry);
35006 +/* ---------------------------------------------------------------------- */
35008 + * whiteouts are all hard-linked usually.
35009 + * when its link count reaches a ceiling, we create a new whiteout base
35010 + * asynchronously.
35013 +struct reinit_br_wh {
35014 + struct super_block *sb;
35015 + struct au_branch *br;
35018 +static void reinit_br_wh(void *arg)
35021 + aufs_bindex_t bindex;
35022 + struct path h_path;
35023 + struct reinit_br_wh *a = arg;
35024 + struct au_wbr *wbr;
35025 + struct inode *dir, *delegated;
35026 + struct dentry *h_root;
35027 + struct au_hinode *hdir;
35030 + wbr = a->br->br_wbr;
35031 + /* big aufs lock */
35032 + si_noflush_write_lock(a->sb);
35033 + if (!au_br_writable(a->br->br_perm))
35035 + bindex = au_br_index(a->sb, a->br->br_id);
35036 + if (unlikely(bindex < 0))
35039 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35040 + dir = d_inode(a->sb->s_root);
35041 + hdir = au_hi(dir, bindex);
35042 + h_root = au_h_dptr(a->sb->s_root, bindex);
35043 + AuDebugOn(h_root != au_br_dentry(a->br));
35045 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35046 + wbr_wh_write_lock(wbr);
35047 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35050 + h_path.dentry = wbr->wbr_whbase;
35051 + h_path.mnt = au_br_mnt(a->br);
35052 + delegated = NULL;
35053 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35055 + if (unlikely(err == -EWOULDBLOCK)) {
35056 + pr_warn("cannot retry for NFSv4 delegation"
35057 + " for an internal unlink\n");
35061 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35064 + dput(wbr->wbr_whbase);
35065 + wbr->wbr_whbase = NULL;
35067 + err = au_wh_init(a->br, a->sb);
35068 + wbr_wh_write_unlock(wbr);
35069 + au_hn_inode_unlock(hdir);
35070 + di_read_unlock(a->sb->s_root, AuLock_IR);
35072 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35076 + atomic_dec(&wbr->wbr_wh_running);
35077 + au_br_put(a->br);
35078 + si_write_unlock(a->sb);
35079 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35081 + if (unlikely(err))
35082 + AuIOErr("err %d\n", err);
35085 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35087 + int do_dec, wkq_err;
35088 + struct reinit_br_wh *arg;
35091 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35094 + /* ignore ENOMEM */
35095 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35098 + * dec(wh_running), kfree(arg) and dec(br_count)
35099 + * in reinit function
35104 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35105 + if (unlikely(wkq_err)) {
35106 + atomic_dec(&br->br_wbr->wbr_wh_running);
35115 + atomic_dec(&br->br_wbr->wbr_wh_running);
35118 +/* ---------------------------------------------------------------------- */
35121 + * create the whiteout @wh.
35123 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35124 + struct dentry *wh)
35127 + struct path h_path = {
35130 + struct au_branch *br;
35131 + struct au_wbr *wbr;
35132 + struct dentry *h_parent;
35133 + struct inode *h_dir, *delegated;
35135 + h_parent = wh->d_parent; /* dir inode is locked */
35136 + h_dir = d_inode(h_parent);
35137 + IMustLock(h_dir);
35139 + br = au_sbr(sb, bindex);
35140 + h_path.mnt = au_br_mnt(br);
35141 + wbr = br->br_wbr;
35142 + wbr_wh_read_lock(wbr);
35143 + if (wbr->wbr_whbase) {
35144 + delegated = NULL;
35145 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35146 + if (unlikely(err == -EWOULDBLOCK)) {
35147 + pr_warn("cannot retry for NFSv4 delegation"
35148 + " for an internal link\n");
35151 + if (!err || err != -EMLINK)
35154 + /* link count full. re-initialize br_whbase. */
35155 + kick_reinit_br_wh(sb, br);
35158 + /* return this error in this context */
35159 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35161 + au_fhsm_wrote(sb, bindex, /*force*/0);
35164 + wbr_wh_read_unlock(wbr);
35168 +/* ---------------------------------------------------------------------- */
35171 + * create or remove the diropq.
35173 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35174 + unsigned int flags)
35176 + struct dentry *opq_dentry, *h_dentry;
35177 + struct super_block *sb;
35178 + struct au_branch *br;
35181 + sb = dentry->d_sb;
35182 + br = au_sbr(sb, bindex);
35183 + h_dentry = au_h_dptr(dentry, bindex);
35184 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35185 + if (IS_ERR(opq_dentry))
35188 + if (au_ftest_diropq(flags, CREATE)) {
35189 + err = link_or_create_wh(sb, bindex, opq_dentry);
35191 + au_set_dbdiropq(dentry, bindex);
35192 + goto out; /* success */
35195 + struct path tmp = {
35196 + .dentry = opq_dentry,
35197 + .mnt = au_br_mnt(br)
35199 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35201 + au_set_dbdiropq(dentry, -1);
35203 + dput(opq_dentry);
35204 + opq_dentry = ERR_PTR(err);
35207 + return opq_dentry;
35210 +struct do_diropq_args {
35211 + struct dentry **errp;
35212 + struct dentry *dentry;
35213 + aufs_bindex_t bindex;
35214 + unsigned int flags;
35217 +static void call_do_diropq(void *args)
35219 + struct do_diropq_args *a = args;
35220 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35223 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35224 + unsigned int flags)
35226 + struct dentry *diropq, *h_dentry;
35228 + h_dentry = au_h_dptr(dentry, bindex);
35229 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35230 + diropq = do_diropq(dentry, bindex, flags);
35233 + struct do_diropq_args args = {
35235 + .dentry = dentry,
35236 + .bindex = bindex,
35240 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35241 + if (unlikely(wkq_err))
35242 + diropq = ERR_PTR(wkq_err);
35248 +/* ---------------------------------------------------------------------- */
35251 + * lookup whiteout dentry.
35252 + * @h_parent: lower parent dentry which must exist and be locked
35253 + * @base_name: name of dentry which will be whiteouted
35254 + * returns dentry for whiteout.
35256 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35257 + struct au_branch *br)
35260 + struct qstr wh_name;
35261 + struct dentry *wh_dentry;
35263 + err = au_wh_name_alloc(&wh_name, base_name);
35264 + wh_dentry = ERR_PTR(err);
35266 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35267 + kfree(wh_name.name);
35269 + return wh_dentry;
35273 + * link/create a whiteout for @dentry on @bindex.
35275 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35276 + struct dentry *h_parent)
35278 + struct dentry *wh_dentry;
35279 + struct super_block *sb;
35282 + sb = dentry->d_sb;
35283 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35284 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35285 + err = link_or_create_wh(sb, bindex, wh_dentry);
35287 + au_set_dbwh(dentry, bindex);
35288 + au_fhsm_wrote(sb, bindex, /*force*/0);
35291 + wh_dentry = ERR_PTR(err);
35295 + return wh_dentry;
35298 +/* ---------------------------------------------------------------------- */
35300 +/* Delete all whiteouts in this directory on branch bindex. */
35301 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35302 + aufs_bindex_t bindex, struct au_branch *br)
35305 + unsigned long ul, n;
35306 + struct qstr wh_name;
35308 + struct hlist_head *head;
35309 + struct au_vdir_wh *pos;
35310 + struct au_vdir_destr *str;
35313 + p = (void *)__get_free_page(GFP_NOFS);
35314 + wh_name.name = p;
35315 + if (unlikely(!wh_name.name))
35319 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35320 + p += AUFS_WH_PFX_LEN;
35321 + n = whlist->nh_num;
35322 + head = whlist->nh_head;
35323 + for (ul = 0; !err && ul < n; ul++, head++) {
35324 + hlist_for_each_entry(pos, head, wh_hash) {
35325 + if (pos->wh_bindex != bindex)
35328 + str = &pos->wh_str;
35329 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35330 + memcpy(p, str->name, str->len);
35331 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35332 + err = unlink_wh_name(h_dentry, &wh_name, br);
35337 + AuIOErr("whiteout name too long %.*s\n",
35338 + str->len, str->name);
35343 + free_page((unsigned long)wh_name.name);
35349 +struct del_wh_children_args {
35351 + struct dentry *h_dentry;
35352 + struct au_nhash *whlist;
35353 + aufs_bindex_t bindex;
35354 + struct au_branch *br;
35357 +static void call_del_wh_children(void *args)
35359 + struct del_wh_children_args *a = args;
35360 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35363 +/* ---------------------------------------------------------------------- */
35365 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35367 + struct au_whtmp_rmdir *whtmp;
35369 + unsigned int rdhash;
35371 + SiMustAnyLock(sb);
35373 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35374 + if (unlikely(!whtmp)) {
35375 + whtmp = ERR_PTR(-ENOMEM);
35379 + /* no estimation for dir size */
35380 + rdhash = au_sbi(sb)->si_rdhash;
35382 + rdhash = AUFS_RDHASH_DEF;
35383 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35384 + if (unlikely(err)) {
35386 + whtmp = ERR_PTR(err);
35393 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35396 + au_br_put(whtmp->br);
35397 + dput(whtmp->wh_dentry);
35398 + iput(whtmp->dir);
35399 + au_nhash_wh_free(&whtmp->whlist);
35404 + * rmdir the whiteouted temporary named dir @h_dentry.
35405 + * @whlist: whiteouted children.
35407 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35408 + struct dentry *wh_dentry, struct au_nhash *whlist)
35411 + unsigned int h_nlink;
35412 + struct path h_tmp;
35413 + struct inode *wh_inode, *h_dir;
35414 + struct au_branch *br;
35416 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35417 + IMustLock(h_dir);
35419 + br = au_sbr(dir->i_sb, bindex);
35420 + wh_inode = d_inode(wh_dentry);
35421 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35424 + * someone else might change some whiteouts while we were sleeping.
35425 + * it means this whlist may have an obsoleted entry.
35427 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35428 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35431 + struct del_wh_children_args args = {
35433 + .h_dentry = wh_dentry,
35434 + .whlist = whlist,
35435 + .bindex = bindex,
35439 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35440 + if (unlikely(wkq_err))
35443 + inode_unlock(wh_inode);
35446 + h_tmp.dentry = wh_dentry;
35447 + h_tmp.mnt = au_br_mnt(br);
35448 + h_nlink = h_dir->i_nlink;
35449 + err = vfsub_rmdir(h_dir, &h_tmp);
35450 + /* some fs doesn't change the parent nlink in some cases */
35451 + h_nlink -= h_dir->i_nlink;
35455 + if (au_ibtop(dir) == bindex) {
35456 + /* todo: dir->i_mutex is necessary */
35457 + au_cpup_attr_timesizes(dir);
35459 + vfsub_drop_nlink(dir);
35461 + return 0; /* success */
35464 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35468 +static void call_rmdir_whtmp(void *args)
35471 + aufs_bindex_t bindex;
35472 + struct au_whtmp_rmdir *a = args;
35473 + struct super_block *sb;
35474 + struct dentry *h_parent;
35475 + struct inode *h_dir;
35476 + struct au_hinode *hdir;
35478 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35479 + /* inode_lock(a->dir); */
35481 + sb = a->dir->i_sb;
35482 + si_read_lock(sb, !AuLock_FLUSH);
35483 + if (!au_br_writable(a->br->br_perm))
35485 + bindex = au_br_index(sb, a->br->br_id);
35486 + if (unlikely(bindex < 0))
35490 + ii_write_lock_parent(a->dir);
35491 + h_parent = dget_parent(a->wh_dentry);
35492 + h_dir = d_inode(h_parent);
35493 + hdir = au_hi(a->dir, bindex);
35494 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35495 + if (unlikely(err))
35497 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35498 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35501 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35502 + au_hn_inode_unlock(hdir);
35503 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35507 + ii_write_unlock(a->dir);
35509 + /* inode_unlock(a->dir); */
35510 + au_whtmp_rmdir_free(a);
35511 + si_read_unlock(sb);
35512 + au_nwt_done(&au_sbi(sb)->si_nowait);
35513 + if (unlikely(err))
35514 + AuIOErr("err %d\n", err);
35517 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35518 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35521 + struct super_block *sb;
35525 + /* all post-process will be done in do_rmdir_whtmp(). */
35527 + args->dir = au_igrab(dir);
35528 + args->br = au_sbr(sb, bindex);
35529 + au_br_get(args->br);
35530 + args->wh_dentry = dget(wh_dentry);
35531 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35532 + if (unlikely(wkq_err)) {
35533 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35534 + au_whtmp_rmdir_free(args);
35537 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35538 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35539 +++ linux/fs/aufs/whout.h 2017-09-05 10:42:11.058755349 +0200
35542 + * Copyright (C) 2005-2017 Junjiro R. Okajima
35544 + * This program, aufs is free software; you can redistribute it and/or modify
35545 + * it under the terms of the GNU General Public License as published by
35546 + * the Free Software Foundation; either version 2 of the License, or
35547 + * (at your option) any later version.
35549 + * This program is distributed in the hope that it will be useful,
35550 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35551 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35552 + * GNU General Public License for more details.
35554 + * You should have received a copy of the GNU General Public License
35555 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35559 + * whiteout for logical deletion and opaque directory
35562 +#ifndef __AUFS_WHOUT_H__
35563 +#define __AUFS_WHOUT_H__
35570 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35571 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35572 +int au_diropq_test(struct dentry *h_dentry);
35574 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35575 + struct qstr *prefix);
35576 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35577 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35578 + struct dentry *dentry);
35579 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35581 +/* diropq flags */
35582 +#define AuDiropq_CREATE 1
35583 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35584 +#define au_fset_diropq(flags, name) \
35585 + do { (flags) |= AuDiropq_##name; } while (0)
35586 +#define au_fclr_diropq(flags, name) \
35587 + do { (flags) &= ~AuDiropq_##name; } while (0)
35589 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35590 + unsigned int flags);
35591 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35592 + struct au_branch *br);
35593 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35594 + struct dentry *h_parent);
35596 +/* real rmdir for the whiteout-ed dir */
35597 +struct au_whtmp_rmdir {
35598 + struct inode *dir;
35599 + struct au_branch *br;
35600 + struct dentry *wh_dentry;
35601 + struct au_nhash whlist;
35604 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35605 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35606 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35607 + struct dentry *wh_dentry, struct au_nhash *whlist);
35608 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35609 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35611 +/* ---------------------------------------------------------------------- */
35613 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35614 + aufs_bindex_t bindex)
35616 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35619 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35621 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35624 +#endif /* __KERNEL__ */
35625 +#endif /* __AUFS_WHOUT_H__ */
35626 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35627 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35628 +++ linux/fs/aufs/wkq.c 2017-11-12 22:24:44.707577830 +0100
35631 + * Copyright (C) 2005-2017 Junjiro R. Okajima
35633 + * This program, aufs is free software; you can redistribute it and/or modify
35634 + * it under the terms of the GNU General Public License as published by
35635 + * the Free Software Foundation; either version 2 of the License, or
35636 + * (at your option) any later version.
35638 + * This program is distributed in the hope that it will be useful,
35639 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35640 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35641 + * GNU General Public License for more details.
35643 + * You should have received a copy of the GNU General Public License
35644 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35648 + * workqueue for asynchronous/super-io operations
35649 + * todo: try new dredential scheme
35652 +#include <linux/module.h>
35655 +/* internal workqueue named AUFS_WKQ_NAME */
35657 +static struct workqueue_struct *au_wkq;
35659 +struct au_wkinfo {
35660 + struct work_struct wk;
35661 + struct kobject *kobj;
35663 + unsigned int flags; /* see wkq.h */
35665 + au_wkq_func_t func;
35668 +#ifdef CONFIG_LOCKDEP
35670 + struct held_lock **hlock;
35673 + struct completion *comp;
35676 +/* ---------------------------------------------------------------------- */
35678 + * Aufs passes some operations to the workqueue such as the internal copyup.
35679 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35680 + * job run by workqueue depends upon the locks acquired in the other task.
35681 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35682 + * information too. And the job in the workqueue restores the info in order to
35683 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35684 + * correctly and expectedly.
35687 +#ifndef CONFIG_LOCKDEP
35688 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35689 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35690 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35691 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35692 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35694 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35696 + wkinfo->hlock = NULL;
35697 + wkinfo->dont_check = 0;
35704 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35706 + static DEFINE_SPINLOCK(spin);
35709 + struct lock_class_key *key;
35711 + { .name = "&sbinfo->si_rwsem" },
35712 + { .name = "&finfo->fi_rwsem" },
35713 + { .name = "&dinfo->di_rwsem" },
35714 + { .name = "&iinfo->ii_rwsem" }
35719 + /* lockless read from 'set.' see below */
35720 + if (set == ARRAY_SIZE(a)) {
35721 + for (i = 0; i < ARRAY_SIZE(a); i++)
35722 + if (a[i].key == key)
35727 + spin_lock(&spin);
35729 + for (i = 0; i < ARRAY_SIZE(a); i++)
35730 + if (a[i].key == key) {
35731 + spin_unlock(&spin);
35734 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35736 + if (unlikely(a[i].key == key)) { /* rare but possible */
35737 + spin_unlock(&spin);
35742 + if (strstr(a[i].name, name)) {
35744 + * the order of these three lines is important for the
35745 + * lockless read above.
35748 + spin_unlock(&spin);
35750 + /* AuDbg("%d, %s\n", set, name); */
35754 + spin_unlock(&spin);
35763 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35766 + struct task_struct *curr;
35767 + struct held_lock **hl, *held_locks, *p;
35771 + wkinfo->dont_check = lockdep_recursing(curr);
35772 + if (wkinfo->dont_check)
35774 + n = curr->lockdep_depth;
35779 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35780 + if (unlikely(!wkinfo->hlock))
35785 + if (0 && au_debug_test()) /* left for debugging */
35786 + lockdep_print_held_locks(curr);
35788 + held_locks = curr->held_locks;
35789 + hl = wkinfo->hlock;
35791 + p = held_locks++;
35792 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35801 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35803 + kfree(wkinfo->hlock);
35806 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
35808 + struct held_lock *p, **hl = wkinfo->hlock;
35811 + if (wkinfo->dont_check)
35815 + while ((p = *hl++)) { /* assignment */
35816 + subclass = lockdep_hlock_class(p)->subclass;
35817 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
35819 + rwsem_acquire_read(p->instance, subclass, 0,
35820 + /*p->acquire_ip*/_RET_IP_);
35822 + rwsem_acquire(p->instance, subclass, 0,
35823 + /*p->acquire_ip*/_RET_IP_);
35827 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
35829 + struct held_lock *p, **hl = wkinfo->hlock;
35831 + if (wkinfo->dont_check)
35835 + while ((p = *hl++)) /* assignment */
35836 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
35840 +static void wkq_func(struct work_struct *wk)
35842 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
35844 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
35845 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
35847 + au_wkq_lockdep_pre(wkinfo);
35848 + wkinfo->func(wkinfo->args);
35849 + au_wkq_lockdep_post(wkinfo);
35850 + if (au_ftest_wkq(wkinfo->flags, WAIT))
35851 + complete(wkinfo->comp);
35853 + kobject_put(wkinfo->kobj);
35854 + module_put(THIS_MODULE); /* todo: ?? */
35860 + * Since struct completion is large, try allocating it dynamically.
35862 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
35863 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
35865 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
35867 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
35869 + init_completion(*comp);
35870 + wkinfo->comp = *comp;
35876 +static void au_wkq_comp_free(struct completion *comp)
35884 +#define AuWkqCompDeclare(name) \
35885 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
35886 + struct completion *comp = &_ ## name
35888 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
35890 + wkinfo->comp = *comp;
35894 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
35898 +#endif /* 4KSTACKS */
35900 +static void au_wkq_run(struct au_wkinfo *wkinfo)
35902 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
35903 + if (au_wkq_test()) {
35904 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
35905 + " due to a dead dir by UDBA?\n");
35906 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
35909 + au_dbg_verify_kthread();
35911 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
35912 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
35913 + queue_work(au_wkq, &wkinfo->wk);
35915 + INIT_WORK(&wkinfo->wk, wkq_func);
35916 + schedule_work(&wkinfo->wk);
35921 + * Be careful. It is easy to make deadlock happen.
35922 + * processA: lock, wkq and wait
35923 + * processB: wkq and wait, lock in wkq
35926 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
35929 + AuWkqCompDeclare(comp);
35930 + struct au_wkinfo wkinfo = {
35936 + err = au_wkq_comp_alloc(&wkinfo, &comp);
35937 + if (unlikely(err))
35939 + err = au_wkq_lockdep_alloc(&wkinfo);
35940 + if (unlikely(err))
35943 + au_wkq_run(&wkinfo);
35944 + /* no timeout, no interrupt */
35945 + wait_for_completion(wkinfo.comp);
35947 + au_wkq_lockdep_free(&wkinfo);
35950 + au_wkq_comp_free(comp);
35952 + destroy_work_on_stack(&wkinfo.wk);
35957 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
35958 + * problem in a concurrent umounting.
35960 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
35961 + unsigned int flags)
35964 + struct au_wkinfo *wkinfo;
35966 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
35969 + * wkq_func() must free this wkinfo.
35970 + * it highly depends upon the implementation of workqueue.
35973 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
35975 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
35976 + wkinfo->flags = flags & ~AuWkq_WAIT;
35977 + wkinfo->func = func;
35978 + wkinfo->args = args;
35979 + wkinfo->comp = NULL;
35980 + au_wkq_lockdep_init(wkinfo);
35981 + kobject_get(wkinfo->kobj);
35982 + __module_get(THIS_MODULE); /* todo: ?? */
35984 + au_wkq_run(wkinfo);
35987 + au_nwt_done(&au_sbi(sb)->si_nowait);
35993 +/* ---------------------------------------------------------------------- */
35995 +void au_nwt_init(struct au_nowait_tasks *nwt)
35997 + atomic_set(&nwt->nw_len, 0);
35998 + /* smp_mb(); */ /* atomic_set */
35999 + init_waitqueue_head(&nwt->nw_wq);
36002 +void au_wkq_fin(void)
36004 + destroy_workqueue(au_wkq);
36007 +int __init au_wkq_init(void)
36012 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36013 + if (IS_ERR(au_wkq))
36014 + err = PTR_ERR(au_wkq);
36015 + else if (!au_wkq)
36020 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36021 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36022 +++ linux/fs/aufs/wkq.h 2017-11-12 22:24:44.707577830 +0100
36025 + * Copyright (C) 2005-2017 Junjiro R. Okajima
36027 + * This program, aufs is free software; you can redistribute it and/or modify
36028 + * it under the terms of the GNU General Public License as published by
36029 + * the Free Software Foundation; either version 2 of the License, or
36030 + * (at your option) any later version.
36032 + * This program is distributed in the hope that it will be useful,
36033 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36034 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36035 + * GNU General Public License for more details.
36037 + * You should have received a copy of the GNU General Public License
36038 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36042 + * workqueue for asynchronous/super-io operations
36043 + * todo: try new credentials management scheme
36046 +#ifndef __AUFS_WKQ_H__
36047 +#define __AUFS_WKQ_H__
36051 +#include <linux/wait.h>
36053 +struct super_block;
36055 +/* ---------------------------------------------------------------------- */
36058 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36060 +struct au_nowait_tasks {
36062 + wait_queue_head_t nw_wq;
36065 +/* ---------------------------------------------------------------------- */
36067 +typedef void (*au_wkq_func_t)(void *args);
36070 +#define AuWkq_WAIT 1
36071 +#define AuWkq_NEST (1 << 1)
36072 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36073 +#define au_fset_wkq(flags, name) \
36074 + do { (flags) |= AuWkq_##name; } while (0)
36075 +#define au_fclr_wkq(flags, name) \
36076 + do { (flags) &= ~AuWkq_##name; } while (0)
36078 +#ifndef CONFIG_AUFS_HNOTIFY
36080 +#define AuWkq_NEST 0
36084 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36085 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36086 + unsigned int flags);
36087 +void au_nwt_init(struct au_nowait_tasks *nwt);
36088 +int __init au_wkq_init(void);
36089 +void au_wkq_fin(void);
36091 +/* ---------------------------------------------------------------------- */
36093 +static inline int au_wkq_test(void)
36095 + return current->flags & PF_WQ_WORKER;
36098 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36100 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36103 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36105 + if (atomic_dec_and_test(&nwt->nw_len))
36106 + wake_up_all(&nwt->nw_wq);
36109 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36111 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36115 +#endif /* __KERNEL__ */
36116 +#endif /* __AUFS_WKQ_H__ */
36117 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36118 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36119 +++ linux/fs/aufs/xattr.c 2017-11-12 22:24:44.707577830 +0100
36122 + * Copyright (C) 2014-2017 Junjiro R. Okajima
36124 + * This program, aufs is free software; you can redistribute it and/or modify
36125 + * it under the terms of the GNU General Public License as published by
36126 + * the Free Software Foundation; either version 2 of the License, or
36127 + * (at your option) any later version.
36129 + * This program is distributed in the hope that it will be useful,
36130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36132 + * GNU General Public License for more details.
36134 + * You should have received a copy of the GNU General Public License
36135 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36139 + * handling xattr functions
36142 +#include <linux/fs.h>
36143 +#include <linux/posix_acl_xattr.h>
36144 +#include <linux/xattr.h>
36147 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36149 + if (!ignore_flags)
36157 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36162 +#define cmp(brattr, prefix) do { \
36163 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36164 + XATTR_##prefix##_PREFIX_LEN)) { \
36165 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36171 + cmp(SEC, SECURITY);
36172 + cmp(SYS, SYSTEM);
36173 + cmp(TR, TRUSTED);
36177 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36184 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36186 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36187 + char *name, char **buf, unsigned int ignore_flags,
36188 + unsigned int verbose)
36192 + struct inode *h_idst;
36194 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36196 + if (unlikely(err <= 0)) {
36197 + if (err == -ENODATA
36198 + || (err == -EOPNOTSUPP
36199 + && ((ignore_flags & au_xattr_out_of_list)
36200 + || (au_test_nfs_noacl(d_inode(h_src))
36201 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36203 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36206 + if (err && (verbose || au_debug_test()))
36207 + pr_err("%s, err %d\n", name, err);
36211 + /* unlock it temporary */
36212 + h_idst = d_inode(h_dst);
36213 + inode_unlock(h_idst);
36214 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36215 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36216 + if (unlikely(err)) {
36217 + if (verbose || au_debug_test())
36218 + pr_err("%s, err %d\n", name, err);
36219 + err = au_xattr_ignore(err, name, ignore_flags);
36226 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36227 + unsigned int verbose)
36229 + int err, unlocked, acl_access, acl_default;
36231 + struct inode *h_isrc, *h_idst;
36232 + char *value, *p, *o, *e;
36234 + /* try stopping to update the source inode while we are referencing */
36235 + /* there should not be the parent-child relationship between them */
36236 + h_isrc = d_inode(h_src);
36237 + h_idst = d_inode(h_dst);
36238 + inode_unlock(h_idst);
36239 + vfsub_inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36240 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36243 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36244 + ssz = vfs_listxattr(h_src, NULL, 0);
36246 + if (unlikely(err < 0)) {
36248 + if (err == -ENODATA
36249 + || err == -EOPNOTSUPP)
36250 + err = 0; /* ignore */
36259 + p = kmalloc(ssz, GFP_NOFS);
36261 + if (unlikely(!p))
36263 + err = vfs_listxattr(h_src, p, ssz);
36265 + inode_unlock_shared(h_isrc);
36267 + AuDbg("err %d, ssz %zd\n", err, ssz);
36268 + if (unlikely(err < 0))
36276 + while (!err && p < e) {
36277 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36278 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36279 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36280 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36282 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36284 + p += strlen(p) + 1;
36287 + ignore_flags |= au_xattr_out_of_list;
36288 + if (!err && !acl_access) {
36289 + err = au_do_cpup_xattr(h_dst, h_src,
36290 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36291 + ignore_flags, verbose);
36294 + if (!err && !acl_default) {
36295 + err = au_do_cpup_xattr(h_dst, h_src,
36296 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36297 + ignore_flags, verbose);
36307 + inode_unlock_shared(h_isrc);
36312 +/* ---------------------------------------------------------------------- */
36314 +static int au_smack_reentering(struct super_block *sb)
36316 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36318 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36319 + * i_op->getxattr(). ouch.
36321 + return si_pid_test(sb);
36332 +struct au_lgxattr {
36340 + const char *name;
36347 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36351 + struct path h_path;
36352 + struct super_block *sb;
36354 + sb = dentry->d_sb;
36355 + reenter = au_smack_reentering(sb);
36357 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36358 + if (unlikely(err))
36361 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36362 + if (unlikely(err))
36364 + if (unlikely(!h_path.dentry))
36365 + /* illegally overlapped or something */
36366 + goto out_di; /* pretending success */
36368 + /* always topmost entry only */
36369 + switch (arg->type) {
36370 + case AU_XATTR_LIST:
36371 + err = vfs_listxattr(h_path.dentry,
36372 + arg->u.list.list, arg->u.list.size);
36374 + case AU_XATTR_GET:
36375 + AuDebugOn(d_is_negative(h_path.dentry));
36376 + err = vfs_getxattr(h_path.dentry,
36377 + arg->u.get.name, arg->u.get.value,
36378 + arg->u.get.size);
36384 + di_read_unlock(dentry, AuLock_IR);
36387 + si_read_unlock(sb);
36393 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36395 + struct au_lgxattr arg = {
36396 + .type = AU_XATTR_LIST,
36403 + return au_lgxattr(dentry, &arg);
36406 +static ssize_t au_getxattr(struct dentry *dentry,
36407 + struct inode *inode __maybe_unused,
36408 + const char *name, void *value, size_t size)
36410 + struct au_lgxattr arg = {
36411 + .type = AU_XATTR_GET,
36419 + return au_lgxattr(dentry, &arg);
36422 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36423 + const char *name, const void *value, size_t size,
36426 + struct au_sxattr arg = {
36427 + .type = AU_XATTR_SET,
36436 + return au_sxattr(dentry, inode, &arg);
36439 +/* ---------------------------------------------------------------------- */
36441 +static int au_xattr_get(const struct xattr_handler *handler,
36442 + struct dentry *dentry, struct inode *inode,
36443 + const char *name, void *buffer, size_t size)
36445 + return au_getxattr(dentry, inode, name, buffer, size);
36448 +static int au_xattr_set(const struct xattr_handler *handler,
36449 + struct dentry *dentry, struct inode *inode,
36450 + const char *name, const void *value, size_t size,
36453 + return au_setxattr(dentry, inode, name, value, size, flags);
36456 +static const struct xattr_handler au_xattr_handler = {
36459 + .get = au_xattr_get,
36460 + .set = au_xattr_set
36463 +static const struct xattr_handler *au_xattr_handlers[] = {
36464 +#ifdef CONFIG_FS_POSIX_ACL
36465 + &posix_acl_access_xattr_handler,
36466 + &posix_acl_default_xattr_handler,
36468 + &au_xattr_handler, /* must be last */
36472 +void au_xattr_init(struct super_block *sb)
36474 + sb->s_xattr = au_xattr_handlers;
36476 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36477 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36478 +++ linux/fs/aufs/xino.c 2017-11-12 22:24:44.710911257 +0100
36481 + * Copyright (C) 2005-2017 Junjiro R. Okajima
36483 + * This program, aufs is free software; you can redistribute it and/or modify
36484 + * it under the terms of the GNU General Public License as published by
36485 + * the Free Software Foundation; either version 2 of the License, or
36486 + * (at your option) any later version.
36488 + * This program is distributed in the hope that it will be useful,
36489 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36490 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36491 + * GNU General Public License for more details.
36493 + * You should have received a copy of the GNU General Public License
36494 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36498 + * external inode number translation table and bitmap
36501 +#include <linux/seq_file.h>
36502 +#include <linux/statfs.h>
36505 +/* todo: unnecessary to support mmap_sem since kernel-space? */
36506 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
36510 + mm_segment_t oldfs;
36517 + oldfs = get_fs();
36518 + set_fs(KERNEL_DS);
36520 + /* todo: signal_pending? */
36521 + err = func(file, buf.u, size, pos);
36522 + } while (err == -EAGAIN || err == -EINTR);
36525 +#if 0 /* reserved for future use */
36527 + fsnotify_access(file->f_path.dentry);
36533 +/* ---------------------------------------------------------------------- */
36535 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
36536 + size_t size, loff_t *pos);
36538 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
36539 + size_t size, loff_t *pos)
36542 + mm_segment_t oldfs;
36545 + const char __user *u;
36548 + const int prevent_endless = 10;
36552 + oldfs = get_fs();
36553 + set_fs(KERNEL_DS);
36555 + err = func(file, buf.u, size, pos);
36556 + if (err == -EINTR
36557 + && !au_wkq_test()
36558 + && fatal_signal_pending(current)) {
36560 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
36561 + BUG_ON(err == -EINTR);
36562 + oldfs = get_fs();
36563 + set_fs(KERNEL_DS);
36565 + } while (i++ < prevent_endless
36566 + && (err == -EAGAIN || err == -EINTR));
36569 +#if 0 /* reserved for future use */
36571 + fsnotify_modify(file->f_path.dentry);
36577 +struct do_xino_fwrite_args {
36579 + vfs_writef_t func;
36580 + struct file *file;
36586 +static void call_do_xino_fwrite(void *args)
36588 + struct do_xino_fwrite_args *a = args;
36589 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
36592 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
36593 + size_t size, loff_t *pos)
36597 + struct do_xino_fwrite_args args = {
36607 + * it breaks RLIMIT_FSIZE and normal user's limit,
36608 + * users should care about quota and real 'filesystem full.'
36610 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
36611 + if (unlikely(wkq_err))
36617 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
36618 + size_t size, loff_t *pos)
36622 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
36624 + err = do_xino_fwrite(func, file, buf, size, pos);
36628 + err = xino_fwrite_wkq(func, file, buf, size, pos);
36635 +/* ---------------------------------------------------------------------- */
36638 + * create a new xinofile at the same place/path as @base_file.
36640 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
36642 + struct file *file;
36643 + struct dentry *base, *parent;
36644 + struct inode *dir, *delegated;
36645 + struct qstr *name;
36646 + struct path path;
36649 + base = base_file->f_path.dentry;
36650 + parent = base->d_parent; /* dir inode is locked */
36651 + dir = d_inode(parent);
36654 + file = ERR_PTR(-EINVAL);
36655 + name = &base->d_name;
36656 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36657 + if (IS_ERR(path.dentry)) {
36658 + file = (void *)path.dentry;
36659 + pr_err("%pd lookup err %ld\n",
36660 + base, PTR_ERR(path.dentry));
36664 + /* no need to mnt_want_write() since we call dentry_open() later */
36665 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
36666 + if (unlikely(err)) {
36667 + file = ERR_PTR(err);
36668 + pr_err("%pd create err %d\n", base, err);
36672 + path.mnt = base_file->f_path.mnt;
36673 + file = vfsub_dentry_open(&path,
36674 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36675 + /* | __FMODE_NONOTIFY */);
36676 + if (IS_ERR(file)) {
36677 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
36681 + delegated = NULL;
36682 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36683 + if (unlikely(err == -EWOULDBLOCK)) {
36684 + pr_warn("cannot retry for NFSv4 delegation"
36685 + " for an internal unlink\n");
36688 + if (unlikely(err)) {
36689 + pr_err("%pd unlink err %d\n", base, err);
36694 + /* no one can touch copy_src xino */
36695 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36696 + if (unlikely(err)) {
36697 + pr_err("%pd copy err %d\n", base, err);
36701 + goto out_dput; /* success */
36705 + file = ERR_PTR(err);
36707 + dput(path.dentry);
36712 +struct au_xino_lock_dir {
36713 + struct au_hinode *hdir;
36714 + struct dentry *parent;
36715 + struct inode *dir;
36718 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
36719 + struct au_xino_lock_dir *ldir)
36721 + aufs_bindex_t brid, bindex;
36723 + ldir->hdir = NULL;
36725 + brid = au_xino_brid(sb);
36727 + bindex = au_br_index(sb, brid);
36728 + if (bindex >= 0) {
36729 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36730 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36732 + ldir->parent = dget_parent(xino->f_path.dentry);
36733 + ldir->dir = d_inode(ldir->parent);
36734 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
36738 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36741 + au_hn_inode_unlock(ldir->hdir);
36743 + inode_unlock(ldir->dir);
36744 + dput(ldir->parent);
36748 +/* ---------------------------------------------------------------------- */
36750 +/* trucate xino files asynchronously */
36752 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
36755 + unsigned long jiffy;
36757 + aufs_bindex_t bi, bbot;
36758 + struct kstatfs *st;
36759 + struct au_branch *br;
36760 + struct file *new_xino, *file;
36761 + struct super_block *h_sb;
36762 + struct au_xino_lock_dir ldir;
36765 + st = kmalloc(sizeof(*st), GFP_NOFS);
36766 + if (unlikely(!st))
36770 + bbot = au_sbbot(sb);
36771 + if (unlikely(bindex < 0 || bbot < bindex))
36773 + br = au_sbr(sb, bindex);
36774 + file = br->br_xino.xi_file;
36778 + err = vfs_statfs(&file->f_path, st);
36779 + if (unlikely(err))
36780 + AuErr1("statfs err %d, ignored\n", err);
36782 + blocks = file_inode(file)->i_blocks;
36783 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36784 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
36786 + au_xino_lock_dir(sb, file, &ldir);
36787 + /* mnt_want_write() is unnecessary here */
36788 + new_xino = au_xino_create2(file, file);
36789 + au_xino_unlock_dir(&ldir);
36790 + err = PTR_ERR(new_xino);
36791 + if (IS_ERR(new_xino)) {
36792 + pr_err("err %d, ignored\n", err);
36797 + br->br_xino.xi_file = new_xino;
36799 + h_sb = au_br_sb(br);
36800 + for (bi = 0; bi <= bbot; bi++) {
36801 + if (unlikely(bi == bindex))
36803 + br = au_sbr(sb, bi);
36804 + if (au_br_sb(br) != h_sb)
36807 + fput(br->br_xino.xi_file);
36808 + br->br_xino.xi_file = new_xino;
36809 + get_file(new_xino);
36812 + err = vfs_statfs(&new_xino->f_path, st);
36814 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36815 + bindex, (u64)file_inode(new_xino)->i_blocks,
36816 + st->f_bfree, st->f_blocks);
36817 + if (file_inode(new_xino)->i_blocks < blocks)
36818 + au_sbi(sb)->si_xino_jiffy = jiffy;
36820 + AuErr1("statfs err %d, ignored\n", err);
36828 +struct xino_do_trunc_args {
36829 + struct super_block *sb;
36830 + struct au_branch *br;
36833 +static void xino_do_trunc(void *_args)
36835 + struct xino_do_trunc_args *args = _args;
36836 + struct super_block *sb;
36837 + struct au_branch *br;
36838 + struct inode *dir;
36840 + aufs_bindex_t bindex;
36844 + dir = d_inode(sb->s_root);
36847 + si_noflush_write_lock(sb);
36848 + ii_read_lock_parent(dir);
36849 + bindex = au_br_index(sb, br->br_id);
36850 + err = au_xino_trunc(sb, bindex);
36851 + ii_read_unlock(dir);
36852 + if (unlikely(err))
36853 + pr_warn("err b%d, (%d)\n", bindex, err);
36854 + atomic_dec(&br->br_xino_running);
36856 + si_write_unlock(sb);
36857 + au_nwt_done(&au_sbi(sb)->si_nowait);
36861 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
36864 + struct kstatfs st;
36865 + struct au_sbinfo *sbinfo;
36867 + /* todo: si_xino_expire and the ratio should be customizable */
36868 + sbinfo = au_sbi(sb);
36869 + if (time_before(jiffies,
36870 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
36873 + /* truncation border */
36874 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
36875 + if (unlikely(err)) {
36876 + AuErr1("statfs err %d, ignored\n", err);
36879 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
36885 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
36887 + struct xino_do_trunc_args *args;
36890 + if (!xino_trunc_test(sb, br))
36893 + if (atomic_inc_return(&br->br_xino_running) > 1)
36896 + /* lock and kfree() will be called in trunc_xino() */
36897 + args = kmalloc(sizeof(*args), GFP_NOFS);
36898 + if (unlikely(!args)) {
36899 + AuErr1("no memory\n");
36906 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
36908 + return; /* success */
36910 + pr_err("wkq %d\n", wkq_err);
36915 + atomic_dec(&br->br_xino_running);
36918 +/* ---------------------------------------------------------------------- */
36920 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
36921 + ino_t h_ino, ino_t ino)
36927 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
36928 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
36931 + pos *= sizeof(ino);
36932 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
36933 + if (sz == sizeof(ino))
36934 + return 0; /* success */
36936 + AuIOErr("write failed (%zd)\n", sz);
36941 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
36942 + * at the position of @h_ino.
36943 + * even if @ino is zero, it is written to the xinofile and means no entry.
36944 + * if the size of the xino file on a specific filesystem exceeds the watermark,
36945 + * try truncating it.
36947 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
36951 + unsigned int mnt_flags;
36952 + struct au_branch *br;
36954 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
36955 + || ((loff_t)-1) > 0);
36956 + SiMustAnyLock(sb);
36958 + mnt_flags = au_mntflags(sb);
36959 + if (!au_opt_test(mnt_flags, XINO))
36962 + br = au_sbr(sb, bindex);
36963 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
36966 + if (au_opt_test(mnt_flags, TRUNC_XINO)
36967 + && au_test_fs_trunc_xino(au_br_sb(br)))
36968 + xino_try_trunc(sb, br);
36969 + return 0; /* success */
36972 + AuIOErr("write failed (%d)\n", err);
36976 +/* ---------------------------------------------------------------------- */
36978 +/* aufs inode number bitmap */
36980 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
36981 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
36985 + AuDebugOn(bit < 0 || page_bits <= bit);
36986 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
36990 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
36992 + AuDebugOn(ino < AUFS_FIRST_INO);
36993 + ino -= AUFS_FIRST_INO;
36994 + *pindex = ino / page_bits;
36995 + *bit = ino % page_bits;
36998 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37003 + struct au_sbinfo *sbinfo;
37004 + struct file *xib;
37005 + unsigned long *p;
37007 + sbinfo = au_sbi(sb);
37008 + MtxMustLock(&sbinfo->si_xib_mtx);
37009 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37010 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37012 + if (pindex == sbinfo->si_xib_last_pindex)
37015 + xib = sbinfo->si_xib;
37016 + p = sbinfo->si_xib_buf;
37017 + pos = sbinfo->si_xib_last_pindex;
37018 + pos *= PAGE_SIZE;
37019 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37020 + if (unlikely(sz != PAGE_SIZE))
37024 + pos *= PAGE_SIZE;
37025 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37026 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37028 + memset(p, 0, PAGE_SIZE);
37029 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37031 + if (sz == PAGE_SIZE) {
37032 + sbinfo->si_xib_last_pindex = pindex;
37033 + return 0; /* success */
37037 + AuIOErr1("write failed (%zd)\n", sz);
37044 +/* ---------------------------------------------------------------------- */
37046 +static void au_xib_clear_bit(struct inode *inode)
37049 + unsigned long pindex;
37050 + struct super_block *sb;
37051 + struct au_sbinfo *sbinfo;
37053 + AuDebugOn(inode->i_nlink);
37055 + sb = inode->i_sb;
37056 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37057 + AuDebugOn(page_bits <= bit);
37058 + sbinfo = au_sbi(sb);
37059 + mutex_lock(&sbinfo->si_xib_mtx);
37060 + err = xib_pindex(sb, pindex);
37062 + clear_bit(bit, sbinfo->si_xib_buf);
37063 + sbinfo->si_xib_next_bit = bit;
37065 + mutex_unlock(&sbinfo->si_xib_mtx);
37068 +/* for s_op->delete_inode() */
37069 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
37072 + unsigned int mnt_flags;
37073 + aufs_bindex_t bindex, bbot, bi;
37074 + unsigned char try_trunc;
37075 + struct au_iinfo *iinfo;
37076 + struct super_block *sb;
37077 + struct au_hinode *hi;
37078 + struct inode *h_inode;
37079 + struct au_branch *br;
37080 + vfs_writef_t xwrite;
37082 + AuDebugOn(au_is_bad_inode(inode));
37084 + sb = inode->i_sb;
37085 + mnt_flags = au_mntflags(sb);
37086 + if (!au_opt_test(mnt_flags, XINO)
37087 + || inode->i_ino == AUFS_ROOT_INO)
37091 + au_xigen_inc(inode);
37092 + au_xib_clear_bit(inode);
37095 + iinfo = au_ii(inode);
37096 + bindex = iinfo->ii_btop;
37100 + xwrite = au_sbi(sb)->si_xwrite;
37101 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
37102 + hi = au_hinode(iinfo, bindex);
37103 + bbot = iinfo->ii_bbot;
37104 + for (; bindex <= bbot; bindex++, hi++) {
37105 + h_inode = hi->hi_inode;
37107 + || (!unlinked && h_inode->i_nlink))
37110 + /* inode may not be revalidated */
37111 + bi = au_br_index(sb, hi->hi_id);
37115 + br = au_sbr(sb, bi);
37116 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
37117 + h_inode->i_ino, /*ino*/0);
37118 + if (!err && try_trunc
37119 + && au_test_fs_trunc_xino(au_br_sb(br)))
37120 + xino_try_trunc(sb, br);
37124 +/* get an unused inode number from bitmap */
37125 +ino_t au_xino_new_ino(struct super_block *sb)
37128 + unsigned long *p, pindex, ul, pend;
37129 + struct au_sbinfo *sbinfo;
37130 + struct file *file;
37131 + int free_bit, err;
37133 + if (!au_opt_test(au_mntflags(sb), XINO))
37134 + return iunique(sb, AUFS_FIRST_INO);
37136 + sbinfo = au_sbi(sb);
37137 + mutex_lock(&sbinfo->si_xib_mtx);
37138 + p = sbinfo->si_xib_buf;
37139 + free_bit = sbinfo->si_xib_next_bit;
37140 + if (free_bit < page_bits && !test_bit(free_bit, p))
37141 + goto out; /* success */
37142 + free_bit = find_first_zero_bit(p, page_bits);
37143 + if (free_bit < page_bits)
37144 + goto out; /* success */
37146 + pindex = sbinfo->si_xib_last_pindex;
37147 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
37148 + err = xib_pindex(sb, ul);
37149 + if (unlikely(err))
37151 + free_bit = find_first_zero_bit(p, page_bits);
37152 + if (free_bit < page_bits)
37153 + goto out; /* success */
37156 + file = sbinfo->si_xib;
37157 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
37158 + for (ul = pindex + 1; ul <= pend; ul++) {
37159 + err = xib_pindex(sb, ul);
37160 + if (unlikely(err))
37162 + free_bit = find_first_zero_bit(p, page_bits);
37163 + if (free_bit < page_bits)
37164 + goto out; /* success */
37169 + set_bit(free_bit, p);
37170 + sbinfo->si_xib_next_bit = free_bit + 1;
37171 + pindex = sbinfo->si_xib_last_pindex;
37172 + mutex_unlock(&sbinfo->si_xib_mtx);
37173 + ino = xib_calc_ino(pindex, free_bit);
37174 + AuDbg("i%lu\n", (unsigned long)ino);
37177 + mutex_unlock(&sbinfo->si_xib_mtx);
37183 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37184 + * at the position of @h_ino.
37185 + * if @ino does not exist and @do_new is true, get new one.
37187 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37193 + struct file *file;
37194 + struct au_sbinfo *sbinfo;
37197 + if (!au_opt_test(au_mntflags(sb), XINO))
37198 + return 0; /* no xino */
37201 + sbinfo = au_sbi(sb);
37203 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
37204 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
37207 + pos *= sizeof(*ino);
37209 + file = au_sbr(sb, bindex)->br_xino.xi_file;
37210 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
37211 + return 0; /* no ino */
37213 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
37214 + if (sz == sizeof(*ino))
37215 + return 0; /* success */
37218 + if (unlikely(sz >= 0)) {
37220 + AuIOErr("xino read error (%zd)\n", sz);
37226 +/* ---------------------------------------------------------------------- */
37228 +/* create and set a new xino file */
37230 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
37232 + struct file *file;
37233 + struct dentry *h_parent, *d;
37234 + struct inode *h_dir, *inode;
37238 + * at mount-time, and the xino file is the default path,
37239 + * hnotify is disabled so we have no notify events to ignore.
37240 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37242 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37243 + /* | __FMODE_NONOTIFY */,
37244 + S_IRUGO | S_IWUGO);
37245 + if (IS_ERR(file)) {
37247 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
37251 + /* keep file count */
37253 + inode = file_inode(file);
37254 + h_parent = dget_parent(file->f_path.dentry);
37255 + h_dir = d_inode(h_parent);
37256 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
37257 + /* mnt_want_write() is unnecessary here */
37258 + /* no delegation since it is just created */
37259 + if (inode->i_nlink)
37260 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37262 + inode_unlock(h_dir);
37264 + if (unlikely(err)) {
37266 + pr_err("unlink %s(%d)\n", fname, err);
37271 + d = file->f_path.dentry;
37272 + if (unlikely(sb == d->d_sb)) {
37274 + pr_err("%s must be outside\n", fname);
37277 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37279 + pr_err("xino doesn't support %s(%s)\n",
37280 + fname, au_sbtype(d->d_sb));
37283 + return file; /* success */
37287 + file = ERR_PTR(err);
37292 + * find another branch who is on the same filesystem of the specified
37293 + * branch{@btgt}. search until @bbot.
37295 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37296 + aufs_bindex_t bbot)
37298 + aufs_bindex_t bindex;
37299 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
37301 + for (bindex = 0; bindex < btgt; bindex++)
37302 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
37304 + for (bindex++; bindex <= bbot; bindex++)
37305 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
37310 +/* ---------------------------------------------------------------------- */
37313 + * initialize the xinofile for the specified branch @br
37314 + * at the place/path where @base_file indicates.
37315 + * test whether another branch is on the same filesystem or not,
37316 + * if @do_test is true.
37318 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
37319 + struct file *base_file, int do_test)
37323 + aufs_bindex_t bbot, bindex;
37324 + struct au_branch *shared_br, *b;
37325 + struct file *file;
37326 + struct super_block *tgt_sb;
37328 + shared_br = NULL;
37329 + bbot = au_sbbot(sb);
37331 + tgt_sb = au_br_sb(br);
37332 + for (bindex = 0; bindex <= bbot; bindex++) {
37333 + b = au_sbr(sb, bindex);
37334 + if (tgt_sb == au_br_sb(b)) {
37341 + if (!shared_br || !shared_br->br_xino.xi_file) {
37342 + struct au_xino_lock_dir ldir;
37344 + au_xino_lock_dir(sb, base_file, &ldir);
37345 + /* mnt_want_write() is unnecessary here */
37346 + file = au_xino_create2(base_file, NULL);
37347 + au_xino_unlock_dir(&ldir);
37348 + err = PTR_ERR(file);
37349 + if (IS_ERR(file))
37351 + br->br_xino.xi_file = file;
37353 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
37354 + get_file(br->br_xino.xi_file);
37357 + ino = AUFS_ROOT_INO;
37358 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
37360 + if (unlikely(err)) {
37361 + fput(br->br_xino.xi_file);
37362 + br->br_xino.xi_file = NULL;
37369 +/* ---------------------------------------------------------------------- */
37371 +/* trucate a xino bitmap file */
37374 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37378 + unsigned long pindex;
37379 + loff_t pos, pend;
37380 + struct au_sbinfo *sbinfo;
37381 + vfs_readf_t func;
37383 + unsigned long *p;
37386 + sbinfo = au_sbi(sb);
37387 + MtxMustLock(&sbinfo->si_xib_mtx);
37388 + p = sbinfo->si_xib_buf;
37389 + func = sbinfo->si_xread;
37390 + pend = vfsub_f_size_read(file);
37392 + while (pos < pend) {
37393 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37395 + if (unlikely(sz <= 0))
37399 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37400 + if (unlikely(*ino < AUFS_FIRST_INO))
37403 + xib_calc_bit(*ino, &pindex, &bit);
37404 + AuDebugOn(page_bits <= bit);
37405 + err = xib_pindex(sb, pindex);
37417 +static int xib_restore(struct super_block *sb)
37420 + aufs_bindex_t bindex, bbot;
37424 + page = (void *)__get_free_page(GFP_NOFS);
37425 + if (unlikely(!page))
37429 + bbot = au_sbbot(sb);
37430 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37431 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
37432 + err = do_xib_restore
37433 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
37435 + AuDbg("b%d\n", bindex);
37436 + free_page((unsigned long)page);
37442 +int au_xib_trunc(struct super_block *sb)
37447 + struct au_xino_lock_dir ldir;
37448 + struct au_sbinfo *sbinfo;
37449 + unsigned long *p;
37450 + struct file *file;
37452 + SiMustWriteLock(sb);
37455 + sbinfo = au_sbi(sb);
37456 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37459 + file = sbinfo->si_xib;
37460 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37463 + au_xino_lock_dir(sb, file, &ldir);
37464 + /* mnt_want_write() is unnecessary here */
37465 + file = au_xino_create2(sbinfo->si_xib, NULL);
37466 + au_xino_unlock_dir(&ldir);
37467 + err = PTR_ERR(file);
37468 + if (IS_ERR(file))
37470 + fput(sbinfo->si_xib);
37471 + sbinfo->si_xib = file;
37473 + p = sbinfo->si_xib_buf;
37474 + memset(p, 0, PAGE_SIZE);
37476 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
37477 + if (unlikely(sz != PAGE_SIZE)) {
37479 + AuIOErr("err %d\n", err);
37485 + mutex_lock(&sbinfo->si_xib_mtx);
37486 + /* mnt_want_write() is unnecessary here */
37487 + err = xib_restore(sb);
37488 + mutex_unlock(&sbinfo->si_xib_mtx);
37494 +/* ---------------------------------------------------------------------- */
37497 + * xino mount option handlers
37501 +static void xino_clear_xib(struct super_block *sb)
37503 + struct au_sbinfo *sbinfo;
37505 + SiMustWriteLock(sb);
37507 + sbinfo = au_sbi(sb);
37508 + sbinfo->si_xread = NULL;
37509 + sbinfo->si_xwrite = NULL;
37510 + if (sbinfo->si_xib)
37511 + fput(sbinfo->si_xib);
37512 + sbinfo->si_xib = NULL;
37513 + if (sbinfo->si_xib_buf)
37514 + free_page((unsigned long)sbinfo->si_xib_buf);
37515 + sbinfo->si_xib_buf = NULL;
37518 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
37522 + struct au_sbinfo *sbinfo;
37523 + struct file *file;
37525 + SiMustWriteLock(sb);
37527 + sbinfo = au_sbi(sb);
37528 + file = au_xino_create2(base, sbinfo->si_xib);
37529 + err = PTR_ERR(file);
37530 + if (IS_ERR(file))
37532 + if (sbinfo->si_xib)
37533 + fput(sbinfo->si_xib);
37534 + sbinfo->si_xib = file;
37535 + sbinfo->si_xread = vfs_readf(file);
37536 + sbinfo->si_xwrite = vfs_writef(file);
37539 + if (!sbinfo->si_xib_buf)
37540 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
37541 + if (unlikely(!sbinfo->si_xib_buf))
37544 + sbinfo->si_xib_last_pindex = 0;
37545 + sbinfo->si_xib_next_bit = 0;
37546 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
37548 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
37549 + PAGE_SIZE, &pos);
37550 + if (unlikely(err != PAGE_SIZE))
37554 + goto out; /* success */
37557 + if (sbinfo->si_xib_buf)
37558 + free_page((unsigned long)sbinfo->si_xib_buf);
37559 + sbinfo->si_xib_buf = NULL;
37563 + fput(sbinfo->si_xib);
37564 + sbinfo->si_xib = NULL;
37565 + sbinfo->si_xread = NULL;
37566 + sbinfo->si_xwrite = NULL;
37571 +/* xino for each branch */
37572 +static void xino_clear_br(struct super_block *sb)
37574 + aufs_bindex_t bindex, bbot;
37575 + struct au_branch *br;
37577 + bbot = au_sbbot(sb);
37578 + for (bindex = 0; bindex <= bbot; bindex++) {
37579 + br = au_sbr(sb, bindex);
37580 + if (!br || !br->br_xino.xi_file)
37583 + fput(br->br_xino.xi_file);
37584 + br->br_xino.xi_file = NULL;
37588 +static int au_xino_set_br(struct super_block *sb, struct file *base)
37592 + aufs_bindex_t bindex, bbot, bshared;
37594 + struct file *old, *new;
37596 + struct au_branch *br;
37597 + struct inode *inode;
37598 + vfs_writef_t writef;
37600 + SiMustWriteLock(sb);
37603 + bbot = au_sbbot(sb);
37604 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
37605 + if (unlikely(!fpair))
37608 + inode = d_inode(sb->s_root);
37609 + ino = AUFS_ROOT_INO;
37610 + writef = au_sbi(sb)->si_xwrite;
37611 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
37612 + bshared = is_sb_shared(sb, bindex, bindex - 1);
37613 + if (bshared >= 0) {
37614 + /* shared xino */
37615 + *p = fpair[bshared];
37616 + get_file(p->new);
37621 + br = au_sbr(sb, bindex);
37622 + p->old = br->br_xino.xi_file;
37623 + p->new = au_xino_create2(base, br->br_xino.xi_file);
37624 + err = PTR_ERR(p->new);
37625 + if (IS_ERR(p->new)) {
37631 + err = au_xino_do_write(writef, p->new,
37632 + au_h_iptr(inode, bindex)->i_ino, ino);
37633 + if (unlikely(err))
37637 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
37638 + br = au_sbr(sb, bindex);
37639 + if (br->br_xino.xi_file)
37640 + fput(br->br_xino.xi_file);
37641 + get_file(p->new);
37642 + br->br_xino.xi_file = p->new;
37646 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
37656 +void au_xino_clr(struct super_block *sb)
37658 + struct au_sbinfo *sbinfo;
37660 + au_xigen_clr(sb);
37661 + xino_clear_xib(sb);
37662 + xino_clear_br(sb);
37663 + sbinfo = au_sbi(sb);
37664 + /* lvalue, do not call au_mntflags() */
37665 + au_opt_clr(sbinfo->si_mntflags, XINO);
37668 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
37671 + struct dentry *parent, *cur_parent;
37672 + struct qstr *dname, *cur_name;
37673 + struct file *cur_xino;
37674 + struct inode *dir;
37675 + struct au_sbinfo *sbinfo;
37677 + SiMustWriteLock(sb);
37680 + sbinfo = au_sbi(sb);
37681 + parent = dget_parent(xino->file->f_path.dentry);
37684 + dname = &xino->file->f_path.dentry->d_name;
37685 + cur_xino = sbinfo->si_xib;
37687 + cur_parent = dget_parent(cur_xino->f_path.dentry);
37688 + cur_name = &cur_xino->f_path.dentry->d_name;
37689 + skip = (cur_parent == parent
37690 + && au_qstreq(dname, cur_name));
37691 + dput(cur_parent);
37697 + au_opt_set(sbinfo->si_mntflags, XINO);
37698 + dir = d_inode(parent);
37699 + inode_lock_nested(dir, AuLsc_I_PARENT);
37700 + /* mnt_want_write() is unnecessary here */
37701 + err = au_xino_set_xib(sb, xino->file);
37703 + err = au_xigen_set(sb, xino->file);
37705 + err = au_xino_set_br(sb, xino->file);
37706 + inode_unlock(dir);
37708 + goto out; /* success */
37711 + AuIOErr("failed creating xino(%d).\n", err);
37712 + au_xigen_clr(sb);
37713 + xino_clear_xib(sb);
37720 +/* ---------------------------------------------------------------------- */
37723 + * create a xinofile at the default place/path.
37725 +struct file *au_xino_def(struct super_block *sb)
37727 + struct file *file;
37729 + struct au_branch *br;
37730 + struct super_block *h_sb;
37731 + struct path path;
37732 + aufs_bindex_t bbot, bindex, bwr;
37735 + bbot = au_sbbot(sb);
37737 + for (bindex = 0; bindex <= bbot; bindex++) {
37738 + br = au_sbr(sb, bindex);
37739 + if (au_br_writable(br->br_perm)
37740 + && !au_test_fs_bad_xino(au_br_sb(br))) {
37747 + file = ERR_PTR(-ENOMEM);
37748 + page = (void *)__get_free_page(GFP_NOFS);
37749 + if (unlikely(!page))
37751 + path.mnt = au_br_mnt(br);
37752 + path.dentry = au_h_dptr(sb->s_root, bwr);
37753 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
37754 + file = (void *)p;
37755 + if (!IS_ERR(p)) {
37756 + strcat(p, "/" AUFS_XINO_FNAME);
37757 + AuDbg("%s\n", p);
37758 + file = au_xino_create(sb, p, /*silent*/0);
37759 + if (!IS_ERR(file))
37760 + au_xino_brid_set(sb, br->br_id);
37762 + free_page((unsigned long)page);
37764 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
37765 + if (IS_ERR(file))
37767 + h_sb = file->f_path.dentry->d_sb;
37768 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
37769 + pr_err("xino doesn't support %s(%s)\n",
37770 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
37772 + file = ERR_PTR(-EINVAL);
37774 + if (!IS_ERR(file))
37775 + au_xino_brid_set(sb, -1);
37782 +/* ---------------------------------------------------------------------- */
37784 +int au_xino_path(struct seq_file *seq, struct file *file)
37788 + err = au_seq_path(seq, &file->f_path);
37789 + if (unlikely(err))
37792 +#define Deleted "\\040(deleted)"
37793 + seq->count -= sizeof(Deleted) - 1;
37794 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
37795 + sizeof(Deleted) - 1));
37802 +/* ---------------------------------------------------------------------- */
37804 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
37805 + ino_t h_ino, int idx)
37807 + struct au_xino_file *xino;
37809 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
37810 + xino = &au_sbr(sb, bindex)->br_xino;
37811 + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx);
37813 + spin_lock(&xino->xi_nondir.spin);
37814 + AuDebugOn(xino->xi_nondir.array[idx] != h_ino);
37815 + xino->xi_nondir.array[idx] = 0;
37816 + spin_unlock(&xino->xi_nondir.spin);
37817 + wake_up_all(&xino->xi_nondir.wqh);
37820 +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino)
37822 + int found, total, i;
37825 + total = xino->xi_nondir.total;
37826 + for (i = 0; i < total; i++) {
37827 + if (xino->xi_nondir.array[i] != h_ino)
37836 +static int au_xinondir_expand(struct au_xino_file *xino)
37841 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
37844 + sz = xino->xi_nondir.total * sizeof(ino_t);
37845 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
37847 + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
37848 + /*may_shrink*/0);
37850 + xino->xi_nondir.array = p;
37851 + xino->xi_nondir.total <<= 1;
37852 + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total);
37860 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37863 + int err, found, empty;
37864 + struct au_xino_file *xino;
37868 + if (!au_opt_test(au_mntflags(sb), XINO))
37869 + goto out; /* no xino */
37871 + xino = &au_sbr(sb, bindex)->br_xino;
37874 + spin_lock(&xino->xi_nondir.spin);
37875 + found = au_xinondir_find(xino, h_ino);
37876 + if (found == -1) {
37877 + empty = au_xinondir_find(xino, /*h_ino*/0);
37878 + if (empty == -1) {
37879 + empty = xino->xi_nondir.total;
37880 + err = au_xinondir_expand(xino);
37881 + if (unlikely(err))
37884 + xino->xi_nondir.array[empty] = h_ino;
37887 + spin_unlock(&xino->xi_nondir.spin);
37888 + wait_event(xino->xi_nondir.wqh,
37889 + xino->xi_nondir.array[found] != h_ino);
37894 + spin_unlock(&xino->xi_nondir.spin);
37898 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
37899 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
37900 +++ linux/include/uapi/linux/aufs_type.h 2017-11-12 22:24:44.710911257 +0100
37903 + * Copyright (C) 2005-2017 Junjiro R. Okajima
37905 + * This program, aufs is free software; you can redistribute it and/or modify
37906 + * it under the terms of the GNU General Public License as published by
37907 + * the Free Software Foundation; either version 2 of the License, or
37908 + * (at your option) any later version.
37910 + * This program is distributed in the hope that it will be useful,
37911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37913 + * GNU General Public License for more details.
37915 + * You should have received a copy of the GNU General Public License
37916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37919 +#ifndef __AUFS_TYPE_H__
37920 +#define __AUFS_TYPE_H__
37922 +#define AUFS_NAME "aufs"
37926 + * define it before including all other headers.
37927 + * sched.h may use pr_* macros before defining "current", so define the
37928 + * no-current version first, and re-define later.
37930 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
37931 +#include <linux/sched.h>
37933 +#define pr_fmt(fmt) \
37934 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
37935 + (int)sizeof(current->comm), current->comm, current->pid
37937 +#include <stdint.h>
37938 +#include <sys/types.h>
37939 +#endif /* __KERNEL__ */
37941 +#include <linux/limits.h>
37943 +#define AUFS_VERSION "4.x-rcN-20171106"
37945 +/* todo? move this to linux-2.6.19/include/magic.h */
37946 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
37948 +/* ---------------------------------------------------------------------- */
37950 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
37951 +typedef int8_t aufs_bindex_t;
37952 +#define AUFS_BRANCH_MAX 127
37954 +typedef int16_t aufs_bindex_t;
37955 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
37956 +#define AUFS_BRANCH_MAX 511
37957 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
37958 +#define AUFS_BRANCH_MAX 1023
37959 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
37960 +#define AUFS_BRANCH_MAX 32767
37965 +#ifndef AUFS_BRANCH_MAX
37966 +#error unknown CONFIG_AUFS_BRANCH_MAX value
37968 +#endif /* __KERNEL__ */
37970 +/* ---------------------------------------------------------------------- */
37972 +#define AUFS_FSTYPE AUFS_NAME
37974 +#define AUFS_ROOT_INO 2
37975 +#define AUFS_FIRST_INO 11
37977 +#define AUFS_WH_PFX ".wh."
37978 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
37979 +#define AUFS_WH_TMP_LEN 4
37980 +/* a limit for rmdir/rename a dir and copyup */
37981 +#define AUFS_MAX_NAMELEN (NAME_MAX \
37982 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
37984 + - AUFS_WH_TMP_LEN) /* hex */
37985 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
37986 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
37987 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
37988 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
37989 +#define AUFS_DIRWH_DEF 3
37990 +#define AUFS_RDCACHE_DEF 10 /* seconds */
37991 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
37992 +#define AUFS_RDBLK_DEF 512 /* bytes */
37993 +#define AUFS_RDHASH_DEF 32
37994 +#define AUFS_WKQ_NAME AUFS_NAME "d"
37995 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
37996 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
37997 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
37998 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38000 +/* pseudo-link maintenace under /proc */
38001 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38002 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38003 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38005 +/* dirren, renamed dir */
38006 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38007 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38008 +/* whiteouted doubly */
38009 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38010 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38012 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38013 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38015 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38016 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38017 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38019 +/* doubly whiteouted */
38020 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38021 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38022 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38024 +/* branch permissions and attributes */
38025 +#define AUFS_BRPERM_RW "rw"
38026 +#define AUFS_BRPERM_RO "ro"
38027 +#define AUFS_BRPERM_RR "rr"
38028 +#define AUFS_BRATTR_COO_REG "coo_reg"
38029 +#define AUFS_BRATTR_COO_ALL "coo_all"
38030 +#define AUFS_BRATTR_FHSM "fhsm"
38031 +#define AUFS_BRATTR_UNPIN "unpin"
38032 +#define AUFS_BRATTR_ICEX "icex"
38033 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38034 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38035 +#define AUFS_BRATTR_ICEX_TR "icextr"
38036 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38037 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38038 +#define AUFS_BRRATTR_WH "wh"
38039 +#define AUFS_BRWATTR_NLWH "nolwh"
38040 +#define AUFS_BRWATTR_MOO "moo"
38042 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38043 +#define AuBrPerm_RO (1 << 1) /* readonly */
38044 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38045 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38047 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38048 +#define AuBrAttr_COO_ALL (1 << 4)
38049 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38051 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38052 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38053 + branch. meaningless since
38054 + linux-3.18-rc1 */
38056 +/* ignore error in copying XATTR */
38057 +#define AuBrAttr_ICEX_SEC (1 << 7)
38058 +#define AuBrAttr_ICEX_SYS (1 << 8)
38059 +#define AuBrAttr_ICEX_TR (1 << 9)
38060 +#define AuBrAttr_ICEX_USR (1 << 10)
38061 +#define AuBrAttr_ICEX_OTH (1 << 11)
38062 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38063 + | AuBrAttr_ICEX_SYS \
38064 + | AuBrAttr_ICEX_TR \
38065 + | AuBrAttr_ICEX_USR \
38066 + | AuBrAttr_ICEX_OTH)
38068 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38069 +#define AuBrRAttr_Mask AuBrRAttr_WH
38071 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38072 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38073 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38075 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38077 +/* #warning test userspace */
38079 +#ifndef CONFIG_AUFS_FHSM
38080 +#undef AuBrAttr_FHSM
38081 +#define AuBrAttr_FHSM 0
38083 +#ifndef CONFIG_AUFS_XATTR
38084 +#undef AuBrAttr_ICEX
38085 +#define AuBrAttr_ICEX 0
38086 +#undef AuBrAttr_ICEX_SEC
38087 +#define AuBrAttr_ICEX_SEC 0
38088 +#undef AuBrAttr_ICEX_SYS
38089 +#define AuBrAttr_ICEX_SYS 0
38090 +#undef AuBrAttr_ICEX_TR
38091 +#define AuBrAttr_ICEX_TR 0
38092 +#undef AuBrAttr_ICEX_USR
38093 +#define AuBrAttr_ICEX_USR 0
38094 +#undef AuBrAttr_ICEX_OTH
38095 +#define AuBrAttr_ICEX_OTH 0
38099 +/* the longest combination */
38100 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38101 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38102 + "+" AUFS_BRATTR_COO_REG \
38103 + "+" AUFS_BRATTR_FHSM \
38104 + "+" AUFS_BRATTR_UNPIN \
38105 + "+" AUFS_BRATTR_ICEX_SEC \
38106 + "+" AUFS_BRATTR_ICEX_SYS \
38107 + "+" AUFS_BRATTR_ICEX_USR \
38108 + "+" AUFS_BRATTR_ICEX_OTH \
38109 + "+" AUFS_BRWATTR_NLWH)
38112 + char a[AuBrPermStrSz];
38113 +} au_br_perm_str_t;
38115 +static inline int au_br_writable(int brperm)
38117 + return brperm & AuBrPerm_RW;
38120 +static inline int au_br_whable(int brperm)
38122 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38125 +static inline int au_br_wh_linkable(int brperm)
38127 + return !(brperm & AuBrWAttr_NoLinkWH);
38130 +static inline int au_br_cmoo(int brperm)
38132 + return brperm & AuBrAttr_CMOO_Mask;
38135 +static inline int au_br_fhsm(int brperm)
38137 + return brperm & AuBrAttr_FHSM;
38140 +/* ---------------------------------------------------------------------- */
38144 + /* readdir in userspace */
38148 + AuCtl_WBR_FD, /* pathconf wrapper */
38149 + AuCtl_IBUSY, /* busy inode */
38150 + AuCtl_MVDOWN, /* move-down */
38151 + AuCtl_BR, /* info about branches */
38152 + AuCtl_FHSM_FD /* connection for fhsm */
38155 +/* borrowed from linux/include/linux/kernel.h */
38157 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38158 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38161 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38163 +#define __aligned(x) __attribute__((aligned(x)))
38168 +#define __packed __attribute__((packed))
38172 +struct au_rdu_cookie {
38177 + uint32_t generation;
38180 +struct au_rdu_ent {
38189 +static inline int au_rdu_len(int nlen)
38191 + /* include the terminating NULL */
38192 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38193 + sizeof(uint64_t));
38196 +union au_rdu_ent_ul {
38197 + struct au_rdu_ent __user *e;
38209 + uint64_t sz; /* AuCtl_RDU */
38210 + uint64_t nent; /* AuCtl_RDU_INO */
38212 + union au_rdu_ent_ul ent;
38213 + uint16_t verify[AufsCtlRduV_End];
38215 + /* input/output */
38219 + union au_rdu_ent_ul tail;
38220 + /* number of entries which were added in a single call */
38225 + struct au_rdu_cookie cookie;
38228 +/* ---------------------------------------------------------------------- */
38230 +/* dirren. the branch is identified by the filename who contains this */
38231 +struct au_drinfo {
38234 + uint8_t oldnamelen;
38235 + uint64_t _padding;
38237 + uint8_t oldname[0];
38240 +struct au_drinfo_fdata {
38242 + struct au_drinfo drinfo;
38245 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38247 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38249 +/* ---------------------------------------------------------------------- */
38251 +struct aufs_wbr_fd {
38256 +/* ---------------------------------------------------------------------- */
38258 +struct aufs_ibusy {
38259 + uint64_t ino, h_ino;
38263 +/* ---------------------------------------------------------------------- */
38265 +/* error code for move-down */
38266 +/* the actual message strings are implemented in aufs-util.git */
38268 + EAU_MVDOWN_OPAQUE = 1,
38269 + EAU_MVDOWN_WHITEOUT,
38270 + EAU_MVDOWN_UPPER,
38271 + EAU_MVDOWN_BOTTOM,
38272 + EAU_MVDOWN_NOUPPER,
38273 + EAU_MVDOWN_NOLOWERBR,
38277 +/* flags for move-down */
38278 +#define AUFS_MVDOWN_DMSG 1
38279 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38280 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38281 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38282 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38283 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38284 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38285 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38286 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38287 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38288 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38289 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38290 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38292 +/* index for move-down */
38294 + AUFS_MVDOWN_UPPER,
38295 + AUFS_MVDOWN_LOWER,
38296 + AUFS_MVDOWN_NARRAY
38300 + * additional info of move-down
38301 + * number of free blocks and inodes.
38302 + * subset of struct kstatfs, but smaller and always 64bit.
38304 +struct aufs_stfs {
38305 + uint64_t f_blocks;
38306 + uint64_t f_bavail;
38307 + uint64_t f_files;
38308 + uint64_t f_ffree;
38311 +struct aufs_stbr {
38312 + int16_t brid; /* optional input */
38313 + int16_t bindex; /* output */
38314 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
38317 +struct aufs_mvdown {
38318 + uint32_t flags; /* input/output */
38319 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
38320 + int8_t au_errno; /* output */
38323 +/* ---------------------------------------------------------------------- */
38325 +union aufs_brinfo {
38326 + /* PATH_MAX may differ between kernel-space and user-space */
38327 + char _spacer[4096];
38335 +/* ---------------------------------------------------------------------- */
38337 +#define AuCtlType 'A'
38338 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
38339 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
38340 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
38341 + struct aufs_wbr_fd)
38342 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
38343 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
38344 + struct aufs_mvdown)
38345 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
38346 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
38348 +#endif /* __AUFS_TYPE_H__ */
38349 aufs4.x-rcN loopback patch
38351 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38352 index d44de9d..095672b 100644
38353 --- a/drivers/block/loop.c
38354 +++ b/drivers/block/loop.c
38355 @@ -595,6 +595,15 @@ static inline void loop_update_dio(struct loop_device *lo)
38359 +static struct file *loop_real_file(struct file *file)
38361 + struct file *f = NULL;
38363 + if (file->f_path.dentry->d_sb->s_op->real_loop)
38364 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
38368 static void loop_reread_partitions(struct loop_device *lo,
38369 struct block_device *bdev)
38371 @@ -629,6 +638,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38374 struct file *file, *old_file;
38375 + struct file *f, *virt_file = NULL, *old_virt_file;
38376 struct inode *inode;
38379 @@ -645,13 +655,20 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38383 + f = loop_real_file(file);
38385 + virt_file = file;
38390 error = loop_validate_file(file, bdev);
38394 inode = file->f_mapping->host;
38395 old_file = lo->lo_backing_file;
38396 + old_virt_file = lo->lo_backing_virt_file;
38400 @@ -662,6 +679,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38401 blk_mq_freeze_queue(lo->lo_queue);
38402 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
38403 lo->lo_backing_file = file;
38404 + lo->lo_backing_virt_file = virt_file;
38405 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
38406 mapping_set_gfp_mask(file->f_mapping,
38407 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
38408 @@ -669,12 +687,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38409 blk_mq_unfreeze_queue(lo->lo_queue);
38412 + if (old_virt_file)
38413 + fput(old_virt_file);
38414 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
38415 loop_reread_partitions(lo, bdev);
38425 @@ -868,7 +890,7 @@ static int loop_prepare_queue(struct loop_device *lo)
38426 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38427 struct block_device *bdev, unsigned int arg)
38429 - struct file *file;
38430 + struct file *file, *f, *virt_file = NULL;
38431 struct inode *inode;
38432 struct address_space *mapping;
38434 @@ -882,6 +904,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38438 + f = loop_real_file(file);
38440 + virt_file = file;
38446 if (lo->lo_state != Lo_unbound)
38447 @@ -930,6 +958,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38448 lo->lo_device = bdev;
38449 lo->lo_flags = lo_flags;
38450 lo->lo_backing_file = file;
38451 + lo->lo_backing_virt_file = virt_file;
38452 lo->transfer = NULL;
38454 lo->lo_sizelimit = 0;
38455 @@ -963,6 +992,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38462 /* This is safe: open() is still holding a reference. */
38463 module_put(THIS_MODULE);
38464 @@ -1009,6 +1040,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
38465 static int loop_clr_fd(struct loop_device *lo)
38467 struct file *filp = lo->lo_backing_file;
38468 + struct file *virt_filp = lo->lo_backing_virt_file;
38469 gfp_t gfp = lo->old_gfp_mask;
38470 struct block_device *bdev = lo->lo_device;
38472 @@ -1040,6 +1072,7 @@ static int loop_clr_fd(struct loop_device *lo)
38473 spin_lock_irq(&lo->lo_lock);
38474 lo->lo_state = Lo_rundown;
38475 lo->lo_backing_file = NULL;
38476 + lo->lo_backing_virt_file = NULL;
38477 spin_unlock_irq(&lo->lo_lock);
38479 loop_release_xfer(lo);
38480 @@ -1087,6 +1120,8 @@ static int loop_clr_fd(struct loop_device *lo)
38481 * bd_mutex which is usually taken before lo_ctl_mutex.
38489 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
38490 index 1f39567..128b137 100644
38491 --- a/drivers/block/loop.h
38492 +++ b/drivers/block/loop.h
38493 @@ -46,7 +46,7 @@ struct loop_device {
38494 int (*ioctl)(struct loop_device *, int cmd,
38495 unsigned long arg);
38497 - struct file * lo_backing_file;
38498 + struct file * lo_backing_file, *lo_backing_virt_file;
38499 struct block_device *lo_device;
38502 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
38503 index 8aff060..e853272 100644
38504 --- a/fs/aufs/f_op.c
38505 +++ b/fs/aufs/f_op.c
38506 @@ -357,7 +357,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
38507 if (IS_ERR(h_file))
38510 - if (au_test_loopback_kthread()) {
38511 + if (0 && au_test_loopback_kthread()) {
38512 au_warn_loopback(h_file->f_path.dentry->d_sb);
38513 if (file->f_mapping != h_file->f_mapping) {
38514 file->f_mapping = h_file->f_mapping;
38515 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
38516 index e35f015..b37f1ae 100644
38517 --- a/fs/aufs/loop.c
38518 +++ b/fs/aufs/loop.c
38519 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
38520 symbol_put(loop_backing_file);
38521 kfree(au_warn_loopback_array);
38524 +/* ---------------------------------------------------------------------- */
38526 +/* support the loopback block device insude aufs */
38528 +struct file *aufs_real_loop(struct file *file)
38532 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
38533 + fi_read_lock(file);
38534 + f = au_hf_top(file);
38535 + fi_read_unlock(file);
38539 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
38540 index e2df495..36e5052 100644
38541 --- a/fs/aufs/loop.h
38542 +++ b/fs/aufs/loop.h
38543 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
38545 int au_loopback_init(void);
38546 void au_loopback_fin(void);
38548 +struct file *aufs_real_loop(struct file *file);
38550 +AuStub(struct file *, loop_backing_file, return NULL)
38552 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
38553 struct dentry *h_adding)
38554 AuStubInt0(au_test_loopback_kthread, void)
38555 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
38557 AuStubInt0(au_loopback_init, void)
38558 AuStubVoid(au_loopback_fin, void)
38560 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
38561 #endif /* BLK_DEV_LOOP */
38563 #endif /* __KERNEL__ */
38564 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
38565 index 3c300125..128d790 100644
38566 --- a/fs/aufs/super.c
38567 +++ b/fs/aufs/super.c
38568 @@ -838,7 +838,10 @@ static const struct super_operations aufs_sop = {
38569 .statfs = aufs_statfs,
38570 .put_super = aufs_put_super,
38571 .sync_fs = aufs_sync_fs,
38572 - .remount_fs = aufs_remount_fs
38573 + .remount_fs = aufs_remount_fs,
38574 +#ifdef CONFIG_AUFS_BDEV_LOOP
38575 + .real_loop = aufs_real_loop
38579 /* ---------------------------------------------------------------------- */
38580 diff --git a/include/linux/fs.h b/include/linux/fs.h
38581 index 8ab6566..8dbaa52 100644
38582 --- a/include/linux/fs.h
38583 +++ b/include/linux/fs.h
38584 @@ -1838,6 +1838,10 @@ struct super_operations {
38585 struct shrink_control *);
38586 long (*free_cached_objects)(struct super_block *,
38587 struct shrink_control *);
38588 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
38590 + struct file *(*real_loop)(struct file *);