1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index bc821a8..7ae814c 100644
8 @@ -251,6 +251,7 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/exofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index c9375fd..8af5671 100644
20 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
21 obj-$(CONFIG_CEPH_FS) += ceph/
22 obj-$(CONFIG_PSTORE) += pstore/
23 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 9c125f7..4616bbf 100644
32 @@ -2519,6 +2519,19 @@ F: include/linux/audit.h
33 F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: linux-unionfs@vger.kernel.org
39 +L: aufs-users@lists.sourceforge.net (members only)
40 +W: http://aufs.sourceforge.net
41 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/filesystems/aufs/
44 +F: Documentation/ABI/testing/debugfs-aufs
45 +F: Documentation/ABI/testing/sysfs-aufs
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
51 W: http://miguelojeda.es/auxdisplay.htm
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index 55cf554..bc965e5 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -713,6 +713,24 @@ static inline int is_loop_device(struct file *file)
57 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index 2acfc69..ff338e2 100644
85 @@ -1234,7 +1234,7 @@ enum d_walk_ret {
87 * The @enter() and @finish() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *),
92 void (*finish)(void *))
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index d737ff0..7550799 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file * filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/inode.c b/fs/inode.c
117 index 3b55391..e0c5255 100644
120 @@ -1663,7 +1663,7 @@ EXPORT_SYMBOL(generic_update_time);
121 * This does the actual work of updating an inodes time or version. Must have
122 * had called mnt_want_write() before calling this.
124 -static int update_time(struct inode *inode, struct timespec *time, int flags)
125 +int update_time(struct inode *inode, struct timespec *time, int flags)
127 int (*update_time)(struct inode *, struct timespec *, int);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index 5f75969..61129ff 100644
133 @@ -846,6 +846,12 @@ static inline int check_mnt(struct mount *mnt)
134 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137 +/* for aufs, CONFIG_AUFS_BR_FUSE */
138 +int is_current_mnt_ns(struct vfsmount *mnt)
140 + return check_mnt(real_mount(mnt));
144 * vfsmount lock must be held for write
146 diff --git a/fs/read_write.c b/fs/read_write.c
147 index c4eabbf..ddd6e67 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -489,6 +489,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
154 +vfs_readf_t vfs_readf(struct file *file)
156 + const struct file_operations *fop = file->f_op;
160 + if (fop->read_iter)
161 + return new_sync_read;
162 + return ERR_PTR(-ENOSYS);
165 +vfs_writef_t vfs_writef(struct file *file)
167 + const struct file_operations *fop = file->f_op;
171 + if (fop->write_iter)
172 + return new_sync_write;
173 + return ERR_PTR(-ENOSYS);
176 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
179 diff --git a/fs/splice.c b/fs/splice.c
180 index 005d09c..f617ab0 100644
183 @@ -837,8 +837,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
185 * Attempt to initiate a splice from pipe to file.
187 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
188 - loff_t *ppos, size_t len, unsigned int flags)
189 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
190 + loff_t *ppos, size_t len, unsigned int flags)
192 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
193 loff_t *, size_t, unsigned int);
194 @@ -854,9 +854,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
196 * Attempt to initiate a splice from a file to a pipe.
198 -static long do_splice_to(struct file *in, loff_t *ppos,
199 - struct pipe_inode_info *pipe, size_t len,
200 - unsigned int flags)
201 +long do_splice_to(struct file *in, loff_t *ppos,
202 + struct pipe_inode_info *pipe, size_t len,
203 + unsigned int flags)
205 ssize_t (*splice_read)(struct file *, loff_t *,
206 struct pipe_inode_info *, size_t, unsigned int);
207 diff --git a/fs/sync.c b/fs/sync.c
208 index b54e054..2860782 100644
212 * wait == 1 case since in that case write_inode() functions do
213 * sync_dirty_buffer() and thus effectively write one block at a time.
215 -static int __sync_filesystem(struct super_block *sb, int wait)
216 +int __sync_filesystem(struct super_block *sb, int wait)
220 diff --git a/include/linux/file.h b/include/linux/file.h
221 index 279720d..76e38ea 100644
222 --- a/include/linux/file.h
223 +++ b/include/linux/file.h
224 @@ -20,6 +20,7 @@ struct dentry;
226 extern struct file *alloc_file(const struct path *, fmode_t mode,
227 const struct file_operations *fop);
228 +extern struct file *get_empty_filp(void);
230 static inline void fput_light(struct file *file, int fput_needed)
232 diff --git a/include/linux/fs.h b/include/linux/fs.h
233 index 760d8da..09a2542 100644
234 --- a/include/linux/fs.h
235 +++ b/include/linux/fs.h
236 @@ -1270,6 +1270,7 @@ extern void fasync_free(struct fasync_struct *);
237 /* can be called from interrupts */
238 extern void kill_fasync(struct fasync_struct **, int, int);
240 +extern int setfl(int fd, struct file * filp, unsigned long arg);
241 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
242 extern int f_setown(struct file *filp, unsigned long arg, int force);
243 extern void f_delown(struct file *filp);
244 @@ -1724,6 +1725,7 @@ struct file_operations {
245 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
246 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
247 int (*check_flags)(int);
248 + int (*setfl)(struct file *, unsigned long);
249 int (*flock) (struct file *, int, struct file_lock *);
250 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
251 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
252 @@ -1794,6 +1796,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
253 struct iovec *fast_pointer,
254 struct iovec **ret_pointer);
256 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
257 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
259 +vfs_readf_t vfs_readf(struct file *file);
260 +vfs_writef_t vfs_writef(struct file *file);
262 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
263 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
264 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
265 @@ -2199,6 +2207,7 @@ extern int current_umask(void);
266 extern void ihold(struct inode * inode);
267 extern void iput(struct inode *);
268 extern int generic_update_time(struct inode *, struct timespec *, int);
269 +extern int update_time(struct inode *, struct timespec *, int);
272 extern struct kobject *fs_kobj;
273 @@ -2485,6 +2494,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
277 +extern int __sync_filesystem(struct super_block *, int);
278 extern int sync_filesystem(struct super_block *);
279 extern const struct file_operations def_blk_fops;
280 extern const struct file_operations def_chr_fops;
281 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
282 index 6fc77d4..27e76f0 100644
283 --- a/include/linux/lockdep.h
284 +++ b/include/linux/lockdep.h
285 @@ -313,6 +313,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
286 return lock->key == key;
289 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
294 @@ -439,6 +441,7 @@ struct lockdep_map { };
296 #define lockdep_depth(tsk) (0)
298 +#define lockdep_is_held(lock) (1)
299 #define lockdep_is_held_type(l, r) (1)
301 #define lockdep_assert_held(l) do { (void)(l); } while (0)
302 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
303 index 3594208..24f5fd1 100644
304 --- a/include/linux/mnt_namespace.h
305 +++ b/include/linux/mnt_namespace.h
307 struct mnt_namespace;
309 struct user_namespace;
312 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
313 struct user_namespace *, struct fs_struct *);
314 extern void put_mnt_ns(struct mnt_namespace *ns);
316 +extern int is_current_mnt_ns(struct vfsmount *mnt);
318 extern const struct file_operations proc_mounts_operations;
319 extern const struct file_operations proc_mountinfo_operations;
320 extern const struct file_operations proc_mountstats_operations;
321 diff --git a/include/linux/splice.h b/include/linux/splice.h
322 index 74b4911..19789fb 100644
323 --- a/include/linux/splice.h
324 +++ b/include/linux/splice.h
325 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
327 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
328 extern const struct pipe_buf_operations default_pipe_buf_ops;
330 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
331 + loff_t *ppos, size_t len, unsigned int flags);
332 +extern long do_splice_to(struct file *in, loff_t *ppos,
333 + struct pipe_inode_info *pipe, size_t len,
334 + unsigned int flags);
336 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
337 index 0233863..06e0d7a 100644
338 --- a/kernel/locking/lockdep.c
339 +++ b/kernel/locking/lockdep.c
340 @@ -140,7 +140,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
341 unsigned long nr_lock_classes;
342 static struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
344 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
345 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
347 if (!hlock->class_idx) {
349 @@ -151,6 +151,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
351 return lock_classes + hlock->class_idx - 1;
353 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
355 #ifdef CONFIG_LOCK_STAT
356 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
357 SPDX-License-Identifier: GPL-2.0
360 diff --git a/fs/proc/base.c b/fs/proc/base.c
361 index 1a76d75..77f698e 100644
364 @@ -2024,7 +2024,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
365 down_read(&mm->mmap_sem);
366 vma = find_exact_vma(mm, vm_start, vm_end);
367 if (vma && vma->vm_file) {
368 - *path = vma->vm_file->f_path;
369 + *path = vma_pr_or_file(vma)->f_path;
373 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
374 index 7563437..7c0dc0f 100644
375 --- a/fs/proc/nommu.c
376 +++ b/fs/proc/nommu.c
377 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
378 file = region->vm_file;
381 - struct inode *inode = file_inode(region->vm_file);
382 + struct inode *inode;
384 + file = vmr_pr_or_file(region);
385 + inode = file_inode(file);
386 dev = inode->i_sb->s_dev;
389 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
390 index c486ad4..76b71f8 100644
391 --- a/fs/proc/task_mmu.c
392 +++ b/fs/proc/task_mmu.c
393 @@ -305,7 +305,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
394 const char *name = NULL;
397 - struct inode *inode = file_inode(vma->vm_file);
398 + struct inode *inode;
400 + file = vma_pr_or_file(vma);
401 + inode = file_inode(file);
402 dev = inode->i_sb->s_dev;
404 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
405 @@ -1726,7 +1729,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
406 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
407 struct vm_area_struct *vma = v;
408 struct numa_maps *md = &numa_priv->md;
409 - struct file *file = vma->vm_file;
410 + struct file *file = vma_pr_or_file(vma);
411 struct mm_struct *mm = vma->vm_mm;
412 struct mm_walk walk = {
413 .hugetlb_entry = gather_hugetlb_stats,
414 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
415 index 5b62f57..dfb4a3b 100644
416 --- a/fs/proc/task_nommu.c
417 +++ b/fs/proc/task_nommu.c
418 @@ -156,7 +156,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
422 - struct inode *inode = file_inode(vma->vm_file);
423 + struct inode *inode;
425 + file = vma_pr_or_file(vma);
426 + inode = file_inode(file);
427 dev = inode->i_sb->s_dev;
429 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
430 diff --git a/include/linux/mm.h b/include/linux/mm.h
431 index 02a616e..01b3bb9 100644
432 --- a/include/linux/mm.h
433 +++ b/include/linux/mm.h
434 @@ -1380,6 +1380,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
435 unmap_mapping_range(mapping, holebegin, holelen, 0);
438 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
439 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
441 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
442 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
444 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
446 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
448 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
449 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
452 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
453 +extern void vmr_do_fput(struct vm_region *, const char[], int);
455 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
457 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
458 +#endif /* !CONFIG_MMU */
460 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
461 void *buf, int len, unsigned int gup_flags);
462 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
463 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
464 index 2161234..78aa367 100644
465 --- a/include/linux/mm_types.h
466 +++ b/include/linux/mm_types.h
467 @@ -251,6 +251,7 @@ struct vm_region {
468 unsigned long vm_top; /* region allocated to here */
469 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
470 struct file *vm_file; /* the backing file or NULL */
471 + struct file *vm_prfile; /* the virtual backing file or NULL */
473 int vm_usage; /* region usage count (access under nommu_region_sem) */
474 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
475 @@ -325,6 +326,7 @@ struct vm_area_struct {
476 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
478 struct file * vm_file; /* File we map to (can be NULL). */
479 + struct file *vm_prfile; /* shadow of vm_file */
480 void * vm_private_data; /* was vm_pte (shared mem) */
482 atomic_long_t swap_readahead_info;
483 diff --git a/kernel/fork.c b/kernel/fork.c
484 index a5d21c4..e965e09 100644
487 @@ -473,7 +473,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
488 struct inode *inode = file_inode(file);
489 struct address_space *mapping = file->f_mapping;
493 if (tmp->vm_flags & VM_DENYWRITE)
494 atomic_dec(&inode->i_writecount);
495 i_mmap_lock_write(mapping);
496 diff --git a/mm/Makefile b/mm/Makefile
497 index b4e54a9a..77892ae 100644
500 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
501 mm_init.o mmu_context.o percpu.o slab_common.o \
502 compaction.o vmacache.o \
503 interval_tree.o list_lru.o workingset.o \
505 + prfile.o debug.o $(mmu-y)
509 diff --git a/mm/filemap.c b/mm/filemap.c
510 index 0604cb0..45d2369 100644
513 @@ -2700,7 +2700,7 @@ int filemap_page_mkwrite(struct vm_fault *vmf)
514 int ret = VM_FAULT_LOCKED;
516 sb_start_pagefault(inode->i_sb);
517 - file_update_time(vmf->vma->vm_file);
518 + vma_file_update_time(vmf->vma);
520 if (page->mapping != inode->i_mapping) {
522 diff --git a/mm/mmap.c b/mm/mmap.c
523 index fc41c05..e376869 100644
526 @@ -180,7 +180,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
527 if (vma->vm_ops && vma->vm_ops->close)
528 vma->vm_ops->close(vma);
530 - fput(vma->vm_file);
532 mpol_put(vma_policy(vma));
533 kmem_cache_free(vm_area_cachep, vma);
535 @@ -905,7 +905,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
538 uprobe_munmap(next, next->vm_start, next->vm_end);
543 anon_vma_merge(vma, next);
544 @@ -1820,8 +1820,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
552 /* Undo any partial mapping done by a device driver. */
553 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
554 @@ -2645,7 +2645,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
558 - get_file(new->vm_file);
561 if (new->vm_ops && new->vm_ops->open)
562 new->vm_ops->open(new);
563 @@ -2664,7 +2664,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
564 if (new->vm_ops && new->vm_ops->close)
565 new->vm_ops->close(new);
567 - fput(new->vm_file);
569 unlink_anon_vmas(new);
571 mpol_put(vma_policy(new));
572 @@ -2826,7 +2826,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 struct vm_area_struct *vma;
574 unsigned long populate = 0;
575 unsigned long ret = -EINVAL;
577 + struct file *file, *prfile;
579 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
580 current->comm, current->pid);
581 @@ -2901,10 +2901,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
585 - file = get_file(vma->vm_file);
587 + file = vma->vm_file;
588 + prfile = vma->vm_prfile;
589 ret = do_mmap_pgoff(vma->vm_file, start, size,
590 prot, flags, pgoff, &populate, NULL);
591 + if (!IS_ERR_VALUE(ret) && file && prfile) {
592 + struct vm_area_struct *new_vma;
594 + new_vma = find_vma(mm, ret);
595 + if (!new_vma->vm_prfile)
596 + new_vma->vm_prfile = prfile;
597 + if (new_vma != vma)
601 + * two fput()s instead of vma_fput(vma),
602 + * coz vma may not be available anymore.
608 up_write(&mm->mmap_sem);
610 @@ -3220,7 +3237,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
611 if (anon_vma_clone(new_vma, vma))
612 goto out_free_mempol;
613 if (new_vma->vm_file)
614 - get_file(new_vma->vm_file);
615 + vma_get_file(new_vma);
616 if (new_vma->vm_ops && new_vma->vm_ops->open)
617 new_vma->vm_ops->open(new_vma);
618 vma_link(mm, new_vma, prev, rb_link, rb_parent);
619 diff --git a/mm/nommu.c b/mm/nommu.c
620 index 1372373..6362dde 100644
623 @@ -629,7 +629,7 @@ static void __put_nommu_region(struct vm_region *region)
624 up_write(&nommu_region_sem);
627 - fput(region->vm_file);
630 /* IO memory and memory shared directly out of the pagecache
631 * from ramfs/tmpfs mustn't be released here */
632 @@ -767,7 +767,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
633 if (vma->vm_ops && vma->vm_ops->close)
634 vma->vm_ops->close(vma);
636 - fput(vma->vm_file);
638 put_nommu_region(vma->vm_region);
639 kmem_cache_free(vm_area_cachep, vma);
641 @@ -1289,7 +1289,7 @@ unsigned long do_mmap(struct file *file,
642 goto error_just_free;
645 - fput(region->vm_file);
647 kmem_cache_free(vm_region_jar, region);
650 @@ -1364,10 +1364,10 @@ unsigned long do_mmap(struct file *file,
651 up_write(&nommu_region_sem);
654 - fput(region->vm_file);
656 kmem_cache_free(vm_region_jar, region);
658 - fput(vma->vm_file);
660 kmem_cache_free(vm_area_cachep, vma);
663 diff --git a/mm/prfile.c b/mm/prfile.c
665 index 0000000..14efc4f
670 + * SPDX-License-Identifier: GPL-2.0
671 + * Mainly for aufs which mmap(2) different file and wants to print different
672 + * path in /proc/PID/maps.
673 + * Call these functions via macros defined in linux/mm.h.
675 + * See Documentation/filesystems/aufs/design/06mmap.txt
677 + * Copyright (c) 2014-2018 Junjro R. Okajima
678 + * Copyright (c) 2014 Ian Campbell
681 +#include <linux/mm.h>
682 +#include <linux/file.h>
683 +#include <linux/fs.h>
685 +/* #define PRFILE_TRACE */
686 +static inline void prfile_trace(struct file *f, struct file *pr,
687 + const char func[], int line, const char func2[])
691 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
695 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
698 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
700 + prfile_trace(f, pr, func, line, __func__);
701 + file_update_time(f);
703 + file_update_time(pr);
706 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
709 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
711 + prfile_trace(f, pr, func, line, __func__);
712 + return (f && pr) ? pr : f;
715 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
717 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
719 + prfile_trace(f, pr, func, line, __func__);
725 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
727 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
729 + prfile_trace(f, pr, func, line, __func__);
736 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
739 + struct file *f = region->vm_file, *pr = region->vm_prfile;
741 + prfile_trace(f, pr, func, line, __func__);
742 + return (f && pr) ? pr : f;
745 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
747 + struct file *f = region->vm_file, *pr = region->vm_prfile;
749 + prfile_trace(f, pr, func, line, __func__);
754 +#endif /* !CONFIG_MMU */
755 SPDX-License-Identifier: GPL-2.0
756 aufs4.17 standalone patch
758 diff --git a/fs/dcache.c b/fs/dcache.c
759 index ff338e2..3e2bae8 100644
762 @@ -1342,6 +1342,7 @@ void d_walk(struct dentry *parent, void *data,
766 +EXPORT_SYMBOL_GPL(d_walk);
769 struct vfsmount *mnt;
770 @@ -2942,6 +2943,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
772 write_sequnlock(&rename_lock);
774 +EXPORT_SYMBOL_GPL(d_exchange);
777 * d_ancestor - search for an ancestor
778 diff --git a/fs/exec.c b/fs/exec.c
779 index 183059c..35adee4 100644
782 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
783 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
784 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
786 +EXPORT_SYMBOL_GPL(path_noexec);
790 diff --git a/fs/fcntl.c b/fs/fcntl.c
791 index 7550799..d403576 100644
794 @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
798 +EXPORT_SYMBOL_GPL(setfl);
800 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
802 diff --git a/fs/file_table.c b/fs/file_table.c
803 index 7ec0b3e..819ee07 100644
804 --- a/fs/file_table.c
805 +++ b/fs/file_table.c
806 @@ -147,6 +147,7 @@ struct file *get_empty_filp(void)
808 return ERR_PTR(-ENFILE);
810 +EXPORT_SYMBOL_GPL(get_empty_filp);
813 * alloc_file - allocate and initialize a 'struct file'
814 @@ -257,6 +258,7 @@ void flush_delayed_fput(void)
818 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
820 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
822 @@ -299,6 +301,7 @@ void __fput_sync(struct file *file)
826 +EXPORT_SYMBOL_GPL(__fput_sync);
828 void put_filp(struct file *file)
830 @@ -307,6 +310,7 @@ void put_filp(struct file *file)
834 +EXPORT_SYMBOL_GPL(put_filp);
836 void __init files_init(void)
838 diff --git a/fs/inode.c b/fs/inode.c
839 index e0c5255..ff36056 100644
842 @@ -1672,6 +1672,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
844 return update_time(inode, time, flags);
846 +EXPORT_SYMBOL_GPL(update_time);
849 * touch_atime - update the access time
850 diff --git a/fs/namespace.c b/fs/namespace.c
851 index 61129ff..5d3e0382 100644
854 @@ -517,6 +517,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
855 mnt_dec_writers(real_mount(mnt));
858 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
861 * mnt_drop_write - give up write access to a mount
862 @@ -851,6 +852,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
864 return check_mnt(real_mount(mnt));
866 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
869 * vfsmount lock must be held for write
870 @@ -1893,6 +1895,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
874 +EXPORT_SYMBOL_GPL(iterate_mounts);
876 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
878 diff --git a/fs/notify/group.c b/fs/notify/group.c
879 index b7a4b6a..5a69d60 100644
880 --- a/fs/notify/group.c
881 +++ b/fs/notify/group.c
883 #include <linux/srcu.h>
884 #include <linux/rculist.h>
885 #include <linux/wait.h>
886 +#include <linux/module.h>
888 #include <linux/fsnotify_backend.h>
889 #include "fsnotify.h"
890 @@ -109,6 +110,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
892 refcount_inc(&group->refcnt);
894 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
897 * Drop a reference to a group. Free it if it's through.
898 @@ -118,6 +120,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
899 if (refcount_dec_and_test(&group->refcnt))
900 fsnotify_final_destroy_group(group);
902 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
905 * Create a new fsnotify_group and hold a reference for the group returned.
906 @@ -147,6 +150,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
910 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
912 int fsnotify_fasync(int fd, struct file *file, int on)
914 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
915 index e9191b4..1f8ccfa 100644
916 --- a/fs/notify/mark.c
917 +++ b/fs/notify/mark.c
918 @@ -108,6 +108,7 @@ void fsnotify_get_mark(struct fsnotify_mark *mark)
919 WARN_ON_ONCE(!refcount_read(&mark->refcnt));
920 refcount_inc(&mark->refcnt);
922 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
924 static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
926 @@ -392,6 +393,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
927 mutex_unlock(&group->mark_mutex);
928 fsnotify_free_mark(mark);
930 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
933 * Sorting function for lists of fsnotify marks.
934 @@ -606,6 +608,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
935 fsnotify_put_mark(mark);
938 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
940 int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
941 struct vfsmount *mnt, int allow_dups)
942 @@ -741,6 +744,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
943 fsnotify_get_group(group);
946 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
949 * Destroy all marks in destroy_list, waits for SRCU period to finish before
950 diff --git a/fs/open.c b/fs/open.c
951 index d0e955b..527bc1a 100644
954 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
955 inode_unlock(dentry->d_inode);
958 +EXPORT_SYMBOL_GPL(do_truncate);
960 long vfs_truncate(const struct path *path, loff_t length)
962 @@ -723,6 +724,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
964 return ksys_fchown(fd, user, group);
966 +EXPORT_SYMBOL_GPL(open_check_o_direct);
968 int open_check_o_direct(struct file *f)
970 diff --git a/fs/read_write.c b/fs/read_write.c
971 index ddd6e67..aabf92d 100644
972 --- a/fs/read_write.c
973 +++ b/fs/read_write.c
974 @@ -459,6 +459,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
978 +EXPORT_SYMBOL_GPL(vfs_read);
980 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
982 @@ -499,6 +500,7 @@ vfs_readf_t vfs_readf(struct file *file)
983 return new_sync_read;
984 return ERR_PTR(-ENOSYS);
986 +EXPORT_SYMBOL_GPL(vfs_readf);
988 vfs_writef_t vfs_writef(struct file *file)
990 @@ -510,6 +512,7 @@ vfs_writef_t vfs_writef(struct file *file)
991 return new_sync_write;
992 return ERR_PTR(-ENOSYS);
994 +EXPORT_SYMBOL_GPL(vfs_writef);
996 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
998 @@ -579,6 +582,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
1002 +EXPORT_SYMBOL_GPL(vfs_write);
1004 static inline loff_t file_pos_read(struct file *file)
1006 diff --git a/fs/splice.c b/fs/splice.c
1007 index f617ab0..ec0ad02 100644
1010 @@ -850,6 +850,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
1012 return splice_write(pipe, out, ppos, len, flags);
1014 +EXPORT_SYMBOL_GPL(do_splice_from);
1017 * Attempt to initiate a splice from a file to a pipe.
1018 @@ -879,6 +880,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
1020 return splice_read(in, ppos, pipe, len, flags);
1022 +EXPORT_SYMBOL_GPL(do_splice_to);
1025 * splice_direct_to_actor - splices data directly between two non-pipes
1026 diff --git a/fs/sync.c b/fs/sync.c
1027 index 2860782..ffd7ea4 100644
1030 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
1031 sb->s_op->sync_fs(sb, wait);
1032 return __sync_blockdev(sb->s_bdev, wait);
1034 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1037 * Write out and wait upon all dirty data associated with this
1038 diff --git a/fs/xattr.c b/fs/xattr.c
1039 index 61cd28b..35570cd 100644
1042 @@ -297,6 +297,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1043 *xattr_value = value;
1046 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1049 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1050 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1051 index 06e0d7a..6af91bd 100644
1052 --- a/kernel/locking/lockdep.c
1053 +++ b/kernel/locking/lockdep.c
1054 @@ -151,6 +151,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1056 return lock_classes + hlock->class_idx - 1;
1058 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1059 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1061 #ifdef CONFIG_LOCK_STAT
1062 diff --git a/kernel/task_work.c b/kernel/task_work.c
1063 index 0fef395..83fb1ec 100644
1064 --- a/kernel/task_work.c
1065 +++ b/kernel/task_work.c
1066 @@ -116,3 +116,4 @@ void task_work_run(void)
1070 +EXPORT_SYMBOL_GPL(task_work_run);
1071 diff --git a/security/commoncap.c b/security/commoncap.c
1072 index 1ce701f..a0d106e 100644
1073 --- a/security/commoncap.c
1074 +++ b/security/commoncap.c
1075 @@ -1332,12 +1332,14 @@ int cap_mmap_addr(unsigned long addr)
1079 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1081 int cap_mmap_file(struct file *file, unsigned long reqprot,
1082 unsigned long prot, unsigned long flags)
1086 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1088 #ifdef CONFIG_SECURITY
1090 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1091 index c65b39b..e363d22 100644
1092 --- a/security/device_cgroup.c
1093 +++ b/security/device_cgroup.c
1095 #include <linux/device_cgroup.h>
1096 #include <linux/cgroup.h>
1097 #include <linux/ctype.h>
1098 +#include <linux/export.h>
1099 #include <linux/list.h>
1100 #include <linux/uaccess.h>
1101 #include <linux/seq_file.h>
1102 @@ -824,3 +825,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1106 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1107 diff --git a/security/security.c b/security/security.c
1108 index 7bc2fde..6bd0468 100644
1109 --- a/security/security.c
1110 +++ b/security/security.c
1111 @@ -537,6 +537,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1113 return call_int_hook(path_rmdir, 0, dir, dentry);
1115 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1117 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1119 @@ -553,6 +554,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1121 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1123 +EXPORT_SYMBOL_GPL(security_path_symlink);
1125 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1126 struct dentry *new_dentry)
1127 @@ -561,6 +563,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1129 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1131 +EXPORT_SYMBOL_GPL(security_path_link);
1133 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1134 const struct path *new_dir, struct dentry *new_dentry,
1135 @@ -588,6 +591,7 @@ int security_path_truncate(const struct path *path)
1137 return call_int_hook(path_truncate, 0, path);
1139 +EXPORT_SYMBOL_GPL(security_path_truncate);
1141 int security_path_chmod(const struct path *path, umode_t mode)
1143 @@ -595,6 +599,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1145 return call_int_hook(path_chmod, 0, path, mode);
1147 +EXPORT_SYMBOL_GPL(security_path_chmod);
1149 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1151 @@ -602,6 +607,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1153 return call_int_hook(path_chown, 0, path, uid, gid);
1155 +EXPORT_SYMBOL_GPL(security_path_chown);
1157 int security_path_chroot(const struct path *path)
1159 @@ -687,6 +693,7 @@ int security_inode_readlink(struct dentry *dentry)
1161 return call_int_hook(inode_readlink, 0, dentry);
1163 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1165 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1167 @@ -702,6 +709,7 @@ int security_inode_permission(struct inode *inode, int mask)
1169 return call_int_hook(inode_permission, 0, inode, mask);
1171 +EXPORT_SYMBOL_GPL(security_inode_permission);
1173 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1175 @@ -873,6 +881,7 @@ int security_file_permission(struct file *file, int mask)
1177 return fsnotify_perm(file, mask);
1179 +EXPORT_SYMBOL_GPL(security_file_permission);
1181 int security_file_alloc(struct file *file)
1183 @@ -932,6 +941,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1185 return ima_file_mmap(file, prot);
1187 +EXPORT_SYMBOL_GPL(security_mmap_file);
1189 int security_mmap_addr(unsigned long addr)
1191 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1192 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1193 +++ linux/Documentation/ABI/testing/debugfs-aufs 2017-07-29 12:14:25.893041746 +0200
1195 +What: /debug/aufs/si_<id>/
1197 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1199 + Under /debug/aufs, a directory named si_<id> is created
1200 + per aufs mount, where <id> is a unique id generated
1203 +What: /debug/aufs/si_<id>/plink
1205 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1207 + It has three lines and shows the information about the
1208 + pseudo-link. The first line is a single number
1209 + representing a number of buckets. The second line is a
1210 + number of pseudo-links per buckets (separated by a
1211 + blank). The last line is a single number representing a
1212 + total number of psedo-links.
1213 + When the aufs mount option 'noplink' is specified, it
1214 + will show "1\n0\n0\n".
1216 +What: /debug/aufs/si_<id>/xib
1218 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1220 + It shows the consumed blocks by xib (External Inode Number
1221 + Bitmap), its block size and file size.
1222 + When the aufs mount option 'noxino' is specified, it
1223 + will be empty. About XINO files, see the aufs manual.
1225 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1227 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1229 + It shows the consumed blocks by xino (External Inode Number
1230 + Translation Table), its link count, block size and file
1232 + When the aufs mount option 'noxino' is specified, it
1233 + will be empty. About XINO files, see the aufs manual.
1235 +What: /debug/aufs/si_<id>/xigen
1237 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1239 + It shows the consumed blocks by xigen (External Inode
1240 + Generation Table), its block size and file size.
1241 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1243 + When the aufs mount option 'noxino' is specified, it
1244 + will be empty. About XINO files, see the aufs manual.
1245 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1246 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1247 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1249 +What: /sys/fs/aufs/si_<id>/
1251 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1253 + Under /sys/fs/aufs, a directory named si_<id> is created
1254 + per aufs mount, where <id> is a unique id generated
1257 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1259 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1261 + It shows the abolute path of a member directory (which
1262 + is called branch) in aufs, and its permission.
1264 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1266 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1268 + It shows the id of a member directory (which is called
1271 +What: /sys/fs/aufs/si_<id>/xi_path
1273 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1275 + It shows the abolute path of XINO (External Inode Number
1276 + Bitmap, Translation Table and Generation Table) file
1277 + even if it is the default path.
1278 + When the aufs mount option 'noxino' is specified, it
1279 + will be empty. About XINO files, see the aufs manual.
1280 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1281 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1282 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2018-04-15 08:49:13.394483860 +0200
1285 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1287 +# This program is free software; you can redistribute it and/or modify
1288 +# it under the terms of the GNU General Public License as published by
1289 +# the Free Software Foundation; either version 2 of the License, or
1290 +# (at your option) any later version.
1292 +# This program is distributed in the hope that it will be useful,
1293 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1294 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1295 +# GNU General Public License for more details.
1297 +# You should have received a copy of the GNU General Public License
1298 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1301 +----------------------------------------
1303 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1304 +1. abbrev. for "advanced multi-layered unification filesystem".
1305 +2. abbrev. for "another unionfs".
1306 +3. abbrev. for "auf das" in German which means "on the" in English.
1307 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1308 + But "Filesystem aufs Filesystem" is hard to understand.
1309 +4. abbrev. for "African Urban Fashion Show".
1311 +AUFS is a filesystem with features:
1312 +- multi layered stackable unification filesystem, the member directory
1313 + is called as a branch.
1314 +- branch permission and attribute, 'readonly', 'real-readonly',
1315 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1317 +- internal "file copy-on-write".
1318 +- logical deletion, whiteout.
1319 +- dynamic branch manipulation, adding, deleting and changing permission.
1320 +- allow bypassing aufs, user's direct branch access.
1321 +- external inode number translation table and bitmap which maintains the
1322 + persistent aufs inode number.
1323 +- seekable directory, including NFS readdir.
1324 +- file mapping, mmap and sharing pages.
1325 +- pseudo-link, hardlink over branches.
1326 +- loopback mounted filesystem as a branch.
1327 +- several policies to select one among multiple writable branches.
1328 +- revert a single systemcall when an error occurs in aufs.
1332 +Multi Layered Stackable Unification Filesystem
1333 +----------------------------------------------------------------------
1334 +Most people already knows what it is.
1335 +It is a filesystem which unifies several directories and provides a
1336 +merged single directory. When users access a file, the access will be
1337 +passed/re-directed/converted (sorry, I am not sure which English word is
1338 +correct) to the real file on the member filesystem. The member
1339 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1340 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1341 +readonly branch is handled by creating 'whiteout' on the upper writable
1344 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1345 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1346 +different approaches to implement the merged-view.
1347 +The former tries putting it into VFS, and the latter implements as a
1348 +separate filesystem.
1349 +(If I misunderstand about these implementations, please let me know and
1350 +I shall correct it. Because it is a long time ago when I read their
1351 +source files last time).
1353 +UnionMount's approach will be able to small, but may be hard to share
1354 +branches between several UnionMount since the whiteout in it is
1355 +implemented in the inode on branch filesystem and always
1356 +shared. According to Bharata's post, readdir does not seems to be
1358 +There are several missing features known in this implementations such as
1359 +- for users, the inode number may change silently. eg. copy-up.
1360 +- link(2) may break by copy-up.
1361 +- read(2) may get an obsoleted filedata (fstat(2) too).
1362 +- fcntl(F_SETLK) may be broken by copy-up.
1363 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1366 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1367 +merged into mainline. This is another implementation of UnionMount as a
1368 +separated filesystem. All the limitations and known problems which
1369 +UnionMount are equally inherited to "overlay" filesystem.
1371 +Unionfs has a longer history. When I started implementing a stackable
1372 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1373 +inode, dentry and file objects and they have an array pointing lower
1374 +same kind objects. After contributing many patches for Unionfs, I
1375 +re-started my project AUFS (Jun 2006).
1377 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1378 +implemented my own ideas, approaches and enhancements and it became
1379 +totally different one.
1381 +Comparing DM snapshot and fs based implementation
1382 +- the number of bytes to be copied between devices is much smaller.
1383 +- the type of filesystem must be one and only.
1384 +- the fs must be writable, no readonly fs, even for the lower original
1385 + device. so the compression fs will not be usable. but if we use
1386 + loopback mount, we may address this issue.
1388 + mount /cdrom/squashfs.img /sq
1389 + losetup /sq/ext2.img
1390 + losetup /somewhere/cow
1391 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1392 +- it will be difficult (or needs more operations) to extract the
1393 + difference between the original device and COW.
1394 +- DM snapshot-merge may help a lot when users try merging. in the
1395 + fs-layer union, users will use rsync(1).
1397 +You may want to read my old paper "Filesystems in LiveCD"
1398 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1401 +Several characters/aspects/persona of aufs
1402 +----------------------------------------------------------------------
1404 +Aufs has several characters, aspects or persona.
1405 +1. a filesystem, callee of VFS helper
1406 +2. sub-VFS, caller of VFS helper for branches
1407 +3. a virtual filesystem which maintains persistent inode number
1408 +4. reader/writer of files on branches such like an application
1410 +1. Callee of VFS Helper
1411 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1412 +unlink(2) from an application reaches sys_unlink() kernel function and
1413 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1414 +calls filesystem specific unlink operation. Actually aufs implements the
1415 +unlink operation but it behaves like a redirector.
1417 +2. Caller of VFS Helper for Branches
1418 +aufs_unlink() passes the unlink request to the branch filesystem as if
1419 +it were called from VFS. So the called unlink operation of the branch
1420 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1421 +every necessary pre/post operation for the branch filesystem.
1422 +- acquire the lock for the parent dir on a branch
1423 +- lookup in a branch
1424 +- revalidate dentry on a branch
1425 +- mnt_want_write() for a branch
1426 +- vfs_unlink() for a branch
1427 +- mnt_drop_write() for a branch
1428 +- release the lock on a branch
1430 +3. Persistent Inode Number
1431 +One of the most important issue for a filesystem is to maintain inode
1432 +numbers. This is particularly important to support exporting a
1433 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1434 +backend block device for its own. But some storage is necessary to
1435 +keep and maintain the inode numbers. It may be a large space and may not
1436 +suit to keep in memory. Aufs rents some space from its first writable
1437 +branch filesystem (by default) and creates file(s) on it. These files
1438 +are created by aufs internally and removed soon (currently) keeping
1440 +Note: Because these files are removed, they are totally gone after
1441 + unmounting aufs. It means the inode numbers are not persistent
1442 + across unmount or reboot. I have a plan to make them really
1443 + persistent which will be important for aufs on NFS server.
1445 +4. Read/Write Files Internally (copy-on-write)
1446 +Because a branch can be readonly, when you write a file on it, aufs will
1447 +"copy-up" it to the upper writable branch internally. And then write the
1448 +originally requested thing to the file. Generally kernel doesn't
1449 +open/read/write file actively. In aufs, even a single write may cause a
1450 +internal "file copy". This behaviour is very similar to cp(1) command.
1452 +Some people may think it is better to pass such work to user space
1453 +helper, instead of doing in kernel space. Actually I am still thinking
1454 +about it. But currently I have implemented it in kernel space.
1455 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1456 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1457 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2018-04-15 08:49:13.394483860 +0200
1460 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1462 +# This program is free software; you can redistribute it and/or modify
1463 +# it under the terms of the GNU General Public License as published by
1464 +# the Free Software Foundation; either version 2 of the License, or
1465 +# (at your option) any later version.
1467 +# This program is distributed in the hope that it will be useful,
1468 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1469 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1470 +# GNU General Public License for more details.
1472 +# You should have received a copy of the GNU General Public License
1473 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1475 +Basic Aufs Internal Structure
1477 +Superblock/Inode/Dentry/File Objects
1478 +----------------------------------------------------------------------
1479 +As like an ordinary filesystem, aufs has its own
1480 +superblock/inode/dentry/file objects. All these objects have a
1481 +dynamically allocated array and store the same kind of pointers to the
1482 +lower filesystem, branch.
1483 +For example, when you build a union with one readwrite branch and one
1484 +readonly, mounted /au, /rw and /ro respectively.
1486 +- /ro/fileA exists but /rw/fileA
1488 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1489 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1490 +- [0] = NULL (because /rw/fileA doesn't exist)
1493 +This style of an array is essentially same to the aufs
1494 +superblock/inode/dentry/file objects.
1496 +Because aufs supports manipulating branches, ie. add/delete/change
1497 +branches dynamically, these objects has its own generation. When
1498 +branches are changed, the generation in aufs superblock is
1499 +incremented. And a generation in other object are compared when it is
1500 +accessed. When a generation in other objects are obsoleted, aufs
1501 +refreshes the internal array.
1505 +----------------------------------------------------------------------
1506 +Additionally aufs superblock has some data for policies to select one
1507 +among multiple writable branches, XIB files, pseudo-links and kobject.
1508 +See below in detail.
1509 +About the policies which supports copy-down a directory, see
1510 +wbr_policy.txt too.
1513 +Branch and XINO(External Inode Number Translation Table)
1514 +----------------------------------------------------------------------
1515 +Every branch has its own xino (external inode number translation table)
1516 +file. The xino file is created and unlinked by aufs internally. When two
1517 +members of a union exist on the same filesystem, they share the single
1519 +The struct of a xino file is simple, just a sequence of aufs inode
1520 +numbers which is indexed by the lower inode number.
1521 +In the above sample, assume the inode number of /ro/fileA is i111 and
1522 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1523 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1525 +When the inode numbers are not contiguous, the xino file will be sparse
1526 +which has a hole in it and doesn't consume as much disk space as it
1527 +might appear. If your branch filesystem consumes disk space for such
1528 +holes, then you should specify 'xino=' option at mounting aufs.
1530 +Aufs has a mount option to free the disk blocks for such holes in XINO
1531 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1532 +meet a problem of disk shortage due to XINO files, then you should try
1533 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1534 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1535 +the holes in XINO files.
1537 +Also a writable branch has three kinds of "whiteout bases". All these
1538 +are existed when the branch is joined to aufs, and their names are
1539 +whiteout-ed doubly, so that users will never see their names in aufs
1541 +1. a regular file which will be hardlinked to all whiteouts.
1542 +2. a directory to store a pseudo-link.
1543 +3. a directory to store an "orphan"-ed file temporary.
1546 + When you remove a file on a readonly branch, aufs handles it as a
1547 + logical deletion and creates a whiteout on the upper writable branch
1548 + as a hardlink of this file in order not to consume inode on the
1551 + See below, Pseudo-link.
1553 + When "fileC" exists on the lower readonly branch only and it is
1554 + opened and removed with its parent dir, and then user writes
1555 + something into it, then aufs copies-up fileC to this
1556 + directory. Because there is no other dir to store fileC. After
1557 + creating a file under this dir, the file is unlinked.
1559 +Because aufs supports manipulating branches, ie. add/delete/change
1560 +dynamically, a branch has its own id. When the branch order changes,
1561 +aufs finds the new index by searching the branch id.
1565 +----------------------------------------------------------------------
1566 +Assume "fileA" exists on the lower readonly branch only and it is
1567 +hardlinked to "fileB" on the branch. When you write something to fileA,
1568 +aufs copies-up it to the upper writable branch. Additionally aufs
1569 +creates a hardlink under the Pseudo-link Directory of the writable
1570 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1571 +simple list. If fileB is read after unlinking fileA, aufs returns
1572 +filedata from the pseudo-link instead of the lower readonly
1573 +branch. Because the pseudo-link is based upon the inode, to keep the
1574 +inode number by xino (see above) is essentially necessary.
1576 +All the hardlinks under the Pseudo-link Directory of the writable branch
1577 +should be restored in a proper location later. Aufs provides a utility
1578 +to do this. The userspace helpers executed at remounting and unmounting
1580 +During this utility is running, it puts aufs into the pseudo-link
1581 +maintenance mode. In this mode, only the process which began the
1582 +maintenance mode (and its child processes) is allowed to operate in
1583 +aufs. Some other processes which are not related to the pseudo-link will
1584 +be allowed to run too, but the rest have to return an error or wait
1585 +until the maintenance mode ends. If a process already acquires an inode
1586 +mutex (in VFS), it has to return an error.
1589 +XIB(external inode number bitmap)
1590 +----------------------------------------------------------------------
1591 +Addition to the xino file per a branch, aufs has an external inode number
1592 +bitmap in a superblock object. It is also an internal file such like a
1594 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1596 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1598 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1599 +reduce the number of consumed disk blocks for these files.
1602 +Virtual or Vertical Dir, and Readdir in Userspace
1603 +----------------------------------------------------------------------
1604 +In order to support multiple layers (branches), aufs readdir operation
1605 +constructs a virtual dir block on memory. For readdir, aufs calls
1606 +vfs_readdir() internally for each dir on branches, merges their entries
1607 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1608 +object. So the file object has its entry list until it is closed. The
1609 +entry list will be updated when the file position is zero and becomes
1610 +obsoleted. This decision is made in aufs automatically.
1612 +The dynamically allocated memory block for the name of entries has a
1613 +unit of 512 bytes (by default) and stores the names contiguously (no
1614 +padding). Another block for each entry is handled by kmem_cache too.
1615 +During building dir blocks, aufs creates hash list and judging whether
1616 +the entry is whiteouted by its upper branch or already listed.
1617 +The merged result is cached in the corresponding inode object and
1618 +maintained by a customizable life-time option.
1620 +Some people may call it can be a security hole or invite DoS attack
1621 +since the opened and once readdir-ed dir (file object) holds its entry
1622 +list and becomes a pressure for system memory. But I'd say it is similar
1623 +to files under /proc or /sys. The virtual files in them also holds a
1624 +memory page (generally) while they are opened. When an idea to reduce
1625 +memory for them is introduced, it will be applied to aufs too.
1626 +For those who really hate this situation, I've developed readdir(3)
1627 +library which operates this merging in userspace. You just need to set
1628 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1629 +kernel space for readdir(3).
1633 +----------------------------------------------------------------------
1634 +Aufs sometimes requires privilege access to a branch. For instance,
1635 +in copy-up/down operation. When a user process is going to make changes
1636 +to a file which exists in the lower readonly branch only, and the mode
1637 +of one of ancestor directories may not be writable by a user
1638 +process. Here aufs copy-up the file with its ancestors and they may
1639 +require privilege to set its owner/group/mode/etc.
1640 +This is a typical case of a application character of aufs (see
1643 +Aufs uses workqueue synchronously for this case. It creates its own
1644 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1645 +passes the request to call mkdir or write (for example), and wait for
1646 +its completion. This approach solves a problem of a signal handler
1648 +If aufs didn't adopt the workqueue and changed the privilege of the
1649 +process, then the process may receive the unexpected SIGXFSZ or other
1652 +Also aufs uses the system global workqueue ("events" kernel thread) too
1653 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1654 +whiteout base and etc. This is unrelated to a privilege.
1655 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1656 +superblock at the beginning, at the same time waits for the completion
1657 +of all queued asynchronous tasks.
1661 +----------------------------------------------------------------------
1662 +The whiteout in aufs is very similar to Unionfs's. That is represented
1663 +by its filename. UnionMount takes an approach of a file mode, but I am
1664 +afraid several utilities (find(1) or something) will have to support it.
1666 +Basically the whiteout represents "logical deletion" which stops aufs to
1667 +lookup further, but also it represents "dir is opaque" which also stop
1670 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1671 +In order to make several functions in a single systemcall to be
1672 +revertible, aufs adopts an approach to rename a directory to a temporary
1673 +unique whiteouted name.
1674 +For example, in rename(2) dir where the target dir already existed, aufs
1675 +renames the target dir to a temporary unique whiteouted name before the
1676 +actual rename on a branch, and then handles other actions (make it opaque,
1677 +update the attributes, etc). If an error happens in these actions, aufs
1678 +simply renames the whiteouted name back and returns an error. If all are
1679 +succeeded, aufs registers a function to remove the whiteouted unique
1680 +temporary name completely and asynchronously to the system global
1685 +----------------------------------------------------------------------
1686 +It is a well-known feature or concept.
1687 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1688 +internally and makes change to the new file on the upper writable branch.
1689 +When the trigger systemcall does not update the timestamps of the parent
1690 +dir, aufs reverts it after copy-up.
1693 +Move-down (aufs3.9 and later)
1694 +----------------------------------------------------------------------
1695 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1696 +the lower readonly branch to the upper writable branch when a user
1697 +changes something about the file.
1698 +"Move-down" is an opposite action of copy-up. Basically this action is
1699 +ran manually instead of automatically and internally.
1700 +For desgin and implementation, aufs has to consider these issues.
1701 +- whiteout for the file may exist on the lower branch.
1702 +- ancestor directories may not exist on the lower branch.
1703 +- diropq for the ancestor directories may exist on the upper branch.
1704 +- free space on the lower branch will reduce.
1705 +- another access to the file may happen during moving-down, including
1706 + UDBA (see "Revalidate Dentry and UDBA").
1707 +- the file should not be hard-linked nor pseudo-linked. they should be
1708 + handled by auplink utility later.
1710 +Sometimes users want to move-down a file from the upper writable branch
1711 +to the lower readonly or writable branch. For instance,
1712 +- the free space of the upper writable branch is going to run out.
1713 +- create a new intermediate branch between the upper and lower branch.
1716 +For this purpose, use "aumvdown" command in aufs-util.git.
1717 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1718 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1719 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2018-04-15 08:49:13.394483860 +0200
1722 +# Copyright (C) 2015-2018 Junjiro R. Okajima
1724 +# This program is free software; you can redistribute it and/or modify
1725 +# it under the terms of the GNU General Public License as published by
1726 +# the Free Software Foundation; either version 2 of the License, or
1727 +# (at your option) any later version.
1729 +# This program is distributed in the hope that it will be useful,
1730 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1731 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1732 +# GNU General Public License for more details.
1734 +# You should have received a copy of the GNU General Public License
1735 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1737 +Support for a branch who has its ->atomic_open()
1738 +----------------------------------------------------------------------
1739 +The filesystems who implement its ->atomic_open() are not majority. For
1740 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1741 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1742 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1743 +sure whether all filesystems who have ->atomic_open() behave like this,
1744 +but NFSv4 surely returns the error.
1746 +In order to support ->atomic_open() for aufs, there are a few
1749 +A. Introduce aufs_atomic_open()
1750 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1752 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1753 + an aufs user Pip Cet's approach
1754 + - calls aufs_create(), VFS finish_open() and notify_change().
1755 + - pass fake-mode to finish_open(), and then correct the mode by
1757 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1758 + - no aufs_atomic_open().
1759 + - aufs_lookup() registers the TID to an aufs internal object.
1760 + - aufs_create() does nothing when the matching TID is registered, but
1761 + registers the mode.
1762 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1763 + TID is registered.
1764 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1766 + - no aufs_atomic_open().
1767 + - aufs_create() registers the TID to an internal object. this info
1768 + represents "this process created this file just now."
1769 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1770 + registered TID and re-try open() with superuser's credential.
1772 +Pros and cons for each approach.
1775 + - straightforward but highly depends upon VFS internal.
1776 + - the atomic behavaiour is kept.
1777 + - some of parameters such as nameidata are hard to reproduce for
1781 + - easy to implement.
1782 + - the atomic behavaiour is lost.
1784 + - the atomic behavaiour is kept.
1785 + - dirty and tricky.
1786 + - VFS checks whether the file is created correctly after calling
1787 + ->create(), which means this approach doesn't work.
1789 + - easy to implement.
1790 + - the atomic behavaiour is lost.
1791 + - to open a file with superuser's credential and give it to a user
1792 + process is a bad idea, since the file object keeps the credential
1793 + in it. It may affect LSM or something. This approach doesn't work
1796 +The approach A is ideal, but it hard to implement. So here is a
1797 +variation of A, which is to be implemented.
1799 +A-1. Introduce aufs_atomic_open()
1800 + - calls branch fs ->atomic_open() if exists. otherwise calls
1801 + vfs_create() and finish_open().
1802 + - the demerit is that the several checks after branch fs
1803 + ->atomic_open() are lost. in the ordinary case, the checks are
1804 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1805 + be implemented in aufs, but not all I am afraid.
1806 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1807 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1808 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2018-04-15 08:49:13.394483860 +0200
1811 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1813 +# This program is free software; you can redistribute it and/or modify
1814 +# it under the terms of the GNU General Public License as published by
1815 +# the Free Software Foundation; either version 2 of the License, or
1816 +# (at your option) any later version.
1818 +# This program is distributed in the hope that it will be useful,
1819 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1820 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1821 +# GNU General Public License for more details.
1823 +# You should have received a copy of the GNU General Public License
1824 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1827 +----------------------------------------------------------------------
1828 +Since aufs has a character of sub-VFS (see Introduction), it operates
1829 +lookup for branches as VFS does. It may be a heavy work. But almost all
1830 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1831 +directly connected to its parent. Digging down the directory hierarchy
1832 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1835 +When a branch is a remote filesystem, aufs basically relies upon its
1836 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1838 +For d_revalidate, aufs implements three levels of revalidate tests. See
1839 +"Revalidate Dentry and UDBA" in detail.
1842 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1843 +----------------------------------------------------------------------
1844 +Let's try case study.
1845 +- aufs has two branches, upper readwrite and lower readonly.
1847 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1848 +- user invoked "chmod a+rx /au/dirA"
1849 +- the internal copy-up is activated and "/rw/dirA" is created and its
1850 + permission bits are set to world readable.
1851 +- then "/au/dirA" becomes world readable?
1853 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1854 +or it may be a natively readonly filesystem. If aufs respects the lower
1855 +branch, it should not respond readdir request from other users. But user
1856 +allowed it by chmod. Should really aufs rejects showing the entries
1859 +To be honest, I don't have a good solution for this case. So aufs
1860 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1862 +When dirperm1 is specified, aufs checks only the highest one for the
1863 +directory permission, and shows the entries. Otherwise, as usual, checks
1864 +every dir existing on all branches and rejects the request.
1866 +As a side effect, dirperm1 option improves the performance of aufs
1867 +because the number of permission check is reduced when the number of
1871 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1872 +----------------------------------------------------------------------
1873 +Generally VFS helpers re-validate a dentry as a part of lookup.
1874 +0. digging down the directory hierarchy.
1875 +1. lock the parent dir by its i_mutex.
1876 +2. lookup the final (child) entry.
1878 +4. call the actual operation (create, unlink, etc.)
1879 +5. unlock the parent dir
1881 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1882 +called. Actually aufs implements it and checks the dentry on a branch is
1884 +But it is not enough. Because aufs has to release the lock for the
1885 +parent dir on a branch at the end of ->lookup() (step 2) and
1886 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1888 +If the file on a branch is changed directly, eg. bypassing aufs, after
1889 +aufs released the lock, then the subsequent operation may cause
1890 +something unpleasant result.
1892 +This situation is a result of VFS architecture, ->lookup() and
1893 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1894 +design from VFS's point of view. It is just not suitable for sub-VFS
1897 +Aufs supports such case by three level of revalidation which is
1898 +selectable by user.
1899 +1. Simple Revalidate
1900 + Addition to the native flow in VFS's, confirm the child-parent
1901 + relationship on the branch just after locking the parent dir on the
1902 + branch in the "actual operation" (step 4). When this validation
1903 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1904 + checks the validation of the dentry on branches.
1905 +2. Monitor Changes Internally by Inotify/Fsnotify
1906 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1907 + the dentry on the branch, and returns EBUSY if it finds different
1909 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1910 + during it is in cache. When the event is notified, aufs registers a
1911 + function to kernel 'events' thread by schedule_work(). And the
1912 + function sets some special status to the cached aufs dentry and inode
1913 + private data. If they are not cached, then aufs has nothing to
1914 + do. When the same file is accessed through aufs (step 0-3) later,
1915 + aufs will detect the status and refresh all necessary data.
1916 + In this mode, aufs has to ignore the event which is fired by aufs
1918 +3. No Extra Validation
1919 + This is the simplest test and doesn't add any additional revalidation
1920 + test, and skip the revalidation in step 4. It is useful and improves
1921 + aufs performance when system surely hide the aufs branches from user,
1922 + by over-mounting something (or another method).
1923 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1924 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1925 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2018-04-15 08:49:13.394483860 +0200
1928 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1930 +# This program is free software; you can redistribute it and/or modify
1931 +# it under the terms of the GNU General Public License as published by
1932 +# the Free Software Foundation; either version 2 of the License, or
1933 +# (at your option) any later version.
1935 +# This program is distributed in the hope that it will be useful,
1936 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1937 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1938 +# GNU General Public License for more details.
1940 +# You should have received a copy of the GNU General Public License
1941 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1943 +Branch Manipulation
1945 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1946 +and changing its permission/attribute, there are a lot of works to do.
1950 +----------------------------------------------------------------------
1951 +o Confirm the adding dir exists outside of aufs, including loopback
1952 + mount, and its various attributes.
1953 +o Initialize the xino file and whiteout bases if necessary.
1956 +o Check the owner/group/mode of the directory
1957 + When the owner/group/mode of the adding directory differs from the
1958 + existing branch, aufs issues a warning because it may impose a
1960 + For example, when a upper writable branch has a world writable empty
1961 + top directory, a malicious user can create any files on the writable
1962 + branch directly, like copy-up and modify manually. If something like
1963 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1964 + writable branch, and the writable branch is world-writable, then a
1965 + malicious guy may create /etc/passwd on the writable branch directly
1966 + and the infected file will be valid in aufs.
1967 + I am afraid it can be a security issue, but aufs can do nothing except
1968 + producing a warning.
1972 +----------------------------------------------------------------------
1973 +o Confirm the deleting branch is not busy
1974 + To be general, there is one merit to adopt "remount" interface to
1975 + manipulate branches. It is to discard caches. At deleting a branch,
1976 + aufs checks the still cached (and connected) dentries and inodes. If
1977 + there are any, then they are all in-use. An inode without its
1978 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1980 + For the cached one, aufs checks whether the same named entry exists on
1982 + If the cached one is a directory, because aufs provides a merged view
1983 + to users, as long as one dir is left on any branch aufs can show the
1984 + dir to users. In this case, the branch can be removed from aufs.
1985 + Otherwise aufs rejects deleting the branch.
1987 + If any file on the deleting branch is opened by aufs, then aufs
1991 +Modify the Permission of a Branch
1992 +----------------------------------------------------------------------
1993 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1996 +o rw --> ro: Confirm the modifying branch is not busy
1997 + Aufs rejects the request if any of these conditions are true.
1998 + - a file on the branch is mmap-ed.
1999 + - a regular file on the branch is opened for write and there is no
2000 + same named entry on the upper branch.
2001 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
2002 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
2003 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2018-04-15 08:49:13.394483860 +0200
2006 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2008 +# This program is free software; you can redistribute it and/or modify
2009 +# it under the terms of the GNU General Public License as published by
2010 +# the Free Software Foundation; either version 2 of the License, or
2011 +# (at your option) any later version.
2013 +# This program is distributed in the hope that it will be useful,
2014 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2015 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2016 +# GNU General Public License for more details.
2018 +# You should have received a copy of the GNU General Public License
2019 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2021 +Policies to Select One among Multiple Writable Branches
2022 +----------------------------------------------------------------------
2023 +When the number of writable branch is more than one, aufs has to decide
2024 +the target branch for file creation or copy-up. By default, the highest
2025 +writable branch which has the parent (or ancestor) dir of the target
2026 +file is chosen (top-down-parent policy).
2027 +By user's request, aufs implements some other policies to select the
2028 +writable branch, for file creation several policies, round-robin,
2029 +most-free-space, and other policies. For copy-up, top-down-parent,
2030 +bottom-up-parent, bottom-up and others.
2032 +As expected, the round-robin policy selects the branch in circular. When
2033 +you have two writable branches and creates 10 new files, 5 files will be
2034 +created for each branch. mkdir(2) systemcall is an exception. When you
2035 +create 10 new directories, all will be created on the same branch.
2036 +And the most-free-space policy selects the one which has most free
2037 +space among the writable branches. The amount of free space will be
2038 +checked by aufs internally, and users can specify its time interval.
2040 +The policies for copy-up is more simple,
2041 +top-down-parent is equivalent to the same named on in create policy,
2042 +bottom-up-parent selects the writable branch where the parent dir
2043 +exists and the nearest upper one from the copyup-source,
2044 +bottom-up selects the nearest upper writable branch from the
2045 +copyup-source, regardless the existence of the parent dir.
2047 +There are some rules or exceptions to apply these policies.
2048 +- If there is a readonly branch above the policy-selected branch and
2049 + the parent dir is marked as opaque (a variation of whiteout), or the
2050 + target (creating) file is whiteout-ed on the upper readonly branch,
2051 + then the result of the policy is ignored and the target file will be
2052 + created on the nearest upper writable branch than the readonly branch.
2053 +- If there is a writable branch above the policy-selected branch and
2054 + the parent dir is marked as opaque or the target file is whiteouted
2055 + on the branch, then the result of the policy is ignored and the target
2056 + file will be created on the highest one among the upper writable
2057 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2059 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2060 + They try selecting the branch where the source exists as possible
2061 + since copyup a large file will take long time. If it can't be,
2062 + ie. the branch where the source exists is readonly, then they will
2063 + follow the copyup policy.
2064 +- There is an exception for rename(2) when the target exists.
2065 + If the rename target exists, aufs compares the index of the branches
2066 + where the source and the target exists and selects the higher
2067 + one. If the selected branch is readonly, then aufs follows the
2069 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2070 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2071 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2018-04-15 08:49:13.394483860 +0200
2074 +// to view this graph, run dot(1) command in GRAPHVIZ.
2078 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2082 +aufs_rename -> whinfo [label="store/remove"];
2085 +inode_list [label="h_inum list in branch\ncache"];
2088 +whinode [label="h_inum list file"];
2091 +brmgmt [label="br_add/del/mod/umount"];
2093 +brmgmt -> inode_list [label="create/remove"];
2094 +brmgmt -> whinode [label="load/store"];
2096 +inode_list -> whinode [style=dashed,dir=both];
2098 +aufs_rename -> inode_list [label="add/del"];
2100 +aufs_lookup -> inode_list [label="search"];
2102 +aufs_lookup -> whinfo [label="load/remove"];
2104 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2105 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2106 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2018-04-15 08:49:13.394483860 +0200
2109 +# Copyright (C) 2017-2018 Junjiro R. Okajima
2111 +# This program is free software; you can redistribute it and/or modify
2112 +# it under the terms of the GNU General Public License as published by
2113 +# the Free Software Foundation; either version 2 of the License, or
2114 +# (at your option) any later version.
2116 +# This program is distributed in the hope that it will be useful,
2117 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2118 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2119 +# GNU General Public License for more details.
2121 +# You should have received a copy of the GNU General Public License
2122 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2124 +Special handling for renaming a directory (DIRREN)
2125 +----------------------------------------------------------------------
2126 +First, let's assume we have a simple usecase.
2130 +- /ro/dirA and /ro/dirA/file exist too
2131 +- there is no dirB on both branches
2132 +- a user issues rename("dirA", "dirB")
2134 +Now, what should aufs behave against this rename(2)?
2135 +There are a few possible cases.
2138 + since dirA exists on a readonly branch which cannot be renamed.
2140 + it is possible to copy-up dirA (only the dir itself), but the child
2141 + entries ("file" in this case) should not be. it must be a bad
2142 + approach to copy-up recursively.
2143 +C. returns a success.
2144 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2145 + is a violation of aufs' policy.
2146 +D. construct an extra information which indicates that /ro/dirA should
2147 + be handled as the name of dirB.
2148 + overlayfs has a similar feature called REDIRECT.
2150 +Until now, aufs implements the case B only which returns EXDEV, and
2151 +expects the userspace application behaves like mv(1) which tries
2152 +issueing rename(2) recursively.
2154 +A new aufs feature called DIRREN is introduced which implements the case
2155 +D. There are several "extra information" added.
2157 +1. detailed info per renamed directory
2158 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2159 +2. the inode-number list of directories on a branch
2160 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2162 +The filename of "detailed info per directory" represents the lower
2163 +branch, and its format is
2164 +- a type of the branch id
2166 + + uuid (not implemented yet)
2169 +- the inode-number of the branch root dir
2171 +And it contains these info in a single regular file.
2173 +- branch's inode-number of the logically renamed dir
2174 +- the name of the before-renamed dir
2176 +The "detailed info per directory" file is created in aufs rename(2), and
2177 +loaded in any lookup.
2178 +The info is considered in lookup for the matching case only. Here
2179 +"matching" means that the root of branch (in the info filename) is same
2180 +to the current looking-up branch. After looking-up the before-renamed
2181 +name, the inode-number is compared. And the matched dentry is used.
2183 +The "inode-number list of directories" is a regular file which contains
2184 +simply the inode-numbers on the branch. The file is created or updated
2185 +in removing the branch, and loaded in adding the branch. Its lifetime is
2186 +equal to the branch.
2187 +The list is refered in lookup, and when the current target inode is
2188 +found in the list, the aufs tries loading the "detailed info per
2189 +directory" and get the changed and valid name of the dir.
2191 +Theoretically these "extra informaiton" may be able to be put into XATTR
2192 +in the dir inode. But aufs doesn't choose this way because
2193 +1. XATTR may not be supported by the branch (or its configuration)
2194 +2. XATTR may have its size limit.
2195 +3. XATTR may be less easy to convert than a regular file, when the
2196 + format of the info is changed in the future.
2197 +At the same time, I agree that the regular file approach is much slower
2198 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2201 +This DIRREN feature is enabled by aufs configuration, and is activated
2202 +by a new mount option.
2204 +For the more complicated case, there is a work with UDBA option, which
2205 +is to dected the direct access to the branches (by-passing aufs) and to
2206 +maintain the cashes in aufs. Since a single cached aufs dentry may
2207 +contains two names, before- and after-rename, the name comparision in
2208 +UDBA handler may not work correctly. In this case, the behaviour will be
2209 +equivalen to udba=reval case.
2210 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2211 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2212 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2018-04-15 08:49:13.394483860 +0200
2215 +# Copyright (C) 2011-2018 Junjiro R. Okajima
2217 +# This program is free software; you can redistribute it and/or modify
2218 +# it under the terms of the GNU General Public License as published by
2219 +# the Free Software Foundation; either version 2 of the License, or
2220 +# (at your option) any later version.
2222 +# This program is distributed in the hope that it will be useful,
2223 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2224 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2225 +# GNU General Public License for more details.
2227 +# You should have received a copy of the GNU General Public License
2228 +# along with this program; if not, write to the Free Software
2229 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2232 +File-based Hierarchical Storage Management (FHSM)
2233 +----------------------------------------------------------------------
2234 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2235 +storage world. Aufs provides this feature as file-based with multiple
2236 +writable branches, based upon the principle of "Colder, the Lower".
2237 +Here the word "colder" means that the less used files, and "lower" means
2238 +that the position in the order of the stacked branches vertically.
2239 +These multiple writable branches are prioritized, ie. the topmost one
2240 +should be the fastest drive and be used heavily.
2242 +o Characters in aufs FHSM story
2243 +- aufs itself and a new branch attribute.
2244 +- a new ioctl interface to move-down and to establish a connection with
2245 + the daemon ("move-down" is a converse of "copy-up").
2246 +- userspace tool and daemon.
2248 +The userspace daemon establishes a connection with aufs and waits for
2249 +the notification. The notified information is very similar to struct
2250 +statfs containing the number of consumed blocks and inodes.
2251 +When the consumed blocks/inodes of a branch exceeds the user-specified
2252 +upper watermark, the daemon activates its move-down process until the
2253 +consumed blocks/inodes reaches the user-specified lower watermark.
2255 +The actual move-down is done by aufs based upon the request from
2256 +user-space since we need to maintain the inode number and the internal
2257 +pointer arrays in aufs.
2259 +Currently aufs FHSM handles the regular files only. Additionally they
2260 +must not be hard-linked nor pseudo-linked.
2263 +o Cowork of aufs and the user-space daemon
2264 + During the userspace daemon established the connection, aufs sends a
2265 + small notification to it whenever aufs writes something into the
2266 + writable branch. But it may cost high since aufs issues statfs(2)
2267 + internally. So user can specify a new option to cache the
2268 + info. Actually the notification is controlled by these factors.
2269 + + the specified cache time.
2270 + + classified as "force" by aufs internally.
2271 + Until the specified time expires, aufs doesn't send the info
2272 + except the forced cases. When aufs decide forcing, the info is always
2273 + notified to userspace.
2274 + For example, the number of free inodes is generally large enough and
2275 + the shortage of it happens rarely. So aufs doesn't force the
2276 + notification when creating a new file, directory and others. This is
2277 + the typical case which aufs doesn't force.
2278 + When aufs writes the actual filedata and the files consumes any of new
2279 + blocks, the aufs forces notifying.
2282 +o Interfaces in aufs
2283 +- New branch attribute.
2285 + Specifies that the branch is managed by FHSM feature. In other word,
2286 + participant in the FHSM.
2287 + When nofhsm is set to the branch, it will not be the source/target
2288 + branch of the move-down operation. This attribute is set
2289 + independently from coo and moo attributes, and if you want full
2290 + FHSM, you should specify them as well.
2291 +- New mount option.
2293 + Specifies a second to suppress many less important info to be
2296 + + AUFS_CTL_FHSM_FD
2297 + create a new file descriptor which userspace can read the notification
2298 + (a subset of struct statfs) from aufs.
2299 +- Module parameter 'brs'
2300 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2302 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2303 + When there are two or more branches with fhsm attributes,
2304 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2305 + terminates it. As a result of remounting and branch-manipulation, the
2306 + number of branches with fhsm attribute can be one. In this case,
2307 + /sbin/mount.aufs will terminate the user-space daemon.
2310 +Finally the operation is done as these steps in kernel-space.
2312 + + no one else is using the file.
2313 + + the file is not hard-linked.
2314 + + the file is not pseudo-linked.
2315 + + the file is a regular file.
2316 + + the parent dir is not opaqued.
2317 +- find the target writable branch.
2318 +- make sure the file is not whiteout-ed by the upper (than the target)
2320 +- make the parent dir on the target branch.
2321 +- mutex lock the inode on the branch.
2322 +- unlink the whiteout on the target branch (if exists).
2323 +- lookup and create the whiteout-ed temporary name on the target branch.
2324 +- copy the file as the whiteout-ed temporary name on the target branch.
2325 +- rename the whiteout-ed temporary name to the original name.
2326 +- unlink the file on the source branch.
2327 +- maintain the internal pointer array and the external inode number
2329 +- maintain the timestamps and other attributes of the parent dir and the
2332 +And of course, in every step, an error may happen. So the operation
2333 +should restore the original file state after an error happens.
2334 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2335 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2336 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2018-04-15 08:49:13.394483860 +0200
2339 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2341 +# This program is free software; you can redistribute it and/or modify
2342 +# it under the terms of the GNU General Public License as published by
2343 +# the Free Software Foundation; either version 2 of the License, or
2344 +# (at your option) any later version.
2346 +# This program is distributed in the hope that it will be useful,
2347 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2348 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2349 +# GNU General Public License for more details.
2351 +# You should have received a copy of the GNU General Public License
2352 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2354 +mmap(2) -- File Memory Mapping
2355 +----------------------------------------------------------------------
2356 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2357 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2359 +This approach is simple and good, but there is one problem.
2360 +Under /proc, several entries show the mmapped files by its path (with
2361 +device and inode number), and the printed path will be the path on the
2362 +branch fs's instead of virtual aufs's.
2363 +This is not a problem in most cases, but some utilities lsof(1) (and its
2364 +user) may expect the path on aufs.
2366 +To address this issue, aufs adds a new member called vm_prfile in struct
2367 +vm_area_struct (and struct vm_region). The original vm_file points to
2368 +the file on the branch fs in order to handle everything correctly as
2369 +usual. The new vm_prfile points to a virtual file in aufs, and the
2370 +show-functions in procfs refers to vm_prfile if it is set.
2371 +Also we need to maintain several other places where touching vm_file
2373 +- fork()/clone() copies vma and the reference count of vm_file is
2375 +- merging vma maintains the ref count too.
2377 +This is not a good approach. It just fakes the printed path. But it
2378 +leaves all behaviour around f_mapping unchanged. This is surely an
2380 +Actually aufs had adopted another complicated approach which calls
2381 +generic_file_mmap() and handles struct vm_operations_struct. In this
2382 +approach, aufs met a hard problem and I could not solve it without
2383 +switching the approach.
2385 +There may be one more another approach which is
2386 +- bind-mount the branch-root onto the aufs-root internally
2387 +- grab the new vfsmount (ie. struct mount)
2388 +- lazy-umount the branch-root internally
2389 +- in open(2) the aufs-file, open the branch-file with the hidden
2390 + vfsmount (instead of the original branch's vfsmount)
2391 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2392 + but it may be possible from userspace by the mount helper.
2394 +Adding the internal hidden vfsmount and using it in opening a file, the
2395 +file path under /proc will be printed correctly. This approach looks
2396 +smarter, but is not possible I am afraid.
2397 +- aufs-root may be bind-mount later. when it happens, another hidden
2398 + vfsmount will be required.
2399 +- it is hard to get the chance to bind-mount and lazy-umount
2400 + + in kernel-space, FS can have vfsmount in open(2) via
2401 + file->f_path, and aufs can know its vfsmount. But several locks are
2402 + already acquired, and if aufs tries to bind-mount and lazy-umount
2403 + here, then it may cause a deadlock.
2404 + + in user-space, bind-mount doesn't invoke the mount helper.
2405 +- since /proc shows dev and ino, aufs has to give vma these info. it
2406 + means a new member vm_prinode will be necessary. this is essentially
2407 + equivalent to vm_prfile described above.
2409 +I have to give up this "looks-smater" approach.
2410 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2411 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2412 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2018-04-15 08:49:13.394483860 +0200
2415 +# Copyright (C) 2014-2018 Junjiro R. Okajima
2417 +# This program is free software; you can redistribute it and/or modify
2418 +# it under the terms of the GNU General Public License as published by
2419 +# the Free Software Foundation; either version 2 of the License, or
2420 +# (at your option) any later version.
2422 +# This program is distributed in the hope that it will be useful,
2423 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2424 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2425 +# GNU General Public License for more details.
2427 +# You should have received a copy of the GNU General Public License
2428 +# along with this program; if not, write to the Free Software
2429 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2432 +Listing XATTR/EA and getting the value
2433 +----------------------------------------------------------------------
2434 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2435 +shows the values from the topmost existing file. This behaviour is good
2436 +for the non-dir entries since the bahaviour exactly matches the shown
2437 +information. But for the directories, aufs considers all the same named
2438 +entries on the lower branches. Which means, if one of the lower entry
2439 +rejects readdir call, then aufs returns an error even if the topmost
2440 +entry allows it. This behaviour is necessary to respect the branch fs's
2441 +security, but can make users confused since the user-visible standard
2442 +attributes don't match the behaviour.
2443 +To address this issue, aufs has a mount option called dirperm1 which
2444 +checks the permission for the topmost entry only, and ignores the lower
2445 +entry's permission.
2447 +A similar issue can happen around XATTR.
2448 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2449 +always set. Otherwise these very unpleasant situation would happen.
2450 +- listxattr(2) may return the duplicated entries.
2451 +- users may not be able to remove or reset the XATTR forever,
2454 +XATTR/EA support in the internal (copy,move)-(up,down)
2455 +----------------------------------------------------------------------
2456 +Generally the extended attributes of inode are categorized as these.
2457 +- "security" for LSM and capability.
2458 +- "system" for posix ACL, 'acl' mount option is required for the branch
2460 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2461 +- "user" for userspace, 'user_xattr' mount option is required for the
2462 + branch fs generally.
2464 +Moreover there are some other categories. Aufs handles these rather
2465 +unpopular categories as the ordinary ones, ie. there is no special
2466 +condition nor exception.
2468 +In copy-up, the support for XATTR on the dst branch may differ from the
2469 +src branch. In this case, the copy-up operation will get an error and
2470 +the original user operation which triggered the copy-up will fail. It
2471 +can happen that even all copy-up will fail.
2472 +When both of src and dst branches support XATTR and if an error occurs
2473 +during copying XATTR, then the copy-up should fail obviously. That is a
2474 +good reason and aufs should return an error to userspace. But when only
2475 +the src branch support that XATTR, aufs should not return an error.
2476 +For example, the src branch supports ACL but the dst branch doesn't
2477 +because the dst branch may natively un-support it or temporary
2478 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2479 +may NOT return an error even if the XATTR is not supported. It is
2480 +totally up to the branch fs.
2482 +Anyway when the aufs internal copy-up gets an error from the dst branch
2483 +fs, then aufs tries removing the just copied entry and returns the error
2484 +to the userspace. The worst case of this situation will be all copy-up
2487 +For the copy-up operation, there two basic approaches.
2488 +- copy the specified XATTR only (by category above), and return the
2489 + error unconditionally if it happens.
2490 +- copy all XATTR, and ignore the error on the specified category only.
2492 +In order to support XATTR and to implement the correct behaviour, aufs
2493 +chooses the latter approach and introduces some new branch attributes,
2494 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2495 +They correspond to the XATTR namespaces (see above). Additionally, to be
2496 +convenient, "icex" is also provided which means all "icex*" attributes
2497 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2499 +The meaning of these attributes is to ignore the error from setting
2500 +XATTR on that branch.
2501 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2502 +error from the dst branch according to the specified attributes.
2504 +Some XATTR may have its default value. The default value may come from
2505 +the parent dir or the environment. If the default value is set at the
2506 +file creating-time, it will be overwritten by copy-up.
2507 +Some contradiction may happen I am afraid.
2508 +Do we need another attribute to stop copying XATTR? I am unsure. For
2509 +now, aufs implements the branch attributes to ignore the error.
2510 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2511 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2512 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2018-04-15 08:49:13.394483860 +0200
2515 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2517 +# This program is free software; you can redistribute it and/or modify
2518 +# it under the terms of the GNU General Public License as published by
2519 +# the Free Software Foundation; either version 2 of the License, or
2520 +# (at your option) any later version.
2522 +# This program is distributed in the hope that it will be useful,
2523 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2524 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2525 +# GNU General Public License for more details.
2527 +# You should have received a copy of the GNU General Public License
2528 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2530 +Export Aufs via NFS
2531 +----------------------------------------------------------------------
2532 +Here is an approach.
2533 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2535 +- iget_locked(): initialize aufs inode generation for a new inode, and
2536 + store it in xigen file.
2537 +- destroy_inode(): increment aufs inode generation and store it in xigen
2538 + file. it is necessary even if it is not unlinked, because any data of
2539 + inode may be changed by UDBA.
2540 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2541 + build file handle by
2542 + + branch id (4 bytes)
2543 + + superblock generation (4 bytes)
2544 + + inode number (4 or 8 bytes)
2545 + + parent dir inode number (4 or 8 bytes)
2546 + + inode generation (4 bytes))
2547 + + return value of exportfs_encode_fh() for the parent on a branch (4
2549 + + file handle for a branch (by exportfs_encode_fh())
2551 + + find the index of a branch from its id in handle, and check it is
2552 + still exist in aufs.
2553 + + 1st level: get the inode number from handle and search it in cache.
2554 + + 2nd level: if not found in cache, get the parent inode number from
2555 + the handle and search it in cache. and then open the found parent
2556 + dir, find the matching inode number by vfs_readdir() and get its
2557 + name, and call lookup_one_len() for the target dentry.
2558 + + 3rd level: if the parent dir is not cached, call
2559 + exportfs_decode_fh() for a branch and get the parent on a branch,
2560 + build a pathname of it, convert it a pathname in aufs, call
2561 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2563 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2564 + for every branch, but not itself. to get this, (currently) aufs
2565 + searches in current->nsproxy->mnt_ns list. it may not be a good
2566 + idea, but I didn't get other approach.
2567 + + test the generation of the gotten inode.
2568 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2569 + convert it into ESTALE for NFSD.
2570 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2571 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2572 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2573 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2574 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2018-04-15 08:49:13.394483860 +0200
2577 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2579 +# This program is free software; you can redistribute it and/or modify
2580 +# it under the terms of the GNU General Public License as published by
2581 +# the Free Software Foundation; either version 2 of the License, or
2582 +# (at your option) any later version.
2584 +# This program is distributed in the hope that it will be useful,
2585 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2586 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2587 +# GNU General Public License for more details.
2589 +# You should have received a copy of the GNU General Public License
2590 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2592 +Show Whiteout Mode (shwh)
2593 +----------------------------------------------------------------------
2594 +Generally aufs hides the name of whiteouts. But in some cases, to show
2595 +them is very useful for users. For instance, creating a new middle layer
2596 +(branch) by merging existing layers.
2598 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2599 +When you have three branches,
2600 +- Bottom: 'system', squashfs (underlying base system), read-only
2601 +- Middle: 'mods', squashfs, read-only
2602 +- Top: 'overlay', ram (tmpfs), read-write
2604 +The top layer is loaded at boot time and saved at shutdown, to preserve
2605 +the changes made to the system during the session.
2606 +When larger changes have been made, or smaller changes have accumulated,
2607 +the size of the saved top layer data grows. At this point, it would be
2608 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2609 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2610 +restoring save and load speed.
2612 +This merging is simplified by the use of another aufs mount, of just the
2613 +two overlay branches using the 'shwh' option.
2614 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2615 + aufs /livesys/merge_union
2617 +A merged view of these two branches is then available at
2618 +/livesys/merge_union, and the new feature is that the whiteouts are
2620 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2621 +writing to all branches. Also the default mode for all branches is 'ro'.
2622 +It is now possible to save the combined contents of the two overlay
2623 +branches to a new squashfs, e.g.:
2624 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2626 +This new squashfs archive can be stored on the boot device and the
2627 +initramfs will use it to replace the old one at the next boot.
2628 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2629 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2630 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2018-04-15 08:49:13.394483860 +0200
2633 +# Copyright (C) 2010-2018 Junjiro R. Okajima
2635 +# This program is free software; you can redistribute it and/or modify
2636 +# it under the terms of the GNU General Public License as published by
2637 +# the Free Software Foundation; either version 2 of the License, or
2638 +# (at your option) any later version.
2640 +# This program is distributed in the hope that it will be useful,
2641 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2642 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2643 +# GNU General Public License for more details.
2645 +# You should have received a copy of the GNU General Public License
2646 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2648 +Dynamically customizable FS operations
2649 +----------------------------------------------------------------------
2650 +Generally FS operations (struct inode_operations, struct
2651 +address_space_operations, struct file_operations, etc.) are defined as
2652 +"static const", but it never means that FS have only one set of
2653 +operation. Some FS have multiple sets of them. For instance, ext2 has
2654 +three sets, one for XIP, for NOBH, and for normal.
2655 +Since aufs overrides and redirects these operations, sometimes aufs has
2656 +to change its behaviour according to the branch FS type. More importantly
2657 +VFS acts differently if a function (member in the struct) is set or
2658 +not. It means aufs should have several sets of operations and select one
2659 +among them according to the branch FS definition.
2661 +In order to solve this problem and not to affect the behaviour of VFS,
2662 +aufs defines these operations dynamically. For instance, aufs defines
2663 +dummy direct_IO function for struct address_space_operations, but it may
2664 +not be set to the address_space_operations actually. When the branch FS
2665 +doesn't have it, aufs doesn't set it to its address_space_operations
2666 +while the function definition itself is still alive. So the behaviour
2667 +itself will not change, and it will return an error when direct_IO is
2670 +The lifetime of these dynamically generated operation object is
2671 +maintained by aufs branch object. When the branch is removed from aufs,
2672 +the reference counter of the object is decremented. When it reaches
2673 +zero, the dynamically generated operation object will be freed.
2675 +This approach is designed to support AIO (io_submit), Direct I/O and
2677 +Currently this approach is applied to address_space_operations for
2678 +regular files only.
2679 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2680 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2681 +++ linux/Documentation/filesystems/aufs/README 2018-06-15 11:15:15.400449109 +0200
2684 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2690 +----------------------------------------
2691 +In the early days, aufs was entirely re-designed and re-implemented
2692 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2693 +improvements and implementations, it becomes totally different from
2694 +Unionfs while keeping the basic features.
2695 +Recently, Unionfs Version 2.x series begin taking some of the same
2696 +approaches to aufs1's.
2697 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2698 +University and his team.
2700 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2701 +If you want older kernel version support, try aufs2-2.6.git or
2702 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2704 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2705 + According to Christoph Hellwig, linux rejects all union-type
2706 + filesystems but UnionMount.
2707 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2709 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2710 + UnionMount, and he pointed out an issue around a directory mutex
2711 + lock and aufs addressed it. But it is still unsure whether aufs will
2712 + be merged (or any other union solution).
2713 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2717 +----------------------------------------
2718 +- unite several directories into a single virtual filesystem. The member
2719 + directory is called as a branch.
2720 +- you can specify the permission flags to the branch, which are 'readonly',
2721 + 'readwrite' and 'whiteout-able.'
2722 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2723 + readonly branch are modifiable logically.
2724 +- dynamic branch manipulation, add, del.
2727 +Also there are many enhancements in aufs, such as:
2728 +- test only the highest one for the directory permission (dirperm1)
2729 +- copyup on open (coo=)
2730 +- 'move' policy for copy-up between two writable branches, after
2731 + checking free space.
2733 +- readdir(3) in userspace.
2734 +- keep inode number by external inode number table
2735 +- keep the timestamps of file/dir in internal copyup operation
2736 +- seekable directory, supporting NFS readdir.
2737 +- whiteout is hardlinked in order to reduce the consumption of inodes
2739 +- do not copyup, nor create a whiteout when it is unnecessary
2740 +- revert a single systemcall when an error occurs in aufs
2741 +- remount interface instead of ioctl
2742 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2743 +- loopback mounted filesystem as a branch
2744 +- kernel thread for removing the dir who has a plenty of whiteouts
2745 +- support copyup sparse file (a file which has a 'hole' in it)
2746 +- default permission flags for branches
2747 +- selectable permission flags for ro branch, whether whiteout can
2750 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2751 +- support multiple writable branches, some policies to select one
2752 + among multiple writable branches.
2753 +- a new semantics for link(2) and rename(2) to support multiple
2754 + writable branches.
2755 +- no glibc changes are required.
2756 +- pseudo hardlink (hardlink over branches)
2757 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2758 + including NFS or remote filesystem branch.
2759 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2762 +Currently these features are dropped temporary from aufs4.
2763 +See design/08plan.txt in detail.
2764 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2766 +- statistics of aufs thread (/sys/fs/aufs/stat)
2768 +Features or just an idea in the future (see also design/*.txt),
2769 +- reorder the branch index without del/re-add.
2770 +- permanent xino files for NFSD
2771 +- an option for refreshing the opened files after add/del branches
2772 +- light version, without branch manipulation. (unnecessary?)
2773 +- copyup in userspace
2774 +- inotify in userspace
2779 +----------------------------------------
2780 +There are three GIT trees for aufs4, aufs4-linux.git,
2781 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2783 +While the aufs-util is always necessary, you need either of aufs4-linux
2784 +or aufs4-standalone.
2786 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2787 +git://git.kernel.org/.../torvalds/linux.git.
2788 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2789 +build aufs4 as an external kernel module.
2790 +Several extra patches are not included in this tree. Only
2791 +aufs4-standalone tree contains them. They are described in the later
2792 +section "Configuration and Compilation."
2794 +On the other hand, the aufs4-standalone tree has only aufs source files
2795 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2796 +But you need to apply all aufs patches manually.
2798 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2799 +represents the linux kernel version, "linux-4.x". For instance,
2800 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2801 +"aufs4.x-rcN" branch.
2804 +$ git clone --reference /your/linux/git/tree \
2805 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2806 +- if you don't have linux GIT tree, then remove "--reference ..."
2807 +$ cd aufs4-linux.git
2808 +$ git checkout origin/aufs4.0
2810 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2811 +leave the patch-work to GIT.
2812 +$ cd /your/linux/git/tree
2813 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2815 +$ git checkout -b my4.0 v4.0
2816 +$ (add your local change...)
2817 +$ git pull aufs4 aufs4.0
2818 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2819 +- you may need to solve some conflicts between your_changes and
2820 + aufs4.0. in this case, git-rerere is recommended so that you can
2821 + solve the similar conflicts automatically when you upgrade to 4.1 or
2822 + later in the future.
2824 +o aufs4-standalone tree
2825 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2826 +$ cd aufs4-standalone.git
2827 +$ git checkout origin/aufs4.0
2830 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2831 +- note that the public aufs-util.git is on SourceForge instead of
2834 +$ git checkout origin/aufs4.0
2836 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2837 +The minor version number, 'x' in '4.x', of aufs may not always
2838 +follow the minor version number of the kernel.
2839 +Because changes in the kernel that cause the use of a new
2840 +minor version number do not always require changes to aufs-util.
2842 +Since aufs-util has its own minor version number, you may not be
2843 +able to find a GIT branch in aufs-util for your kernel's
2844 +exact minor version number.
2845 +In this case, you should git-checkout the branch for the
2846 +nearest lower number.
2848 +For (an unreleased) example:
2849 +If you are using "linux-4.10" and the "aufs4.10" branch
2850 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2851 +or something numerically smaller is the branch for your kernel.
2853 +Also you can view all branches by
2857 +3. Configuration and Compilation
2858 +----------------------------------------
2859 +Make sure you have git-checkout'ed the correct branch.
2861 +For aufs4-linux tree,
2862 +- enable CONFIG_AUFS_FS.
2863 +- set other aufs configurations if necessary.
2865 +For aufs4-standalone tree,
2866 +There are several ways to build.
2869 +- apply ./aufs4-kbuild.patch to your kernel source files.
2870 +- apply ./aufs4-base.patch too.
2871 +- apply ./aufs4-mmap.patch too.
2872 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2873 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2874 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2875 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2876 +- enable CONFIG_AUFS_FS, you can select either
2878 +- and build your kernel as usual.
2879 +- install the built kernel.
2880 + Note: Since linux-3.9, every filesystem module requires an alias
2881 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2882 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2883 +- install the header files too by "make headers_install" to the
2884 + directory where you specify. By default, it is $PWD/usr.
2885 + "make help" shows a brief note for headers_install.
2886 +- and reboot your system.
2889 +- module only (CONFIG_AUFS_FS=m).
2890 +- apply ./aufs4-base.patch to your kernel source files.
2891 +- apply ./aufs4-mmap.patch too.
2892 +- apply ./aufs4-standalone.patch too.
2893 +- build your kernel, don't forget "make headers_install", and reboot.
2894 +- edit ./config.mk and set other aufs configurations if necessary.
2895 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2896 + every aufs configurations.
2897 +- build the module by simple "make".
2898 + Note: Since linux-3.9, every filesystem module requires an alias
2899 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2900 + modules.aliases file.
2901 +- you can specify ${KDIR} make variable which points to your kernel
2903 +- install the files
2904 + + run "make install" to install the aufs module, or copy the built
2905 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2906 + + run "make install_headers" (instead of headers_install) to install
2907 + the modified aufs header file (you can specify DESTDIR which is
2908 + available in aufs standalone version's Makefile only), or copy
2909 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2910 + you like manually. By default, the target directory is $PWD/usr.
2911 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2912 + kernel source tree.
2914 +Note: The header file aufs_type.h is necessary to build aufs-util
2915 + as well as "make headers_install" in the kernel source tree.
2916 + headers_install is subject to be forgotten, but it is essentially
2917 + necessary, not only for building aufs-util.
2918 + You may not meet problems without headers_install in some older
2922 +- read README in aufs-util, build and install it
2923 +- note that your distribution may contain an obsoleted version of
2924 + aufs_type.h in /usr/include/linux or something. When you build aufs
2925 + utilities, make sure that your compiler refers the correct aufs header
2926 + file which is built by "make headers_install."
2927 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2928 + then run "make install_ulib" too. And refer to the aufs manual in
2931 +There several other patches in aufs4-standalone.git. They are all
2932 +optional. When you meet some problems, they will help you.
2933 +- aufs4-loopback.patch
2934 + Supports a nested loopback mount in a branch-fs. This patch is
2935 + unnecessary until aufs produces a message like "you may want to try
2936 + another patch for loopback file".
2938 + Modifies a system global kernel internal function get_next_ino() in
2939 + order to stop assigning 0 for an inode-number. Not directly related to
2940 + aufs, but recommended generally.
2942 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2943 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2944 + duplication of inode number, which is important for backup tools and
2945 + other utilities. When you find aufs XINO files for tmpfs branch
2946 + growing too much, try this patch.
2947 +- lockdep-debug.patch
2948 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2949 + also a caller of VFS functions for branch filesystems, subclassing of
2950 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2951 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2952 + need to apply this debug patch to expand several constant values.
2953 + If don't know what LOCKDEP, then you don't have apply this patch.
2957 +----------------------------------------
2958 +At first, make sure aufs-util are installed, and please read the aufs
2959 +manual, aufs.5 in aufs-util.git tree.
2963 +$ mkdir /tmp/rw /tmp/aufs
2964 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2966 +Here is another example. The result is equivalent.
2967 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2969 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2970 +# mount -o remount,append:${HOME} /tmp/aufs
2972 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2973 +you modify a file under /tmp/aufs, the one on your home directory is
2974 +not affected, instead the same named file will be newly created under
2975 +/tmp/rw. And all of your modification to a file will be applied to
2976 +the one under /tmp/rw. This is called the file based Copy on Write
2978 +Aufs mount options are described in aufs.5.
2979 +If you run chroot or something and make your aufs as a root directory,
2980 +then you need to customize the shutdown script. See the aufs manual in
2983 +Additionally, there are some sample usages of aufs which are a
2984 +diskless system with network booting, and LiveCD over NFS.
2985 +See sample dir in CVS tree on SourceForge.
2989 +----------------------------------------
2990 +When you have any problems or strange behaviour in aufs, please let me
2992 +- /proc/mounts (instead of the output of mount(8))
2993 +- /sys/module/aufs/*
2994 +- /sys/fs/aufs/* (if you have them)
2995 +- /debug/aufs/* (if you have them)
2996 +- linux kernel version
2997 + if your kernel is not plain, for example modified by distributor,
2998 + the url where i can download its source is necessary too.
2999 +- aufs version which was printed at loading the module or booting the
3000 + system, instead of the date you downloaded.
3001 +- configuration (define/undefine CONFIG_AUFS_xxx)
3002 +- kernel configuration or /proc/config.gz (if you have it)
3003 +- behaviour which you think to be incorrect
3004 +- actual operation, reproducible one is better
3005 +- mailto: aufs-users at lists.sourceforge.net
3007 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
3008 +and Feature Requests) on SourceForge. Please join and write to
3012 +6. Acknowledgements
3013 +----------------------------------------
3014 +Thanks to everyone who have tried and are using aufs, whoever
3015 +have reported a bug or any feedback.
3017 +Especially donators:
3018 +Tomas Matejicek(slax.org) made a donation (much more than once).
3019 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
3020 + scripts) is making "doubling" donations.
3021 + Unfortunately I cannot list all of the donators, but I really
3023 + It ends Aug 2010, but the ordinary donation URL is still available.
3024 + <http://sourceforge.net/donate/index.php?group_id=167503>
3025 +Dai Itasaka made a donation (2007/8).
3026 +Chuck Smith made a donation (2008/4, 10 and 12).
3027 +Henk Schoneveld made a donation (2008/9).
3028 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
3029 +Francois Dupoux made a donation (2008/11).
3030 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
3031 + aufs2 GIT tree (2009/2).
3032 +William Grant made a donation (2009/3).
3033 +Patrick Lane made a donation (2009/4).
3034 +The Mail Archive (mail-archive.com) made donations (2009/5).
3035 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
3036 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
3037 +Pavel Pronskiy made a donation (2011/2).
3038 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
3039 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
3040 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
3042 +Sam Liddicott made a donation (2011/9).
3043 +Era Scarecrow made a donation (2013/4).
3044 +Bor Ratajc made a donation (2013/4).
3045 +Alessandro Gorreta made a donation (2013/4).
3046 +POIRETTE Marc made a donation (2013/4).
3047 +Alessandro Gorreta made a donation (2013/4).
3048 +lauri kasvandik made a donation (2013/5).
3049 +"pemasu from Finland" made a donation (2013/7).
3050 +The Parted Magic Project made a donation (2013/9 and 11).
3051 +Pavel Barta made a donation (2013/10).
3052 +Nikolay Pertsev made a donation (2014/5).
3053 +James B made a donation (2014/7 and 2015/7).
3054 +Stefano Di Biase made a donation (2014/8).
3055 +Daniel Epellei made a donation (2015/1).
3056 +OmegaPhil made a donation (2016/1, 2018/4).
3057 +Tomasz Szewczyk made a donation (2016/4).
3058 +James Burry made a donation (2016/12).
3060 +Thank you very much.
3061 +Donations are always, including future donations, very important and
3062 +helpful for me to keep on developing aufs.
3066 +----------------------------------------
3067 +If you are an experienced user, no explanation is needed. Aufs is
3068 +just a linux filesystem.
3073 +# Local variables: ;
3076 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3077 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3078 +++ linux/fs/aufs/aufs.h 2018-04-15 08:49:13.394483860 +0200
3081 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3083 + * This program, aufs is free software; you can redistribute it and/or modify
3084 + * it under the terms of the GNU General Public License as published by
3085 + * the Free Software Foundation; either version 2 of the License, or
3086 + * (at your option) any later version.
3088 + * This program is distributed in the hope that it will be useful,
3089 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3090 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3091 + * GNU General Public License for more details.
3093 + * You should have received a copy of the GNU General Public License
3094 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3098 + * all header files
3106 +#define AuStub(type, name, body, ...) \
3107 + static inline type name(__VA_ARGS__) { body; }
3109 +#define AuStubVoid(name, ...) \
3110 + AuStub(void, name, , __VA_ARGS__)
3111 +#define AuStubInt0(name, ...) \
3112 + AuStub(int, name, return 0, __VA_ARGS__)
3116 +#include "branch.h"
3119 +#include "dbgaufs.h"
3120 +#include "dentry.h"
3122 +#include "dirren.h"
3125 +#include "fstype.h"
3129 +#include "module.h"
3133 +#include "sysaufs.h"
3138 +#endif /* __KERNEL__ */
3139 +#endif /* __AUFS_H__ */
3140 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3141 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3142 +++ linux/fs/aufs/branch.c 2018-04-15 08:49:13.394483860 +0200
3145 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3147 + * This program, aufs is free software; you can redistribute it and/or modify
3148 + * it under the terms of the GNU General Public License as published by
3149 + * the Free Software Foundation; either version 2 of the License, or
3150 + * (at your option) any later version.
3152 + * This program is distributed in the hope that it will be useful,
3153 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3154 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3155 + * GNU General Public License for more details.
3157 + * You should have received a copy of the GNU General Public License
3158 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3162 + * branch management
3165 +#include <linux/compat.h>
3166 +#include <linux/statfs.h>
3170 + * free a single branch
3172 +static void au_br_do_free(struct au_branch *br)
3175 + struct au_wbr *wbr;
3176 + struct au_dykey **key;
3178 + au_hnotify_fin_br(br);
3179 + /* always, regardless the mount option */
3180 + au_dr_hino_free(&br->br_dirren);
3182 + if (br->br_xino.xi_file)
3183 + fput(br->br_xino.xi_file);
3184 + for (i = br->br_xino.xi_nondir.total - 1; i >= 0; i--)
3185 + AuDebugOn(br->br_xino.xi_nondir.array[i]);
3186 + kfree(br->br_xino.xi_nondir.array);
3188 + AuDebugOn(au_br_count(br));
3189 + au_br_count_fin(br);
3193 + for (i = 0; i < AuBrWh_Last; i++)
3194 + dput(wbr->wbr_wh[i]);
3195 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3196 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3199 + if (br->br_fhsm) {
3200 + au_br_fhsm_fin(br->br_fhsm);
3201 + kfree(br->br_fhsm);
3204 + key = br->br_dykey;
3205 + for (i = 0; i < AuBrDynOp; i++, key++)
3211 + /* recursive lock, s_umount of branch's */
3213 + path_put(&br->br_path);
3220 + * frees all branches
3222 +void au_br_free(struct au_sbinfo *sbinfo)
3224 + aufs_bindex_t bmax;
3225 + struct au_branch **br;
3227 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3229 + bmax = sbinfo->si_bbot + 1;
3230 + br = sbinfo->si_branch;
3232 + au_br_do_free(*br++);
3236 + * find the index of a branch which is specified by @br_id.
3238 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3240 + aufs_bindex_t bindex, bbot;
3242 + bbot = au_sbbot(sb);
3243 + for (bindex = 0; bindex <= bbot; bindex++)
3244 + if (au_sbr_id(sb, bindex) == br_id)
3249 +/* ---------------------------------------------------------------------- */
3255 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3256 + struct dentry *h_root)
3258 + if (unlikely(h_adding == h_root
3259 + || au_test_loopback_overlap(sb, h_adding)))
3261 + if (h_adding->d_sb != h_root->d_sb)
3263 + return au_test_subdir(h_adding, h_root)
3264 + || au_test_subdir(h_root, h_adding);
3268 + * returns a newly allocated branch. @new_nbranch is a number of branches
3269 + * after adding a branch.
3271 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3274 + struct au_branch *add_branch;
3275 + struct dentry *root;
3276 + struct inode *inode;
3280 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3281 + if (unlikely(!add_branch))
3283 + add_branch->br_xino.xi_nondir.total = 8; /* initial size */
3284 + add_branch->br_xino.xi_nondir.array
3285 + = kcalloc(add_branch->br_xino.xi_nondir.total, sizeof(ino_t),
3287 + if (unlikely(!add_branch->br_xino.xi_nondir.array))
3290 + err = au_hnotify_init_br(add_branch, perm);
3291 + if (unlikely(err))
3292 + goto out_xinondir;
3294 + if (au_br_writable(perm)) {
3295 + /* may be freed separately at changing the branch permission */
3296 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3298 + if (unlikely(!add_branch->br_wbr))
3302 + if (au_br_fhsm(perm)) {
3303 + err = au_fhsm_br_alloc(add_branch);
3304 + if (unlikely(err))
3308 + root = sb->s_root;
3309 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3311 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3313 + inode = d_inode(root);
3314 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3318 + return add_branch; /* success */
3321 + kfree(add_branch->br_wbr);
3323 + au_hnotify_fin_br(add_branch);
3325 + kfree(add_branch->br_xino.xi_nondir.array);
3327 + kfree(add_branch);
3329 + return ERR_PTR(err);
3333 + * test if the branch permission is legal or not.
3335 +static int test_br(struct inode *inode, int brperm, char *path)
3339 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3344 + pr_err("write permission for readonly mount or inode, %s\n", path);
3352 + * 0: success, the caller will add it
3353 + * plus: success, it is already unified, the caller should ignore it
3356 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3359 + aufs_bindex_t bbot, bindex;
3360 + struct dentry *root, *h_dentry;
3361 + struct inode *inode, *h_inode;
3363 + root = sb->s_root;
3364 + bbot = au_sbbot(sb);
3365 + if (unlikely(bbot >= 0
3366 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3370 + pr_err("%s duplicated\n", add->pathname);
3375 + err = -ENOSPC; /* -E2BIG; */
3376 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3377 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3378 + pr_err("number of branches exceeded %s\n", add->pathname);
3383 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3384 + pr_err("bad index %d\n", add->bindex);
3388 + inode = d_inode(add->path.dentry);
3390 + if (unlikely(!inode->i_nlink)) {
3391 + pr_err("no existence %s\n", add->pathname);
3396 + if (unlikely(inode->i_sb == sb)) {
3397 + pr_err("%s must be outside\n", add->pathname);
3401 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3402 + pr_err("unsupported filesystem, %s (%s)\n",
3403 + add->pathname, au_sbtype(inode->i_sb));
3407 + if (unlikely(inode->i_sb->s_stack_depth)) {
3408 + pr_err("already stacked, %s (%s)\n",
3409 + add->pathname, au_sbtype(inode->i_sb));
3413 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3414 + if (unlikely(err))
3418 + return 0; /* success */
3421 + for (bindex = 0; bindex <= bbot; bindex++)
3422 + if (unlikely(test_overlap(sb, add->path.dentry,
3423 + au_h_dptr(root, bindex)))) {
3424 + pr_err("%s is overlapped\n", add->pathname);
3429 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3430 + h_dentry = au_h_dptr(root, 0);
3431 + h_inode = d_inode(h_dentry);
3432 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3433 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3434 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3435 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3437 + i_uid_read(inode), i_gid_read(inode),
3438 + (inode->i_mode & S_IALLUGO),
3439 + i_uid_read(h_inode), i_gid_read(h_inode),
3440 + (h_inode->i_mode & S_IALLUGO));
3448 + * initialize or clean the whiteouts for an adding branch
3450 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3453 + int err, old_perm;
3454 + aufs_bindex_t bindex;
3455 + struct inode *h_inode;
3456 + struct au_wbr *wbr;
3457 + struct au_hinode *hdir;
3458 + struct dentry *h_dentry;
3460 + err = vfsub_mnt_want_write(au_br_mnt(br));
3461 + if (unlikely(err))
3465 + old_perm = br->br_perm;
3466 + br->br_perm = new_perm;
3469 + bindex = au_br_index(sb, br->br_id);
3470 + if (0 <= bindex) {
3471 + hdir = au_hi(d_inode(sb->s_root), bindex);
3472 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3474 + h_dentry = au_br_dentry(br);
3475 + h_inode = d_inode(h_dentry);
3476 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3479 + err = au_wh_init(br, sb);
3481 + wbr_wh_write_lock(wbr);
3482 + err = au_wh_init(br, sb);
3483 + wbr_wh_write_unlock(wbr);
3486 + au_hn_inode_unlock(hdir);
3488 + inode_unlock(h_inode);
3489 + vfsub_mnt_drop_write(au_br_mnt(br));
3490 + br->br_perm = old_perm;
3492 + if (!err && wbr && !au_br_writable(new_perm)) {
3494 + br->br_wbr = NULL;
3501 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3505 + struct kstatfs kst;
3506 + struct au_wbr *wbr;
3509 + au_rw_init(&wbr->wbr_wh_rwsem);
3510 + atomic_set(&wbr->wbr_wh_running, 0);
3513 + * a limit for rmdir/rename a dir
3514 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3516 + err = vfs_statfs(&br->br_path, &kst);
3517 + if (unlikely(err))
3520 + if (kst.f_namelen >= NAME_MAX)
3521 + err = au_br_init_wh(sb, br, perm);
3523 + pr_err("%pd(%s), unsupported namelen %ld\n",
3525 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3531 +/* initialize a new branch */
3532 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3533 + struct au_opt_add *add)
3536 + struct inode *h_inode;
3539 + spin_lock_init(&br->br_xino.xi_nondir.spin);
3540 + init_waitqueue_head(&br->br_xino.xi_nondir.wqh);
3541 + br->br_perm = add->perm;
3542 + br->br_path = add->path; /* set first, path_get() later */
3543 + spin_lock_init(&br->br_dykey_lock);
3544 + au_br_count_init(br);
3545 + atomic_set(&br->br_xino_running, 0);
3546 + br->br_id = au_new_br_id(sb);
3547 + AuDebugOn(br->br_id < 0);
3549 + /* always, regardless the given option */
3550 + err = au_dr_br_init(sb, br, &add->path);
3551 + if (unlikely(err))
3554 + if (au_br_writable(add->perm)) {
3555 + err = au_wbr_init(br, sb, add->perm);
3556 + if (unlikely(err))
3560 + if (au_opt_test(au_mntflags(sb), XINO)) {
3561 + h_inode = d_inode(add->path.dentry);
3562 + err = au_xino_br(sb, br, h_inode->i_ino,
3563 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3564 + if (unlikely(err)) {
3565 + AuDebugOn(br->br_xino.xi_file);
3570 + sysaufs_br_init(br);
3571 + path_get(&br->br_path);
3572 + goto out; /* success */
3575 + memset(&br->br_path, 0, sizeof(br->br_path));
3580 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3581 + struct au_branch *br, aufs_bindex_t bbot,
3582 + aufs_bindex_t amount)
3584 + struct au_branch **brp;
3586 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3588 + brp = sbinfo->si_branch + bindex;
3589 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3591 + sbinfo->si_bbot++;
3592 + if (unlikely(bbot < 0))
3593 + sbinfo->si_bbot = 0;
3596 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3597 + aufs_bindex_t bbot, aufs_bindex_t amount)
3599 + struct au_hdentry *hdp;
3601 + AuRwMustWriteLock(&dinfo->di_rwsem);
3603 + hdp = au_hdentry(dinfo, bindex);
3604 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3605 + au_h_dentry_init(hdp);
3607 + if (unlikely(bbot < 0))
3608 + dinfo->di_btop = 0;
3611 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3612 + aufs_bindex_t bbot, aufs_bindex_t amount)
3614 + struct au_hinode *hip;
3616 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3618 + hip = au_hinode(iinfo, bindex);
3619 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3620 + au_hinode_init(hip);
3622 + if (unlikely(bbot < 0))
3623 + iinfo->ii_btop = 0;
3626 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3627 + aufs_bindex_t bindex)
3629 + struct dentry *root, *h_dentry;
3630 + struct inode *root_inode, *h_inode;
3631 + aufs_bindex_t bbot, amount;
3633 + root = sb->s_root;
3634 + root_inode = d_inode(root);
3635 + bbot = au_sbbot(sb);
3636 + amount = bbot + 1 - bindex;
3637 + h_dentry = au_br_dentry(br);
3638 + au_sbilist_lock();
3639 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3640 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3641 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3642 + au_set_h_dptr(root, bindex, dget(h_dentry));
3643 + h_inode = d_inode(h_dentry);
3644 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3645 + au_sbilist_unlock();
3648 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3651 + aufs_bindex_t bbot, add_bindex;
3652 + struct dentry *root, *h_dentry;
3653 + struct inode *root_inode;
3654 + struct au_branch *add_branch;
3656 + root = sb->s_root;
3657 + root_inode = d_inode(root);
3658 + IMustLock(root_inode);
3659 + IiMustWriteLock(root_inode);
3660 + err = test_add(sb, add, remount);
3661 + if (unlikely(err < 0))
3665 + goto out; /* success */
3668 + bbot = au_sbbot(sb);
3669 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3670 + err = PTR_ERR(add_branch);
3671 + if (IS_ERR(add_branch))
3674 + err = au_br_init(add_branch, sb, add);
3675 + if (unlikely(err)) {
3676 + au_br_do_free(add_branch);
3680 + add_bindex = add->bindex;
3682 + au_br_do_add(sb, add_branch, add_bindex);
3684 + sysaufs_brs_del(sb, add_bindex);
3685 + au_br_do_add(sb, add_branch, add_bindex);
3686 + sysaufs_brs_add(sb, add_bindex);
3689 + h_dentry = add->path.dentry;
3690 + if (!add_bindex) {
3691 + au_cpup_attr_all(root_inode, /*force*/1);
3692 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3694 + au_add_nlink(root_inode, d_inode(h_dentry));
3697 + * this test/set prevents aufs from handling unnecesary notify events
3698 + * of xino files, in case of re-adding a writable branch which was
3699 + * once detached from aufs.
3701 + if (au_xino_brid(sb) < 0
3702 + && au_br_writable(add_branch->br_perm)
3703 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3704 + && add_branch->br_xino.xi_file
3705 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3706 + au_xino_brid_set(sb, add_branch->br_id);
3712 +/* ---------------------------------------------------------------------- */
3714 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3715 + unsigned long long max __maybe_unused,
3718 + unsigned long long n;
3719 + struct file **p, *f;
3720 + struct hlist_bl_head *files;
3721 + struct hlist_bl_node *pos;
3722 + struct au_finfo *finfo;
3726 + files = &au_sbi(sb)->si_files;
3727 + hlist_bl_lock(files);
3728 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3729 + f = finfo->fi_file;
3731 + && !special_file(file_inode(f)->i_mode)) {
3735 + AuDebugOn(n > max);
3738 + hlist_bl_unlock(files);
3743 +static struct file **au_farray_alloc(struct super_block *sb,
3744 + unsigned long long *max)
3746 + *max = au_nfiles(sb);
3747 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3750 +static void au_farray_free(struct file **a, unsigned long long max)
3752 + unsigned long long ull;
3754 + for (ull = 0; ull < max; ull++)
3760 +/* ---------------------------------------------------------------------- */
3766 +/* to show the line number, do not make it inlined function */
3767 +#define AuVerbose(do_info, fmt, ...) do { \
3769 + pr_info(fmt, ##__VA_ARGS__); \
3772 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3773 + aufs_bindex_t bbot)
3775 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3778 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3779 + aufs_bindex_t bbot)
3781 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3785 + * test if the branch is deletable or not.
3787 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3788 + unsigned int sigen, const unsigned int verbose)
3790 + int err, i, j, ndentry;
3791 + aufs_bindex_t btop, bbot;
3792 + struct au_dcsub_pages dpages;
3793 + struct au_dpage *dpage;
3796 + err = au_dpages_init(&dpages, GFP_NOFS);
3797 + if (unlikely(err))
3799 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3800 + if (unlikely(err))
3803 + for (i = 0; !err && i < dpages.ndpage; i++) {
3804 + dpage = dpages.dpages + i;
3805 + ndentry = dpage->ndentry;
3806 + for (j = 0; !err && j < ndentry; j++) {
3807 + d = dpage->dentries[j];
3808 + AuDebugOn(au_dcount(d) <= 0);
3809 + if (!au_digen_test(d, sigen)) {
3810 + di_read_lock_child(d, AuLock_IR);
3811 + if (unlikely(au_dbrange_test(d))) {
3812 + di_read_unlock(d, AuLock_IR);
3816 + di_write_lock_child(d);
3817 + if (unlikely(au_dbrange_test(d))) {
3818 + di_write_unlock(d);
3821 + err = au_reval_dpath(d, sigen);
3823 + di_downgrade_lock(d, AuLock_IR);
3825 + di_write_unlock(d);
3830 + /* AuDbgDentry(d); */
3831 + btop = au_dbtop(d);
3832 + bbot = au_dbbot(d);
3833 + if (btop <= bindex
3835 + && au_h_dptr(d, bindex)
3836 + && au_test_dbusy(d, btop, bbot)) {
3838 + AuVerbose(verbose, "busy %pd\n", d);
3841 + di_read_unlock(d, AuLock_IR);
3846 + au_dpages_free(&dpages);
3851 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3852 + unsigned int sigen, const unsigned int verbose)
3855 + unsigned long long max, ull;
3856 + struct inode *i, **array;
3857 + aufs_bindex_t btop, bbot;
3859 + array = au_iarray_alloc(sb, &max);
3860 + err = PTR_ERR(array);
3861 + if (IS_ERR(array))
3865 + AuDbg("b%d\n", bindex);
3866 + for (ull = 0; !err && ull < max; ull++) {
3870 + if (i->i_ino == AUFS_ROOT_INO)
3873 + /* AuDbgInode(i); */
3874 + if (au_iigen(i, NULL) == sigen)
3875 + ii_read_lock_child(i);
3877 + ii_write_lock_child(i);
3878 + err = au_refresh_hinode_self(i);
3881 + ii_downgrade_lock(i);
3883 + ii_write_unlock(i);
3888 + btop = au_ibtop(i);
3889 + bbot = au_ibbot(i);
3890 + if (btop <= bindex
3892 + && au_h_iptr(i, bindex)
3893 + && au_test_ibusy(i, btop, bbot)) {
3895 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3898 + ii_read_unlock(i);
3900 + au_iarray_free(array, max);
3906 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3907 + const unsigned int verbose)
3910 + unsigned int sigen;
3912 + sigen = au_sigen(root->d_sb);
3913 + DiMustNoWaiters(root);
3914 + IiMustNoWaiters(d_inode(root));
3915 + di_write_unlock(root);
3916 + err = test_dentry_busy(root, bindex, sigen, verbose);
3918 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3919 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3924 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3925 + struct file **to_free, int *idx)
3928 + unsigned char matched, root;
3929 + aufs_bindex_t bindex, bbot;
3930 + struct au_fidir *fidir;
3931 + struct au_hfile *hfile;
3934 + root = IS_ROOT(file->f_path.dentry);
3937 + to_free[*idx] = file;
3943 + fidir = au_fi(file)->fi_hdir;
3944 + AuDebugOn(!fidir);
3945 + bbot = au_fbbot_dir(file);
3946 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3947 + hfile = fidir->fd_hfile + bindex;
3948 + if (!hfile->hf_file)
3951 + if (hfile->hf_br->br_id == br_id) {
3963 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3964 + struct file **to_free, int opened)
3967 + unsigned long long ull, max;
3968 + aufs_bindex_t btop;
3969 + struct file *file, **array;
3970 + struct dentry *root;
3971 + struct au_hfile *hfile;
3973 + array = au_farray_alloc(sb, &max);
3974 + err = PTR_ERR(array);
3975 + if (IS_ERR(array))
3980 + root = sb->s_root;
3981 + di_write_unlock(root);
3982 + for (ull = 0; ull < max; ull++) {
3983 + file = array[ull];
3984 + if (unlikely(!file))
3987 + /* AuDbg("%pD\n", file); */
3988 + fi_read_lock(file);
3989 + btop = au_fbtop(file);
3990 + if (!d_is_dir(file->f_path.dentry)) {
3991 + hfile = &au_fi(file)->fi_htop;
3992 + if (hfile->hf_br->br_id == br_id)
3995 + err = test_dir_busy(file, br_id, to_free, &idx);
3996 + fi_read_unlock(file);
3997 + if (unlikely(err))
4000 + di_write_lock_child(root);
4001 + au_farray_free(array, max);
4002 + AuDebugOn(idx > opened);
4008 +static void br_del_file(struct file **to_free, unsigned long long opened,
4009 + aufs_bindex_t br_id)
4011 + unsigned long long ull;
4012 + aufs_bindex_t bindex, btop, bbot, bfound;
4013 + struct file *file;
4014 + struct au_fidir *fidir;
4015 + struct au_hfile *hfile;
4017 + for (ull = 0; ull < opened; ull++) {
4018 + file = to_free[ull];
4019 + if (unlikely(!file))
4022 + /* AuDbg("%pD\n", file); */
4023 + AuDebugOn(!d_is_dir(file->f_path.dentry));
4025 + fidir = au_fi(file)->fi_hdir;
4026 + AuDebugOn(!fidir);
4027 + fi_write_lock(file);
4028 + btop = au_fbtop(file);
4029 + bbot = au_fbbot_dir(file);
4030 + for (bindex = btop; bindex <= bbot; bindex++) {
4031 + hfile = fidir->fd_hfile + bindex;
4032 + if (!hfile->hf_file)
4035 + if (hfile->hf_br->br_id == br_id) {
4040 + AuDebugOn(bfound < 0);
4041 + au_set_h_fptr(file, bfound, NULL);
4042 + if (bfound == btop) {
4043 + for (btop++; btop <= bbot; btop++)
4044 + if (au_hf_dir(file, btop)) {
4045 + au_set_fbtop(file, btop);
4049 + fi_write_unlock(file);
4053 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4054 + const aufs_bindex_t bindex,
4055 + const aufs_bindex_t bbot)
4057 + struct au_branch **brp, **p;
4059 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4061 + brp = sbinfo->si_branch + bindex;
4062 + if (bindex < bbot)
4063 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4064 + sbinfo->si_branch[0 + bbot] = NULL;
4065 + sbinfo->si_bbot--;
4067 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4070 + sbinfo->si_branch = p;
4071 + /* harmless error */
4074 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4075 + const aufs_bindex_t bbot)
4077 + struct au_hdentry *hdp, *p;
4079 + AuRwMustWriteLock(&dinfo->di_rwsem);
4081 + hdp = au_hdentry(dinfo, bindex);
4082 + if (bindex < bbot)
4083 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4084 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4087 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4090 + dinfo->di_hdentry = p;
4091 + /* harmless error */
4094 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4095 + const aufs_bindex_t bbot)
4097 + struct au_hinode *hip, *p;
4099 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4101 + hip = au_hinode(iinfo, bindex);
4102 + if (bindex < bbot)
4103 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4104 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4107 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4110 + iinfo->ii_hinode = p;
4111 + /* harmless error */
4114 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4115 + struct au_branch *br)
4117 + aufs_bindex_t bbot;
4118 + struct au_sbinfo *sbinfo;
4119 + struct dentry *root, *h_root;
4120 + struct inode *inode, *h_inode;
4121 + struct au_hinode *hinode;
4123 + SiMustWriteLock(sb);
4125 + root = sb->s_root;
4126 + inode = d_inode(root);
4127 + sbinfo = au_sbi(sb);
4128 + bbot = sbinfo->si_bbot;
4130 + h_root = au_h_dptr(root, bindex);
4131 + hinode = au_hi(inode, bindex);
4132 + h_inode = au_igrab(hinode->hi_inode);
4135 + au_sbilist_lock();
4136 + au_br_do_del_brp(sbinfo, bindex, bbot);
4137 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4138 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4139 + au_sbilist_unlock();
4141 + /* ignore an error */
4142 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4146 + au_br_do_free(br);
4149 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4150 + unsigned long long max, void *arg)
4155 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4158 + unsigned long long opened;
4159 + unsigned int mnt_flags;
4160 + aufs_bindex_t bindex, bbot, br_id;
4161 + unsigned char do_wh, verbose;
4162 + struct au_branch *br;
4163 + struct au_wbr *wbr;
4164 + struct dentry *root;
4165 + struct file **to_free;
4170 + root = sb->s_root;
4171 + bindex = au_find_dbindex(root, del->h_path.dentry);
4174 + goto out; /* success */
4176 + pr_err("%s no such branch\n", del->pathname);
4179 + AuDbg("bindex b%d\n", bindex);
4182 + mnt_flags = au_mntflags(sb);
4183 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4184 + bbot = au_sbbot(sb);
4185 + if (unlikely(!bbot)) {
4186 + AuVerbose(verbose, "no more branches left\n");
4189 + br = au_sbr(sb, bindex);
4190 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4192 + br_id = br->br_id;
4193 + opened = au_br_count(br);
4194 + if (unlikely(opened)) {
4195 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4196 + err = PTR_ERR(to_free);
4197 + if (IS_ERR(to_free))
4200 + err = test_file_busy(sb, br_id, to_free, opened);
4201 + if (unlikely(err)) {
4202 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4208 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4210 + /* instead of WbrWhMustWriteLock(wbr) */
4211 + SiMustWriteLock(sb);
4212 + for (i = 0; i < AuBrWh_Last; i++) {
4213 + dput(wbr->wbr_wh[i]);
4214 + wbr->wbr_wh[i] = NULL;
4218 + err = test_children_busy(root, bindex, verbose);
4219 + if (unlikely(err)) {
4228 + * now we confirmed the branch is deletable.
4229 + * let's free the remaining opened dirs on the branch.
4231 + di_write_unlock(root);
4232 + br_del_file(to_free, opened, br_id);
4233 + di_write_lock_child(root);
4237 + au_br_do_del(sb, bindex, br);
4239 + sysaufs_brs_del(sb, bindex);
4240 + au_br_do_del(sb, bindex, br);
4241 + sysaufs_brs_add(sb, bindex);
4245 + au_cpup_attr_all(d_inode(root), /*force*/1);
4246 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4248 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4249 + if (au_opt_test(mnt_flags, PLINK))
4250 + au_plink_half_refresh(sb, br_id);
4252 + if (au_xino_brid(sb) == br_id)
4253 + au_xino_brid_set(sb, -1);
4254 + goto out; /* success */
4258 + rerr = au_br_init_wh(sb, br, br->br_perm);
4260 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4261 + del->pathname, rerr);
4264 + au_farray_free(to_free, opened);
4268 +/* ---------------------------------------------------------------------- */
4270 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4273 + aufs_bindex_t btop, bbot;
4274 + struct aufs_ibusy ibusy;
4275 + struct inode *inode, *h_inode;
4278 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4281 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4283 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4284 + if (unlikely(err)) {
4291 + si_read_lock(sb, AuLock_FLUSH);
4292 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4296 + ibusy.h_ino = 0; /* invalid */
4297 + inode = ilookup(sb, ibusy.ino);
4299 + || inode->i_ino == AUFS_ROOT_INO
4300 + || au_is_bad_inode(inode))
4303 + ii_read_lock_child(inode);
4304 + btop = au_ibtop(inode);
4305 + bbot = au_ibbot(inode);
4306 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4307 + h_inode = au_h_iptr(inode, ibusy.bindex);
4308 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4309 + ibusy.h_ino = h_inode->i_ino;
4311 + ii_read_unlock(inode);
4315 + si_read_unlock(sb);
4317 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4318 + if (unlikely(err)) {
4327 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4329 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4332 +#ifdef CONFIG_COMPAT
4333 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4335 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4339 +/* ---------------------------------------------------------------------- */
4342 + * change a branch permission
4345 +static void au_warn_ima(void)
4348 + /* since it doesn't support mark_files_ro() */
4349 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4353 +static int do_need_sigen_inc(int a, int b)
4355 + return au_br_whable(a) && !au_br_whable(b);
4358 +static int need_sigen_inc(int old, int new)
4360 + return do_need_sigen_inc(old, new)
4361 + || do_need_sigen_inc(new, old);
4364 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4367 + unsigned int mnt_flags;
4368 + unsigned long long ull, max;
4369 + aufs_bindex_t br_id;
4370 + unsigned char verbose, writer;
4371 + struct file *file, *hf, **array;
4372 + struct au_hfile *hfile;
4374 + mnt_flags = au_mntflags(sb);
4375 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4377 + array = au_farray_alloc(sb, &max);
4378 + err = PTR_ERR(array);
4379 + if (IS_ERR(array))
4383 + br_id = au_sbr_id(sb, bindex);
4384 + for (ull = 0; ull < max; ull++) {
4385 + file = array[ull];
4386 + if (unlikely(!file))
4389 + /* AuDbg("%pD\n", file); */
4390 + fi_read_lock(file);
4391 + if (unlikely(au_test_mmapped(file))) {
4393 + AuVerbose(verbose, "mmapped %pD\n", file);
4395 + FiMustNoWaiters(file);
4396 + fi_read_unlock(file);
4400 + hfile = &au_fi(file)->fi_htop;
4401 + hf = hfile->hf_file;
4402 + if (!d_is_reg(file->f_path.dentry)
4403 + || !(file->f_mode & FMODE_WRITE)
4404 + || hfile->hf_br->br_id != br_id
4405 + || !(hf->f_mode & FMODE_WRITE))
4406 + array[ull] = NULL;
4412 + FiMustNoWaiters(file);
4413 + fi_read_unlock(file);
4421 + for (ull = 0; ull < max; ull++) {
4422 + file = array[ull];
4426 + /* todo: already flushed? */
4428 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4429 + * approach which resets f_mode and calls mnt_drop_write() and
4430 + * file_release_write() for each file, because the branch
4431 + * attribute in aufs world is totally different from the native
4434 + /* fi_read_lock(file); */
4435 + hfile = &au_fi(file)->fi_htop;
4436 + hf = hfile->hf_file;
4437 + /* fi_read_unlock(file); */
4438 + spin_lock(&hf->f_lock);
4439 + writer = !!(hf->f_mode & FMODE_WRITER);
4440 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4441 + spin_unlock(&hf->f_lock);
4443 + put_write_access(file_inode(hf));
4444 + __mnt_drop_write(hf->f_path.mnt);
4449 + au_farray_free(array, max);
4455 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4459 + aufs_bindex_t bindex;
4460 + struct dentry *root;
4461 + struct au_branch *br;
4462 + struct au_br_fhsm *bf;
4464 + root = sb->s_root;
4465 + bindex = au_find_dbindex(root, mod->h_root);
4468 + return 0; /* success */
4470 + pr_err("%s no such branch\n", mod->path);
4473 + AuDbg("bindex b%d\n", bindex);
4475 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4476 + if (unlikely(err))
4479 + br = au_sbr(sb, bindex);
4480 + AuDebugOn(mod->h_root != au_br_dentry(br));
4481 + if (br->br_perm == mod->perm)
4482 + return 0; /* success */
4484 + /* pre-allocate for non-fhsm --> fhsm */
4486 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4487 + err = au_fhsm_br_alloc(br);
4488 + if (unlikely(err))
4491 + br->br_fhsm = NULL;
4494 + if (au_br_writable(br->br_perm)) {
4495 + /* remove whiteout base */
4496 + err = au_br_init_wh(sb, br, mod->perm);
4497 + if (unlikely(err))
4500 + if (!au_br_writable(mod->perm)) {
4501 + /* rw --> ro, file might be mmapped */
4502 + DiMustNoWaiters(root);
4503 + IiMustNoWaiters(d_inode(root));
4504 + di_write_unlock(root);
4505 + err = au_br_mod_files_ro(sb, bindex);
4506 + /* aufs_write_lock() calls ..._child() */
4507 + di_write_lock_child(root);
4509 + if (unlikely(err)) {
4511 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4514 + rerr = au_wbr_init(br, sb, br->br_perm);
4515 + if (unlikely(rerr)) {
4516 + AuIOErr("nested error %d (%d)\n",
4518 + br->br_perm = mod->perm;
4522 + } else if (au_br_writable(mod->perm)) {
4525 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4527 + err = au_wbr_init(br, sb, mod->perm);
4528 + if (unlikely(err)) {
4529 + kfree(br->br_wbr);
4530 + br->br_wbr = NULL;
4534 + if (unlikely(err))
4537 + if (au_br_fhsm(br->br_perm)) {
4538 + if (!au_br_fhsm(mod->perm)) {
4539 + /* fhsm --> non-fhsm */
4540 + au_br_fhsm_fin(br->br_fhsm);
4541 + kfree(br->br_fhsm);
4542 + br->br_fhsm = NULL;
4544 + } else if (au_br_fhsm(mod->perm))
4545 + /* non-fhsm --> fhsm */
4548 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4549 + br->br_perm = mod->perm;
4550 + goto out; /* success */
4559 +/* ---------------------------------------------------------------------- */
4561 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4564 + struct kstatfs kstfs;
4566 + err = vfs_statfs(&br->br_path, &kstfs);
4568 + stfs->f_blocks = kstfs.f_blocks;
4569 + stfs->f_bavail = kstfs.f_bavail;
4570 + stfs->f_files = kstfs.f_files;
4571 + stfs->f_ffree = kstfs.f_ffree;
4576 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4577 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4578 +++ linux/fs/aufs/branch.h 2018-06-04 09:08:09.181412645 +0200
4581 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4583 + * This program, aufs is free software; you can redistribute it and/or modify
4584 + * it under the terms of the GNU General Public License as published by
4585 + * the Free Software Foundation; either version 2 of the License, or
4586 + * (at your option) any later version.
4588 + * This program is distributed in the hope that it will be useful,
4589 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4590 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4591 + * GNU General Public License for more details.
4593 + * You should have received a copy of the GNU General Public License
4594 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4598 + * branch filesystems and xino for them
4601 +#ifndef __AUFS_BRANCH_H__
4602 +#define __AUFS_BRANCH_H__
4606 +#include <linux/mount.h>
4607 +#include "dirren.h"
4612 +/* ---------------------------------------------------------------------- */
4615 +struct au_xino_file {
4616 + struct file *xi_file;
4621 + /* reserved for future use */
4622 + /* unsigned long *bitmap; */
4623 + wait_queue_head_t wqh;
4626 + /* todo: make xino files an array to support huge inode number */
4628 +#ifdef CONFIG_DEBUG_FS
4629 + struct dentry *xi_dbgaufs;
4633 +/* File-based Hierarchical Storage Management */
4634 +struct au_br_fhsm {
4635 +#ifdef CONFIG_AUFS_FHSM
4636 + struct mutex bf_lock;
4637 + unsigned long bf_jiffy;
4638 + struct aufs_stfs bf_stfs;
4643 +/* members for writable branch only */
4644 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4646 + struct au_rwsem wbr_wh_rwsem;
4647 + struct dentry *wbr_wh[AuBrWh_Last];
4648 + atomic_t wbr_wh_running;
4649 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4650 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4651 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4654 + unsigned long long wbr_bytes;
4657 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4658 +#define AuBrDynOp (AuDyLast * 4)
4660 +#ifdef CONFIG_AUFS_HFSNOTIFY
4661 +/* support for asynchronous destruction */
4662 +struct au_br_hfsnotify {
4663 + struct fsnotify_group *hfsn_group;
4667 +/* sysfs entries */
4668 +struct au_brsysfs {
4670 + struct attribute attr;
4679 +/* protected by superblock rwsem */
4681 + struct au_xino_file br_xino;
4683 + aufs_bindex_t br_id;
4686 + struct path br_path;
4687 + spinlock_t br_dykey_lock;
4688 + struct au_dykey *br_dykey[AuBrDynOp];
4689 + struct percpu_counter br_count;
4691 + struct au_wbr *br_wbr;
4692 + struct au_br_fhsm *br_fhsm;
4694 + /* xino truncation */
4695 + atomic_t br_xino_running;
4697 +#ifdef CONFIG_AUFS_HFSNOTIFY
4698 + struct au_br_hfsnotify *br_hfsn;
4701 +#ifdef CONFIG_SYSFS
4702 + /* entries under sysfs per mount-point */
4703 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4706 + struct au_dr_br br_dirren;
4709 +/* ---------------------------------------------------------------------- */
4711 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4713 + return br->br_path.mnt;
4716 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4718 + return br->br_path.dentry;
4721 +static inline struct super_block *au_br_sb(struct au_branch *br)
4723 + return au_br_mnt(br)->mnt_sb;
4726 +static inline void au_br_get(struct au_branch *br)
4728 + percpu_counter_inc(&br->br_count);
4731 +static inline void au_br_put(struct au_branch *br)
4733 + percpu_counter_dec(&br->br_count);
4736 +static inline s64 au_br_count(struct au_branch *br)
4738 + return percpu_counter_sum(&br->br_count);
4741 +static inline void au_br_count_init(struct au_branch *br)
4743 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4746 +static inline void au_br_count_fin(struct au_branch *br)
4748 + percpu_counter_destroy(&br->br_count);
4751 +static inline int au_br_rdonly(struct au_branch *br)
4753 + return (sb_rdonly(au_br_sb(br))
4754 + || !au_br_writable(br->br_perm))
4758 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4760 +#ifdef CONFIG_AUFS_HNOTIFY
4761 + return !(brperm & AuBrPerm_RR);
4767 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4769 + int err, exec_flag;
4772 + exec_flag = oflag & __FMODE_EXEC;
4773 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4779 +/* ---------------------------------------------------------------------- */
4783 +void au_br_free(struct au_sbinfo *sinfo);
4784 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4786 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4788 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4789 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4790 +#ifdef CONFIG_COMPAT
4791 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4794 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4797 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4800 +static const loff_t au_loff_max = LLONG_MAX;
4802 +int au_xib_trunc(struct super_block *sb);
4803 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4805 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4806 + size_t size, loff_t *pos);
4807 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4808 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4809 +ino_t au_xino_new_ino(struct super_block *sb);
4810 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4811 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4813 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4815 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4816 + struct file *base_file, int do_test);
4817 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4819 +struct au_opt_xino;
4820 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4821 +void au_xino_clr(struct super_block *sb);
4822 +struct file *au_xino_def(struct super_block *sb);
4823 +int au_xino_path(struct seq_file *seq, struct file *file);
4825 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4826 + ino_t h_ino, int idx);
4827 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4830 +/* ---------------------------------------------------------------------- */
4832 +/* Superblock to branch */
4834 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4836 + return au_sbr(sb, bindex)->br_id;
4840 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4842 + return au_br_mnt(au_sbr(sb, bindex));
4846 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4848 + return au_br_sb(au_sbr(sb, bindex));
4851 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4853 + au_br_get(au_sbr(sb, bindex));
4856 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4858 + au_br_put(au_sbr(sb, bindex));
4861 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4863 + return au_sbr(sb, bindex)->br_perm;
4866 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4868 + return au_br_whable(au_sbr_perm(sb, bindex));
4871 +/* ---------------------------------------------------------------------- */
4873 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4874 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4875 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4876 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4878 +#define wbr_wh_read_trylock_nested(wbr) \
4879 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4880 +#define wbr_wh_write_trylock_nested(wbr) \
4881 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4884 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4885 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4886 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4888 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4889 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4890 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4892 +/* ---------------------------------------------------------------------- */
4894 +#ifdef CONFIG_AUFS_FHSM
4895 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4897 + mutex_init(&brfhsm->bf_lock);
4898 + brfhsm->bf_jiffy = 0;
4899 + brfhsm->bf_readable = 0;
4902 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4904 + mutex_destroy(&brfhsm->bf_lock);
4907 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4908 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4911 +#endif /* __KERNEL__ */
4912 +#endif /* __AUFS_BRANCH_H__ */
4913 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4914 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4915 +++ linux/fs/aufs/conf.mk 2018-06-04 09:08:09.181412645 +0200
4917 +# SPDX-License-Identifier: GPL-2.0
4919 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4923 +AuConfStr += ${1}=${${1}}
4927 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4929 + HNOTIFY HFSNOTIFY \
4941 +$(foreach i, ${AuConfAll}, \
4942 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4944 +AuConfName = ${obj}/conf.str
4945 +${AuConfName}.tmp: FORCE
4946 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4947 +${AuConfName}: ${AuConfName}.tmp
4948 + @diff -q $< $@ > /dev/null 2>&1 || { \
4949 + echo ' GEN ' $@; \
4953 +clean-files += ${AuConfName} ${AuConfName}.tmp
4954 +${obj}/sysfs.o: ${AuConfName}
4956 +-include ${srctree}/${src}/conf_priv.mk
4957 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4958 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4959 +++ linux/fs/aufs/cpup.c 2018-06-04 09:08:09.181412645 +0200
4962 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4964 + * This program, aufs is free software; you can redistribute it and/or modify
4965 + * it under the terms of the GNU General Public License as published by
4966 + * the Free Software Foundation; either version 2 of the License, or
4967 + * (at your option) any later version.
4969 + * This program is distributed in the hope that it will be useful,
4970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4972 + * GNU General Public License for more details.
4974 + * You should have received a copy of the GNU General Public License
4975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4979 + * copy-up functions, see wbr_policy.c for copy-down
4982 +#include <linux/fs_stack.h>
4983 +#include <linux/mm.h>
4984 +#include <linux/task_work.h>
4987 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4989 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4990 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4992 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4994 + dst->i_flags |= iflags & ~mask;
4995 + if (au_test_fs_notime(dst->i_sb))
4996 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4999 +void au_cpup_attr_timesizes(struct inode *inode)
5001 + struct inode *h_inode;
5003 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5004 + fsstack_copy_attr_times(inode, h_inode);
5005 + fsstack_copy_inode_size(inode, h_inode);
5008 +void au_cpup_attr_nlink(struct inode *inode, int force)
5010 + struct inode *h_inode;
5011 + struct super_block *sb;
5012 + aufs_bindex_t bindex, bbot;
5015 + bindex = au_ibtop(inode);
5016 + h_inode = au_h_iptr(inode, bindex);
5018 + && !S_ISDIR(h_inode->i_mode)
5019 + && au_opt_test(au_mntflags(sb), PLINK)
5020 + && au_plink_test(inode))
5024 + * 0 can happen in revalidating.
5025 + * h_inode->i_mutex may not be held here, but it is harmless since once
5026 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5028 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5029 + * the incorrect link count.
5031 + set_nlink(inode, h_inode->i_nlink);
5034 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5035 + * it may includes whplink directory.
5037 + if (S_ISDIR(h_inode->i_mode)) {
5038 + bbot = au_ibbot(inode);
5039 + for (bindex++; bindex <= bbot; bindex++) {
5040 + h_inode = au_h_iptr(inode, bindex);
5042 + au_add_nlink(inode, h_inode);
5047 +void au_cpup_attr_changeable(struct inode *inode)
5049 + struct inode *h_inode;
5051 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5052 + inode->i_mode = h_inode->i_mode;
5053 + inode->i_uid = h_inode->i_uid;
5054 + inode->i_gid = h_inode->i_gid;
5055 + au_cpup_attr_timesizes(inode);
5056 + au_cpup_attr_flags(inode, h_inode->i_flags);
5059 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5061 + struct au_iinfo *iinfo = au_ii(inode);
5063 + IiMustWriteLock(inode);
5065 + iinfo->ii_higen = h_inode->i_generation;
5066 + iinfo->ii_hsb1 = h_inode->i_sb;
5069 +void au_cpup_attr_all(struct inode *inode, int force)
5071 + struct inode *h_inode;
5073 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5074 + au_cpup_attr_changeable(inode);
5075 + if (inode->i_nlink > 0)
5076 + au_cpup_attr_nlink(inode, force);
5077 + inode->i_rdev = h_inode->i_rdev;
5078 + inode->i_blkbits = h_inode->i_blkbits;
5079 + au_cpup_igen(inode, h_inode);
5082 +/* ---------------------------------------------------------------------- */
5084 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5086 +/* keep the timestamps of the parent dir when cpup */
5087 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5088 + struct path *h_path)
5090 + struct inode *h_inode;
5092 + dt->dt_dentry = dentry;
5093 + dt->dt_h_path = *h_path;
5094 + h_inode = d_inode(h_path->dentry);
5095 + dt->dt_atime = h_inode->i_atime;
5096 + dt->dt_mtime = h_inode->i_mtime;
5100 +void au_dtime_revert(struct au_dtime *dt)
5102 + struct iattr attr;
5105 + attr.ia_atime = dt->dt_atime;
5106 + attr.ia_mtime = dt->dt_mtime;
5107 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5108 + | ATTR_ATIME | ATTR_ATIME_SET;
5110 + /* no delegation since this is a directory */
5111 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5112 + if (unlikely(err))
5113 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5116 +/* ---------------------------------------------------------------------- */
5118 +/* internal use only */
5119 +struct au_cpup_reg_attr {
5122 + unsigned int iflags; /* inode->i_flags */
5125 +static noinline_for_stack
5126 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5127 + struct au_cpup_reg_attr *h_src_attr)
5129 + int err, sbits, icex;
5130 + unsigned int mnt_flags;
5131 + unsigned char verbose;
5133 + struct path h_path;
5134 + struct inode *h_isrc, *h_idst;
5135 + struct kstat *h_st;
5136 + struct au_branch *br;
5138 + h_path.dentry = au_h_dptr(dst, bindex);
5139 + h_idst = d_inode(h_path.dentry);
5140 + br = au_sbr(dst->d_sb, bindex);
5141 + h_path.mnt = au_br_mnt(br);
5142 + h_isrc = d_inode(h_src);
5143 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5144 + | ATTR_ATIME | ATTR_MTIME
5145 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5146 + if (h_src_attr && h_src_attr->valid) {
5147 + h_st = &h_src_attr->st;
5148 + ia.ia_uid = h_st->uid;
5149 + ia.ia_gid = h_st->gid;
5150 + ia.ia_atime = h_st->atime;
5151 + ia.ia_mtime = h_st->mtime;
5152 + if (h_idst->i_mode != h_st->mode
5153 + && !S_ISLNK(h_idst->i_mode)) {
5154 + ia.ia_valid |= ATTR_MODE;
5155 + ia.ia_mode = h_st->mode;
5157 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5158 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5160 + ia.ia_uid = h_isrc->i_uid;
5161 + ia.ia_gid = h_isrc->i_gid;
5162 + ia.ia_atime = h_isrc->i_atime;
5163 + ia.ia_mtime = h_isrc->i_mtime;
5164 + if (h_idst->i_mode != h_isrc->i_mode
5165 + && !S_ISLNK(h_idst->i_mode)) {
5166 + ia.ia_valid |= ATTR_MODE;
5167 + ia.ia_mode = h_isrc->i_mode;
5169 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5170 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5172 + /* no delegation since it is just created */
5173 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5175 + /* is this nfs only? */
5176 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5177 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5178 + ia.ia_mode = h_isrc->i_mode;
5179 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5182 + icex = br->br_perm & AuBrAttr_ICEX;
5184 + mnt_flags = au_mntflags(dst->d_sb);
5185 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5186 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5192 +/* ---------------------------------------------------------------------- */
5194 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5195 + char *buf, unsigned long blksize)
5198 + size_t sz, rbytes, wbytes;
5199 + unsigned char all_zero;
5201 + struct inode *h_inode;
5202 + /* reduce stack usage */
5205 + zp = page_address(ZERO_PAGE(0));
5206 + if (unlikely(!zp))
5207 + return -ENOMEM; /* possible? */
5212 + AuDbg("len %lld\n", len);
5214 + if (len < blksize)
5218 + /* todo: signal_pending? */
5219 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5220 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5223 + if (unlikely(err < 0))
5227 + if (len >= rbytes && rbytes == blksize)
5228 + all_zero = !memcmp(buf, zp, rbytes);
5235 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5237 + /* todo: signal_pending? */
5238 + if (unlikely(err == -EAGAIN || err == -EINTR))
5240 + if (unlikely(err < 0))
5245 + if (unlikely(err < 0))
5251 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5253 + if (unlikely(res < 0))
5260 + /* the last block may be a hole */
5261 + if (!err && all_zero) {
5262 + AuLabel(last hole);
5265 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5266 + /* nfs requires this step to make last hole */
5267 + /* is this only nfs? */
5269 + /* todo: signal_pending? */
5270 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5271 + } while (err == -EAGAIN || err == -EINTR);
5278 + ia->ia_size = dst->f_pos;
5279 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5280 + ia->ia_file = dst;
5281 + h_inode = file_inode(dst);
5282 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5283 + /* no delegation since it is just created */
5284 + err = vfsub_notify_change(&dst->f_path, ia,
5285 + /*delegated*/NULL);
5286 + inode_unlock(h_inode);
5293 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5296 + unsigned long blksize;
5297 + unsigned char do_kfree;
5301 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5302 + if (!blksize || PAGE_SIZE < blksize)
5303 + blksize = PAGE_SIZE;
5304 + AuDbg("blksize %lu\n", blksize);
5305 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5307 + buf = kmalloc(blksize, GFP_NOFS);
5309 + buf = (void *)__get_free_page(GFP_NOFS);
5310 + if (unlikely(!buf))
5313 + if (len > (1 << 22))
5314 + AuDbg("copying a large file %lld\n", (long long)len);
5318 + err = au_do_copy_file(dst, src, len, buf, blksize);
5322 + free_page((unsigned long)buf);
5328 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5331 + struct super_block *h_src_sb;
5332 + struct inode *h_src_inode;
5334 + h_src_inode = file_inode(src);
5335 + h_src_sb = h_src_inode->i_sb;
5337 + /* XFS acquires inode_lock */
5338 + if (!au_test_xfs(h_src_sb))
5339 + err = au_copy_file(dst, src, len);
5341 + inode_unlock_shared(h_src_inode);
5342 + err = au_copy_file(dst, src, len);
5343 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5349 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5352 + struct super_block *h_src_sb;
5353 + struct inode *h_src_inode;
5355 + h_src_inode = file_inode(src);
5356 + h_src_sb = h_src_inode->i_sb;
5357 + if (h_src_sb != file_inode(dst)->i_sb
5358 + || !dst->f_op->clone_file_range) {
5359 + err = au_do_copy(dst, src, len);
5363 + if (!au_test_nfs(h_src_sb)) {
5364 + inode_unlock_shared(h_src_inode);
5365 + err = vfsub_clone_file_range(src, dst, len);
5366 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5368 + err = vfsub_clone_file_range(src, dst, len);
5369 + /* older XFS has a condition in cloning */
5370 + if (unlikely(err != -EOPNOTSUPP))
5373 + /* the backend fs on NFS may not support cloning */
5374 + err = au_do_copy(dst, src, len);
5382 + * to support a sparse file which is opened with O_APPEND,
5383 + * we need to close the file.
5385 +static int au_cp_regular(struct au_cp_generic *cpg)
5388 + enum { SRC, DST };
5390 + aufs_bindex_t bindex;
5391 + unsigned int flags;
5392 + struct dentry *dentry;
5394 + struct file *file;
5398 + .bindex = cpg->bsrc,
5399 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5403 + .bindex = cpg->bdst,
5404 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5405 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5406 + .label = &&out_src
5409 + struct super_block *sb, *h_src_sb;
5410 + struct inode *h_src_inode;
5411 + struct task_struct *tsk = current;
5413 + /* bsrc branch can be ro/rw. */
5414 + sb = cpg->dentry->d_sb;
5416 + for (i = 0; i < 2; i++, f++) {
5417 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5418 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5419 + /*file*/NULL, f->force_wr);
5420 + err = PTR_ERR(f->file);
5421 + if (IS_ERR(f->file))
5425 + /* try stopping to update while we copyup */
5426 + h_src_inode = d_inode(file[SRC].dentry);
5427 + h_src_sb = h_src_inode->i_sb;
5428 + if (!au_test_nfs(h_src_sb))
5429 + IMustLock(h_src_inode);
5430 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5432 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5433 + if (tsk->flags & PF_KTHREAD)
5434 + __fput_sync(file[DST].file);
5436 + /* it happend actually */
5437 + fput(file[DST].file);
5440 + * we have to call both since we don't know which place the file
5444 + flush_delayed_fput();
5446 + au_sbr_put(sb, file[DST].bindex);
5449 + fput(file[SRC].file);
5450 + au_sbr_put(sb, file[SRC].bindex);
5455 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5456 + struct au_cpup_reg_attr *h_src_attr)
5460 + struct path h_path;
5461 + struct inode *h_src_inode, *h_dst_inode;
5464 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5465 + l = i_size_read(h_src_inode);
5466 + if (cpg->len == -1 || l < cpg->len)
5469 + /* try stopping to update while we are referencing */
5470 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5471 + au_pin_hdir_unlock(cpg->pin);
5473 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5474 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5475 + h_src_attr->iflags = h_src_inode->i_flags;
5476 + if (!au_test_nfs(h_src_inode->i_sb))
5477 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5479 + inode_unlock_shared(h_src_inode);
5480 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5481 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5483 + if (unlikely(err)) {
5484 + inode_unlock_shared(h_src_inode);
5487 + h_src_attr->valid = 1;
5488 + if (!au_test_nfs(h_src_inode->i_sb)) {
5489 + err = au_cp_regular(cpg);
5490 + inode_unlock_shared(h_src_inode);
5492 + inode_unlock_shared(h_src_inode);
5493 + err = au_cp_regular(cpg);
5495 + rerr = au_pin_hdir_relock(cpg->pin);
5499 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5500 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5501 + h_dst_inode = d_inode(h_path.dentry);
5502 + spin_lock(&h_dst_inode->i_lock);
5503 + h_dst_inode->i_state |= I_LINKABLE;
5504 + spin_unlock(&h_dst_inode->i_lock);
5511 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5512 + struct inode *h_dir)
5515 + mm_segment_t old_fs;
5522 + sym.k = (void *)__get_free_page(GFP_NOFS);
5523 + if (unlikely(!sym.k))
5526 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5527 + old_fs = get_fs();
5528 + set_fs(KERNEL_DS);
5529 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5534 + sym.k[symlen] = 0;
5535 + err = vfsub_symlink(h_dir, h_path, sym.k);
5537 + free_page((unsigned long)sym.k);
5544 + * regardless 'acl' option, reset all ACL.
5545 + * All ACL will be copied up later from the original entry on the lower branch.
5547 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5550 + struct dentry *h_dentry;
5551 + struct inode *h_inode;
5553 + h_dentry = h_path->dentry;
5554 + h_inode = d_inode(h_dentry);
5555 + /* forget_all_cached_acls(h_inode)); */
5556 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5558 + if (err == -EOPNOTSUPP)
5561 + err = vfsub_acl_chmod(h_inode, mode);
5567 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5568 + struct inode *h_dir, struct path *h_path)
5571 + struct inode *dir, *inode;
5573 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5575 + if (err == -EOPNOTSUPP)
5577 + if (unlikely(err))
5581 + * strange behaviour from the users view,
5582 + * particularry setattr case
5584 + dir = d_inode(dst_parent);
5585 + if (au_ibtop(dir) == cpg->bdst)
5586 + au_cpup_attr_nlink(dir, /*force*/1);
5587 + inode = d_inode(cpg->dentry);
5588 + au_cpup_attr_nlink(inode, /*force*/1);
5594 +static noinline_for_stack
5595 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5596 + struct au_cpup_reg_attr *h_src_attr)
5600 + unsigned int mnt_flags;
5601 + unsigned char isdir, isreg, force;
5602 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5603 + struct au_dtime dt;
5604 + struct path h_path;
5605 + struct dentry *h_src, *h_dst, *h_parent;
5606 + struct inode *h_inode, *h_dir;
5607 + struct super_block *sb;
5609 + /* bsrc branch can be ro/rw. */
5610 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5611 + h_inode = d_inode(h_src);
5612 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5614 + /* try stopping to be referenced while we are creating */
5615 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5616 + if (au_ftest_cpup(cpg->flags, RENAME))
5617 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5618 + AUFS_WH_PFX_LEN));
5619 + h_parent = h_dst->d_parent; /* dir inode is locked */
5620 + h_dir = d_inode(h_parent);
5622 + AuDebugOn(h_parent != h_dst->d_parent);
5624 + sb = cpg->dentry->d_sb;
5625 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5627 + h_path.dentry = h_parent;
5628 + au_dtime_store(&dt, dst_parent, &h_path);
5630 + h_path.dentry = h_dst;
5634 + mode = h_inode->i_mode;
5635 + switch (mode & S_IFMT) {
5638 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5639 + /*want_excl*/true);
5641 + err = au_do_cpup_regular(cpg, h_src_attr);
5645 + err = vfsub_mkdir(h_dir, &h_path, mode);
5647 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5650 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5654 + AuDebugOn(!capable(CAP_MKNOD));
5658 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5661 + AuIOErr("Unknown inode type 0%o\n", mode);
5665 + err = au_reset_acl(h_dir, &h_path, mode);
5667 + mnt_flags = au_mntflags(sb);
5668 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5670 + && au_opt_test(mnt_flags, XINO)
5671 + && (h_inode->i_nlink == 1
5672 + || (h_inode->i_state & I_LINKABLE))
5673 + /* todo: unnecessary? */
5674 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5675 + && cpg->bdst < cpg->bsrc
5676 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5677 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5678 + /* ignore this error */
5683 + force = !!cpg->len;
5684 + if (cpg->len == -1)
5685 + force = !!i_size_read(h_inode);
5687 + au_fhsm_wrote(sb, cpg->bdst, force);
5691 + au_dtime_revert(&dt);
5695 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5698 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5699 + struct inode *h_dir;
5700 + aufs_bindex_t bdst;
5702 + dentry = cpg->dentry;
5704 + h_dentry = au_h_dptr(dentry, bdst);
5705 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5707 + au_set_h_dptr(dentry, bdst, NULL);
5708 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5710 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5711 + au_set_h_dptr(dentry, bdst, h_dentry);
5714 + parent = dget_parent(dentry);
5715 + h_parent = au_h_dptr(parent, bdst);
5717 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5718 + if (IS_ERR(h_path->dentry))
5719 + err = PTR_ERR(h_path->dentry);
5721 + if (unlikely(err))
5724 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5725 + h_dir = d_inode(h_parent);
5727 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5728 + /* no delegation since it is just created */
5729 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5731 + dput(h_path->dentry);
5738 + * copyup the @dentry from @bsrc to @bdst.
5739 + * the caller must set the both of lower dentries.
5740 + * @len is for truncating when it is -1 copyup the entire file.
5741 + * in link/rename cases, @dst_parent may be different from the real one.
5742 + * basic->bsrc can be larger than basic->bdst.
5743 + * aufs doesn't touch the credential so
5744 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5746 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5749 + aufs_bindex_t old_ibtop;
5750 + unsigned char isdir, plink;
5751 + struct dentry *h_src, *h_dst, *h_parent;
5752 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5753 + struct super_block *sb;
5754 + struct au_branch *br;
5755 + /* to reuduce stack size */
5757 + struct au_dtime dt;
5758 + struct path h_path;
5759 + struct au_cpup_reg_attr h_src_attr;
5763 + a = kmalloc(sizeof(*a), GFP_NOFS);
5766 + a->h_src_attr.valid = 0;
5768 + sb = cpg->dentry->d_sb;
5769 + br = au_sbr(sb, cpg->bdst);
5770 + a->h_path.mnt = au_br_mnt(br);
5771 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5772 + h_parent = h_dst->d_parent; /* dir inode is locked */
5773 + h_dir = d_inode(h_parent);
5776 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5777 + inode = d_inode(cpg->dentry);
5780 + dst_parent = dget_parent(cpg->dentry);
5784 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5785 + dst_inode = au_h_iptr(inode, cpg->bdst);
5787 + if (unlikely(!plink)) {
5789 + AuIOErr("hi%lu(i%lu) exists on b%d "
5790 + "but plink is disabled\n",
5791 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5795 + if (dst_inode->i_nlink) {
5796 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5798 + h_src = au_plink_lkup(inode, cpg->bdst);
5799 + err = PTR_ERR(h_src);
5800 + if (IS_ERR(h_src))
5802 + if (unlikely(d_is_negative(h_src))) {
5804 + AuIOErr("i%lu exists on b%d "
5805 + "but not pseudo-linked\n",
5806 + inode->i_ino, cpg->bdst);
5812 + a->h_path.dentry = h_parent;
5813 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5816 + a->h_path.dentry = h_dst;
5818 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5819 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5820 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5822 + au_dtime_revert(&a->dt);
5823 + if (unlikely(err == -EWOULDBLOCK)) {
5824 + pr_warn("cannot retry for NFSv4 delegation"
5825 + " for an internal link\n");
5831 + /* todo: cpup_wh_file? */
5833 + au_update_ibrange(inode, /*do_put_zero*/1);
5836 + isdir = S_ISDIR(inode->i_mode);
5837 + old_ibtop = au_ibtop(inode);
5838 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5839 + if (unlikely(err))
5841 + dst_inode = d_inode(h_dst);
5842 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5843 + /* todo: necessary? */
5844 + /* au_pin_hdir_unlock(cpg->pin); */
5846 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5847 + if (unlikely(err)) {
5848 + /* todo: necessary? */
5849 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5850 + inode_unlock(dst_inode);
5854 + if (cpg->bdst < old_ibtop) {
5855 + if (S_ISREG(inode->i_mode)) {
5856 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5857 + if (unlikely(err)) {
5858 + /* ignore an error */
5859 + /* au_pin_hdir_relock(cpg->pin); */
5860 + inode_unlock(dst_inode);
5864 + au_set_ibtop(inode, cpg->bdst);
5866 + au_set_ibbot(inode, cpg->bdst);
5867 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5868 + au_hi_flags(inode, isdir));
5870 + /* todo: necessary? */
5871 + /* err = au_pin_hdir_relock(cpg->pin); */
5872 + inode_unlock(dst_inode);
5873 + if (unlikely(err))
5876 + src_inode = d_inode(h_src);
5878 + && (src_inode->i_nlink > 1
5879 + || src_inode->i_state & I_LINKABLE)
5881 + au_plink_append(inode, cpg->bdst, h_dst);
5883 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5884 + a->h_path.dentry = h_dst;
5885 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5888 + goto out_parent; /* success */
5892 + a->h_path.dentry = h_parent;
5893 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5894 + a->h_path.dentry = h_dst;
5896 + if (d_is_positive(h_dst)) {
5898 + /* no delegation since it is just created */
5899 + rerr = vfsub_unlink(h_dir, &a->h_path,
5900 + /*delegated*/NULL, /*force*/0);
5902 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5904 + au_dtime_revert(&a->dt);
5906 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5916 +#if 0 /* reserved */
5917 +struct au_cpup_single_args {
5919 + struct au_cp_generic *cpg;
5920 + struct dentry *dst_parent;
5923 +static void au_call_cpup_single(void *args)
5925 + struct au_cpup_single_args *a = args;
5927 + au_pin_hdir_acquire_nest(a->cpg->pin);
5928 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5929 + au_pin_hdir_release(a->cpg->pin);
5934 + * prevent SIGXFSZ in copy-up.
5935 + * testing CAP_MKNOD is for generic fs,
5936 + * but CAP_FSETID is for xfs only, currently.
5938 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5941 + struct super_block *sb;
5942 + struct inode *h_dir;
5945 + sb = au_pinned_parent(pin)->d_sb;
5946 + if (!au_wkq_test()
5947 + && (!au_sbi(sb)->si_plink_maint_pid
5948 + || au_plink_maint(sb, AuLock_NOPLM))) {
5949 + switch (mode & S_IFMT) {
5951 + /* no condition about RLIMIT_FSIZE and the file size */
5956 + do_sio = !capable(CAP_MKNOD);
5960 + do_sio = ((mode & (S_ISUID | S_ISGID))
5961 + && !capable(CAP_FSETID));
5962 + /* this workaround may be removed in the future */
5964 + h_dir = au_pinned_h_dir(pin);
5965 + do_sio = h_dir->i_mode & S_ISVTX;
5972 +#if 0 /* reserved */
5973 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5976 + struct dentry *h_dentry;
5978 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5979 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5980 + err = au_cpup_single(cpg, dst_parent);
5982 + struct au_cpup_single_args args = {
5985 + .dst_parent = dst_parent
5987 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5988 + if (unlikely(wkq_err))
5997 + * copyup the @dentry from the first active lower branch to @bdst,
5998 + * using au_cpup_single().
6000 +static int au_cpup_simple(struct au_cp_generic *cpg)
6003 + unsigned int flags_orig;
6004 + struct dentry *dentry;
6006 + AuDebugOn(cpg->bsrc < 0);
6008 + dentry = cpg->dentry;
6009 + DiMustWriteLock(dentry);
6011 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6013 + flags_orig = cpg->flags;
6014 + au_fset_cpup(cpg->flags, RENAME);
6015 + err = au_cpup_single(cpg, NULL);
6016 + cpg->flags = flags_orig;
6018 + return 0; /* success */
6021 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6022 + au_set_dbtop(dentry, cpg->bsrc);
6028 +struct au_cpup_simple_args {
6030 + struct au_cp_generic *cpg;
6033 +static void au_call_cpup_simple(void *args)
6035 + struct au_cpup_simple_args *a = args;
6037 + au_pin_hdir_acquire_nest(a->cpg->pin);
6038 + *a->errp = au_cpup_simple(a->cpg);
6039 + au_pin_hdir_release(a->cpg->pin);
6042 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6045 + struct dentry *dentry, *parent;
6046 + struct file *h_file;
6047 + struct inode *h_dir;
6049 + dentry = cpg->dentry;
6051 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6052 + AuDebugOn(cpg->bsrc < 0);
6053 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6054 + err = PTR_ERR(h_file);
6055 + if (IS_ERR(h_file))
6059 + parent = dget_parent(dentry);
6060 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6061 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6062 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6063 + err = au_cpup_simple(cpg);
6065 + struct au_cpup_simple_args args = {
6069 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6070 + if (unlikely(wkq_err))
6076 + au_h_open_post(dentry, cpg->bsrc, h_file);
6082 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6084 + aufs_bindex_t bsrc, bbot;
6085 + struct dentry *dentry, *h_dentry;
6087 + if (cpg->bsrc < 0) {
6088 + dentry = cpg->dentry;
6089 + bbot = au_dbbot(dentry);
6090 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6091 + h_dentry = au_h_dptr(dentry, bsrc);
6093 + AuDebugOn(d_is_negative(h_dentry));
6097 + AuDebugOn(bsrc > bbot);
6100 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6101 + return au_do_sio_cpup_simple(cpg);
6104 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6106 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6107 + return au_do_sio_cpup_simple(cpg);
6110 +/* ---------------------------------------------------------------------- */
6113 + * copyup the deleted file for writing.
6115 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6116 + struct file *file)
6119 + unsigned int flags_orig;
6120 + aufs_bindex_t bsrc_orig;
6121 + struct au_dinfo *dinfo;
6123 + struct au_hdentry *hd;
6124 + struct dentry *h_dentry;
6127 + dinfo = au_di(cpg->dentry);
6128 + AuRwMustWriteLock(&dinfo->di_rwsem);
6130 + bsrc_orig = cpg->bsrc;
6131 + cpg->bsrc = dinfo->di_btop;
6132 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6133 + hdst.h_dentry = hdst.hd->hd_dentry;
6134 + hdst.hd->hd_dentry = wh_dentry;
6135 + dinfo->di_btop = cpg->bdst;
6137 + hsrc.h_dentry = NULL;
6139 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6140 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6141 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6143 + flags_orig = cpg->flags;
6144 + cpg->flags = !AuCpup_DTIME;
6145 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6146 + cpg->flags = flags_orig;
6149 + err = au_reopen_nondir(file);
6150 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6152 + hdst.hd->hd_dentry = hdst.h_dentry;
6153 + dinfo->di_btop = cpg->bsrc;
6154 + cpg->bsrc = bsrc_orig;
6159 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6162 + aufs_bindex_t bdst;
6163 + struct au_dtime dt;
6164 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6165 + struct au_branch *br;
6166 + struct path h_path;
6168 + dentry = cpg->dentry;
6170 + br = au_sbr(dentry->d_sb, bdst);
6171 + parent = dget_parent(dentry);
6172 + h_parent = au_h_dptr(parent, bdst);
6173 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6174 + err = PTR_ERR(wh_dentry);
6175 + if (IS_ERR(wh_dentry))
6178 + h_path.dentry = h_parent;
6179 + h_path.mnt = au_br_mnt(br);
6180 + au_dtime_store(&dt, parent, &h_path);
6181 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6182 + if (unlikely(err))
6186 + h_path.dentry = wh_dentry;
6187 + if (!d_is_dir(wh_dentry)) {
6188 + /* no delegation since it is just created */
6189 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6190 + /*delegated*/NULL, /*force*/0);
6192 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6193 + if (unlikely(err)) {
6194 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6198 + au_dtime_revert(&dt);
6199 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6208 +struct au_cpup_wh_args {
6210 + struct au_cp_generic *cpg;
6211 + struct file *file;
6214 +static void au_call_cpup_wh(void *args)
6216 + struct au_cpup_wh_args *a = args;
6218 + au_pin_hdir_acquire_nest(a->cpg->pin);
6219 + *a->errp = au_cpup_wh(a->cpg, a->file);
6220 + au_pin_hdir_release(a->cpg->pin);
6223 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6226 + aufs_bindex_t bdst;
6227 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6228 + struct inode *dir, *h_dir, *h_tmpdir;
6229 + struct au_wbr *wbr;
6230 + struct au_pin wh_pin, *pin_orig;
6232 + dentry = cpg->dentry;
6234 + parent = dget_parent(dentry);
6235 + dir = d_inode(parent);
6238 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6241 + if (!h_dir->i_nlink) {
6242 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6243 + h_orph = wbr->wbr_orph;
6245 + h_parent = dget(au_h_dptr(parent, bdst));
6246 + au_set_h_dptr(parent, bdst, dget(h_orph));
6247 + h_tmpdir = d_inode(h_orph);
6248 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6250 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6251 + /* todo: au_h_open_pre()? */
6253 + pin_orig = cpg->pin;
6254 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6255 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6256 + cpg->pin = &wh_pin;
6259 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6260 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6261 + err = au_cpup_wh(cpg, file);
6263 + struct au_cpup_wh_args args = {
6268 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6269 + if (unlikely(wkq_err))
6274 + inode_unlock(h_tmpdir);
6275 + /* todo: au_h_open_post()? */
6276 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6277 + au_set_h_dptr(parent, bdst, h_parent);
6278 + AuDebugOn(!pin_orig);
6279 + cpg->pin = pin_orig;
6287 +/* ---------------------------------------------------------------------- */
6290 + * generic routine for both of copy-up and copy-down.
6292 +/* cf. revalidate function in file.c */
6293 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6294 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6295 + struct au_pin *pin,
6296 + struct dentry *h_parent, void *arg),
6300 + struct au_pin pin;
6301 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6304 + parent = dget_parent(dentry);
6305 + if (IS_ROOT(parent))
6308 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6309 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6311 + /* do not use au_dpage */
6312 + real_parent = parent;
6315 + parent = dget_parent(dentry);
6316 + h_parent = au_h_dptr(parent, bdst);
6318 + goto out; /* success */
6320 + /* find top dir which is necessary to cpup */
6324 + parent = dget_parent(d);
6325 + di_read_lock_parent3(parent, !AuLock_IR);
6326 + h_parent = au_h_dptr(parent, bdst);
6327 + di_read_unlock(parent, !AuLock_IR);
6328 + } while (!h_parent);
6330 + if (d != real_parent)
6331 + di_write_lock_child3(d);
6333 + /* somebody else might create while we were sleeping */
6334 + h_dentry = au_h_dptr(d, bdst);
6335 + if (!h_dentry || d_is_negative(h_dentry)) {
6337 + au_update_dbtop(d);
6339 + au_pin_set_dentry(&pin, d);
6340 + err = au_do_pin(&pin);
6342 + err = cp(d, bdst, &pin, h_parent, arg);
6347 + if (d != real_parent)
6348 + di_write_unlock(d);
6349 + if (unlikely(err))
6358 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6359 + struct au_pin *pin,
6360 + struct dentry *h_parent __maybe_unused,
6361 + void *arg __maybe_unused)
6363 + struct au_cp_generic cpg = {
6369 + .flags = AuCpup_DTIME
6371 + return au_sio_cpup_simple(&cpg);
6374 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6376 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6379 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6382 + struct dentry *parent;
6383 + struct inode *dir;
6385 + parent = dget_parent(dentry);
6386 + dir = d_inode(parent);
6388 + if (au_h_iptr(dir, bdst))
6391 + di_read_unlock(parent, AuLock_IR);
6392 + di_write_lock_parent(parent);
6393 + /* someone else might change our inode while we were sleeping */
6394 + if (!au_h_iptr(dir, bdst))
6395 + err = au_cpup_dirs(dentry, bdst);
6396 + di_downgrade_lock(parent, AuLock_IR);
6402 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6403 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6404 +++ linux/fs/aufs/cpup.h 2018-04-15 08:49:13.397817296 +0200
6407 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6409 + * This program, aufs is free software; you can redistribute it and/or modify
6410 + * it under the terms of the GNU General Public License as published by
6411 + * the Free Software Foundation; either version 2 of the License, or
6412 + * (at your option) any later version.
6414 + * This program is distributed in the hope that it will be useful,
6415 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6416 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6417 + * GNU General Public License for more details.
6419 + * You should have received a copy of the GNU General Public License
6420 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6424 + * copy-up/down functions
6427 +#ifndef __AUFS_CPUP_H__
6428 +#define __AUFS_CPUP_H__
6432 +#include <linux/path.h>
6438 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6439 +void au_cpup_attr_timesizes(struct inode *inode);
6440 +void au_cpup_attr_nlink(struct inode *inode, int force);
6441 +void au_cpup_attr_changeable(struct inode *inode);
6442 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6443 +void au_cpup_attr_all(struct inode *inode, int force);
6445 +/* ---------------------------------------------------------------------- */
6447 +struct au_cp_generic {
6448 + struct dentry *dentry;
6449 + aufs_bindex_t bdst, bsrc;
6451 + struct au_pin *pin;
6452 + unsigned int flags;
6456 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6457 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6459 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6460 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6462 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6464 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6465 + the branch is marked as RO */
6467 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6468 +#undef AuCpup_HOPEN
6469 +#define AuCpup_HOPEN 0
6472 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6473 +#define au_fset_cpup(flags, name) \
6474 + do { (flags) |= AuCpup_##name; } while (0)
6475 +#define au_fclr_cpup(flags, name) \
6476 + do { (flags) &= ~AuCpup_##name; } while (0)
6478 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6479 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6480 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6481 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6483 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6484 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6485 + struct au_pin *pin,
6486 + struct dentry *h_parent, void *arg),
6488 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6489 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6491 +/* ---------------------------------------------------------------------- */
6493 +/* keep timestamps when copyup */
6495 + struct dentry *dt_dentry;
6496 + struct path dt_h_path;
6497 + struct timespec dt_atime, dt_mtime;
6499 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6500 + struct path *h_path);
6501 +void au_dtime_revert(struct au_dtime *dt);
6503 +#endif /* __KERNEL__ */
6504 +#endif /* __AUFS_CPUP_H__ */
6505 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6506 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6507 +++ linux/fs/aufs/dbgaufs.c 2018-06-04 09:08:09.181412645 +0200
6510 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6512 + * This program, aufs is free software; you can redistribute it and/or modify
6513 + * it under the terms of the GNU General Public License as published by
6514 + * the Free Software Foundation; either version 2 of the License, or
6515 + * (at your option) any later version.
6517 + * This program is distributed in the hope that it will be useful,
6518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6520 + * GNU General Public License for more details.
6522 + * You should have received a copy of the GNU General Public License
6523 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6527 + * debugfs interface
6530 +#include <linux/debugfs.h>
6533 +#ifndef CONFIG_SYSFS
6534 +#error DEBUG_FS depends upon SYSFS
6537 +static struct dentry *dbgaufs;
6538 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6540 +/* 20 is max digits length of ulong 64 */
6541 +struct dbgaufs_arg {
6547 + * common function for all XINO files
6549 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6550 + struct file *file)
6552 + kfree(file->private_data);
6556 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6560 + struct dbgaufs_arg *p;
6563 + p = kmalloc(sizeof(*p), GFP_NOFS);
6569 + file->private_data = p;
6573 + err = vfsub_getattr(&xf->f_path, &st);
6577 + (p->a, sizeof(p->a), "%ld, %llux%u %lld\n",
6578 + (long)file_count(xf), st.blocks, st.blksize,
6579 + (long long)st.size);
6581 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6582 + st.blocks, st.blksize,
6583 + (long long)st.size);
6584 + AuDebugOn(p->n >= sizeof(p->a));
6586 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6595 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6596 + size_t count, loff_t *ppos)
6598 + struct dbgaufs_arg *p;
6600 + p = file->private_data;
6601 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6604 +/* ---------------------------------------------------------------------- */
6606 +struct dbgaufs_plink_arg {
6611 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6612 + struct file *file)
6614 + free_page((unsigned long)file->private_data);
6618 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6620 + int err, i, limit;
6621 + unsigned long n, sum;
6622 + struct dbgaufs_plink_arg *p;
6623 + struct au_sbinfo *sbinfo;
6624 + struct super_block *sb;
6625 + struct hlist_bl_head *hbl;
6628 + p = (void *)get_zeroed_page(GFP_NOFS);
6633 + sbinfo = inode->i_private;
6634 + sb = sbinfo->si_sb;
6635 + si_noflush_read_lock(sb);
6636 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6637 + limit = PAGE_SIZE - sizeof(p->n);
6639 + /* the number of buckets */
6640 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6645 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6647 + n = au_hbl_count(hbl);
6650 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6653 + if (unlikely(limit <= 0))
6656 + p->a[p->n - 1] = '\n';
6658 + /* the sum of plinks */
6659 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6662 + if (unlikely(limit <= 0))
6665 +#define str "1\n0\n0\n"
6666 + p->n = sizeof(str) - 1;
6667 + strcpy(p->a, str);
6670 + si_read_unlock(sb);
6673 + file->private_data = p;
6674 + goto out; /* success */
6677 + free_page((unsigned long)p);
6682 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6683 + size_t count, loff_t *ppos)
6685 + struct dbgaufs_plink_arg *p;
6687 + p = file->private_data;
6688 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6691 +static const struct file_operations dbgaufs_plink_fop = {
6692 + .owner = THIS_MODULE,
6693 + .open = dbgaufs_plink_open,
6694 + .release = dbgaufs_plink_release,
6695 + .read = dbgaufs_plink_read
6698 +/* ---------------------------------------------------------------------- */
6700 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6703 + struct au_sbinfo *sbinfo;
6704 + struct super_block *sb;
6706 + sbinfo = inode->i_private;
6707 + sb = sbinfo->si_sb;
6708 + si_noflush_read_lock(sb);
6709 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6710 + si_read_unlock(sb);
6714 +static const struct file_operations dbgaufs_xib_fop = {
6715 + .owner = THIS_MODULE,
6716 + .open = dbgaufs_xib_open,
6717 + .release = dbgaufs_xi_release,
6718 + .read = dbgaufs_xi_read
6721 +/* ---------------------------------------------------------------------- */
6723 +#define DbgaufsXi_PREFIX "xi"
6725 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6729 + struct au_sbinfo *sbinfo;
6730 + struct super_block *sb;
6732 + struct qstr *name;
6736 + name = &file->f_path.dentry->d_name;
6737 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6738 + || memcmp(name->name, DbgaufsXi_PREFIX,
6739 + sizeof(DbgaufsXi_PREFIX) - 1)))
6741 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6742 + if (unlikely(err))
6745 + sbinfo = inode->i_private;
6746 + sb = sbinfo->si_sb;
6747 + si_noflush_read_lock(sb);
6748 + if (l <= au_sbbot(sb)) {
6749 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6750 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6753 + si_read_unlock(sb);
6759 +static const struct file_operations dbgaufs_xino_fop = {
6760 + .owner = THIS_MODULE,
6761 + .open = dbgaufs_xino_open,
6762 + .release = dbgaufs_xi_release,
6763 + .read = dbgaufs_xi_read
6766 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6768 + aufs_bindex_t bbot;
6769 + struct au_branch *br;
6770 + struct au_xino_file *xi;
6772 + if (!au_sbi(sb)->si_dbgaufs)
6775 + bbot = au_sbbot(sb);
6776 + for (; bindex <= bbot; bindex++) {
6777 + br = au_sbr(sb, bindex);
6778 + xi = &br->br_xino;
6779 + /* debugfs acquires the parent i_mutex */
6781 + debugfs_remove(xi->xi_dbgaufs);
6783 + xi->xi_dbgaufs = NULL;
6787 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6789 + struct au_sbinfo *sbinfo;
6790 + struct dentry *parent;
6791 + struct au_branch *br;
6792 + struct au_xino_file *xi;
6793 + aufs_bindex_t bbot;
6794 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6796 + sbinfo = au_sbi(sb);
6797 + parent = sbinfo->si_dbgaufs;
6801 + bbot = au_sbbot(sb);
6802 + for (; bindex <= bbot; bindex++) {
6803 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6804 + br = au_sbr(sb, bindex);
6805 + xi = &br->br_xino;
6806 + AuDebugOn(xi->xi_dbgaufs);
6807 + /* debugfs acquires the parent i_mutex */
6809 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6810 + sbinfo, &dbgaufs_xino_fop);
6812 + /* ignore an error */
6813 + if (unlikely(!xi->xi_dbgaufs))
6814 + AuWarn1("failed %s under debugfs\n", name);
6818 +/* ---------------------------------------------------------------------- */
6820 +#ifdef CONFIG_AUFS_EXPORT
6821 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6824 + struct au_sbinfo *sbinfo;
6825 + struct super_block *sb;
6827 + sbinfo = inode->i_private;
6828 + sb = sbinfo->si_sb;
6829 + si_noflush_read_lock(sb);
6830 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6831 + si_read_unlock(sb);
6835 +static const struct file_operations dbgaufs_xigen_fop = {
6836 + .owner = THIS_MODULE,
6837 + .open = dbgaufs_xigen_open,
6838 + .release = dbgaufs_xi_release,
6839 + .read = dbgaufs_xi_read
6842 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6847 + * This function is a dynamic '__init' function actually,
6848 + * so the tiny check for si_rwsem is unnecessary.
6850 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6853 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6854 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6855 + &dbgaufs_xigen_fop);
6856 + if (sbinfo->si_dbgaufs_xigen)
6862 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6866 +#endif /* CONFIG_AUFS_EXPORT */
6868 +/* ---------------------------------------------------------------------- */
6870 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6873 + * This function is a dynamic '__fin' function actually,
6874 + * so the tiny check for si_rwsem is unnecessary.
6876 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6878 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6879 + sbinfo->si_dbgaufs = NULL;
6880 + kobject_put(&sbinfo->si_kobj);
6883 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6886 + char name[SysaufsSiNameLen];
6889 + * This function is a dynamic '__init' function actually,
6890 + * so the tiny check for si_rwsem is unnecessary.
6892 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6896 + AuErr1("/debug/aufs is uninitialized\n");
6901 + sysaufs_name(sbinfo, name);
6902 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6903 + if (unlikely(!sbinfo->si_dbgaufs))
6905 + kobject_get(&sbinfo->si_kobj);
6907 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6908 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6909 + &dbgaufs_xib_fop);
6910 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6913 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6914 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6915 + &dbgaufs_plink_fop);
6916 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6919 + err = dbgaufs_xigen_init(sbinfo);
6921 + goto out; /* success */
6924 + dbgaufs_si_fin(sbinfo);
6929 +/* ---------------------------------------------------------------------- */
6931 +void dbgaufs_fin(void)
6933 + debugfs_remove(dbgaufs);
6936 +int __init dbgaufs_init(void)
6941 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6946 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6947 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6948 +++ linux/fs/aufs/dbgaufs.h 2018-04-15 08:49:13.397817296 +0200
6951 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6953 + * This program, aufs is free software; you can redistribute it and/or modify
6954 + * it under the terms of the GNU General Public License as published by
6955 + * the Free Software Foundation; either version 2 of the License, or
6956 + * (at your option) any later version.
6958 + * This program is distributed in the hope that it will be useful,
6959 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6960 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6961 + * GNU General Public License for more details.
6963 + * You should have received a copy of the GNU General Public License
6964 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6968 + * debugfs interface
6971 +#ifndef __DBGAUFS_H__
6972 +#define __DBGAUFS_H__
6976 +struct super_block;
6979 +#ifdef CONFIG_DEBUG_FS
6981 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6982 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6983 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6984 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6985 +void dbgaufs_fin(void);
6986 +int __init dbgaufs_init(void);
6988 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6989 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6990 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6991 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6992 +AuStubVoid(dbgaufs_fin, void)
6993 +AuStubInt0(__init dbgaufs_init, void)
6994 +#endif /* CONFIG_DEBUG_FS */
6996 +#endif /* __KERNEL__ */
6997 +#endif /* __DBGAUFS_H__ */
6998 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6999 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7000 +++ linux/fs/aufs/dcsub.c 2018-04-15 08:49:13.397817296 +0200
7003 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7005 + * This program, aufs is free software; you can redistribute it and/or modify
7006 + * it under the terms of the GNU General Public License as published by
7007 + * the Free Software Foundation; either version 2 of the License, or
7008 + * (at your option) any later version.
7010 + * This program is distributed in the hope that it will be useful,
7011 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7012 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7013 + * GNU General Public License for more details.
7015 + * You should have received a copy of the GNU General Public License
7016 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7020 + * sub-routines for dentry cache
7025 +static void au_dpage_free(struct au_dpage *dpage)
7028 + struct dentry **p;
7030 + p = dpage->dentries;
7031 + for (i = 0; i < dpage->ndentry; i++)
7033 + free_page((unsigned long)dpage->dentries);
7036 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7042 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7043 + if (unlikely(!dpages->dpages))
7046 + p = (void *)__get_free_page(gfp);
7050 + dpages->dpages[0].ndentry = 0;
7051 + dpages->dpages[0].dentries = p;
7052 + dpages->ndpage = 1;
7053 + return 0; /* success */
7056 + kfree(dpages->dpages);
7061 +void au_dpages_free(struct au_dcsub_pages *dpages)
7064 + struct au_dpage *p;
7066 + p = dpages->dpages;
7067 + for (i = 0; i < dpages->ndpage; i++)
7068 + au_dpage_free(p++);
7069 + kfree(dpages->dpages);
7072 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7073 + struct dentry *dentry, gfp_t gfp)
7076 + struct au_dpage *dpage;
7079 + dpage = dpages->dpages + dpages->ndpage - 1;
7080 + sz = PAGE_SIZE / sizeof(dentry);
7081 + if (unlikely(dpage->ndentry >= sz)) {
7082 + AuLabel(new dpage);
7084 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7085 + p = au_kzrealloc(dpages->dpages, sz,
7086 + sz + sizeof(*dpages->dpages), gfp,
7091 + dpages->dpages = p;
7092 + dpage = dpages->dpages + dpages->ndpage;
7093 + p = (void *)__get_free_page(gfp);
7097 + dpage->ndentry = 0;
7098 + dpage->dentries = p;
7102 + AuDebugOn(au_dcount(dentry) <= 0);
7103 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7104 + return 0; /* success */
7110 +/* todo: BAD approach */
7111 +/* copied from linux/fs/dcache.c */
7119 +extern void d_walk(struct dentry *parent, void *data,
7120 + enum d_walk_ret (*enter)(void *, struct dentry *),
7121 + void (*finish)(void *));
7123 +struct ac_dpages_arg {
7125 + struct au_dcsub_pages *dpages;
7126 + struct super_block *sb;
7127 + au_dpages_test test;
7131 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7133 + enum d_walk_ret ret;
7134 + struct ac_dpages_arg *arg = _arg;
7136 + ret = D_WALK_CONTINUE;
7137 + if (dentry->d_sb == arg->sb
7138 + && !IS_ROOT(dentry)
7139 + && au_dcount(dentry) > 0
7141 + && (!arg->test || arg->test(dentry, arg->arg))) {
7142 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7143 + if (unlikely(arg->err))
7144 + ret = D_WALK_QUIT;
7150 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7151 + au_dpages_test test, void *arg)
7153 + struct ac_dpages_arg args = {
7161 + d_walk(root, &args, au_call_dpages_append, NULL);
7166 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7167 + int do_include, au_dpages_test test, void *arg)
7172 + write_seqlock(&rename_lock);
7173 + spin_lock(&dentry->d_lock);
7175 + && au_dcount(dentry) > 0
7176 + && (!test || test(dentry, arg)))
7177 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7178 + spin_unlock(&dentry->d_lock);
7179 + if (unlikely(err))
7183 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7186 + while (!IS_ROOT(dentry)) {
7187 + dentry = dentry->d_parent; /* rename_lock is locked */
7188 + spin_lock(&dentry->d_lock);
7189 + if (au_dcount(dentry) > 0
7190 + && (!test || test(dentry, arg)))
7191 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7192 + spin_unlock(&dentry->d_lock);
7193 + if (unlikely(err))
7198 + write_sequnlock(&rename_lock);
7202 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7204 + return au_di(dentry) && dentry->d_sb == arg;
7207 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7208 + struct dentry *dentry, int do_include)
7210 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7211 + au_dcsub_dpages_aufs, dentry->d_sb);
7214 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7216 + struct path path[2] = {
7225 + return path_is_under(path + 0, path + 1);
7227 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7228 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7229 +++ linux/fs/aufs/dcsub.h 2018-04-15 08:49:13.397817296 +0200
7232 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7234 + * This program, aufs is free software; you can redistribute it and/or modify
7235 + * it under the terms of the GNU General Public License as published by
7236 + * the Free Software Foundation; either version 2 of the License, or
7237 + * (at your option) any later version.
7239 + * This program is distributed in the hope that it will be useful,
7240 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7241 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7242 + * GNU General Public License for more details.
7244 + * You should have received a copy of the GNU General Public License
7245 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7249 + * sub-routines for dentry cache
7252 +#ifndef __AUFS_DCSUB_H__
7253 +#define __AUFS_DCSUB_H__
7257 +#include <linux/dcache.h>
7258 +#include <linux/fs.h>
7262 + struct dentry **dentries;
7265 +struct au_dcsub_pages {
7267 + struct au_dpage *dpages;
7270 +/* ---------------------------------------------------------------------- */
7273 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7274 +void au_dpages_free(struct au_dcsub_pages *dpages);
7275 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7276 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7277 + au_dpages_test test, void *arg);
7278 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7279 + int do_include, au_dpages_test test, void *arg);
7280 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7281 + struct dentry *dentry, int do_include);
7282 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7284 +/* ---------------------------------------------------------------------- */
7287 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7288 + * include/linux/dcache.h. Try them (in the future).
7291 +static inline int au_d_hashed_positive(struct dentry *d)
7294 + struct inode *inode = d_inode(d);
7297 + if (unlikely(d_unhashed(d)
7298 + || d_is_negative(d)
7299 + || !inode->i_nlink))
7304 +static inline int au_d_linkable(struct dentry *d)
7307 + struct inode *inode = d_inode(d);
7309 + err = au_d_hashed_positive(d);
7311 + && d_is_positive(d)
7312 + && (inode->i_state & I_LINKABLE))
7317 +static inline int au_d_alive(struct dentry *d)
7320 + struct inode *inode;
7324 + err = au_d_hashed_positive(d);
7326 + inode = d_inode(d);
7327 + if (unlikely(d_unlinked(d)
7328 + || d_is_negative(d)
7329 + || !inode->i_nlink))
7335 +static inline int au_alive_dir(struct dentry *d)
7339 + err = au_d_alive(d);
7340 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7345 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7347 + return a->len == b->len
7348 + && !memcmp(a->name, b->name, a->len);
7353 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7355 + * the type of d_lockref.count became int, but the inlined function d_count()
7356 + * still returns unsigned int.
7357 + * I don't know why. Maybe it is for every d_count() users?
7358 + * Anyway au_dcount() lives on.
7360 +static inline int au_dcount(struct dentry *d)
7362 + return (int)d_count(d);
7365 +#endif /* __KERNEL__ */
7366 +#endif /* __AUFS_DCSUB_H__ */
7367 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7368 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7369 +++ linux/fs/aufs/debug.c 2018-06-04 09:08:09.181412645 +0200
7372 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7374 + * This program, aufs is free software; you can redistribute it and/or modify
7375 + * it under the terms of the GNU General Public License as published by
7376 + * the Free Software Foundation; either version 2 of the License, or
7377 + * (at your option) any later version.
7379 + * This program is distributed in the hope that it will be useful,
7380 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7381 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7382 + * GNU General Public License for more details.
7384 + * You should have received a copy of the GNU General Public License
7385 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7389 + * debug print functions
7394 +/* Returns 0, or -errno. arg is in kp->arg. */
7395 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7399 + err = kstrtoint(val, 0, &n);
7409 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7410 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7415 + return sprintf(buffer, "%d", atomic_read(a));
7418 +static struct kernel_param_ops param_ops_atomic_t = {
7419 + .set = param_atomic_t_set,
7420 + .get = param_atomic_t_get
7421 + /* void (*free)(void *arg) */
7424 +atomic_t aufs_debug = ATOMIC_INIT(0);
7425 +MODULE_PARM_DESC(debug, "debug print");
7426 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7428 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7429 +char *au_plevel = KERN_DEBUG;
7430 +#define dpri(fmt, ...) do { \
7432 + && strcmp(au_plevel, KERN_DEBUG)) \
7433 + || au_debug_test()) \
7434 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7437 +/* ---------------------------------------------------------------------- */
7439 +void au_dpri_whlist(struct au_nhash *whlist)
7441 + unsigned long ul, n;
7442 + struct hlist_head *head;
7443 + struct au_vdir_wh *pos;
7445 + n = whlist->nh_num;
7446 + head = whlist->nh_head;
7447 + for (ul = 0; ul < n; ul++) {
7448 + hlist_for_each_entry(pos, head, wh_hash)
7449 + dpri("b%d, %.*s, %d\n",
7451 + pos->wh_str.len, pos->wh_str.name,
7457 +void au_dpri_vdir(struct au_vdir *vdir)
7460 + union au_vdir_deblk_p p;
7463 + if (!vdir || IS_ERR(vdir)) {
7464 + dpri("err %ld\n", PTR_ERR(vdir));
7468 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7469 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7470 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7471 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7472 + p.deblk = vdir->vd_deblk[ul];
7474 + dpri("[%lu]: %p\n", ul, o);
7478 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7479 + struct dentry *wh)
7484 + if (!inode || IS_ERR(inode)) {
7485 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7489 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7490 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7491 + && sizeof(inode->i_blocks) != sizeof(u64));
7493 + n = (void *)wh->d_name.name;
7494 + l = wh->d_name.len;
7497 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7498 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7500 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7501 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7502 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7503 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7504 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7505 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7506 + inode->i_generation,
7507 + l ? ", wh " : "", l, n);
7511 +void au_dpri_inode(struct inode *inode)
7513 + struct au_iinfo *iinfo;
7514 + struct au_hinode *hi;
7515 + aufs_bindex_t bindex;
7518 + err = do_pri_inode(-1, inode, -1, NULL);
7519 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7522 + iinfo = au_ii(inode);
7523 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7524 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7525 + if (iinfo->ii_btop < 0)
7528 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7529 + hi = au_hinode(iinfo, bindex);
7531 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7535 +void au_dpri_dalias(struct inode *inode)
7539 + spin_lock(&inode->i_lock);
7540 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7541 + au_dpri_dentry(d);
7542 + spin_unlock(&inode->i_lock);
7545 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7547 + struct dentry *wh = NULL;
7549 + struct inode *inode;
7550 + struct au_iinfo *iinfo;
7551 + struct au_hinode *hi;
7553 + if (!dentry || IS_ERR(dentry)) {
7554 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7557 + /* do not call dget_parent() here */
7558 + /* note: access d_xxx without d_lock */
7559 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7560 + bindex, dentry, dentry,
7561 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7562 + au_dcount(dentry), dentry->d_flags,
7563 + d_unhashed(dentry) ? "un" : "");
7566 + if (d_is_positive(dentry))
7567 + inode = d_inode(dentry);
7569 + && au_test_aufs(dentry->d_sb)
7571 + && !au_is_bad_inode(inode)) {
7572 + iinfo = au_ii(inode);
7573 + hi = au_hinode(iinfo, bindex);
7575 + wh = hi->hi_whdentry;
7577 + do_pri_inode(bindex, inode, hn, wh);
7581 +void au_dpri_dentry(struct dentry *dentry)
7583 + struct au_dinfo *dinfo;
7584 + aufs_bindex_t bindex;
7587 + err = do_pri_dentry(-1, dentry);
7588 + if (err || !au_test_aufs(dentry->d_sb))
7591 + dinfo = au_di(dentry);
7594 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7595 + dinfo->di_btop, dinfo->di_bbot,
7596 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7597 + dinfo->di_tmpfile);
7598 + if (dinfo->di_btop < 0)
7600 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7601 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7604 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7608 + if (!file || IS_ERR(file)) {
7609 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7614 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7615 + && au_test_aufs(file->f_path.dentry->d_sb)
7617 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7618 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7619 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7620 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7621 + file->f_version, file->f_pos, a);
7622 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7623 + do_pri_dentry(bindex, file->f_path.dentry);
7627 +void au_dpri_file(struct file *file)
7629 + struct au_finfo *finfo;
7630 + struct au_fidir *fidir;
7631 + struct au_hfile *hfile;
7632 + aufs_bindex_t bindex;
7635 + err = do_pri_file(-1, file);
7637 + || IS_ERR_OR_NULL(file->f_path.dentry)
7638 + || !au_test_aufs(file->f_path.dentry->d_sb))
7641 + finfo = au_fi(file);
7644 + if (finfo->fi_btop < 0)
7646 + fidir = finfo->fi_hdir;
7648 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7650 + for (bindex = finfo->fi_btop;
7651 + bindex >= 0 && bindex <= fidir->fd_bbot;
7653 + hfile = fidir->fd_hfile + bindex;
7654 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7658 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7660 + struct vfsmount *mnt;
7661 + struct super_block *sb;
7663 + if (!br || IS_ERR(br))
7665 + mnt = au_br_mnt(br);
7666 + if (!mnt || IS_ERR(mnt))
7669 + if (!sb || IS_ERR(sb))
7672 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7673 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7675 + bindex, br->br_perm, br->br_id, au_br_count(br),
7676 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7677 + sb->s_flags, sb->s_count,
7678 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7682 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7686 +void au_dpri_sb(struct super_block *sb)
7688 + struct au_sbinfo *sbinfo;
7689 + aufs_bindex_t bindex;
7691 + /* to reuduce stack size */
7693 + struct vfsmount mnt;
7694 + struct au_branch fake;
7697 + /* this function can be called from magic sysrq */
7698 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7699 + if (unlikely(!a)) {
7700 + dpri("no memory\n");
7704 + a->mnt.mnt_sb = sb;
7705 + a->fake.br_path.mnt = &a->mnt;
7706 + au_br_count_init(&a->fake);
7707 + err = do_pri_br(-1, &a->fake);
7708 + au_br_count_fin(&a->fake);
7710 + dpri("dev 0x%x\n", sb->s_dev);
7711 + if (err || !au_test_aufs(sb))
7714 + sbinfo = au_sbi(sb);
7717 + dpri("nw %d, gen %u, kobj %d\n",
7718 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7719 + kref_read(&sbinfo->si_kobj.kref));
7720 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7721 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7724 +/* ---------------------------------------------------------------------- */
7726 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7728 + struct inode *h_inode, *inode = d_inode(dentry);
7729 + struct dentry *h_dentry;
7730 + aufs_bindex_t bindex, bbot, bi;
7732 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7735 + bbot = au_dbbot(dentry);
7736 + bi = au_ibbot(inode);
7739 + bindex = au_dbtop(dentry);
7740 + bi = au_ibtop(inode);
7744 + for (; bindex <= bbot; bindex++) {
7745 + h_dentry = au_h_dptr(dentry, bindex);
7748 + h_inode = au_h_iptr(inode, bindex);
7749 + if (unlikely(h_inode != d_inode(h_dentry))) {
7751 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7752 + AuDbgDentry(dentry);
7753 + AuDbgInode(inode);
7760 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7763 + struct au_dcsub_pages dpages;
7764 + struct au_dpage *dpage;
7765 + struct dentry **dentries;
7767 + err = au_dpages_init(&dpages, GFP_NOFS);
7769 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7771 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7772 + dpage = dpages.dpages + i;
7773 + dentries = dpage->dentries;
7774 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7775 + AuDebugOn(au_digen_test(dentries[j], sigen));
7777 + au_dpages_free(&dpages);
7780 +void au_dbg_verify_kthread(void)
7782 + if (au_wkq_test()) {
7785 + * It may be recursive, but udba=notify between two aufs mounts,
7786 + * where a single ro branch is shared, is not a problem.
7792 +/* ---------------------------------------------------------------------- */
7794 +int __init au_debug_init(void)
7796 + aufs_bindex_t bindex;
7797 + struct au_vdir_destr destr;
7800 + AuDebugOn(bindex >= 0);
7803 + AuDebugOn(destr.len < NAME_MAX);
7805 +#ifdef CONFIG_4KSTACKS
7806 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7811 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7812 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7813 +++ linux/fs/aufs/debug.h 2018-04-15 08:49:13.397817296 +0200
7816 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7818 + * This program, aufs is free software; you can redistribute it and/or modify
7819 + * it under the terms of the GNU General Public License as published by
7820 + * the Free Software Foundation; either version 2 of the License, or
7821 + * (at your option) any later version.
7823 + * This program is distributed in the hope that it will be useful,
7824 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7825 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7826 + * GNU General Public License for more details.
7828 + * You should have received a copy of the GNU General Public License
7829 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7833 + * debug print functions
7836 +#ifndef __AUFS_DEBUG_H__
7837 +#define __AUFS_DEBUG_H__
7841 +#include <linux/atomic.h>
7842 +#include <linux/module.h>
7843 +#include <linux/kallsyms.h>
7844 +#include <linux/sysrq.h>
7846 +#ifdef CONFIG_AUFS_DEBUG
7847 +#define AuDebugOn(a) BUG_ON(a)
7849 +/* module parameter */
7850 +extern atomic_t aufs_debug;
7851 +static inline void au_debug_on(void)
7853 + atomic_inc(&aufs_debug);
7855 +static inline void au_debug_off(void)
7857 + atomic_dec_if_positive(&aufs_debug);
7860 +static inline int au_debug_test(void)
7862 + return atomic_read(&aufs_debug) > 0;
7865 +#define AuDebugOn(a) do {} while (0)
7866 +AuStubVoid(au_debug_on, void)
7867 +AuStubVoid(au_debug_off, void)
7868 +AuStubInt0(au_debug_test, void)
7869 +#endif /* CONFIG_AUFS_DEBUG */
7871 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7873 +/* ---------------------------------------------------------------------- */
7877 +#define AuDbg(fmt, ...) do { \
7878 + if (au_debug_test()) \
7879 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7881 +#define AuLabel(l) AuDbg(#l "\n")
7882 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7883 +#define AuWarn1(fmt, ...) do { \
7884 + static unsigned char _c; \
7886 + pr_warn(fmt, ##__VA_ARGS__); \
7889 +#define AuErr1(fmt, ...) do { \
7890 + static unsigned char _c; \
7892 + pr_err(fmt, ##__VA_ARGS__); \
7895 +#define AuIOErr1(fmt, ...) do { \
7896 + static unsigned char _c; \
7898 + AuIOErr(fmt, ##__VA_ARGS__); \
7901 +#define AuUnsupportMsg "This operation is not supported." \
7902 + " Please report this application to aufs-users ML."
7903 +#define AuUnsupport(fmt, ...) do { \
7904 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7908 +#define AuTraceErr(e) do { \
7909 + if (unlikely((e) < 0)) \
7910 + AuDbg("err %d\n", (int)(e)); \
7913 +#define AuTraceErrPtr(p) do { \
7915 + AuDbg("err %ld\n", PTR_ERR(p)); \
7918 +/* dirty macros for debug print, use with "%.*s" and caution */
7919 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7921 +/* ---------------------------------------------------------------------- */
7924 +#ifdef CONFIG_AUFS_DEBUG
7925 +extern struct mutex au_dbg_mtx;
7926 +extern char *au_plevel;
7928 +void au_dpri_whlist(struct au_nhash *whlist);
7930 +void au_dpri_vdir(struct au_vdir *vdir);
7932 +void au_dpri_inode(struct inode *inode);
7933 +void au_dpri_dalias(struct inode *inode);
7934 +void au_dpri_dentry(struct dentry *dentry);
7936 +void au_dpri_file(struct file *filp);
7937 +struct super_block;
7938 +void au_dpri_sb(struct super_block *sb);
7940 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7941 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7942 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7943 +void au_dbg_verify_kthread(void);
7945 +int __init au_debug_init(void);
7947 +#define AuDbgWhlist(w) do { \
7948 + mutex_lock(&au_dbg_mtx); \
7950 + au_dpri_whlist(w); \
7951 + mutex_unlock(&au_dbg_mtx); \
7954 +#define AuDbgVdir(v) do { \
7955 + mutex_lock(&au_dbg_mtx); \
7957 + au_dpri_vdir(v); \
7958 + mutex_unlock(&au_dbg_mtx); \
7961 +#define AuDbgInode(i) do { \
7962 + mutex_lock(&au_dbg_mtx); \
7964 + au_dpri_inode(i); \
7965 + mutex_unlock(&au_dbg_mtx); \
7968 +#define AuDbgDAlias(i) do { \
7969 + mutex_lock(&au_dbg_mtx); \
7971 + au_dpri_dalias(i); \
7972 + mutex_unlock(&au_dbg_mtx); \
7975 +#define AuDbgDentry(d) do { \
7976 + mutex_lock(&au_dbg_mtx); \
7978 + au_dpri_dentry(d); \
7979 + mutex_unlock(&au_dbg_mtx); \
7982 +#define AuDbgFile(f) do { \
7983 + mutex_lock(&au_dbg_mtx); \
7985 + au_dpri_file(f); \
7986 + mutex_unlock(&au_dbg_mtx); \
7989 +#define AuDbgSb(sb) do { \
7990 + mutex_lock(&au_dbg_mtx); \
7991 + AuDbg(#sb "\n"); \
7993 + mutex_unlock(&au_dbg_mtx); \
7996 +#define AuDbgSym(addr) do { \
7997 + char sym[KSYM_SYMBOL_LEN]; \
7998 + sprint_symbol(sym, (unsigned long)addr); \
7999 + AuDbg("%s\n", sym); \
8002 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8003 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8004 +AuStubVoid(au_dbg_verify_kthread, void)
8005 +AuStubInt0(__init au_debug_init, void)
8007 +#define AuDbgWhlist(w) do {} while (0)
8008 +#define AuDbgVdir(v) do {} while (0)
8009 +#define AuDbgInode(i) do {} while (0)
8010 +#define AuDbgDAlias(i) do {} while (0)
8011 +#define AuDbgDentry(d) do {} while (0)
8012 +#define AuDbgFile(f) do {} while (0)
8013 +#define AuDbgSb(sb) do {} while (0)
8014 +#define AuDbgSym(addr) do {} while (0)
8015 +#endif /* CONFIG_AUFS_DEBUG */
8017 +/* ---------------------------------------------------------------------- */
8019 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8020 +int __init au_sysrq_init(void);
8021 +void au_sysrq_fin(void);
8023 +#ifdef CONFIG_HW_CONSOLE
8024 +#define au_dbg_blocked() do { \
8026 + handle_sysrq('w'); \
8029 +AuStubVoid(au_dbg_blocked, void)
8033 +AuStubInt0(__init au_sysrq_init, void)
8034 +AuStubVoid(au_sysrq_fin, void)
8035 +AuStubVoid(au_dbg_blocked, void)
8036 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8038 +#endif /* __KERNEL__ */
8039 +#endif /* __AUFS_DEBUG_H__ */
8040 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8041 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8042 +++ linux/fs/aufs/dentry.c 2018-06-04 09:08:09.184746078 +0200
8045 + * Copyright (C) 2005-2018 Junjiro R. Okajima
8047 + * This program, aufs is free software; you can redistribute it and/or modify
8048 + * it under the terms of the GNU General Public License as published by
8049 + * the Free Software Foundation; either version 2 of the License, or
8050 + * (at your option) any later version.
8052 + * This program is distributed in the hope that it will be useful,
8053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8055 + * GNU General Public License for more details.
8057 + * You should have received a copy of the GNU General Public License
8058 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8062 + * lookup and dentry operations
8065 +#include <linux/namei.h>
8069 + * returns positive/negative dentry, NULL or an error.
8070 + * NULL means whiteout-ed or not-found.
8072 +static struct dentry*
8073 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8074 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8076 + struct dentry *h_dentry;
8077 + struct inode *h_inode;
8078 + struct au_branch *br;
8079 + int wh_found, opq;
8080 + unsigned char wh_able;
8081 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8082 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8086 + br = au_sbr(dentry->d_sb, bindex);
8087 + wh_able = !!au_br_whable(br->br_perm);
8089 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8090 + h_dentry = ERR_PTR(wh_found);
8093 + if (unlikely(wh_found < 0))
8096 + /* We found a whiteout */
8097 + /* au_set_dbbot(dentry, bindex); */
8098 + au_set_dbwh(dentry, bindex);
8100 + return NULL; /* success */
8104 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8106 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8107 + if (IS_ERR(h_dentry)) {
8108 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8114 + h_inode = d_inode(h_dentry);
8115 + if (d_is_negative(h_dentry)) {
8118 + } else if (wh_found
8119 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8121 + else if (au_ftest_lkup(args->flags, DIRREN)
8123 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8124 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8125 + (unsigned long long)h_inode->i_ino);
8129 + if (au_dbbot(dentry) <= bindex)
8130 + au_set_dbbot(dentry, bindex);
8131 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8132 + au_set_dbtop(dentry, bindex);
8133 + au_set_h_dptr(dentry, bindex, h_dentry);
8135 + if (!d_is_dir(h_dentry)
8137 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8138 + goto out; /* success */
8140 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8141 + opq = au_diropq_test(h_dentry);
8142 + inode_unlock_shared(h_inode);
8144 + au_set_dbdiropq(dentry, bindex);
8145 + else if (unlikely(opq < 0)) {
8146 + au_set_h_dptr(dentry, bindex, NULL);
8147 + h_dentry = ERR_PTR(opq);
8158 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8160 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8161 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8167 + * returns the number of lower positive dentries,
8168 + * otherwise an error.
8169 + * can be called at unlinking with @type is zero.
8171 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8172 + unsigned int flags)
8174 + int npositive, err;
8175 + aufs_bindex_t bindex, btail, bdiropq;
8176 + unsigned char isdir, dirperm1, dirren;
8177 + struct au_do_lookup_args args = {
8179 + .name = &dentry->d_name
8181 + struct dentry *parent;
8182 + struct super_block *sb;
8184 + sb = dentry->d_sb;
8185 + err = au_test_shwh(sb, args.name);
8186 + if (unlikely(err))
8189 + err = au_wh_name_alloc(&args.whname, args.name);
8190 + if (unlikely(err))
8193 + isdir = !!d_is_dir(dentry);
8194 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8195 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8197 + au_fset_lkup(args.flags, DIRREN);
8200 + parent = dget_parent(dentry);
8201 + btail = au_dbtaildir(parent);
8202 + for (bindex = btop; bindex <= btail; bindex++) {
8203 + struct dentry *h_parent, *h_dentry;
8204 + struct inode *h_inode, *h_dir;
8205 + struct au_branch *br;
8207 + h_dentry = au_h_dptr(dentry, bindex);
8209 + if (d_is_positive(h_dentry))
8213 + h_parent = au_h_dptr(parent, bindex);
8214 + if (!h_parent || !d_is_dir(h_parent))
8218 + /* if the inum matches, then use the prepared name */
8219 + err = au_dr_lkup_name(&args, bindex);
8220 + if (unlikely(err))
8224 + h_dir = d_inode(h_parent);
8225 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8226 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8227 + inode_unlock_shared(h_dir);
8228 + err = PTR_ERR(h_dentry);
8229 + if (IS_ERR(h_dentry))
8232 + au_fclr_lkup(args.flags, ALLOW_NEG);
8234 + au_fset_lkup(args.flags, IGNORE_PERM);
8236 + if (au_dbwh(dentry) == bindex)
8240 + if (d_is_negative(h_dentry))
8242 + h_inode = d_inode(h_dentry);
8245 + args.type = h_inode->i_mode & S_IFMT;
8246 + if (args.type != S_IFDIR)
8249 + /* the type of lower may be different */
8250 + bdiropq = au_dbdiropq(dentry);
8251 + if (bdiropq >= 0 && bdiropq <= bindex)
8254 + br = au_sbr(sb, bindex);
8256 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8257 + /*add_ent*/NULL)) {
8258 + /* prepare next name to lookup */
8259 + err = au_dr_lkup(&args, dentry, bindex);
8260 + if (unlikely(err))
8266 + AuLabel(positive);
8267 + au_update_dbtop(dentry);
8270 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8271 + && au_dbtop(dentry) < 0)) {
8273 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8279 + kfree(args.whname.name);
8281 + au_dr_lkup_fin(&args);
8286 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8288 + struct dentry *dentry;
8291 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8292 + dentry = vfsub_lkup_one(name, parent);
8294 + struct vfsub_lkup_one_args args = {
8300 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8301 + if (unlikely(wkq_err))
8302 + dentry = ERR_PTR(wkq_err);
8309 + * lookup @dentry on @bindex which should be negative.
8311 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8314 + struct dentry *parent, *h_parent, *h_dentry;
8315 + struct au_branch *br;
8317 + parent = dget_parent(dentry);
8318 + h_parent = au_h_dptr(parent, bindex);
8319 + br = au_sbr(dentry->d_sb, bindex);
8321 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8323 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8324 + err = PTR_ERR(h_dentry);
8325 + if (IS_ERR(h_dentry))
8327 + if (unlikely(d_is_positive(h_dentry))) {
8329 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8335 + if (bindex < au_dbtop(dentry))
8336 + au_set_dbtop(dentry, bindex);
8337 + if (au_dbbot(dentry) < bindex)
8338 + au_set_dbbot(dentry, bindex);
8339 + au_set_h_dptr(dentry, bindex, h_dentry);
8346 +/* ---------------------------------------------------------------------- */
8348 +/* subset of struct inode */
8350 + unsigned long i_ino;
8351 + /* unsigned int i_nlink; */
8357 + blkcnt_t i_blocks;
8362 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8364 + ia->i_ino = h_inode->i_ino;
8365 + /* ia->i_nlink = h_inode->i_nlink; */
8366 + ia->i_uid = h_inode->i_uid;
8367 + ia->i_gid = h_inode->i_gid;
8368 + ia->i_version = inode_query_iversion(h_inode);
8370 + ia->i_size = h_inode->i_size;
8371 + ia->i_blocks = h_inode->i_blocks;
8373 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8376 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8378 + return ia->i_ino != h_inode->i_ino
8379 + /* || ia->i_nlink != h_inode->i_nlink */
8380 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8381 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8382 + || !inode_eq_iversion(h_inode, ia->i_version)
8384 + || ia->i_size != h_inode->i_size
8385 + || ia->i_blocks != h_inode->i_blocks
8387 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8390 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8391 + struct au_branch *br)
8394 + struct au_iattr ia;
8395 + struct inode *h_inode;
8396 + struct dentry *h_d;
8397 + struct super_block *h_sb;
8400 + memset(&ia, -1, sizeof(ia));
8401 + h_sb = h_dentry->d_sb;
8403 + if (d_is_positive(h_dentry)) {
8404 + h_inode = d_inode(h_dentry);
8405 + au_iattr_save(&ia, h_inode);
8406 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8407 + /* nfs d_revalidate may return 0 for negative dentry */
8408 + /* fuse d_revalidate always return 0 for negative dentry */
8411 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8412 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8413 + err = PTR_ERR(h_d);
8418 + if (unlikely(h_d != h_dentry
8419 + || d_inode(h_d) != h_inode
8420 + || (h_inode && au_iattr_test(&ia, h_inode))))
8421 + err = au_busy_or_stale();
8429 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8430 + struct dentry *h_parent, struct au_branch *br)
8435 + if (udba == AuOpt_UDBA_REVAL
8436 + && !au_test_fs_remote(h_dentry->d_sb)) {
8438 + err = (d_inode(h_dentry->d_parent) != h_dir);
8439 + } else if (udba != AuOpt_UDBA_NONE)
8440 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8445 +/* ---------------------------------------------------------------------- */
8447 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8450 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8451 + struct au_hdentry tmp, *p, *q;
8452 + struct au_dinfo *dinfo;
8453 + struct super_block *sb;
8455 + DiMustWriteLock(dentry);
8457 + sb = dentry->d_sb;
8458 + dinfo = au_di(dentry);
8459 + bbot = dinfo->di_bbot;
8460 + bwh = dinfo->di_bwh;
8461 + bdiropq = dinfo->di_bdiropq;
8462 + bindex = dinfo->di_btop;
8463 + p = au_hdentry(dinfo, bindex);
8464 + for (; bindex <= bbot; bindex++, p++) {
8465 + if (!p->hd_dentry)
8468 + new_bindex = au_br_index(sb, p->hd_id);
8469 + if (new_bindex == bindex)
8472 + if (dinfo->di_bwh == bindex)
8474 + if (dinfo->di_bdiropq == bindex)
8475 + bdiropq = new_bindex;
8476 + if (new_bindex < 0) {
8478 + p->hd_dentry = NULL;
8482 + /* swap two lower dentries, and loop again */
8483 + q = au_hdentry(dinfo, new_bindex);
8487 + if (tmp.hd_dentry) {
8493 + dinfo->di_bwh = -1;
8494 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8495 + dinfo->di_bwh = bwh;
8497 + dinfo->di_bdiropq = -1;
8499 + && bdiropq <= au_sbbot(sb)
8500 + && au_sbr_whable(sb, bdiropq))
8501 + dinfo->di_bdiropq = bdiropq;
8504 + dinfo->di_btop = -1;
8505 + dinfo->di_bbot = -1;
8506 + bbot = au_dbbot(parent);
8508 + p = au_hdentry(dinfo, bindex);
8509 + for (; bindex <= bbot; bindex++, p++)
8510 + if (p->hd_dentry) {
8511 + dinfo->di_btop = bindex;
8515 + if (dinfo->di_btop >= 0) {
8517 + p = au_hdentry(dinfo, bindex);
8518 + for (; bindex >= 0; bindex--, p--)
8519 + if (p->hd_dentry) {
8520 + dinfo->di_bbot = bindex;
8529 +static void au_do_hide(struct dentry *dentry)
8531 + struct inode *inode;
8533 + if (d_really_is_positive(dentry)) {
8534 + inode = d_inode(dentry);
8535 + if (!d_is_dir(dentry)) {
8536 + if (inode->i_nlink && !d_unhashed(dentry))
8537 + drop_nlink(inode);
8539 + clear_nlink(inode);
8540 + /* stop next lookup */
8541 + inode->i_flags |= S_DEAD;
8543 + smp_mb(); /* necessary? */
8548 +static int au_hide_children(struct dentry *parent)
8550 + int err, i, j, ndentry;
8551 + struct au_dcsub_pages dpages;
8552 + struct au_dpage *dpage;
8553 + struct dentry *dentry;
8555 + err = au_dpages_init(&dpages, GFP_NOFS);
8556 + if (unlikely(err))
8558 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8559 + if (unlikely(err))
8562 + /* in reverse order */
8563 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8564 + dpage = dpages.dpages + i;
8565 + ndentry = dpage->ndentry;
8566 + for (j = ndentry - 1; j >= 0; j--) {
8567 + dentry = dpage->dentries[j];
8568 + if (dentry != parent)
8569 + au_do_hide(dentry);
8574 + au_dpages_free(&dpages);
8579 +static void au_hide(struct dentry *dentry)
8583 + AuDbgDentry(dentry);
8584 + if (d_is_dir(dentry)) {
8585 + /* shrink_dcache_parent(dentry); */
8586 + err = au_hide_children(dentry);
8587 + if (unlikely(err))
8588 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8591 + au_do_hide(dentry);
8595 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8597 + * a dirty branch is added
8598 + * - on the top of layers
8599 + * - in the middle of layers
8600 + * - to the bottom of layers
8602 + * on the added branch there exists
8605 + * - a same named entry
8607 + * * negative --> positive
8608 + * * positive --> positive
8609 + * - type is unchanged
8610 + * - type is changed
8612 + * * negative --> negative
8613 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8616 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8617 + struct au_dinfo *tmp)
8620 + aufs_bindex_t bindex, bbot;
8622 + struct dentry *dentry;
8623 + struct inode *inode;
8625 + } orig_h, tmp_h = {
8628 + struct au_hdentry *hd;
8629 + struct inode *inode, *h_inode;
8630 + struct dentry *h_dentry;
8633 + AuDebugOn(dinfo->di_btop < 0);
8635 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8636 + orig_h.inode = NULL;
8637 + if (d_is_positive(orig_h.dentry)) {
8638 + orig_h.inode = d_inode(orig_h.dentry);
8639 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8641 + if (tmp->di_btop >= 0) {
8642 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8643 + if (d_is_positive(tmp_h.dentry)) {
8644 + tmp_h.inode = d_inode(tmp_h.dentry);
8645 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8650 + if (d_really_is_positive(dentry))
8651 + inode = d_inode(dentry);
8652 + if (!orig_h.inode) {
8653 + AuDbg("nagative originally\n");
8659 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8660 + AuDebugOn(dinfo->di_bdiropq != -1);
8662 + if (!tmp_h.inode) {
8663 + AuDbg("negative --> negative\n");
8664 + /* should have only one negative lower */
8665 + if (tmp->di_btop >= 0
8666 + && tmp->di_btop < dinfo->di_btop) {
8667 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8668 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8669 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8670 + au_di_cp(dinfo, tmp);
8671 + hd = au_hdentry(tmp, tmp->di_btop);
8672 + au_set_h_dptr(dentry, tmp->di_btop,
8673 + dget(hd->hd_dentry));
8675 + au_dbg_verify_dinode(dentry);
8677 + AuDbg("negative --> positive\n");
8679 + * similar to the behaviour of creating with bypassing
8681 + * unhash it in order to force an error in the
8682 + * succeeding create operation.
8683 + * we should not set S_DEAD here.
8686 + /* au_di_swap(tmp, dinfo); */
8687 + au_dbg_verify_dinode(dentry);
8690 + AuDbg("positive originally\n");
8691 + /* inode may be NULL */
8692 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8693 + if (!tmp_h.inode) {
8694 + AuDbg("positive --> negative\n");
8695 + /* or bypassing aufs */
8697 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8698 + dinfo->di_bwh = tmp->di_bwh;
8700 + err = au_refresh_hinode_self(inode);
8701 + au_dbg_verify_dinode(dentry);
8702 + } else if (orig_h.mode == tmp_h.mode) {
8703 + AuDbg("positive --> positive, same type\n");
8704 + if (!S_ISDIR(orig_h.mode)
8705 + && dinfo->di_btop > tmp->di_btop) {
8707 + * similar to the behaviour of removing and
8712 + err = au_refresh_hinode_self(inode);
8713 + au_dbg_verify_dinode(dentry);
8715 + /* fill empty slots */
8716 + if (dinfo->di_btop > tmp->di_btop)
8717 + dinfo->di_btop = tmp->di_btop;
8718 + if (dinfo->di_bbot < tmp->di_bbot)
8719 + dinfo->di_bbot = tmp->di_bbot;
8720 + dinfo->di_bwh = tmp->di_bwh;
8721 + dinfo->di_bdiropq = tmp->di_bdiropq;
8722 + bbot = dinfo->di_bbot;
8723 + bindex = tmp->di_btop;
8724 + hd = au_hdentry(tmp, bindex);
8725 + for (; bindex <= bbot; bindex++, hd++) {
8726 + if (au_h_dptr(dentry, bindex))
8728 + h_dentry = hd->hd_dentry;
8731 + AuDebugOn(d_is_negative(h_dentry));
8732 + h_inode = d_inode(h_dentry);
8733 + AuDebugOn(orig_h.mode
8734 + != (h_inode->i_mode
8736 + au_set_h_dptr(dentry, bindex,
8740 + err = au_refresh_hinode(inode, dentry);
8741 + au_dbg_verify_dinode(dentry);
8744 + AuDbg("positive --> positive, different type\n");
8745 + /* similar to the behaviour of removing and creating */
8748 + err = au_refresh_hinode_self(inode);
8749 + au_dbg_verify_dinode(dentry);
8757 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8759 + const struct dentry_operations *dop
8760 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8761 + static const unsigned int mask
8762 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8764 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8766 + if (dentry->d_op == dop)
8769 + AuDbg("%pd\n", dentry);
8770 + spin_lock(&dentry->d_lock);
8771 + if (dop == &aufs_dop)
8772 + dentry->d_flags |= mask;
8774 + dentry->d_flags &= ~mask;
8775 + dentry->d_op = dop;
8776 + spin_unlock(&dentry->d_lock);
8779 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8781 + int err, ebrange, nbr;
8782 + unsigned int sigen;
8783 + struct au_dinfo *dinfo, *tmp;
8784 + struct super_block *sb;
8785 + struct inode *inode;
8787 + DiMustWriteLock(dentry);
8788 + AuDebugOn(IS_ROOT(dentry));
8789 + AuDebugOn(d_really_is_negative(parent));
8791 + sb = dentry->d_sb;
8792 + sigen = au_sigen(sb);
8793 + err = au_digen_test(parent, sigen);
8794 + if (unlikely(err))
8797 + nbr = au_sbbot(sb) + 1;
8798 + dinfo = au_di(dentry);
8799 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8800 + if (unlikely(err))
8802 + ebrange = au_dbrange_test(dentry);
8804 + ebrange = au_do_refresh_hdentry(dentry, parent);
8806 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8807 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8808 + if (d_really_is_positive(dentry)) {
8809 + inode = d_inode(dentry);
8810 + err = au_refresh_hinode_self(inode);
8812 + au_dbg_verify_dinode(dentry);
8814 + goto out_dgen; /* success */
8818 + /* temporary dinfo */
8819 + AuDbgDentry(dentry);
8821 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8822 + if (unlikely(!tmp))
8824 + au_di_swap(tmp, dinfo);
8825 + /* returns the number of positive dentries */
8827 + * if current working dir is removed, it returns an error.
8828 + * but the dentry is legal.
8830 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8831 + AuDbgDentry(dentry);
8832 + au_di_swap(tmp, dinfo);
8833 + if (err == -ENOENT)
8836 + /* compare/refresh by dinfo */
8837 + AuDbgDentry(dentry);
8838 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8839 + au_dbg_verify_dinode(dentry);
8842 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8843 + au_rw_write_unlock(&tmp->di_rwsem);
8845 + if (unlikely(err))
8849 + au_update_digen(dentry);
8851 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8852 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8853 + AuDbgDentry(dentry);
8859 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8860 + struct dentry *dentry, aufs_bindex_t bindex)
8865 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8868 + AuDbg("b%d\n", bindex);
8870 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8871 + * due to whiteout and branch permission.
8873 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8874 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8875 + /* it may return tri-state */
8876 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8878 + if (unlikely(valid < 0))
8888 +/* todo: remove this */
8889 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8890 + unsigned int flags, int do_udba, int dirren)
8893 + umode_t mode, h_mode;
8894 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8895 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8896 + struct inode *h_inode, *h_cached_inode;
8897 + struct dentry *h_dentry;
8898 + struct qstr *name, *h_name;
8905 + unhashed = !!d_unhashed(dentry);
8906 + is_root = !!IS_ROOT(dentry);
8907 + name = &dentry->d_name;
8908 + tmpfile = au_di(dentry)->di_tmpfile;
8911 + * Theoretically, REVAL test should be unnecessary in case of
8913 + * But {fs,i}notify doesn't fire some necessary events,
8914 + * IN_ATTRIB for atime/nlink/pageio
8915 + * Let's do REVAL test too.
8917 + if (do_udba && inode) {
8918 + mode = (inode->i_mode & S_IFMT);
8919 + plus = (inode->i_nlink > 0);
8920 + ibs = au_ibtop(inode);
8921 + ibe = au_ibbot(inode);
8924 + btop = au_dbtop(dentry);
8926 + if (inode && S_ISDIR(inode->i_mode))
8927 + btail = au_dbtaildir(dentry);
8928 + for (bindex = btop; bindex <= btail; bindex++) {
8929 + h_dentry = au_h_dptr(dentry, bindex);
8933 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8934 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8935 + spin_lock(&h_dentry->d_lock);
8936 + h_name = &h_dentry->d_name;
8937 + if (unlikely(do_udba
8940 + && (unhashed != !!d_unhashed(h_dentry)
8941 + || (!tmpfile && !dirren
8942 + && !au_qstreq(name, h_name))
8945 + && !(flags & LOOKUP_OPEN)
8946 + && (h_dentry->d_flags
8947 + & DCACHE_NFSFS_RENAMED)))
8951 + h_unhashed = d_unhashed(h_dentry);
8952 + spin_unlock(&h_dentry->d_lock);
8953 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8954 + unhashed, h_unhashed, dentry, h_dentry);
8957 + spin_unlock(&h_dentry->d_lock);
8959 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8960 + if (unlikely(err))
8961 + /* do not goto err, to keep the errno */
8964 + /* todo: plink too? */
8969 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8973 + if (d_is_positive(h_dentry))
8974 + h_inode = d_inode(h_dentry);
8977 + h_cached_inode = h_inode;
8979 + h_mode = (h_inode->i_mode & S_IFMT);
8980 + h_plus = (h_inode->i_nlink > 0);
8982 + if (inode && ibs <= bindex && bindex <= ibe)
8983 + h_cached_inode = au_h_iptr(inode, bindex);
8986 + if (unlikely(plus != h_plus && !tmpfile))
8989 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8991 + && !IS_ROOT(h_dentry)
8992 + && unhashed != d_unhashed(h_dentry)))
8995 + if (unlikely(mode != h_mode
8996 + || h_cached_inode != h_inode))
9009 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9010 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9013 + struct dentry *parent;
9015 + if (!au_digen_test(dentry, sigen))
9018 + parent = dget_parent(dentry);
9019 + di_read_lock_parent(parent, AuLock_IR);
9020 + AuDebugOn(au_digen_test(parent, sigen));
9021 + au_dbg_verify_gen(parent, sigen);
9022 + err = au_refresh_dentry(dentry, parent);
9023 + di_read_unlock(parent, AuLock_IR);
9029 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9032 + struct dentry *d, *parent;
9034 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9035 + return simple_reval_dpath(dentry, sigen);
9037 + /* slow loop, keep it simple and stupid */
9038 + /* cf: au_cpup_dirs() */
9041 + while (au_digen_test(dentry, sigen)) {
9045 + parent = dget_parent(d);
9046 + if (!au_digen_test(parent, sigen))
9052 + di_write_lock_child2(d);
9054 + /* someone might update our dentry while we were sleeping */
9055 + if (au_digen_test(d, sigen)) {
9057 + * todo: consolidate with simple_reval_dpath(),
9058 + * do_refresh() and au_reval_for_attr().
9060 + di_read_lock_parent(parent, AuLock_IR);
9061 + err = au_refresh_dentry(d, parent);
9062 + di_read_unlock(parent, AuLock_IR);
9066 + di_write_unlock(d);
9068 + if (unlikely(err))
9076 + * if valid returns 1, otherwise 0.
9078 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9081 + unsigned int sigen;
9082 + unsigned char do_udba, dirren;
9083 + struct super_block *sb;
9084 + struct inode *inode;
9086 + /* todo: support rcu-walk? */
9087 + if (flags & LOOKUP_RCU)
9091 + if (unlikely(!au_di(dentry)))
9095 + sb = dentry->d_sb;
9098 + * i_mutex of parent dir may be held,
9099 + * but we should not return 'invalid' due to busy.
9101 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9102 + if (unlikely(err)) {
9108 + if (d_really_is_positive(dentry))
9109 + inode = d_inode(dentry);
9110 + if (unlikely(inode && au_is_bad_inode(inode))) {
9115 + if (unlikely(au_dbrange_test(dentry))) {
9121 + sigen = au_sigen(sb);
9122 + if (au_digen_test(dentry, sigen)) {
9123 + AuDebugOn(IS_ROOT(dentry));
9124 + err = au_reval_dpath(dentry, sigen);
9125 + if (unlikely(err)) {
9130 + di_downgrade_lock(dentry, AuLock_IR);
9133 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9135 + && !(inode->i_state && I_LINKABLE)
9136 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9141 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9142 + if (do_udba && inode) {
9143 + aufs_bindex_t btop = au_ibtop(inode);
9144 + struct inode *h_inode;
9147 + h_inode = au_h_iptr(inode, btop);
9148 + if (h_inode && au_test_higen(inode, h_inode)) {
9155 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9156 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9157 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9159 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9165 + di_downgrade_lock(dentry, AuLock_IR);
9167 + aufs_read_unlock(dentry, AuLock_IR);
9172 + AuDbg("%pd invalid, %d\n", dentry, valid);
9178 +static void aufs_d_release(struct dentry *dentry)
9180 + if (au_di(dentry)) {
9181 + au_di_fin(dentry);
9182 + au_hn_di_reinit(dentry);
9186 +const struct dentry_operations aufs_dop = {
9187 + .d_revalidate = aufs_d_revalidate,
9188 + .d_weak_revalidate = aufs_d_revalidate,
9189 + .d_release = aufs_d_release
9192 +/* aufs_dop without d_revalidate */
9193 +const struct dentry_operations aufs_dop_noreval = {
9194 + .d_release = aufs_d_release
9196 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9197 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9198 +++ linux/fs/aufs/dentry.h 2018-04-15 08:49:13.397817296 +0200
9201 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9203 + * This program, aufs is free software; you can redistribute it and/or modify
9204 + * it under the terms of the GNU General Public License as published by
9205 + * the Free Software Foundation; either version 2 of the License, or
9206 + * (at your option) any later version.
9208 + * This program is distributed in the hope that it will be useful,
9209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9211 + * GNU General Public License for more details.
9213 + * You should have received a copy of the GNU General Public License
9214 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9218 + * lookup and dentry operations
9221 +#ifndef __AUFS_DENTRY_H__
9222 +#define __AUFS_DENTRY_H__
9226 +#include <linux/dcache.h>
9227 +#include "dirren.h"
9230 +struct au_hdentry {
9231 + struct dentry *hd_dentry;
9232 + aufs_bindex_t hd_id;
9236 + atomic_t di_generation;
9238 + struct au_rwsem di_rwsem;
9239 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9240 + unsigned char di_tmpfile; /* to allow the different name */
9241 + struct au_hdentry *di_hdentry;
9242 +} ____cacheline_aligned_in_smp;
9244 +/* ---------------------------------------------------------------------- */
9246 +/* flags for au_lkup_dentry() */
9247 +#define AuLkup_ALLOW_NEG 1
9248 +#define AuLkup_IGNORE_PERM (1 << 1)
9249 +#define AuLkup_DIRREN (1 << 2)
9250 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9251 +#define au_fset_lkup(flags, name) \
9252 + do { (flags) |= AuLkup_##name; } while (0)
9253 +#define au_fclr_lkup(flags, name) \
9254 + do { (flags) &= ~AuLkup_##name; } while (0)
9256 +#ifndef CONFIG_AUFS_DIRREN
9257 +#undef AuLkup_DIRREN
9258 +#define AuLkup_DIRREN 0
9261 +struct au_do_lookup_args {
9262 + unsigned int flags;
9264 + struct qstr whname, *name;
9265 + struct au_dr_lookup dirren;
9268 +/* ---------------------------------------------------------------------- */
9271 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9273 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9274 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9275 + struct dentry *h_parent, struct au_branch *br);
9277 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9278 + unsigned int flags);
9279 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9280 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9281 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9282 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9285 +void au_di_init_once(void *_di);
9286 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9287 +void au_di_free(struct au_dinfo *dinfo);
9288 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9289 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9290 +int au_di_init(struct dentry *dentry);
9291 +void au_di_fin(struct dentry *dentry);
9292 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9294 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9295 +void di_read_unlock(struct dentry *d, int flags);
9296 +void di_downgrade_lock(struct dentry *d, int flags);
9297 +void di_write_lock(struct dentry *d, unsigned int lsc);
9298 +void di_write_unlock(struct dentry *d);
9299 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9300 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9301 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9303 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9304 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9305 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9306 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9308 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9309 + struct dentry *h_dentry);
9310 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9311 +int au_dbrange_test(struct dentry *dentry);
9312 +void au_update_digen(struct dentry *dentry);
9313 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9314 +void au_update_dbtop(struct dentry *dentry);
9315 +void au_update_dbbot(struct dentry *dentry);
9316 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9318 +/* ---------------------------------------------------------------------- */
9320 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9322 + return dentry->d_fsdata;
9325 +/* ---------------------------------------------------------------------- */
9327 +/* lock subclass for dinfo */
9329 + AuLsc_DI_CHILD, /* child first */
9330 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9331 + AuLsc_DI_CHILD3, /* copyup dirs */
9335 + AuLsc_DI_TMP /* temp for replacing dinfo */
9339 + * di_read_lock_child, di_write_lock_child,
9340 + * di_read_lock_child2, di_write_lock_child2,
9341 + * di_read_lock_child3, di_write_lock_child3,
9342 + * di_read_lock_parent, di_write_lock_parent,
9343 + * di_read_lock_parent2, di_write_lock_parent2,
9344 + * di_read_lock_parent3, di_write_lock_parent3,
9346 +#define AuReadLockFunc(name, lsc) \
9347 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9348 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9350 +#define AuWriteLockFunc(name, lsc) \
9351 +static inline void di_write_lock_##name(struct dentry *d) \
9352 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9354 +#define AuRWLockFuncs(name, lsc) \
9355 + AuReadLockFunc(name, lsc) \
9356 + AuWriteLockFunc(name, lsc)
9358 +AuRWLockFuncs(child, CHILD);
9359 +AuRWLockFuncs(child2, CHILD2);
9360 +AuRWLockFuncs(child3, CHILD3);
9361 +AuRWLockFuncs(parent, PARENT);
9362 +AuRWLockFuncs(parent2, PARENT2);
9363 +AuRWLockFuncs(parent3, PARENT3);
9365 +#undef AuReadLockFunc
9366 +#undef AuWriteLockFunc
9367 +#undef AuRWLockFuncs
9369 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9370 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9371 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9373 +/* ---------------------------------------------------------------------- */
9375 +/* todo: memory barrier? */
9376 +static inline unsigned int au_digen(struct dentry *d)
9378 + return atomic_read(&au_di(d)->di_generation);
9381 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9383 + hdentry->hd_dentry = NULL;
9386 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9387 + aufs_bindex_t bindex)
9389 + return di->di_hdentry + bindex;
9392 +static inline void au_hdput(struct au_hdentry *hd)
9395 + dput(hd->hd_dentry);
9398 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9400 + DiMustAnyLock(dentry);
9401 + return au_di(dentry)->di_btop;
9404 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9406 + DiMustAnyLock(dentry);
9407 + return au_di(dentry)->di_bbot;
9410 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9412 + DiMustAnyLock(dentry);
9413 + return au_di(dentry)->di_bwh;
9416 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9418 + DiMustAnyLock(dentry);
9419 + return au_di(dentry)->di_bdiropq;
9422 +/* todo: hard/soft set? */
9423 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9425 + DiMustWriteLock(dentry);
9426 + au_di(dentry)->di_btop = bindex;
9429 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9431 + DiMustWriteLock(dentry);
9432 + au_di(dentry)->di_bbot = bindex;
9435 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9437 + DiMustWriteLock(dentry);
9438 + /* dbwh can be outside of btop - bbot range */
9439 + au_di(dentry)->di_bwh = bindex;
9442 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9444 + DiMustWriteLock(dentry);
9445 + au_di(dentry)->di_bdiropq = bindex;
9448 +/* ---------------------------------------------------------------------- */
9450 +#ifdef CONFIG_AUFS_HNOTIFY
9451 +static inline void au_digen_dec(struct dentry *d)
9453 + atomic_dec(&au_di(d)->di_generation);
9456 +static inline void au_hn_di_reinit(struct dentry *dentry)
9458 + dentry->d_fsdata = NULL;
9461 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9462 +#endif /* CONFIG_AUFS_HNOTIFY */
9464 +#endif /* __KERNEL__ */
9465 +#endif /* __AUFS_DENTRY_H__ */
9466 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9467 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9468 +++ linux/fs/aufs/dinfo.c 2018-04-15 08:49:13.397817296 +0200
9471 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9473 + * This program, aufs is free software; you can redistribute it and/or modify
9474 + * it under the terms of the GNU General Public License as published by
9475 + * the Free Software Foundation; either version 2 of the License, or
9476 + * (at your option) any later version.
9478 + * This program is distributed in the hope that it will be useful,
9479 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9480 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9481 + * GNU General Public License for more details.
9483 + * You should have received a copy of the GNU General Public License
9484 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9488 + * dentry private data
9493 +void au_di_init_once(void *_dinfo)
9495 + struct au_dinfo *dinfo = _dinfo;
9497 + au_rw_init(&dinfo->di_rwsem);
9500 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9502 + struct au_dinfo *dinfo;
9505 + dinfo = au_cache_alloc_dinfo();
9506 + if (unlikely(!dinfo))
9509 + nbr = au_sbbot(sb) + 1;
9512 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9513 + if (dinfo->di_hdentry) {
9514 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9515 + dinfo->di_btop = -1;
9516 + dinfo->di_bbot = -1;
9517 + dinfo->di_bwh = -1;
9518 + dinfo->di_bdiropq = -1;
9519 + dinfo->di_tmpfile = 0;
9520 + for (i = 0; i < nbr; i++)
9521 + dinfo->di_hdentry[i].hd_id = -1;
9525 + au_cache_free_dinfo(dinfo);
9532 +void au_di_free(struct au_dinfo *dinfo)
9534 + struct au_hdentry *p;
9535 + aufs_bindex_t bbot, bindex;
9537 + /* dentry may not be revalidated */
9538 + bindex = dinfo->di_btop;
9539 + if (bindex >= 0) {
9540 + bbot = dinfo->di_bbot;
9541 + p = au_hdentry(dinfo, bindex);
9542 + while (bindex++ <= bbot)
9545 + kfree(dinfo->di_hdentry);
9546 + au_cache_free_dinfo(dinfo);
9549 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9551 + struct au_hdentry *p;
9554 + AuRwMustWriteLock(&a->di_rwsem);
9555 + AuRwMustWriteLock(&b->di_rwsem);
9557 +#define DiSwap(v, name) \
9559 + v = a->di_##name; \
9560 + a->di_##name = b->di_##name; \
9561 + b->di_##name = v; \
9564 + DiSwap(p, hdentry);
9568 + DiSwap(bi, bdiropq);
9574 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9576 + AuRwMustWriteLock(&dst->di_rwsem);
9577 + AuRwMustWriteLock(&src->di_rwsem);
9579 + dst->di_btop = src->di_btop;
9580 + dst->di_bbot = src->di_bbot;
9581 + dst->di_bwh = src->di_bwh;
9582 + dst->di_bdiropq = src->di_bdiropq;
9586 +int au_di_init(struct dentry *dentry)
9589 + struct super_block *sb;
9590 + struct au_dinfo *dinfo;
9593 + sb = dentry->d_sb;
9594 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9596 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9597 + /* smp_mb(); */ /* atomic_set */
9598 + dentry->d_fsdata = dinfo;
9605 +void au_di_fin(struct dentry *dentry)
9607 + struct au_dinfo *dinfo;
9609 + dinfo = au_di(dentry);
9610 + AuRwDestroy(&dinfo->di_rwsem);
9611 + au_di_free(dinfo);
9614 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9617 + struct au_hdentry *hdp;
9619 + AuRwMustWriteLock(&dinfo->di_rwsem);
9622 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9624 + sz = sizeof(*hdp);
9625 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9628 + dinfo->di_hdentry = hdp;
9635 +/* ---------------------------------------------------------------------- */
9637 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9640 + case AuLsc_DI_CHILD:
9641 + ii_write_lock_child(inode);
9643 + case AuLsc_DI_CHILD2:
9644 + ii_write_lock_child2(inode);
9646 + case AuLsc_DI_CHILD3:
9647 + ii_write_lock_child3(inode);
9649 + case AuLsc_DI_PARENT:
9650 + ii_write_lock_parent(inode);
9652 + case AuLsc_DI_PARENT2:
9653 + ii_write_lock_parent2(inode);
9655 + case AuLsc_DI_PARENT3:
9656 + ii_write_lock_parent3(inode);
9663 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9666 + case AuLsc_DI_CHILD:
9667 + ii_read_lock_child(inode);
9669 + case AuLsc_DI_CHILD2:
9670 + ii_read_lock_child2(inode);
9672 + case AuLsc_DI_CHILD3:
9673 + ii_read_lock_child3(inode);
9675 + case AuLsc_DI_PARENT:
9676 + ii_read_lock_parent(inode);
9678 + case AuLsc_DI_PARENT2:
9679 + ii_read_lock_parent2(inode);
9681 + case AuLsc_DI_PARENT3:
9682 + ii_read_lock_parent3(inode);
9689 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9691 + struct inode *inode;
9693 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9694 + if (d_really_is_positive(d)) {
9695 + inode = d_inode(d);
9696 + if (au_ftest_lock(flags, IW))
9697 + do_ii_write_lock(inode, lsc);
9698 + else if (au_ftest_lock(flags, IR))
9699 + do_ii_read_lock(inode, lsc);
9703 +void di_read_unlock(struct dentry *d, int flags)
9705 + struct inode *inode;
9707 + if (d_really_is_positive(d)) {
9708 + inode = d_inode(d);
9709 + if (au_ftest_lock(flags, IW)) {
9710 + au_dbg_verify_dinode(d);
9711 + ii_write_unlock(inode);
9712 + } else if (au_ftest_lock(flags, IR)) {
9713 + au_dbg_verify_dinode(d);
9714 + ii_read_unlock(inode);
9717 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9720 +void di_downgrade_lock(struct dentry *d, int flags)
9722 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9723 + ii_downgrade_lock(d_inode(d));
9724 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9727 +void di_write_lock(struct dentry *d, unsigned int lsc)
9729 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9730 + if (d_really_is_positive(d))
9731 + do_ii_write_lock(d_inode(d), lsc);
9734 +void di_write_unlock(struct dentry *d)
9736 + au_dbg_verify_dinode(d);
9737 + if (d_really_is_positive(d))
9738 + ii_write_unlock(d_inode(d));
9739 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9742 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9744 + AuDebugOn(d1 == d2
9745 + || d_inode(d1) == d_inode(d2)
9746 + || d1->d_sb != d2->d_sb);
9748 + if ((isdir && au_test_subdir(d1, d2))
9750 + di_write_lock_child(d1);
9751 + di_write_lock_child2(d2);
9753 + di_write_lock_child(d2);
9754 + di_write_lock_child2(d1);
9758 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9760 + AuDebugOn(d1 == d2
9761 + || d_inode(d1) == d_inode(d2)
9762 + || d1->d_sb != d2->d_sb);
9764 + if ((isdir && au_test_subdir(d1, d2))
9766 + di_write_lock_parent(d1);
9767 + di_write_lock_parent2(d2);
9769 + di_write_lock_parent(d2);
9770 + di_write_lock_parent2(d1);
9774 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9776 + di_write_unlock(d1);
9777 + if (d_inode(d1) == d_inode(d2))
9778 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9780 + di_write_unlock(d2);
9783 +/* ---------------------------------------------------------------------- */
9785 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9789 + DiMustAnyLock(dentry);
9791 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9793 + AuDebugOn(bindex < 0);
9794 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9795 + AuDebugOn(d && au_dcount(d) <= 0);
9800 + * extended version of au_h_dptr().
9801 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9804 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9806 + struct dentry *h_dentry;
9807 + struct inode *inode, *h_inode;
9809 + AuDebugOn(d_really_is_negative(dentry));
9812 + if (au_dbtop(dentry) <= bindex
9813 + && bindex <= au_dbbot(dentry))
9814 + h_dentry = au_h_dptr(dentry, bindex);
9815 + if (h_dentry && !au_d_linkable(h_dentry)) {
9817 + goto out; /* success */
9820 + inode = d_inode(dentry);
9821 + AuDebugOn(bindex < au_ibtop(inode));
9822 + AuDebugOn(au_ibbot(inode) < bindex);
9823 + h_inode = au_h_iptr(inode, bindex);
9824 + h_dentry = d_find_alias(h_inode);
9826 + if (!IS_ERR(h_dentry)) {
9827 + if (!au_d_linkable(h_dentry))
9828 + goto out; /* success */
9834 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9835 + h_dentry = au_plink_lkup(inode, bindex);
9836 + AuDebugOn(!h_dentry);
9837 + if (!IS_ERR(h_dentry)) {
9838 + if (!au_d_hashed_positive(h_dentry))
9839 + goto out; /* success */
9846 + AuDbgDentry(h_dentry);
9850 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9852 + aufs_bindex_t bbot, bwh;
9854 + bbot = au_dbbot(dentry);
9856 + bwh = au_dbwh(dentry);
9859 + if (0 < bwh && bwh < bbot)
9865 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9867 + aufs_bindex_t bbot, bopq;
9869 + bbot = au_dbtail(dentry);
9871 + bopq = au_dbdiropq(dentry);
9872 + if (0 <= bopq && bopq < bbot)
9878 +/* ---------------------------------------------------------------------- */
9880 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9881 + struct dentry *h_dentry)
9883 + struct au_dinfo *dinfo;
9884 + struct au_hdentry *hd;
9885 + struct au_branch *br;
9887 + DiMustWriteLock(dentry);
9889 + dinfo = au_di(dentry);
9890 + hd = au_hdentry(dinfo, bindex);
9892 + hd->hd_dentry = h_dentry;
9894 + br = au_sbr(dentry->d_sb, bindex);
9895 + hd->hd_id = br->br_id;
9899 +int au_dbrange_test(struct dentry *dentry)
9902 + aufs_bindex_t btop, bbot;
9905 + btop = au_dbtop(dentry);
9906 + bbot = au_dbbot(dentry);
9908 + AuDebugOn(bbot < 0 && btop > bbot);
9911 + AuDebugOn(bbot >= 0);
9917 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9922 + if (unlikely(au_digen(dentry) != sigen
9923 + || au_iigen_test(d_inode(dentry), sigen)))
9929 +void au_update_digen(struct dentry *dentry)
9931 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9932 + /* smp_mb(); */ /* atomic_set */
9935 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9937 + struct au_dinfo *dinfo;
9938 + struct dentry *h_d;
9939 + struct au_hdentry *hdp;
9940 + aufs_bindex_t bindex, bbot;
9942 + DiMustWriteLock(dentry);
9944 + dinfo = au_di(dentry);
9945 + if (!dinfo || dinfo->di_btop < 0)
9948 + if (do_put_zero) {
9949 + bbot = dinfo->di_bbot;
9950 + bindex = dinfo->di_btop;
9951 + hdp = au_hdentry(dinfo, bindex);
9952 + for (; bindex <= bbot; bindex++, hdp++) {
9953 + h_d = hdp->hd_dentry;
9954 + if (h_d && d_is_negative(h_d))
9955 + au_set_h_dptr(dentry, bindex, NULL);
9959 + dinfo->di_btop = 0;
9960 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9961 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9962 + if (hdp->hd_dentry)
9964 + if (dinfo->di_btop > dinfo->di_bbot) {
9965 + dinfo->di_btop = -1;
9966 + dinfo->di_bbot = -1;
9970 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9971 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9972 + if (hdp->hd_dentry)
9974 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9977 +void au_update_dbtop(struct dentry *dentry)
9979 + aufs_bindex_t bindex, bbot;
9980 + struct dentry *h_dentry;
9982 + bbot = au_dbbot(dentry);
9983 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9984 + h_dentry = au_h_dptr(dentry, bindex);
9987 + if (d_is_positive(h_dentry)) {
9988 + au_set_dbtop(dentry, bindex);
9991 + au_set_h_dptr(dentry, bindex, NULL);
9995 +void au_update_dbbot(struct dentry *dentry)
9997 + aufs_bindex_t bindex, btop;
9998 + struct dentry *h_dentry;
10000 + btop = au_dbtop(dentry);
10001 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10002 + h_dentry = au_h_dptr(dentry, bindex);
10005 + if (d_is_positive(h_dentry)) {
10006 + au_set_dbbot(dentry, bindex);
10009 + au_set_h_dptr(dentry, bindex, NULL);
10013 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10015 + aufs_bindex_t bindex, bbot;
10017 + bbot = au_dbbot(dentry);
10018 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10019 + if (au_h_dptr(dentry, bindex) == h_dentry)
10023 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10024 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10025 +++ linux/fs/aufs/dir.c 2018-06-04 09:08:09.184746078 +0200
10028 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10030 + * This program, aufs is free software; you can redistribute it and/or modify
10031 + * it under the terms of the GNU General Public License as published by
10032 + * the Free Software Foundation; either version 2 of the License, or
10033 + * (at your option) any later version.
10035 + * This program is distributed in the hope that it will be useful,
10036 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10037 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10038 + * GNU General Public License for more details.
10040 + * You should have received a copy of the GNU General Public License
10041 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10045 + * directory operations
10048 +#include <linux/fs_stack.h>
10051 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10053 + unsigned int nlink;
10055 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10057 + nlink = dir->i_nlink;
10058 + nlink += h_dir->i_nlink - 2;
10059 + if (h_dir->i_nlink < 2)
10061 + smp_mb(); /* for i_nlink */
10062 + /* 0 can happen in revaliding */
10063 + set_nlink(dir, nlink);
10066 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10068 + unsigned int nlink;
10070 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10072 + nlink = dir->i_nlink;
10073 + nlink -= h_dir->i_nlink - 2;
10074 + if (h_dir->i_nlink < 2)
10076 + smp_mb(); /* for i_nlink */
10077 + /* nlink == 0 means the branch-fs is broken */
10078 + set_nlink(dir, nlink);
10081 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10084 + aufs_bindex_t bindex, bbot;
10085 + struct file *h_file;
10086 + struct dentry *h_dentry;
10090 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10092 + bbot = au_fbbot_dir(file);
10093 + for (bindex = au_fbtop(file);
10094 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10096 + h_file = au_hf_dir(file, bindex);
10097 + if (h_file && file_inode(h_file))
10098 + sz += vfsub_f_size_read(h_file);
10101 + AuDebugOn(!dentry);
10102 + AuDebugOn(!d_is_dir(dentry));
10104 + bbot = au_dbtaildir(dentry);
10105 + for (bindex = au_dbtop(dentry);
10106 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10108 + h_dentry = au_h_dptr(dentry, bindex);
10109 + if (h_dentry && d_is_positive(h_dentry))
10110 + sz += i_size_read(d_inode(h_dentry));
10113 + if (sz < KMALLOC_MAX_SIZE)
10114 + sz = roundup_pow_of_two(sz);
10115 + if (sz > KMALLOC_MAX_SIZE)
10116 + sz = KMALLOC_MAX_SIZE;
10117 + else if (sz < NAME_MAX) {
10118 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10119 + sz = AUFS_RDBLK_DEF;
10124 +struct au_dir_ts_arg {
10125 + struct dentry *dentry;
10126 + aufs_bindex_t brid;
10129 +static void au_do_dir_ts(void *arg)
10131 + struct au_dir_ts_arg *a = arg;
10132 + struct au_dtime dt;
10133 + struct path h_path;
10134 + struct inode *dir, *h_dir;
10135 + struct super_block *sb;
10136 + struct au_branch *br;
10137 + struct au_hinode *hdir;
10139 + aufs_bindex_t btop, bindex;
10141 + sb = a->dentry->d_sb;
10142 + if (d_really_is_negative(a->dentry))
10144 + /* no dir->i_mutex lock */
10145 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10147 + dir = d_inode(a->dentry);
10148 + btop = au_ibtop(dir);
10149 + bindex = au_br_index(sb, a->brid);
10150 + if (bindex < btop)
10153 + br = au_sbr(sb, bindex);
10154 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10155 + if (!h_path.dentry)
10157 + h_path.mnt = au_br_mnt(br);
10158 + au_dtime_store(&dt, a->dentry, &h_path);
10160 + br = au_sbr(sb, btop);
10161 + if (!au_br_writable(br->br_perm))
10163 + h_path.dentry = au_h_dptr(a->dentry, btop);
10164 + h_path.mnt = au_br_mnt(br);
10165 + err = vfsub_mnt_want_write(h_path.mnt);
10168 + hdir = au_hi(dir, btop);
10169 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10170 + h_dir = au_h_iptr(dir, btop);
10171 + if (h_dir->i_nlink
10172 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10173 + dt.dt_h_path = h_path;
10174 + au_dtime_revert(&dt);
10176 + au_hn_inode_unlock(hdir);
10177 + vfsub_mnt_drop_write(h_path.mnt);
10178 + au_cpup_attr_timesizes(dir);
10181 + aufs_read_unlock(a->dentry, AuLock_DW);
10184 + au_nwt_done(&au_sbi(sb)->si_nowait);
10188 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10190 + int perm, wkq_err;
10191 + aufs_bindex_t btop;
10192 + struct au_dir_ts_arg *arg;
10193 + struct dentry *dentry;
10194 + struct super_block *sb;
10198 + dentry = d_find_any_alias(dir);
10199 + AuDebugOn(!dentry);
10200 + sb = dentry->d_sb;
10201 + btop = au_ibtop(dir);
10202 + if (btop == bindex) {
10203 + au_cpup_attr_timesizes(dir);
10207 + perm = au_sbr_perm(sb, btop);
10208 + if (!au_br_writable(perm))
10211 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10215 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10216 + arg->brid = au_sbr_id(sb, bindex);
10217 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10218 + if (unlikely(wkq_err)) {
10219 + pr_err("wkq %d\n", wkq_err);
10228 +/* ---------------------------------------------------------------------- */
10230 +static int reopen_dir(struct file *file)
10233 + unsigned int flags;
10234 + aufs_bindex_t bindex, btail, btop;
10235 + struct dentry *dentry, *h_dentry;
10236 + struct file *h_file;
10238 + /* open all lower dirs */
10239 + dentry = file->f_path.dentry;
10240 + btop = au_dbtop(dentry);
10241 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10242 + au_set_h_fptr(file, bindex, NULL);
10243 + au_set_fbtop(file, btop);
10245 + btail = au_dbtaildir(dentry);
10246 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10247 + au_set_h_fptr(file, bindex, NULL);
10248 + au_set_fbbot_dir(file, btail);
10250 + flags = vfsub_file_flags(file);
10251 + for (bindex = btop; bindex <= btail; bindex++) {
10252 + h_dentry = au_h_dptr(dentry, bindex);
10255 + h_file = au_hf_dir(file, bindex);
10259 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10260 + err = PTR_ERR(h_file);
10261 + if (IS_ERR(h_file))
10262 + goto out; /* close all? */
10263 + au_set_h_fptr(file, bindex, h_file);
10265 + au_update_figen(file);
10266 + /* todo: necessary? */
10267 + /* file->f_ra = h_file->f_ra; */
10274 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10277 + aufs_bindex_t bindex, btail;
10278 + struct dentry *dentry, *h_dentry;
10279 + struct vfsmount *mnt;
10281 + FiMustWriteLock(file);
10282 + AuDebugOn(h_file);
10285 + mnt = file->f_path.mnt;
10286 + dentry = file->f_path.dentry;
10287 + file->f_version = inode_query_iversion(d_inode(dentry));
10288 + bindex = au_dbtop(dentry);
10289 + au_set_fbtop(file, bindex);
10290 + btail = au_dbtaildir(dentry);
10291 + au_set_fbbot_dir(file, btail);
10292 + for (; !err && bindex <= btail; bindex++) {
10293 + h_dentry = au_h_dptr(dentry, bindex);
10297 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10298 + if (unlikely(err))
10300 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10301 + if (IS_ERR(h_file)) {
10302 + err = PTR_ERR(h_file);
10305 + au_set_h_fptr(file, bindex, h_file);
10307 + au_update_figen(file);
10308 + /* todo: necessary? */
10309 + /* file->f_ra = h_file->f_ra; */
10311 + return 0; /* success */
10314 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10315 + au_set_h_fptr(file, bindex, NULL);
10316 + au_set_fbtop(file, -1);
10317 + au_set_fbbot_dir(file, -1);
10322 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10323 + struct file *file)
10326 + struct super_block *sb;
10327 + struct au_fidir *fidir;
10330 + sb = file->f_path.dentry->d_sb;
10331 + si_read_lock(sb, AuLock_FLUSH);
10332 + fidir = au_fidir_alloc(sb);
10334 + struct au_do_open_args args = {
10335 + .open = do_open_dir,
10338 + err = au_do_open(file, &args);
10339 + if (unlikely(err))
10342 + si_read_unlock(sb);
10346 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10347 + struct file *file)
10349 + struct au_vdir *vdir_cache;
10350 + struct au_finfo *finfo;
10351 + struct au_fidir *fidir;
10352 + struct au_hfile *hf;
10353 + aufs_bindex_t bindex, bbot;
10355 + finfo = au_fi(file);
10356 + fidir = finfo->fi_hdir;
10358 + au_hbl_del(&finfo->fi_hlist,
10359 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10360 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10362 + au_vdir_free(vdir_cache);
10364 + bindex = finfo->fi_btop;
10365 + if (bindex >= 0) {
10366 + hf = fidir->fd_hfile + bindex;
10368 + * calls fput() instead of filp_close(),
10369 + * since no dnotify or lock for the lower file.
10371 + bbot = fidir->fd_bbot;
10372 + for (; bindex <= bbot; bindex++, hf++)
10374 + au_hfput(hf, /*execed*/0);
10377 + finfo->fi_hdir = NULL;
10379 + au_finfo_fin(file);
10383 +/* ---------------------------------------------------------------------- */
10385 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10388 + aufs_bindex_t bindex, bbot;
10389 + struct file *h_file;
10392 + bbot = au_fbbot_dir(file);
10393 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10394 + h_file = au_hf_dir(file, bindex);
10396 + err = vfsub_flush(h_file, id);
10401 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10403 + return au_do_flush(file, id, au_do_flush_dir);
10406 +/* ---------------------------------------------------------------------- */
10408 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10411 + aufs_bindex_t bbot, bindex;
10412 + struct inode *inode;
10413 + struct super_block *sb;
10416 + sb = dentry->d_sb;
10417 + inode = d_inode(dentry);
10418 + IMustLock(inode);
10419 + bbot = au_dbbot(dentry);
10420 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10421 + struct path h_path;
10423 + if (au_test_ro(sb, bindex, inode))
10425 + h_path.dentry = au_h_dptr(dentry, bindex);
10426 + if (!h_path.dentry)
10429 + h_path.mnt = au_sbr_mnt(sb, bindex);
10430 + err = vfsub_fsync(NULL, &h_path, datasync);
10436 +static int au_do_fsync_dir(struct file *file, int datasync)
10439 + aufs_bindex_t bbot, bindex;
10440 + struct file *h_file;
10441 + struct super_block *sb;
10442 + struct inode *inode;
10444 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10445 + if (unlikely(err))
10448 + inode = file_inode(file);
10449 + sb = inode->i_sb;
10450 + bbot = au_fbbot_dir(file);
10451 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10452 + h_file = au_hf_dir(file, bindex);
10453 + if (!h_file || au_test_ro(sb, bindex, inode))
10456 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10464 + * @file may be NULL
10466 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10470 + struct dentry *dentry;
10471 + struct inode *inode;
10472 + struct super_block *sb;
10475 + dentry = file->f_path.dentry;
10476 + inode = d_inode(dentry);
10477 + inode_lock(inode);
10478 + sb = dentry->d_sb;
10479 + si_noflush_read_lock(sb);
10481 + err = au_do_fsync_dir(file, datasync);
10483 + di_write_lock_child(dentry);
10484 + err = au_do_fsync_dir_no_file(dentry, datasync);
10486 + au_cpup_attr_timesizes(inode);
10487 + di_write_unlock(dentry);
10489 + fi_write_unlock(file);
10491 + si_read_unlock(sb);
10492 + inode_unlock(inode);
10496 +/* ---------------------------------------------------------------------- */
10498 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10501 + struct dentry *dentry;
10502 + struct inode *inode, *h_inode;
10503 + struct super_block *sb;
10505 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10507 + dentry = file->f_path.dentry;
10508 + inode = d_inode(dentry);
10509 + IMustLock(inode);
10511 + sb = dentry->d_sb;
10512 + si_read_lock(sb, AuLock_FLUSH);
10513 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10514 + if (unlikely(err))
10516 + err = au_alive_dir(dentry);
10518 + err = au_vdir_init(file);
10519 + di_downgrade_lock(dentry, AuLock_IR);
10520 + if (unlikely(err))
10523 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10524 + if (!au_test_nfsd()) {
10525 + err = au_vdir_fill_de(file, ctx);
10526 + fsstack_copy_attr_atime(inode, h_inode);
10529 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10530 + * encode_fh() and others.
10532 + atomic_inc(&h_inode->i_count);
10533 + di_read_unlock(dentry, AuLock_IR);
10534 + si_read_unlock(sb);
10535 + err = au_vdir_fill_de(file, ctx);
10536 + fsstack_copy_attr_atime(inode, h_inode);
10537 + fi_write_unlock(file);
10545 + di_read_unlock(dentry, AuLock_IR);
10546 + fi_write_unlock(file);
10548 + si_read_unlock(sb);
10552 +/* ---------------------------------------------------------------------- */
10554 +#define AuTestEmpty_WHONLY 1
10555 +#define AuTestEmpty_CALLED (1 << 1)
10556 +#define AuTestEmpty_SHWH (1 << 2)
10557 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10558 +#define au_fset_testempty(flags, name) \
10559 + do { (flags) |= AuTestEmpty_##name; } while (0)
10560 +#define au_fclr_testempty(flags, name) \
10561 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10563 +#ifndef CONFIG_AUFS_SHWH
10564 +#undef AuTestEmpty_SHWH
10565 +#define AuTestEmpty_SHWH 0
10568 +struct test_empty_arg {
10569 + struct dir_context ctx;
10570 + struct au_nhash *whlist;
10571 + unsigned int flags;
10573 + aufs_bindex_t bindex;
10576 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10577 + int namelen, loff_t offset __maybe_unused, u64 ino,
10578 + unsigned int d_type)
10580 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10582 + char *name = (void *)__name;
10585 + au_fset_testempty(arg->flags, CALLED);
10587 + if (name[0] == '.'
10588 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10589 + goto out; /* success */
10591 + if (namelen <= AUFS_WH_PFX_LEN
10592 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10593 + if (au_ftest_testempty(arg->flags, WHONLY)
10594 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10595 + arg->err = -ENOTEMPTY;
10599 + name += AUFS_WH_PFX_LEN;
10600 + namelen -= AUFS_WH_PFX_LEN;
10601 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10602 + arg->err = au_nhash_append_wh
10603 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10604 + au_ftest_testempty(arg->flags, SHWH));
10608 + AuTraceErr(arg->err);
10612 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10615 + struct file *h_file;
10617 + h_file = au_h_open(dentry, arg->bindex,
10618 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10619 + /*file*/NULL, /*force_wr*/0);
10620 + err = PTR_ERR(h_file);
10621 + if (IS_ERR(h_file))
10625 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10626 + && !file_inode(h_file)->i_nlink)
10631 + au_fclr_testempty(arg->flags, CALLED);
10633 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10636 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10640 + au_sbr_put(dentry->d_sb, arg->bindex);
10645 +struct do_test_empty_args {
10647 + struct dentry *dentry;
10648 + struct test_empty_arg *arg;
10651 +static void call_do_test_empty(void *args)
10653 + struct do_test_empty_args *a = args;
10654 + *a->errp = do_test_empty(a->dentry, a->arg);
10657 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10659 + int err, wkq_err;
10660 + struct dentry *h_dentry;
10661 + struct inode *h_inode;
10663 + h_dentry = au_h_dptr(dentry, arg->bindex);
10664 + h_inode = d_inode(h_dentry);
10665 + /* todo: i_mode changes anytime? */
10666 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10667 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10668 + inode_unlock_shared(h_inode);
10670 + err = do_test_empty(dentry, arg);
10672 + struct do_test_empty_args args = {
10674 + .dentry = dentry,
10677 + unsigned int flags = arg->flags;
10679 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10680 + if (unlikely(wkq_err))
10682 + arg->flags = flags;
10688 +int au_test_empty_lower(struct dentry *dentry)
10691 + unsigned int rdhash;
10692 + aufs_bindex_t bindex, btop, btail;
10693 + struct au_nhash whlist;
10694 + struct test_empty_arg arg = {
10696 + .actor = test_empty_cb
10699 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10701 + SiMustAnyLock(dentry->d_sb);
10703 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10705 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10706 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10707 + if (unlikely(err))
10711 + arg.whlist = &whlist;
10712 + btop = au_dbtop(dentry);
10713 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10714 + au_fset_testempty(arg.flags, SHWH);
10715 + test_empty = do_test_empty;
10716 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10717 + test_empty = sio_test_empty;
10718 + arg.bindex = btop;
10719 + err = test_empty(dentry, &arg);
10720 + if (unlikely(err))
10723 + au_fset_testempty(arg.flags, WHONLY);
10724 + btail = au_dbtaildir(dentry);
10725 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10726 + struct dentry *h_dentry;
10728 + h_dentry = au_h_dptr(dentry, bindex);
10729 + if (h_dentry && d_is_positive(h_dentry)) {
10730 + arg.bindex = bindex;
10731 + err = test_empty(dentry, &arg);
10736 + au_nhash_wh_free(&whlist);
10741 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10744 + struct test_empty_arg arg = {
10746 + .actor = test_empty_cb
10749 + aufs_bindex_t bindex, btail;
10752 + arg.whlist = whlist;
10753 + arg.flags = AuTestEmpty_WHONLY;
10754 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10755 + au_fset_testempty(arg.flags, SHWH);
10756 + btail = au_dbtaildir(dentry);
10757 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10758 + struct dentry *h_dentry;
10760 + h_dentry = au_h_dptr(dentry, bindex);
10761 + if (h_dentry && d_is_positive(h_dentry)) {
10762 + arg.bindex = bindex;
10763 + err = sio_test_empty(dentry, &arg);
10770 +/* ---------------------------------------------------------------------- */
10772 +const struct file_operations aufs_dir_fop = {
10773 + .owner = THIS_MODULE,
10774 + .llseek = default_llseek,
10775 + .read = generic_read_dir,
10776 + .iterate_shared = aufs_iterate_shared,
10777 + .unlocked_ioctl = aufs_ioctl_dir,
10778 +#ifdef CONFIG_COMPAT
10779 + .compat_ioctl = aufs_compat_ioctl_dir,
10781 + .open = aufs_open_dir,
10782 + .release = aufs_release_dir,
10783 + .flush = aufs_flush_dir,
10784 + .fsync = aufs_fsync_dir
10786 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10787 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10788 +++ linux/fs/aufs/dir.h 2018-06-04 09:08:09.184746078 +0200
10791 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10793 + * This program, aufs is free software; you can redistribute it and/or modify
10794 + * it under the terms of the GNU General Public License as published by
10795 + * the Free Software Foundation; either version 2 of the License, or
10796 + * (at your option) any later version.
10798 + * This program is distributed in the hope that it will be useful,
10799 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10800 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10801 + * GNU General Public License for more details.
10803 + * You should have received a copy of the GNU General Public License
10804 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10808 + * directory operations
10811 +#ifndef __AUFS_DIR_H__
10812 +#define __AUFS_DIR_H__
10816 +#include <linux/fs.h>
10818 +/* ---------------------------------------------------------------------- */
10820 +/* need to be faster and smaller */
10823 + unsigned int nh_num;
10824 + struct hlist_head *nh_head;
10827 +struct au_vdir_destr {
10828 + unsigned char len;
10829 + unsigned char name[0];
10832 +struct au_vdir_dehstr {
10833 + struct hlist_node hash;
10834 + struct au_vdir_destr *str;
10835 +} ____cacheline_aligned_in_smp;
10837 +struct au_vdir_de {
10839 + unsigned char de_type;
10840 + /* caution: packed */
10841 + struct au_vdir_destr de_str;
10844 +struct au_vdir_wh {
10845 + struct hlist_node wh_hash;
10846 +#ifdef CONFIG_AUFS_SHWH
10848 + aufs_bindex_t wh_bindex;
10849 + unsigned char wh_type;
10851 + aufs_bindex_t wh_bindex;
10853 + /* caution: packed */
10854 + struct au_vdir_destr wh_str;
10857 +union au_vdir_deblk_p {
10858 + unsigned char *deblk;
10859 + struct au_vdir_de *de;
10863 + unsigned char **vd_deblk;
10864 + unsigned long vd_nblk;
10866 + unsigned long ul;
10867 + union au_vdir_deblk_p p;
10871 + unsigned int vd_deblk_sz;
10872 + unsigned long vd_jiffy;
10873 +} ____cacheline_aligned_in_smp;
10875 +/* ---------------------------------------------------------------------- */
10878 +extern const struct file_operations aufs_dir_fop;
10879 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10880 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10881 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10882 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10883 +int au_test_empty_lower(struct dentry *dentry);
10884 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10887 +unsigned int au_rdhash_est(loff_t sz);
10888 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10889 +void au_nhash_wh_free(struct au_nhash *whlist);
10890 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10892 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10893 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10894 + unsigned int d_type, aufs_bindex_t bindex,
10895 + unsigned char shwh);
10896 +void au_vdir_free(struct au_vdir *vdir);
10897 +int au_vdir_init(struct file *file);
10898 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10901 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10903 +#ifdef CONFIG_AUFS_RDU
10905 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10906 +#ifdef CONFIG_COMPAT
10907 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10908 + unsigned long arg);
10911 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10912 + unsigned int cmd, unsigned long arg)
10913 +#ifdef CONFIG_COMPAT
10914 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10915 + unsigned int cmd, unsigned long arg)
10919 +#endif /* __KERNEL__ */
10920 +#endif /* __AUFS_DIR_H__ */
10921 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10922 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10923 +++ linux/fs/aufs/dirren.c 2018-06-04 09:08:09.184746078 +0200
10926 + * Copyright (C) 2017-2018 Junjiro R. Okajima
10928 + * This program, aufs is free software; you can redistribute it and/or modify
10929 + * it under the terms of the GNU General Public License as published by
10930 + * the Free Software Foundation; either version 2 of the License, or
10931 + * (at your option) any later version.
10933 + * This program is distributed in the hope that it will be useful,
10934 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10935 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10936 + * GNU General Public License for more details.
10938 + * You should have received a copy of the GNU General Public License
10939 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10943 + * special handling in renaming a directoy
10944 + * in order to support looking-up the before-renamed name on the lower readonly
10948 +#include <linux/byteorder/generic.h>
10951 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10955 + idx = au_dr_ihash(ent->dr_h_ino);
10956 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10959 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10962 + struct hlist_bl_head *hbl;
10965 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10966 + hbl = dr->dr_h_ino + i;
10967 + hlist_bl_lock(hbl);
10968 + ret &= hlist_bl_empty(hbl);
10969 + hlist_bl_unlock(hbl);
10975 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10977 + struct au_dr_hino *found, *ent;
10978 + struct hlist_bl_head *hbl;
10979 + struct hlist_bl_node *pos;
10983 + idx = au_dr_ihash(ino);
10984 + hbl = dr->dr_h_ino + idx;
10985 + hlist_bl_lock(hbl);
10986 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10987 + if (ent->dr_h_ino == ino) {
10991 + hlist_bl_unlock(hbl);
10996 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10997 + struct au_dr_hino *add_ent)
11000 + struct hlist_bl_head *hbl;
11001 + struct hlist_bl_node *pos;
11002 + struct au_dr_hino *ent;
11005 + idx = au_dr_ihash(ino);
11006 + hbl = dr->dr_h_ino + idx;
11009 + struct hlist_bl_node *tmp;
11011 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11012 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11015 + hlist_bl_lock(hbl);
11016 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11017 + if (ent->dr_h_ino == ino) {
11021 + if (!found && add_ent)
11022 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11023 + hlist_bl_unlock(hbl);
11025 + if (!found && add_ent)
11026 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11031 +void au_dr_hino_free(struct au_dr_br *dr)
11034 + struct hlist_bl_head *hbl;
11035 + struct hlist_bl_node *pos, *tmp;
11036 + struct au_dr_hino *ent;
11038 + /* SiMustWriteLock(sb); */
11040 + for (i = 0; i < AuDirren_NHASH; i++) {
11041 + hbl = dr->dr_h_ino + i;
11042 + /* no spinlock since sbinfo must be write-locked */
11043 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11045 + INIT_HLIST_BL_HEAD(hbl);
11049 +/* returns the number of inodes or an error */
11050 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11051 + struct file *hinofile)
11055 + loff_t pos, oldsize;
11057 + struct inode *hinoinode;
11058 + struct hlist_bl_head *hbl;
11059 + struct hlist_bl_node *n1, *n2;
11060 + struct au_dr_hino *ent;
11062 + SiMustWriteLock(sb);
11063 + AuDebugOn(!au_br_writable(br->br_perm));
11065 + hinoinode = file_inode(hinofile);
11066 + oldsize = i_size_read(hinoinode);
11070 + hbl = br->br_dirren.dr_h_ino;
11071 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11072 + /* no bit-lock since sbinfo must be write-locked */
11073 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11074 + AuDbg("hi%llu, %pD2\n",
11075 + (unsigned long long)ent->dr_h_ino, hinofile);
11076 + u64 = cpu_to_be64(ent->dr_h_ino);
11077 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11078 + if (ssz == sizeof(u64))
11081 + /* write error */
11082 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11089 + /* regardless the error */
11090 + if (pos < oldsize) {
11091 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11099 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11106 + struct au_dr_hino *ent;
11107 + struct inode *hinoinode;
11108 + struct hlist_bl_head *hbl;
11112 + hbl = dr->dr_h_ino;
11113 + hinoinode = file_inode(hinofile);
11114 + sz = i_size_read(hinoinode);
11115 + AuDebugOn(sz % sizeof(u64));
11116 + n = sz / sizeof(u64);
11118 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11119 + if (unlikely(ssz != sizeof(u64))) {
11120 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11127 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11133 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11134 + AuDbg("hi%llu, %pD2\n",
11135 + (unsigned long long)ent->dr_h_ino, hinofile);
11136 + hidx = au_dr_ihash(ent->dr_h_ino);
11137 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11139 + goto out; /* success */
11142 + au_dr_hino_free(dr);
11149 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11150 + * @path is a switch to distinguish load and store.
11152 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11153 + struct au_branch *br, const struct path *path)
11156 + unsigned char load, suspend;
11157 + struct file *hinofile;
11158 + struct au_hinode *hdir;
11159 + struct inode *dir, *delegated;
11160 + struct path hinopath;
11161 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11162 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11164 + AuDebugOn(bindex < 0 && !br);
11165 + AuDebugOn(bindex >= 0 && br);
11170 + br = au_sbr(sb, bindex);
11173 + path = &br->br_path;
11174 + AuDebugOn(!au_br_writable(br->br_perm));
11175 + if (unlikely(!au_br_writable(br->br_perm)))
11181 + dir = d_inode(sb->s_root);
11182 + hdir = au_hinode(au_ii(dir), bindex);
11183 + dir = hdir->hi_inode;
11184 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11186 + dir = d_inode(path->dentry);
11187 + inode_lock_nested(dir, AuLsc_I_CHILD);
11189 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11190 + err = PTR_ERR(hinopath.dentry);
11191 + if (IS_ERR(hinopath.dentry))
11195 + flags = O_RDONLY;
11197 + if (d_is_negative(hinopath.dentry))
11198 + goto out_dput; /* success */
11200 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11201 + if (d_is_positive(hinopath.dentry)) {
11202 + delegated = NULL;
11203 + err = vfsub_unlink(dir, &hinopath, &delegated,
11206 + if (unlikely(err))
11207 + pr_err("ignored err %d, %pd2\n",
11208 + err, hinopath.dentry);
11209 + if (unlikely(err == -EWOULDBLOCK))
11214 + } else if (!d_is_positive(hinopath.dentry)) {
11215 + err = vfsub_create(dir, &hinopath, 0600,
11216 + /*want_excl*/false);
11218 + if (unlikely(err))
11221 + flags = O_WRONLY;
11223 + hinopath.mnt = path->mnt;
11224 + hinofile = vfsub_dentry_open(&hinopath, flags);
11226 + au_hn_inode_unlock(hdir);
11228 + inode_unlock(dir);
11229 + dput(hinopath.dentry);
11230 + AuTraceErrPtr(hinofile);
11231 + if (IS_ERR(hinofile)) {
11232 + err = PTR_ERR(hinofile);
11237 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11239 + err = au_dr_hino_store(sb, br, hinofile);
11244 + dput(hinopath.dentry);
11247 + au_hn_inode_unlock(hdir);
11249 + inode_unlock(dir);
11255 +/* ---------------------------------------------------------------------- */
11257 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11260 + struct kstatfs kstfs;
11262 + struct dentry *dentry;
11263 + struct super_block *sb;
11265 + err = vfs_statfs((void *)path, &kstfs);
11267 + if (unlikely(err))
11270 + /* todo: support for UUID */
11272 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11273 + brid->type = AuBrid_FSID;
11274 + brid->fsid = kstfs.f_fsid;
11276 + dentry = path->dentry;
11277 + sb = dentry->d_sb;
11280 + brid->type = AuBrid_DEV;
11289 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11290 + const struct path *path)
11293 + struct au_dr_br *dr;
11294 + struct hlist_bl_head *hbl;
11296 + dr = &br->br_dirren;
11297 + hbl = dr->dr_h_ino;
11298 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11299 + INIT_HLIST_BL_HEAD(hbl);
11301 + err = au_dr_brid_init(&dr->dr_brid, path);
11302 + if (unlikely(err))
11305 + if (au_opt_test(au_mntflags(sb), DIRREN))
11306 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11313 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11318 + if (au_br_writable(br->br_perm))
11319 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11321 + au_dr_hino_free(&br->br_dirren);
11326 +/* ---------------------------------------------------------------------- */
11328 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11329 + char *buf, size_t sz)
11332 + unsigned int major, minor;
11336 + err = snprintf(p, sz, "%d_", brid->type);
11337 + AuDebugOn(err > sz);
11340 + switch (brid->type) {
11341 + case AuBrid_Unset:
11343 + case AuBrid_UUID:
11344 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11346 + case AuBrid_FSID:
11347 + err = snprintf(p, sz, "%08x-%08x",
11348 + brid->fsid.val[0], brid->fsid.val[1]);
11351 + major = MAJOR(brid->dev);
11352 + minor = MINOR(brid->dev);
11353 + if (major <= 0xff && minor <= 0xff)
11354 + err = snprintf(p, sz, "%02x%02x", major, minor);
11356 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11359 + AuDebugOn(err > sz);
11362 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11363 + AuDebugOn(err > sz);
11370 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11373 + struct dentry *br_dentry;
11374 + struct inode *br_inode;
11376 + br_dentry = au_br_dentry(br);
11377 + br_inode = d_inode(br_dentry);
11378 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11379 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11380 + AuDebugOn(rlen > len);
11385 +/* ---------------------------------------------------------------------- */
11388 + * from the given @h_dentry, construct drinfo at @*fdata.
11389 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11392 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11393 + struct dentry *h_dentry,
11394 + unsigned char *allocated)
11397 + struct au_drinfo_fdata *f, *p;
11398 + struct au_drinfo *drinfo;
11399 + struct inode *h_inode;
11400 + struct qstr *qname;
11404 + h_inode = d_inode(h_dentry);
11405 + qname = &h_dentry->d_name;
11406 + drinfo = &f->drinfo;
11407 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11408 + drinfo->oldnamelen = qname->len;
11409 + if (*allocated < sizeof(*f) + qname->len) {
11410 + v = roundup_pow_of_two(*allocated + qname->len);
11411 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11412 + if (unlikely(!p)) {
11420 + drinfo = &f->drinfo;
11422 + memcpy(drinfo->oldname, qname->name, qname->len);
11423 + AuDbg("i%llu, %.*s\n",
11424 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11425 + drinfo->oldname);
11432 +/* callers have to free the return value */
11433 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11435 + struct au_drinfo *ret, *drinfo;
11436 + struct au_drinfo_fdata fdata;
11441 + ret = ERR_PTR(-EIO);
11443 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11444 + if (unlikely(ssz != sizeof(fdata))) {
11445 + AuIOErr("ssz %zd, %u, %pD2\n",
11446 + ssz, (unsigned int)sizeof(fdata), file);
11450 + fdata.magic = ntohl((__force __be32)fdata.magic);
11451 + switch (fdata.magic) {
11452 + case AUFS_DRINFO_MAGIC_V1:
11455 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11456 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11460 + drinfo = &fdata.drinfo;
11461 + len = drinfo->oldnamelen;
11463 + AuIOErr("broken drinfo %pD2\n", file);
11468 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11469 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11470 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11471 + (unsigned long long)drinfo->ino,
11472 + (unsigned long long)h_ino, file);
11473 + goto out; /* success */
11476 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11477 + if (unlikely(!ret)) {
11478 + ret = ERR_PTR(-ENOMEM);
11479 + AuTraceErrPtr(ret);
11484 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11485 + if (unlikely(ssz != len)) {
11487 + ret = ERR_PTR(-EIO);
11488 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11492 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11498 +/* ---------------------------------------------------------------------- */
11500 +/* in order to be revertible */
11501 +struct au_drinfo_rev_elm {
11503 + struct dentry *info_dentry;
11504 + struct au_drinfo *info_last;
11507 +struct au_drinfo_rev {
11508 + unsigned char already;
11509 + aufs_bindex_t nelm;
11510 + struct au_drinfo_rev_elm elm[0];
11513 +/* todo: isn't it too large? */
11514 +struct au_drinfo_store {
11515 + struct path h_ppath;
11516 + struct dentry *h_dentry;
11517 + struct au_drinfo_fdata *fdata;
11518 + char *infoname; /* inside of whname, just after PFX */
11519 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11520 + aufs_bindex_t btgt, btail;
11521 + unsigned char no_sio,
11522 + allocated, /* current size of *fdata */
11523 + infonamelen, /* room size for p */
11524 + whnamelen, /* length of the genarated name */
11525 + renameback; /* renamed back */
11528 +/* on rename(2) error, the caller should revert it using @elm */
11529 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11530 + struct au_drinfo_rev_elm *elm)
11535 + struct path infopath = {
11536 + .mnt = w->h_ppath.mnt
11538 + struct inode *h_dir, *h_inode, *delegated;
11539 + struct file *infofile;
11540 + struct qstr *qname;
11543 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11545 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11547 + AuTraceErrPtr(infopath.dentry);
11548 + if (IS_ERR(infopath.dentry)) {
11549 + err = PTR_ERR(infopath.dentry);
11554 + h_dir = d_inode(w->h_ppath.dentry);
11555 + if (elm && d_is_negative(infopath.dentry)) {
11556 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11558 + if (unlikely(err))
11560 + elm->created = 1;
11561 + elm->info_dentry = dget(infopath.dentry);
11564 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11565 + AuTraceErrPtr(infofile);
11566 + if (IS_ERR(infofile)) {
11567 + err = PTR_ERR(infofile);
11571 + h_inode = d_inode(infopath.dentry);
11572 + if (elm && i_size_read(h_inode)) {
11573 + h_inode = d_inode(w->h_dentry);
11574 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11575 + AuTraceErrPtr(elm->info_last);
11576 + if (IS_ERR(elm->info_last)) {
11577 + err = PTR_ERR(elm->info_last);
11578 + elm->info_last = NULL;
11579 + AuDebugOn(elm->info_dentry);
11584 + if (elm && w->renameback) {
11585 + delegated = NULL;
11586 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11588 + if (unlikely(err == -EWOULDBLOCK))
11594 + qname = &w->h_dentry->d_name;
11595 + len = sizeof(*w->fdata) + qname->len;
11597 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11598 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11599 + if (ssz == len) {
11600 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11601 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11602 + goto out_fput; /* success */
11607 + /* the caller should revert it using @elm */
11613 + dput(infopath.dentry);
11619 +struct au_call_drinfo_do_store_args {
11621 + struct au_drinfo_store *w;
11622 + struct au_drinfo_rev_elm *elm;
11625 +static void au_call_drinfo_do_store(void *args)
11627 + struct au_call_drinfo_do_store_args *a = args;
11629 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11632 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11633 + struct au_drinfo_rev_elm *elm)
11635 + int err, wkq_err;
11638 + err = au_drinfo_do_store(w, elm);
11640 + struct au_call_drinfo_do_store_args a = {
11645 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11646 + if (unlikely(wkq_err))
11654 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11655 + aufs_bindex_t btgt)
11659 + memset(w, 0, sizeof(*w));
11660 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11661 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11662 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11663 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11665 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11668 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11669 + if (unlikely(!w->fdata)) {
11673 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11680 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11685 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11686 + struct au_drinfo_store *w)
11688 + struct au_drinfo_rev_elm *elm;
11689 + struct inode *h_dir, *delegated;
11691 + struct path infopath = {
11692 + .mnt = w->h_ppath.mnt
11695 + h_dir = d_inode(w->h_ppath.dentry);
11696 + IMustLock(h_dir);
11700 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11701 + AuDebugOn(elm->created && elm->info_last);
11702 + if (elm->created) {
11704 + delegated = NULL;
11705 + infopath.dentry = elm->info_dentry;
11706 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11709 + if (unlikely(err == -EWOULDBLOCK))
11711 + dput(elm->info_dentry);
11712 + } else if (elm->info_last) {
11714 + w->fdata->drinfo = *elm->info_last;
11715 + memcpy(w->fdata->drinfo.oldname,
11716 + elm->info_last->oldname,
11717 + elm->info_last->oldnamelen);
11718 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11719 + kfree(elm->info_last);
11721 + if (unlikely(err))
11722 + AuIOErr("%d, %s\n", err, w->whname);
11723 + /* go on even if err */
11727 +/* caller has to call au_dr_rename_fin() later */
11728 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11729 + struct qstr *dst_name, void *_rev)
11731 + int err, sz, nelm;
11732 + aufs_bindex_t bindex, btail;
11733 + struct au_drinfo_store work;
11734 + struct au_drinfo_rev *rev, **p;
11735 + struct au_drinfo_rev_elm *elm;
11736 + struct super_block *sb;
11737 + struct au_branch *br;
11738 + struct au_hinode *hdir;
11740 + err = au_drinfo_store_work_init(&work, btgt);
11742 + if (unlikely(err))
11746 + btail = au_dbtaildir(dentry);
11747 + nelm = btail - btgt;
11748 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11749 + rev = kcalloc(1, sz, GFP_NOFS);
11750 + if (unlikely(!rev)) {
11754 + rev->nelm = nelm;
11760 + sb = dentry->d_sb;
11761 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11762 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11763 + hdir = au_hi(d_inode(dentry), btgt);
11764 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11765 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11766 + work.h_dentry = au_h_dptr(dentry, bindex);
11767 + if (!work.h_dentry)
11770 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11771 + &work.allocated);
11773 + if (unlikely(err))
11776 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11777 + br = au_sbr(sb, bindex);
11778 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11779 + work.whnamelen += au_drinfo_name(br, work.infoname,
11780 + work.infonamelen);
11781 + AuDbg("whname %.*s, i%llu, %.*s\n",
11782 + work.whnamelen, work.whname,
11783 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11784 + work.fdata->drinfo.oldnamelen,
11785 + work.fdata->drinfo.oldname);
11787 + err = au_drinfo_store_sio(&work, elm);
11789 + if (unlikely(err))
11792 + if (unlikely(err)) {
11793 + /* revert all drinfo */
11794 + au_drinfo_store_rev(rev, &work);
11798 + au_hn_inode_unlock(hdir);
11801 + au_drinfo_store_work_fin(&work);
11806 +/* ---------------------------------------------------------------------- */
11808 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11809 + struct qstr *dst_name, void *_rev)
11811 + int err, already;
11813 + struct super_block *sb;
11814 + struct au_branch *br;
11815 + struct au_dr_br *dr;
11816 + struct dentry *h_dentry;
11817 + struct inode *h_inode;
11818 + struct au_dr_hino *ent;
11819 + struct au_drinfo_rev *rev, **p;
11821 + AuDbg("bindex %d\n", bindex);
11824 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11825 + if (unlikely(!ent))
11829 + br = au_sbr(sb, bindex);
11830 + dr = &br->br_dirren;
11831 + h_dentry = au_h_dptr(src, bindex);
11832 + h_inode = d_inode(h_dentry);
11833 + ino = h_inode->i_ino;
11834 + ent->dr_h_ino = ino;
11835 + already = au_dr_hino_test_add(dr, ino, ent);
11836 + AuDbg("b%d, hi%llu, already %d\n",
11837 + bindex, (unsigned long long)ino, already);
11839 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11844 + rev->already = already;
11845 + goto out; /* success */
11850 + au_dr_hino_del(dr, ent);
11858 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11860 + struct au_drinfo_rev *rev;
11861 + struct au_drinfo_rev_elm *elm;
11866 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11867 + dput(elm->info_dentry);
11868 + kfree(elm->info_last);
11873 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11876 + struct au_drinfo_store work;
11877 + struct au_drinfo_rev *rev = _rev;
11878 + struct super_block *sb;
11879 + struct au_branch *br;
11880 + struct inode *h_inode;
11881 + struct au_dr_br *dr;
11882 + struct au_dr_hino *ent;
11884 + err = au_drinfo_store_work_init(&work, btgt);
11885 + if (unlikely(err))
11889 + br = au_sbr(sb, btgt);
11890 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11891 + work.h_ppath.mnt = au_br_mnt(br);
11892 + au_drinfo_store_rev(rev, &work);
11893 + au_drinfo_store_work_fin(&work);
11894 + if (rev->already)
11897 + dr = &br->br_dirren;
11898 + h_inode = d_inode(work.h_ppath.dentry);
11899 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11901 + au_dr_hino_del(dr, ent);
11906 + if (unlikely(err))
11907 + pr_err("failed to remove dirren info\n");
11910 +/* ---------------------------------------------------------------------- */
11912 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11913 + char *whname, int whnamelen,
11914 + struct dentry **info_dentry)
11916 + struct au_drinfo *drinfo;
11918 + struct inode *h_dir;
11919 + struct path infopath;
11922 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11924 + *info_dentry = NULL;
11927 + h_dir = d_inode(h_ppath->dentry);
11928 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11929 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11931 + if (IS_ERR(infopath.dentry)) {
11932 + drinfo = (void *)infopath.dentry;
11936 + if (d_is_negative(infopath.dentry))
11937 + goto out_dput; /* success */
11939 + infopath.mnt = h_ppath->mnt;
11940 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11941 + inode_unlock_shared(h_dir);
11944 + drinfo = (void *)f;
11948 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11949 + if (IS_ERR_OR_NULL(drinfo))
11952 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11953 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11958 + dput(infopath.dentry);
11961 + inode_unlock_shared(h_dir);
11962 + AuTraceErrPtr(drinfo);
11966 +struct au_drinfo_do_load_args {
11967 + struct au_drinfo **drinfop;
11968 + struct path *h_ppath;
11971 + struct dentry **info_dentry;
11974 +static void au_call_drinfo_do_load(void *args)
11976 + struct au_drinfo_do_load_args *a = args;
11978 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11982 +struct au_drinfo_load {
11983 + struct path h_ppath;
11984 + struct qstr *qname;
11985 + unsigned char no_sio;
11987 + aufs_bindex_t ninfo;
11988 + struct au_drinfo **drinfo;
11991 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11992 + struct au_branch *br)
11994 + int err, wkq_err, whnamelen, e;
11995 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11996 + = AUFS_WH_DR_INFO_PFX;
11997 + struct au_drinfo *drinfo;
11998 + struct qstr oldname;
11999 + struct inode *h_dir, *delegated;
12000 + struct dentry *info_dentry;
12001 + struct path infopath;
12003 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12004 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12005 + sizeof(whname) - whnamelen);
12007 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12010 + struct au_drinfo_do_load_args args = {
12011 + .drinfop = &drinfo,
12012 + .h_ppath = &w->h_ppath,
12013 + .whname = whname,
12014 + .whnamelen = whnamelen,
12015 + .info_dentry = &info_dentry
12017 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12018 + if (unlikely(wkq_err))
12019 + drinfo = ERR_PTR(wkq_err);
12021 + err = PTR_ERR(drinfo);
12022 + if (IS_ERR_OR_NULL(drinfo))
12026 + oldname.len = drinfo->oldnamelen;
12027 + oldname.name = drinfo->oldname;
12028 + if (au_qstreq(w->qname, &oldname)) {
12029 + /* the name is renamed back */
12033 + infopath.dentry = info_dentry;
12034 + infopath.mnt = w->h_ppath.mnt;
12035 + h_dir = d_inode(w->h_ppath.dentry);
12036 + delegated = NULL;
12037 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12038 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12039 + inode_unlock(h_dir);
12041 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12042 + if (unlikely(e == -EWOULDBLOCK))
12045 + kfree(w->drinfo[bindex]);
12046 + w->drinfo[bindex] = drinfo;
12047 + dput(info_dentry);
12054 +/* ---------------------------------------------------------------------- */
12056 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12058 + struct au_drinfo **p = drinfo;
12061 + kfree(*drinfo++);
12065 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12066 + aufs_bindex_t btgt)
12069 + struct au_drinfo_load w;
12070 + aufs_bindex_t bindex, bbot;
12071 + struct au_branch *br;
12072 + struct inode *h_dir;
12073 + struct au_dr_hino *ent;
12074 + struct super_block *sb;
12076 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12077 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12078 + AuLNPair(&lkup->whname), btgt);
12080 + sb = dentry->d_sb;
12081 + bbot = au_sbbot(sb);
12082 + w.ninfo = bbot + 1;
12083 + if (!lkup->dirren.drinfo) {
12084 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12085 + sizeof(*lkup->dirren.drinfo),
12087 + if (unlikely(!lkup->dirren.drinfo)) {
12091 + lkup->dirren.ninfo = w.ninfo;
12093 + w.drinfo = lkup->dirren.drinfo;
12094 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12095 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12096 + AuDebugOn(!w.h_ppath.dentry);
12097 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12098 + w.qname = &dentry->d_name;
12101 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12102 + br = au_sbr(sb, bindex);
12103 + err = au_drinfo_load(&w, bindex, br);
12104 + if (unlikely(err))
12106 + if (w.drinfo[bindex])
12110 + br = au_sbr(sb, btgt);
12111 + h_dir = d_inode(w.h_ppath.dentry);
12112 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12114 + au_dr_hino_del(&br->br_dirren, ent);
12117 + goto out; /* success */
12120 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12121 + lkup->dirren.ninfo = 0;
12122 + lkup->dirren.drinfo = NULL;
12128 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12130 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12133 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12136 + struct au_drinfo *drinfo;
12139 + if (!lkup->dirren.drinfo)
12141 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12142 + drinfo = lkup->dirren.drinfo[btgt + 1];
12146 + kfree(lkup->whname.name);
12147 + lkup->whname.name = NULL;
12148 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12149 + lkup->dirren.dr_name.name = drinfo->oldname;
12150 + lkup->name = &lkup->dirren.dr_name;
12151 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12153 + AuDbg("name %.*s, whname %.*s, b%d\n",
12154 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12162 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12166 + struct au_drinfo *drinfo;
12169 + if (!lkup->dirren.drinfo)
12171 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12172 + drinfo = lkup->dirren.drinfo[bindex + 1];
12176 + match = (drinfo->ino == h_ino);
12177 + AuDbg("match %d\n", match);
12183 +/* ---------------------------------------------------------------------- */
12185 +int au_dr_opt_set(struct super_block *sb)
12188 + aufs_bindex_t bindex, bbot;
12189 + struct au_branch *br;
12192 + bbot = au_sbbot(sb);
12193 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12194 + br = au_sbr(sb, bindex);
12195 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12201 +int au_dr_opt_flush(struct super_block *sb)
12204 + aufs_bindex_t bindex, bbot;
12205 + struct au_branch *br;
12208 + bbot = au_sbbot(sb);
12209 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12210 + br = au_sbr(sb, bindex);
12211 + if (au_br_writable(br->br_perm))
12212 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12218 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12221 + aufs_bindex_t bindex, bbot;
12222 + struct au_branch *br;
12226 + err = au_dr_opt_flush(sb);
12227 + if (unlikely(err))
12231 + bbot = au_sbbot(sb);
12232 + for (bindex = 0; bindex <= bbot; bindex++) {
12233 + br = au_sbr(sb, bindex);
12234 + au_dr_hino_free(&br->br_dirren);
12240 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12241 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12242 +++ linux/fs/aufs/dirren.h 2018-06-04 09:08:09.184746078 +0200
12245 + * Copyright (C) 2017-2018 Junjiro R. Okajima
12247 + * This program, aufs is free software; you can redistribute it and/or modify
12248 + * it under the terms of the GNU General Public License as published by
12249 + * the Free Software Foundation; either version 2 of the License, or
12250 + * (at your option) any later version.
12252 + * This program is distributed in the hope that it will be useful,
12253 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12254 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12255 + * GNU General Public License for more details.
12257 + * You should have received a copy of the GNU General Public License
12258 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12262 + * renamed dir info
12265 +#ifndef __AUFS_DIRREN_H__
12266 +#define __AUFS_DIRREN_H__
12270 +#include <linux/dcache.h>
12271 +#include <linux/statfs.h>
12272 +#include <linux/uuid.h>
12275 +#define AuDirren_NHASH 100
12277 +#ifdef CONFIG_AUFS_DIRREN
12278 +enum au_brid_type {
12285 +struct au_dr_brid {
12286 + enum au_brid_type type;
12288 + uuid_t uuid; /* unimplemented yet */
12294 +/* 20 is the max digits length of ulong 64 */
12295 +/* brid-type "_" uuid "_" inum */
12296 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12297 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12299 +struct au_dr_hino {
12300 + struct hlist_bl_node dr_hnode;
12305 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12306 + struct au_dr_brid dr_brid;
12309 +struct au_dr_lookup {
12310 + /* dr_name is pointed by struct au_do_lookup_args.name */
12311 + struct qstr dr_name; /* subset of dr_info */
12312 + aufs_bindex_t ninfo;
12313 + struct au_drinfo **drinfo;
12316 +struct au_dr_hino;
12318 +struct au_dr_br { };
12319 +struct au_dr_lookup { };
12322 +/* ---------------------------------------------------------------------- */
12325 +struct au_do_lookup_args;
12327 +#ifdef CONFIG_AUFS_DIRREN
12328 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12329 + struct au_dr_hino *add_ent);
12330 +void au_dr_hino_free(struct au_dr_br *dr);
12331 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12332 + const struct path *path);
12333 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12334 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12335 + struct qstr *dst_name, void *_rev);
12336 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12337 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12338 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12339 + aufs_bindex_t bindex);
12340 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12341 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12343 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12344 +int au_dr_opt_set(struct super_block *sb);
12345 +int au_dr_opt_flush(struct super_block *sb);
12346 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12348 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12349 + struct au_dr_hino *add_ent);
12350 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12351 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12352 + const struct path *path);
12353 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12354 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12355 + struct qstr *dst_name, void *_rev);
12356 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12357 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12359 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12360 + aufs_bindex_t bindex);
12361 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12362 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12363 + aufs_bindex_t bindex, ino_t h_ino);
12364 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12365 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12366 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12367 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12370 +/* ---------------------------------------------------------------------- */
12372 +#ifdef CONFIG_AUFS_DIRREN
12373 +static inline int au_dr_ihash(ino_t h_ino)
12375 + return h_ino % AuDirren_NHASH;
12378 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12381 +#endif /* __KERNEL__ */
12382 +#endif /* __AUFS_DIRREN_H__ */
12383 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12384 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12385 +++ linux/fs/aufs/dynop.c 2018-04-15 08:49:13.397817296 +0200
12388 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12390 + * This program, aufs is free software; you can redistribute it and/or modify
12391 + * it under the terms of the GNU General Public License as published by
12392 + * the Free Software Foundation; either version 2 of the License, or
12393 + * (at your option) any later version.
12395 + * This program is distributed in the hope that it will be useful,
12396 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12397 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12398 + * GNU General Public License for more details.
12400 + * You should have received a copy of the GNU General Public License
12401 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12405 + * dynamically customizable operations for regular files
12410 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12413 + * How large will these lists be?
12414 + * Usually just a few elements, 20-30 at most for each, I guess.
12416 +static struct hlist_bl_head dynop[AuDyLast];
12418 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12419 + const void *h_op)
12421 + struct au_dykey *key, *tmp;
12422 + struct hlist_bl_node *pos;
12425 + hlist_bl_lock(hbl);
12426 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12427 + if (tmp->dk_op.dy_hop == h_op) {
12429 + kref_get(&key->dk_kref);
12432 + hlist_bl_unlock(hbl);
12437 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12439 + struct au_dykey **k, *found;
12440 + const void *h_op = key->dk_op.dy_hop;
12444 + k = br->br_dykey;
12445 + for (i = 0; i < AuBrDynOp; i++)
12447 + if (k[i]->dk_op.dy_hop == h_op) {
12454 + spin_lock(&br->br_dykey_lock);
12455 + for (; i < AuBrDynOp; i++)
12457 + if (k[i]->dk_op.dy_hop == h_op) {
12465 + spin_unlock(&br->br_dykey_lock);
12466 + BUG_ON(i == AuBrDynOp); /* expand the array */
12472 +/* kref_get() if @key is already added */
12473 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12475 + struct au_dykey *tmp, *found;
12476 + struct hlist_bl_node *pos;
12477 + const void *h_op = key->dk_op.dy_hop;
12480 + hlist_bl_lock(hbl);
12481 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12482 + if (tmp->dk_op.dy_hop == h_op) {
12483 + kref_get(&tmp->dk_kref);
12488 + hlist_bl_add_head(&key->dk_hnode, hbl);
12489 + hlist_bl_unlock(hbl);
12496 +static void dy_free_rcu(struct rcu_head *rcu)
12498 + struct au_dykey *key;
12500 + key = container_of(rcu, struct au_dykey, dk_rcu);
12505 +static void dy_free(struct kref *kref)
12507 + struct au_dykey *key;
12508 + struct hlist_bl_head *hbl;
12510 + key = container_of(kref, struct au_dykey, dk_kref);
12511 + hbl = dynop + key->dk_op.dy_type;
12512 + au_hbl_del(&key->dk_hnode, hbl);
12513 + call_rcu(&key->dk_rcu, dy_free_rcu);
12516 +void au_dy_put(struct au_dykey *key)
12518 + kref_put(&key->dk_kref, dy_free);
12521 +/* ---------------------------------------------------------------------- */
12523 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12525 +#ifdef CONFIG_AUFS_DEBUG
12526 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12527 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12529 +#define DyDbgDeclare(cnt) do {} while (0)
12530 +#define DyDbgInc(cnt) do {} while (0)
12533 +#define DySet(func, dst, src, h_op, h_sb) do { \
12535 + if (h_op->func) { \
12537 + dst.func = src.func; \
12539 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12543 +#define DySetForce(func, dst, src) do { \
12544 + AuDebugOn(!src.func); \
12546 + dst.func = src.func; \
12549 +#define DySetAop(func) \
12550 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12551 +#define DySetAopForce(func) \
12552 + DySetForce(func, dyaop->da_op, aufs_aop)
12554 +static void dy_aop(struct au_dykey *key, const void *h_op,
12555 + struct super_block *h_sb __maybe_unused)
12557 + struct au_dyaop *dyaop = (void *)key;
12558 + const struct address_space_operations *h_aop = h_op;
12559 + DyDbgDeclare(cnt);
12561 + AuDbg("%s\n", au_sbtype(h_sb));
12563 + DySetAop(writepage);
12564 + DySetAopForce(readpage); /* force */
12565 + DySetAop(writepages);
12566 + DySetAop(set_page_dirty);
12567 + DySetAop(readpages);
12568 + DySetAop(write_begin);
12569 + DySetAop(write_end);
12571 + DySetAop(invalidatepage);
12572 + DySetAop(releasepage);
12573 + DySetAop(freepage);
12574 + /* this one will be changed according to an aufs mount option */
12575 + DySetAop(direct_IO);
12576 + DySetAop(migratepage);
12577 + DySetAop(isolate_page);
12578 + DySetAop(putback_page);
12579 + DySetAop(launder_page);
12580 + DySetAop(is_partially_uptodate);
12581 + DySetAop(is_dirty_writeback);
12582 + DySetAop(error_remove_page);
12583 + DySetAop(swap_activate);
12584 + DySetAop(swap_deactivate);
12586 + DyDbgSize(cnt, *h_aop);
12589 +/* ---------------------------------------------------------------------- */
12591 +static void dy_bug(struct kref *kref)
12596 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12598 + struct au_dykey *key, *old;
12599 + struct hlist_bl_head *hbl;
12602 + void (*set)(struct au_dykey *key, const void *h_op,
12603 + struct super_block *h_sb __maybe_unused);
12605 + static const struct op a[] = {
12607 + .sz = sizeof(struct au_dyaop),
12611 + const struct op *p;
12613 + hbl = dynop + op->dy_type;
12614 + key = dy_gfind_get(hbl, op->dy_hop);
12616 + goto out_add; /* success */
12618 + p = a + op->dy_type;
12619 + key = kzalloc(p->sz, GFP_NOFS);
12620 + if (unlikely(!key)) {
12621 + key = ERR_PTR(-ENOMEM);
12625 + key->dk_op.dy_hop = op->dy_hop;
12626 + kref_init(&key->dk_kref);
12627 + p->set(key, op->dy_hop, au_br_sb(br));
12628 + old = dy_gadd(hbl, key);
12635 + old = dy_bradd(br, key);
12637 + /* its ref-count should never be zero here */
12638 + kref_put(&key->dk_kref, dy_bug);
12643 +/* ---------------------------------------------------------------------- */
12645 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
12646 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12647 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12648 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12649 + * See the aufs manual in detail.
12651 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12654 + dyaop->da_op.direct_IO = NULL;
12656 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12659 +static struct au_dyaop *dy_aget(struct au_branch *br,
12660 + const struct address_space_operations *h_aop,
12663 + struct au_dyaop *dyaop;
12664 + struct au_dynop op;
12666 + op.dy_type = AuDy_AOP;
12667 + op.dy_haop = h_aop;
12668 + dyaop = (void *)dy_get(&op, br);
12669 + if (IS_ERR(dyaop))
12671 + dy_adx(dyaop, do_dx);
12677 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12678 + struct inode *h_inode)
12681 + struct super_block *sb;
12682 + struct au_branch *br;
12683 + struct au_dyaop *dyaop;
12685 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12686 + IiMustWriteLock(inode);
12688 + sb = inode->i_sb;
12689 + br = au_sbr(sb, bindex);
12690 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12691 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12692 + err = PTR_ERR(dyaop);
12693 + if (IS_ERR(dyaop))
12694 + /* unnecessary to call dy_fput() */
12698 + inode->i_mapping->a_ops = &dyaop->da_op;
12705 + * Is it safe to replace a_ops during the inode/file is in operation?
12706 + * Yes, I hope so.
12708 +int au_dy_irefresh(struct inode *inode)
12711 + aufs_bindex_t btop;
12712 + struct inode *h_inode;
12715 + if (S_ISREG(inode->i_mode)) {
12716 + btop = au_ibtop(inode);
12717 + h_inode = au_h_iptr(inode, btop);
12718 + err = au_dy_iaop(inode, btop, h_inode);
12723 +void au_dy_arefresh(int do_dx)
12725 + struct hlist_bl_head *hbl;
12726 + struct hlist_bl_node *pos;
12727 + struct au_dykey *key;
12729 + hbl = dynop + AuDy_AOP;
12730 + hlist_bl_lock(hbl);
12731 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12732 + dy_adx((void *)key, do_dx);
12733 + hlist_bl_unlock(hbl);
12736 +/* ---------------------------------------------------------------------- */
12738 +void __init au_dy_init(void)
12742 + /* make sure that 'struct au_dykey *' can be any type */
12743 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12745 + for (i = 0; i < AuDyLast; i++)
12746 + INIT_HLIST_BL_HEAD(dynop + i);
12749 +void au_dy_fin(void)
12753 + for (i = 0; i < AuDyLast; i++)
12754 + WARN_ON(!hlist_bl_empty(dynop + i));
12756 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12757 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12758 +++ linux/fs/aufs/dynop.h 2018-04-15 08:49:13.397817296 +0200
12761 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12763 + * This program, aufs is free software; you can redistribute it and/or modify
12764 + * it under the terms of the GNU General Public License as published by
12765 + * the Free Software Foundation; either version 2 of the License, or
12766 + * (at your option) any later version.
12768 + * This program is distributed in the hope that it will be useful,
12769 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12770 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12771 + * GNU General Public License for more details.
12773 + * You should have received a copy of the GNU General Public License
12774 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12778 + * dynamically customizable operations (for regular files only)
12781 +#ifndef __AUFS_DYNOP_H__
12782 +#define __AUFS_DYNOP_H__
12786 +#include <linux/fs.h>
12787 +#include <linux/kref.h>
12789 +enum {AuDy_AOP, AuDyLast};
12794 + const void *dy_hop;
12795 + const struct address_space_operations *dy_haop;
12801 + struct hlist_bl_node dk_hnode;
12802 + struct rcu_head dk_rcu;
12804 + struct au_dynop dk_op;
12807 + * during I am in the branch local array, kref is gotten. when the
12808 + * branch is removed, kref is put.
12810 + struct kref dk_kref;
12813 +/* stop unioning since their sizes are very different from each other */
12815 + struct au_dykey da_key;
12816 + struct address_space_operations da_op; /* not const */
12819 +/* ---------------------------------------------------------------------- */
12823 +void au_dy_put(struct au_dykey *key);
12824 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12825 + struct inode *h_inode);
12826 +int au_dy_irefresh(struct inode *inode);
12827 +void au_dy_arefresh(int do_dio);
12829 +void __init au_dy_init(void);
12830 +void au_dy_fin(void);
12832 +#endif /* __KERNEL__ */
12833 +#endif /* __AUFS_DYNOP_H__ */
12834 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12835 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12836 +++ linux/fs/aufs/export.c 2018-04-15 08:49:13.397817296 +0200
12839 + * Copyright (C) 2005-2018 Junjiro R. Okajima
12841 + * This program, aufs is free software; you can redistribute it and/or modify
12842 + * it under the terms of the GNU General Public License as published by
12843 + * the Free Software Foundation; either version 2 of the License, or
12844 + * (at your option) any later version.
12846 + * This program is distributed in the hope that it will be useful,
12847 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12848 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12849 + * GNU General Public License for more details.
12851 + * You should have received a copy of the GNU General Public License
12852 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12859 +#include <linux/exportfs.h>
12860 +#include <linux/fs_struct.h>
12861 +#include <linux/namei.h>
12862 +#include <linux/nsproxy.h>
12863 +#include <linux/random.h>
12864 +#include <linux/writeback.h>
12868 +#ifdef CONFIG_AUFS_INO_T_64
12876 +static ino_t decode_ino(__u32 *a)
12880 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12882 +#ifdef CONFIG_AUFS_INO_T_64
12888 +static void encode_ino(__u32 *a, ino_t ino)
12894 +#ifdef CONFIG_AUFS_INO_T_64
12899 +/* NFS file handle */
12903 +#ifdef CONFIG_AUFS_INO_T_64
12904 + /* support 64bit inode number */
12917 + Fh_ino = Fh_ino1,
12918 + Fh_dir_ino = Fh_dir_ino1
12921 +static int au_test_anon(struct dentry *dentry)
12923 + /* note: read d_flags without d_lock */
12924 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12927 +int au_test_nfsd(void)
12930 + struct task_struct *tsk = current;
12931 + char comm[sizeof(tsk->comm)];
12934 + if (tsk->flags & PF_KTHREAD) {
12935 + get_task_comm(comm, tsk);
12936 + ret = !strcmp(comm, "nfsd");
12942 +/* ---------------------------------------------------------------------- */
12943 +/* inode generation external table */
12945 +void au_xigen_inc(struct inode *inode)
12950 + struct super_block *sb;
12951 + struct au_sbinfo *sbinfo;
12953 + sb = inode->i_sb;
12954 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12956 + sbinfo = au_sbi(sb);
12957 + pos = inode->i_ino;
12958 + pos *= sizeof(igen);
12959 + igen = inode->i_generation + 1;
12960 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12961 + sizeof(igen), &pos);
12962 + if (sz == sizeof(igen))
12963 + return; /* success */
12965 + if (unlikely(sz >= 0))
12966 + AuIOErr("xigen error (%zd)\n", sz);
12969 +int au_xigen_new(struct inode *inode)
12974 + struct super_block *sb;
12975 + struct au_sbinfo *sbinfo;
12976 + struct file *file;
12979 + /* todo: dirty, at mount time */
12980 + if (inode->i_ino == AUFS_ROOT_INO)
12982 + sb = inode->i_sb;
12983 + SiMustAnyLock(sb);
12984 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12988 + pos = inode->i_ino;
12989 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12990 + AuIOErr1("too large i%lld\n", pos);
12993 + pos *= sizeof(inode->i_generation);
12996 + sbinfo = au_sbi(sb);
12997 + file = sbinfo->si_xigen;
13000 + if (vfsub_f_size_read(file)
13001 + < pos + sizeof(inode->i_generation)) {
13002 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13003 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13004 + sizeof(inode->i_generation), &pos);
13006 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13007 + sizeof(inode->i_generation), &pos);
13008 + if (sz == sizeof(inode->i_generation))
13009 + goto out; /* success */
13012 + if (unlikely(sz >= 0)) {
13014 + AuIOErr("xigen error (%zd)\n", sz);
13021 +int au_xigen_set(struct super_block *sb, struct file *base)
13024 + struct au_sbinfo *sbinfo;
13025 + struct file *file;
13027 + SiMustWriteLock(sb);
13029 + sbinfo = au_sbi(sb);
13030 + file = au_xino_create2(base, sbinfo->si_xigen);
13031 + err = PTR_ERR(file);
13032 + if (IS_ERR(file))
13035 + if (sbinfo->si_xigen)
13036 + fput(sbinfo->si_xigen);
13037 + sbinfo->si_xigen = file;
13043 +void au_xigen_clr(struct super_block *sb)
13045 + struct au_sbinfo *sbinfo;
13047 + SiMustWriteLock(sb);
13049 + sbinfo = au_sbi(sb);
13050 + if (sbinfo->si_xigen) {
13051 + fput(sbinfo->si_xigen);
13052 + sbinfo->si_xigen = NULL;
13056 +/* ---------------------------------------------------------------------- */
13058 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13061 + struct dentry *dentry, *d;
13062 + struct inode *inode;
13063 + unsigned int sigen;
13066 + inode = ilookup(sb, ino);
13070 + dentry = ERR_PTR(-ESTALE);
13071 + sigen = au_sigen(sb);
13072 + if (unlikely(au_is_bad_inode(inode)
13073 + || IS_DEADDIR(inode)
13074 + || sigen != au_iigen(inode, NULL)))
13078 + if (!dir_ino || S_ISDIR(inode->i_mode))
13079 + dentry = d_find_alias(inode);
13081 + spin_lock(&inode->i_lock);
13082 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13083 + spin_lock(&d->d_lock);
13084 + if (!au_test_anon(d)
13085 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13086 + dentry = dget_dlock(d);
13087 + spin_unlock(&d->d_lock);
13090 + spin_unlock(&d->d_lock);
13092 + spin_unlock(&inode->i_lock);
13094 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13095 + /* need to refresh */
13103 + AuTraceErrPtr(dentry);
13107 +/* ---------------------------------------------------------------------- */
13109 +/* todo: dirty? */
13110 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13112 +struct au_compare_mnt_args {
13114 + struct super_block *sb;
13117 + struct vfsmount *mnt;
13120 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13122 + struct au_compare_mnt_args *a = arg;
13124 + if (mnt->mnt_sb != a->sb)
13126 + a->mnt = mntget(mnt);
13130 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13133 + struct path root;
13134 + struct au_compare_mnt_args args = {
13138 + get_fs_root(current->fs, &root);
13140 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13141 + rcu_read_unlock();
13144 + AuDebugOn(!args.mnt);
13148 +struct au_nfsd_si_lock {
13149 + unsigned int sigen;
13150 + aufs_bindex_t bindex, br_id;
13151 + unsigned char force_lock;
13154 +static int si_nfsd_read_lock(struct super_block *sb,
13155 + struct au_nfsd_si_lock *nsi_lock)
13158 + aufs_bindex_t bindex;
13160 + si_read_lock(sb, AuLock_FLUSH);
13162 + /* branch id may be wrapped around */
13164 + bindex = au_br_index(sb, nsi_lock->br_id);
13165 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13166 + goto out; /* success */
13170 + if (!nsi_lock->force_lock)
13171 + si_read_unlock(sb);
13174 + nsi_lock->bindex = bindex;
13178 +struct find_name_by_ino {
13179 + struct dir_context ctx;
13180 + int called, found;
13187 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13188 + loff_t offset, u64 ino, unsigned int d_type)
13190 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13194 + if (a->ino != ino)
13197 + memcpy(a->name, name, namelen);
13198 + a->namelen = namelen;
13203 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13204 + struct au_nfsd_si_lock *nsi_lock)
13206 + struct dentry *dentry, *parent;
13207 + struct file *file;
13208 + struct inode *dir;
13209 + struct find_name_by_ino arg = {
13211 + .actor = find_name_by_ino
13216 + parent = path->dentry;
13218 + si_read_unlock(parent->d_sb);
13219 + file = vfsub_dentry_open(path, au_dir_roflags);
13220 + dentry = (void *)file;
13221 + if (IS_ERR(file))
13224 + dentry = ERR_PTR(-ENOMEM);
13225 + arg.name = (void *)__get_free_page(GFP_NOFS);
13226 + if (unlikely(!arg.name))
13233 + err = vfsub_iterate_dir(file, &arg.ctx);
13234 + } while (!err && !arg.found && arg.called);
13235 + dentry = ERR_PTR(err);
13236 + if (unlikely(err))
13238 + /* instead of ENOENT */
13239 + dentry = ERR_PTR(-ESTALE);
13243 + /* do not call vfsub_lkup_one() */
13244 + dir = d_inode(parent);
13245 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13246 + AuTraceErrPtr(dentry);
13247 + if (IS_ERR(dentry))
13249 + AuDebugOn(au_test_anon(dentry));
13250 + if (unlikely(d_really_is_negative(dentry))) {
13252 + dentry = ERR_PTR(-ENOENT);
13256 + free_page((unsigned long)arg.name);
13260 + if (unlikely(nsi_lock
13261 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13262 + if (!IS_ERR(dentry)) {
13264 + dentry = ERR_PTR(-ESTALE);
13266 + AuTraceErrPtr(dentry);
13270 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13272 + struct au_nfsd_si_lock *nsi_lock)
13274 + struct dentry *dentry;
13275 + struct path path;
13277 + if (dir_ino != AUFS_ROOT_INO) {
13278 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13279 + dentry = path.dentry;
13280 + if (!path.dentry || IS_ERR(path.dentry))
13282 + AuDebugOn(au_test_anon(path.dentry));
13284 + path.dentry = dget(sb->s_root);
13286 + path.mnt = au_mnt_get(sb);
13287 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13291 + AuTraceErrPtr(dentry);
13295 +/* ---------------------------------------------------------------------- */
13297 +static int h_acceptable(void *expv, struct dentry *dentry)
13302 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13303 + char *buf, int len, struct super_block *sb)
13307 + struct path path;
13309 + p = d_path(h_rootpath, buf, len);
13314 + path.mnt = h_rootpath->mnt;
13315 + path.dentry = h_parent;
13316 + p = d_path(&path, buf, len);
13322 + path.mnt = au_mnt_get(sb);
13323 + path.dentry = sb->s_root;
13324 + p = d_path(&path, buf, len - strlen(p));
13325 + mntput(path.mnt);
13329 + p[strlen(p)] = '/';
13332 + AuTraceErrPtr(p);
13337 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13338 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13340 + struct dentry *dentry, *h_parent, *root;
13341 + struct super_block *h_sb;
13342 + char *pathname, *p;
13343 + struct vfsmount *h_mnt;
13344 + struct au_branch *br;
13346 + struct path path;
13348 + br = au_sbr(sb, nsi_lock->bindex);
13349 + h_mnt = au_br_mnt(br);
13350 + h_sb = h_mnt->mnt_sb;
13351 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13353 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13354 + fh_len - Fh_tail, fh[Fh_h_type],
13355 + h_acceptable, /*context*/NULL);
13357 + dentry = h_parent;
13358 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13359 + AuWarn1("%s decode_fh failed, %ld\n",
13360 + au_sbtype(h_sb), PTR_ERR(h_parent));
13364 + if (unlikely(au_test_anon(h_parent))) {
13365 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13366 + au_sbtype(h_sb));
13367 + goto out_h_parent;
13370 + dentry = ERR_PTR(-ENOMEM);
13371 + pathname = (void *)__get_free_page(GFP_NOFS);
13372 + if (unlikely(!pathname))
13373 + goto out_h_parent;
13375 + root = sb->s_root;
13376 + path.mnt = h_mnt;
13377 + di_read_lock_parent(root, !AuLock_IR);
13378 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13379 + di_read_unlock(root, !AuLock_IR);
13380 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13381 + dentry = (void *)p;
13383 + goto out_pathname;
13385 + si_read_unlock(sb);
13386 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13387 + dentry = ERR_PTR(err);
13388 + if (unlikely(err))
13391 + dentry = ERR_PTR(-ENOENT);
13392 + AuDebugOn(au_test_anon(path.dentry));
13393 + if (unlikely(d_really_is_negative(path.dentry)))
13396 + if (ino != d_inode(path.dentry)->i_ino)
13397 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13399 + dentry = dget(path.dentry);
13404 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13405 + if (!IS_ERR(dentry)) {
13407 + dentry = ERR_PTR(-ESTALE);
13410 + free_page((unsigned long)pathname);
13414 + AuTraceErrPtr(dentry);
13418 +/* ---------------------------------------------------------------------- */
13420 +static struct dentry *
13421 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13424 + struct dentry *dentry;
13425 + __u32 *fh = fid->raw;
13426 + struct au_branch *br;
13427 + ino_t ino, dir_ino;
13428 + struct au_nfsd_si_lock nsi_lock = {
13432 + dentry = ERR_PTR(-ESTALE);
13433 + /* it should never happen, but the file handle is unreliable */
13434 + if (unlikely(fh_len < Fh_tail))
13436 + nsi_lock.sigen = fh[Fh_sigen];
13437 + nsi_lock.br_id = fh[Fh_br_id];
13439 + /* branch id may be wrapped around */
13441 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13443 + nsi_lock.force_lock = 1;
13445 + /* is this inode still cached? */
13446 + ino = decode_ino(fh + Fh_ino);
13447 + /* it should never happen */
13448 + if (unlikely(ino == AUFS_ROOT_INO))
13451 + dir_ino = decode_ino(fh + Fh_dir_ino);
13452 + dentry = decode_by_ino(sb, ino, dir_ino);
13453 + if (IS_ERR(dentry))
13458 + /* is the parent dir cached? */
13459 + br = au_sbr(sb, nsi_lock.bindex);
13461 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13462 + if (IS_ERR(dentry))
13467 + /* lookup path */
13468 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13469 + if (IS_ERR(dentry))
13471 + if (unlikely(!dentry))
13472 + /* todo?: make it ESTALE */
13476 + if (!au_digen_test(dentry, au_sigen(sb))
13477 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13478 + goto out_unlock; /* success */
13481 + dentry = ERR_PTR(-ESTALE);
13485 + si_read_unlock(sb);
13487 + AuTraceErrPtr(dentry);
13491 +#if 0 /* reserved for future use */
13492 +/* support subtreecheck option */
13493 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13494 + int fh_len, int fh_type)
13496 + struct dentry *parent;
13497 + __u32 *fh = fid->raw;
13500 + dir_ino = decode_ino(fh + Fh_dir_ino);
13501 + parent = decode_by_ino(sb, dir_ino, 0);
13502 + if (IS_ERR(parent))
13505 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13506 + dir_ino, fh, fh_len);
13509 + AuTraceErrPtr(parent);
13514 +/* ---------------------------------------------------------------------- */
13516 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13517 + struct inode *dir)
13520 + aufs_bindex_t bindex;
13521 + struct super_block *sb, *h_sb;
13522 + struct dentry *dentry, *parent, *h_parent;
13523 + struct inode *h_dir;
13524 + struct au_branch *br;
13527 + if (unlikely(*max_len <= Fh_tail)) {
13528 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13532 + err = FILEID_ROOT;
13533 + if (inode->i_ino == AUFS_ROOT_INO) {
13534 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13539 + sb = inode->i_sb;
13540 + err = si_read_lock(sb, AuLock_FLUSH);
13541 + if (unlikely(err))
13544 +#ifdef CONFIG_AUFS_DEBUG
13545 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13546 + AuWarn1("NFS-exporting requires xino\n");
13550 + ii_read_lock_child(inode);
13551 + bindex = au_ibtop(inode);
13553 + dentry = d_find_any_alias(inode);
13554 + if (unlikely(!dentry))
13556 + AuDebugOn(au_test_anon(dentry));
13557 + parent = dget_parent(dentry);
13559 + if (unlikely(!parent))
13561 + if (d_really_is_positive(parent))
13562 + dir = d_inode(parent);
13565 + ii_read_lock_parent(dir);
13566 + h_dir = au_h_iptr(dir, bindex);
13567 + ii_read_unlock(dir);
13568 + if (unlikely(!h_dir))
13570 + h_parent = d_find_any_alias(h_dir);
13571 + if (unlikely(!h_parent))
13572 + goto out_hparent;
13575 + br = au_sbr(sb, bindex);
13576 + h_sb = au_br_sb(br);
13577 + if (unlikely(!h_sb->s_export_op)) {
13578 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13579 + goto out_hparent;
13582 + fh[Fh_br_id] = br->br_id;
13583 + fh[Fh_sigen] = au_sigen(sb);
13584 + encode_ino(fh + Fh_ino, inode->i_ino);
13585 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13586 + fh[Fh_igen] = inode->i_generation;
13588 + *max_len -= Fh_tail;
13589 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13591 + /*connectable or subtreecheck*/0);
13592 + err = fh[Fh_h_type];
13593 + *max_len += Fh_tail;
13594 + /* todo: macros? */
13595 + if (err != FILEID_INVALID)
13598 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13605 + ii_read_unlock(inode);
13606 + si_read_unlock(sb);
13608 + if (unlikely(err < 0))
13609 + err = FILEID_INVALID;
13613 +/* ---------------------------------------------------------------------- */
13615 +static int aufs_commit_metadata(struct inode *inode)
13618 + aufs_bindex_t bindex;
13619 + struct super_block *sb;
13620 + struct inode *h_inode;
13621 + int (*f)(struct inode *inode);
13623 + sb = inode->i_sb;
13624 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13625 + ii_write_lock_child(inode);
13626 + bindex = au_ibtop(inode);
13627 + AuDebugOn(bindex < 0);
13628 + h_inode = au_h_iptr(inode, bindex);
13630 + f = h_inode->i_sb->s_export_op->commit_metadata;
13632 + err = f(h_inode);
13634 + struct writeback_control wbc = {
13635 + .sync_mode = WB_SYNC_ALL,
13636 + .nr_to_write = 0 /* metadata only */
13639 + err = sync_inode(h_inode, &wbc);
13642 + au_cpup_attr_timesizes(inode);
13643 + ii_write_unlock(inode);
13644 + si_read_unlock(sb);
13648 +/* ---------------------------------------------------------------------- */
13650 +static struct export_operations aufs_export_op = {
13651 + .fh_to_dentry = aufs_fh_to_dentry,
13652 + /* .fh_to_parent = aufs_fh_to_parent, */
13653 + .encode_fh = aufs_encode_fh,
13654 + .commit_metadata = aufs_commit_metadata
13657 +void au_export_init(struct super_block *sb)
13659 + struct au_sbinfo *sbinfo;
13662 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13663 + && IS_MODULE(CONFIG_EXPORTFS),
13664 + AUFS_NAME ": unsupported configuration "
13665 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13667 + sb->s_export_op = &aufs_export_op;
13668 + sbinfo = au_sbi(sb);
13669 + sbinfo->si_xigen = NULL;
13670 + get_random_bytes(&u, sizeof(u));
13671 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13672 + atomic_set(&sbinfo->si_xigen_next, u);
13674 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13675 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13676 +++ linux/fs/aufs/fhsm.c 2018-06-04 09:08:09.184746078 +0200
13679 + * Copyright (C) 2011-2018 Junjiro R. Okajima
13681 + * This program, aufs is free software; you can redistribute it and/or modify
13682 + * it under the terms of the GNU General Public License as published by
13683 + * the Free Software Foundation; either version 2 of the License, or
13684 + * (at your option) any later version.
13686 + * This program is distributed in the hope that it will be useful,
13687 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13688 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13689 + * GNU General Public License for more details.
13691 + * You should have received a copy of the GNU General Public License
13692 + * along with this program; if not, write to the Free Software
13693 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13697 + * File-based Hierarchy Storage Management
13700 +#include <linux/anon_inodes.h>
13701 +#include <linux/poll.h>
13702 +#include <linux/seq_file.h>
13703 +#include <linux/statfs.h>
13706 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13708 + struct au_sbinfo *sbinfo;
13709 + struct au_fhsm *fhsm;
13711 + SiMustAnyLock(sb);
13713 + sbinfo = au_sbi(sb);
13714 + fhsm = &sbinfo->si_fhsm;
13715 + AuDebugOn(!fhsm);
13716 + return fhsm->fhsm_bottom;
13719 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13721 + struct au_sbinfo *sbinfo;
13722 + struct au_fhsm *fhsm;
13724 + SiMustWriteLock(sb);
13726 + sbinfo = au_sbi(sb);
13727 + fhsm = &sbinfo->si_fhsm;
13728 + AuDebugOn(!fhsm);
13729 + fhsm->fhsm_bottom = bindex;
13732 +/* ---------------------------------------------------------------------- */
13734 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13736 + struct au_br_fhsm *bf;
13738 + bf = br->br_fhsm;
13739 + MtxMustLock(&bf->bf_lock);
13741 + return !bf->bf_readable
13742 + || time_after(jiffies,
13743 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13746 +/* ---------------------------------------------------------------------- */
13748 +static void au_fhsm_notify(struct super_block *sb, int val)
13750 + struct au_sbinfo *sbinfo;
13751 + struct au_fhsm *fhsm;
13753 + SiMustAnyLock(sb);
13755 + sbinfo = au_sbi(sb);
13756 + fhsm = &sbinfo->si_fhsm;
13757 + if (au_fhsm_pid(fhsm)
13758 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13759 + atomic_set(&fhsm->fhsm_readable, val);
13761 + wake_up(&fhsm->fhsm_wqh);
13765 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13766 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13769 + struct au_branch *br;
13770 + struct au_br_fhsm *bf;
13772 + br = au_sbr(sb, bindex);
13773 + AuDebugOn(au_br_rdonly(br));
13774 + bf = br->br_fhsm;
13778 + mutex_lock(&bf->bf_lock);
13780 + MtxMustLock(&bf->bf_lock);
13782 + /* sb->s_root for NFS is unreliable */
13783 + err = au_br_stfs(br, &bf->bf_stfs);
13784 + if (unlikely(err)) {
13785 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13789 + bf->bf_jiffy = jiffies;
13790 + bf->bf_readable = 1;
13792 + au_fhsm_notify(sb, /*val*/1);
13794 + *rstfs = bf->bf_stfs;
13798 + mutex_unlock(&bf->bf_lock);
13799 + au_fhsm_notify(sb, /*val*/1);
13804 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13807 + struct au_sbinfo *sbinfo;
13808 + struct au_fhsm *fhsm;
13809 + struct au_branch *br;
13810 + struct au_br_fhsm *bf;
13812 + AuDbg("b%d, force %d\n", bindex, force);
13813 + SiMustAnyLock(sb);
13815 + sbinfo = au_sbi(sb);
13816 + fhsm = &sbinfo->si_fhsm;
13817 + if (!au_ftest_si(sbinfo, FHSM)
13818 + || fhsm->fhsm_bottom == bindex)
13821 + br = au_sbr(sb, bindex);
13822 + bf = br->br_fhsm;
13824 + mutex_lock(&bf->bf_lock);
13826 + || au_fhsm_pid(fhsm)
13827 + || au_fhsm_test_jiffy(sbinfo, br))
13828 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13830 + mutex_unlock(&bf->bf_lock);
13833 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13835 + aufs_bindex_t bindex, bbot;
13836 + struct au_branch *br;
13838 + /* exclude the bottom */
13839 + bbot = au_fhsm_bottom(sb);
13840 + for (bindex = 0; bindex < bbot; bindex++) {
13841 + br = au_sbr(sb, bindex);
13842 + if (au_br_fhsm(br->br_perm))
13843 + au_fhsm_wrote(sb, bindex, force);
13847 +/* ---------------------------------------------------------------------- */
13849 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
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 = EPOLLIN /* | EPOLLRDNORM */;
13863 + AuDbg("mask 0x%x\n", mask);
13867 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13868 + struct aufs_stfs *stfs, __s16 brid)
13872 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13874 + err = __put_user(brid, &stbr->brid);
13875 + if (unlikely(err))
13881 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13882 + struct aufs_stbr __user *stbr, size_t count)
13886 + aufs_bindex_t bindex, bbot;
13887 + struct au_branch *br;
13888 + struct au_br_fhsm *bf;
13890 + /* except the bottom branch */
13893 + bbot = au_fhsm_bottom(sb);
13894 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13895 + br = au_sbr(sb, bindex);
13896 + if (!au_br_fhsm(br->br_perm))
13899 + bf = br->br_fhsm;
13900 + mutex_lock(&bf->bf_lock);
13901 + if (bf->bf_readable) {
13903 + if (count >= sizeof(*stbr))
13904 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13907 + bf->bf_readable = 0;
13908 + count -= sizeof(*stbr);
13912 + mutex_unlock(&bf->bf_lock);
13915 + err = sizeof(*stbr) * nstbr;
13920 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13925 + aufs_bindex_t nfhsm, bindex, bbot;
13926 + struct au_sbinfo *sbinfo;
13927 + struct au_fhsm *fhsm;
13928 + struct au_branch *br;
13929 + struct super_block *sb;
13932 + sbinfo = file->private_data;
13933 + fhsm = &sbinfo->si_fhsm;
13935 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13936 + if (!atomic_read(&fhsm->fhsm_readable)) {
13937 + if (vfsub_file_flags(file) & O_NONBLOCK)
13940 + err = wait_event_interruptible_locked_irq
13942 + atomic_read(&fhsm->fhsm_readable));
13944 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13945 + if (unlikely(err))
13948 + /* sb may already be dead */
13949 + au_rw_read_lock(&sbinfo->si_rwsem);
13950 + readable = atomic_read(&fhsm->fhsm_readable);
13951 + if (readable > 0) {
13952 + sb = sbinfo->si_sb;
13954 + /* exclude the bottom branch */
13956 + bbot = au_fhsm_bottom(sb);
13957 + for (bindex = 0; bindex < bbot; bindex++) {
13958 + br = au_sbr(sb, bindex);
13959 + if (au_br_fhsm(br->br_perm))
13963 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13964 + atomic_set(&fhsm->fhsm_readable, 0);
13965 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13969 + au_rw_read_unlock(&sbinfo->si_rwsem);
13977 +static int au_fhsm_release(struct inode *inode, struct file *file)
13979 + struct au_sbinfo *sbinfo;
13980 + struct au_fhsm *fhsm;
13982 + /* sb may already be dead */
13983 + sbinfo = file->private_data;
13984 + fhsm = &sbinfo->si_fhsm;
13985 + spin_lock(&fhsm->fhsm_spin);
13986 + fhsm->fhsm_pid = 0;
13987 + spin_unlock(&fhsm->fhsm_spin);
13988 + kobject_put(&sbinfo->si_kobj);
13993 +static const struct file_operations au_fhsm_fops = {
13994 + .owner = THIS_MODULE,
13995 + .llseek = noop_llseek,
13996 + .read = au_fhsm_read,
13997 + .poll = au_fhsm_poll,
13998 + .release = au_fhsm_release
14001 +int au_fhsm_fd(struct super_block *sb, int oflags)
14004 + struct au_sbinfo *sbinfo;
14005 + struct au_fhsm *fhsm;
14008 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14012 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14016 + sbinfo = au_sbi(sb);
14017 + fhsm = &sbinfo->si_fhsm;
14018 + spin_lock(&fhsm->fhsm_spin);
14019 + if (!fhsm->fhsm_pid)
14020 + fhsm->fhsm_pid = current->pid;
14023 + spin_unlock(&fhsm->fhsm_spin);
14024 + if (unlikely(err))
14027 + oflags |= O_RDONLY;
14028 + /* oflags |= FMODE_NONOTIFY; */
14029 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14031 + if (unlikely(fd < 0))
14034 + /* succeed reglardless 'fhsm' status */
14035 + kobject_get(&sbinfo->si_kobj);
14036 + si_noflush_read_lock(sb);
14037 + if (au_ftest_si(sbinfo, FHSM))
14038 + au_fhsm_wrote_all(sb, /*force*/0);
14039 + si_read_unlock(sb);
14040 + goto out; /* success */
14043 + spin_lock(&fhsm->fhsm_spin);
14044 + fhsm->fhsm_pid = 0;
14045 + spin_unlock(&fhsm->fhsm_spin);
14051 +/* ---------------------------------------------------------------------- */
14053 +int au_fhsm_br_alloc(struct au_branch *br)
14058 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14060 + au_br_fhsm_init(br->br_fhsm);
14067 +/* ---------------------------------------------------------------------- */
14069 +void au_fhsm_fin(struct super_block *sb)
14071 + au_fhsm_notify(sb, /*val*/-1);
14074 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14076 + struct au_fhsm *fhsm;
14078 + fhsm = &sbinfo->si_fhsm;
14079 + spin_lock_init(&fhsm->fhsm_spin);
14080 + init_waitqueue_head(&fhsm->fhsm_wqh);
14081 + atomic_set(&fhsm->fhsm_readable, 0);
14082 + fhsm->fhsm_expire
14083 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14084 + fhsm->fhsm_bottom = -1;
14087 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14089 + sbinfo->si_fhsm.fhsm_expire
14090 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14093 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14097 + if (!au_ftest_si(sbinfo, FHSM))
14100 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14101 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14102 + seq_printf(seq, ",fhsm_sec=%u", u);
14104 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14105 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14106 +++ linux/fs/aufs/file.c 2018-06-04 09:08:09.184746078 +0200
14109 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14111 + * This program, aufs is free software; you can redistribute it and/or modify
14112 + * it under the terms of the GNU General Public License as published by
14113 + * the Free Software Foundation; either version 2 of the License, or
14114 + * (at your option) any later version.
14116 + * This program is distributed in the hope that it will be useful,
14117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14119 + * GNU General Public License for more details.
14121 + * You should have received a copy of the GNU General Public License
14122 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14126 + * handling file/dir, and address_space operation
14129 +#ifdef CONFIG_AUFS_DEBUG
14130 +#include <linux/migrate.h>
14132 +#include <linux/pagemap.h>
14135 +/* drop flags for writing */
14136 +unsigned int au_file_roflags(unsigned int flags)
14138 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14139 + flags |= O_RDONLY | O_NOATIME;
14143 +/* common functions to regular file and dir */
14144 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14145 + struct file *file, int force_wr)
14147 + struct file *h_file;
14148 + struct dentry *h_dentry;
14149 + struct inode *h_inode;
14150 + struct super_block *sb;
14151 + struct au_branch *br;
14152 + struct path h_path;
14155 + /* a race condition can happen between open and unlink/rmdir */
14156 + h_file = ERR_PTR(-ENOENT);
14157 + h_dentry = au_h_dptr(dentry, bindex);
14158 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14160 + h_inode = d_inode(h_dentry);
14161 + spin_lock(&h_dentry->d_lock);
14162 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14163 + /* || !d_inode(dentry)->i_nlink */
14165 + spin_unlock(&h_dentry->d_lock);
14166 + if (unlikely(err))
14169 + sb = dentry->d_sb;
14170 + br = au_sbr(sb, bindex);
14171 + err = au_br_test_oflag(flags, br);
14172 + h_file = ERR_PTR(err);
14173 + if (unlikely(err))
14176 + /* drop flags for writing */
14177 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14178 + if (force_wr && !(flags & O_WRONLY))
14180 + flags = au_file_roflags(flags);
14182 + h_file = ERR_PTR(-EROFS);
14183 + flags = au_file_roflags(flags);
14184 + if (unlikely(vfsub_native_ro(h_inode)
14185 + || IS_APPEND(h_inode)))
14187 + flags &= ~O_ACCMODE;
14188 + flags |= O_WRONLY;
14191 + flags &= ~O_CREAT;
14193 + h_path.dentry = h_dentry;
14194 + h_path.mnt = au_br_mnt(br);
14195 + h_file = vfsub_dentry_open(&h_path, flags);
14196 + if (IS_ERR(h_file))
14199 + if (flags & __FMODE_EXEC) {
14200 + err = deny_write_access(h_file);
14201 + if (unlikely(err)) {
14203 + h_file = ERR_PTR(err);
14207 + fsnotify_open(h_file);
14208 + goto out; /* success */
14216 +static int au_cmoo(struct dentry *dentry)
14218 + int err, cmoo, matched;
14219 + unsigned int udba;
14220 + struct path h_path;
14221 + struct au_pin pin;
14222 + struct au_cp_generic cpg = {
14223 + .dentry = dentry,
14228 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14230 + struct inode *delegated;
14231 + struct super_block *sb;
14232 + struct au_sbinfo *sbinfo;
14233 + struct au_fhsm *fhsm;
14235 + struct au_branch *br;
14236 + struct dentry *parent;
14237 + struct au_hinode *hdir;
14239 + DiMustWriteLock(dentry);
14240 + IiMustWriteLock(d_inode(dentry));
14243 + if (IS_ROOT(dentry))
14245 + cpg.bsrc = au_dbtop(dentry);
14249 + sb = dentry->d_sb;
14250 + sbinfo = au_sbi(sb);
14251 + fhsm = &sbinfo->si_fhsm;
14252 + pid = au_fhsm_pid(fhsm);
14255 + && (current->pid == pid
14256 + || rcu_dereference(current->real_parent)->pid == pid));
14257 + rcu_read_unlock();
14261 + br = au_sbr(sb, cpg.bsrc);
14262 + cmoo = au_br_cmoo(br->br_perm);
14265 + if (!d_is_reg(dentry))
14266 + cmoo &= AuBrAttr_COO_ALL;
14270 + parent = dget_parent(dentry);
14271 + di_write_lock_parent(parent);
14272 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14274 + if (unlikely(err < 0)) {
14275 + err = 0; /* there is no upper writable branch */
14278 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14280 + /* do not respect the coo attrib for the target branch */
14281 + err = au_cpup_dirs(dentry, cpg.bdst);
14282 + if (unlikely(err))
14285 + di_downgrade_lock(parent, AuLock_IR);
14286 + udba = au_opt_udba(sb);
14287 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14288 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14289 + if (unlikely(err))
14292 + err = au_sio_cpup_simple(&cpg);
14294 + if (unlikely(err))
14296 + if (!(cmoo & AuBrWAttr_MOO))
14297 + goto out_parent; /* success */
14299 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14300 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14301 + if (unlikely(err))
14304 + h_path.mnt = au_br_mnt(br);
14305 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14306 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14307 + delegated = NULL;
14308 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14310 + /* todo: keep h_dentry or not? */
14311 + if (unlikely(err == -EWOULDBLOCK)) {
14312 + pr_warn("cannot retry for NFSv4 delegation"
14313 + " for an internal unlink\n");
14316 + if (unlikely(err)) {
14317 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14321 + goto out_parent; /* success */
14324 + di_downgrade_lock(parent, AuLock_IR);
14326 + di_read_unlock(parent, AuLock_IR);
14333 +int au_do_open(struct file *file, struct au_do_open_args *args)
14335 + int err, aopen = args->aopen;
14336 + struct dentry *dentry;
14337 + struct au_finfo *finfo;
14340 + err = au_finfo_init(file, args->fidir);
14343 + err = au_finfo_init(file, args->fidir);
14346 + if (unlikely(err))
14349 + dentry = file->f_path.dentry;
14350 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14351 + di_write_lock_child(dentry);
14352 + err = au_cmoo(dentry);
14353 + di_downgrade_lock(dentry, AuLock_IR);
14356 + err = args->open(file, vfsub_file_flags(file), NULL);
14359 + err = args->open(file, vfsub_file_flags(file), NULL);
14363 + di_read_unlock(dentry, AuLock_IR);
14365 + finfo = au_fi(file);
14367 + finfo->fi_file = file;
14368 + au_hbl_add(&finfo->fi_hlist,
14369 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14372 + fi_write_unlock(file);
14375 + fi_write_unlock(file);
14378 + if (unlikely(err)) {
14379 + finfo->fi_hdir = NULL;
14380 + au_finfo_fin(file);
14388 +int au_reopen_nondir(struct file *file)
14391 + aufs_bindex_t btop;
14392 + struct dentry *dentry;
14393 + struct file *h_file, *h_file_tmp;
14395 + dentry = file->f_path.dentry;
14396 + btop = au_dbtop(dentry);
14397 + h_file_tmp = NULL;
14398 + if (au_fbtop(file) == btop) {
14399 + h_file = au_hf_top(file);
14400 + if (file->f_mode == h_file->f_mode)
14401 + return 0; /* success */
14402 + h_file_tmp = h_file;
14403 + get_file(h_file_tmp);
14404 + au_set_h_fptr(file, btop, NULL);
14406 + AuDebugOn(au_fi(file)->fi_hdir);
14409 + * file exists on both of rw and ro
14410 + * open --> dbtop and fbtop are both 0
14411 + * prepend a branch as rw, "rw" become ro
14413 + * delete the top branch, "rw" becomes rw again
14414 + * --> dbtop is 1, fbtop is still 0
14415 + * write --> fbtop is 0 but dbtop is 1
14417 + /* AuDebugOn(au_fbtop(file) < btop); */
14419 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14420 + file, /*force_wr*/0);
14421 + err = PTR_ERR(h_file);
14422 + if (IS_ERR(h_file)) {
14423 + if (h_file_tmp) {
14424 + au_sbr_get(dentry->d_sb, btop);
14425 + au_set_h_fptr(file, btop, h_file_tmp);
14426 + h_file_tmp = NULL;
14428 + goto out; /* todo: close all? */
14432 + au_set_fbtop(file, btop);
14433 + au_set_h_fptr(file, btop, h_file);
14434 + au_update_figen(file);
14435 + /* todo: necessary? */
14436 + /* file->f_ra = h_file->f_ra; */
14440 + fput(h_file_tmp);
14444 +/* ---------------------------------------------------------------------- */
14446 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14447 + struct dentry *hi_wh)
14450 + aufs_bindex_t btop;
14451 + struct au_dinfo *dinfo;
14452 + struct dentry *h_dentry;
14453 + struct au_hdentry *hdp;
14455 + dinfo = au_di(file->f_path.dentry);
14456 + AuRwMustWriteLock(&dinfo->di_rwsem);
14458 + btop = dinfo->di_btop;
14459 + dinfo->di_btop = btgt;
14460 + hdp = au_hdentry(dinfo, btgt);
14461 + h_dentry = hdp->hd_dentry;
14462 + hdp->hd_dentry = hi_wh;
14463 + err = au_reopen_nondir(file);
14464 + hdp->hd_dentry = h_dentry;
14465 + dinfo->di_btop = btop;
14470 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14471 + aufs_bindex_t bcpup, struct au_pin *pin)
14474 + struct inode *inode, *h_inode;
14475 + struct dentry *h_dentry, *hi_wh;
14476 + struct au_cp_generic cpg = {
14477 + .dentry = file->f_path.dentry,
14484 + au_update_dbtop(cpg.dentry);
14485 + inode = d_inode(cpg.dentry);
14487 + if (au_dbtop(cpg.dentry) <= bcpup
14488 + && au_dbbot(cpg.dentry) >= bcpup) {
14489 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14490 + if (h_dentry && d_is_positive(h_dentry))
14491 + h_inode = d_inode(h_dentry);
14493 + hi_wh = au_hi_wh(inode, bcpup);
14494 + if (!hi_wh && !h_inode)
14495 + err = au_sio_cpup_wh(&cpg, file);
14497 + /* already copied-up after unlink */
14498 + err = au_reopen_wh(file, bcpup, hi_wh);
14501 + && (inode->i_nlink > 1
14502 + || (inode->i_state & I_LINKABLE))
14503 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14504 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14510 + * prepare the @file for writing.
14512 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14515 + aufs_bindex_t dbtop;
14516 + struct dentry *parent;
14517 + struct inode *inode;
14518 + struct super_block *sb;
14519 + struct file *h_file;
14520 + struct au_cp_generic cpg = {
14521 + .dentry = file->f_path.dentry,
14526 + .flags = AuCpup_DTIME
14529 + sb = cpg.dentry->d_sb;
14530 + inode = d_inode(cpg.dentry);
14531 + cpg.bsrc = au_fbtop(file);
14532 + err = au_test_ro(sb, cpg.bsrc, inode);
14533 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14534 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14539 + /* need to cpup or reopen */
14540 + parent = dget_parent(cpg.dentry);
14541 + di_write_lock_parent(parent);
14542 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14544 + if (unlikely(err < 0))
14548 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14549 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14550 + if (unlikely(err))
14554 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14555 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14556 + if (unlikely(err))
14559 + dbtop = au_dbtop(cpg.dentry);
14560 + if (dbtop <= cpg.bdst)
14561 + cpg.bsrc = cpg.bdst;
14563 + if (dbtop <= cpg.bdst /* just reopen */
14564 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14566 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14567 + if (IS_ERR(h_file))
14568 + err = PTR_ERR(h_file);
14570 + di_downgrade_lock(parent, AuLock_IR);
14571 + if (dbtop > cpg.bdst)
14572 + err = au_sio_cpup_simple(&cpg);
14574 + err = au_reopen_nondir(file);
14575 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14577 + } else { /* copyup as wh and reopen */
14579 + * since writable hfsplus branch is not supported,
14580 + * h_open_pre/post() are unnecessary.
14582 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14583 + di_downgrade_lock(parent, AuLock_IR);
14587 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14588 + goto out_dput; /* success */
14594 + di_downgrade_lock(parent, AuLock_IR);
14596 + di_read_unlock(parent, AuLock_IR);
14603 +/* ---------------------------------------------------------------------- */
14605 +int au_do_flush(struct file *file, fl_owner_t id,
14606 + int (*flush)(struct file *file, fl_owner_t id))
14609 + struct super_block *sb;
14610 + struct inode *inode;
14612 + inode = file_inode(file);
14613 + sb = inode->i_sb;
14614 + si_noflush_read_lock(sb);
14615 + fi_read_lock(file);
14616 + ii_read_lock_child(inode);
14618 + err = flush(file, id);
14619 + au_cpup_attr_timesizes(inode);
14621 + ii_read_unlock(inode);
14622 + fi_read_unlock(file);
14623 + si_read_unlock(sb);
14627 +/* ---------------------------------------------------------------------- */
14629 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14632 + struct au_pin pin;
14633 + struct au_finfo *finfo;
14634 + struct dentry *parent, *hi_wh;
14635 + struct inode *inode;
14636 + struct super_block *sb;
14637 + struct au_cp_generic cpg = {
14638 + .dentry = file->f_path.dentry,
14643 + .flags = AuCpup_DTIME
14646 + FiMustWriteLock(file);
14649 + finfo = au_fi(file);
14650 + sb = cpg.dentry->d_sb;
14651 + inode = d_inode(cpg.dentry);
14652 + cpg.bdst = au_ibtop(inode);
14653 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14656 + parent = dget_parent(cpg.dentry);
14657 + if (au_test_ro(sb, cpg.bdst, inode)) {
14658 + di_read_lock_parent(parent, !AuLock_IR);
14659 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14661 + di_read_unlock(parent, !AuLock_IR);
14662 + if (unlikely(err < 0))
14667 + di_read_lock_parent(parent, AuLock_IR);
14668 + hi_wh = au_hi_wh(inode, cpg.bdst);
14669 + if (!S_ISDIR(inode->i_mode)
14670 + && au_opt_test(au_mntflags(sb), PLINK)
14671 + && au_plink_test(inode)
14672 + && !d_unhashed(cpg.dentry)
14673 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14674 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14675 + if (unlikely(err))
14678 + /* always superio. */
14679 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14680 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14682 + err = au_sio_cpup_simple(&cpg);
14685 + } else if (hi_wh) {
14686 + /* already copied-up after unlink */
14687 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14688 + *need_reopen = 0;
14692 + di_read_unlock(parent, AuLock_IR);
14699 +static void au_do_refresh_dir(struct file *file)
14701 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14702 + struct au_hfile *p, tmp, *q;
14703 + struct au_finfo *finfo;
14704 + struct super_block *sb;
14705 + struct au_fidir *fidir;
14707 + FiMustWriteLock(file);
14709 + sb = file->f_path.dentry->d_sb;
14710 + finfo = au_fi(file);
14711 + fidir = finfo->fi_hdir;
14712 + AuDebugOn(!fidir);
14713 + p = fidir->fd_hfile + finfo->fi_btop;
14714 + brid = p->hf_br->br_id;
14715 + bbot = fidir->fd_bbot;
14716 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14720 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14721 + if (new_bindex == bindex)
14723 + if (new_bindex < 0) {
14724 + au_set_h_fptr(file, bindex, NULL);
14728 + /* swap two lower inode, and loop again */
14729 + q = fidir->fd_hfile + new_bindex;
14733 + if (tmp.hf_file) {
14739 + p = fidir->fd_hfile;
14740 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14741 + bbot = au_sbbot(sb);
14742 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14743 + finfo->fi_btop++, p++)
14744 + if (p->hf_file) {
14745 + if (file_inode(p->hf_file))
14747 + au_hfput(p, /*execed*/0);
14750 + bbot = au_br_index(sb, brid);
14751 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14752 + finfo->fi_btop++, p++)
14754 + au_hfput(p, /*execed*/0);
14755 + bbot = au_sbbot(sb);
14758 + p = fidir->fd_hfile + bbot;
14759 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14760 + fidir->fd_bbot--, p--)
14761 + if (p->hf_file) {
14762 + if (file_inode(p->hf_file))
14764 + au_hfput(p, /*execed*/0);
14766 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14770 + * after branch manipulating, refresh the file.
14772 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14774 + int err, need_reopen, nbr;
14775 + aufs_bindex_t bbot, bindex;
14776 + struct dentry *dentry;
14777 + struct super_block *sb;
14778 + struct au_finfo *finfo;
14779 + struct au_hfile *hfile;
14781 + dentry = file->f_path.dentry;
14782 + sb = dentry->d_sb;
14783 + nbr = au_sbbot(sb) + 1;
14784 + finfo = au_fi(file);
14785 + if (!finfo->fi_hdir) {
14786 + hfile = &finfo->fi_htop;
14787 + AuDebugOn(!hfile->hf_file);
14788 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14789 + AuDebugOn(bindex < 0);
14790 + if (bindex != finfo->fi_btop)
14791 + au_set_fbtop(file, bindex);
14793 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14794 + if (unlikely(err))
14796 + au_do_refresh_dir(file);
14801 + if (!au_test_mmapped(file))
14802 + err = au_file_refresh_by_inode(file, &need_reopen);
14803 + if (finfo->fi_hdir)
14804 + /* harmless if err */
14805 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14806 + if (!err && need_reopen && !d_unlinked(dentry))
14807 + err = reopen(file);
14809 + au_update_figen(file);
14810 + goto out; /* success */
14813 + /* error, close all lower files */
14814 + if (finfo->fi_hdir) {
14815 + bbot = au_fbbot_dir(file);
14816 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14817 + au_set_h_fptr(file, bindex, NULL);
14824 +/* common function to regular file and dir */
14825 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14826 + int wlock, unsigned int fi_lsc)
14829 + unsigned int sigen, figen;
14830 + aufs_bindex_t btop;
14831 + unsigned char pseudo_link;
14832 + struct dentry *dentry;
14833 + struct inode *inode;
14836 + dentry = file->f_path.dentry;
14837 + inode = d_inode(dentry);
14838 + sigen = au_sigen(dentry->d_sb);
14839 + fi_write_lock_nested(file, fi_lsc);
14840 + figen = au_figen(file);
14842 + di_write_lock_child(dentry);
14844 + di_write_lock_child2(dentry);
14845 + btop = au_dbtop(dentry);
14846 + pseudo_link = (btop != au_ibtop(inode));
14847 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14849 + di_downgrade_lock(dentry, AuLock_IR);
14850 + fi_downgrade_lock(file);
14852 + goto out; /* success */
14855 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14856 + if (au_digen_test(dentry, sigen)) {
14857 + err = au_reval_dpath(dentry, sigen);
14858 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14862 + err = refresh_file(file, reopen);
14865 + di_downgrade_lock(dentry, AuLock_IR);
14866 + fi_downgrade_lock(file);
14869 + di_write_unlock(dentry);
14870 + fi_write_unlock(file);
14877 +/* ---------------------------------------------------------------------- */
14879 +/* cf. aufs_nopage() */
14880 +/* for madvise(2) */
14881 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14883 + unlock_page(page);
14887 +/* it will never be called, but necessary to support O_DIRECT */
14888 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14889 +{ BUG(); return 0; }
14891 +/* they will never be called. */
14892 +#ifdef CONFIG_AUFS_DEBUG
14893 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14894 + loff_t pos, unsigned len, unsigned flags,
14895 + struct page **pagep, void **fsdata)
14896 +{ AuUnsupport(); return 0; }
14897 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14898 + loff_t pos, unsigned len, unsigned copied,
14899 + struct page *page, void *fsdata)
14900 +{ AuUnsupport(); return 0; }
14901 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14902 +{ AuUnsupport(); return 0; }
14904 +static int aufs_set_page_dirty(struct page *page)
14905 +{ AuUnsupport(); return 0; }
14906 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14907 + unsigned int length)
14908 +{ AuUnsupport(); }
14909 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14910 +{ AuUnsupport(); return 0; }
14911 +#if 0 /* called by memory compaction regardless file */
14912 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14913 + struct page *page, enum migrate_mode mode)
14914 +{ AuUnsupport(); return 0; }
14916 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14917 +{ AuUnsupport(); return true; }
14918 +static void aufs_putback_page(struct page *page)
14919 +{ AuUnsupport(); }
14920 +static int aufs_launder_page(struct page *page)
14921 +{ AuUnsupport(); return 0; }
14922 +static int aufs_is_partially_uptodate(struct page *page,
14923 + unsigned long from,
14924 + unsigned long count)
14925 +{ AuUnsupport(); return 0; }
14926 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14928 +{ AuUnsupport(); }
14929 +static int aufs_error_remove_page(struct address_space *mapping,
14930 + struct page *page)
14931 +{ AuUnsupport(); return 0; }
14932 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14934 +{ AuUnsupport(); return 0; }
14935 +static void aufs_swap_deactivate(struct file *file)
14936 +{ AuUnsupport(); }
14937 +#endif /* CONFIG_AUFS_DEBUG */
14939 +const struct address_space_operations aufs_aop = {
14940 + .readpage = aufs_readpage,
14941 + .direct_IO = aufs_direct_IO,
14942 +#ifdef CONFIG_AUFS_DEBUG
14943 + .writepage = aufs_writepage,
14944 + /* no writepages, because of writepage */
14945 + .set_page_dirty = aufs_set_page_dirty,
14946 + /* no readpages, because of readpage */
14947 + .write_begin = aufs_write_begin,
14948 + .write_end = aufs_write_end,
14949 + /* no bmap, no block device */
14950 + .invalidatepage = aufs_invalidatepage,
14951 + .releasepage = aufs_releasepage,
14952 + /* is fallback_migrate_page ok? */
14953 + /* .migratepage = aufs_migratepage, */
14954 + .isolate_page = aufs_isolate_page,
14955 + .putback_page = aufs_putback_page,
14956 + .launder_page = aufs_launder_page,
14957 + .is_partially_uptodate = aufs_is_partially_uptodate,
14958 + .is_dirty_writeback = aufs_is_dirty_writeback,
14959 + .error_remove_page = aufs_error_remove_page,
14960 + .swap_activate = aufs_swap_activate,
14961 + .swap_deactivate = aufs_swap_deactivate
14962 +#endif /* CONFIG_AUFS_DEBUG */
14964 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14965 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14966 +++ linux/fs/aufs/file.h 2018-06-04 09:08:09.184746078 +0200
14969 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14971 + * This program, aufs is free software; you can redistribute it and/or modify
14972 + * it under the terms of the GNU General Public License as published by
14973 + * the Free Software Foundation; either version 2 of the License, or
14974 + * (at your option) any later version.
14976 + * This program is distributed in the hope that it will be useful,
14977 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14978 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14979 + * GNU General Public License for more details.
14981 + * You should have received a copy of the GNU General Public License
14982 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14986 + * file operations
14989 +#ifndef __AUFS_FILE_H__
14990 +#define __AUFS_FILE_H__
14994 +#include <linux/file.h>
14995 +#include <linux/fs.h>
14996 +#include <linux/mm_types.h>
14997 +#include <linux/poll.h>
14998 +#include "rwsem.h"
15002 + struct file *hf_file;
15003 + struct au_branch *hf_br;
15008 + aufs_bindex_t fd_bbot;
15009 + aufs_bindex_t fd_nent;
15010 + struct au_vdir *fd_vdir_cache;
15011 + struct au_hfile fd_hfile[];
15014 +static inline int au_fidir_sz(int nent)
15016 + AuDebugOn(nent < 0);
15017 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15021 + atomic_t fi_generation;
15023 + struct au_rwsem fi_rwsem;
15024 + aufs_bindex_t fi_btop;
15026 + /* do not union them */
15027 + struct { /* for non-dir */
15028 + struct au_hfile fi_htop;
15029 + atomic_t fi_mmapped;
15031 + struct au_fidir *fi_hdir; /* for dir only */
15033 + struct hlist_bl_node fi_hlist;
15034 + struct file *fi_file; /* very ugly */
15035 +} ____cacheline_aligned_in_smp;
15037 +/* ---------------------------------------------------------------------- */
15040 +extern const struct address_space_operations aufs_aop;
15041 +unsigned int au_file_roflags(unsigned int flags);
15042 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15043 + struct file *file, int force_wr);
15044 +struct au_do_open_args {
15046 + int (*open)(struct file *file, int flags,
15047 + struct file *h_file);
15048 + struct au_fidir *fidir;
15049 + struct file *h_file;
15051 +int au_do_open(struct file *file, struct au_do_open_args *args);
15052 +int au_reopen_nondir(struct file *file);
15054 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15055 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15056 + int wlock, unsigned int fi_lsc);
15057 +int au_do_flush(struct file *file, fl_owner_t id,
15058 + int (*flush)(struct file *file, fl_owner_t id));
15061 +#ifdef CONFIG_AUFS_POLL
15062 +__poll_t aufs_poll(struct file *file, poll_table *wait);
15065 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15067 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15069 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15070 + struct file *h_file);
15072 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15073 + aufs_bindex_t bindex, int force_wr)
15074 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15075 + struct file *h_file);
15079 +extern const struct file_operations aufs_file_fop;
15080 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15081 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15082 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15085 +void au_hfput(struct au_hfile *hf, int execed);
15086 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15087 + struct file *h_file);
15089 +void au_update_figen(struct file *file);
15090 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15091 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15093 +void au_fi_init_once(void *_fi);
15094 +void au_finfo_fin(struct file *file);
15095 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15098 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15099 +#ifdef CONFIG_COMPAT
15100 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15101 + unsigned long arg);
15102 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15103 + unsigned long arg);
15106 +/* ---------------------------------------------------------------------- */
15108 +static inline struct au_finfo *au_fi(struct file *file)
15110 + return file->private_data;
15113 +/* ---------------------------------------------------------------------- */
15115 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15116 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15117 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15118 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15120 +#define fi_read_trylock_nested(f) \
15121 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15122 +#define fi_write_trylock_nested(f) \
15123 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15126 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15127 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15128 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15130 +/* lock subclass for finfo */
15136 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15138 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15141 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15143 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15147 + * fi_read_lock_1, fi_write_lock_1,
15148 + * fi_read_lock_2, fi_write_lock_2
15150 +#define AuReadLockFunc(name) \
15151 +static inline void fi_read_lock_##name(struct file *f) \
15152 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15154 +#define AuWriteLockFunc(name) \
15155 +static inline void fi_write_lock_##name(struct file *f) \
15156 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15158 +#define AuRWLockFuncs(name) \
15159 + AuReadLockFunc(name) \
15160 + AuWriteLockFunc(name)
15165 +#undef AuReadLockFunc
15166 +#undef AuWriteLockFunc
15167 +#undef AuRWLockFuncs
15169 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15170 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15171 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15173 +/* ---------------------------------------------------------------------- */
15175 +/* todo: hard/soft set? */
15176 +static inline aufs_bindex_t au_fbtop(struct file *file)
15178 + FiMustAnyLock(file);
15179 + return au_fi(file)->fi_btop;
15182 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15184 + FiMustAnyLock(file);
15185 + AuDebugOn(!au_fi(file)->fi_hdir);
15186 + return au_fi(file)->fi_hdir->fd_bbot;
15189 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15191 + FiMustAnyLock(file);
15192 + AuDebugOn(!au_fi(file)->fi_hdir);
15193 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15196 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15198 + FiMustWriteLock(file);
15199 + au_fi(file)->fi_btop = bindex;
15202 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15204 + FiMustWriteLock(file);
15205 + AuDebugOn(!au_fi(file)->fi_hdir);
15206 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15209 +static inline void au_set_fvdir_cache(struct file *file,
15210 + struct au_vdir *vdir_cache)
15212 + FiMustWriteLock(file);
15213 + AuDebugOn(!au_fi(file)->fi_hdir);
15214 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15217 +static inline struct file *au_hf_top(struct file *file)
15219 + FiMustAnyLock(file);
15220 + AuDebugOn(au_fi(file)->fi_hdir);
15221 + return au_fi(file)->fi_htop.hf_file;
15224 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15226 + FiMustAnyLock(file);
15227 + AuDebugOn(!au_fi(file)->fi_hdir);
15228 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15231 +/* todo: memory barrier? */
15232 +static inline unsigned int au_figen(struct file *f)
15234 + return atomic_read(&au_fi(f)->fi_generation);
15237 +static inline void au_set_mmapped(struct file *f)
15239 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15241 + pr_warn("fi_mmapped wrapped around\n");
15242 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15246 +static inline void au_unset_mmapped(struct file *f)
15248 + atomic_dec(&au_fi(f)->fi_mmapped);
15251 +static inline int au_test_mmapped(struct file *f)
15253 + return atomic_read(&au_fi(f)->fi_mmapped);
15256 +/* customize vma->vm_file */
15258 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15259 + struct file *file)
15263 + f = vma->vm_file;
15265 + vma->vm_file = file;
15270 +#define AuDbgVmRegion(file, vma) do {} while (0)
15272 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15273 + struct file *file)
15275 + au_do_vm_file_reset(vma, file);
15278 +#define AuDbgVmRegion(file, vma) \
15279 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15281 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15282 + struct file *file)
15286 + au_do_vm_file_reset(vma, file);
15287 + f = vma->vm_region->vm_file;
15289 + vma->vm_region->vm_file = file;
15292 +#endif /* CONFIG_MMU */
15294 +/* handle vma->vm_prfile */
15295 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15296 + struct file *file)
15299 + vma->vm_prfile = file;
15300 +#ifndef CONFIG_MMU
15302 + vma->vm_region->vm_prfile = file;
15306 +#endif /* __KERNEL__ */
15307 +#endif /* __AUFS_FILE_H__ */
15308 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15309 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15310 +++ linux/fs/aufs/finfo.c 2018-04-15 08:49:13.397817296 +0200
15313 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15315 + * This program, aufs is free software; you can redistribute it and/or modify
15316 + * it under the terms of the GNU General Public License as published by
15317 + * the Free Software Foundation; either version 2 of the License, or
15318 + * (at your option) any later version.
15320 + * This program is distributed in the hope that it will be useful,
15321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15323 + * GNU General Public License for more details.
15325 + * You should have received a copy of the GNU General Public License
15326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15330 + * file private data
15335 +void au_hfput(struct au_hfile *hf, int execed)
15338 + allow_write_access(hf->hf_file);
15339 + fput(hf->hf_file);
15340 + hf->hf_file = NULL;
15341 + au_br_put(hf->hf_br);
15342 + hf->hf_br = NULL;
15345 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15347 + struct au_finfo *finfo = au_fi(file);
15348 + struct au_hfile *hf;
15349 + struct au_fidir *fidir;
15351 + fidir = finfo->fi_hdir;
15353 + AuDebugOn(finfo->fi_btop != bindex);
15354 + hf = &finfo->fi_htop;
15356 + hf = fidir->fd_hfile + bindex;
15358 + if (hf && hf->hf_file)
15359 + au_hfput(hf, vfsub_file_execed(file));
15361 + FiMustWriteLock(file);
15362 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15363 + hf->hf_file = val;
15364 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15368 +void au_update_figen(struct file *file)
15370 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15371 + /* smp_mb(); */ /* atomic_set */
15374 +/* ---------------------------------------------------------------------- */
15376 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15378 + struct au_fidir *fidir;
15381 + nbr = au_sbbot(sb) + 1;
15383 + nbr = 2; /* initial allocate for 2 branches */
15384 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15386 + fidir->fd_bbot = -1;
15387 + fidir->fd_nent = nbr;
15393 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15396 + struct au_fidir *fidir, *p;
15398 + AuRwMustWriteLock(&finfo->fi_rwsem);
15399 + fidir = finfo->fi_hdir;
15400 + AuDebugOn(!fidir);
15403 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15404 + GFP_NOFS, may_shrink);
15406 + p->fd_nent = nbr;
15407 + finfo->fi_hdir = p;
15414 +/* ---------------------------------------------------------------------- */
15416 +void au_finfo_fin(struct file *file)
15418 + struct au_finfo *finfo;
15420 + au_nfiles_dec(file->f_path.dentry->d_sb);
15422 + finfo = au_fi(file);
15423 + AuDebugOn(finfo->fi_hdir);
15424 + AuRwDestroy(&finfo->fi_rwsem);
15425 + au_cache_free_finfo(finfo);
15428 +void au_fi_init_once(void *_finfo)
15430 + struct au_finfo *finfo = _finfo;
15432 + au_rw_init(&finfo->fi_rwsem);
15435 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15438 + struct au_finfo *finfo;
15439 + struct dentry *dentry;
15442 + dentry = file->f_path.dentry;
15443 + finfo = au_cache_alloc_finfo();
15444 + if (unlikely(!finfo))
15448 + au_nfiles_inc(dentry->d_sb);
15449 + au_rw_write_lock(&finfo->fi_rwsem);
15450 + finfo->fi_btop = -1;
15451 + finfo->fi_hdir = fidir;
15452 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15453 + /* smp_mb(); */ /* atomic_set */
15455 + file->private_data = finfo;
15460 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15461 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15462 +++ linux/fs/aufs/f_op.c 2018-06-04 09:08:09.184746078 +0200
15465 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15467 + * This program, aufs is free software; you can redistribute it and/or modify
15468 + * it under the terms of the GNU General Public License as published by
15469 + * the Free Software Foundation; either version 2 of the License, or
15470 + * (at your option) any later version.
15472 + * This program is distributed in the hope that it will be useful,
15473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15475 + * GNU General Public License for more details.
15477 + * You should have received a copy of the GNU General Public License
15478 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15482 + * file and vm operations
15485 +#include <linux/aio.h>
15486 +#include <linux/fs_stack.h>
15487 +#include <linux/mman.h>
15488 +#include <linux/security.h>
15491 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15494 + aufs_bindex_t bindex;
15495 + struct dentry *dentry, *h_dentry;
15496 + struct au_finfo *finfo;
15497 + struct inode *h_inode;
15499 + FiMustWriteLock(file);
15502 + dentry = file->f_path.dentry;
15503 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15504 + finfo = au_fi(file);
15505 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15506 + atomic_set(&finfo->fi_mmapped, 0);
15507 + bindex = au_dbtop(dentry);
15509 + h_dentry = au_h_dptr(dentry, bindex);
15510 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15511 + if (unlikely(err))
15513 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15515 + h_dentry = h_file->f_path.dentry;
15516 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15517 + if (unlikely(err))
15519 + get_file(h_file);
15521 + if (IS_ERR(h_file))
15522 + err = PTR_ERR(h_file);
15524 + if ((flags & __O_TMPFILE)
15525 + && !(flags & O_EXCL)) {
15526 + h_inode = file_inode(h_file);
15527 + spin_lock(&h_inode->i_lock);
15528 + h_inode->i_state |= I_LINKABLE;
15529 + spin_unlock(&h_inode->i_lock);
15531 + au_set_fbtop(file, bindex);
15532 + au_set_h_fptr(file, bindex, h_file);
15533 + au_update_figen(file);
15534 + /* todo: necessary? */
15535 + /* file->f_ra = h_file->f_ra; */
15542 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15543 + struct file *file)
15546 + struct super_block *sb;
15547 + struct au_do_open_args args = {
15548 + .open = au_do_open_nondir
15551 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15552 + file, vfsub_file_flags(file), file->f_mode);
15554 + sb = file->f_path.dentry->d_sb;
15555 + si_read_lock(sb, AuLock_FLUSH);
15556 + err = au_do_open(file, &args);
15557 + si_read_unlock(sb);
15561 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15563 + struct au_finfo *finfo;
15564 + aufs_bindex_t bindex;
15566 + finfo = au_fi(file);
15567 + au_hbl_del(&finfo->fi_hlist,
15568 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15569 + bindex = finfo->fi_btop;
15571 + au_set_h_fptr(file, bindex, NULL);
15573 + au_finfo_fin(file);
15577 +/* ---------------------------------------------------------------------- */
15579 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15582 + struct file *h_file;
15585 + h_file = au_hf_top(file);
15587 + err = vfsub_flush(h_file, id);
15591 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15593 + return au_do_flush(file, id, au_do_flush_nondir);
15596 +/* ---------------------------------------------------------------------- */
15598 + * read and write functions acquire [fdi]_rwsem once, but release before
15599 + * mmap_sem. This is because to stop a race condition between mmap(2).
15600 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
15601 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15602 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15605 +/* Callers should call au_read_post() or fput() in the end */
15606 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15608 + struct file *h_file;
15611 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15613 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15614 + h_file = au_hf_top(file);
15615 + get_file(h_file);
15617 + fi_read_unlock(file);
15619 + h_file = ERR_PTR(err);
15624 +static void au_read_post(struct inode *inode, struct file *h_file)
15626 + /* update without lock, I don't think it a problem */
15627 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15631 +struct au_write_pre {
15633 + unsigned int lsc;
15637 + aufs_bindex_t btop;
15641 + * return with iinfo is write-locked
15642 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15645 +static struct file *au_write_pre(struct file *file, int do_ready,
15646 + struct au_write_pre *wpre)
15648 + struct file *h_file;
15649 + struct dentry *dentry;
15651 + unsigned int lsc;
15652 + struct au_pin pin;
15657 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15658 + h_file = ERR_PTR(err);
15659 + if (unlikely(err))
15662 + dentry = file->f_path.dentry;
15664 + err = au_ready_to_write(file, -1, &pin);
15665 + if (unlikely(err)) {
15666 + h_file = ERR_PTR(err);
15667 + di_write_unlock(dentry);
15672 + di_downgrade_lock(dentry, /*flags*/0);
15674 + wpre->btop = au_fbtop(file);
15675 + h_file = au_hf_top(file);
15676 + get_file(h_file);
15678 + wpre->blks = file_inode(h_file)->i_blocks;
15681 + di_read_unlock(dentry, /*flags*/0);
15684 + fi_write_unlock(file);
15689 +static void au_write_post(struct inode *inode, struct file *h_file,
15690 + struct au_write_pre *wpre, ssize_t written)
15692 + struct inode *h_inode;
15694 + au_cpup_attr_timesizes(inode);
15695 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15696 + h_inode = file_inode(h_file);
15697 + inode->i_mode = h_inode->i_mode;
15698 + ii_write_unlock(inode);
15699 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15701 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15702 + /*force*/h_inode->i_blocks > wpre->blks);
15706 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15710 + struct inode *inode;
15711 + struct file *h_file;
15712 + struct super_block *sb;
15714 + inode = file_inode(file);
15715 + sb = inode->i_sb;
15716 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15718 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15719 + err = PTR_ERR(h_file);
15720 + if (IS_ERR(h_file))
15723 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15724 + err = vfsub_read_u(h_file, buf, count, ppos);
15725 + /* todo: necessary? */
15726 + /* file->f_ra = h_file->f_ra; */
15727 + au_read_post(inode, h_file);
15730 + si_read_unlock(sb);
15735 + * todo: very ugly
15736 + * it locks both of i_mutex and si_rwsem for read in safe.
15737 + * if the plink maintenance mode continues forever (that is the problem),
15738 + * may loop forever.
15740 +static void au_mtx_and_read_lock(struct inode *inode)
15743 + struct super_block *sb = inode->i_sb;
15746 + inode_lock(inode);
15747 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15750 + inode_unlock(inode);
15751 + si_read_lock(sb, AuLock_NOPLMW);
15752 + si_read_unlock(sb);
15756 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15757 + size_t count, loff_t *ppos)
15760 + struct au_write_pre wpre;
15761 + struct inode *inode;
15762 + struct file *h_file;
15763 + char __user *buf = (char __user *)ubuf;
15765 + inode = file_inode(file);
15766 + au_mtx_and_read_lock(inode);
15769 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15770 + err = PTR_ERR(h_file);
15771 + if (IS_ERR(h_file))
15774 + err = vfsub_write_u(h_file, buf, count, ppos);
15775 + au_write_post(inode, h_file, &wpre, err);
15778 + si_read_unlock(inode->i_sb);
15779 + inode_unlock(inode);
15783 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15784 + struct iov_iter *iov_iter)
15787 + struct file *file;
15788 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15790 + err = security_file_permission(h_file, rw);
15791 + if (unlikely(err))
15796 + if (rw == MAY_READ)
15797 + iter = h_file->f_op->read_iter;
15798 + else if (rw == MAY_WRITE)
15799 + iter = h_file->f_op->write_iter;
15801 + file = kio->ki_filp;
15802 + kio->ki_filp = h_file;
15805 + err = iter(kio, iov_iter);
15808 + /* currently there is no such fs */
15810 + kio->ki_filp = file;
15816 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15819 + struct file *file, *h_file;
15820 + struct inode *inode;
15821 + struct super_block *sb;
15823 + file = kio->ki_filp;
15824 + inode = file_inode(file);
15825 + sb = inode->i_sb;
15826 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15828 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15829 + err = PTR_ERR(h_file);
15830 + if (IS_ERR(h_file))
15833 + if (au_test_loopback_kthread()) {
15834 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15835 + if (file->f_mapping != h_file->f_mapping) {
15836 + file->f_mapping = h_file->f_mapping;
15837 + smp_mb(); /* unnecessary? */
15840 + fi_read_unlock(file);
15842 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15843 + /* todo: necessary? */
15844 + /* file->f_ra = h_file->f_ra; */
15845 + au_read_post(inode, h_file);
15848 + si_read_unlock(sb);
15852 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15855 + struct au_write_pre wpre;
15856 + struct inode *inode;
15857 + struct file *file, *h_file;
15859 + file = kio->ki_filp;
15860 + inode = file_inode(file);
15861 + au_mtx_and_read_lock(inode);
15864 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15865 + err = PTR_ERR(h_file);
15866 + if (IS_ERR(h_file))
15869 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15870 + au_write_post(inode, h_file, &wpre, err);
15873 + si_read_unlock(inode->i_sb);
15874 + inode_unlock(inode);
15878 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15879 + struct pipe_inode_info *pipe, size_t len,
15880 + unsigned int flags)
15883 + struct file *h_file;
15884 + struct inode *inode;
15885 + struct super_block *sb;
15887 + inode = file_inode(file);
15888 + sb = inode->i_sb;
15889 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15891 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15892 + err = PTR_ERR(h_file);
15893 + if (IS_ERR(h_file))
15896 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15897 + /* todo: necessasry? */
15898 + /* file->f_ra = h_file->f_ra; */
15899 + au_read_post(inode, h_file);
15902 + si_read_unlock(sb);
15907 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15908 + size_t len, unsigned int flags)
15911 + struct au_write_pre wpre;
15912 + struct inode *inode;
15913 + struct file *h_file;
15915 + inode = file_inode(file);
15916 + au_mtx_and_read_lock(inode);
15919 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15920 + err = PTR_ERR(h_file);
15921 + if (IS_ERR(h_file))
15924 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15925 + au_write_post(inode, h_file, &wpre, err);
15928 + si_read_unlock(inode->i_sb);
15929 + inode_unlock(inode);
15933 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15937 + struct au_write_pre wpre;
15938 + struct inode *inode;
15939 + struct file *h_file;
15941 + inode = file_inode(file);
15942 + au_mtx_and_read_lock(inode);
15945 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15946 + err = PTR_ERR(h_file);
15947 + if (IS_ERR(h_file))
15951 + err = vfs_fallocate(h_file, mode, offset, len);
15953 + au_write_post(inode, h_file, &wpre, /*written*/1);
15956 + si_read_unlock(inode->i_sb);
15957 + inode_unlock(inode);
15961 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15962 + struct file *dst, loff_t dst_pos,
15963 + size_t len, unsigned int flags)
15966 + struct au_write_pre wpre;
15967 + enum { SRC, DST };
15969 + struct inode *inode;
15970 + struct file *h_file;
15971 + struct super_block *h_sb;
15973 +#define a_src a[SRC]
15974 +#define a_dst a[DST]
15977 + a_src.inode = file_inode(src);
15978 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15980 + a_dst.inode = file_inode(dst);
15981 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15984 + au_mtx_and_read_lock(a_dst.inode);
15986 + * in order to match the order in di_write_lock2_{child,parent}(),
15987 + * use f_path.dentry for this comparision.
15989 + if (src->f_path.dentry < dst->f_path.dentry) {
15990 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15991 + err = PTR_ERR(a_src.h_file);
15992 + if (IS_ERR(a_src.h_file))
15995 + wpre.lsc = AuLsc_FI_2;
15996 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15997 + err = PTR_ERR(a_dst.h_file);
15998 + if (IS_ERR(a_dst.h_file)) {
15999 + au_read_post(a_src.inode, a_src.h_file);
16003 + wpre.lsc = AuLsc_FI_1;
16004 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16005 + err = PTR_ERR(a_dst.h_file);
16006 + if (IS_ERR(a_dst.h_file))
16009 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16010 + err = PTR_ERR(a_src.h_file);
16011 + if (IS_ERR(a_src.h_file)) {
16012 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16019 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16020 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16021 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16027 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16028 + dst_pos, len, flags);
16031 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16032 + fi_read_unlock(src);
16033 + au_read_post(a_src.inode, a_src.h_file);
16035 + si_read_unlock(a_dst.inode->i_sb);
16036 + inode_unlock(a_dst.inode);
16043 +/* ---------------------------------------------------------------------- */
16046 + * The locking order around current->mmap_sem.
16047 + * - in most and regular cases
16048 + * file I/O syscall -- aufs_read() or something
16049 + * -- si_rwsem for read -- mmap_sem
16050 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16052 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16053 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
16054 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
16055 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16056 + * It means that when aufs acquires si_rwsem for write, the process should never
16057 + * acquire mmap_sem.
16059 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16060 + * problem either since any directory is not able to be mmap-ed.
16061 + * The similar scenario is applied to aufs_readlink() too.
16064 +#if 0 /* stop calling security_file_mmap() */
16065 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16066 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16068 +static unsigned long au_arch_prot_conv(unsigned long flags)
16070 + /* currently ppc64 only */
16071 +#ifdef CONFIG_PPC64
16072 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16073 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16074 + return AuConv_VM_PROT(flags, SAO);
16076 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16081 +static unsigned long au_prot_conv(unsigned long flags)
16083 + return AuConv_VM_PROT(flags, READ)
16084 + | AuConv_VM_PROT(flags, WRITE)
16085 + | AuConv_VM_PROT(flags, EXEC)
16086 + | au_arch_prot_conv(flags);
16089 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16090 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16092 +static unsigned long au_flag_conv(unsigned long flags)
16094 + return AuConv_VM_MAP(flags, GROWSDOWN)
16095 + | AuConv_VM_MAP(flags, DENYWRITE)
16096 + | AuConv_VM_MAP(flags, LOCKED);
16100 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16103 + const unsigned char wlock
16104 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16105 + struct super_block *sb;
16106 + struct file *h_file;
16107 + struct inode *inode;
16109 + AuDbgVmRegion(file, vma);
16111 + inode = file_inode(file);
16112 + sb = inode->i_sb;
16114 + si_read_lock(sb, AuLock_NOPLMW);
16116 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16118 + err = PTR_ERR(h_file);
16119 + if (IS_ERR(h_file))
16123 + au_set_mmapped(file);
16124 + au_vm_file_reset(vma, h_file);
16126 + * we cannot call security_mmap_file() here since it may acquire
16127 + * mmap_sem or i_mutex.
16129 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16130 + * au_flag_conv(vma->vm_flags));
16133 + err = call_mmap(h_file, vma);
16135 + au_vm_prfile_set(vma, file);
16136 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16137 + goto out_fput; /* success */
16139 + au_unset_mmapped(file);
16140 + au_vm_file_reset(vma, file);
16144 + ii_write_unlock(inode);
16149 + si_read_unlock(sb);
16155 +/* ---------------------------------------------------------------------- */
16157 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16161 + struct au_write_pre wpre;
16162 + struct inode *inode;
16163 + struct file *h_file;
16165 + err = 0; /* -EBADF; */ /* posix? */
16166 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16169 + inode = file_inode(file);
16170 + au_mtx_and_read_lock(inode);
16173 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16174 + err = PTR_ERR(h_file);
16175 + if (IS_ERR(h_file))
16178 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16179 + au_write_post(inode, h_file, &wpre, /*written*/0);
16182 + si_read_unlock(inode->i_sb);
16183 + inode_unlock(inode);
16188 +static int aufs_fasync(int fd, struct file *file, int flag)
16191 + struct file *h_file;
16192 + struct super_block *sb;
16194 + sb = file->f_path.dentry->d_sb;
16195 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16197 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16198 + err = PTR_ERR(h_file);
16199 + if (IS_ERR(h_file))
16202 + if (h_file->f_op->fasync)
16203 + err = h_file->f_op->fasync(fd, h_file, flag);
16204 + fput(h_file); /* instead of au_read_post() */
16207 + si_read_unlock(sb);
16211 +static int aufs_setfl(struct file *file, unsigned long arg)
16214 + struct file *h_file;
16215 + struct super_block *sb;
16217 + sb = file->f_path.dentry->d_sb;
16218 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16220 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16221 + err = PTR_ERR(h_file);
16222 + if (IS_ERR(h_file))
16225 + /* stop calling h_file->fasync */
16226 + arg |= vfsub_file_flags(file) & FASYNC;
16227 + err = setfl(/*unused fd*/-1, h_file, arg);
16228 + fput(h_file); /* instead of au_read_post() */
16231 + si_read_unlock(sb);
16235 +/* ---------------------------------------------------------------------- */
16237 +/* no one supports this operation, currently */
16239 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16240 + size_t len, loff_t *pos, int more)
16245 +/* ---------------------------------------------------------------------- */
16247 +const struct file_operations aufs_file_fop = {
16248 + .owner = THIS_MODULE,
16250 + .llseek = default_llseek,
16252 + .read = aufs_read,
16253 + .write = aufs_write,
16254 + .read_iter = aufs_read_iter,
16255 + .write_iter = aufs_write_iter,
16257 +#ifdef CONFIG_AUFS_POLL
16258 + .poll = aufs_poll,
16260 + .unlocked_ioctl = aufs_ioctl_nondir,
16261 +#ifdef CONFIG_COMPAT
16262 + .compat_ioctl = aufs_compat_ioctl_nondir,
16264 + .mmap = aufs_mmap,
16265 + .open = aufs_open_nondir,
16266 + .flush = aufs_flush_nondir,
16267 + .release = aufs_release_nondir,
16268 + .fsync = aufs_fsync_nondir,
16269 + .fasync = aufs_fasync,
16270 + /* .sendpage = aufs_sendpage, */
16271 + .setfl = aufs_setfl,
16272 + .splice_write = aufs_splice_write,
16273 + .splice_read = aufs_splice_read,
16275 + .aio_splice_write = aufs_aio_splice_write,
16276 + .aio_splice_read = aufs_aio_splice_read,
16278 + .fallocate = aufs_fallocate,
16279 + .copy_file_range = aufs_copy_file_range
16281 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16282 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16283 +++ linux/fs/aufs/fstype.h 2018-06-04 09:08:09.184746078 +0200
16286 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16288 + * This program, aufs is free software; you can redistribute it and/or modify
16289 + * it under the terms of the GNU General Public License as published by
16290 + * the Free Software Foundation; either version 2 of the License, or
16291 + * (at your option) any later version.
16293 + * This program is distributed in the hope that it will be useful,
16294 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16295 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16296 + * GNU General Public License for more details.
16298 + * You should have received a copy of the GNU General Public License
16299 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16303 + * judging filesystem type
16306 +#ifndef __AUFS_FSTYPE_H__
16307 +#define __AUFS_FSTYPE_H__
16311 +#include <linux/fs.h>
16312 +#include <linux/magic.h>
16313 +#include <linux/nfs_fs.h>
16314 +#include <linux/romfs_fs.h>
16316 +static inline int au_test_aufs(struct super_block *sb)
16318 + return sb->s_magic == AUFS_SUPER_MAGIC;
16321 +static inline const char *au_sbtype(struct super_block *sb)
16323 + return sb->s_type->name;
16326 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16328 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16329 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16335 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16337 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16338 + return sb->s_magic == ROMFS_MAGIC;
16344 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16346 +#if IS_ENABLED(CONFIG_CRAMFS)
16347 + return sb->s_magic == CRAMFS_MAGIC;
16352 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16354 +#if IS_ENABLED(CONFIG_NFS_FS)
16355 + return sb->s_magic == NFS_SUPER_MAGIC;
16361 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16363 +#if IS_ENABLED(CONFIG_FUSE_FS)
16364 + return sb->s_magic == FUSE_SUPER_MAGIC;
16370 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16372 +#if IS_ENABLED(CONFIG_XFS_FS)
16373 + return sb->s_magic == XFS_SB_MAGIC;
16379 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16381 +#ifdef CONFIG_TMPFS
16382 + return sb->s_magic == TMPFS_MAGIC;
16388 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16390 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16391 + return !strcmp(au_sbtype(sb), "ecryptfs");
16397 +static inline int au_test_ramfs(struct super_block *sb)
16399 + return sb->s_magic == RAMFS_MAGIC;
16402 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16404 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16405 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16411 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16413 +#ifdef CONFIG_PROC_FS
16414 + return sb->s_magic == PROC_SUPER_MAGIC;
16420 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16422 +#ifdef CONFIG_SYSFS
16423 + return sb->s_magic == SYSFS_MAGIC;
16429 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16431 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16432 + return sb->s_magic == CONFIGFS_MAGIC;
16438 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16440 +#if IS_ENABLED(CONFIG_MINIX_FS)
16441 + return sb->s_magic == MINIX3_SUPER_MAGIC
16442 + || sb->s_magic == MINIX2_SUPER_MAGIC
16443 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16444 + || sb->s_magic == MINIX_SUPER_MAGIC
16445 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16451 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16453 +#if IS_ENABLED(CONFIG_FAT_FS)
16454 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16460 +static inline int au_test_msdos(struct super_block *sb)
16462 + return au_test_fat(sb);
16465 +static inline int au_test_vfat(struct super_block *sb)
16467 + return au_test_fat(sb);
16470 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16472 +#ifdef CONFIG_SECURITYFS
16473 + return sb->s_magic == SECURITYFS_MAGIC;
16479 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16481 +#if IS_ENABLED(CONFIG_SQUASHFS)
16482 + return sb->s_magic == SQUASHFS_MAGIC;
16488 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16490 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16491 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16497 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16499 +#if IS_ENABLED(CONFIG_XENFS)
16500 + return sb->s_magic == XENFS_SUPER_MAGIC;
16506 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16508 +#ifdef CONFIG_DEBUG_FS
16509 + return sb->s_magic == DEBUGFS_MAGIC;
16515 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16517 +#if IS_ENABLED(CONFIG_NILFS)
16518 + return sb->s_magic == NILFS_SUPER_MAGIC;
16524 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16526 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16527 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16533 +/* ---------------------------------------------------------------------- */
16535 + * they can't be an aufs branch.
16537 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16540 +#ifndef CONFIG_AUFS_BR_RAMFS
16541 + au_test_ramfs(sb) ||
16543 + au_test_procfs(sb)
16544 + || au_test_sysfs(sb)
16545 + || au_test_configfs(sb)
16546 + || au_test_debugfs(sb)
16547 + || au_test_securityfs(sb)
16548 + || au_test_xenfs(sb)
16549 + || au_test_ecryptfs(sb)
16550 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16551 + || au_test_aufs(sb); /* will be supported in next version */
16554 +static inline int au_test_fs_remote(struct super_block *sb)
16556 + return !au_test_tmpfs(sb)
16557 +#ifdef CONFIG_AUFS_BR_RAMFS
16558 + && !au_test_ramfs(sb)
16560 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16563 +/* ---------------------------------------------------------------------- */
16566 + * Note: these functions (below) are created after reading ->getattr() in all
16567 + * filesystems under linux/fs. it means we have to do so in every update...
16571 + * some filesystems require getattr to refresh the inode attributes before
16573 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16574 + * and leave the work for d_revalidate()
16576 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16578 + return au_test_nfs(sb)
16579 + || au_test_fuse(sb)
16580 + /* || au_test_btrfs(sb) */ /* untested */
16585 + * filesystems which don't maintain i_size or i_blocks.
16587 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16589 + return au_test_xfs(sb)
16590 + || au_test_btrfs(sb)
16591 + || au_test_ubifs(sb)
16592 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16593 + /* || au_test_minix(sb) */ /* untested */
16598 + * filesystems which don't store the correct value in some of their inode
16601 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16603 + return au_test_fs_bad_iattr_size(sb)
16604 + || au_test_fat(sb)
16605 + || au_test_msdos(sb)
16606 + || au_test_vfat(sb);
16609 +/* they don't check i_nlink in link(2) */
16610 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16612 + return au_test_tmpfs(sb)
16613 +#ifdef CONFIG_AUFS_BR_RAMFS
16614 + || au_test_ramfs(sb)
16616 + || au_test_ubifs(sb)
16617 + || au_test_hfsplus(sb);
16621 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16623 +static inline int au_test_fs_notime(struct super_block *sb)
16625 + return au_test_nfs(sb)
16626 + || au_test_fuse(sb)
16627 + || au_test_ubifs(sb)
16631 +/* temporary support for i#1 in cramfs */
16632 +static inline int au_test_fs_unique_ino(struct inode *inode)
16634 + if (au_test_cramfs(inode->i_sb))
16635 + return inode->i_ino != 1;
16639 +/* ---------------------------------------------------------------------- */
16642 + * the filesystem where the xino files placed must support i/o after unlink and
16643 + * maintain i_size and i_blocks.
16645 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16647 + return au_test_fs_remote(sb)
16648 + || au_test_fs_bad_iattr_size(sb)
16649 + /* don't want unnecessary work for xino */
16650 + || au_test_aufs(sb)
16651 + || au_test_ecryptfs(sb)
16652 + || au_test_nilfs(sb);
16655 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16657 + return au_test_tmpfs(sb)
16658 + || au_test_ramfs(sb);
16662 + * test if the @sb is real-readonly.
16664 +static inline int au_test_fs_rr(struct super_block *sb)
16666 + return au_test_squashfs(sb)
16667 + || au_test_iso9660(sb)
16668 + || au_test_cramfs(sb)
16669 + || au_test_romfs(sb);
16673 + * test if the @inode is nfs with 'noacl' option
16674 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16676 +static inline int au_test_nfs_noacl(struct inode *inode)
16678 + return au_test_nfs(inode->i_sb)
16679 + /* && IS_POSIXACL(inode) */
16680 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16683 +#endif /* __KERNEL__ */
16684 +#endif /* __AUFS_FSTYPE_H__ */
16685 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16686 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16687 +++ linux/fs/aufs/hbl.h 2018-04-15 08:49:13.401150731 +0200
16690 + * Copyright (C) 2017-2018 Junjiro R. Okajima
16692 + * This program, aufs is free software; you can redistribute it and/or modify
16693 + * it under the terms of the GNU General Public License as published by
16694 + * the Free Software Foundation; either version 2 of the License, or
16695 + * (at your option) any later version.
16697 + * This program is distributed in the hope that it will be useful,
16698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16700 + * GNU General Public License for more details.
16702 + * You should have received a copy of the GNU General Public License
16703 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16707 + * helpers for hlist_bl.h
16710 +#ifndef __AUFS_HBL_H__
16711 +#define __AUFS_HBL_H__
16715 +#include <linux/list_bl.h>
16717 +static inline void au_hbl_add(struct hlist_bl_node *node,
16718 + struct hlist_bl_head *hbl)
16720 + hlist_bl_lock(hbl);
16721 + hlist_bl_add_head(node, hbl);
16722 + hlist_bl_unlock(hbl);
16725 +static inline void au_hbl_del(struct hlist_bl_node *node,
16726 + struct hlist_bl_head *hbl)
16728 + hlist_bl_lock(hbl);
16729 + hlist_bl_del(node);
16730 + hlist_bl_unlock(hbl);
16733 +#define au_hbl_for_each(pos, head) \
16734 + for (pos = hlist_bl_first(head); \
16738 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16740 + unsigned long cnt;
16741 + struct hlist_bl_node *pos;
16744 + hlist_bl_lock(hbl);
16745 + au_hbl_for_each(pos, hbl)
16747 + hlist_bl_unlock(hbl);
16751 +#endif /* __KERNEL__ */
16752 +#endif /* __AUFS_HBL_H__ */
16753 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16754 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16755 +++ linux/fs/aufs/hfsnotify.c 2018-06-04 09:08:09.184746078 +0200
16758 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16760 + * This program, aufs is free software; you can redistribute it and/or modify
16761 + * it under the terms of the GNU General Public License as published by
16762 + * the Free Software Foundation; either version 2 of the License, or
16763 + * (at your option) any later version.
16765 + * This program is distributed in the hope that it will be useful,
16766 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16767 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16768 + * GNU General Public License for more details.
16770 + * You should have received a copy of the GNU General Public License
16771 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16775 + * fsnotify for the lower directories
16780 +/* FS_IN_IGNORED is unnecessary */
16781 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16782 + | FS_CREATE | FS_EVENT_ON_CHILD);
16783 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16784 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16786 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16788 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16790 + /* AuDbg("here\n"); */
16791 + au_cache_free_hnotify(hn);
16792 + smp_mb__before_atomic(); /* for atomic64_dec */
16793 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16794 + wake_up(&au_hfsn_wq);
16797 +static int au_hfsn_alloc(struct au_hinode *hinode)
16800 + struct au_hnotify *hn;
16801 + struct super_block *sb;
16802 + struct au_branch *br;
16803 + struct fsnotify_mark *mark;
16804 + aufs_bindex_t bindex;
16806 + hn = hinode->hi_notify;
16807 + sb = hn->hn_aufs_inode->i_sb;
16808 + bindex = au_br_index(sb, hinode->hi_id);
16809 + br = au_sbr(sb, bindex);
16810 + AuDebugOn(!br->br_hfsn);
16812 + mark = &hn->hn_mark;
16813 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16814 + mark->mask = AuHfsnMask;
16816 + * by udba rename or rmdir, aufs assign a new inode to the known
16817 + * h_inode, so specify 1 to allow dups.
16820 + err = fsnotify_add_mark(mark, hinode->hi_inode, /*mnt*/NULL,
16821 + /*allow_dups*/1);
16827 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16829 + struct fsnotify_mark *mark;
16830 + unsigned long long ull;
16831 + struct fsnotify_group *group;
16833 + ull = atomic64_inc_return(&au_hfsn_ifree);
16836 + mark = &hn->hn_mark;
16837 + spin_lock(&mark->lock);
16838 + group = mark->group;
16839 + fsnotify_get_group(group);
16840 + spin_unlock(&mark->lock);
16842 + fsnotify_destroy_mark(mark, group);
16843 + fsnotify_put_mark(mark);
16844 + fsnotify_put_group(group);
16847 + /* free hn by myself */
16851 +/* ---------------------------------------------------------------------- */
16853 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16855 + struct fsnotify_mark *mark;
16857 + mark = &hinode->hi_notify->hn_mark;
16858 + spin_lock(&mark->lock);
16860 + AuDebugOn(mark->mask & AuHfsnMask);
16861 + mark->mask |= AuHfsnMask;
16863 + AuDebugOn(!(mark->mask & AuHfsnMask));
16864 + mark->mask &= ~AuHfsnMask;
16866 + spin_unlock(&mark->lock);
16867 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16870 +/* ---------------------------------------------------------------------- */
16872 +/* #define AuDbgHnotify */
16873 +#ifdef AuDbgHnotify
16874 +static char *au_hfsn_name(u32 mask)
16876 +#ifdef CONFIG_AUFS_DEBUG
16877 +#define test_ret(flag) \
16879 + if (mask & flag) \
16882 + test_ret(FS_ACCESS);
16883 + test_ret(FS_MODIFY);
16884 + test_ret(FS_ATTRIB);
16885 + test_ret(FS_CLOSE_WRITE);
16886 + test_ret(FS_CLOSE_NOWRITE);
16887 + test_ret(FS_OPEN);
16888 + test_ret(FS_MOVED_FROM);
16889 + test_ret(FS_MOVED_TO);
16890 + test_ret(FS_CREATE);
16891 + test_ret(FS_DELETE);
16892 + test_ret(FS_DELETE_SELF);
16893 + test_ret(FS_MOVE_SELF);
16894 + test_ret(FS_UNMOUNT);
16895 + test_ret(FS_Q_OVERFLOW);
16896 + test_ret(FS_IN_IGNORED);
16897 + test_ret(FS_ISDIR);
16898 + test_ret(FS_IN_ONESHOT);
16899 + test_ret(FS_EVENT_ON_CHILD);
16908 +/* ---------------------------------------------------------------------- */
16910 +static void au_hfsn_free_group(struct fsnotify_group *group)
16912 + struct au_br_hfsnotify *hfsn = group->private;
16914 + /* AuDbg("here\n"); */
16918 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16919 + struct inode *inode,
16920 + struct fsnotify_mark *inode_mark,
16921 + struct fsnotify_mark *vfsmount_mark,
16922 + u32 mask, const void *data, int data_type,
16923 + const unsigned char *file_name, u32 cookie,
16924 + struct fsnotify_iter_info *iter_info)
16927 + struct au_hnotify *hnotify;
16928 + struct inode *h_dir, *h_inode;
16929 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
16931 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16934 + /* if FS_UNMOUNT happens, there must be another bug */
16935 + AuDebugOn(mask & FS_UNMOUNT);
16936 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16941 +#ifdef AuDbgHnotify
16943 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16944 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16945 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16946 + h_dir->i_ino, mask, au_hfsn_name(mask),
16947 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16948 + /* WARN_ON(1); */
16953 + AuDebugOn(!inode_mark);
16954 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16955 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
16961 +static struct fsnotify_ops au_hfsn_ops = {
16962 + .handle_event = au_hfsn_handle_event,
16963 + .free_group_priv = au_hfsn_free_group,
16964 + .free_mark = au_hfsn_free_mark
16967 +/* ---------------------------------------------------------------------- */
16969 +static void au_hfsn_fin_br(struct au_branch *br)
16971 + struct au_br_hfsnotify *hfsn;
16973 + hfsn = br->br_hfsn;
16976 + fsnotify_put_group(hfsn->hfsn_group);
16981 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16984 + struct fsnotify_group *group;
16985 + struct au_br_hfsnotify *hfsn;
16988 + br->br_hfsn = NULL;
16989 + if (!au_br_hnotifyable(perm))
16993 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16994 + if (unlikely(!hfsn))
16998 + group = fsnotify_alloc_group(&au_hfsn_ops);
16999 + if (IS_ERR(group)) {
17000 + err = PTR_ERR(group);
17001 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17005 + group->private = hfsn;
17006 + hfsn->hfsn_group = group;
17007 + br->br_hfsn = hfsn;
17008 + goto out; /* success */
17016 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17021 + if (!br->br_hfsn)
17022 + err = au_hfsn_init_br(br, perm);
17027 +/* ---------------------------------------------------------------------- */
17029 +static void au_hfsn_fin(void)
17031 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17032 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17035 +const struct au_hnotify_op au_hnotify_op = {
17036 + .ctl = au_hfsn_ctl,
17037 + .alloc = au_hfsn_alloc,
17038 + .free = au_hfsn_free,
17040 + .fin = au_hfsn_fin,
17042 + .reset_br = au_hfsn_reset_br,
17043 + .fin_br = au_hfsn_fin_br,
17044 + .init_br = au_hfsn_init_br
17046 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17047 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17048 +++ linux/fs/aufs/hfsplus.c 2018-04-15 08:49:13.401150731 +0200
17051 + * Copyright (C) 2010-2018 Junjiro R. Okajima
17053 + * This program, aufs is free software; you can redistribute it and/or modify
17054 + * it under the terms of the GNU General Public License as published by
17055 + * the Free Software Foundation; either version 2 of the License, or
17056 + * (at your option) any later version.
17058 + * This program is distributed in the hope that it will be useful,
17059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17061 + * GNU General Public License for more details.
17063 + * You should have received a copy of the GNU General Public License
17064 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17068 + * special support for filesystems which aqucires an inode mutex
17069 + * at final closing a file, eg, hfsplus.
17071 + * This trick is very simple and stupid, just to open the file before really
17072 + * neceeary open to tell hfsplus that this is not the final closing.
17073 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17074 + * and au_h_open_post() after releasing it.
17079 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17082 + struct file *h_file;
17083 + struct dentry *h_dentry;
17085 + h_dentry = au_h_dptr(dentry, bindex);
17086 + AuDebugOn(!h_dentry);
17087 + AuDebugOn(d_is_negative(h_dentry));
17090 + if (au_test_hfsplus(h_dentry->d_sb)
17091 + && d_is_reg(h_dentry))
17092 + h_file = au_h_open(dentry, bindex,
17093 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17094 + /*file*/NULL, force_wr);
17098 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17099 + struct file *h_file)
17103 + au_sbr_put(dentry->d_sb, bindex);
17106 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17107 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17108 +++ linux/fs/aufs/hnotify.c 2018-06-04 09:08:09.184746078 +0200
17111 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17113 + * This program, aufs is free software; you can redistribute it and/or modify
17114 + * it under the terms of the GNU General Public License as published by
17115 + * the Free Software Foundation; either version 2 of the License, or
17116 + * (at your option) any later version.
17118 + * This program is distributed in the hope that it will be useful,
17119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17121 + * GNU General Public License for more details.
17123 + * You should have received a copy of the GNU General Public License
17124 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17128 + * abstraction to notify the direct changes on lower directories
17133 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17136 + struct au_hnotify *hn;
17139 + hn = au_cache_alloc_hnotify();
17141 + hn->hn_aufs_inode = inode;
17142 + hinode->hi_notify = hn;
17143 + err = au_hnotify_op.alloc(hinode);
17145 + if (unlikely(err)) {
17146 + hinode->hi_notify = NULL;
17147 + au_cache_free_hnotify(hn);
17149 + * The upper dir was removed by udba, but the same named
17150 + * dir left. In this case, aufs assignes a new inode
17151 + * number and set the monitor again.
17152 + * For the lower dir, the old monitnor is still left.
17154 + if (err == -EEXIST)
17163 +void au_hn_free(struct au_hinode *hinode)
17165 + struct au_hnotify *hn;
17167 + hn = hinode->hi_notify;
17169 + hinode->hi_notify = NULL;
17170 + if (au_hnotify_op.free(hinode, hn))
17171 + au_cache_free_hnotify(hn);
17175 +/* ---------------------------------------------------------------------- */
17177 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17179 + if (hinode->hi_notify)
17180 + au_hnotify_op.ctl(hinode, do_set);
17183 +void au_hn_reset(struct inode *inode, unsigned int flags)
17185 + aufs_bindex_t bindex, bbot;
17186 + struct inode *hi;
17187 + struct dentry *iwhdentry;
17189 + bbot = au_ibbot(inode);
17190 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17191 + hi = au_h_iptr(inode, bindex);
17195 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17196 + iwhdentry = au_hi_wh(inode, bindex);
17200 + au_set_h_iptr(inode, bindex, NULL, 0);
17201 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17202 + flags & ~AuHi_XINO);
17205 + /* inode_unlock(hi); */
17209 +/* ---------------------------------------------------------------------- */
17211 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17214 + aufs_bindex_t bindex, bbot, bfound, btop;
17215 + struct inode *h_i;
17218 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17219 + pr_warn("branch root dir was changed\n");
17224 + bbot = au_ibbot(inode);
17225 + btop = au_ibtop(inode);
17226 +#if 0 /* reserved for future use */
17227 + if (bindex == bbot) {
17228 + /* keep this ino in rename case */
17232 + for (bindex = btop; bindex <= bbot; bindex++)
17233 + if (au_h_iptr(inode, bindex) == h_inode) {
17240 + for (bindex = btop; bindex <= bbot; bindex++) {
17241 + h_i = au_h_iptr(inode, bindex);
17245 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17246 + /* ignore this error */
17247 + /* bad action? */
17250 + /* children inode number will be broken */
17257 +static int hn_gen_tree(struct dentry *dentry)
17259 + int err, i, j, ndentry;
17260 + struct au_dcsub_pages dpages;
17261 + struct au_dpage *dpage;
17262 + struct dentry **dentries;
17264 + err = au_dpages_init(&dpages, GFP_NOFS);
17265 + if (unlikely(err))
17267 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17268 + if (unlikely(err))
17271 + for (i = 0; i < dpages.ndpage; i++) {
17272 + dpage = dpages.dpages + i;
17273 + dentries = dpage->dentries;
17274 + ndentry = dpage->ndentry;
17275 + for (j = 0; j < ndentry; j++) {
17276 + struct dentry *d;
17283 + if (d_really_is_positive(d))
17284 + /* todo: reset children xino?
17285 + cached children only? */
17286 + au_iigen_dec(d_inode(d));
17291 + au_dpages_free(&dpages);
17294 + /* discard children */
17295 + dentry_unhash(dentry);
17303 + * return 0 if processed.
17305 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17306 + const unsigned int isdir)
17309 + struct dentry *d;
17310 + struct qstr *dname;
17313 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17314 + pr_warn("branch root dir was changed\n");
17320 + AuDebugOn(!name);
17321 + au_iigen_dec(inode);
17322 + spin_lock(&inode->i_lock);
17323 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17324 + spin_lock(&d->d_lock);
17325 + dname = &d->d_name;
17326 + if (dname->len != nlen
17327 + && memcmp(dname->name, name, nlen)) {
17328 + spin_unlock(&d->d_lock);
17333 + spin_unlock(&d->d_lock);
17336 + spin_unlock(&inode->i_lock);
17338 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17339 + d = d_find_any_alias(inode);
17341 + au_iigen_dec(inode);
17345 + spin_lock(&d->d_lock);
17346 + dname = &d->d_name;
17347 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17348 + spin_unlock(&d->d_lock);
17349 + err = hn_gen_tree(d);
17350 + spin_lock(&d->d_lock);
17352 + spin_unlock(&d->d_lock);
17361 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17365 + if (IS_ROOT(dentry)) {
17366 + pr_warn("branch root dir was changed\n");
17372 + au_digen_dec(dentry);
17373 + if (d_really_is_positive(dentry))
17374 + au_iigen_dec(d_inode(dentry));
17376 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17377 + if (d_really_is_positive(dentry))
17378 + err = hn_gen_tree(dentry);
17385 +/* ---------------------------------------------------------------------- */
17387 +/* hnotify job flags */
17388 +#define AuHnJob_XINO0 1
17389 +#define AuHnJob_GEN (1 << 1)
17390 +#define AuHnJob_DIRENT (1 << 2)
17391 +#define AuHnJob_ISDIR (1 << 3)
17392 +#define AuHnJob_TRYXINO0 (1 << 4)
17393 +#define AuHnJob_MNTPNT (1 << 5)
17394 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17395 +#define au_fset_hnjob(flags, name) \
17396 + do { (flags) |= AuHnJob_##name; } while (0)
17397 +#define au_fclr_hnjob(flags, name) \
17398 + do { (flags) &= ~AuHnJob_##name; } while (0)
17406 +struct au_hnotify_args {
17407 + struct inode *h_dir, *dir, *h_child_inode;
17409 + unsigned int flags[AuHnLast];
17410 + unsigned int h_child_nlen;
17411 + char h_child_name[];
17414 +struct hn_job_args {
17415 + unsigned int flags;
17416 + struct inode *inode, *h_inode, *dir, *h_dir;
17417 + struct dentry *dentry;
17422 +static int hn_job(struct hn_job_args *a)
17424 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17428 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17429 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17431 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17434 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17435 + if (!a->h_inode->i_nlink
17436 + && !(a->h_inode->i_state & I_LINKABLE))
17437 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17438 + inode_unlock_shared(a->h_inode);
17441 + /* make the generation obsolete */
17442 + if (au_ftest_hnjob(a->flags, GEN)) {
17445 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17447 + if (e && a->dentry)
17448 + hn_gen_by_name(a->dentry, isdir);
17449 + /* ignore this error */
17452 + /* make dir entries obsolete */
17453 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17454 + struct au_vdir *vdir;
17456 + vdir = au_ivdir(a->inode);
17458 + vdir->vd_jiffy = 0;
17459 + /* IMustLock(a->inode); */
17460 + /* inode_inc_iversion(a->inode); */
17463 + /* can do nothing but warn */
17464 + if (au_ftest_hnjob(a->flags, MNTPNT)
17466 + && d_mountpoint(a->dentry))
17467 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17472 +/* ---------------------------------------------------------------------- */
17474 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17475 + struct inode *dir)
17477 + struct dentry *dentry, *d, *parent;
17478 + struct qstr *dname;
17480 + parent = d_find_any_alias(dir);
17485 + spin_lock(&parent->d_lock);
17486 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17487 + /* AuDbg("%pd\n", d); */
17488 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17489 + dname = &d->d_name;
17490 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17491 + goto cont_unlock;
17495 + goto cont_unlock;
17496 + if (au_dcount(d) > 0) {
17497 + dentry = dget_dlock(d);
17498 + spin_unlock(&d->d_lock);
17503 + spin_unlock(&d->d_lock);
17505 + spin_unlock(&parent->d_lock);
17509 + di_write_lock_child(dentry);
17514 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17515 + aufs_bindex_t bindex, ino_t h_ino)
17517 + struct inode *inode;
17522 + err = au_xino_read(sb, bindex, h_ino, &ino);
17524 + inode = ilookup(sb, ino);
17528 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17529 + pr_warn("wrong root branch\n");
17535 + ii_write_lock_child(inode);
17541 +static void au_hn_bh(void *_args)
17543 + struct au_hnotify_args *a = _args;
17544 + struct super_block *sb;
17545 + aufs_bindex_t bindex, bbot, bfound;
17546 + unsigned char xino, try_iput;
17548 + struct inode *inode;
17550 + struct hn_job_args args;
17551 + struct dentry *dentry;
17552 + struct au_sbinfo *sbinfo;
17554 + AuDebugOn(!_args);
17555 + AuDebugOn(!a->h_dir);
17556 + AuDebugOn(!a->dir);
17557 + AuDebugOn(!a->mask);
17558 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17559 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17560 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17565 + * do not lock a->dir->i_mutex here
17566 + * because of d_revalidate() may cause a deadlock.
17568 + sb = a->dir->i_sb;
17570 + sbinfo = au_sbi(sb);
17571 + AuDebugOn(!sbinfo);
17572 + si_write_lock(sb, AuLock_NOPLMW);
17574 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17575 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17576 + case FS_MOVED_FROM:
17577 + case FS_MOVED_TO:
17578 + AuWarn1("DIRREN with UDBA may not work correctly "
17579 + "for the direct rename(2)\n");
17582 + ii_read_lock_parent(a->dir);
17584 + bbot = au_ibbot(a->dir);
17585 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17586 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17590 + ii_read_unlock(a->dir);
17591 + if (unlikely(bfound < 0))
17594 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17596 + if (a->h_child_inode)
17597 + h_ino = a->h_child_inode->i_ino;
17599 + if (a->h_child_nlen
17600 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17601 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17602 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17605 + if (dentry && d_really_is_positive(dentry))
17606 + inode = d_inode(dentry);
17607 + if (xino && !inode && h_ino
17608 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17609 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17610 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17611 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17615 + args.flags = a->flags[AuHn_CHILD];
17616 + args.dentry = dentry;
17617 + args.inode = inode;
17618 + args.h_inode = a->h_child_inode;
17619 + args.dir = a->dir;
17620 + args.h_dir = a->h_dir;
17621 + args.h_name = a->h_child_name;
17622 + args.h_nlen = a->h_child_nlen;
17623 + err = hn_job(&args);
17625 + if (au_di(dentry))
17626 + di_write_unlock(dentry);
17629 + if (inode && try_iput) {
17630 + ii_write_unlock(inode);
17634 + ii_write_lock_parent(a->dir);
17635 + args.flags = a->flags[AuHn_PARENT];
17636 + args.dentry = NULL;
17637 + args.inode = a->dir;
17638 + args.h_inode = a->h_dir;
17640 + args.h_dir = NULL;
17641 + args.h_name = NULL;
17643 + err = hn_job(&args);
17644 + ii_write_unlock(a->dir);
17647 + iput(a->h_child_inode);
17650 + si_write_unlock(sb);
17651 + au_nwt_done(&sbinfo->si_nowait);
17655 +/* ---------------------------------------------------------------------- */
17657 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17658 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17661 + unsigned int flags[AuHnLast], f;
17662 + unsigned char isdir, isroot, wh;
17663 + struct inode *dir;
17664 + struct au_hnotify_args *args;
17665 + char *p, *h_child_name;
17668 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17669 + dir = igrab(hnotify->hn_aufs_inode);
17673 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17675 + h_child_name = (void *)h_child_qstr->name;
17676 + len = h_child_qstr->len;
17677 + if (h_child_name) {
17678 + if (len > AUFS_WH_PFX_LEN
17679 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17680 + h_child_name += AUFS_WH_PFX_LEN;
17681 + len -= AUFS_WH_PFX_LEN;
17687 + if (h_child_inode)
17688 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17689 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17690 + flags[AuHn_CHILD] = 0;
17692 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17693 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17694 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17695 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17696 + case FS_MOVED_FROM:
17697 + case FS_MOVED_TO:
17698 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17699 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17702 + AuDebugOn(!h_child_name);
17707 + * aufs never be able to get this child inode.
17708 + * revalidation should be in d_revalidate()
17709 + * by checking i_nlink, i_generation or d_unhashed().
17711 + AuDebugOn(!h_child_name);
17712 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17713 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17721 + h_child_inode = NULL;
17724 + /* iput() and kfree() will be called in au_hnotify() */
17725 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17726 + if (unlikely(!args)) {
17727 + AuErr1("no memory\n");
17731 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17732 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17733 + args->mask = mask;
17735 + args->h_dir = igrab(h_dir);
17736 + if (h_child_inode)
17737 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17738 + args->h_child_inode = h_child_inode;
17739 + args->h_child_nlen = len;
17741 + p = (void *)args;
17742 + p += sizeof(*args);
17743 + memcpy(p, h_child_name, len);
17747 + /* NFS fires the event for silly-renamed one from kworker */
17749 + if (!dir->i_nlink
17750 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17752 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17753 + if (unlikely(err)) {
17754 + pr_err("wkq %d\n", err);
17755 + iput(args->h_child_inode);
17756 + iput(args->h_dir);
17765 +/* ---------------------------------------------------------------------- */
17767 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17771 + AuDebugOn(!(udba & AuOptMask_UDBA));
17774 + if (au_hnotify_op.reset_br)
17775 + err = au_hnotify_op.reset_br(udba, br, perm);
17780 +int au_hnotify_init_br(struct au_branch *br, int perm)
17785 + if (au_hnotify_op.init_br)
17786 + err = au_hnotify_op.init_br(br, perm);
17791 +void au_hnotify_fin_br(struct au_branch *br)
17793 + if (au_hnotify_op.fin_br)
17794 + au_hnotify_op.fin_br(br);
17797 +static void au_hn_destroy_cache(void)
17799 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17800 + au_cache[AuCache_HNOTIFY] = NULL;
17803 +int __init au_hnotify_init(void)
17808 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17809 + if (au_cache[AuCache_HNOTIFY]) {
17811 + if (au_hnotify_op.init)
17812 + err = au_hnotify_op.init();
17813 + if (unlikely(err))
17814 + au_hn_destroy_cache();
17820 +void au_hnotify_fin(void)
17822 + if (au_hnotify_op.fin)
17823 + au_hnotify_op.fin();
17825 + /* cf. au_cache_fin() */
17826 + if (au_cache[AuCache_HNOTIFY])
17827 + au_hn_destroy_cache();
17829 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17830 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17831 +++ linux/fs/aufs/iinfo.c 2018-04-15 08:49:13.401150731 +0200
17834 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17836 + * This program, aufs is free software; you can redistribute it and/or modify
17837 + * it under the terms of the GNU General Public License as published by
17838 + * the Free Software Foundation; either version 2 of the License, or
17839 + * (at your option) any later version.
17841 + * This program is distributed in the hope that it will be useful,
17842 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17843 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17844 + * GNU General Public License for more details.
17846 + * You should have received a copy of the GNU General Public License
17847 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17851 + * inode private data
17856 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17858 + struct inode *h_inode;
17859 + struct au_hinode *hinode;
17861 + IiMustAnyLock(inode);
17863 + hinode = au_hinode(au_ii(inode), bindex);
17864 + h_inode = hinode->hi_inode;
17865 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17869 +/* todo: hard/soft set? */
17870 +void au_hiput(struct au_hinode *hinode)
17872 + au_hn_free(hinode);
17873 + dput(hinode->hi_whdentry);
17874 + iput(hinode->hi_inode);
17877 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17879 + unsigned int flags;
17880 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17883 + if (au_opt_test(mnt_flags, XINO))
17884 + au_fset_hi(flags, XINO);
17885 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17886 + au_fset_hi(flags, HNOTIFY);
17890 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17891 + struct inode *h_inode, unsigned int flags)
17893 + struct au_hinode *hinode;
17894 + struct inode *hi;
17895 + struct au_iinfo *iinfo = au_ii(inode);
17897 + IiMustWriteLock(inode);
17899 + hinode = au_hinode(iinfo, bindex);
17900 + hi = hinode->hi_inode;
17901 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17904 + au_hiput(hinode);
17905 + hinode->hi_inode = h_inode;
17908 + struct super_block *sb = inode->i_sb;
17909 + struct au_branch *br;
17911 + AuDebugOn(inode->i_mode
17912 + && (h_inode->i_mode & S_IFMT)
17913 + != (inode->i_mode & S_IFMT));
17914 + if (bindex == iinfo->ii_btop)
17915 + au_cpup_igen(inode, h_inode);
17916 + br = au_sbr(sb, bindex);
17917 + hinode->hi_id = br->br_id;
17918 + if (au_ftest_hi(flags, XINO)) {
17919 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17921 + if (unlikely(err))
17922 + AuIOErr1("failed au_xino_write() %d\n", err);
17925 + if (au_ftest_hi(flags, HNOTIFY)
17926 + && au_br_hnotifyable(br->br_perm)) {
17927 + err = au_hn_alloc(hinode, inode);
17928 + if (unlikely(err))
17929 + AuIOErr1("au_hn_alloc() %d\n", err);
17934 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17935 + struct dentry *h_wh)
17937 + struct au_hinode *hinode;
17939 + IiMustWriteLock(inode);
17941 + hinode = au_hinode(au_ii(inode), bindex);
17942 + AuDebugOn(hinode->hi_whdentry);
17943 + hinode->hi_whdentry = h_wh;
17946 +void au_update_iigen(struct inode *inode, int half)
17948 + struct au_iinfo *iinfo;
17949 + struct au_iigen *iigen;
17950 + unsigned int sigen;
17952 + sigen = au_sigen(inode->i_sb);
17953 + iinfo = au_ii(inode);
17954 + iigen = &iinfo->ii_generation;
17955 + spin_lock(&iigen->ig_spin);
17956 + iigen->ig_generation = sigen;
17958 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17960 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17961 + spin_unlock(&iigen->ig_spin);
17964 +/* it may be called at remount time, too */
17965 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17967 + struct au_iinfo *iinfo;
17968 + aufs_bindex_t bindex, bbot;
17970 + AuDebugOn(au_is_bad_inode(inode));
17971 + IiMustWriteLock(inode);
17973 + iinfo = au_ii(inode);
17974 + if (do_put_zero && iinfo->ii_btop >= 0) {
17975 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17977 + struct inode *h_i;
17979 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17982 + && !(h_i->i_state & I_LINKABLE))
17983 + au_set_h_iptr(inode, bindex, NULL, 0);
17987 + iinfo->ii_btop = -1;
17988 + iinfo->ii_bbot = -1;
17989 + bbot = au_sbbot(inode->i_sb);
17990 + for (bindex = 0; bindex <= bbot; bindex++)
17991 + if (au_hinode(iinfo, bindex)->hi_inode) {
17992 + iinfo->ii_btop = bindex;
17995 + if (iinfo->ii_btop >= 0)
17996 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17997 + if (au_hinode(iinfo, bindex)->hi_inode) {
17998 + iinfo->ii_bbot = bindex;
18001 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18004 +/* ---------------------------------------------------------------------- */
18006 +void au_icntnr_init_once(void *_c)
18008 + struct au_icntnr *c = _c;
18009 + struct au_iinfo *iinfo = &c->iinfo;
18011 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18012 + au_rw_init(&iinfo->ii_rwsem);
18013 + inode_init_once(&c->vfs_inode);
18016 +void au_hinode_init(struct au_hinode *hinode)
18018 + hinode->hi_inode = NULL;
18019 + hinode->hi_id = -1;
18020 + au_hn_init(hinode);
18021 + hinode->hi_whdentry = NULL;
18024 +int au_iinfo_init(struct inode *inode)
18026 + struct au_iinfo *iinfo;
18027 + struct super_block *sb;
18028 + struct au_hinode *hi;
18031 + sb = inode->i_sb;
18032 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18033 + nbr = au_sbbot(sb) + 1;
18034 + if (unlikely(nbr <= 0))
18036 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18038 + au_ninodes_inc(sb);
18040 + iinfo->ii_hinode = hi;
18041 + for (i = 0; i < nbr; i++, hi++)
18042 + au_hinode_init(hi);
18044 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18045 + iinfo->ii_btop = -1;
18046 + iinfo->ii_bbot = -1;
18047 + iinfo->ii_vdir = NULL;
18053 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18056 + struct au_hinode *hip;
18058 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18061 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18064 + iinfo->ii_hinode = hip;
18065 + i = iinfo->ii_bbot + 1;
18067 + for (; i < nbr; i++, hip++)
18068 + au_hinode_init(hip);
18075 +void au_iinfo_fin(struct inode *inode)
18077 + struct au_iinfo *iinfo;
18078 + struct au_hinode *hi;
18079 + struct super_block *sb;
18080 + aufs_bindex_t bindex, bbot;
18081 + const unsigned char unlinked = !inode->i_nlink;
18083 + AuDebugOn(au_is_bad_inode(inode));
18085 + sb = inode->i_sb;
18086 + au_ninodes_dec(sb);
18087 + if (si_pid_test(sb))
18088 + au_xino_delete_inode(inode, unlinked);
18091 + * it is safe to hide the dependency between sbinfo and
18095 + si_noflush_read_lock(sb);
18096 + au_xino_delete_inode(inode, unlinked);
18097 + si_read_unlock(sb);
18101 + iinfo = au_ii(inode);
18102 + if (iinfo->ii_vdir)
18103 + au_vdir_free(iinfo->ii_vdir);
18105 + bindex = iinfo->ii_btop;
18106 + if (bindex >= 0) {
18107 + hi = au_hinode(iinfo, bindex);
18108 + bbot = iinfo->ii_bbot;
18109 + while (bindex++ <= bbot) {
18110 + if (hi->hi_inode)
18115 + kfree(iinfo->ii_hinode);
18116 + AuRwDestroy(&iinfo->ii_rwsem);
18118 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18119 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18120 +++ linux/fs/aufs/inode.c 2018-06-04 09:08:09.184746078 +0200
18123 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18125 + * This program, aufs is free software; you can redistribute it and/or modify
18126 + * it under the terms of the GNU General Public License as published by
18127 + * the Free Software Foundation; either version 2 of the License, or
18128 + * (at your option) any later version.
18130 + * This program is distributed in the hope that it will be useful,
18131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18133 + * GNU General Public License for more details.
18135 + * You should have received a copy of the GNU General Public License
18136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18140 + * inode functions
18145 +struct inode *au_igrab(struct inode *inode)
18148 + AuDebugOn(!atomic_read(&inode->i_count));
18154 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18156 + au_cpup_attr_all(inode, /*force*/0);
18157 + au_update_iigen(inode, /*half*/1);
18159 + inode_inc_iversion(inode);
18162 +static int au_ii_refresh(struct inode *inode, int *update)
18166 + aufs_bindex_t bindex, new_bindex;
18167 + struct super_block *sb;
18168 + struct au_iinfo *iinfo;
18169 + struct au_hinode *p, *q, tmp;
18171 + AuDebugOn(au_is_bad_inode(inode));
18172 + IiMustWriteLock(inode);
18175 + sb = inode->i_sb;
18176 + nbr = au_sbbot(sb) + 1;
18177 + type = inode->i_mode & S_IFMT;
18178 + iinfo = au_ii(inode);
18179 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18180 + if (unlikely(err))
18183 + AuDebugOn(iinfo->ii_btop < 0);
18184 + p = au_hinode(iinfo, iinfo->ii_btop);
18185 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18187 + if (!p->hi_inode)
18190 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18191 + new_bindex = au_br_index(sb, p->hi_id);
18192 + if (new_bindex == bindex)
18195 + if (new_bindex < 0) {
18198 + p->hi_inode = NULL;
18202 + if (new_bindex < iinfo->ii_btop)
18203 + iinfo->ii_btop = new_bindex;
18204 + if (iinfo->ii_bbot < new_bindex)
18205 + iinfo->ii_bbot = new_bindex;
18206 + /* swap two lower inode, and loop again */
18207 + q = au_hinode(iinfo, new_bindex);
18211 + if (tmp.hi_inode) {
18216 + au_update_ibrange(inode, /*do_put_zero*/0);
18217 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18218 + e = au_dy_irefresh(inode);
18219 + if (unlikely(e && !err))
18227 +void au_refresh_iop(struct inode *inode, int force_getattr)
18230 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18231 + const struct inode_operations *iop
18232 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18234 + if (inode->i_op == iop)
18237 + switch (inode->i_mode & S_IFMT) {
18239 + type = AuIop_DIR;
18242 + type = AuIop_SYMLINK;
18245 + type = AuIop_OTHER;
18249 + inode->i_op = iop + type;
18250 + /* unnecessary smp_wmb() */
18253 +int au_refresh_hinode_self(struct inode *inode)
18257 + err = au_ii_refresh(inode, &update);
18259 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18265 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18267 + int err, e, update;
18268 + unsigned int flags;
18270 + aufs_bindex_t bindex, bbot;
18271 + unsigned char isdir;
18272 + struct au_hinode *p;
18273 + struct au_iinfo *iinfo;
18275 + err = au_ii_refresh(inode, &update);
18276 + if (unlikely(err))
18280 + iinfo = au_ii(inode);
18281 + p = au_hinode(iinfo, iinfo->ii_btop);
18282 + mode = (inode->i_mode & S_IFMT);
18283 + isdir = S_ISDIR(mode);
18284 + flags = au_hi_flags(inode, isdir);
18285 + bbot = au_dbbot(dentry);
18286 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18287 + struct inode *h_i, *h_inode;
18288 + struct dentry *h_d;
18290 + h_d = au_h_dptr(dentry, bindex);
18291 + if (!h_d || d_is_negative(h_d))
18294 + h_inode = d_inode(h_d);
18295 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18296 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18297 + h_i = au_h_iptr(inode, bindex);
18299 + if (h_i == h_inode)
18305 + if (bindex < iinfo->ii_btop)
18306 + iinfo->ii_btop = bindex;
18307 + if (iinfo->ii_bbot < bindex)
18308 + iinfo->ii_bbot = bindex;
18309 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18312 + au_update_ibrange(inode, /*do_put_zero*/0);
18313 + e = au_dy_irefresh(inode);
18314 + if (unlikely(e && !err))
18317 + au_refresh_hinode_attr(inode, update && isdir);
18324 +static int set_inode(struct inode *inode, struct dentry *dentry)
18327 + unsigned int flags;
18329 + aufs_bindex_t bindex, btop, btail;
18330 + unsigned char isdir;
18331 + struct dentry *h_dentry;
18332 + struct inode *h_inode;
18333 + struct au_iinfo *iinfo;
18334 + struct inode_operations *iop;
18336 + IiMustWriteLock(inode);
18340 + iop = au_sbi(inode->i_sb)->si_iop_array;
18341 + btop = au_dbtop(dentry);
18342 + h_dentry = au_h_dptr(dentry, btop);
18343 + h_inode = d_inode(h_dentry);
18344 + mode = h_inode->i_mode;
18345 + switch (mode & S_IFMT) {
18347 + btail = au_dbtail(dentry);
18348 + inode->i_op = iop + AuIop_OTHER;
18349 + inode->i_fop = &aufs_file_fop;
18350 + err = au_dy_iaop(inode, btop, h_inode);
18351 + if (unlikely(err))
18356 + btail = au_dbtaildir(dentry);
18357 + inode->i_op = iop + AuIop_DIR;
18358 + inode->i_fop = &aufs_dir_fop;
18361 + btail = au_dbtail(dentry);
18362 + inode->i_op = iop + AuIop_SYMLINK;
18368 + btail = au_dbtail(dentry);
18369 + inode->i_op = iop + AuIop_OTHER;
18370 + init_special_inode(inode, mode, h_inode->i_rdev);
18373 + AuIOErr("Unknown file type 0%o\n", mode);
18378 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18379 + flags = au_hi_flags(inode, isdir);
18380 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18381 + && au_ftest_hi(flags, HNOTIFY)
18382 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18383 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18384 + au_fclr_hi(flags, HNOTIFY);
18385 + iinfo = au_ii(inode);
18386 + iinfo->ii_btop = btop;
18387 + iinfo->ii_bbot = btail;
18388 + for (bindex = btop; bindex <= btail; bindex++) {
18389 + h_dentry = au_h_dptr(dentry, bindex);
18391 + au_set_h_iptr(inode, bindex,
18392 + au_igrab(d_inode(h_dentry)), flags);
18394 + au_cpup_attr_all(inode, /*force*/1);
18396 + * to force calling aufs_get_acl() every time,
18397 + * do not call cache_no_acl() for aufs inode.
18405 + * successful returns with iinfo write_locked
18407 + * zero: success, matched
18408 + * plus: no error, but unmatched
18410 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18413 + unsigned int gen, igflags;
18414 + aufs_bindex_t bindex, bbot;
18415 + struct inode *h_inode, *h_dinode;
18416 + struct dentry *h_dentry;
18419 + * before this function, if aufs got any iinfo lock, it must be only
18420 + * one, the parent dir.
18421 + * it can happen by UDBA and the obsoleted inode number.
18424 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18428 + ii_write_lock_new_child(inode);
18429 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18430 + h_dinode = d_inode(h_dentry);
18431 + bbot = au_ibbot(inode);
18432 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18433 + h_inode = au_h_iptr(inode, bindex);
18434 + if (!h_inode || h_inode != h_dinode)
18438 + gen = au_iigen(inode, &igflags);
18439 + if (gen == au_digen(dentry)
18440 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18443 + /* fully refresh inode using dentry */
18444 + err = au_refresh_hinode(inode, dentry);
18446 + au_update_iigen(inode, /*half*/0);
18450 + if (unlikely(err))
18451 + ii_write_unlock(inode);
18456 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18457 + unsigned int d_type, ino_t *ino)
18460 + const int isnondir = d_type != DT_DIR;
18462 + /* prevent hardlinked inode number from race condition */
18464 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18465 + if (unlikely(err))
18469 + err = au_xino_read(sb, bindex, h_ino, ino);
18470 + if (unlikely(err))
18471 + goto out_xinondir;
18475 + *ino = au_xino_new_ino(sb);
18476 + if (unlikely(!*ino))
18477 + goto out_xinondir;
18478 + err = au_xino_write(sb, bindex, h_ino, *ino);
18479 + if (unlikely(err))
18480 + goto out_xinondir;
18484 + if (isnondir && idx >= 0)
18485 + au_xinondir_leave(sb, bindex, h_ino, idx);
18490 +/* successful returns with iinfo write_locked */
18491 +/* todo: return with unlocked? */
18492 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18494 + struct inode *inode, *h_inode;
18495 + struct dentry *h_dentry;
18496 + struct super_block *sb;
18497 + ino_t h_ino, ino;
18498 + int err, idx, hlinked;
18499 + aufs_bindex_t btop;
18501 + sb = dentry->d_sb;
18502 + btop = au_dbtop(dentry);
18503 + h_dentry = au_h_dptr(dentry, btop);
18504 + h_inode = d_inode(h_dentry);
18505 + h_ino = h_inode->i_ino;
18506 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18510 + * stop 'race'-ing between hardlinks under different
18514 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18515 + inode = ERR_PTR(err);
18516 + if (unlikely(err))
18520 + err = au_xino_read(sb, btop, h_ino, &ino);
18521 + inode = ERR_PTR(err);
18522 + if (unlikely(err))
18523 + goto out_xinondir;
18526 + ino = au_xino_new_ino(sb);
18527 + if (unlikely(!ino)) {
18528 + inode = ERR_PTR(-EIO);
18529 + goto out_xinondir;
18533 + AuDbg("i%lu\n", (unsigned long)ino);
18534 + inode = au_iget_locked(sb, ino);
18535 + err = PTR_ERR(inode);
18536 + if (IS_ERR(inode))
18537 + goto out_xinondir;
18539 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18540 + if (inode->i_state & I_NEW) {
18541 + ii_write_lock_new_child(inode);
18542 + err = set_inode(inode, dentry);
18544 + unlock_new_inode(inode);
18545 + goto out_xinondir; /* success */
18549 + * iget_failed() calls iput(), but we need to call
18550 + * ii_write_unlock() after iget_failed(). so dirty hack for
18553 + atomic_inc(&inode->i_count);
18554 + iget_failed(inode);
18555 + ii_write_unlock(inode);
18556 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18557 + /* ignore this error */
18559 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18561 + * horrible race condition between lookup, readdir and copyup
18562 + * (or something).
18564 + if (hlinked && idx >= 0)
18565 + au_xinondir_leave(sb, btop, h_ino, idx);
18566 + err = reval_inode(inode, dentry);
18567 + if (unlikely(err < 0)) {
18572 + goto out; /* success */
18573 + else if (hlinked && idx >= 0) {
18574 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18575 + if (unlikely(err)) {
18577 + inode = ERR_PTR(err);
18583 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18584 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18585 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18586 + btop, au_sbtype(h_dentry->d_sb), dentry,
18587 + (unsigned long)h_ino, (unsigned long)ino);
18589 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18592 + if (hlinked && idx >= 0)
18593 + au_xinondir_leave(sb, btop, h_ino, idx);
18599 + inode = ERR_PTR(err);
18601 + if (hlinked && idx >= 0)
18602 + au_xinondir_leave(sb, btop, h_ino, idx);
18607 +/* ---------------------------------------------------------------------- */
18609 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18610 + struct inode *inode)
18613 + struct inode *hi;
18615 + err = au_br_rdonly(au_sbr(sb, bindex));
18617 + /* pseudo-link after flushed may happen out of bounds */
18620 + && au_ibtop(inode) <= bindex
18621 + && bindex <= au_ibbot(inode)) {
18623 + * permission check is unnecessary since vfsub routine
18624 + * will be called later
18626 + hi = au_h_iptr(inode, bindex);
18628 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18634 +int au_test_h_perm(struct inode *h_inode, int mask)
18636 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18638 + return inode_permission(h_inode, mask);
18641 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18643 + if (au_test_nfs(h_inode->i_sb)
18644 + && (mask & MAY_WRITE)
18645 + && S_ISDIR(h_inode->i_mode))
18646 + mask |= MAY_READ; /* force permission check */
18647 + return au_test_h_perm(h_inode, mask);
18649 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18650 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18651 +++ linux/fs/aufs/inode.h 2018-06-04 09:08:09.188079511 +0200
18654 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18656 + * This program, aufs is free software; you can redistribute it and/or modify
18657 + * it under the terms of the GNU General Public License as published by
18658 + * the Free Software Foundation; either version 2 of the License, or
18659 + * (at your option) any later version.
18661 + * This program is distributed in the hope that it will be useful,
18662 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18663 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18664 + * GNU General Public License for more details.
18666 + * You should have received a copy of the GNU General Public License
18667 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18671 + * inode operations
18674 +#ifndef __AUFS_INODE_H__
18675 +#define __AUFS_INODE_H__
18679 +#include <linux/fsnotify.h>
18680 +#include "rwsem.h"
18684 +struct au_hnotify {
18685 +#ifdef CONFIG_AUFS_HNOTIFY
18686 +#ifdef CONFIG_AUFS_HFSNOTIFY
18687 + /* never use fsnotify_add_vfsmount_mark() */
18688 + struct fsnotify_mark hn_mark;
18690 + struct inode *hn_aufs_inode; /* no get/put */
18692 +} ____cacheline_aligned_in_smp;
18694 +struct au_hinode {
18695 + struct inode *hi_inode;
18696 + aufs_bindex_t hi_id;
18697 +#ifdef CONFIG_AUFS_HNOTIFY
18698 + struct au_hnotify *hi_notify;
18701 + /* reference to the copied-up whiteout with get/put */
18702 + struct dentry *hi_whdentry;
18706 +#define AuIG_HALF_REFRESHED 1
18707 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18708 +#define au_ig_fset(flags, name) \
18709 + do { (flags) |= AuIG_##name; } while (0)
18710 +#define au_ig_fclr(flags, name) \
18711 + do { (flags) &= ~AuIG_##name; } while (0)
18714 + spinlock_t ig_spin;
18715 + __u32 ig_generation, ig_flags;
18720 + struct au_iigen ii_generation;
18721 + struct super_block *ii_hsb1; /* no get/put */
18723 + struct au_rwsem ii_rwsem;
18724 + aufs_bindex_t ii_btop, ii_bbot;
18726 + struct au_hinode *ii_hinode;
18727 + struct au_vdir *ii_vdir;
18730 +struct au_icntnr {
18731 + struct au_iinfo iinfo;
18732 + struct inode vfs_inode;
18733 + struct hlist_bl_node plink;
18734 +} ____cacheline_aligned_in_smp;
18736 +/* au_pin flags */
18737 +#define AuPin_DI_LOCKED 1
18738 +#define AuPin_MNT_WRITE (1 << 1)
18739 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18740 +#define au_fset_pin(flags, name) \
18741 + do { (flags) |= AuPin_##name; } while (0)
18742 +#define au_fclr_pin(flags, name) \
18743 + do { (flags) &= ~AuPin_##name; } while (0)
18747 + struct dentry *dentry;
18748 + unsigned int udba;
18749 + unsigned char lsc_di, lsc_hi, flags;
18750 + aufs_bindex_t bindex;
18753 + struct dentry *parent;
18754 + struct au_hinode *hdir;
18755 + struct vfsmount *h_mnt;
18757 + /* temporary unlock/relock for copyup */
18758 + struct dentry *h_dentry, *h_parent;
18759 + struct au_branch *br;
18760 + struct task_struct *task;
18763 +void au_pin_hdir_unlock(struct au_pin *p);
18764 +int au_pin_hdir_lock(struct au_pin *p);
18765 +int au_pin_hdir_relock(struct au_pin *p);
18766 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18767 +void au_pin_hdir_release(struct au_pin *p);
18769 +/* ---------------------------------------------------------------------- */
18771 +static inline struct au_iinfo *au_ii(struct inode *inode)
18773 + BUG_ON(is_bad_inode(inode));
18774 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18777 +/* ---------------------------------------------------------------------- */
18780 +struct inode *au_igrab(struct inode *inode);
18781 +void au_refresh_iop(struct inode *inode, int force_getattr);
18782 +int au_refresh_hinode_self(struct inode *inode);
18783 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18784 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18785 + unsigned int d_type, ino_t *ino);
18786 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18787 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18788 + struct inode *inode);
18789 +int au_test_h_perm(struct inode *h_inode, int mask);
18790 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18792 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18793 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18795 +#ifdef CONFIG_AUFS_SHWH
18796 + return au_ino(sb, bindex, h_ino, d_type, ino);
18809 +extern struct inode_operations aufs_iop[AuIop_Last],
18810 + aufs_iop_nogetattr[AuIop_Last];
18812 +/* au_wr_dir flags */
18813 +#define AuWrDir_ADD_ENTRY 1
18814 +#define AuWrDir_ISDIR (1 << 1)
18815 +#define AuWrDir_TMPFILE (1 << 2)
18816 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18817 +#define au_fset_wrdir(flags, name) \
18818 + do { (flags) |= AuWrDir_##name; } while (0)
18819 +#define au_fclr_wrdir(flags, name) \
18820 + do { (flags) &= ~AuWrDir_##name; } while (0)
18822 +struct au_wr_dir_args {
18823 + aufs_bindex_t force_btgt;
18824 + unsigned char flags;
18826 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18827 + struct au_wr_dir_args *args);
18829 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18830 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18831 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18832 + unsigned int udba, unsigned char flags);
18833 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18834 + unsigned int udba, unsigned char flags) __must_check;
18835 +int au_do_pin(struct au_pin *pin) __must_check;
18836 +void au_unpin(struct au_pin *pin);
18837 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18839 +#define AuIcpup_DID_CPUP 1
18840 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18841 +#define au_fset_icpup(flags, name) \
18842 + do { (flags) |= AuIcpup_##name; } while (0)
18843 +#define au_fclr_icpup(flags, name) \
18844 + do { (flags) &= ~AuIcpup_##name; } while (0)
18846 +struct au_icpup_args {
18847 + unsigned char flags;
18848 + unsigned char pin_flags;
18849 + aufs_bindex_t btgt;
18850 + unsigned int udba;
18851 + struct au_pin pin;
18852 + struct path h_path;
18853 + struct inode *h_inode;
18856 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18857 + struct au_icpup_args *a);
18859 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18863 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18864 + struct dentry *h_parent, int isdir);
18865 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18867 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18868 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18870 +struct vfsub_aopen_args;
18871 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18872 + struct vfsub_aopen_args *args);
18873 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18874 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18875 + struct dentry *dentry);
18876 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18879 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18880 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18881 + struct dentry *h_parent, int isdir);
18882 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18883 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18886 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18887 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18888 + struct inode *dir, struct dentry *dentry,
18889 + unsigned int flags);
18892 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18893 +void au_hiput(struct au_hinode *hinode);
18894 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18895 + struct dentry *h_wh);
18896 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18898 +/* hinode flags */
18899 +#define AuHi_XINO 1
18900 +#define AuHi_HNOTIFY (1 << 1)
18901 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18902 +#define au_fset_hi(flags, name) \
18903 + do { (flags) |= AuHi_##name; } while (0)
18904 +#define au_fclr_hi(flags, name) \
18905 + do { (flags) &= ~AuHi_##name; } while (0)
18907 +#ifndef CONFIG_AUFS_HNOTIFY
18908 +#undef AuHi_HNOTIFY
18909 +#define AuHi_HNOTIFY 0
18912 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18913 + struct inode *h_inode, unsigned int flags);
18915 +void au_update_iigen(struct inode *inode, int half);
18916 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18918 +void au_icntnr_init_once(void *_c);
18919 +void au_hinode_init(struct au_hinode *hinode);
18920 +int au_iinfo_init(struct inode *inode);
18921 +void au_iinfo_fin(struct inode *inode);
18922 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18924 +#ifdef CONFIG_PROC_FS
18926 +int au_plink_maint(struct super_block *sb, int flags);
18928 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18929 +int au_plink_maint_enter(struct super_block *sb);
18930 +#ifdef CONFIG_AUFS_DEBUG
18931 +void au_plink_list(struct super_block *sb);
18933 +AuStubVoid(au_plink_list, struct super_block *sb)
18935 +int au_plink_test(struct inode *inode);
18936 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18937 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18938 + struct dentry *h_dentry);
18939 +void au_plink_put(struct super_block *sb, int verbose);
18940 +void au_plink_clean(struct super_block *sb, int verbose);
18941 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18943 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18944 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18945 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18946 +AuStubVoid(au_plink_list, struct super_block *sb);
18947 +AuStubInt0(au_plink_test, struct inode *inode);
18948 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18949 + struct inode *inode, aufs_bindex_t bindex);
18950 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18951 + struct dentry *h_dentry);
18952 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18953 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18954 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18955 +#endif /* CONFIG_PROC_FS */
18957 +#ifdef CONFIG_AUFS_XATTR
18959 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18960 + unsigned int verbose);
18961 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18962 +void au_xattr_init(struct super_block *sb);
18964 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18965 + int ignore_flags, unsigned int verbose);
18966 +AuStubVoid(au_xattr_init, struct super_block *sb);
18969 +#ifdef CONFIG_FS_POSIX_ACL
18970 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18971 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18974 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18980 +struct au_sxattr {
18984 + const char *name;
18985 + const void *value;
18990 + struct posix_acl *acl;
18995 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18996 + struct au_sxattr *arg);
18999 +/* ---------------------------------------------------------------------- */
19001 +/* lock subclass for iinfo */
19003 + AuLsc_II_CHILD, /* child first */
19004 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19005 + AuLsc_II_CHILD3, /* copyup dirs */
19006 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19007 + AuLsc_II_PARENT2,
19008 + AuLsc_II_PARENT3, /* copyup dirs */
19009 + AuLsc_II_NEW_CHILD
19013 + * ii_read_lock_child, ii_write_lock_child,
19014 + * ii_read_lock_child2, ii_write_lock_child2,
19015 + * ii_read_lock_child3, ii_write_lock_child3,
19016 + * ii_read_lock_parent, ii_write_lock_parent,
19017 + * ii_read_lock_parent2, ii_write_lock_parent2,
19018 + * ii_read_lock_parent3, ii_write_lock_parent3,
19019 + * ii_read_lock_new_child, ii_write_lock_new_child,
19021 +#define AuReadLockFunc(name, lsc) \
19022 +static inline void ii_read_lock_##name(struct inode *i) \
19024 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19027 +#define AuWriteLockFunc(name, lsc) \
19028 +static inline void ii_write_lock_##name(struct inode *i) \
19030 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19033 +#define AuRWLockFuncs(name, lsc) \
19034 + AuReadLockFunc(name, lsc) \
19035 + AuWriteLockFunc(name, lsc)
19037 +AuRWLockFuncs(child, CHILD);
19038 +AuRWLockFuncs(child2, CHILD2);
19039 +AuRWLockFuncs(child3, CHILD3);
19040 +AuRWLockFuncs(parent, PARENT);
19041 +AuRWLockFuncs(parent2, PARENT2);
19042 +AuRWLockFuncs(parent3, PARENT3);
19043 +AuRWLockFuncs(new_child, NEW_CHILD);
19045 +#undef AuReadLockFunc
19046 +#undef AuWriteLockFunc
19047 +#undef AuRWLockFuncs
19049 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19050 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19051 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19053 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19054 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19055 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19057 +/* ---------------------------------------------------------------------- */
19059 +static inline void au_icntnr_init(struct au_icntnr *c)
19061 +#ifdef CONFIG_AUFS_DEBUG
19062 + c->vfs_inode.i_mode = 0;
19066 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19068 + unsigned int gen;
19069 + struct au_iinfo *iinfo;
19070 + struct au_iigen *iigen;
19072 + iinfo = au_ii(inode);
19073 + iigen = &iinfo->ii_generation;
19074 + spin_lock(&iigen->ig_spin);
19076 + *igflags = iigen->ig_flags;
19077 + gen = iigen->ig_generation;
19078 + spin_unlock(&iigen->ig_spin);
19083 +/* tiny test for inode number */
19084 +/* tmpfs generation is too rough */
19085 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19087 + struct au_iinfo *iinfo;
19089 + iinfo = au_ii(inode);
19090 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19091 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19092 + && iinfo->ii_higen == h_inode->i_generation);
19095 +static inline void au_iigen_dec(struct inode *inode)
19097 + struct au_iinfo *iinfo;
19098 + struct au_iigen *iigen;
19100 + iinfo = au_ii(inode);
19101 + iigen = &iinfo->ii_generation;
19102 + spin_lock(&iigen->ig_spin);
19103 + iigen->ig_generation--;
19104 + spin_unlock(&iigen->ig_spin);
19107 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19112 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19118 +/* ---------------------------------------------------------------------- */
19120 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19121 + aufs_bindex_t bindex)
19123 + return iinfo->ii_hinode + bindex;
19126 +static inline int au_is_bad_inode(struct inode *inode)
19128 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19131 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19132 + aufs_bindex_t bindex)
19134 + IiMustAnyLock(inode);
19135 + return au_hinode(au_ii(inode), bindex)->hi_id;
19138 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19140 + IiMustAnyLock(inode);
19141 + return au_ii(inode)->ii_btop;
19144 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19146 + IiMustAnyLock(inode);
19147 + return au_ii(inode)->ii_bbot;
19150 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19152 + IiMustAnyLock(inode);
19153 + return au_ii(inode)->ii_vdir;
19156 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19158 + IiMustAnyLock(inode);
19159 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19162 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19164 + IiMustWriteLock(inode);
19165 + au_ii(inode)->ii_btop = bindex;
19168 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19170 + IiMustWriteLock(inode);
19171 + au_ii(inode)->ii_bbot = bindex;
19174 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19176 + IiMustWriteLock(inode);
19177 + au_ii(inode)->ii_vdir = vdir;
19180 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19182 + IiMustAnyLock(inode);
19183 + return au_hinode(au_ii(inode), bindex);
19186 +/* ---------------------------------------------------------------------- */
19188 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19191 + return pin->parent;
19195 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19197 + if (pin && pin->hdir)
19198 + return pin->hdir->hi_inode;
19202 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19205 + return pin->hdir;
19209 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19212 + pin->dentry = dentry;
19215 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19216 + unsigned char lflag)
19220 + au_fset_pin(pin->flags, DI_LOCKED);
19222 + au_fclr_pin(pin->flags, DI_LOCKED);
19226 +#if 0 /* reserved */
19227 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19230 + dput(pin->parent);
19231 + pin->parent = dget(parent);
19236 +/* ---------------------------------------------------------------------- */
19239 +#ifdef CONFIG_AUFS_HNOTIFY
19240 +struct au_hnotify_op {
19241 + void (*ctl)(struct au_hinode *hinode, int do_set);
19242 + int (*alloc)(struct au_hinode *hinode);
19245 + * if it returns true, the the caller should free hinode->hi_notify,
19246 + * otherwise ->free() frees it.
19248 + int (*free)(struct au_hinode *hinode,
19249 + struct au_hnotify *hn) __must_check;
19251 + void (*fin)(void);
19252 + int (*init)(void);
19254 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19255 + void (*fin_br)(struct au_branch *br);
19256 + int (*init_br)(struct au_branch *br, int perm);
19260 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19261 +void au_hn_free(struct au_hinode *hinode);
19262 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19263 +void au_hn_reset(struct inode *inode, unsigned int flags);
19264 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19265 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19266 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19267 +int au_hnotify_init_br(struct au_branch *br, int perm);
19268 +void au_hnotify_fin_br(struct au_branch *br);
19269 +int __init au_hnotify_init(void);
19270 +void au_hnotify_fin(void);
19273 +extern const struct au_hnotify_op au_hnotify_op;
19276 +void au_hn_init(struct au_hinode *hinode)
19278 + hinode->hi_notify = NULL;
19281 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19283 + return hinode->hi_notify;
19287 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19288 + struct au_hinode *hinode __maybe_unused,
19289 + struct inode *inode __maybe_unused)
19290 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19291 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19292 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19293 + int do_set __maybe_unused)
19294 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19295 + unsigned int flags __maybe_unused)
19296 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19297 + struct au_branch *br __maybe_unused,
19298 + int perm __maybe_unused)
19299 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19300 + int perm __maybe_unused)
19301 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19302 +AuStubInt0(__init au_hnotify_init, void)
19303 +AuStubVoid(au_hnotify_fin, void)
19304 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19305 +#endif /* CONFIG_AUFS_HNOTIFY */
19307 +static inline void au_hn_suspend(struct au_hinode *hdir)
19309 + au_hn_ctl(hdir, /*do_set*/0);
19312 +static inline void au_hn_resume(struct au_hinode *hdir)
19314 + au_hn_ctl(hdir, /*do_set*/1);
19317 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19319 + inode_lock(hdir->hi_inode);
19320 + au_hn_suspend(hdir);
19323 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19324 + unsigned int sc __maybe_unused)
19326 + inode_lock_nested(hdir->hi_inode, sc);
19327 + au_hn_suspend(hdir);
19330 +#if 0 /* unused */
19331 +#include "vfsub.h"
19332 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19335 + inode_lock_shared_nested(hdir->hi_inode, sc);
19336 + au_hn_suspend(hdir);
19340 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19342 + au_hn_resume(hdir);
19343 + inode_unlock(hdir->hi_inode);
19346 +#endif /* __KERNEL__ */
19347 +#endif /* __AUFS_INODE_H__ */
19348 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19349 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19350 +++ linux/fs/aufs/ioctl.c 2018-04-15 08:49:13.401150731 +0200
19353 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19355 + * This program, aufs is free software; you can redistribute it and/or modify
19356 + * it under the terms of the GNU General Public License as published by
19357 + * the Free Software Foundation; either version 2 of the License, or
19358 + * (at your option) any later version.
19360 + * This program is distributed in the hope that it will be useful,
19361 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19362 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19363 + * GNU General Public License for more details.
19365 + * You should have received a copy of the GNU General Public License
19366 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19371 + * plink-management and readdir in userspace.
19372 + * assist the pathconf(3) wrapper library.
19374 + * File-based Hierarchical Storage Management.
19377 +#include <linux/compat.h>
19378 +#include <linux/file.h>
19381 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19384 + aufs_bindex_t wbi, bindex, bbot;
19385 + struct file *h_file;
19386 + struct super_block *sb;
19387 + struct dentry *root;
19388 + struct au_branch *br;
19389 + struct aufs_wbr_fd wbrfd = {
19390 + .oflags = au_dir_roflags,
19393 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19394 + | O_NOATIME | O_CLOEXEC;
19396 + AuDebugOn(wbrfd.oflags & ~valid);
19399 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19400 + if (unlikely(err)) {
19406 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19407 + wbrfd.oflags |= au_dir_roflags;
19408 + AuDbg("0%o\n", wbrfd.oflags);
19409 + if (unlikely(wbrfd.oflags & ~valid))
19413 + fd = get_unused_fd_flags(0);
19415 + if (unlikely(fd < 0))
19418 + h_file = ERR_PTR(-EINVAL);
19421 + sb = path->dentry->d_sb;
19422 + root = sb->s_root;
19423 + aufs_read_lock(root, AuLock_IR);
19424 + bbot = au_sbbot(sb);
19425 + if (wbrfd.brid >= 0) {
19426 + wbi = au_br_index(sb, wbrfd.brid);
19427 + if (unlikely(wbi < 0 || wbi > bbot))
19431 + h_file = ERR_PTR(-ENOENT);
19432 + br = au_sbr(sb, wbi);
19433 + if (!au_br_writable(br->br_perm)) {
19437 + bindex = wbi + 1;
19439 + for (; bindex <= bbot; bindex++) {
19440 + br = au_sbr(sb, bindex);
19441 + if (au_br_writable(br->br_perm)) {
19443 + br = au_sbr(sb, wbi);
19448 + AuDbg("wbi %d\n", wbi);
19450 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19454 + aufs_read_unlock(root, AuLock_IR);
19455 + err = PTR_ERR(h_file);
19456 + if (IS_ERR(h_file))
19459 + au_br_put(br); /* cf. au_h_open() */
19460 + fd_install(fd, h_file);
19462 + goto out; /* success */
19465 + put_unused_fd(fd);
19471 +/* ---------------------------------------------------------------------- */
19473 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19476 + struct dentry *dentry;
19479 + case AUFS_CTL_RDU:
19480 + case AUFS_CTL_RDU_INO:
19481 + err = au_rdu_ioctl(file, cmd, arg);
19484 + case AUFS_CTL_WBR_FD:
19485 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19488 + case AUFS_CTL_IBUSY:
19489 + err = au_ibusy_ioctl(file, arg);
19492 + case AUFS_CTL_BRINFO:
19493 + err = au_brinfo_ioctl(file, arg);
19496 + case AUFS_CTL_FHSM_FD:
19497 + dentry = file->f_path.dentry;
19498 + if (IS_ROOT(dentry))
19499 + err = au_fhsm_fd(dentry->d_sb, arg);
19505 + /* do not call the lower */
19506 + AuDbg("0x%x\n", cmd);
19514 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19519 + case AUFS_CTL_MVDOWN:
19520 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19523 + case AUFS_CTL_WBR_FD:
19524 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19528 + /* do not call the lower */
19529 + AuDbg("0x%x\n", cmd);
19537 +#ifdef CONFIG_COMPAT
19538 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19539 + unsigned long arg)
19544 + case AUFS_CTL_RDU:
19545 + case AUFS_CTL_RDU_INO:
19546 + err = au_rdu_compat_ioctl(file, cmd, arg);
19549 + case AUFS_CTL_IBUSY:
19550 + err = au_ibusy_compat_ioctl(file, arg);
19553 + case AUFS_CTL_BRINFO:
19554 + err = au_brinfo_compat_ioctl(file, arg);
19558 + err = aufs_ioctl_dir(file, cmd, arg);
19565 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19566 + unsigned long arg)
19568 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19571 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19572 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19573 +++ linux/fs/aufs/i_op_add.c 2018-06-04 09:08:09.184746078 +0200
19576 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19578 + * This program, aufs is free software; you can redistribute it and/or modify
19579 + * it under the terms of the GNU General Public License as published by
19580 + * the Free Software Foundation; either version 2 of the License, or
19581 + * (at your option) any later version.
19583 + * This program is distributed in the hope that it will be useful,
19584 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19585 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19586 + * GNU General Public License for more details.
19588 + * You should have received a copy of the GNU General Public License
19589 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19593 + * inode operations (add entry)
19599 + * final procedure of adding a new entry, except link(2).
19600 + * remove whiteout, instantiate, copyup the parent dir's times and size
19601 + * and update version.
19602 + * if it failed, re-create the removed whiteout.
19604 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19605 + struct dentry *wh_dentry, struct dentry *dentry)
19608 + aufs_bindex_t bwh;
19609 + struct path h_path;
19610 + struct super_block *sb;
19611 + struct inode *inode, *h_dir;
19612 + struct dentry *wh;
19617 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19618 + IMustLock(h_dir);
19619 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19620 + bwh = au_dbwh(dentry);
19621 + h_path.dentry = wh_dentry;
19622 + h_path.mnt = au_sbr_mnt(sb, bindex);
19623 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19625 + if (unlikely(err))
19629 + inode = au_new_inode(dentry, /*must_new*/1);
19630 + if (!IS_ERR(inode)) {
19631 + d_instantiate(dentry, inode);
19632 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19634 + au_dir_ts(dir, bindex);
19635 + inode_inc_iversion(dir);
19636 + au_fhsm_wrote(sb, bindex, /*force*/0);
19637 + return 0; /* success */
19640 + err = PTR_ERR(inode);
19645 + /* dir inode is locked */
19646 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19647 + rerr = PTR_ERR(wh);
19648 + if (IS_ERR(wh)) {
19649 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19650 + dentry, err, rerr);
19659 +static int au_d_may_add(struct dentry *dentry)
19664 + if (unlikely(d_unhashed(dentry)))
19666 + if (unlikely(d_really_is_positive(dentry)))
19672 + * simple tests for the adding inode operations.
19673 + * following the checks in vfs, plus the parent-child relationship.
19675 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19676 + struct dentry *h_parent, int isdir)
19680 + struct dentry *h_dentry;
19681 + struct inode *h_inode;
19683 + err = -ENAMETOOLONG;
19684 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19687 + h_dentry = au_h_dptr(dentry, bindex);
19688 + if (d_really_is_negative(dentry)) {
19690 + if (unlikely(d_is_positive(h_dentry)))
19693 + /* rename(2) case */
19695 + if (unlikely(d_is_negative(h_dentry)))
19697 + h_inode = d_inode(h_dentry);
19698 + if (unlikely(!h_inode->i_nlink))
19701 + h_mode = h_inode->i_mode;
19704 + if (unlikely(S_ISDIR(h_mode)))
19706 + } else if (unlikely(!S_ISDIR(h_mode))) {
19713 + /* expected parent dir is locked */
19714 + if (unlikely(h_parent != h_dentry->d_parent))
19723 + * initial procedure of adding a new entry.
19724 + * prepare writable branch and the parent dir, lock it,
19725 + * and lookup whiteout for the new entry.
19727 +static struct dentry*
19728 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19729 + struct dentry *src_dentry, struct au_pin *pin,
19730 + struct au_wr_dir_args *wr_dir_args)
19732 + struct dentry *wh_dentry, *h_parent;
19733 + struct super_block *sb;
19734 + struct au_branch *br;
19736 + unsigned int udba;
19737 + aufs_bindex_t bcpup;
19739 + AuDbg("%pd\n", dentry);
19741 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19743 + wh_dentry = ERR_PTR(err);
19744 + if (unlikely(err < 0))
19747 + sb = dentry->d_sb;
19748 + udba = au_opt_udba(sb);
19749 + err = au_pin(pin, dentry, bcpup, udba,
19750 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19751 + wh_dentry = ERR_PTR(err);
19752 + if (unlikely(err))
19755 + h_parent = au_pinned_h_parent(pin);
19756 + if (udba != AuOpt_UDBA_NONE
19757 + && au_dbtop(dentry) == bcpup)
19758 + err = au_may_add(dentry, bcpup, h_parent,
19759 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19760 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19761 + err = -ENAMETOOLONG;
19762 + wh_dentry = ERR_PTR(err);
19763 + if (unlikely(err))
19766 + br = au_sbr(sb, bcpup);
19768 + struct path tmp = {
19769 + .dentry = h_parent,
19770 + .mnt = au_br_mnt(br)
19772 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19775 + wh_dentry = NULL;
19776 + if (bcpup != au_dbwh(dentry))
19777 + goto out; /* success */
19780 + * ENAMETOOLONG here means that if we allowed create such name, then it
19781 + * would not be able to removed in the future. So we don't allow such
19782 + * name here and we don't handle ENAMETOOLONG differently here.
19784 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19787 + if (IS_ERR(wh_dentry))
19790 + return wh_dentry;
19793 +/* ---------------------------------------------------------------------- */
19795 +enum { Mknod, Symlink, Creat };
19796 +struct simple_arg {
19803 + struct vfsub_aopen_args *aopen;
19806 + const char *symname;
19815 +static int add_simple(struct inode *dir, struct dentry *dentry,
19816 + struct simple_arg *arg)
19819 + aufs_bindex_t btop;
19820 + unsigned char created;
19821 + const unsigned char try_aopen
19822 + = (arg->type == Creat && arg->u.c.try_aopen);
19823 + struct dentry *wh_dentry, *parent;
19824 + struct inode *h_dir;
19825 + struct super_block *sb;
19826 + struct au_branch *br;
19827 + /* to reuduce stack size */
19829 + struct au_dtime dt;
19830 + struct au_pin pin;
19831 + struct path h_path;
19832 + struct au_wr_dir_args wr_dir_args;
19835 + AuDbg("%pd\n", dentry);
19839 + a = kmalloc(sizeof(*a), GFP_NOFS);
19840 + if (unlikely(!a))
19842 + a->wr_dir_args.force_btgt = -1;
19843 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19845 + parent = dentry->d_parent; /* dir inode is locked */
19846 + if (!try_aopen) {
19847 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19848 + if (unlikely(err))
19851 + err = au_d_may_add(dentry);
19852 + if (unlikely(err))
19855 + di_write_lock_parent(parent);
19856 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19857 + &a->pin, &a->wr_dir_args);
19858 + err = PTR_ERR(wh_dentry);
19859 + if (IS_ERR(wh_dentry))
19862 + btop = au_dbtop(dentry);
19863 + sb = dentry->d_sb;
19864 + br = au_sbr(sb, btop);
19865 + a->h_path.dentry = au_h_dptr(dentry, btop);
19866 + a->h_path.mnt = au_br_mnt(br);
19867 + h_dir = au_pinned_h_dir(&a->pin);
19868 + switch (arg->type) {
19871 + if (!try_aopen || !h_dir->i_op->atomic_open)
19872 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19873 + arg->u.c.want_excl);
19875 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
19876 + arg->u.c.aopen, br);
19879 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19882 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19890 + err = epilog(dir, btop, wh_dentry, dentry);
19893 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
19894 + /* no delegation since it is just created */
19895 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19898 + AuIOErr("%pd revert failure(%d, %d)\n",
19899 + dentry, err, rerr);
19902 + au_dtime_revert(&a->dt);
19905 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
19906 + *arg->u.c.aopen->opened |= FILE_CREATED;
19908 + au_unpin(&a->pin);
19913 + di_write_unlock(parent);
19915 + if (unlikely(err)) {
19916 + au_update_dbtop(dentry);
19920 + aufs_read_unlock(dentry, AuLock_DW);
19927 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19930 + struct simple_arg arg = {
19937 + return add_simple(dir, dentry, &arg);
19940 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19942 + struct simple_arg arg = {
19944 + .u.s.symname = symname
19946 + return add_simple(dir, dentry, &arg);
19949 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19952 + struct simple_arg arg = {
19956 + .want_excl = want_excl
19959 + return add_simple(dir, dentry, &arg);
19962 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19963 + struct vfsub_aopen_args *aopen_args)
19965 + struct simple_arg arg = {
19968 + .mode = aopen_args->create_mode,
19969 + .want_excl = aopen_args->open_flag & O_EXCL,
19970 + .try_aopen = true,
19971 + .aopen = aopen_args
19974 + return add_simple(dir, dentry, &arg);
19977 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19980 + aufs_bindex_t bindex;
19981 + struct super_block *sb;
19982 + struct dentry *parent, *h_parent, *h_dentry;
19983 + struct inode *h_dir, *inode;
19984 + struct vfsmount *h_mnt;
19985 + struct au_wr_dir_args wr_dir_args = {
19986 + .force_btgt = -1,
19987 + .flags = AuWrDir_TMPFILE
19990 + /* copy-up may happen */
19994 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19995 + if (unlikely(err))
19998 + err = au_di_init(dentry);
19999 + if (unlikely(err))
20003 + parent = d_find_any_alias(dir);
20004 + AuDebugOn(!parent);
20005 + di_write_lock_parent(parent);
20006 + if (unlikely(d_inode(parent) != dir))
20009 + err = au_digen_test(parent, au_sigen(sb));
20010 + if (unlikely(err))
20013 + bindex = au_dbtop(parent);
20014 + au_set_dbtop(dentry, bindex);
20015 + au_set_dbbot(dentry, bindex);
20016 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20018 + if (unlikely(err < 0))
20021 + err = -EOPNOTSUPP;
20022 + h_dir = au_h_iptr(dir, bindex);
20023 + if (unlikely(!h_dir->i_op->tmpfile))
20026 + h_mnt = au_sbr_mnt(sb, bindex);
20027 + err = vfsub_mnt_want_write(h_mnt);
20028 + if (unlikely(err))
20031 + h_parent = au_h_dptr(parent, bindex);
20032 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20033 + if (IS_ERR(h_dentry)) {
20034 + err = PTR_ERR(h_dentry);
20038 + au_set_dbtop(dentry, bindex);
20039 + au_set_dbbot(dentry, bindex);
20040 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20041 + inode = au_new_inode(dentry, /*must_new*/1);
20042 + if (IS_ERR(inode)) {
20043 + err = PTR_ERR(inode);
20044 + au_set_h_dptr(dentry, bindex, NULL);
20045 + au_set_dbtop(dentry, -1);
20046 + au_set_dbbot(dentry, -1);
20048 + if (!inode->i_nlink)
20049 + set_nlink(inode, 1);
20050 + d_tmpfile(dentry, inode);
20051 + au_di(dentry)->di_tmpfile = 1;
20053 + /* update without i_mutex */
20054 + if (au_ibtop(dir) == au_dbtop(dentry))
20055 + au_cpup_attr_timesizes(dir);
20060 + vfsub_mnt_drop_write(h_mnt);
20062 + di_write_unlock(parent);
20064 + di_write_unlock(dentry);
20065 + if (unlikely(err)) {
20066 + au_di_fin(dentry);
20067 + dentry->d_fsdata = NULL;
20070 + si_read_unlock(sb);
20072 + inode_unlock(dir);
20076 +/* ---------------------------------------------------------------------- */
20078 +struct au_link_args {
20079 + aufs_bindex_t bdst, bsrc;
20080 + struct au_pin pin;
20081 + struct path h_path;
20082 + struct dentry *src_parent, *parent;
20085 +static int au_cpup_before_link(struct dentry *src_dentry,
20086 + struct au_link_args *a)
20089 + struct dentry *h_src_dentry;
20090 + struct au_cp_generic cpg = {
20091 + .dentry = src_dentry,
20096 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20099 + di_read_lock_parent(a->src_parent, AuLock_IR);
20100 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20101 + if (unlikely(err))
20104 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20105 + err = au_pin(&a->pin, src_dentry, a->bdst,
20106 + au_opt_udba(src_dentry->d_sb),
20107 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20108 + if (unlikely(err))
20111 + err = au_sio_cpup_simple(&cpg);
20112 + au_unpin(&a->pin);
20115 + di_read_unlock(a->src_parent, AuLock_IR);
20119 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20120 + struct au_link_args *a)
20123 + unsigned char plink;
20124 + aufs_bindex_t bbot;
20125 + struct dentry *h_src_dentry;
20126 + struct inode *h_inode, *inode, *delegated;
20127 + struct super_block *sb;
20128 + struct file *h_file;
20132 + sb = src_dentry->d_sb;
20133 + inode = d_inode(src_dentry);
20134 + if (au_ibtop(inode) <= a->bdst)
20135 + h_inode = au_h_iptr(inode, a->bdst);
20136 + if (!h_inode || !h_inode->i_nlink) {
20137 + /* copyup src_dentry as the name of dentry. */
20138 + bbot = au_dbbot(dentry);
20139 + if (bbot < a->bsrc)
20140 + au_set_dbbot(dentry, a->bsrc);
20141 + au_set_h_dptr(dentry, a->bsrc,
20142 + dget(au_h_dptr(src_dentry, a->bsrc)));
20143 + dget(a->h_path.dentry);
20144 + au_set_h_dptr(dentry, a->bdst, NULL);
20145 + AuDbg("temporary d_inode...\n");
20146 + spin_lock(&dentry->d_lock);
20147 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20148 + spin_unlock(&dentry->d_lock);
20149 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20150 + if (IS_ERR(h_file))
20151 + err = PTR_ERR(h_file);
20153 + struct au_cp_generic cpg = {
20154 + .dentry = dentry,
20159 + .flags = AuCpup_KEEPLINO
20161 + err = au_sio_cpup_simple(&cpg);
20162 + au_h_open_post(dentry, a->bsrc, h_file);
20164 + dput(a->h_path.dentry);
20165 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20167 + au_set_h_dptr(dentry, a->bdst,
20168 + a->h_path.dentry);
20170 + spin_lock(&dentry->d_lock);
20171 + dentry->d_inode = NULL; /* restore */
20172 + spin_unlock(&dentry->d_lock);
20173 + AuDbg("temporary d_inode...done\n");
20174 + au_set_h_dptr(dentry, a->bsrc, NULL);
20175 + au_set_dbbot(dentry, bbot);
20177 + /* the inode of src_dentry already exists on a.bdst branch */
20178 + h_src_dentry = d_find_alias(h_inode);
20179 + if (!h_src_dentry && au_plink_test(inode)) {
20181 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20182 + err = PTR_ERR(h_src_dentry);
20183 + if (IS_ERR(h_src_dentry))
20186 + if (unlikely(d_is_negative(h_src_dentry))) {
20187 + dput(h_src_dentry);
20188 + h_src_dentry = NULL;
20192 + if (h_src_dentry) {
20193 + delegated = NULL;
20194 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20195 + &a->h_path, &delegated);
20196 + if (unlikely(err == -EWOULDBLOCK)) {
20197 + pr_warn("cannot retry for NFSv4 delegation"
20198 + " for an internal link\n");
20201 + dput(h_src_dentry);
20203 + AuIOErr("no dentry found for hi%lu on b%d\n",
20204 + h_inode->i_ino, a->bdst);
20209 + if (!err && !plink)
20210 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20217 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20218 + struct dentry *dentry)
20221 + struct au_dtime dt;
20222 + struct au_link_args *a;
20223 + struct dentry *wh_dentry, *h_src_dentry;
20224 + struct inode *inode, *delegated;
20225 + struct super_block *sb;
20226 + struct au_wr_dir_args wr_dir_args = {
20227 + /* .force_btgt = -1, */
20228 + .flags = AuWrDir_ADD_ENTRY
20232 + inode = d_inode(src_dentry);
20233 + IMustLock(inode);
20236 + a = kzalloc(sizeof(*a), GFP_NOFS);
20237 + if (unlikely(!a))
20240 + a->parent = dentry->d_parent; /* dir inode is locked */
20241 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20242 + AuLock_NOPLM | AuLock_GEN);
20243 + if (unlikely(err))
20245 + err = au_d_linkable(src_dentry);
20246 + if (unlikely(err))
20248 + err = au_d_may_add(dentry);
20249 + if (unlikely(err))
20252 + a->src_parent = dget_parent(src_dentry);
20253 + wr_dir_args.force_btgt = au_ibtop(inode);
20255 + di_write_lock_parent(a->parent);
20256 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20257 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20259 + err = PTR_ERR(wh_dentry);
20260 + if (IS_ERR(wh_dentry))
20264 + sb = dentry->d_sb;
20265 + a->bdst = au_dbtop(dentry);
20266 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20267 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20268 + a->bsrc = au_ibtop(inode);
20269 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20270 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20271 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20272 + if (!h_src_dentry) {
20273 + a->bsrc = au_dbtop(src_dentry);
20274 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20275 + AuDebugOn(!h_src_dentry);
20276 + } else if (IS_ERR(h_src_dentry)) {
20277 + err = PTR_ERR(h_src_dentry);
20282 + * aufs doesn't touch the credential so
20283 + * security_dentry_create_files_as() is unnecrssary.
20285 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20286 + if (a->bdst < a->bsrc
20287 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20288 + err = au_cpup_or_link(src_dentry, dentry, a);
20290 + delegated = NULL;
20291 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20292 + &a->h_path, &delegated);
20293 + if (unlikely(err == -EWOULDBLOCK)) {
20294 + pr_warn("cannot retry for NFSv4 delegation"
20295 + " for an internal link\n");
20299 + dput(h_src_dentry);
20302 + * copyup src_dentry to the branch we process,
20303 + * and then link(2) to it.
20305 + dput(h_src_dentry);
20306 + if (a->bdst < a->bsrc
20307 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20308 + au_unpin(&a->pin);
20309 + di_write_unlock(a->parent);
20310 + err = au_cpup_before_link(src_dentry, a);
20311 + di_write_lock_parent(a->parent);
20313 + err = au_pin(&a->pin, dentry, a->bdst,
20315 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20316 + if (unlikely(err))
20320 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20322 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20323 + delegated = NULL;
20324 + err = vfsub_link(h_src_dentry,
20325 + au_pinned_h_dir(&a->pin),
20326 + &a->h_path, &delegated);
20327 + if (unlikely(err == -EWOULDBLOCK)) {
20328 + pr_warn("cannot retry"
20329 + " for NFSv4 delegation"
20330 + " for an internal link\n");
20336 + if (unlikely(err))
20340 + a->h_path.dentry = wh_dentry;
20341 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20343 + if (unlikely(err))
20347 + au_dir_ts(dir, a->bdst);
20348 + inode_inc_iversion(dir);
20349 + inc_nlink(inode);
20350 + inode->i_ctime = dir->i_ctime;
20351 + d_instantiate(dentry, au_igrab(inode));
20352 + if (d_unhashed(a->h_path.dentry))
20353 + /* some filesystem calls d_drop() */
20355 + /* some filesystems consume an inode even hardlink */
20356 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20357 + goto out_unpin; /* success */
20360 + /* no delegation since it is just created */
20361 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20362 + /*delegated*/NULL, /*force*/0);
20363 + if (unlikely(rerr)) {
20364 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20367 + au_dtime_revert(&dt);
20369 + au_unpin(&a->pin);
20373 + di_write_unlock(a->parent);
20374 + dput(a->src_parent);
20376 + if (unlikely(err)) {
20377 + au_update_dbtop(dentry);
20380 + aufs_read_and_write_unlock2(dentry, src_dentry);
20388 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20391 + aufs_bindex_t bindex;
20392 + unsigned char diropq;
20393 + struct path h_path;
20394 + struct dentry *wh_dentry, *parent, *opq_dentry;
20395 + struct inode *h_inode;
20396 + struct super_block *sb;
20398 + struct au_pin pin;
20399 + struct au_dtime dt;
20400 + } *a; /* reduce the stack usage */
20401 + struct au_wr_dir_args wr_dir_args = {
20402 + .force_btgt = -1,
20403 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20409 + a = kmalloc(sizeof(*a), GFP_NOFS);
20410 + if (unlikely(!a))
20413 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20414 + if (unlikely(err))
20416 + err = au_d_may_add(dentry);
20417 + if (unlikely(err))
20420 + parent = dentry->d_parent; /* dir inode is locked */
20421 + di_write_lock_parent(parent);
20422 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20423 + &a->pin, &wr_dir_args);
20424 + err = PTR_ERR(wh_dentry);
20425 + if (IS_ERR(wh_dentry))
20428 + sb = dentry->d_sb;
20429 + bindex = au_dbtop(dentry);
20430 + h_path.dentry = au_h_dptr(dentry, bindex);
20431 + h_path.mnt = au_sbr_mnt(sb, bindex);
20432 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20433 + if (unlikely(err))
20436 + /* make the dir opaque */
20438 + h_inode = d_inode(h_path.dentry);
20440 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20441 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20442 + opq_dentry = au_diropq_create(dentry, bindex);
20443 + inode_unlock(h_inode);
20444 + err = PTR_ERR(opq_dentry);
20445 + if (IS_ERR(opq_dentry))
20447 + dput(opq_dentry);
20451 + err = epilog(dir, bindex, wh_dentry, dentry);
20454 + goto out_unpin; /* success */
20459 + AuLabel(revert opq);
20460 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20461 + rerr = au_diropq_remove(dentry, bindex);
20462 + inode_unlock(h_inode);
20464 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20465 + dentry, err, rerr);
20471 + AuLabel(revert dir);
20472 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20474 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20475 + dentry, err, rerr);
20478 + au_dtime_revert(&a->dt);
20480 + au_unpin(&a->pin);
20483 + di_write_unlock(parent);
20485 + if (unlikely(err)) {
20486 + au_update_dbtop(dentry);
20489 + aufs_read_unlock(dentry, AuLock_DW);
20495 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20496 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20497 +++ linux/fs/aufs/i_op.c 2018-06-04 09:08:09.184746078 +0200
20500 + * Copyright (C) 2005-2018 Junjiro R. Okajima
20502 + * This program, aufs is free software; you can redistribute it and/or modify
20503 + * it under the terms of the GNU General Public License as published by
20504 + * the Free Software Foundation; either version 2 of the License, or
20505 + * (at your option) any later version.
20507 + * This program is distributed in the hope that it will be useful,
20508 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20509 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20510 + * GNU General Public License for more details.
20512 + * You should have received a copy of the GNU General Public License
20513 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20517 + * inode operations (except add/del/rename)
20520 +#include <linux/device_cgroup.h>
20521 +#include <linux/fs_stack.h>
20522 +#include <linux/namei.h>
20523 +#include <linux/security.h>
20526 +static int h_permission(struct inode *h_inode, int mask,
20527 + struct path *h_path, int brperm)
20530 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20533 + if (write_mask && IS_IMMUTABLE(h_inode))
20537 + if (((mask & MAY_EXEC)
20538 + && S_ISREG(h_inode->i_mode)
20539 + && (path_noexec(h_path)
20540 + || !(h_inode->i_mode & S_IXUGO))))
20544 + * - skip the lower fs test in the case of write to ro branch.
20545 + * - nfs dir permission write check is optimized, but a policy for
20546 + * link/rename requires a real check.
20547 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20548 + * in this case, generic_permission() returns -EOPNOTSUPP.
20550 + if ((write_mask && !au_br_writable(brperm))
20551 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20552 + && write_mask && !(mask & MAY_READ))
20553 + || !h_inode->i_op->permission) {
20554 + /* AuLabel(generic_permission); */
20555 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
20556 + err = generic_permission(h_inode, mask);
20557 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20558 + err = h_inode->i_op->permission(h_inode, mask);
20561 + /* AuLabel(h_inode->permission); */
20562 + err = h_inode->i_op->permission(h_inode, mask);
20567 + err = devcgroup_inode_permission(h_inode, mask);
20569 + err = security_inode_permission(h_inode, mask);
20573 + /* todo: do we need to call ima_path_check()? */
20574 + struct path h_path = {
20578 + err = ima_path_check(&h_path,
20579 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20580 + IMA_COUNT_LEAVE);
20588 +static int aufs_permission(struct inode *inode, int mask)
20591 + aufs_bindex_t bindex, bbot;
20592 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20593 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20594 + struct inode *h_inode;
20595 + struct super_block *sb;
20596 + struct au_branch *br;
20598 + /* todo: support rcu-walk? */
20599 + if (mask & MAY_NOT_BLOCK)
20602 + sb = inode->i_sb;
20603 + si_read_lock(sb, AuLock_FLUSH);
20604 + ii_read_lock_child(inode);
20606 + err = au_iigen_test(inode, au_sigen(sb));
20607 + if (unlikely(err))
20613 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20614 + err = au_busy_or_stale();
20615 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20616 + if (unlikely(!h_inode
20617 + || (h_inode->i_mode & S_IFMT)
20618 + != (inode->i_mode & S_IFMT)))
20622 + bindex = au_ibtop(inode);
20623 + br = au_sbr(sb, bindex);
20624 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20627 + && !special_file(h_inode->i_mode)) {
20628 + /* test whether the upper writable branch exists */
20630 + for (; bindex >= 0; bindex--)
20631 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20639 + /* non-write to dir */
20641 + bbot = au_ibbot(inode);
20642 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20643 + h_inode = au_h_iptr(inode, bindex);
20645 + err = au_busy_or_stale();
20646 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20649 + br = au_sbr(sb, bindex);
20650 + err = h_permission(h_inode, mask, &br->br_path,
20656 + ii_read_unlock(inode);
20657 + si_read_unlock(sb);
20661 +/* ---------------------------------------------------------------------- */
20663 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20664 + unsigned int flags)
20666 + struct dentry *ret, *parent;
20667 + struct inode *inode;
20668 + struct super_block *sb;
20669 + int err, npositive;
20673 + /* todo: support rcu-walk? */
20674 + ret = ERR_PTR(-ECHILD);
20675 + if (flags & LOOKUP_RCU)
20678 + ret = ERR_PTR(-ENAMETOOLONG);
20679 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20683 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20684 + ret = ERR_PTR(err);
20685 + if (unlikely(err))
20688 + err = au_di_init(dentry);
20689 + ret = ERR_PTR(err);
20690 + if (unlikely(err))
20694 + npositive = 0; /* suppress a warning */
20695 + parent = dentry->d_parent; /* dir inode is locked */
20696 + di_read_lock_parent(parent, AuLock_IR);
20697 + err = au_alive_dir(parent);
20699 + err = au_digen_test(parent, au_sigen(sb));
20701 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20702 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20703 + AuLkup_ALLOW_NEG);
20706 + di_read_unlock(parent, AuLock_IR);
20707 + ret = ERR_PTR(err);
20708 + if (unlikely(err < 0))
20712 + inode = au_new_inode(dentry, /*must_new*/0);
20713 + if (IS_ERR(inode)) {
20714 + ret = (void *)inode;
20721 + atomic_inc(&inode->i_count);
20722 + ret = d_splice_alias(inode, dentry);
20724 + if (unlikely(d_need_lookup(dentry))) {
20725 + spin_lock(&dentry->d_lock);
20726 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20727 + spin_unlock(&dentry->d_lock);
20731 + if (!IS_ERR(ret)) {
20733 + if (ret && ret != dentry)
20734 + ii_write_unlock(inode);
20736 + ii_write_unlock(inode);
20743 + di_write_unlock(dentry);
20745 + si_read_unlock(sb);
20750 +/* ---------------------------------------------------------------------- */
20752 +struct aopen_node {
20753 + struct hlist_bl_node hblist;
20754 + struct file *file, *h_file;
20757 +static int au_do_aopen(struct inode *inode, struct file *file)
20759 + struct hlist_bl_head *aopen;
20760 + struct hlist_bl_node *pos;
20761 + struct aopen_node *node;
20762 + struct au_do_open_args args = {
20764 + .open = au_do_open_nondir
20767 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20768 + hlist_bl_lock(aopen);
20769 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20770 + if (node->file == file) {
20771 + args.h_file = node->h_file;
20774 + hlist_bl_unlock(aopen);
20775 + /* AuDebugOn(!args.h_file); */
20777 + return au_do_open(file, &args);
20780 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20781 + struct file *file, unsigned int open_flag,
20782 + umode_t create_mode, int *opened)
20784 + int err, unlocked, h_opened = *opened;
20785 + unsigned int lkup_flags;
20786 + struct dentry *parent, *d;
20787 + struct hlist_bl_head *aopen;
20788 + struct vfsub_aopen_args args = {
20789 + .open_flag = open_flag,
20790 + .create_mode = create_mode,
20791 + .opened = &h_opened
20793 + struct aopen_node aopen_node = {
20798 + AuDbg("open_flag 0%o\n", open_flag);
20799 + AuDbgDentry(dentry);
20802 + if (!au_di(dentry)) {
20803 + lkup_flags = LOOKUP_OPEN;
20804 + if (open_flag & O_CREAT)
20805 + lkup_flags |= LOOKUP_CREATE;
20806 + d = aufs_lookup(dir, dentry, lkup_flags);
20808 + err = PTR_ERR(d);
20813 + * obsoleted dentry found.
20814 + * another error will be returned later.
20820 + AuDbgDentry(dentry);
20823 + if (d_is_positive(dentry)
20824 + || d_unhashed(dentry)
20825 + || d_unlinked(dentry)
20826 + || !(open_flag & O_CREAT))
20827 + goto out_no_open;
20830 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20831 + if (unlikely(err))
20834 + parent = dentry->d_parent; /* dir is locked */
20835 + di_write_lock_parent(parent);
20836 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20837 + if (unlikely(err))
20840 + AuDbgDentry(dentry);
20841 + if (d_is_positive(dentry))
20844 + args.file = get_empty_filp();
20845 + err = PTR_ERR(args.file);
20846 + if (IS_ERR(args.file))
20849 + args.file->f_flags = file->f_flags;
20850 + err = au_aopen_or_create(dir, dentry, &args);
20852 + AuDbgFile(args.file);
20853 + if (unlikely(err < 0)) {
20854 + if (h_opened & FILE_OPENED)
20857 + put_filp(args.file);
20860 + di_write_unlock(parent);
20861 + di_write_unlock(dentry);
20864 + /* some filesystems don't set FILE_CREATED while succeeded? */
20865 + *opened |= FILE_CREATED;
20866 + if (h_opened & FILE_OPENED)
20867 + aopen_node.h_file = args.file;
20869 + put_filp(args.file);
20870 + args.file = NULL;
20872 + aopen = &au_sbi(dir->i_sb)->si_aopen;
20873 + au_hbl_add(&aopen_node.hblist, aopen);
20874 + err = finish_open(file, dentry, au_do_aopen, opened);
20875 + au_hbl_del(&aopen_node.hblist, aopen);
20878 + if (aopen_node.h_file)
20879 + fput(aopen_node.h_file);
20883 + si_read_unlock(dentry->d_sb);
20885 + di_write_unlock(parent);
20886 + aufs_read_unlock(dentry, AuLock_DW);
20888 + AuDbgDentry(dentry);
20889 + if (unlikely(err < 0))
20892 + if (err >= 0 && !(*opened & FILE_CREATED)) {
20893 + AuLabel(out_no_open);
20895 + err = finish_no_open(file, dentry);
20898 + AuDbg("%pd%s%s\n", dentry,
20899 + (*opened & FILE_CREATED) ? " created" : "",
20900 + (*opened & FILE_OPENED) ? " opened" : "");
20906 +/* ---------------------------------------------------------------------- */
20908 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20909 + const unsigned char add_entry, aufs_bindex_t bcpup,
20910 + aufs_bindex_t btop)
20913 + struct dentry *h_parent;
20914 + struct inode *h_dir;
20917 + IMustLock(d_inode(parent));
20919 + di_write_lock_parent(parent);
20922 + if (!au_h_dptr(parent, bcpup)) {
20923 + if (btop > bcpup)
20924 + err = au_cpup_dirs(dentry, bcpup);
20925 + else if (btop < bcpup)
20926 + err = au_cpdown_dirs(dentry, bcpup);
20930 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20931 + h_parent = au_h_dptr(parent, bcpup);
20932 + h_dir = d_inode(h_parent);
20933 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20934 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20935 + /* todo: no unlock here */
20936 + inode_unlock_shared(h_dir);
20938 + AuDbg("bcpup %d\n", bcpup);
20940 + if (d_really_is_negative(dentry))
20941 + au_set_h_dptr(dentry, btop, NULL);
20942 + au_update_dbrange(dentry, /*do_put_zero*/0);
20947 + di_write_unlock(parent);
20949 + err = bcpup; /* success */
20956 + * decide the branch and the parent dir where we will create a new entry.
20957 + * returns new bindex or an error.
20958 + * copyup the parent dir if needed.
20960 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20961 + struct au_wr_dir_args *args)
20964 + unsigned int flags;
20965 + aufs_bindex_t bcpup, btop, src_btop;
20966 + const unsigned char add_entry
20967 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20968 + | au_ftest_wrdir(args->flags, TMPFILE);
20969 + struct super_block *sb;
20970 + struct dentry *parent;
20971 + struct au_sbinfo *sbinfo;
20973 + sb = dentry->d_sb;
20974 + sbinfo = au_sbi(sb);
20975 + parent = dget_parent(dentry);
20976 + btop = au_dbtop(dentry);
20978 + if (args->force_btgt < 0) {
20979 + if (src_dentry) {
20980 + src_btop = au_dbtop(src_dentry);
20981 + if (src_btop < btop)
20982 + bcpup = src_btop;
20983 + } else if (add_entry) {
20985 + if (au_ftest_wrdir(args->flags, ISDIR))
20986 + au_fset_wbr(flags, DIR);
20987 + err = AuWbrCreate(sbinfo, dentry, flags);
20991 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20993 + err = AuWbrCopyup(sbinfo, dentry);
20995 + if (!IS_ROOT(dentry)) {
20996 + di_read_lock_parent(parent, !AuLock_IR);
20997 + err = AuWbrCopyup(sbinfo, dentry);
20998 + di_read_unlock(parent, !AuLock_IR);
21000 + err = AuWbrCopyup(sbinfo, dentry);
21003 + if (unlikely(err < 0))
21007 + bcpup = args->force_btgt;
21008 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21011 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21013 + if (bcpup == btop)
21014 + goto out; /* success */
21016 + /* copyup the new parent into the branch we process */
21017 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21019 + if (d_really_is_negative(dentry)) {
21020 + au_set_h_dptr(dentry, btop, NULL);
21021 + au_set_dbtop(dentry, bcpup);
21022 + au_set_dbbot(dentry, bcpup);
21024 + AuDebugOn(add_entry
21025 + && !au_ftest_wrdir(args->flags, TMPFILE)
21026 + && !au_h_dptr(dentry, bcpup));
21034 +/* ---------------------------------------------------------------------- */
21036 +void au_pin_hdir_unlock(struct au_pin *p)
21039 + au_hn_inode_unlock(p->hdir);
21042 +int au_pin_hdir_lock(struct au_pin *p)
21050 + /* even if an error happens later, keep this lock */
21051 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21054 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21059 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21060 + p->h_parent, p->br);
21066 +int au_pin_hdir_relock(struct au_pin *p)
21069 + struct inode *h_i;
21070 + struct dentry *h_d[] = {
21075 + err = au_pin_hdir_lock(p);
21076 + if (unlikely(err))
21079 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21082 + if (d_is_positive(h_d[i])) {
21083 + h_i = d_inode(h_d[i]);
21084 + err = !h_i->i_nlink;
21092 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21094 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21095 + p->hdir->hi_inode->i_rwsem.owner = task;
21099 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21102 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21103 + p->lsc_hi, 0, NULL, _RET_IP_);
21104 + au_pin_hdir_set_owner(p, current);
21108 +void au_pin_hdir_release(struct au_pin *p)
21111 + au_pin_hdir_set_owner(p, p->task);
21112 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21116 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21118 + if (pin && pin->parent)
21119 + return au_h_dptr(pin->parent, pin->bindex);
21123 +void au_unpin(struct au_pin *p)
21126 + au_pin_hdir_unlock(p);
21127 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21128 + vfsub_mnt_drop_write(p->h_mnt);
21132 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21133 + di_read_unlock(p->parent, AuLock_IR);
21134 + iput(p->hdir->hi_inode);
21136 + p->parent = NULL;
21139 + /* do not clear p->task */
21142 +int au_do_pin(struct au_pin *p)
21145 + struct super_block *sb;
21146 + struct inode *h_dir;
21149 + sb = p->dentry->d_sb;
21150 + p->br = au_sbr(sb, p->bindex);
21151 + if (IS_ROOT(p->dentry)) {
21152 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21153 + p->h_mnt = au_br_mnt(p->br);
21154 + err = vfsub_mnt_want_write(p->h_mnt);
21155 + if (unlikely(err)) {
21156 + au_fclr_pin(p->flags, MNT_WRITE);
21163 + p->h_dentry = NULL;
21164 + if (p->bindex <= au_dbbot(p->dentry))
21165 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21167 + p->parent = dget_parent(p->dentry);
21168 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21169 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21172 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21173 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21175 + h_dir = p->hdir->hi_inode;
21179 + * if DI_LOCKED is not set, then p->parent may be different
21180 + * and h_parent can be NULL.
21182 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21184 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21185 + di_read_unlock(p->parent, AuLock_IR);
21187 + p->parent = NULL;
21191 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21192 + p->h_mnt = au_br_mnt(p->br);
21193 + err = vfsub_mnt_want_write(p->h_mnt);
21194 + if (unlikely(err)) {
21195 + au_fclr_pin(p->flags, MNT_WRITE);
21196 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21197 + di_read_unlock(p->parent, AuLock_IR);
21199 + p->parent = NULL;
21205 + err = au_pin_hdir_lock(p);
21207 + goto out; /* success */
21212 + pr_err("err %d\n", err);
21213 + err = au_busy_or_stale();
21218 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21219 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21220 + unsigned int udba, unsigned char flags)
21222 + p->dentry = dentry;
21224 + p->lsc_di = lsc_di;
21225 + p->lsc_hi = lsc_hi;
21226 + p->flags = flags;
21227 + p->bindex = bindex;
21229 + p->parent = NULL;
21233 + p->h_dentry = NULL;
21234 + p->h_parent = NULL;
21236 + p->task = current;
21239 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21240 + unsigned int udba, unsigned char flags)
21242 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21244 + return au_do_pin(pin);
21247 +/* ---------------------------------------------------------------------- */
21250 + * ->setattr() and ->getattr() are called in various cases.
21251 + * chmod, stat: dentry is revalidated.
21252 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21254 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21256 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21257 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21260 + struct dentry *parent;
21263 + if (au_digen_test(dentry, sigen)) {
21264 + parent = dget_parent(dentry);
21265 + di_read_lock_parent(parent, AuLock_IR);
21266 + err = au_refresh_dentry(dentry, parent);
21267 + di_read_unlock(parent, AuLock_IR);
21275 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21276 + struct au_icpup_args *a)
21280 + aufs_bindex_t btop, ibtop;
21281 + struct dentry *hi_wh, *parent;
21282 + struct inode *inode;
21283 + struct au_wr_dir_args wr_dir_args = {
21284 + .force_btgt = -1,
21288 + if (d_is_dir(dentry))
21289 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21290 + /* plink or hi_wh() case */
21291 + btop = au_dbtop(dentry);
21292 + inode = d_inode(dentry);
21293 + ibtop = au_ibtop(inode);
21294 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21295 + wr_dir_args.force_btgt = ibtop;
21296 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21297 + if (unlikely(err < 0))
21301 + au_fset_icpup(a->flags, DID_CPUP);
21304 + a->pin_flags = AuPin_MNT_WRITE;
21306 + if (!IS_ROOT(dentry)) {
21307 + au_fset_pin(a->pin_flags, DI_LOCKED);
21308 + parent = dget_parent(dentry);
21309 + di_write_lock_parent(parent);
21312 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21313 + if (unlikely(err))
21317 + a->h_path.dentry = au_h_dptr(dentry, btop);
21318 + a->h_inode = d_inode(a->h_path.dentry);
21319 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21320 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21321 + if (ia->ia_size < i_size_read(a->h_inode))
21322 + sz = ia->ia_size;
21323 + inode_unlock_shared(a->h_inode);
21327 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21328 + hi_wh = au_hi_wh(inode, a->btgt);
21330 + struct au_cp_generic cpg = {
21331 + .dentry = dentry,
21337 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21338 + if (unlikely(err))
21340 + hi_wh = au_hi_wh(inode, a->btgt);
21341 + /* todo: revalidate hi_wh? */
21346 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21347 + di_downgrade_lock(parent, AuLock_IR);
21351 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21352 + goto out; /* success */
21354 + if (!d_unhashed(dentry)) {
21355 + struct au_cp_generic cpg = {
21356 + .dentry = dentry,
21361 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21363 + err = au_sio_cpup_simple(&cpg);
21365 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21366 + } else if (!hi_wh)
21367 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21369 + a->h_path.dentry = hi_wh; /* do not dget here */
21372 + a->h_inode = d_inode(a->h_path.dentry);
21374 + goto out; /* success */
21375 + au_unpin(&a->pin);
21378 + di_write_unlock(parent);
21383 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21387 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21390 + struct inode *inode, *delegated;
21391 + struct super_block *sb;
21392 + struct file *file;
21393 + struct au_icpup_args *a;
21395 + inode = d_inode(dentry);
21396 + IMustLock(inode);
21398 + err = setattr_prepare(dentry, ia);
21399 + if (unlikely(err))
21403 + a = kzalloc(sizeof(*a), GFP_NOFS);
21404 + if (unlikely(!a))
21407 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21408 + ia->ia_valid &= ~ATTR_MODE;
21411 + sb = dentry->d_sb;
21412 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21413 + if (unlikely(err))
21416 + if (ia->ia_valid & ATTR_FILE) {
21417 + /* currently ftruncate(2) only */
21418 + AuDebugOn(!d_is_reg(dentry));
21419 + file = ia->ia_file;
21420 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21422 + if (unlikely(err))
21424 + ia->ia_file = au_hf_top(file);
21425 + a->udba = AuOpt_UDBA_NONE;
21427 + /* fchmod() doesn't pass ia_file */
21428 + a->udba = au_opt_udba(sb);
21429 + di_write_lock_child(dentry);
21430 + /* no d_unlinked(), to set UDBA_NONE for root */
21431 + if (d_unhashed(dentry))
21432 + a->udba = AuOpt_UDBA_NONE;
21433 + if (a->udba != AuOpt_UDBA_NONE) {
21434 + AuDebugOn(IS_ROOT(dentry));
21435 + err = au_reval_for_attr(dentry, au_sigen(sb));
21436 + if (unlikely(err))
21441 + err = au_pin_and_icpup(dentry, ia, a);
21442 + if (unlikely(err < 0))
21444 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21445 + ia->ia_file = NULL;
21446 + ia->ia_valid &= ~ATTR_FILE;
21449 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21450 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21451 + == (ATTR_MODE | ATTR_CTIME)) {
21452 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21453 + if (unlikely(err))
21455 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21456 + && (ia->ia_valid & ATTR_CTIME)) {
21457 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21458 + if (unlikely(err))
21462 + if (ia->ia_valid & ATTR_SIZE) {
21465 + if (ia->ia_size < i_size_read(inode))
21467 + truncate_setsize(inode, ia->ia_size);
21470 + if (ia->ia_valid & ATTR_FILE)
21472 + inode_unlock(a->h_inode);
21473 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21474 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21476 + delegated = NULL;
21478 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21480 + err = break_deleg_wait(&delegated);
21488 + * regardless aufs 'acl' option setting.
21489 + * why don't all acl-aware fs call this func from their ->setattr()?
21491 + if (!err && (ia->ia_valid & ATTR_MODE))
21492 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21494 + au_cpup_attr_changeable(inode);
21497 + inode_unlock(a->h_inode);
21498 + au_unpin(&a->pin);
21499 + if (unlikely(err))
21500 + au_update_dbtop(dentry);
21502 + di_write_unlock(dentry);
21504 + fi_write_unlock(file);
21505 + ia->ia_file = file;
21506 + ia->ia_valid |= ATTR_FILE;
21509 + si_read_unlock(sb);
21517 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21518 +static int au_h_path_to_set_attr(struct dentry *dentry,
21519 + struct au_icpup_args *a, struct path *h_path)
21522 + struct super_block *sb;
21524 + sb = dentry->d_sb;
21525 + a->udba = au_opt_udba(sb);
21526 + /* no d_unlinked(), to set UDBA_NONE for root */
21527 + if (d_unhashed(dentry))
21528 + a->udba = AuOpt_UDBA_NONE;
21529 + if (a->udba != AuOpt_UDBA_NONE) {
21530 + AuDebugOn(IS_ROOT(dentry));
21531 + err = au_reval_for_attr(dentry, au_sigen(sb));
21532 + if (unlikely(err))
21535 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21536 + if (unlikely(err < 0))
21539 + h_path->dentry = a->h_path.dentry;
21540 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21546 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21547 + struct au_sxattr *arg)
21550 + struct path h_path;
21551 + struct super_block *sb;
21552 + struct au_icpup_args *a;
21553 + struct inode *h_inode;
21555 + IMustLock(inode);
21558 + a = kzalloc(sizeof(*a), GFP_NOFS);
21559 + if (unlikely(!a))
21562 + sb = dentry->d_sb;
21563 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21564 + if (unlikely(err))
21567 + h_path.dentry = NULL; /* silence gcc */
21568 + di_write_lock_child(dentry);
21569 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21570 + if (unlikely(err))
21573 + inode_unlock(a->h_inode);
21574 + switch (arg->type) {
21575 + case AU_XATTR_SET:
21576 + AuDebugOn(d_is_negative(h_path.dentry));
21577 + err = vfsub_setxattr(h_path.dentry,
21578 + arg->u.set.name, arg->u.set.value,
21579 + arg->u.set.size, arg->u.set.flags);
21582 + err = -EOPNOTSUPP;
21583 + h_inode = d_inode(h_path.dentry);
21584 + if (h_inode->i_op->set_acl)
21585 + /* this will call posix_acl_update_mode */
21586 + err = h_inode->i_op->set_acl(h_inode,
21587 + arg->u.acl_set.acl,
21588 + arg->u.acl_set.type);
21592 + au_cpup_attr_timesizes(inode);
21594 + au_unpin(&a->pin);
21595 + if (unlikely(err))
21596 + au_update_dbtop(dentry);
21599 + di_write_unlock(dentry);
21600 + si_read_unlock(sb);
21609 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21610 + unsigned int nlink)
21614 + inode->i_mode = st->mode;
21615 + /* don't i_[ug]id_write() here */
21616 + inode->i_uid = st->uid;
21617 + inode->i_gid = st->gid;
21618 + inode->i_atime = st->atime;
21619 + inode->i_mtime = st->mtime;
21620 + inode->i_ctime = st->ctime;
21622 + au_cpup_attr_nlink(inode, /*force*/0);
21623 + if (S_ISDIR(inode->i_mode)) {
21624 + n = inode->i_nlink;
21627 + smp_mb(); /* for i_nlink */
21628 + /* 0 can happen */
21629 + set_nlink(inode, n);
21632 + spin_lock(&inode->i_lock);
21633 + inode->i_blocks = st->blocks;
21634 + i_size_write(inode, st->size);
21635 + spin_unlock(&inode->i_lock);
21639 + * common routine for aufs_getattr() and au_getxattr().
21640 + * returns zero or negative (an error).
21641 + * @dentry will be read-locked in success.
21643 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21647 + unsigned int mnt_flags, sigen;
21648 + unsigned char udba_none;
21649 + aufs_bindex_t bindex;
21650 + struct super_block *sb, *h_sb;
21651 + struct inode *inode;
21653 + h_path->mnt = NULL;
21654 + h_path->dentry = NULL;
21657 + sb = dentry->d_sb;
21658 + mnt_flags = au_mntflags(sb);
21659 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21661 + if (unlikely(locked))
21662 + goto body; /* skip locking dinfo */
21664 + /* support fstat(2) */
21665 + if (!d_unlinked(dentry) && !udba_none) {
21666 + sigen = au_sigen(sb);
21667 + err = au_digen_test(dentry, sigen);
21669 + di_read_lock_child(dentry, AuLock_IR);
21670 + err = au_dbrange_test(dentry);
21671 + if (unlikely(err)) {
21672 + di_read_unlock(dentry, AuLock_IR);
21676 + AuDebugOn(IS_ROOT(dentry));
21677 + di_write_lock_child(dentry);
21678 + err = au_dbrange_test(dentry);
21680 + err = au_reval_for_attr(dentry, sigen);
21682 + di_downgrade_lock(dentry, AuLock_IR);
21684 + di_write_unlock(dentry);
21689 + di_read_lock_child(dentry, AuLock_IR);
21692 + inode = d_inode(dentry);
21693 + bindex = au_ibtop(inode);
21694 + h_path->mnt = au_sbr_mnt(sb, bindex);
21695 + h_sb = h_path->mnt->mnt_sb;
21697 + && !au_test_fs_bad_iattr(h_sb)
21699 + goto out; /* success */
21701 + if (au_dbtop(dentry) == bindex)
21702 + h_path->dentry = au_h_dptr(dentry, bindex);
21703 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21704 + h_path->dentry = au_plink_lkup(inode, bindex);
21705 + if (IS_ERR(h_path->dentry))
21706 + /* pretending success */
21707 + h_path->dentry = NULL;
21709 + dput(h_path->dentry);
21716 +static int aufs_getattr(const struct path *path, struct kstat *st,
21717 + u32 request, unsigned int query)
21720 + unsigned char positive;
21721 + struct path h_path;
21722 + struct dentry *dentry;
21723 + struct inode *inode;
21724 + struct super_block *sb;
21726 + dentry = path->dentry;
21727 + inode = d_inode(dentry);
21728 + sb = dentry->d_sb;
21729 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21730 + if (unlikely(err))
21732 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21733 + if (unlikely(err))
21735 + if (unlikely(!h_path.dentry))
21736 + /* illegally overlapped or something */
21737 + goto out_fill; /* pretending success */
21739 + positive = d_is_positive(h_path.dentry);
21741 + /* no vfsub version */
21742 + err = vfs_getattr(&h_path, st, request, query);
21745 + au_refresh_iattr(inode, st,
21746 + d_inode(h_path.dentry)->i_nlink);
21747 + goto out_fill; /* success */
21753 + generic_fillattr(inode, st);
21755 + di_read_unlock(dentry, AuLock_IR);
21757 + si_read_unlock(sb);
21763 +/* ---------------------------------------------------------------------- */
21765 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21766 + struct delayed_call *done)
21769 + struct dentry *h_dentry;
21770 + struct inode *h_inode;
21772 + aufs_bindex_t bindex;
21774 + ret = NULL; /* suppress a warning */
21779 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21780 + if (unlikely(err))
21783 + err = au_d_hashed_positive(dentry);
21784 + if (unlikely(err))
21788 + inode = d_inode(dentry);
21789 + bindex = au_ibtop(inode);
21790 + h_inode = au_h_iptr(inode, bindex);
21791 + if (unlikely(!h_inode->i_op->get_link))
21796 + if (au_dbtop(dentry) <= bindex) {
21797 + h_dentry = au_h_dptr(dentry, bindex);
21802 + h_dentry = d_find_any_alias(h_inode);
21803 + if (IS_ERR(h_dentry)) {
21804 + err = PTR_ERR(h_dentry);
21808 + if (unlikely(!h_dentry))
21812 + AuDbg("%pf\n", h_inode->i_op->get_link);
21813 + AuDbgDentry(h_dentry);
21814 + ret = vfs_get_link(h_dentry, done);
21817 + err = PTR_ERR(ret);
21820 + aufs_read_unlock(dentry, AuLock_IR);
21822 + if (unlikely(err))
21823 + ret = ERR_PTR(err);
21824 + AuTraceErrPtr(ret);
21828 +/* ---------------------------------------------------------------------- */
21830 +static int au_is_special(struct inode *inode)
21832 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21835 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
21838 + aufs_bindex_t bindex;
21839 + struct super_block *sb;
21840 + struct inode *h_inode;
21841 + struct vfsmount *h_mnt;
21843 + sb = inode->i_sb;
21844 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21845 + "unexpected s_flags 0x%lx", sb->s_flags);
21847 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21849 + si_read_lock(sb, AuLock_FLUSH);
21850 + ii_write_lock_child(inode);
21853 + bindex = au_ibtop(inode);
21854 + h_inode = au_h_iptr(inode, bindex);
21855 + if (!au_test_ro(sb, bindex, inode)) {
21856 + h_mnt = au_sbr_mnt(sb, bindex);
21857 + err = vfsub_mnt_want_write(h_mnt);
21859 + err = vfsub_update_time(h_inode, ts, flags);
21860 + vfsub_mnt_drop_write(h_mnt);
21862 + } else if (au_is_special(h_inode)) {
21864 + * Never copy-up here.
21865 + * These special files may already be opened and used for
21866 + * communicating. If we copied it up, then the communication
21867 + * would be corrupted.
21869 + AuWarn1("timestamps for i%lu are ignored "
21870 + "since it is on readonly branch (hi%lu).\n",
21871 + inode->i_ino, h_inode->i_ino);
21872 + } else if (flags & ~S_ATIME) {
21874 + AuIOErr1("unexpected flags 0x%x\n", flags);
21879 + au_cpup_attr_timesizes(inode);
21880 + ii_write_unlock(inode);
21881 + si_read_unlock(sb);
21884 + if (!err && (flags & S_VERSION))
21885 + inode_inc_iversion(inode);
21890 +/* ---------------------------------------------------------------------- */
21892 +/* no getattr version will be set by module.c:aufs_init() */
21893 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21895 + [AuIop_SYMLINK] = {
21896 + .permission = aufs_permission,
21897 +#ifdef CONFIG_FS_POSIX_ACL
21898 + .get_acl = aufs_get_acl,
21899 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21902 + .setattr = aufs_setattr,
21903 + .getattr = aufs_getattr,
21905 +#ifdef CONFIG_AUFS_XATTR
21906 + .listxattr = aufs_listxattr,
21909 + .get_link = aufs_get_link,
21911 + /* .update_time = aufs_update_time */
21914 + .create = aufs_create,
21915 + .lookup = aufs_lookup,
21916 + .link = aufs_link,
21917 + .unlink = aufs_unlink,
21918 + .symlink = aufs_symlink,
21919 + .mkdir = aufs_mkdir,
21920 + .rmdir = aufs_rmdir,
21921 + .mknod = aufs_mknod,
21922 + .rename = aufs_rename,
21924 + .permission = aufs_permission,
21925 +#ifdef CONFIG_FS_POSIX_ACL
21926 + .get_acl = aufs_get_acl,
21927 + .set_acl = aufs_set_acl,
21930 + .setattr = aufs_setattr,
21931 + .getattr = aufs_getattr,
21933 +#ifdef CONFIG_AUFS_XATTR
21934 + .listxattr = aufs_listxattr,
21937 + .update_time = aufs_update_time,
21938 + .atomic_open = aufs_atomic_open,
21939 + .tmpfile = aufs_tmpfile
21941 + [AuIop_OTHER] = {
21942 + .permission = aufs_permission,
21943 +#ifdef CONFIG_FS_POSIX_ACL
21944 + .get_acl = aufs_get_acl,
21945 + .set_acl = aufs_set_acl,
21948 + .setattr = aufs_setattr,
21949 + .getattr = aufs_getattr,
21951 +#ifdef CONFIG_AUFS_XATTR
21952 + .listxattr = aufs_listxattr,
21955 + .update_time = aufs_update_time
21958 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21959 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21960 +++ linux/fs/aufs/i_op_del.c 2018-06-04 09:08:09.184746078 +0200
21963 + * Copyright (C) 2005-2018 Junjiro R. Okajima
21965 + * This program, aufs is free software; you can redistribute it and/or modify
21966 + * it under the terms of the GNU General Public License as published by
21967 + * the Free Software Foundation; either version 2 of the License, or
21968 + * (at your option) any later version.
21970 + * This program is distributed in the hope that it will be useful,
21971 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21972 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21973 + * GNU General Public License for more details.
21975 + * You should have received a copy of the GNU General Public License
21976 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21980 + * inode operations (del entry)
21986 + * decide if a new whiteout for @dentry is necessary or not.
21987 + * when it is necessary, prepare the parent dir for the upper branch whose
21988 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21989 + * be done by caller.
21991 + * 0: wh is unnecessary
21992 + * plus: wh is necessary
21995 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21997 + int need_wh, err;
21998 + aufs_bindex_t btop;
21999 + struct super_block *sb;
22001 + sb = dentry->d_sb;
22002 + btop = au_dbtop(dentry);
22003 + if (*bcpup < 0) {
22005 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22006 + err = AuWbrCopyup(au_sbi(sb), dentry);
22008 + if (unlikely(err < 0))
22012 + AuDebugOn(btop < *bcpup
22013 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22014 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22016 + if (*bcpup != btop) {
22017 + err = au_cpup_dirs(dentry, *bcpup);
22018 + if (unlikely(err))
22022 + struct au_dinfo *dinfo, *tmp;
22024 + need_wh = -ENOMEM;
22025 + dinfo = au_di(dentry);
22026 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22028 + au_di_cp(tmp, dinfo);
22029 + au_di_swap(tmp, dinfo);
22030 + /* returns the number of positive dentries */
22031 + need_wh = au_lkup_dentry(dentry, btop + 1,
22032 + /* AuLkup_IGNORE_PERM */ 0);
22033 + au_di_swap(tmp, dinfo);
22034 + au_rw_write_unlock(&tmp->di_rwsem);
22038 + AuDbg("need_wh %d\n", need_wh);
22046 + * simple tests for the del-entry operations.
22047 + * following the checks in vfs, plus the parent-child relationship.
22049 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22050 + struct dentry *h_parent, int isdir)
22054 + struct dentry *h_dentry, *h_latest;
22055 + struct inode *h_inode;
22057 + h_dentry = au_h_dptr(dentry, bindex);
22058 + if (d_really_is_positive(dentry)) {
22060 + if (unlikely(d_is_negative(h_dentry)))
22062 + h_inode = d_inode(h_dentry);
22063 + if (unlikely(!h_inode->i_nlink))
22066 + h_mode = h_inode->i_mode;
22069 + if (unlikely(S_ISDIR(h_mode)))
22071 + } else if (unlikely(!S_ISDIR(h_mode))) {
22076 + /* rename(2) case */
22078 + if (unlikely(d_is_positive(h_dentry)))
22083 + /* expected parent dir is locked */
22084 + if (unlikely(h_parent != h_dentry->d_parent))
22089 + * rmdir a dir may break the consistency on some filesystem.
22090 + * let's try heavy test.
22093 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22094 + && au_test_h_perm(d_inode(h_parent),
22095 + MAY_EXEC | MAY_WRITE)))
22098 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22100 + if (IS_ERR(h_latest))
22102 + if (h_latest == h_dentry)
22111 + * decide the branch where we operate for @dentry. the branch index will be set
22112 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
22113 + * dir for reverting.
22114 + * when a new whiteout is necessary, create it.
22116 +static struct dentry*
22117 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22118 + struct au_dtime *dt, struct au_pin *pin)
22120 + struct dentry *wh_dentry;
22121 + struct super_block *sb;
22122 + struct path h_path;
22123 + int err, need_wh;
22124 + unsigned int udba;
22125 + aufs_bindex_t bcpup;
22127 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22128 + wh_dentry = ERR_PTR(need_wh);
22129 + if (unlikely(need_wh < 0))
22132 + sb = dentry->d_sb;
22133 + udba = au_opt_udba(sb);
22135 + err = au_pin(pin, dentry, bcpup, udba,
22136 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22137 + wh_dentry = ERR_PTR(err);
22138 + if (unlikely(err))
22141 + h_path.dentry = au_pinned_h_parent(pin);
22142 + if (udba != AuOpt_UDBA_NONE
22143 + && au_dbtop(dentry) == bcpup) {
22144 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22145 + wh_dentry = ERR_PTR(err);
22146 + if (unlikely(err))
22150 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22151 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22152 + wh_dentry = NULL;
22154 + goto out; /* success, no need to create whiteout */
22156 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22157 + if (IS_ERR(wh_dentry))
22160 + /* returns with the parent is locked and wh_dentry is dget-ed */
22161 + goto out; /* success */
22166 + return wh_dentry;
22170 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22171 + * in order to be revertible and save time for removing many child whiteouts
22173 + * returns 1 when there are too many child whiteout and caller should remove
22174 + * them asynchronously. returns 0 when the number of children is enough small to
22175 + * remove now or the branch fs is a remote fs.
22176 + * otherwise return an error.
22178 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22179 + struct au_nhash *whlist, struct inode *dir)
22181 + int rmdir_later, err, dirwh;
22182 + struct dentry *h_dentry;
22183 + struct super_block *sb;
22184 + struct inode *inode;
22186 + sb = dentry->d_sb;
22187 + SiMustAnyLock(sb);
22188 + h_dentry = au_h_dptr(dentry, bindex);
22189 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22190 + if (unlikely(err))
22193 + /* stop monitoring */
22194 + inode = d_inode(dentry);
22195 + au_hn_free(au_hi(inode, bindex));
22197 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22198 + dirwh = au_sbi(sb)->si_dirwh;
22199 + rmdir_later = (dirwh <= 1);
22200 + if (!rmdir_later)
22201 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22204 + return rmdir_later;
22207 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22208 + if (unlikely(err)) {
22209 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22210 + h_dentry, bindex, err);
22220 + * final procedure for deleting a entry.
22221 + * maintain dentry and iattr.
22223 +static void epilog(struct inode *dir, struct dentry *dentry,
22224 + aufs_bindex_t bindex)
22226 + struct inode *inode;
22228 + inode = d_inode(dentry);
22230 + inode->i_ctime = dir->i_ctime;
22232 + au_dir_ts(dir, bindex);
22233 + inode_inc_iversion(dir);
22237 + * when an error happened, remove the created whiteout and revert everything.
22239 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22240 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22241 + struct dentry *dentry, struct au_dtime *dt)
22244 + struct path h_path = {
22245 + .dentry = wh_dentry,
22246 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22249 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22251 + au_set_dbwh(dentry, bwh);
22252 + au_dtime_revert(dt);
22256 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22260 +/* ---------------------------------------------------------------------- */
22262 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22265 + aufs_bindex_t bwh, bindex, btop;
22266 + struct inode *inode, *h_dir, *delegated;
22267 + struct dentry *parent, *wh_dentry;
22268 + /* to reuduce stack size */
22270 + struct au_dtime dt;
22271 + struct au_pin pin;
22272 + struct path h_path;
22278 + a = kmalloc(sizeof(*a), GFP_NOFS);
22279 + if (unlikely(!a))
22282 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22283 + if (unlikely(err))
22285 + err = au_d_hashed_positive(dentry);
22286 + if (unlikely(err))
22288 + inode = d_inode(dentry);
22289 + IMustLock(inode);
22291 + if (unlikely(d_is_dir(dentry)))
22292 + goto out_unlock; /* possible? */
22294 + btop = au_dbtop(dentry);
22295 + bwh = au_dbwh(dentry);
22297 + parent = dentry->d_parent; /* dir inode is locked */
22298 + di_write_lock_parent(parent);
22299 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22301 + err = PTR_ERR(wh_dentry);
22302 + if (IS_ERR(wh_dentry))
22305 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22306 + a->h_path.dentry = au_h_dptr(dentry, btop);
22307 + dget(a->h_path.dentry);
22308 + if (bindex == btop) {
22309 + h_dir = au_pinned_h_dir(&a->pin);
22310 + delegated = NULL;
22311 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22312 + if (unlikely(err == -EWOULDBLOCK)) {
22313 + pr_warn("cannot retry for NFSv4 delegation"
22314 + " for an internal unlink\n");
22318 + /* dir inode is locked */
22319 + h_dir = d_inode(wh_dentry->d_parent);
22320 + IMustLock(h_dir);
22325 + vfsub_drop_nlink(inode);
22326 + epilog(dir, dentry, bindex);
22328 + /* update target timestamps */
22329 + if (bindex == btop) {
22330 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22332 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22334 + /* todo: this timestamp may be reverted later */
22335 + inode->i_ctime = h_dir->i_ctime;
22336 + goto out_unpin; /* success */
22343 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22350 + au_unpin(&a->pin);
22352 + dput(a->h_path.dentry);
22354 + di_write_unlock(parent);
22356 + aufs_read_unlock(dentry, AuLock_DW);
22363 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22365 + int err, rmdir_later;
22366 + aufs_bindex_t bwh, bindex, btop;
22367 + struct inode *inode;
22368 + struct dentry *parent, *wh_dentry, *h_dentry;
22369 + struct au_whtmp_rmdir *args;
22370 + /* to reuduce stack size */
22372 + struct au_dtime dt;
22373 + struct au_pin pin;
22379 + a = kmalloc(sizeof(*a), GFP_NOFS);
22380 + if (unlikely(!a))
22383 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22384 + if (unlikely(err))
22386 + err = au_alive_dir(dentry);
22387 + if (unlikely(err))
22389 + inode = d_inode(dentry);
22390 + IMustLock(inode);
22392 + if (unlikely(!d_is_dir(dentry)))
22393 + goto out_unlock; /* possible? */
22396 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22397 + if (unlikely(!args))
22400 + parent = dentry->d_parent; /* dir inode is locked */
22401 + di_write_lock_parent(parent);
22402 + err = au_test_empty(dentry, &args->whlist);
22403 + if (unlikely(err))
22406 + btop = au_dbtop(dentry);
22407 + bwh = au_dbwh(dentry);
22409 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22411 + err = PTR_ERR(wh_dentry);
22412 + if (IS_ERR(wh_dentry))
22415 + h_dentry = au_h_dptr(dentry, btop);
22418 + if (bindex == btop) {
22419 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22421 + rmdir_later = err;
22425 + /* stop monitoring */
22426 + au_hn_free(au_hi(inode, btop));
22428 + /* dir inode is locked */
22429 + IMustLock(d_inode(wh_dentry->d_parent));
22434 + vfsub_dead_dir(inode);
22435 + au_set_dbdiropq(dentry, -1);
22436 + epilog(dir, dentry, bindex);
22438 + if (rmdir_later) {
22439 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22443 + goto out_unpin; /* success */
22451 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22458 + au_unpin(&a->pin);
22462 + di_write_unlock(parent);
22464 + au_whtmp_rmdir_free(args);
22466 + aufs_read_unlock(dentry, AuLock_DW);
22473 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22474 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22475 +++ linux/fs/aufs/i_op_ren.c 2018-06-04 09:08:09.184746078 +0200
22478 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22480 + * This program, aufs is free software; you can redistribute it and/or modify
22481 + * it under the terms of the GNU General Public License as published by
22482 + * the Free Software Foundation; either version 2 of the License, or
22483 + * (at your option) any later version.
22485 + * This program is distributed in the hope that it will be useful,
22486 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22487 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22488 + * GNU General Public License for more details.
22490 + * You should have received a copy of the GNU General Public License
22491 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22495 + * inode operation (rename entry)
22496 + * todo: this is crazy monster
22501 +enum { AuSRC, AuDST, AuSrcDst };
22502 +enum { AuPARENT, AuCHILD, AuParentChild };
22504 +#define AuRen_ISDIR_SRC 1
22505 +#define AuRen_ISDIR_DST (1 << 1)
22506 +#define AuRen_ISSAMEDIR (1 << 2)
22507 +#define AuRen_WHSRC (1 << 3)
22508 +#define AuRen_WHDST (1 << 4)
22509 +#define AuRen_MNT_WRITE (1 << 5)
22510 +#define AuRen_DT_DSTDIR (1 << 6)
22511 +#define AuRen_DIROPQ_SRC (1 << 7)
22512 +#define AuRen_DIROPQ_DST (1 << 8)
22513 +#define AuRen_DIRREN (1 << 9)
22514 +#define AuRen_DROPPED_SRC (1 << 10)
22515 +#define AuRen_DROPPED_DST (1 << 11)
22516 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22517 +#define au_fset_ren(flags, name) \
22518 + do { (flags) |= AuRen_##name; } while (0)
22519 +#define au_fclr_ren(flags, name) \
22520 + do { (flags) &= ~AuRen_##name; } while (0)
22522 +#ifndef CONFIG_AUFS_DIRREN
22523 +#undef AuRen_DIRREN
22524 +#define AuRen_DIRREN 0
22527 +struct au_ren_args {
22529 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22531 + struct inode *dir, *inode;
22532 + struct au_hinode *hdir, *hinode;
22533 + struct au_dtime dt[AuParentChild];
22534 + aufs_bindex_t btop, bdiropq;
22537 +#define src_dentry sd[AuSRC].dentry
22538 +#define src_dir sd[AuSRC].dir
22539 +#define src_inode sd[AuSRC].inode
22540 +#define src_h_dentry sd[AuSRC].h_dentry
22541 +#define src_parent sd[AuSRC].parent
22542 +#define src_h_parent sd[AuSRC].h_parent
22543 +#define src_wh_dentry sd[AuSRC].wh_dentry
22544 +#define src_hdir sd[AuSRC].hdir
22545 +#define src_hinode sd[AuSRC].hinode
22546 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22547 +#define src_dt sd[AuSRC].dt
22548 +#define src_btop sd[AuSRC].btop
22549 +#define src_bdiropq sd[AuSRC].bdiropq
22551 +#define dst_dentry sd[AuDST].dentry
22552 +#define dst_dir sd[AuDST].dir
22553 +#define dst_inode sd[AuDST].inode
22554 +#define dst_h_dentry sd[AuDST].h_dentry
22555 +#define dst_parent sd[AuDST].parent
22556 +#define dst_h_parent sd[AuDST].h_parent
22557 +#define dst_wh_dentry sd[AuDST].wh_dentry
22558 +#define dst_hdir sd[AuDST].hdir
22559 +#define dst_hinode sd[AuDST].hinode
22560 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22561 +#define dst_dt sd[AuDST].dt
22562 +#define dst_btop sd[AuDST].btop
22563 +#define dst_bdiropq sd[AuDST].bdiropq
22565 + struct dentry *h_trap;
22566 + struct au_branch *br;
22567 + struct path h_path;
22568 + struct au_nhash whlist;
22569 + aufs_bindex_t btgt, src_bwh;
22572 + unsigned short auren_flags;
22573 + unsigned char flags; /* syscall parameter */
22574 + unsigned char exchange;
22577 + struct au_whtmp_rmdir *thargs;
22578 + struct dentry *h_dst;
22579 + struct au_hinode *h_root;
22582 +/* ---------------------------------------------------------------------- */
22585 + * functions for reverting.
22586 + * when an error happened in a single rename systemcall, we should revert
22587 + * everything as if nothing happened.
22588 + * we don't need to revert the copied-up/down the parent dir since they are
22592 +#define RevertFailure(fmt, ...) do { \
22593 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22594 + ##__VA_ARGS__, err, rerr); \
22598 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22601 + struct dentry *d;
22602 +#define src_or_dst(member) a->sd[idx].member
22604 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22605 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22606 + rerr = au_diropq_remove(d, a->btgt);
22607 + au_hn_inode_unlock(src_or_dst(hinode));
22608 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22610 + RevertFailure("remove diropq %pd", d);
22612 +#undef src_or_dst_
22615 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22617 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22618 + au_ren_do_rev_diropq(err, a, AuSRC);
22619 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22620 + au_ren_do_rev_diropq(err, a, AuDST);
22623 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22626 + struct inode *delegated;
22628 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22629 + a->src_h_parent);
22630 + rerr = PTR_ERR(a->h_path.dentry);
22631 + if (IS_ERR(a->h_path.dentry)) {
22632 + RevertFailure("lkup one %pd", a->src_dentry);
22636 + delegated = NULL;
22637 + rerr = vfsub_rename(a->dst_h_dir,
22638 + au_h_dptr(a->src_dentry, a->btgt),
22639 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22640 + if (unlikely(rerr == -EWOULDBLOCK)) {
22641 + pr_warn("cannot retry for NFSv4 delegation"
22642 + " for an internal rename\n");
22645 + d_drop(a->h_path.dentry);
22646 + dput(a->h_path.dentry);
22647 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22649 + RevertFailure("rename %pd", a->src_dentry);
22652 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22655 + struct inode *delegated;
22657 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22658 + a->dst_h_parent);
22659 + rerr = PTR_ERR(a->h_path.dentry);
22660 + if (IS_ERR(a->h_path.dentry)) {
22661 + RevertFailure("lkup one %pd", a->dst_dentry);
22664 + if (d_is_positive(a->h_path.dentry)) {
22665 + d_drop(a->h_path.dentry);
22666 + dput(a->h_path.dentry);
22670 + delegated = NULL;
22671 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22672 + &delegated, a->flags);
22673 + if (unlikely(rerr == -EWOULDBLOCK)) {
22674 + pr_warn("cannot retry for NFSv4 delegation"
22675 + " for an internal rename\n");
22678 + d_drop(a->h_path.dentry);
22679 + dput(a->h_path.dentry);
22681 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22683 + RevertFailure("rename %pd", a->h_dst);
22686 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22690 + a->h_path.dentry = a->src_wh_dentry;
22691 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22692 + au_set_dbwh(a->src_dentry, a->src_bwh);
22694 + RevertFailure("unlink %pd", a->src_wh_dentry);
22696 +#undef RevertFailure
22698 +/* ---------------------------------------------------------------------- */
22701 + * when we have to copyup the renaming entry, do it with the rename-target name
22702 + * in order to minimize the cost (the later actual rename is unnecessary).
22703 + * otherwise rename it on the target branch.
22705 +static int au_ren_or_cpup(struct au_ren_args *a)
22708 + struct dentry *d;
22709 + struct inode *delegated;
22711 + d = a->src_dentry;
22712 + if (au_dbtop(d) == a->btgt) {
22713 + a->h_path.dentry = a->dst_h_dentry;
22714 + AuDebugOn(au_dbtop(d) != a->btgt);
22715 + delegated = NULL;
22716 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22717 + a->dst_h_dir, &a->h_path, &delegated,
22719 + if (unlikely(err == -EWOULDBLOCK)) {
22720 + pr_warn("cannot retry for NFSv4 delegation"
22721 + " for an internal rename\n");
22727 + if (!err && a->h_dst)
22728 + /* it will be set to dinfo later */
22734 +/* cf. aufs_rmdir() */
22735 +static int au_ren_del_whtmp(struct au_ren_args *a)
22738 + struct inode *dir;
22740 + dir = a->dst_dir;
22741 + SiMustAnyLock(dir->i_sb);
22742 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22743 + au_sbi(dir->i_sb)->si_dirwh)
22744 + || au_test_fs_remote(a->h_dst->d_sb)) {
22745 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22746 + if (unlikely(err))
22747 + pr_warn("failed removing whtmp dir %pd (%d), "
22748 + "ignored.\n", a->h_dst, err);
22750 + au_nhash_wh_free(&a->thargs->whlist);
22751 + a->thargs->whlist = a->whlist;
22752 + a->whlist.nh_num = 0;
22753 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22755 + a->thargs = NULL;
22761 +/* make it 'opaque' dir. */
22762 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22765 + struct dentry *d, *diropq;
22766 +#define src_or_dst(member) a->sd[idx].member
22769 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22770 + src_or_dst(bdiropq) = au_dbdiropq(d);
22771 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22772 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22773 + diropq = au_diropq_create(d, a->btgt);
22774 + au_hn_inode_unlock(src_or_dst(hinode));
22775 + if (IS_ERR(diropq))
22776 + err = PTR_ERR(diropq);
22780 +#undef src_or_dst_
22784 +static int au_ren_diropq(struct au_ren_args *a)
22787 + unsigned char always;
22788 + struct dentry *d;
22791 + d = a->dst_dentry; /* already renamed on the branch */
22792 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22793 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22794 + && !au_ftest_ren(a->auren_flags, DIRREN)
22795 + && a->btgt != au_dbdiropq(a->src_dentry)
22796 + && (a->dst_wh_dentry
22797 + || a->btgt <= au_dbdiropq(d)
22798 + /* hide the lower to keep xino */
22799 + /* the lowers may not be a dir, but we hide them anyway */
22800 + || a->btgt < au_dbbot(d)
22803 + err = au_ren_do_diropq(a, AuSRC);
22804 + if (unlikely(err))
22806 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22808 + if (!a->exchange)
22809 + goto out; /* success */
22811 + d = a->src_dentry; /* already renamed on the branch */
22812 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22813 + && a->btgt != au_dbdiropq(a->dst_dentry)
22814 + && (a->btgt < au_dbdiropq(d)
22815 + || a->btgt < au_dbbot(d)
22817 + AuDbgDentry(a->src_dentry);
22818 + AuDbgDentry(a->dst_dentry);
22819 + err = au_ren_do_diropq(a, AuDST);
22820 + if (unlikely(err))
22821 + goto out_rev_src;
22822 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22824 + goto out; /* success */
22827 + AuDbg("err %d, reverting src\n", err);
22828 + au_ren_rev_diropq(err, a);
22833 +static int do_rename(struct au_ren_args *a)
22836 + struct dentry *d, *h_d;
22838 + if (!a->exchange) {
22839 + /* prepare workqueue args for asynchronous rmdir */
22840 + h_d = a->dst_h_dentry;
22841 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22842 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22843 + && d_is_positive(h_d)) {
22845 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22847 + if (unlikely(!a->thargs))
22849 + a->h_dst = dget(h_d);
22852 + /* create whiteout for src_dentry */
22853 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22854 + a->src_bwh = au_dbwh(a->src_dentry);
22855 + AuDebugOn(a->src_bwh >= 0);
22856 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22857 + a->src_h_parent);
22858 + err = PTR_ERR(a->src_wh_dentry);
22859 + if (IS_ERR(a->src_wh_dentry))
22863 + /* lookup whiteout for dentry */
22864 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22865 + h_d = au_wh_lkup(a->dst_h_parent,
22866 + &a->dst_dentry->d_name, a->br);
22867 + err = PTR_ERR(h_d);
22870 + if (d_is_negative(h_d))
22873 + a->dst_wh_dentry = h_d;
22876 + /* rename dentry to tmpwh */
22878 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22879 + if (unlikely(err))
22882 + d = a->dst_dentry;
22883 + au_set_h_dptr(d, a->btgt, NULL);
22884 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22885 + if (unlikely(err))
22887 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22891 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22893 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22894 + && d_is_positive(a->dst_h_dentry)
22895 + && a->src_btop != a->btgt);
22898 + /* rename by vfs_rename or cpup */
22899 + err = au_ren_or_cpup(a);
22900 + if (unlikely(err))
22901 + /* leave the copied-up one */
22904 + /* make dir opaque */
22905 + err = au_ren_diropq(a);
22906 + if (unlikely(err))
22909 + /* update target timestamps */
22910 + if (a->exchange) {
22911 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22912 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22913 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22914 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22916 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22917 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22918 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22919 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22921 + if (!a->exchange) {
22922 + /* remove whiteout for dentry */
22923 + if (a->dst_wh_dentry) {
22924 + a->h_path.dentry = a->dst_wh_dentry;
22925 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22927 + if (unlikely(err))
22931 + /* remove whtmp */
22933 + au_ren_del_whtmp(a); /* ignore this error */
22935 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22938 + goto out_success;
22941 + au_ren_rev_diropq(err, a);
22943 + au_ren_rev_rename(err, a);
22947 + au_ren_rev_whtmp(err, a);
22949 + dput(a->dst_wh_dentry);
22950 + a->dst_wh_dentry = NULL;
22952 + if (a->src_wh_dentry)
22953 + au_ren_rev_whsrc(err, a);
22955 + dput(a->src_wh_dentry);
22956 + dput(a->dst_wh_dentry);
22960 + au_whtmp_rmdir_free(a->thargs);
22961 + a->thargs = NULL;
22967 +/* ---------------------------------------------------------------------- */
22970 + * test if @dentry dir can be rename destination or not.
22971 + * success means, it is a logically empty dir.
22973 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22975 + return au_test_empty(dentry, whlist);
22979 + * test if @a->src_dentry dir can be rename source or not.
22980 + * if it can, return 0.
22982 + * - it is a logically empty dir.
22983 + * - or, it exists on writable branch and has no children including whiteouts
22984 + * on the lower branch unless DIRREN is on.
22986 +static int may_rename_srcdir(struct au_ren_args *a)
22989 + unsigned int rdhash;
22990 + aufs_bindex_t btop, btgt;
22991 + struct dentry *dentry;
22992 + struct super_block *sb;
22993 + struct au_sbinfo *sbinfo;
22995 + dentry = a->src_dentry;
22996 + sb = dentry->d_sb;
22997 + sbinfo = au_sbi(sb);
22998 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22999 + au_fset_ren(a->auren_flags, DIRREN);
23002 + btop = au_dbtop(dentry);
23003 + if (btop != btgt) {
23004 + struct au_nhash whlist;
23006 + SiMustAnyLock(sb);
23007 + rdhash = sbinfo->si_rdhash;
23009 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23011 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23012 + if (unlikely(err))
23014 + err = au_test_empty(dentry, &whlist);
23015 + au_nhash_wh_free(&whlist);
23019 + if (btop == au_dbtaildir(dentry))
23020 + return 0; /* success */
23022 + err = au_test_empty_lower(dentry);
23025 + if (err == -ENOTEMPTY) {
23026 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23029 + AuWarn1("renaming dir who has child(ren) on multiple "
23030 + "branches, is not supported\n");
23037 +/* side effect: sets whlist and h_dentry */
23038 +static int au_ren_may_dir(struct au_ren_args *a)
23041 + unsigned int rdhash;
23042 + struct dentry *d;
23044 + d = a->dst_dentry;
23045 + SiMustAnyLock(d->d_sb);
23048 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23049 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23051 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23052 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23053 + if (unlikely(err))
23056 + if (!a->exchange) {
23057 + au_set_dbtop(d, a->dst_btop);
23058 + err = may_rename_dstdir(d, &a->whlist);
23059 + au_set_dbtop(d, a->btgt);
23061 + err = may_rename_srcdir(a);
23063 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23064 + if (unlikely(err))
23067 + d = a->src_dentry;
23068 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23069 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23070 + err = may_rename_srcdir(a);
23071 + if (unlikely(err)) {
23072 + au_nhash_wh_free(&a->whlist);
23073 + a->whlist.nh_num = 0;
23080 +/* ---------------------------------------------------------------------- */
23083 + * simple tests for rename.
23084 + * following the checks in vfs, plus the parent-child relationship.
23086 +static int au_may_ren(struct au_ren_args *a)
23089 + struct inode *h_inode;
23091 + if (a->src_btop == a->btgt) {
23092 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23093 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23094 + if (unlikely(err))
23097 + if (unlikely(a->src_h_dentry == a->h_trap))
23102 + if (a->dst_btop != a->btgt)
23105 + err = -ENOTEMPTY;
23106 + if (unlikely(a->dst_h_dentry == a->h_trap))
23110 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23111 + if (d_really_is_negative(a->dst_dentry)) {
23112 + if (d_is_negative(a->dst_h_dentry))
23113 + err = au_may_add(a->dst_dentry, a->btgt,
23114 + a->dst_h_parent, isdir);
23116 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23118 + h_inode = d_inode(a->dst_h_dentry);
23119 + if (h_inode->i_nlink)
23120 + err = au_may_del(a->dst_dentry, a->btgt,
23121 + a->dst_h_parent, isdir);
23125 + if (unlikely(err == -ENOENT || err == -EEXIST))
23131 +/* ---------------------------------------------------------------------- */
23136 + * - src_dir and dir by lock_rename()
23137 + * - inode if exitsts
23140 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23142 + * + di_write_lock2_child()
23143 + * + di_write_lock_child()
23144 + * + ii_write_lock_child()
23145 + * + di_write_lock_child2()
23146 + * + ii_write_lock_child2()
23147 + * + src_parent and parent
23148 + * + di_write_lock_parent()
23149 + * + ii_write_lock_parent()
23150 + * + di_write_lock_parent2()
23151 + * + ii_write_lock_parent2()
23152 + * + lower src_dir and dir by vfsub_lock_rename()
23153 + * + verify the every relationships between child and parent. if any
23154 + * of them failed, unlock all and return -EBUSY.
23156 +static void au_ren_unlock(struct au_ren_args *a)
23158 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23159 + a->dst_h_parent, a->dst_hdir);
23160 + if (au_ftest_ren(a->auren_flags, DIRREN)
23162 + au_hn_inode_unlock(a->h_root);
23163 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23164 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23167 +static int au_ren_lock(struct au_ren_args *a)
23170 + unsigned int udba;
23173 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23174 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23175 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23176 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23178 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23179 + if (unlikely(err))
23181 + au_fset_ren(a->auren_flags, MNT_WRITE);
23182 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23183 + struct dentry *root;
23184 + struct inode *dir;
23187 + * sbinfo is already locked, so this ii_read_lock is
23188 + * unnecessary. but our debugging feature checks it.
23190 + root = a->src_inode->i_sb->s_root;
23191 + if (root != a->src_parent && root != a->dst_parent) {
23192 + dir = d_inode(root);
23193 + ii_read_lock_parent3(dir);
23194 + a->h_root = au_hi(dir, a->btgt);
23195 + ii_read_unlock(dir);
23196 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23199 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23200 + a->dst_h_parent, a->dst_hdir);
23201 + udba = au_opt_udba(a->src_dentry->d_sb);
23202 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23203 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23204 + err = au_busy_or_stale();
23205 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23206 + err = au_h_verify(a->src_h_dentry, udba,
23207 + d_inode(a->src_h_parent), a->src_h_parent,
23209 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23210 + err = au_h_verify(a->dst_h_dentry, udba,
23211 + d_inode(a->dst_h_parent), a->dst_h_parent,
23214 + goto out; /* success */
23216 + err = au_busy_or_stale();
23217 + au_ren_unlock(a);
23223 +/* ---------------------------------------------------------------------- */
23225 +static void au_ren_refresh_dir(struct au_ren_args *a)
23227 + struct inode *dir;
23229 + dir = a->dst_dir;
23230 + inode_inc_iversion(dir);
23231 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23232 + /* is this updating defined in POSIX? */
23233 + au_cpup_attr_timesizes(a->src_inode);
23234 + au_cpup_attr_nlink(dir, /*force*/1);
23236 + au_dir_ts(dir, a->btgt);
23238 + if (a->exchange) {
23239 + dir = a->src_dir;
23240 + inode_inc_iversion(dir);
23241 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23242 + /* is this updating defined in POSIX? */
23243 + au_cpup_attr_timesizes(a->dst_inode);
23244 + au_cpup_attr_nlink(dir, /*force*/1);
23246 + au_dir_ts(dir, a->btgt);
23249 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23252 + dir = a->src_dir;
23253 + inode_inc_iversion(dir);
23254 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23255 + au_cpup_attr_nlink(dir, /*force*/1);
23256 + au_dir_ts(dir, a->btgt);
23259 +static void au_ren_refresh(struct au_ren_args *a)
23261 + aufs_bindex_t bbot, bindex;
23262 + struct dentry *d, *h_d;
23263 + struct inode *i, *h_i;
23264 + struct super_block *sb;
23266 + d = a->dst_dentry;
23269 + /* already dget-ed by au_ren_or_cpup() */
23270 + au_set_h_dptr(d, a->btgt, a->h_dst);
23272 + i = a->dst_inode;
23274 + if (!a->exchange) {
23275 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23276 + vfsub_drop_nlink(i);
23278 + vfsub_dead_dir(i);
23279 + au_cpup_attr_timesizes(i);
23281 + au_update_dbrange(d, /*do_put_zero*/1);
23283 + au_cpup_attr_nlink(i, /*force*/1);
23286 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23287 + au_set_h_dptr(d, bindex, NULL);
23288 + bbot = au_dbbot(d);
23289 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23290 + au_set_h_dptr(d, bindex, NULL);
23291 + au_update_dbrange(d, /*do_put_zero*/0);
23295 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23296 + d_drop(a->src_dentry);
23297 + if (au_ftest_ren(a->auren_flags, DIRREN))
23298 + au_set_dbwh(a->src_dentry, -1);
23302 + d = a->src_dentry;
23303 + au_set_dbwh(d, -1);
23304 + bbot = au_dbbot(d);
23305 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23306 + h_d = au_h_dptr(d, bindex);
23308 + au_set_h_dptr(d, bindex, NULL);
23310 + au_set_dbbot(d, a->btgt);
23313 + i = a->src_inode;
23314 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23315 + return; /* success */
23317 + bbot = au_ibbot(i);
23318 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23319 + h_i = au_h_iptr(i, bindex);
23321 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23322 + /* ignore this error */
23323 + au_set_h_iptr(i, bindex, NULL, 0);
23326 + au_set_ibbot(i, a->btgt);
23329 +/* ---------------------------------------------------------------------- */
23331 +/* mainly for link(2) and rename(2) */
23332 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23334 + aufs_bindex_t bdiropq, bwh;
23335 + struct dentry *parent;
23336 + struct au_branch *br;
23338 + parent = dentry->d_parent;
23339 + IMustLock(d_inode(parent)); /* dir is locked */
23341 + bdiropq = au_dbdiropq(parent);
23342 + bwh = au_dbwh(dentry);
23343 + br = au_sbr(dentry->d_sb, btgt);
23344 + if (au_br_rdonly(br)
23345 + || (0 <= bdiropq && bdiropq < btgt)
23346 + || (0 <= bwh && bwh < btgt))
23349 + AuDbg("btgt %d\n", btgt);
23353 +/* sets src_btop, dst_btop and btgt */
23354 +static int au_ren_wbr(struct au_ren_args *a)
23357 + struct au_wr_dir_args wr_dir_args = {
23358 + /* .force_btgt = -1, */
23359 + .flags = AuWrDir_ADD_ENTRY
23362 + a->src_btop = au_dbtop(a->src_dentry);
23363 + a->dst_btop = au_dbtop(a->dst_dentry);
23364 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23365 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23366 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23367 + wr_dir_args.force_btgt = a->src_btop;
23368 + if (a->dst_inode && a->dst_btop < a->src_btop)
23369 + wr_dir_args.force_btgt = a->dst_btop;
23370 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23371 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23374 + au_update_dbtop(a->dst_dentry);
23379 +static void au_ren_dt(struct au_ren_args *a)
23381 + a->h_path.dentry = a->src_h_parent;
23382 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23383 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23384 + a->h_path.dentry = a->dst_h_parent;
23385 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23388 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23389 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23393 + a->h_path.dentry = a->src_h_dentry;
23394 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23395 + if (d_is_positive(a->dst_h_dentry)) {
23396 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23397 + a->h_path.dentry = a->dst_h_dentry;
23398 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23402 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23404 + struct dentry *h_d;
23405 + struct inode *h_inode;
23407 + au_dtime_revert(a->src_dt + AuPARENT);
23408 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23409 + au_dtime_revert(a->dst_dt + AuPARENT);
23411 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23412 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23413 + h_inode = d_inode(h_d);
23414 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23415 + au_dtime_revert(a->src_dt + AuCHILD);
23416 + inode_unlock(h_inode);
23418 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23419 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23420 + h_inode = d_inode(h_d);
23421 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23422 + au_dtime_revert(a->dst_dt + AuCHILD);
23423 + inode_unlock(h_inode);
23428 +/* ---------------------------------------------------------------------- */
23430 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23431 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23432 + unsigned int _flags)
23434 + int err, lock_flags;
23436 + /* reduce stack space */
23437 + struct au_ren_args *a;
23438 + struct au_pin pin;
23440 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23441 + IMustLock(_src_dir);
23442 + IMustLock(_dst_dir);
23445 + if (unlikely(_flags & RENAME_WHITEOUT))
23449 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23450 + a = kzalloc(sizeof(*a), GFP_NOFS);
23451 + if (unlikely(!a))
23454 + a->flags = _flags;
23455 + a->exchange = _flags & RENAME_EXCHANGE;
23456 + a->src_dir = _src_dir;
23457 + a->src_dentry = _src_dentry;
23458 + a->src_inode = NULL;
23459 + if (d_really_is_positive(a->src_dentry))
23460 + a->src_inode = d_inode(a->src_dentry);
23461 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23462 + a->dst_dir = _dst_dir;
23463 + a->dst_dentry = _dst_dentry;
23464 + a->dst_inode = NULL;
23465 + if (d_really_is_positive(a->dst_dentry))
23466 + a->dst_inode = d_inode(a->dst_dentry);
23467 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23468 + if (a->dst_inode) {
23470 + * if EXCHANGE && src is non-dir && dst is dir,
23471 + * dst is not locked.
23473 + /* IMustLock(a->dst_inode); */
23474 + au_igrab(a->dst_inode);
23478 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23479 + if (d_is_dir(a->src_dentry)) {
23480 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23481 + if (unlikely(!a->exchange
23482 + && d_really_is_positive(a->dst_dentry)
23483 + && !d_is_dir(a->dst_dentry)))
23485 + lock_flags |= AuLock_DIRS;
23487 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23488 + au_fset_ren(a->auren_flags, ISDIR_DST);
23489 + if (unlikely(!a->exchange
23490 + && d_really_is_positive(a->src_dentry)
23491 + && !d_is_dir(a->src_dentry)))
23493 + lock_flags |= AuLock_DIRS;
23495 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23497 + if (unlikely(err))
23500 + err = au_d_hashed_positive(a->src_dentry);
23501 + if (unlikely(err))
23504 + if (a->dst_inode) {
23506 + * If it is a dir, VFS unhash it before this
23507 + * function. It means we cannot rely upon d_unhashed().
23509 + if (unlikely(!a->dst_inode->i_nlink))
23511 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23512 + err = au_d_hashed_positive(a->dst_dentry);
23513 + if (unlikely(err && !a->exchange))
23515 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23517 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23521 + * is it possible?
23522 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23523 + * there may exist a problem somewhere else.
23526 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23529 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23530 + di_write_lock_parent(a->dst_parent);
23532 + /* which branch we process */
23533 + err = au_ren_wbr(a);
23534 + if (unlikely(err < 0))
23536 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23537 + a->h_path.mnt = au_br_mnt(a->br);
23539 + /* are they available to be renamed */
23540 + err = au_ren_may_dir(a);
23541 + if (unlikely(err))
23542 + goto out_children;
23544 + /* prepare the writable parent dir on the same branch */
23545 + if (a->dst_btop == a->btgt) {
23546 + au_fset_ren(a->auren_flags, WHDST);
23548 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23549 + if (unlikely(err))
23550 + goto out_children;
23554 + if (!a->exchange) {
23555 + if (a->src_dir != a->dst_dir) {
23557 + * this temporary unlock is safe,
23558 + * because both dir->i_mutex are locked.
23560 + di_write_unlock(a->dst_parent);
23561 + di_write_lock_parent(a->src_parent);
23562 + err = au_wr_dir_need_wh(a->src_dentry,
23563 + au_ftest_ren(a->auren_flags,
23566 + di_write_unlock(a->src_parent);
23567 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23569 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23571 + err = au_wr_dir_need_wh(a->src_dentry,
23572 + au_ftest_ren(a->auren_flags,
23576 + if (unlikely(err < 0))
23577 + goto out_children;
23579 + au_fset_ren(a->auren_flags, WHSRC);
23582 + if (a->src_btop != a->btgt) {
23583 + err = au_pin(&pin, a->src_dentry, a->btgt,
23584 + au_opt_udba(a->src_dentry->d_sb),
23585 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23587 + struct au_cp_generic cpg = {
23588 + .dentry = a->src_dentry,
23590 + .bsrc = a->src_btop,
23593 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23595 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23596 + err = au_sio_cpup_simple(&cpg);
23599 + if (unlikely(err))
23600 + goto out_children;
23601 + a->src_btop = a->btgt;
23602 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23603 + if (!a->exchange)
23604 + au_fset_ren(a->auren_flags, WHSRC);
23608 + if (a->exchange && a->dst_inode
23609 + && a->dst_btop != a->btgt) {
23610 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23611 + au_opt_udba(a->dst_dentry->d_sb),
23612 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23614 + struct au_cp_generic cpg = {
23615 + .dentry = a->dst_dentry,
23617 + .bsrc = a->dst_btop,
23620 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23622 + err = au_sio_cpup_simple(&cpg);
23625 + if (unlikely(err))
23626 + goto out_children;
23627 + a->dst_btop = a->btgt;
23628 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23631 + /* lock them all */
23632 + err = au_ren_lock(a);
23633 + if (unlikely(err))
23634 + /* leave the copied-up one */
23635 + goto out_children;
23637 + if (!a->exchange) {
23638 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23639 + err = au_may_ren(a);
23640 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23641 + err = -ENAMETOOLONG;
23642 + if (unlikely(err))
23646 + /* store timestamps to be revertible */
23649 + /* store dirren info */
23650 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23651 + err = au_dr_rename(a->src_dentry, a->btgt,
23652 + &a->dst_dentry->d_name, &rev);
23654 + if (unlikely(err))
23659 + err = do_rename(a);
23660 + if (unlikely(err))
23663 + if (au_ftest_ren(a->auren_flags, DIRREN))
23664 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23666 + /* update dir attributes */
23667 + au_ren_refresh_dir(a);
23669 + /* dput/iput all lower dentries */
23670 + au_ren_refresh(a);
23672 + goto out_hdir; /* success */
23675 + if (au_ftest_ren(a->auren_flags, DIRREN))
23676 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23678 + au_ren_rev_dt(err, a);
23680 + au_ren_unlock(a);
23682 + au_nhash_wh_free(&a->whlist);
23683 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23684 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23685 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23686 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23690 + if (d_unhashed(a->src_dentry))
23691 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23692 + if (d_unhashed(a->dst_dentry))
23693 + au_fset_ren(a->auren_flags, DROPPED_DST);
23694 + if (!a->exchange)
23695 + d_move(a->src_dentry, a->dst_dentry);
23697 + d_exchange(a->src_dentry, a->dst_dentry);
23698 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23699 + d_drop(a->dst_dentry);
23701 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23702 + d_drop(a->src_dentry);
23704 + au_update_dbtop(a->dst_dentry);
23705 + if (!a->dst_inode)
23706 + d_drop(a->dst_dentry);
23708 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23709 + di_write_unlock(a->dst_parent);
23711 + di_write_unlock2(a->src_parent, a->dst_parent);
23713 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23715 + iput(a->dst_inode);
23717 + au_whtmp_rmdir_free(a->thargs);
23723 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23724 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23725 +++ linux/fs/aufs/Kconfig 2018-06-04 09:08:09.181412645 +0200
23727 +# SPDX-License-Identifier: GPL-2.0
23729 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23731 + Aufs is a stackable unification filesystem such as Unionfs,
23732 + which unifies several directories and provides a merged single
23734 + In the early days, aufs was entirely re-designed and
23735 + re-implemented Unionfs Version 1.x series. Introducing many
23736 + original ideas, approaches and improvements, it becomes totally
23737 + different from Unionfs while keeping the basic features.
23741 + prompt "Maximum number of branches"
23742 + default AUFS_BRANCH_MAX_127
23744 + Specifies the maximum number of branches (or member directories)
23745 + in a single aufs. The larger value consumes more system
23746 + resources and has a minor impact to performance.
23747 +config AUFS_BRANCH_MAX_127
23750 + Specifies the maximum number of branches (or member directories)
23751 + in a single aufs. The larger value consumes more system
23752 + resources and has a minor impact to performance.
23753 +config AUFS_BRANCH_MAX_511
23756 + Specifies the maximum number of branches (or member directories)
23757 + in a single aufs. The larger value consumes more system
23758 + resources and has a minor impact to performance.
23759 +config AUFS_BRANCH_MAX_1023
23762 + Specifies the maximum number of branches (or member directories)
23763 + in a single aufs. The larger value consumes more system
23764 + resources and has a minor impact to performance.
23765 +config AUFS_BRANCH_MAX_32767
23768 + Specifies the maximum number of branches (or member directories)
23769 + in a single aufs. The larger value consumes more system
23770 + resources and has a minor impact to performance.
23773 +config AUFS_SBILIST
23775 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23778 + Automatic configuration for internal use.
23779 + When aufs supports Magic SysRq or /proc, enabled automatically.
23781 +config AUFS_HNOTIFY
23782 + bool "Detect direct branch access (bypassing aufs)"
23784 + If you want to modify files on branches directly, eg. bypassing aufs,
23785 + and want aufs to detect the changes of them fully, then enable this
23786 + option and use 'udba=notify' mount option.
23787 + Currently there is only one available configuration, "fsnotify".
23788 + It will have a negative impact to the performance.
23789 + See detail in aufs.5.
23792 + prompt "method" if AUFS_HNOTIFY
23793 + default AUFS_HFSNOTIFY
23794 +config AUFS_HFSNOTIFY
23799 +config AUFS_EXPORT
23800 + bool "NFS-exportable aufs"
23801 + depends on EXPORTFS
23803 + If you want to export your mounted aufs via NFS, then enable this
23804 + option. There are several requirements for this configuration.
23805 + See detail in aufs.5.
23807 +config AUFS_INO_T_64
23809 + depends on AUFS_EXPORT
23810 + depends on 64BIT && !(ALPHA || S390)
23813 + Automatic configuration for internal use.
23814 + /* typedef unsigned long/int __kernel_ino_t */
23815 + /* alpha and s390x are int */
23818 + bool "support for XATTR/EA (including Security Labels)"
23820 + If your branch fs supports XATTR/EA and you want to make them
23821 + available in aufs too, then enable this opsion and specify the
23822 + branch attributes for EA.
23823 + See detail in aufs.5.
23826 + bool "File-based Hierarchical Storage Management"
23828 + Hierarchical Storage Management (or HSM) is a well-known feature
23829 + in the storage world. Aufs provides this feature as file-based.
23830 + with multiple branches.
23831 + These multiple branches are prioritized, ie. the topmost one
23832 + should be the fastest drive and be used heavily.
23835 + bool "Readdir in userspace"
23837 + Aufs has two methods to provide a merged view for a directory,
23838 + by a user-space library and by kernel-space natively. The latter
23839 + is always enabled but sometimes large and slow.
23840 + If you enable this option, install the library in aufs2-util
23841 + package, and set some environment variables for your readdir(3),
23842 + then the work will be handled in user-space which generally
23843 + shows better performance in most cases.
23844 + See detail in aufs.5.
23846 +config AUFS_DIRREN
23847 + bool "Workaround for rename(2)-ing a directory"
23849 + By default, aufs returns EXDEV error in renameing a dir who has
23850 + his child on the lower branch, since it is a bad idea to issue
23851 + rename(2) internally for every lower branch. But user may not
23852 + accept this behaviour. So here is a workaround to allow such
23853 + rename(2) and store some extra infromation on the writable
23854 + branch. Obviously this costs high (and I don't like it).
23855 + To use this feature, you need to enable this configuration AND
23856 + to specify the mount option `dirren.'
23857 + See details in aufs.5 and the design documents.
23860 + bool "Show whiteouts"
23862 + If you want to make the whiteouts in aufs visible, then enable
23863 + this option and specify 'shwh' mount option. Although it may
23864 + sounds like philosophy or something, but in technically it
23865 + simply shows the name of whiteout with keeping its behaviour.
23867 +config AUFS_BR_RAMFS
23868 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23870 + If you want to use ramfs as an aufs branch fs, then enable this
23871 + option. Generally tmpfs is recommended.
23872 + Aufs prohibited them to be a branch fs by default, because
23873 + initramfs becomes unusable after switch_root or something
23874 + generally. If you sets initramfs as an aufs branch and boot your
23875 + system by switch_root, you will meet a problem easily since the
23876 + files in initramfs may be inaccessible.
23877 + Unless you are going to use ramfs as an aufs branch fs without
23878 + switch_root or something, leave it N.
23880 +config AUFS_BR_FUSE
23881 + bool "Fuse fs as an aufs branch"
23882 + depends on FUSE_FS
23885 + If you want to use fuse-based userspace filesystem as an aufs
23886 + branch fs, then enable this option.
23887 + It implements the internal poll(2) operation which is
23888 + implemented by fuse only (curretnly).
23893 + Automatic configuration for internal use.
23895 +config AUFS_BR_HFSPLUS
23896 + bool "Hfsplus as an aufs branch"
23897 + depends on HFSPLUS_FS
23900 + If you want to use hfsplus fs as an aufs branch fs, then enable
23901 + this option. This option introduces a small overhead at
23902 + copying-up a file on hfsplus.
23904 +config AUFS_BDEV_LOOP
23906 + depends on BLK_DEV_LOOP
23909 + Automatic configuration for internal use.
23910 + Convert =[ym] into =y.
23913 + bool "Debug aufs"
23915 + Enable this to compile aufs internal debug code.
23916 + It will have a negative impact to the performance.
23918 +config AUFS_MAGIC_SYSRQ
23920 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23923 + Automatic configuration for internal use.
23924 + When aufs supports Magic SysRq, enabled automatically.
23926 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
23927 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
23928 +++ linux/fs/aufs/loop.c 2018-04-15 08:49:13.401150731 +0200
23931 + * Copyright (C) 2005-2018 Junjiro R. Okajima
23933 + * This program, aufs is free software; you can redistribute it and/or modify
23934 + * it under the terms of the GNU General Public License as published by
23935 + * the Free Software Foundation; either version 2 of the License, or
23936 + * (at your option) any later version.
23938 + * This program is distributed in the hope that it will be useful,
23939 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23940 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23941 + * GNU General Public License for more details.
23943 + * You should have received a copy of the GNU General Public License
23944 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23948 + * support for loopback block device as a branch
23953 +/* added into drivers/block/loop.c */
23954 +static struct file *(*backing_file_func)(struct super_block *sb);
23957 + * test if two lower dentries have overlapping branches.
23959 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
23961 + struct super_block *h_sb;
23962 + struct file *backing_file;
23964 + if (unlikely(!backing_file_func)) {
23965 + /* don't load "loop" module here */
23966 + backing_file_func = symbol_get(loop_backing_file);
23967 + if (unlikely(!backing_file_func))
23968 + /* "loop" module is not loaded */
23972 + h_sb = h_adding->d_sb;
23973 + backing_file = backing_file_func(h_sb);
23974 + if (!backing_file)
23977 + h_adding = backing_file->f_path.dentry;
23979 + * h_adding can be local NFS.
23980 + * in this case aufs cannot detect the loop.
23982 + if (unlikely(h_adding->d_sb == sb))
23984 + return !!au_test_subdir(h_adding, sb->s_root);
23987 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
23988 +int au_test_loopback_kthread(void)
23991 + struct task_struct *tsk = current;
23992 + char c, comm[sizeof(tsk->comm)];
23995 + if (tsk->flags & PF_KTHREAD) {
23996 + get_task_comm(comm, tsk);
23998 + ret = ('0' <= c && c <= '9'
23999 + && !strncmp(comm, "loop", 4));
24005 +/* ---------------------------------------------------------------------- */
24007 +#define au_warn_loopback_step 16
24008 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24009 +static unsigned long *au_warn_loopback_array;
24011 +void au_warn_loopback(struct super_block *h_sb)
24013 + int i, new_nelem;
24014 + unsigned long *a, magic;
24015 + static DEFINE_SPINLOCK(spin);
24017 + magic = h_sb->s_magic;
24018 + spin_lock(&spin);
24019 + a = au_warn_loopback_array;
24020 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24021 + if (a[i] == magic) {
24022 + spin_unlock(&spin);
24026 + /* h_sb is new to us, print it */
24027 + if (i < au_warn_loopback_nelem) {
24032 + /* expand the array */
24033 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24034 + a = au_kzrealloc(au_warn_loopback_array,
24035 + au_warn_loopback_nelem * sizeof(unsigned long),
24036 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24037 + /*may_shrink*/0);
24039 + au_warn_loopback_nelem = new_nelem;
24040 + au_warn_loopback_array = a;
24045 + spin_unlock(&spin);
24046 + AuWarn1("realloc failed, ignored\n");
24050 + spin_unlock(&spin);
24051 + pr_warn("you may want to try another patch for loopback file "
24052 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24055 +int au_loopback_init(void)
24058 + struct super_block *sb __maybe_unused;
24060 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24063 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24064 + sizeof(unsigned long), GFP_NOFS);
24065 + if (unlikely(!au_warn_loopback_array))
24071 +void au_loopback_fin(void)
24073 + if (backing_file_func)
24074 + symbol_put(loop_backing_file);
24075 + kfree(au_warn_loopback_array);
24077 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24078 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24079 +++ linux/fs/aufs/loop.h 2018-04-15 08:49:13.401150731 +0200
24082 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24084 + * This program, aufs is free software; you can redistribute it and/or modify
24085 + * it under the terms of the GNU General Public License as published by
24086 + * the Free Software Foundation; either version 2 of the License, or
24087 + * (at your option) any later version.
24089 + * This program is distributed in the hope that it will be useful,
24090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24092 + * GNU General Public License for more details.
24094 + * You should have received a copy of the GNU General Public License
24095 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24099 + * support for loopback mount as a branch
24102 +#ifndef __AUFS_LOOP_H__
24103 +#define __AUFS_LOOP_H__
24108 +struct super_block;
24110 +#ifdef CONFIG_AUFS_BDEV_LOOP
24111 +/* drivers/block/loop.c */
24112 +struct file *loop_backing_file(struct super_block *sb);
24115 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24116 +int au_test_loopback_kthread(void);
24117 +void au_warn_loopback(struct super_block *h_sb);
24119 +int au_loopback_init(void);
24120 +void au_loopback_fin(void);
24122 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24123 + struct dentry *h_adding)
24124 +AuStubInt0(au_test_loopback_kthread, void)
24125 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24127 +AuStubInt0(au_loopback_init, void)
24128 +AuStubVoid(au_loopback_fin, void)
24129 +#endif /* BLK_DEV_LOOP */
24131 +#endif /* __KERNEL__ */
24132 +#endif /* __AUFS_LOOP_H__ */
24133 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24134 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24135 +++ linux/fs/aufs/magic.mk 2018-06-04 09:08:09.188079511 +0200
24137 +# SPDX-License-Identifier: GPL-2.0
24139 +# defined in ${srctree}/fs/fuse/inode.c
24141 +ifdef CONFIG_FUSE_FS
24142 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24145 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24147 +ifdef CONFIG_XFS_FS
24148 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24151 +# defined in ${srctree}/fs/configfs/mount.c
24153 +ifdef CONFIG_CONFIGFS_FS
24154 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24157 +# defined in ${srctree}/fs/ubifs/ubifs.h
24159 +ifdef CONFIG_UBIFS_FS
24160 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24163 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24165 +ifdef CONFIG_HFSPLUS_FS
24166 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24168 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24169 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24170 +++ linux/fs/aufs/Makefile 2018-06-04 09:08:09.181412645 +0200
24172 +# SPDX-License-Identifier: GPL-2.0
24174 +include ${src}/magic.mk
24175 +ifeq (${CONFIG_AUFS_FS},m)
24176 +include ${src}/conf.mk
24178 +-include ${src}/priv_def.mk
24180 +# cf. include/linux/kernel.h
24182 +ccflags-y += -DDEBUG
24183 +# sparse requires the full pathname
24185 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24187 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24190 +obj-$(CONFIG_AUFS_FS) += aufs.o
24191 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24192 + wkq.o vfsub.o dcsub.o \
24193 + cpup.o whout.o wbr_policy.o \
24194 + dinfo.o dentry.o \
24196 + finfo.o file.o f_op.o \
24198 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24202 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24203 +aufs-$(CONFIG_SYSFS) += sysfs.o
24204 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24205 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24206 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24207 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24208 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24209 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24210 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24211 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24212 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24213 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24214 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24215 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24216 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24217 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24218 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24219 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24220 +++ linux/fs/aufs/module.c 2018-04-15 08:49:13.401150731 +0200
24223 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24225 + * This program, aufs is free software; you can redistribute it and/or modify
24226 + * it under the terms of the GNU General Public License as published by
24227 + * the Free Software Foundation; either version 2 of the License, or
24228 + * (at your option) any later version.
24230 + * This program is distributed in the hope that it will be useful,
24231 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24232 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24233 + * GNU General Public License for more details.
24235 + * You should have received a copy of the GNU General Public License
24236 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24240 + * module global variables and operations
24243 +#include <linux/module.h>
24244 +#include <linux/seq_file.h>
24247 +/* shrinkable realloc */
24248 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24256 +#if 0 /* unused */
24263 + AuDebugOn(!new_sz);
24266 + diff = au_kmidx_sub(sz, new_sz);
24272 + /* expand or SLOB */
24273 + p = krealloc(p, new_sz, gfp);
24274 + else if (new_sz < sz && may_shrink) {
24278 + q = kmalloc(new_sz, gfp);
24281 + memcpy(q, p, new_sz);
24293 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24296 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24297 + if (p && new_sz > nused)
24298 + memset(p + nused, 0, new_sz - nused);
24302 +/* ---------------------------------------------------------------------- */
24306 +struct kmem_cache *au_cache[AuCache_Last];
24308 +static void au_cache_fin(void)
24313 + * Make sure all delayed rcu free inodes are flushed before we
24318 + /* excluding AuCache_HNOTIFY */
24319 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24320 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24321 + kmem_cache_destroy(au_cache[i]);
24322 + au_cache[i] = NULL;
24326 +static int __init au_cache_init(void)
24328 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24329 + if (au_cache[AuCache_DINFO])
24330 + /* SLAB_DESTROY_BY_RCU */
24331 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24332 + au_icntnr_init_once);
24333 + if (au_cache[AuCache_ICNTNR])
24334 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24335 + au_fi_init_once);
24336 + if (au_cache[AuCache_FINFO])
24337 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24338 + if (au_cache[AuCache_VDIR])
24339 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24340 + if (au_cache[AuCache_DEHSTR])
24347 +/* ---------------------------------------------------------------------- */
24349 +int au_dir_roflags;
24351 +#ifdef CONFIG_AUFS_SBILIST
24353 + * iterate_supers_type() doesn't protect us from
24354 + * remounting (branch management)
24356 +struct hlist_bl_head au_sbilist;
24360 + * functions for module interface.
24362 +MODULE_LICENSE("GPL");
24363 +/* MODULE_LICENSE("GPL v2"); */
24364 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24365 +MODULE_DESCRIPTION(AUFS_NAME
24366 + " -- Advanced multi layered unification filesystem");
24367 +MODULE_VERSION(AUFS_VERSION);
24368 +MODULE_ALIAS_FS(AUFS_NAME);
24370 +/* this module parameter has no meaning when SYSFS is disabled */
24371 +int sysaufs_brs = 1;
24372 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24373 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
24375 +/* this module parameter has no meaning when USER_NS is disabled */
24377 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24378 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
24380 +/* ---------------------------------------------------------------------- */
24382 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24384 +int au_seq_path(struct seq_file *seq, struct path *path)
24388 + err = seq_path(seq, path, au_esc_chars);
24397 +/* ---------------------------------------------------------------------- */
24399 +static int __init aufs_init(void)
24404 + p = au_esc_chars;
24405 + for (i = 1; i <= ' '; i++)
24411 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24413 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24414 + for (i = 0; i < AuIop_Last; i++)
24415 + aufs_iop_nogetattr[i].getattr = NULL;
24417 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24419 + au_sbilist_init();
24420 + sysaufs_brs_init();
24423 + err = sysaufs_init();
24424 + if (unlikely(err))
24426 + err = au_procfs_init();
24427 + if (unlikely(err))
24428 + goto out_sysaufs;
24429 + err = au_wkq_init();
24430 + if (unlikely(err))
24432 + err = au_loopback_init();
24433 + if (unlikely(err))
24435 + err = au_hnotify_init();
24436 + if (unlikely(err))
24437 + goto out_loopback;
24438 + err = au_sysrq_init();
24439 + if (unlikely(err))
24441 + err = au_cache_init();
24442 + if (unlikely(err))
24445 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24446 + err = register_filesystem(&aufs_fs_type);
24447 + if (unlikely(err))
24450 + /* since we define pr_fmt, call printk directly */
24451 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24452 + goto out; /* success */
24459 + au_hnotify_fin();
24461 + au_loopback_fin();
24473 +static void __exit aufs_exit(void)
24475 + unregister_filesystem(&aufs_fs_type);
24478 + au_hnotify_fin();
24479 + au_loopback_fin();
24486 +module_init(aufs_init);
24487 +module_exit(aufs_exit);
24488 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24489 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24490 +++ linux/fs/aufs/module.h 2018-04-15 08:49:13.401150731 +0200
24493 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24495 + * This program, aufs is free software; you can redistribute it and/or modify
24496 + * it under the terms of the GNU General Public License as published by
24497 + * the Free Software Foundation; either version 2 of the License, or
24498 + * (at your option) any later version.
24500 + * This program is distributed in the hope that it will be useful,
24501 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24502 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24503 + * GNU General Public License for more details.
24505 + * You should have received a copy of the GNU General Public License
24506 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24510 + * module initialization and module-global
24513 +#ifndef __AUFS_MODULE_H__
24514 +#define __AUFS_MODULE_H__
24518 +#include <linux/slab.h>
24523 +/* module parameters */
24524 +extern int sysaufs_brs;
24525 +extern bool au_userns;
24527 +/* ---------------------------------------------------------------------- */
24529 +extern int au_dir_roflags;
24531 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24532 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24535 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24537 +#ifndef CONFIG_SLOB
24538 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24540 + return -1; /* SLOB is untested */
24544 +int au_seq_path(struct seq_file *seq, struct path *path);
24546 +#ifdef CONFIG_PROC_FS
24548 +int __init au_procfs_init(void);
24549 +void au_procfs_fin(void);
24551 +AuStubInt0(au_procfs_init, void);
24552 +AuStubVoid(au_procfs_fin, void);
24555 +/* ---------------------------------------------------------------------- */
24564 + AuCache_HNOTIFY, /* must be last */
24568 +extern struct kmem_cache *au_cache[AuCache_Last];
24570 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24571 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24572 +#define AuCacheCtor(type, ctor) \
24573 + kmem_cache_create(#type, sizeof(struct type), \
24574 + __alignof__(struct type), AuCacheFlags, ctor)
24576 +#define AuCacheFuncs(name, index) \
24577 +static inline struct au_##name *au_cache_alloc_##name(void) \
24578 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24579 +static inline void au_cache_free_##name(struct au_##name *p) \
24580 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
24582 +AuCacheFuncs(dinfo, DINFO);
24583 +AuCacheFuncs(icntnr, ICNTNR);
24584 +AuCacheFuncs(finfo, FINFO);
24585 +AuCacheFuncs(vdir, VDIR);
24586 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24587 +#ifdef CONFIG_AUFS_HNOTIFY
24588 +AuCacheFuncs(hnotify, HNOTIFY);
24591 +#endif /* __KERNEL__ */
24592 +#endif /* __AUFS_MODULE_H__ */
24593 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24594 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24595 +++ linux/fs/aufs/mvdown.c 2018-06-04 09:08:09.188079511 +0200
24598 + * Copyright (C) 2011-2018 Junjiro R. Okajima
24600 + * This program, aufs is free software; you can redistribute it and/or modify
24601 + * it under the terms of the GNU General Public License as published by
24602 + * the Free Software Foundation; either version 2 of the License, or
24603 + * (at your option) any later version.
24605 + * This program is distributed in the hope that it will be useful,
24606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24608 + * GNU General Public License for more details.
24610 + * You should have received a copy of the GNU General Public License
24611 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24615 + * move-down, opposite of copy-up
24620 +struct au_mvd_args {
24622 + struct super_block *h_sb;
24623 + struct dentry *h_parent;
24624 + struct au_hinode *hdir;
24625 + struct inode *h_dir, *h_inode;
24626 + struct au_pin pin;
24627 + } info[AUFS_MVDOWN_NARRAY];
24629 + struct aufs_mvdown mvdown;
24630 + struct dentry *dentry, *parent;
24631 + struct inode *inode, *dir;
24632 + struct super_block *sb;
24633 + aufs_bindex_t bopq, bwh, bfound;
24634 + unsigned char rename_lock;
24637 +#define mvd_errno mvdown.au_errno
24638 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24639 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24640 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24641 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24643 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24644 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24645 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24646 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24647 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24648 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24650 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24651 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24652 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24653 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24654 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24655 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24657 +#define AU_MVD_PR(flag, ...) do { \
24659 + pr_err(__VA_ARGS__); \
24662 +static int find_lower_writable(struct au_mvd_args *a)
24664 + struct super_block *sb;
24665 + aufs_bindex_t bindex, bbot;
24666 + struct au_branch *br;
24669 + bindex = a->mvd_bsrc;
24670 + bbot = au_sbbot(sb);
24671 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24672 + for (bindex++; bindex <= bbot; bindex++) {
24673 + br = au_sbr(sb, bindex);
24674 + if (au_br_fhsm(br->br_perm)
24675 + && !sb_rdonly(au_br_sb(br)))
24678 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24679 + for (bindex++; bindex <= bbot; bindex++) {
24680 + br = au_sbr(sb, bindex);
24681 + if (!au_br_rdonly(br))
24685 + for (bindex++; bindex <= bbot; bindex++) {
24686 + br = au_sbr(sb, bindex);
24687 + if (!sb_rdonly(au_br_sb(br))) {
24688 + if (au_br_rdonly(br))
24690 + |= AUFS_MVDOWN_ROLOWER_R;
24698 +/* make the parent dir on bdst */
24699 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24704 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24705 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24706 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24707 + a->mvd_h_dst_parent = NULL;
24708 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24709 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24710 + if (!a->mvd_h_dst_parent) {
24711 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24712 + if (unlikely(err)) {
24713 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24716 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24724 +/* lock them all */
24725 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24728 + struct dentry *h_trap;
24730 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24731 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24732 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24733 + au_opt_udba(a->sb),
24734 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24736 + if (unlikely(err)) {
24737 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24741 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24742 + a->rename_lock = 0;
24743 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24744 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24745 + au_opt_udba(a->sb),
24746 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24747 + err = au_do_pin(&a->mvd_pin_src);
24749 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24750 + if (unlikely(err)) {
24751 + AU_MVD_PR(dmsg, "pin_src failed\n");
24754 + goto out; /* success */
24757 + a->rename_lock = 1;
24758 + au_pin_hdir_unlock(&a->mvd_pin_dst);
24759 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24760 + au_opt_udba(a->sb),
24761 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24763 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24764 + if (unlikely(err)) {
24765 + AU_MVD_PR(dmsg, "pin_src failed\n");
24766 + au_pin_hdir_lock(&a->mvd_pin_dst);
24769 + au_pin_hdir_unlock(&a->mvd_pin_src);
24770 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24771 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24773 + err = (h_trap != a->mvd_h_src_parent);
24775 + err = (h_trap != a->mvd_h_dst_parent);
24777 + BUG_ON(err); /* it should never happen */
24778 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
24781 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24782 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24783 + au_pin_hdir_lock(&a->mvd_pin_src);
24784 + au_unpin(&a->mvd_pin_src);
24785 + au_pin_hdir_lock(&a->mvd_pin_dst);
24788 + goto out; /* success */
24791 + au_unpin(&a->mvd_pin_dst);
24797 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
24799 + if (!a->rename_lock)
24800 + au_unpin(&a->mvd_pin_src);
24802 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24803 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24804 + au_pin_hdir_lock(&a->mvd_pin_src);
24805 + au_unpin(&a->mvd_pin_src);
24806 + au_pin_hdir_lock(&a->mvd_pin_dst);
24808 + au_unpin(&a->mvd_pin_dst);
24811 +/* copy-down the file */
24812 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
24815 + struct au_cp_generic cpg = {
24816 + .dentry = a->dentry,
24817 + .bdst = a->mvd_bdst,
24818 + .bsrc = a->mvd_bsrc,
24820 + .pin = &a->mvd_pin_dst,
24821 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24824 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
24825 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
24826 + au_fset_cpup(cpg.flags, OVERWRITE);
24827 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
24828 + au_fset_cpup(cpg.flags, RWDST);
24829 + err = au_sio_cpdown_simple(&cpg);
24830 + if (unlikely(err))
24831 + AU_MVD_PR(dmsg, "cpdown failed\n");
24838 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
24841 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
24844 + struct path h_path;
24845 + struct au_branch *br;
24846 + struct inode *delegated;
24848 + br = au_sbr(a->sb, a->mvd_bdst);
24849 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
24850 + err = PTR_ERR(h_path.dentry);
24851 + if (IS_ERR(h_path.dentry)) {
24852 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
24857 + if (d_is_positive(h_path.dentry)) {
24858 + h_path.mnt = au_br_mnt(br);
24859 + delegated = NULL;
24860 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
24861 + &delegated, /*force*/0);
24862 + if (unlikely(err == -EWOULDBLOCK)) {
24863 + pr_warn("cannot retry for NFSv4 delegation"
24864 + " for an internal unlink\n");
24867 + if (unlikely(err))
24868 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
24870 + dput(h_path.dentry);
24878 + * unlink the topmost h_dentry
24880 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
24883 + struct path h_path;
24884 + struct inode *delegated;
24886 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
24887 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
24888 + delegated = NULL;
24889 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
24890 + if (unlikely(err == -EWOULDBLOCK)) {
24891 + pr_warn("cannot retry for NFSv4 delegation"
24892 + " for an internal unlink\n");
24895 + if (unlikely(err))
24896 + AU_MVD_PR(dmsg, "unlink failed\n");
24902 +/* Since mvdown succeeded, we ignore an error of this function */
24903 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
24906 + struct au_branch *br;
24908 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
24909 + br = au_sbr(a->sb, a->mvd_bsrc);
24910 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
24912 + br = au_sbr(a->sb, a->mvd_bdst);
24913 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
24914 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
24917 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
24919 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
24923 + * copy-down the file and unlink the bsrc file.
24924 + * - unlink the bdst whout if exist
24925 + * - copy-down the file (with whtmp name and rename)
24926 + * - unlink the bsrc file
24928 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
24932 + err = au_do_mkdir(dmsg, a);
24934 + err = au_do_lock(dmsg, a);
24935 + if (unlikely(err))
24939 + * do not revert the activities we made on bdst since they should be
24940 + * harmless in aufs.
24943 + err = au_do_cpdown(dmsg, a);
24945 + err = au_do_unlink_wh(dmsg, a);
24946 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
24947 + err = au_do_unlink(dmsg, a);
24948 + if (unlikely(err))
24951 + AuDbg("%pd2, 0x%x, %d --> %d\n",
24952 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
24953 + if (find_lower_writable(a) < 0)
24954 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
24956 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
24957 + au_do_stfs(dmsg, a);
24959 + /* maintain internal array */
24960 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
24961 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
24962 + au_set_dbtop(a->dentry, a->mvd_bdst);
24963 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
24964 + au_set_ibtop(a->inode, a->mvd_bdst);
24966 + /* hide the lower */
24967 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
24968 + au_set_dbbot(a->dentry, a->mvd_bsrc);
24969 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
24970 + au_set_ibbot(a->inode, a->mvd_bsrc);
24972 + if (au_dbbot(a->dentry) < a->mvd_bdst)
24973 + au_set_dbbot(a->dentry, a->mvd_bdst);
24974 + if (au_ibbot(a->inode) < a->mvd_bdst)
24975 + au_set_ibbot(a->inode, a->mvd_bdst);
24978 + au_do_unlock(dmsg, a);
24984 +/* ---------------------------------------------------------------------- */
24986 +/* make sure the file is idle */
24987 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
24989 + int err, plinked;
24992 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
24993 + if (au_dbtop(a->dentry) == a->mvd_bsrc
24994 + && au_dcount(a->dentry) == 1
24995 + && atomic_read(&a->inode->i_count) == 1
24996 + /* && a->mvd_h_src_inode->i_nlink == 1 */
24997 + && (!plinked || !au_plink_test(a->inode))
24998 + && a->inode->i_nlink == 1)
25003 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25004 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25005 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25006 + a->mvd_h_src_inode->i_nlink,
25007 + plinked, plinked ? au_plink_test(a->inode) : 0);
25014 +/* make sure the parent dir is fine */
25015 +static int au_mvd_args_parent(const unsigned char dmsg,
25016 + struct au_mvd_args *a)
25019 + aufs_bindex_t bindex;
25022 + if (unlikely(au_alive_dir(a->parent))) {
25024 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25028 + a->bopq = au_dbdiropq(a->parent);
25029 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25030 + AuDbg("b%d\n", bindex);
25031 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25032 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25034 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25035 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25036 + a->bopq, a->mvd_bdst);
25044 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25045 + struct au_mvd_args *a)
25048 + struct au_dinfo *dinfo, *tmp;
25050 + /* lookup the next lower positive entry */
25052 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25053 + if (unlikely(!tmp))
25058 + dinfo = au_di(a->dentry);
25059 + au_di_cp(tmp, dinfo);
25060 + au_di_swap(tmp, dinfo);
25062 + /* returns the number of positive dentries */
25063 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25064 + /* AuLkup_IGNORE_PERM */ 0);
25066 + a->bwh = au_dbwh(a->dentry);
25067 + else if (err > 0)
25068 + a->bfound = au_dbtop(a->dentry);
25070 + au_di_swap(tmp, dinfo);
25071 + au_rw_write_unlock(&tmp->di_rwsem);
25073 + if (unlikely(err < 0))
25074 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25077 + * here, we have these cases.
25079 + * no positive dentry under bsrc. there are more sub-cases.
25081 + * there no whiteout, we can safely move-down.
25084 + * bsrc < bwh && bwh < bdst
25085 + * there is a whiteout on RO branch. cannot proceed.
25087 + * there is a whiteout on the RW target branch. it should
25090 + * there is a whiteout somewhere unrelated branch.
25091 + * -1 < bfound && bfound <= bsrc
25094 + * found, but it is on RO branch between bsrc and bdst. cannot
25097 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25100 + * found, after we create the file on bdst, it will be hidden.
25103 + AuDebugOn(a->bfound == -1
25105 + && a->bwh <= a->mvd_bsrc);
25106 + AuDebugOn(-1 < a->bfound
25107 + && a->bfound <= a->mvd_bsrc);
25110 + if (a->bfound == -1
25111 + && a->mvd_bsrc < a->bwh
25113 + && a->bwh < a->mvd_bdst) {
25114 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25115 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25116 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25118 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25119 + a->mvd_errno = EAU_MVDOWN_UPPER;
25120 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25121 + a->mvd_bdst, a->bfound);
25125 + err = 0; /* success */
25132 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25137 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25138 + && a->bfound == a->mvd_bdst)
25144 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25147 + struct au_branch *br;
25150 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25154 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25155 + a->mvd_bsrc = au_ibtop(a->inode);
25157 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25158 + if (unlikely(a->mvd_bsrc < 0
25159 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25160 + || au_dbbot(a->dentry) < a->mvd_bsrc
25161 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25162 + || (a->mvd_bsrc < au_ibtop(a->inode)
25163 + || au_ibbot(a->inode) < a->mvd_bsrc
25164 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25165 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25166 + AU_MVD_PR(dmsg, "no upper\n");
25170 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25171 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25172 + AU_MVD_PR(dmsg, "on the bottom\n");
25175 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25176 + br = au_sbr(a->sb, a->mvd_bsrc);
25177 + err = au_br_rdonly(br);
25178 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25179 + if (unlikely(err))
25181 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25182 + || IS_APPEND(a->mvd_h_src_inode))) {
25184 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25190 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25191 + a->mvd_bdst = find_lower_writable(a);
25192 + if (unlikely(a->mvd_bdst < 0)) {
25193 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25194 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25198 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25199 + if (unlikely(a->mvd_bdst < 0
25200 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25201 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25202 + AU_MVD_PR(dmsg, "no lower brid\n");
25207 + err = au_mvd_args_busy(dmsg, a);
25209 + err = au_mvd_args_parent(dmsg, a);
25211 + err = au_mvd_args_intermediate(dmsg, a);
25213 + err = au_mvd_args_exist(dmsg, a);
25215 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25222 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25225 + unsigned char dmsg;
25226 + struct au_mvd_args *args;
25227 + struct inode *inode;
25229 + inode = d_inode(dentry);
25231 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25235 + args = kmalloc(sizeof(*args), GFP_NOFS);
25236 + if (unlikely(!args))
25239 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25241 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25242 + if (unlikely(err)) {
25247 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25248 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25249 + args->mvdown.au_errno = 0;
25250 + args->dentry = dentry;
25251 + args->inode = inode;
25252 + args->sb = dentry->d_sb;
25255 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25256 + args->parent = dget_parent(dentry);
25257 + args->dir = d_inode(args->parent);
25258 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25259 + dput(args->parent);
25260 + if (unlikely(args->parent != dentry->d_parent)) {
25261 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25265 + inode_lock_nested(inode, I_MUTEX_CHILD);
25266 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25267 + if (unlikely(err))
25270 + di_write_lock_parent(args->parent);
25271 + err = au_mvd_args(dmsg, args);
25272 + if (unlikely(err))
25275 + err = au_do_mvdown(dmsg, args);
25276 + if (unlikely(err))
25279 + au_cpup_attr_timesizes(args->dir);
25280 + au_cpup_attr_timesizes(inode);
25281 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25282 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25283 + /* au_digen_dec(dentry); */
25286 + di_write_unlock(args->parent);
25287 + aufs_read_unlock(dentry, AuLock_DW);
25289 + inode_unlock(inode);
25291 + inode_unlock(args->dir);
25293 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25301 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25302 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25303 +++ linux/fs/aufs/opts.c 2018-06-04 09:08:09.188079511 +0200
25306 + * Copyright (C) 2005-2018 Junjiro R. Okajima
25308 + * This program, aufs is free software; you can redistribute it and/or modify
25309 + * it under the terms of the GNU General Public License as published by
25310 + * the Free Software Foundation; either version 2 of the License, or
25311 + * (at your option) any later version.
25313 + * This program is distributed in the hope that it will be useful,
25314 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25315 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25316 + * GNU General Public License for more details.
25318 + * You should have received a copy of the GNU General Public License
25319 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25323 + * mount options/flags
25326 +#include <linux/namei.h>
25327 +#include <linux/types.h> /* a distribution requires */
25328 +#include <linux/parser.h>
25331 +/* ---------------------------------------------------------------------- */
25335 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25336 + Opt_idel, Opt_imod,
25337 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25338 + Opt_rdblk_def, Opt_rdhash_def,
25339 + Opt_xino, Opt_noxino,
25340 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25341 + Opt_trunc_xino_path, Opt_itrunc_xino,
25342 + Opt_trunc_xib, Opt_notrunc_xib,
25343 + Opt_shwh, Opt_noshwh,
25344 + Opt_plink, Opt_noplink, Opt_list_plink,
25346 + Opt_dio, Opt_nodio,
25347 + Opt_diropq_a, Opt_diropq_w,
25348 + Opt_warn_perm, Opt_nowarn_perm,
25349 + Opt_wbr_copyup, Opt_wbr_create,
25351 + Opt_verbose, Opt_noverbose,
25352 + Opt_sum, Opt_nosum, Opt_wsum,
25353 + Opt_dirperm1, Opt_nodirperm1,
25354 + Opt_dirren, Opt_nodirren,
25355 + Opt_acl, Opt_noacl,
25356 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25359 +static match_table_t options = {
25360 + {Opt_br, "br=%s"},
25361 + {Opt_br, "br:%s"},
25363 + {Opt_add, "add=%d:%s"},
25364 + {Opt_add, "add:%d:%s"},
25365 + {Opt_add, "ins=%d:%s"},
25366 + {Opt_add, "ins:%d:%s"},
25367 + {Opt_append, "append=%s"},
25368 + {Opt_append, "append:%s"},
25369 + {Opt_prepend, "prepend=%s"},
25370 + {Opt_prepend, "prepend:%s"},
25372 + {Opt_del, "del=%s"},
25373 + {Opt_del, "del:%s"},
25374 + /* {Opt_idel, "idel:%d"}, */
25375 + {Opt_mod, "mod=%s"},
25376 + {Opt_mod, "mod:%s"},
25377 + /* {Opt_imod, "imod:%d:%s"}, */
25379 + {Opt_dirwh, "dirwh=%d"},
25381 + {Opt_xino, "xino=%s"},
25382 + {Opt_noxino, "noxino"},
25383 + {Opt_trunc_xino, "trunc_xino"},
25384 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25385 + {Opt_notrunc_xino, "notrunc_xino"},
25386 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25387 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25388 + /* {Opt_zxino, "zxino=%s"}, */
25389 + {Opt_trunc_xib, "trunc_xib"},
25390 + {Opt_notrunc_xib, "notrunc_xib"},
25392 +#ifdef CONFIG_PROC_FS
25393 + {Opt_plink, "plink"},
25395 + {Opt_ignore_silent, "plink"},
25398 + {Opt_noplink, "noplink"},
25400 +#ifdef CONFIG_AUFS_DEBUG
25401 + {Opt_list_plink, "list_plink"},
25404 + {Opt_udba, "udba=%s"},
25406 + {Opt_dio, "dio"},
25407 + {Opt_nodio, "nodio"},
25409 +#ifdef CONFIG_AUFS_DIRREN
25410 + {Opt_dirren, "dirren"},
25411 + {Opt_nodirren, "nodirren"},
25413 + {Opt_ignore, "dirren"},
25414 + {Opt_ignore_silent, "nodirren"},
25417 +#ifdef CONFIG_AUFS_FHSM
25418 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25420 + {Opt_ignore, "fhsm_sec=%d"},
25423 + {Opt_diropq_a, "diropq=always"},
25424 + {Opt_diropq_a, "diropq=a"},
25425 + {Opt_diropq_w, "diropq=whiteouted"},
25426 + {Opt_diropq_w, "diropq=w"},
25428 + {Opt_warn_perm, "warn_perm"},
25429 + {Opt_nowarn_perm, "nowarn_perm"},
25431 + /* keep them temporary */
25432 + {Opt_ignore_silent, "nodlgt"},
25433 + {Opt_ignore, "clean_plink"},
25435 +#ifdef CONFIG_AUFS_SHWH
25436 + {Opt_shwh, "shwh"},
25438 + {Opt_noshwh, "noshwh"},
25440 + {Opt_dirperm1, "dirperm1"},
25441 + {Opt_nodirperm1, "nodirperm1"},
25443 + {Opt_verbose, "verbose"},
25444 + {Opt_verbose, "v"},
25445 + {Opt_noverbose, "noverbose"},
25446 + {Opt_noverbose, "quiet"},
25447 + {Opt_noverbose, "q"},
25448 + {Opt_noverbose, "silent"},
25450 + {Opt_sum, "sum"},
25451 + {Opt_nosum, "nosum"},
25452 + {Opt_wsum, "wsum"},
25454 + {Opt_rdcache, "rdcache=%d"},
25455 + {Opt_rdblk, "rdblk=%d"},
25456 + {Opt_rdblk_def, "rdblk=def"},
25457 + {Opt_rdhash, "rdhash=%d"},
25458 + {Opt_rdhash_def, "rdhash=def"},
25460 + {Opt_wbr_create, "create=%s"},
25461 + {Opt_wbr_create, "create_policy=%s"},
25462 + {Opt_wbr_copyup, "cpup=%s"},
25463 + {Opt_wbr_copyup, "copyup=%s"},
25464 + {Opt_wbr_copyup, "copyup_policy=%s"},
25466 + /* generic VFS flag */
25467 +#ifdef CONFIG_FS_POSIX_ACL
25468 + {Opt_acl, "acl"},
25469 + {Opt_noacl, "noacl"},
25471 + {Opt_ignore, "acl"},
25472 + {Opt_ignore_silent, "noacl"},
25475 + /* internal use for the scripts */
25476 + {Opt_ignore_silent, "si=%s"},
25478 + {Opt_br, "dirs=%s"},
25479 + {Opt_ignore, "debug=%d"},
25480 + {Opt_ignore, "delete=whiteout"},
25481 + {Opt_ignore, "delete=all"},
25482 + {Opt_ignore, "imap=%s"},
25484 + /* temporary workaround, due to old mount(8)? */
25485 + {Opt_ignore_silent, "relatime"},
25490 +/* ---------------------------------------------------------------------- */
25492 +static const char *au_parser_pattern(int val, match_table_t tbl)
25494 + struct match_token *p;
25497 + while (p->pattern) {
25498 + if (p->token == val)
25499 + return p->pattern;
25506 +static const char *au_optstr(int *val, match_table_t tbl)
25508 + struct match_token *p;
25515 + while (p->pattern) {
25517 + && (v & p->token) == p->token) {
25518 + *val &= ~p->token;
25519 + return p->pattern;
25528 +/* ---------------------------------------------------------------------- */
25530 +static match_table_t brperm = {
25531 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25532 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25533 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25537 +static match_table_t brattr = {
25539 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25540 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25541 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25542 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25543 +#ifdef CONFIG_AUFS_FHSM
25544 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25546 +#ifdef CONFIG_AUFS_XATTR
25547 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25548 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25549 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25550 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25551 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25552 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25555 + /* ro/rr branch */
25556 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25559 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25560 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25565 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25572 + p = strchr(str, '+');
25575 + v = match_token(str, table, args);
25577 + if (v & AuBrAttr_CMOO_Mask)
25578 + attr &= ~AuBrAttr_CMOO_Mask;
25583 + pr_warn("ignored branch attribute %s\n", str);
25593 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25601 + p = au_optstr(&perm, brattr);
25604 + memcpy(q, p, sz + 1);
25610 + p = au_optstr(&perm, brattr);
25614 + memcpy(q, p, sz + 1);
25620 + return q - str->a;
25623 +static int noinline_for_stack br_perm_val(char *perm)
25625 + int val, bad, sz;
25627 + substring_t args[MAX_OPT_ARGS];
25628 + au_br_perm_str_t attr;
25630 + p = strchr(perm, '+');
25633 + val = match_token(perm, brperm, args);
25637 + pr_warn("ignored branch permission %s\n", perm);
25638 + val = AuBrPerm_RO;
25644 + val |= br_attr_val(p + 1, brattr, args);
25647 + switch (val & AuBrPerm_Mask) {
25648 + case AuBrPerm_RO:
25649 + case AuBrPerm_RR:
25650 + bad = val & AuBrWAttr_Mask;
25651 + val &= ~AuBrWAttr_Mask;
25653 + case AuBrPerm_RW:
25654 + bad = val & AuBrRAttr_Mask;
25655 + val &= ~AuBrRAttr_Mask;
25660 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25661 + * does not treat it as an error, just warning.
25662 + * this is a tiny guard for the user operation.
25664 + if (val & AuBrAttr_UNPIN) {
25665 + bad |= AuBrAttr_UNPIN;
25666 + val &= ~AuBrAttr_UNPIN;
25669 + if (unlikely(bad)) {
25670 + sz = au_do_optstr_br_attr(&attr, bad);
25672 + pr_warn("ignored branch attribute %s\n", attr.a);
25679 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25681 + au_br_perm_str_t attr;
25687 + p = au_optstr(&perm, brperm);
25688 + AuDebugOn(!p || !*p);
25690 + memcpy(q, p, sz + 1);
25693 + sz = au_do_optstr_br_attr(&attr, perm);
25696 + memcpy(q, attr.a, sz + 1);
25699 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25702 +/* ---------------------------------------------------------------------- */
25704 +static match_table_t udbalevel = {
25705 + {AuOpt_UDBA_REVAL, "reval"},
25706 + {AuOpt_UDBA_NONE, "none"},
25707 +#ifdef CONFIG_AUFS_HNOTIFY
25708 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25709 +#ifdef CONFIG_AUFS_HFSNOTIFY
25710 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25716 +static int noinline_for_stack udba_val(char *str)
25718 + substring_t args[MAX_OPT_ARGS];
25720 + return match_token(str, udbalevel, args);
25723 +const char *au_optstr_udba(int udba)
25725 + return au_parser_pattern(udba, udbalevel);
25728 +/* ---------------------------------------------------------------------- */
25730 +static match_table_t au_wbr_create_policy = {
25731 + {AuWbrCreate_TDP, "tdp"},
25732 + {AuWbrCreate_TDP, "top-down-parent"},
25733 + {AuWbrCreate_RR, "rr"},
25734 + {AuWbrCreate_RR, "round-robin"},
25735 + {AuWbrCreate_MFS, "mfs"},
25736 + {AuWbrCreate_MFS, "most-free-space"},
25737 + {AuWbrCreate_MFSV, "mfs:%d"},
25738 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25740 + /* top-down regardless the parent, and then mfs */
25741 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25742 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25744 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25745 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25746 + {AuWbrCreate_PMFS, "pmfs"},
25747 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25748 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25749 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
25754 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
25755 + struct au_opt_wbr_create *create)
25758 + unsigned long long ull;
25761 + if (!match_u64(arg, &ull))
25762 + create->mfsrr_watermark = ull;
25764 + pr_err("bad integer in %s\n", str);
25771 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
25772 + struct au_opt_wbr_create *create)
25777 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
25778 + create->mfs_second = n;
25780 + pr_err("bad integer in %s\n", str);
25787 +static int noinline_for_stack
25788 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
25791 + substring_t args[MAX_OPT_ARGS];
25793 + err = match_token(str, au_wbr_create_policy, args);
25794 + create->wbr_create = err;
25796 + case AuWbrCreate_MFSRRV:
25797 + case AuWbrCreate_TDMFSV:
25798 + case AuWbrCreate_PMFSRRV:
25799 + e = au_wbr_mfs_wmark(&args[0], str, create);
25801 + e = au_wbr_mfs_sec(&args[1], str, create);
25805 + case AuWbrCreate_MFSRR:
25806 + case AuWbrCreate_TDMFS:
25807 + case AuWbrCreate_PMFSRR:
25808 + e = au_wbr_mfs_wmark(&args[0], str, create);
25809 + if (unlikely(e)) {
25814 + case AuWbrCreate_MFS:
25815 + case AuWbrCreate_PMFS:
25816 + create->mfs_second = AUFS_MFS_DEF_SEC;
25818 + case AuWbrCreate_MFSV:
25819 + case AuWbrCreate_PMFSV:
25820 + e = au_wbr_mfs_sec(&args[0], str, create);
25829 +const char *au_optstr_wbr_create(int wbr_create)
25831 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
25834 +static match_table_t au_wbr_copyup_policy = {
25835 + {AuWbrCopyup_TDP, "tdp"},
25836 + {AuWbrCopyup_TDP, "top-down-parent"},
25837 + {AuWbrCopyup_BUP, "bup"},
25838 + {AuWbrCopyup_BUP, "bottom-up-parent"},
25839 + {AuWbrCopyup_BU, "bu"},
25840 + {AuWbrCopyup_BU, "bottom-up"},
25844 +static int noinline_for_stack au_wbr_copyup_val(char *str)
25846 + substring_t args[MAX_OPT_ARGS];
25848 + return match_token(str, au_wbr_copyup_policy, args);
25851 +const char *au_optstr_wbr_copyup(int wbr_copyup)
25853 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
25856 +/* ---------------------------------------------------------------------- */
25858 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
25860 +static void dump_opts(struct au_opts *opts)
25862 +#ifdef CONFIG_AUFS_DEBUG
25863 + /* reduce stack space */
25865 + struct au_opt_add *add;
25866 + struct au_opt_del *del;
25867 + struct au_opt_mod *mod;
25868 + struct au_opt_xino *xino;
25869 + struct au_opt_xino_itrunc *xino_itrunc;
25870 + struct au_opt_wbr_create *create;
25872 + struct au_opt *opt;
25875 + while (opt->type != Opt_tail) {
25876 + switch (opt->type) {
25878 + u.add = &opt->add;
25879 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
25880 + u.add->bindex, u.add->pathname, u.add->perm,
25881 + u.add->path.dentry);
25885 + u.del = &opt->del;
25886 + AuDbg("del {%s, %p}\n",
25887 + u.del->pathname, u.del->h_path.dentry);
25891 + u.mod = &opt->mod;
25892 + AuDbg("mod {%s, 0x%x, %p}\n",
25893 + u.mod->path, u.mod->perm, u.mod->h_root);
25896 + u.add = &opt->add;
25897 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
25898 + u.add->bindex, u.add->pathname, u.add->perm,
25899 + u.add->path.dentry);
25901 + case Opt_prepend:
25902 + u.add = &opt->add;
25903 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
25904 + u.add->bindex, u.add->pathname, u.add->perm,
25905 + u.add->path.dentry);
25908 + AuDbg("dirwh %d\n", opt->dirwh);
25910 + case Opt_rdcache:
25911 + AuDbg("rdcache %d\n", opt->rdcache);
25914 + AuDbg("rdblk %u\n", opt->rdblk);
25916 + case Opt_rdblk_def:
25917 + AuDbg("rdblk_def\n");
25920 + AuDbg("rdhash %u\n", opt->rdhash);
25922 + case Opt_rdhash_def:
25923 + AuDbg("rdhash_def\n");
25926 + u.xino = &opt->xino;
25927 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
25929 + case Opt_trunc_xino:
25930 + AuLabel(trunc_xino);
25932 + case Opt_notrunc_xino:
25933 + AuLabel(notrunc_xino);
25935 + case Opt_trunc_xino_path:
25936 + case Opt_itrunc_xino:
25937 + u.xino_itrunc = &opt->xino_itrunc;
25938 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
25943 + case Opt_trunc_xib:
25944 + AuLabel(trunc_xib);
25946 + case Opt_notrunc_xib:
25947 + AuLabel(notrunc_xib);
25955 + case Opt_dirperm1:
25956 + AuLabel(dirperm1);
25958 + case Opt_nodirperm1:
25959 + AuLabel(nodirperm1);
25964 + case Opt_noplink:
25965 + AuLabel(noplink);
25967 + case Opt_list_plink:
25968 + AuLabel(list_plink);
25971 + AuDbg("udba %d, %s\n",
25972 + opt->udba, au_optstr_udba(opt->udba));
25980 + case Opt_diropq_a:
25981 + AuLabel(diropq_a);
25983 + case Opt_diropq_w:
25984 + AuLabel(diropq_w);
25986 + case Opt_warn_perm:
25987 + AuLabel(warn_perm);
25989 + case Opt_nowarn_perm:
25990 + AuLabel(nowarn_perm);
25992 + case Opt_verbose:
25993 + AuLabel(verbose);
25995 + case Opt_noverbose:
25996 + AuLabel(noverbose);
26007 + case Opt_wbr_create:
26008 + u.create = &opt->wbr_create;
26009 + AuDbg("create %d, %s\n", u.create->wbr_create,
26010 + au_optstr_wbr_create(u.create->wbr_create));
26011 + switch (u.create->wbr_create) {
26012 + case AuWbrCreate_MFSV:
26013 + case AuWbrCreate_PMFSV:
26014 + AuDbg("%d sec\n", u.create->mfs_second);
26016 + case AuWbrCreate_MFSRR:
26017 + case AuWbrCreate_TDMFS:
26018 + AuDbg("%llu watermark\n",
26019 + u.create->mfsrr_watermark);
26021 + case AuWbrCreate_MFSRRV:
26022 + case AuWbrCreate_TDMFSV:
26023 + case AuWbrCreate_PMFSRRV:
26024 + AuDbg("%llu watermark, %d sec\n",
26025 + u.create->mfsrr_watermark,
26026 + u.create->mfs_second);
26030 + case Opt_wbr_copyup:
26031 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26032 + au_optstr_wbr_copyup(opt->wbr_copyup));
26034 + case Opt_fhsm_sec:
26035 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26040 + case Opt_nodirren:
26041 + AuLabel(nodirren);
26057 +void au_opts_free(struct au_opts *opts)
26059 + struct au_opt *opt;
26062 + while (opt->type != Opt_tail) {
26063 + switch (opt->type) {
26066 + case Opt_prepend:
26067 + path_put(&opt->add.path);
26071 + path_put(&opt->del.h_path);
26075 + dput(opt->mod.h_root);
26078 + fput(opt->xino.file);
26085 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26086 + aufs_bindex_t bindex)
26089 + struct au_opt_add *add = &opt->add;
26092 + add->bindex = bindex;
26093 + add->perm = AuBrPerm_RO;
26094 + add->pathname = opt_str;
26095 + p = strchr(opt_str, '=');
26099 + add->perm = br_perm_val(p);
26102 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26105 + add->perm = AuBrPerm_RO;
26106 + if (au_test_fs_rr(add->path.dentry->d_sb))
26107 + add->perm = AuBrPerm_RR;
26108 + else if (!bindex && !(sb_flags & SB_RDONLY))
26109 + add->perm = AuBrPerm_RW;
26111 + opt->type = Opt_add;
26114 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26121 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26125 + del->pathname = args[0].from;
26126 + AuDbg("del path %s\n", del->pathname);
26128 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26129 + if (unlikely(err))
26130 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26135 +#if 0 /* reserved for future use */
26136 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26137 + struct au_opt_del *del, substring_t args[])
26140 + struct dentry *root;
26143 + root = sb->s_root;
26144 + aufs_read_lock(root, AuLock_FLUSH);
26145 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26146 + pr_err("out of bounds, %d\n", bindex);
26151 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26152 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26155 + aufs_read_unlock(root, !AuLock_IR);
26160 +static int noinline_for_stack
26161 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26164 + struct path path;
26168 + mod->path = args[0].from;
26169 + p = strchr(mod->path, '=');
26170 + if (unlikely(!p)) {
26171 + pr_err("no permssion %s\n", args[0].from);
26176 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26177 + if (unlikely(err)) {
26178 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26182 + mod->perm = br_perm_val(p);
26183 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26184 + mod->h_root = dget(path.dentry);
26191 +#if 0 /* reserved for future use */
26192 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26193 + struct au_opt_mod *mod, substring_t args[])
26196 + struct dentry *root;
26199 + root = sb->s_root;
26200 + aufs_read_lock(root, AuLock_FLUSH);
26201 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26202 + pr_err("out of bounds, %d\n", bindex);
26207 + mod->perm = br_perm_val(args[1].from);
26208 + AuDbg("mod path %s, perm 0x%x, %s\n",
26209 + mod->path, mod->perm, args[1].from);
26210 + mod->h_root = dget(au_h_dptr(root, bindex));
26213 + aufs_read_unlock(root, !AuLock_IR);
26218 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26219 + substring_t args[])
26222 + struct file *file;
26224 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26225 + err = PTR_ERR(file);
26226 + if (IS_ERR(file))
26230 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26232 + pr_err("%s must be outside\n", args[0].from);
26237 + xino->file = file;
26238 + xino->path = args[0].from;
26244 +static int noinline_for_stack
26245 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26246 + struct au_opt_xino_itrunc *xino_itrunc,
26247 + substring_t args[])
26250 + aufs_bindex_t bbot, bindex;
26251 + struct path path;
26252 + struct dentry *root;
26254 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26255 + if (unlikely(err)) {
26256 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26260 + xino_itrunc->bindex = -1;
26261 + root = sb->s_root;
26262 + aufs_read_lock(root, AuLock_FLUSH);
26263 + bbot = au_sbbot(sb);
26264 + for (bindex = 0; bindex <= bbot; bindex++) {
26265 + if (au_h_dptr(root, bindex) == path.dentry) {
26266 + xino_itrunc->bindex = bindex;
26270 + aufs_read_unlock(root, !AuLock_IR);
26273 + if (unlikely(xino_itrunc->bindex < 0)) {
26274 + pr_err("no such branch %s\n", args[0].from);
26282 +/* called without aufs lock */
26283 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26285 + int err, n, token;
26286 + aufs_bindex_t bindex;
26287 + unsigned char skipped;
26288 + struct dentry *root;
26289 + struct au_opt *opt, *opt_tail;
26291 + /* reduce the stack space */
26293 + struct au_opt_xino_itrunc *xino_itrunc;
26294 + struct au_opt_wbr_create *create;
26297 + substring_t args[MAX_OPT_ARGS];
26301 + a = kmalloc(sizeof(*a), GFP_NOFS);
26302 + if (unlikely(!a))
26305 + root = sb->s_root;
26309 + opt_tail = opt + opts->max_opt - 1;
26310 + opt->type = Opt_tail;
26311 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26314 + token = match_token(opt_str, options, a->args);
26318 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26320 + err = opt_add(opt, opt_str, opts->sb_flags,
26322 + if (unlikely(!err && ++opt > opt_tail)) {
26326 + opt->type = Opt_tail;
26331 + if (unlikely(match_int(&a->args[0], &n))) {
26332 + pr_err("bad integer in %s\n", opt_str);
26336 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26339 + opt->type = token;
26342 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26343 + /*dummy bindex*/1);
26345 + opt->type = token;
26347 + case Opt_prepend:
26348 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26351 + opt->type = token;
26354 + err = au_opts_parse_del(&opt->del, a->args);
26356 + opt->type = token;
26358 +#if 0 /* reserved for future use */
26360 + del->pathname = "(indexed)";
26361 + if (unlikely(match_int(&args[0], &n))) {
26362 + pr_err("bad integer in %s\n", opt_str);
26365 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26367 + opt->type = token;
26371 + err = au_opts_parse_mod(&opt->mod, a->args);
26373 + opt->type = token;
26375 +#ifdef IMOD /* reserved for future use */
26377 + u.mod->path = "(indexed)";
26378 + if (unlikely(match_int(&a->args[0], &n))) {
26379 + pr_err("bad integer in %s\n", opt_str);
26382 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26384 + opt->type = token;
26388 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26390 + opt->type = token;
26393 + case Opt_trunc_xino_path:
26394 + err = au_opts_parse_xino_itrunc_path
26395 + (sb, &opt->xino_itrunc, a->args);
26397 + opt->type = token;
26400 + case Opt_itrunc_xino:
26401 + u.xino_itrunc = &opt->xino_itrunc;
26402 + if (unlikely(match_int(&a->args[0], &n))) {
26403 + pr_err("bad integer in %s\n", opt_str);
26406 + u.xino_itrunc->bindex = n;
26407 + aufs_read_lock(root, AuLock_FLUSH);
26408 + if (n < 0 || au_sbbot(sb) < n) {
26409 + pr_err("out of bounds, %d\n", n);
26410 + aufs_read_unlock(root, !AuLock_IR);
26413 + aufs_read_unlock(root, !AuLock_IR);
26415 + opt->type = token;
26419 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26422 + opt->type = token;
26425 + case Opt_rdcache:
26426 + if (unlikely(match_int(&a->args[0], &n))) {
26427 + pr_err("bad integer in %s\n", opt_str);
26430 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26431 + pr_err("rdcache must be smaller than %d\n",
26432 + AUFS_RDCACHE_MAX);
26435 + opt->rdcache = n;
26437 + opt->type = token;
26440 + if (unlikely(match_int(&a->args[0], &n)
26442 + || n > KMALLOC_MAX_SIZE)) {
26443 + pr_err("bad integer in %s\n", opt_str);
26446 + if (unlikely(n && n < NAME_MAX)) {
26447 + pr_err("rdblk must be larger than %d\n",
26453 + opt->type = token;
26456 + if (unlikely(match_int(&a->args[0], &n)
26458 + || n * sizeof(struct hlist_head)
26459 + > KMALLOC_MAX_SIZE)) {
26460 + pr_err("bad integer in %s\n", opt_str);
26465 + opt->type = token;
26468 + case Opt_trunc_xino:
26469 + case Opt_notrunc_xino:
26471 + case Opt_trunc_xib:
26472 + case Opt_notrunc_xib:
26475 + case Opt_dirperm1:
26476 + case Opt_nodirperm1:
26478 + case Opt_noplink:
26479 + case Opt_list_plink:
26482 + case Opt_diropq_a:
26483 + case Opt_diropq_w:
26484 + case Opt_warn_perm:
26485 + case Opt_nowarn_perm:
26486 + case Opt_verbose:
26487 + case Opt_noverbose:
26491 + case Opt_rdblk_def:
26492 + case Opt_rdhash_def:
26494 + case Opt_nodirren:
26498 + opt->type = token;
26502 + opt->udba = udba_val(a->args[0].from);
26503 + if (opt->udba >= 0) {
26505 + opt->type = token;
26507 + pr_err("wrong value, %s\n", opt_str);
26510 + case Opt_wbr_create:
26511 + u.create = &opt->wbr_create;
26512 + u.create->wbr_create
26513 + = au_wbr_create_val(a->args[0].from, u.create);
26514 + if (u.create->wbr_create >= 0) {
26516 + opt->type = token;
26518 + pr_err("wrong value, %s\n", opt_str);
26520 + case Opt_wbr_copyup:
26521 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26522 + if (opt->wbr_copyup >= 0) {
26524 + opt->type = token;
26526 + pr_err("wrong value, %s\n", opt_str);
26529 + case Opt_fhsm_sec:
26530 + if (unlikely(match_int(&a->args[0], &n)
26532 + pr_err("bad integer in %s\n", opt_str);
26535 + if (sysaufs_brs) {
26536 + opt->fhsm_second = n;
26537 + opt->type = token;
26539 + pr_warn("ignored %s\n", opt_str);
26544 + pr_warn("ignored %s\n", opt_str);
26546 + case Opt_ignore_silent:
26551 + pr_err("unknown option %s\n", opt_str);
26555 + if (!err && !skipped) {
26556 + if (unlikely(++opt > opt_tail)) {
26559 + opt->type = Opt_tail;
26562 + opt->type = Opt_tail;
26568 + if (unlikely(err))
26569 + au_opts_free(opts);
26575 +static int au_opt_wbr_create(struct super_block *sb,
26576 + struct au_opt_wbr_create *create)
26579 + struct au_sbinfo *sbinfo;
26581 + SiMustWriteLock(sb);
26583 + err = 1; /* handled */
26584 + sbinfo = au_sbi(sb);
26585 + if (sbinfo->si_wbr_create_ops->fin) {
26586 + err = sbinfo->si_wbr_create_ops->fin(sb);
26591 + sbinfo->si_wbr_create = create->wbr_create;
26592 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26593 + switch (create->wbr_create) {
26594 + case AuWbrCreate_MFSRRV:
26595 + case AuWbrCreate_MFSRR:
26596 + case AuWbrCreate_TDMFS:
26597 + case AuWbrCreate_TDMFSV:
26598 + case AuWbrCreate_PMFSRR:
26599 + case AuWbrCreate_PMFSRRV:
26600 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26602 + case AuWbrCreate_MFS:
26603 + case AuWbrCreate_MFSV:
26604 + case AuWbrCreate_PMFS:
26605 + case AuWbrCreate_PMFSV:
26606 + sbinfo->si_wbr_mfs.mfs_expire
26607 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26611 + if (sbinfo->si_wbr_create_ops->init)
26612 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26619 + * plus: processed without an error
26620 + * zero: unprocessed
26622 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26623 + struct au_opts *opts)
26626 + struct au_sbinfo *sbinfo;
26628 + SiMustWriteLock(sb);
26630 + err = 1; /* handled */
26631 + sbinfo = au_sbi(sb);
26632 + switch (opt->type) {
26634 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26635 + sbinfo->si_mntflags |= opt->udba;
26636 + opts->given_udba |= opt->udba;
26640 + au_opt_set(sbinfo->si_mntflags, PLINK);
26642 + case Opt_noplink:
26643 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26644 + au_plink_put(sb, /*verbose*/1);
26645 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26647 + case Opt_list_plink:
26648 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26649 + au_plink_list(sb);
26653 + au_opt_set(sbinfo->si_mntflags, DIO);
26654 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26657 + au_opt_clr(sbinfo->si_mntflags, DIO);
26658 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26661 + case Opt_fhsm_sec:
26662 + au_fhsm_set(sbinfo, opt->fhsm_second);
26665 + case Opt_diropq_a:
26666 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26668 + case Opt_diropq_w:
26669 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26672 + case Opt_warn_perm:
26673 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26675 + case Opt_nowarn_perm:
26676 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26679 + case Opt_verbose:
26680 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26682 + case Opt_noverbose:
26683 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26687 + au_opt_set(sbinfo->si_mntflags, SUM);
26690 + au_opt_clr(sbinfo->si_mntflags, SUM);
26691 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26693 + au_opt_clr(sbinfo->si_mntflags, SUM);
26694 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26697 + case Opt_wbr_create:
26698 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26700 + case Opt_wbr_copyup:
26701 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26702 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26706 + sbinfo->si_dirwh = opt->dirwh;
26709 + case Opt_rdcache:
26710 + sbinfo->si_rdcache
26711 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26714 + sbinfo->si_rdblk = opt->rdblk;
26716 + case Opt_rdblk_def:
26717 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26720 + sbinfo->si_rdhash = opt->rdhash;
26722 + case Opt_rdhash_def:
26723 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26727 + au_opt_set(sbinfo->si_mntflags, SHWH);
26730 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26733 + case Opt_dirperm1:
26734 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26736 + case Opt_nodirperm1:
26737 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26740 + case Opt_trunc_xino:
26741 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26743 + case Opt_notrunc_xino:
26744 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26747 + case Opt_trunc_xino_path:
26748 + case Opt_itrunc_xino:
26749 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
26754 + case Opt_trunc_xib:
26755 + au_fset_opts(opts->flags, TRUNC_XIB);
26757 + case Opt_notrunc_xib:
26758 + au_fclr_opts(opts->flags, TRUNC_XIB);
26763 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26764 + err = au_dr_opt_set(sb);
26769 + au_opt_set(sbinfo->si_mntflags, DIRREN);
26771 + case Opt_nodirren:
26773 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26774 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
26780 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
26784 + sb->s_flags |= SB_POSIXACL;
26787 + sb->s_flags &= ~SB_POSIXACL;
26799 + * returns tri-state.
26800 + * plus: processed without an error
26801 + * zero: unprocessed
26804 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
26805 + struct au_opts *opts)
26807 + int err, do_refresh;
26810 + switch (opt->type) {
26812 + opt->add.bindex = au_sbbot(sb) + 1;
26813 + if (opt->add.bindex < 0)
26814 + opt->add.bindex = 0;
26816 + case Opt_prepend:
26817 + opt->add.bindex = 0;
26818 + add: /* indented label */
26820 + err = au_br_add(sb, &opt->add,
26821 + au_ftest_opts(opts->flags, REMOUNT));
26824 + au_fset_opts(opts->flags, REFRESH);
26830 + err = au_br_del(sb, &opt->del,
26831 + au_ftest_opts(opts->flags, REMOUNT));
26834 + au_fset_opts(opts->flags, TRUNC_XIB);
26835 + au_fset_opts(opts->flags, REFRESH);
26841 + err = au_br_mod(sb, &opt->mod,
26842 + au_ftest_opts(opts->flags, REMOUNT),
26847 + au_fset_opts(opts->flags, REFRESH);
26854 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
26855 + struct au_opt_xino **opt_xino,
26856 + struct au_opts *opts)
26859 + aufs_bindex_t bbot, bindex;
26860 + struct dentry *root, *parent, *h_root;
26863 + switch (opt->type) {
26865 + err = au_xino_set(sb, &opt->xino,
26866 + !!au_ftest_opts(opts->flags, REMOUNT));
26867 + if (unlikely(err))
26870 + *opt_xino = &opt->xino;
26871 + au_xino_brid_set(sb, -1);
26873 + /* safe d_parent access */
26874 + parent = opt->xino.file->f_path.dentry->d_parent;
26875 + root = sb->s_root;
26876 + bbot = au_sbbot(sb);
26877 + for (bindex = 0; bindex <= bbot; bindex++) {
26878 + h_root = au_h_dptr(root, bindex);
26879 + if (h_root == parent) {
26880 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
26888 + au_xino_brid_set(sb, -1);
26889 + *opt_xino = (void *)-1;
26896 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
26897 + unsigned int pending)
26900 + aufs_bindex_t bindex, bbot;
26901 + unsigned char do_plink, skip, do_free, can_no_dreval;
26902 + struct au_branch *br;
26903 + struct au_wbr *wbr;
26904 + struct dentry *root, *dentry;
26905 + struct inode *dir, *h_dir;
26906 + struct au_sbinfo *sbinfo;
26907 + struct au_hinode *hdir;
26909 + SiMustAnyLock(sb);
26911 + sbinfo = au_sbi(sb);
26912 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
26914 + if (!(sb_flags & SB_RDONLY)) {
26915 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
26916 + pr_warn("first branch should be rw\n");
26917 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
26918 + pr_warn_once("shwh should be used with ro\n");
26921 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
26922 + && !au_opt_test(sbinfo->si_mntflags, XINO))
26923 + pr_warn_once("udba=*notify requires xino\n");
26925 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
26926 + pr_warn_once("dirperm1 breaks the protection"
26927 + " by the permission bits on the lower branch\n");
26931 + root = sb->s_root;
26932 + dir = d_inode(root);
26933 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
26934 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
26936 + bbot = au_sbbot(sb);
26937 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
26939 + h_dir = au_h_iptr(dir, bindex);
26940 + br = au_sbr(sb, bindex);
26942 + if ((br->br_perm & AuBrAttr_ICEX)
26943 + && !h_dir->i_op->listxattr)
26944 + br->br_perm &= ~AuBrAttr_ICEX;
26946 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
26947 + && (au_br_sb(br)->s_flags & SB_NOSEC))
26948 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
26952 + wbr = br->br_wbr;
26954 + wbr_wh_read_lock(wbr);
26956 + if (!au_br_writable(br->br_perm)) {
26959 + || (!wbr->wbr_whbase
26960 + && !wbr->wbr_plink
26961 + && !wbr->wbr_orph));
26962 + } else if (!au_br_wh_linkable(br->br_perm)) {
26963 + /* skip = (!br->br_whbase && !br->br_orph); */
26964 + skip = (!wbr || !wbr->wbr_whbase);
26965 + if (skip && wbr) {
26967 + skip = !!wbr->wbr_plink;
26969 + skip = !wbr->wbr_plink;
26972 + /* skip = (br->br_whbase && br->br_ohph); */
26973 + skip = (wbr && wbr->wbr_whbase);
26976 + skip = !!wbr->wbr_plink;
26978 + skip = !wbr->wbr_plink;
26982 + wbr_wh_read_unlock(wbr);
26984 + if (can_no_dreval) {
26985 + dentry = br->br_path.dentry;
26986 + spin_lock(&dentry->d_lock);
26987 + if (dentry->d_flags &
26988 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
26989 + can_no_dreval = 0;
26990 + spin_unlock(&dentry->d_lock);
26993 + if (au_br_fhsm(br->br_perm)) {
26995 + AuDebugOn(!br->br_fhsm);
27001 + hdir = au_hi(dir, bindex);
27002 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27004 + wbr_wh_write_lock(wbr);
27005 + err = au_wh_init(br, sb);
27007 + wbr_wh_write_unlock(wbr);
27008 + au_hn_inode_unlock(hdir);
27010 + if (!err && do_free) {
27012 + br->br_wbr = NULL;
27016 + if (can_no_dreval)
27017 + au_fset_si(sbinfo, NO_DREVAL);
27019 + au_fclr_si(sbinfo, NO_DREVAL);
27022 + au_fset_si(sbinfo, FHSM);
27023 + for (bindex = bbot; bindex >= 0; bindex--) {
27024 + br = au_sbr(sb, bindex);
27025 + if (au_br_fhsm(br->br_perm)) {
27026 + au_fhsm_set_bottom(sb, bindex);
27031 + au_fclr_si(sbinfo, FHSM);
27032 + au_fhsm_set_bottom(sb, -1);
27038 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27041 + unsigned int tmp;
27042 + aufs_bindex_t bindex, bbot;
27043 + struct au_opt *opt;
27044 + struct au_opt_xino *opt_xino, xino;
27045 + struct au_sbinfo *sbinfo;
27046 + struct au_branch *br;
27047 + struct inode *dir;
27049 + SiMustWriteLock(sb);
27054 + while (err >= 0 && opt->type != Opt_tail)
27055 + err = au_opt_simple(sb, opt++, opts);
27058 + else if (unlikely(err < 0))
27061 + /* disable xino and udba temporary */
27062 + sbinfo = au_sbi(sb);
27063 + tmp = sbinfo->si_mntflags;
27064 + au_opt_clr(sbinfo->si_mntflags, XINO);
27065 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27068 + while (err >= 0 && opt->type != Opt_tail)
27069 + err = au_opt_br(sb, opt++, opts);
27072 + else if (unlikely(err < 0))
27075 + bbot = au_sbbot(sb);
27076 + if (unlikely(bbot < 0)) {
27078 + pr_err("no branches\n");
27082 + if (au_opt_test(tmp, XINO))
27083 + au_opt_set(sbinfo->si_mntflags, XINO);
27085 + while (!err && opt->type != Opt_tail)
27086 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27087 + if (unlikely(err))
27090 + err = au_opts_verify(sb, sb->s_flags, tmp);
27091 + if (unlikely(err))
27094 + /* restore xino */
27095 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27096 + xino.file = au_xino_def(sb);
27097 + err = PTR_ERR(xino.file);
27098 + if (IS_ERR(xino.file))
27101 + err = au_xino_set(sb, &xino, /*remount*/0);
27103 + if (unlikely(err))
27107 + /* restore udba */
27108 + tmp &= AuOptMask_UDBA;
27109 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27110 + sbinfo->si_mntflags |= tmp;
27111 + bbot = au_sbbot(sb);
27112 + for (bindex = 0; bindex <= bbot; bindex++) {
27113 + br = au_sbr(sb, bindex);
27114 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27115 + if (unlikely(err))
27116 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27118 + /* go on even if err */
27120 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27121 + dir = d_inode(sb->s_root);
27122 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27129 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27132 + unsigned char no_dreval;
27133 + struct inode *dir;
27134 + struct au_opt_xino *opt_xino;
27135 + struct au_opt *opt;
27136 + struct au_sbinfo *sbinfo;
27138 + SiMustWriteLock(sb);
27140 + err = au_dr_opt_flush(sb);
27141 + if (unlikely(err))
27143 + au_fset_opts(opts->flags, DR_FLUSHED);
27145 + dir = d_inode(sb->s_root);
27146 + sbinfo = au_sbi(sb);
27149 + while (err >= 0 && opt->type != Opt_tail) {
27150 + err = au_opt_simple(sb, opt, opts);
27152 + err = au_opt_br(sb, opt, opts);
27154 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27160 + /* go on even err */
27162 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27163 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27164 + if (unlikely(rerr && !err))
27167 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27168 + au_fset_opts(opts->flags, REFRESH_IDOP);
27170 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27171 + rerr = au_xib_trunc(sb);
27172 + if (unlikely(rerr && !err))
27176 + /* will be handled by the caller */
27177 + if (!au_ftest_opts(opts->flags, REFRESH)
27178 + && (opts->given_udba
27179 + || au_opt_test(sbinfo->si_mntflags, XINO)
27180 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27182 + au_fset_opts(opts->flags, REFRESH);
27184 + AuDbg("status 0x%x\n", opts->flags);
27190 +/* ---------------------------------------------------------------------- */
27192 +unsigned int au_opt_udba(struct super_block *sb)
27194 + return au_mntflags(sb) & AuOptMask_UDBA;
27196 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27197 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27198 +++ linux/fs/aufs/opts.h 2018-04-15 08:49:13.401150731 +0200
27201 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27203 + * This program, aufs is free software; you can redistribute it and/or modify
27204 + * it under the terms of the GNU General Public License as published by
27205 + * the Free Software Foundation; either version 2 of the License, or
27206 + * (at your option) any later version.
27208 + * This program is distributed in the hope that it will be useful,
27209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27211 + * GNU General Public License for more details.
27213 + * You should have received a copy of the GNU General Public License
27214 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27218 + * mount options/flags
27221 +#ifndef __AUFS_OPTS_H__
27222 +#define __AUFS_OPTS_H__
27226 +#include <linux/path.h>
27230 +/* ---------------------------------------------------------------------- */
27233 +#define AuOpt_XINO 1 /* external inode number bitmap
27234 + and translation table */
27235 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27236 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27237 +#define AuOpt_UDBA_REVAL (1 << 3)
27238 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27239 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27240 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27241 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27243 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27244 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27245 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27246 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27247 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27248 +#define AuOpt_DIO (1 << 14) /* direct io */
27249 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27251 +#ifndef CONFIG_AUFS_HNOTIFY
27252 +#undef AuOpt_UDBA_HNOTIFY
27253 +#define AuOpt_UDBA_HNOTIFY 0
27255 +#ifndef CONFIG_AUFS_DIRREN
27256 +#undef AuOpt_DIRREN
27257 +#define AuOpt_DIRREN 0
27259 +#ifndef CONFIG_AUFS_SHWH
27261 +#define AuOpt_SHWH 0
27264 +#define AuOpt_Def (AuOpt_XINO \
27265 + | AuOpt_UDBA_REVAL \
27267 + /* | AuOpt_DIRPERM1 */ \
27268 + | AuOpt_WARN_PERM)
27269 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27270 + | AuOpt_UDBA_REVAL \
27271 + | AuOpt_UDBA_HNOTIFY)
27273 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27274 +#define au_opt_set(flags, name) do { \
27275 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27276 + ((flags) |= AuOpt_##name); \
27278 +#define au_opt_set_udba(flags, name) do { \
27279 + (flags) &= ~AuOptMask_UDBA; \
27280 + ((flags) |= AuOpt_##name); \
27282 +#define au_opt_clr(flags, name) do { \
27283 + ((flags) &= ~AuOpt_##name); \
27286 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27288 +#ifdef CONFIG_PROC_FS
27291 + return mntflags & ~AuOpt_PLINK;
27295 +/* ---------------------------------------------------------------------- */
27297 +/* policies to select one among multiple writable branches */
27299 + AuWbrCreate_TDP, /* top down parent */
27300 + AuWbrCreate_RR, /* round robin */
27301 + AuWbrCreate_MFS, /* most free space */
27302 + AuWbrCreate_MFSV, /* mfs with seconds */
27303 + AuWbrCreate_MFSRR, /* mfs then rr */
27304 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27305 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27306 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27307 + AuWbrCreate_PMFS, /* parent and mfs */
27308 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27309 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27310 + AuWbrCreate_PMFSRRV, /* plus seconds */
27312 + AuWbrCreate_Def = AuWbrCreate_TDP
27316 + AuWbrCopyup_TDP, /* top down parent */
27317 + AuWbrCopyup_BUP, /* bottom up parent */
27318 + AuWbrCopyup_BU, /* bottom up */
27320 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27323 +/* ---------------------------------------------------------------------- */
27325 +struct au_opt_add {
27326 + aufs_bindex_t bindex;
27329 + struct path path;
27332 +struct au_opt_del {
27334 + struct path h_path;
27337 +struct au_opt_mod {
27340 + struct dentry *h_root;
27343 +struct au_opt_xino {
27345 + struct file *file;
27348 +struct au_opt_xino_itrunc {
27349 + aufs_bindex_t bindex;
27352 +struct au_opt_wbr_create {
27355 + unsigned long long mfsrr_watermark;
27361 + struct au_opt_xino xino;
27362 + struct au_opt_xino_itrunc xino_itrunc;
27363 + struct au_opt_add add;
27364 + struct au_opt_del del;
27365 + struct au_opt_mod mod;
27368 + unsigned int rdblk;
27369 + unsigned int rdhash;
27371 + struct au_opt_wbr_create wbr_create;
27373 + unsigned int fhsm_second;
27378 +#define AuOpts_REMOUNT 1
27379 +#define AuOpts_REFRESH (1 << 1)
27380 +#define AuOpts_TRUNC_XIB (1 << 2)
27381 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27382 +#define AuOpts_REFRESH_IDOP (1 << 4)
27383 +#define AuOpts_DR_FLUSHED (1 << 5)
27384 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27385 +#define au_fset_opts(flags, name) \
27386 + do { (flags) |= AuOpts_##name; } while (0)
27387 +#define au_fclr_opts(flags, name) \
27388 + do { (flags) &= ~AuOpts_##name; } while (0)
27390 +#ifndef CONFIG_AUFS_DIRREN
27391 +#undef AuOpts_DR_FLUSHED
27392 +#define AuOpts_DR_FLUSHED 0
27396 + struct au_opt *opt;
27399 + unsigned int given_udba;
27400 + unsigned int flags;
27401 + unsigned long sb_flags;
27404 +/* ---------------------------------------------------------------------- */
27407 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27408 +const char *au_optstr_udba(int udba);
27409 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27410 +const char *au_optstr_wbr_create(int wbr_create);
27412 +void au_opts_free(struct au_opts *opts);
27413 +struct super_block;
27414 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27415 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27416 + unsigned int pending);
27417 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27418 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27420 +unsigned int au_opt_udba(struct super_block *sb);
27422 +#endif /* __KERNEL__ */
27423 +#endif /* __AUFS_OPTS_H__ */
27424 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27425 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27426 +++ linux/fs/aufs/plink.c 2018-06-04 09:08:09.188079511 +0200
27429 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27431 + * This program, aufs is free software; you can redistribute it and/or modify
27432 + * it under the terms of the GNU General Public License as published by
27433 + * the Free Software Foundation; either version 2 of the License, or
27434 + * (at your option) any later version.
27436 + * This program is distributed in the hope that it will be useful,
27437 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27438 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27439 + * GNU General Public License for more details.
27441 + * You should have received a copy of the GNU General Public License
27442 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27452 + * the pseudo-link maintenance mode.
27453 + * during a user process maintains the pseudo-links,
27454 + * prohibit adding a new plink and branch manipulation.
27458 + * For entry functions which will handle plink, and i_mutex is already held
27460 + * They cannot wait and should return an error at once.
27461 + * Callers has to check the error.
27463 + * For entry functions which will handle plink, but i_mutex is not held
27465 + * They can wait the plink maintenance mode to finish.
27467 + * They behave like F_SETLK and F_SETLKW.
27468 + * If the caller never handle plink, then both flags are unnecessary.
27471 +int au_plink_maint(struct super_block *sb, int flags)
27475 + struct task_struct *parent, *prev;
27476 + struct au_sbinfo *sbi;
27478 + SiMustAnyLock(sb);
27481 + if (!au_opt_test(au_mntflags(sb), PLINK))
27484 + sbi = au_sbi(sb);
27485 + pid = sbi->si_plink_maint_pid;
27486 + if (!pid || pid == current->pid)
27489 + /* todo: it highly depends upon /sbin/mount.aufs */
27491 + parent = current;
27495 + parent = rcu_dereference(parent->real_parent);
27496 + if (parent == prev)
27498 + ppid = task_pid_vnr(parent);
27499 + if (pid == ppid) {
27500 + rcu_read_unlock();
27505 + rcu_read_unlock();
27507 + if (au_ftest_lock(flags, NOPLMW)) {
27508 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27509 + /* AuDebugOn(!lockdep_depth(current)); */
27510 + while (sbi->si_plink_maint_pid) {
27511 + si_read_unlock(sb);
27512 + /* gave up wake_up_bit() */
27513 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27515 + if (au_ftest_lock(flags, FLUSH))
27516 + au_nwt_flush(&sbi->si_nowait);
27517 + si_noflush_read_lock(sb);
27519 + } else if (au_ftest_lock(flags, NOPLM)) {
27520 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27528 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27530 + spin_lock(&sbinfo->si_plink_maint_lock);
27531 + sbinfo->si_plink_maint_pid = 0;
27532 + spin_unlock(&sbinfo->si_plink_maint_lock);
27533 + wake_up_all(&sbinfo->si_plink_wq);
27536 +int au_plink_maint_enter(struct super_block *sb)
27539 + struct au_sbinfo *sbinfo;
27542 + sbinfo = au_sbi(sb);
27543 + /* make sure i am the only one in this fs */
27544 + si_write_lock(sb, AuLock_FLUSH);
27545 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27546 + spin_lock(&sbinfo->si_plink_maint_lock);
27547 + if (!sbinfo->si_plink_maint_pid)
27548 + sbinfo->si_plink_maint_pid = current->pid;
27551 + spin_unlock(&sbinfo->si_plink_maint_lock);
27553 + si_write_unlock(sb);
27558 +/* ---------------------------------------------------------------------- */
27560 +#ifdef CONFIG_AUFS_DEBUG
27561 +void au_plink_list(struct super_block *sb)
27564 + struct au_sbinfo *sbinfo;
27565 + struct hlist_bl_head *hbl;
27566 + struct hlist_bl_node *pos;
27567 + struct au_icntnr *icntnr;
27569 + SiMustAnyLock(sb);
27571 + sbinfo = au_sbi(sb);
27572 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27573 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27575 + for (i = 0; i < AuPlink_NHASH; i++) {
27576 + hbl = sbinfo->si_plink + i;
27577 + hlist_bl_lock(hbl);
27578 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27579 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27580 + hlist_bl_unlock(hbl);
27585 +/* is the inode pseudo-linked? */
27586 +int au_plink_test(struct inode *inode)
27589 + struct au_sbinfo *sbinfo;
27590 + struct hlist_bl_head *hbl;
27591 + struct hlist_bl_node *pos;
27592 + struct au_icntnr *icntnr;
27594 + sbinfo = au_sbi(inode->i_sb);
27595 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27596 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27597 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27600 + i = au_plink_hash(inode->i_ino);
27601 + hbl = sbinfo->si_plink + i;
27602 + hlist_bl_lock(hbl);
27603 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27604 + if (&icntnr->vfs_inode == inode) {
27608 + hlist_bl_unlock(hbl);
27612 +/* ---------------------------------------------------------------------- */
27615 + * generate a name for plink.
27616 + * the file will be stored under AUFS_WH_PLINKDIR.
27618 +/* 20 is max digits length of ulong 64 */
27619 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27621 +static int plink_name(char *name, int len, struct inode *inode,
27622 + aufs_bindex_t bindex)
27625 + struct inode *h_inode;
27627 + h_inode = au_h_iptr(inode, bindex);
27628 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27632 +struct au_do_plink_lkup_args {
27633 + struct dentry **errp;
27634 + struct qstr *tgtname;
27635 + struct dentry *h_parent;
27636 + struct au_branch *br;
27639 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27640 + struct dentry *h_parent,
27641 + struct au_branch *br)
27643 + struct dentry *h_dentry;
27644 + struct inode *h_inode;
27646 + h_inode = d_inode(h_parent);
27647 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27648 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27649 + inode_unlock_shared(h_inode);
27653 +static void au_call_do_plink_lkup(void *args)
27655 + struct au_do_plink_lkup_args *a = args;
27656 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27659 +/* lookup the plink-ed @inode under the branch at @bindex */
27660 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27662 + struct dentry *h_dentry, *h_parent;
27663 + struct au_branch *br;
27665 + char a[PLINK_NAME_LEN];
27666 + struct qstr tgtname = QSTR_INIT(a, 0);
27668 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27670 + br = au_sbr(inode->i_sb, bindex);
27671 + h_parent = br->br_wbr->wbr_plink;
27672 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27674 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27675 + struct au_do_plink_lkup_args args = {
27676 + .errp = &h_dentry,
27677 + .tgtname = &tgtname,
27678 + .h_parent = h_parent,
27682 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27683 + if (unlikely(wkq_err))
27684 + h_dentry = ERR_PTR(wkq_err);
27686 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27691 +/* create a pseudo-link */
27692 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27693 + struct dentry *h_dentry, struct au_branch *br)
27696 + struct path h_path = {
27697 + .mnt = au_br_mnt(br)
27699 + struct inode *h_dir, *delegated;
27701 + h_dir = d_inode(h_parent);
27702 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27704 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27705 + err = PTR_ERR(h_path.dentry);
27706 + if (IS_ERR(h_path.dentry))
27710 + /* wh.plink dir is not monitored */
27711 + /* todo: is it really safe? */
27712 + if (d_is_positive(h_path.dentry)
27713 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27714 + delegated = NULL;
27715 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27716 + if (unlikely(err == -EWOULDBLOCK)) {
27717 + pr_warn("cannot retry for NFSv4 delegation"
27718 + " for an internal unlink\n");
27721 + dput(h_path.dentry);
27722 + h_path.dentry = NULL;
27726 + if (!err && d_is_negative(h_path.dentry)) {
27727 + delegated = NULL;
27728 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27729 + if (unlikely(err == -EWOULDBLOCK)) {
27730 + pr_warn("cannot retry for NFSv4 delegation"
27731 + " for an internal link\n");
27735 + dput(h_path.dentry);
27738 + inode_unlock(h_dir);
27742 +struct do_whplink_args {
27744 + struct qstr *tgt;
27745 + struct dentry *h_parent;
27746 + struct dentry *h_dentry;
27747 + struct au_branch *br;
27750 +static void call_do_whplink(void *args)
27752 + struct do_whplink_args *a = args;
27753 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27756 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27757 + aufs_bindex_t bindex, struct au_branch *br)
27759 + int err, wkq_err;
27760 + struct au_wbr *wbr;
27761 + struct dentry *h_parent;
27762 + char a[PLINK_NAME_LEN];
27763 + struct qstr tgtname = QSTR_INIT(a, 0);
27765 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
27766 + h_parent = wbr->wbr_plink;
27767 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27769 + /* always superio. */
27770 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27771 + struct do_whplink_args args = {
27774 + .h_parent = h_parent,
27775 + .h_dentry = h_dentry,
27778 + wkq_err = au_wkq_wait(call_do_whplink, &args);
27779 + if (unlikely(wkq_err))
27782 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
27788 + * create a new pseudo-link for @h_dentry on @bindex.
27789 + * the linked inode is held in aufs @inode.
27791 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
27792 + struct dentry *h_dentry)
27794 + struct super_block *sb;
27795 + struct au_sbinfo *sbinfo;
27796 + struct hlist_bl_head *hbl;
27797 + struct hlist_bl_node *pos;
27798 + struct au_icntnr *icntnr;
27799 + int found, err, cnt, i;
27801 + sb = inode->i_sb;
27802 + sbinfo = au_sbi(sb);
27803 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27804 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27806 + found = au_plink_test(inode);
27810 + i = au_plink_hash(inode->i_ino);
27811 + hbl = sbinfo->si_plink + i;
27814 + hlist_bl_lock(hbl);
27815 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
27816 + if (&icntnr->vfs_inode == inode) {
27822 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
27823 + hlist_bl_add_head(&icntnr->plink, hbl);
27825 + hlist_bl_unlock(hbl);
27827 + cnt = au_hbl_count(hbl);
27828 +#define msg "unexpectedly unblanced or too many pseudo-links"
27829 + if (cnt > AUFS_PLINK_WARN)
27830 + AuWarn1(msg ", %d\n", cnt);
27832 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
27833 + if (unlikely(err)) {
27834 + pr_warn("err %d, damaged pseudo link.\n", err);
27835 + au_hbl_del(&icntnr->plink, hbl);
27836 + iput(&icntnr->vfs_inode);
27839 + iput(&icntnr->vfs_inode);
27842 +/* free all plinks */
27843 +void au_plink_put(struct super_block *sb, int verbose)
27846 + struct au_sbinfo *sbinfo;
27847 + struct hlist_bl_head *hbl;
27848 + struct hlist_bl_node *pos, *tmp;
27849 + struct au_icntnr *icntnr;
27851 + SiMustWriteLock(sb);
27853 + sbinfo = au_sbi(sb);
27854 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27855 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27857 + /* no spin_lock since sbinfo is write-locked */
27859 + for (i = 0; i < AuPlink_NHASH; i++) {
27860 + hbl = sbinfo->si_plink + i;
27861 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
27862 + pr_warn("pseudo-link is not flushed");
27865 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
27866 + iput(&icntnr->vfs_inode);
27867 + INIT_HLIST_BL_HEAD(hbl);
27871 +void au_plink_clean(struct super_block *sb, int verbose)
27873 + struct dentry *root;
27875 + root = sb->s_root;
27876 + aufs_write_lock(root);
27877 + if (au_opt_test(au_mntflags(sb), PLINK))
27878 + au_plink_put(sb, verbose);
27879 + aufs_write_unlock(root);
27882 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
27885 + aufs_bindex_t btop, bbot, bindex;
27888 + btop = au_ibtop(inode);
27889 + bbot = au_ibbot(inode);
27891 + for (bindex = btop; bindex <= bbot; bindex++) {
27892 + if (!au_h_iptr(inode, bindex)
27893 + || au_ii_br_id(inode, bindex) != br_id)
27895 + au_set_h_iptr(inode, bindex, NULL, 0);
27900 + for (bindex = btop; bindex <= bbot; bindex++)
27901 + if (au_h_iptr(inode, bindex)) {
27911 +/* free the plinks on a branch specified by @br_id */
27912 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
27914 + struct au_sbinfo *sbinfo;
27915 + struct hlist_bl_head *hbl;
27916 + struct hlist_bl_node *pos, *tmp;
27917 + struct au_icntnr *icntnr;
27918 + struct inode *inode;
27921 + SiMustWriteLock(sb);
27923 + sbinfo = au_sbi(sb);
27924 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27925 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27927 + /* no bit_lock since sbinfo is write-locked */
27928 + for (i = 0; i < AuPlink_NHASH; i++) {
27929 + hbl = sbinfo->si_plink + i;
27930 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
27931 + inode = au_igrab(&icntnr->vfs_inode);
27932 + ii_write_lock_child(inode);
27933 + do_put = au_plink_do_half_refresh(inode, br_id);
27935 + hlist_bl_del(&icntnr->plink);
27938 + ii_write_unlock(inode);
27943 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
27944 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
27945 +++ linux/fs/aufs/poll.c 2018-06-04 09:08:09.188079511 +0200
27948 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27950 + * This program, aufs is free software; you can redistribute it and/or modify
27951 + * it under the terms of the GNU General Public License as published by
27952 + * the Free Software Foundation; either version 2 of the License, or
27953 + * (at your option) any later version.
27955 + * This program is distributed in the hope that it will be useful,
27956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27958 + * GNU General Public License for more details.
27960 + * You should have received a copy of the GNU General Public License
27961 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27966 + * There is only one filesystem which implements ->poll operation, currently.
27971 +__poll_t aufs_poll(struct file *file, poll_table *wait)
27975 + struct file *h_file;
27976 + struct super_block *sb;
27978 + /* We should pretend an error happened. */
27979 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
27980 + sb = file->f_path.dentry->d_sb;
27981 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
27983 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
27984 + err = PTR_ERR(h_file);
27985 + if (IS_ERR(h_file))
27988 + /* it is not an error if h_file has no operation */
27989 + mask = DEFAULT_POLLMASK;
27990 + if (h_file->f_op->poll)
27991 + mask = h_file->f_op->poll(h_file, wait);
27992 + fput(h_file); /* instead of au_read_post() */
27995 + si_read_unlock(sb);
27996 + if (mask & POLLERR)
27997 + AuDbg("mask 0x%x\n", mask);
28000 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28001 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28002 +++ linux/fs/aufs/posix_acl.c 2018-06-04 09:08:09.188079511 +0200
28005 + * Copyright (C) 2014-2018 Junjiro R. Okajima
28007 + * This program, aufs is free software; you can redistribute it and/or modify
28008 + * it under the terms of the GNU General Public License as published by
28009 + * the Free Software Foundation; either version 2 of the License, or
28010 + * (at your option) any later version.
28012 + * This program is distributed in the hope that it will be useful,
28013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28015 + * GNU General Public License for more details.
28017 + * You should have received a copy of the GNU General Public License
28018 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28022 + * posix acl operations
28025 +#include <linux/fs.h>
28028 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28030 + struct posix_acl *acl;
28032 + aufs_bindex_t bindex;
28033 + struct inode *h_inode;
28034 + struct super_block *sb;
28037 + sb = inode->i_sb;
28038 + si_read_lock(sb, AuLock_FLUSH);
28039 + ii_read_lock_child(inode);
28040 + if (!(sb->s_flags & SB_POSIXACL))
28043 + bindex = au_ibtop(inode);
28044 + h_inode = au_h_iptr(inode, bindex);
28045 + if (unlikely(!h_inode
28046 + || ((h_inode->i_mode & S_IFMT)
28047 + != (inode->i_mode & S_IFMT)))) {
28048 + err = au_busy_or_stale();
28049 + acl = ERR_PTR(err);
28053 + /* always topmost only */
28054 + acl = get_acl(h_inode, type);
28055 + if (!IS_ERR_OR_NULL(acl))
28056 + set_cached_acl(inode, type, acl);
28059 + ii_read_unlock(inode);
28060 + si_read_unlock(sb);
28062 + AuTraceErrPtr(acl);
28066 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28070 + struct dentry *dentry;
28071 + struct au_sxattr arg = {
28072 + .type = AU_ACL_SET,
28079 + IMustLock(inode);
28081 + if (inode->i_ino == AUFS_ROOT_INO)
28082 + dentry = dget(inode->i_sb->s_root);
28084 + dentry = d_find_alias(inode);
28086 + dentry = d_find_any_alias(inode);
28088 + pr_warn("cannot handle this inode, "
28089 + "please report to aufs-users ML\n");
28095 + ssz = au_sxattr(dentry, inode, &arg);
28100 + set_cached_acl(inode, type, acl);
28106 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28107 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28108 +++ linux/fs/aufs/procfs.c 2018-04-15 08:49:13.401150731 +0200
28111 + * Copyright (C) 2010-2018 Junjiro R. Okajima
28113 + * This program, aufs is free software; you can redistribute it and/or modify
28114 + * it under the terms of the GNU General Public License as published by
28115 + * the Free Software Foundation; either version 2 of the License, or
28116 + * (at your option) any later version.
28118 + * This program is distributed in the hope that it will be useful,
28119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28121 + * GNU General Public License for more details.
28123 + * You should have received a copy of the GNU General Public License
28124 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28128 + * procfs interfaces
28131 +#include <linux/proc_fs.h>
28134 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28136 + struct au_sbinfo *sbinfo;
28138 + sbinfo = file->private_data;
28140 + au_plink_maint_leave(sbinfo);
28141 + kobject_put(&sbinfo->si_kobj);
28147 +static void au_procfs_plm_write_clean(struct file *file)
28149 + struct au_sbinfo *sbinfo;
28151 + sbinfo = file->private_data;
28153 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28156 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28159 + struct super_block *sb;
28160 + struct au_sbinfo *sbinfo;
28161 + struct hlist_bl_node *pos;
28164 + if (unlikely(file->private_data))
28168 + /* don't use au_sbilist_lock() here */
28169 + hlist_bl_lock(&au_sbilist);
28170 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28171 + if (id == sysaufs_si_id(sbinfo)) {
28172 + kobject_get(&sbinfo->si_kobj);
28173 + sb = sbinfo->si_sb;
28176 + hlist_bl_unlock(&au_sbilist);
28179 + if (unlikely(!sb))
28182 + err = au_plink_maint_enter(sb);
28184 + /* keep kobject_get() */
28185 + file->private_data = sbinfo;
28187 + kobject_put(&sbinfo->si_kobj);
28193 + * Accept a valid "si=xxxx" only.
28194 + * Once it is accepted successfully, accept "clean" too.
28196 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28197 + size_t count, loff_t *ppos)
28200 + unsigned long id;
28201 + /* last newline is allowed */
28202 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28205 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28209 + if (unlikely(count > sizeof(buf)))
28212 + err = copy_from_user(buf, ubuf, count);
28213 + if (unlikely(err)) {
28220 + if (!strcmp("clean", buf)) {
28221 + au_procfs_plm_write_clean(file);
28222 + goto out_success;
28223 + } else if (unlikely(strncmp("si=", buf, 3)))
28226 + err = kstrtoul(buf + 3, 16, &id);
28227 + if (unlikely(err))
28230 + err = au_procfs_plm_write_si(file, id);
28231 + if (unlikely(err))
28235 + err = count; /* success */
28240 +static const struct file_operations au_procfs_plm_fop = {
28241 + .write = au_procfs_plm_write,
28242 + .release = au_procfs_plm_release,
28243 + .owner = THIS_MODULE
28246 +/* ---------------------------------------------------------------------- */
28248 +static struct proc_dir_entry *au_procfs_dir;
28250 +void au_procfs_fin(void)
28252 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28253 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28256 +int __init au_procfs_init(void)
28259 + struct proc_dir_entry *entry;
28262 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28263 + if (unlikely(!au_procfs_dir))
28266 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
28267 + au_procfs_dir, &au_procfs_plm_fop);
28268 + if (unlikely(!entry))
28272 + goto out; /* success */
28276 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28280 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28281 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28282 +++ linux/fs/aufs/rdu.c 2018-04-15 08:49:13.404484168 +0200
28285 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28287 + * This program, aufs is free software; you can redistribute it and/or modify
28288 + * it under the terms of the GNU General Public License as published by
28289 + * the Free Software Foundation; either version 2 of the License, or
28290 + * (at your option) any later version.
28292 + * This program is distributed in the hope that it will be useful,
28293 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28294 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28295 + * GNU General Public License for more details.
28297 + * You should have received a copy of the GNU General Public License
28298 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28302 + * readdir in userspace.
28305 +#include <linux/compat.h>
28306 +#include <linux/fs_stack.h>
28307 +#include <linux/security.h>
28310 +/* bits for struct aufs_rdu.flags */
28311 +#define AuRdu_CALLED 1
28312 +#define AuRdu_CONT (1 << 1)
28313 +#define AuRdu_FULL (1 << 2)
28314 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28315 +#define au_fset_rdu(flags, name) \
28316 + do { (flags) |= AuRdu_##name; } while (0)
28317 +#define au_fclr_rdu(flags, name) \
28318 + do { (flags) &= ~AuRdu_##name; } while (0)
28320 +struct au_rdu_arg {
28321 + struct dir_context ctx;
28322 + struct aufs_rdu *rdu;
28323 + union au_rdu_ent_ul ent;
28324 + unsigned long end;
28326 + struct super_block *sb;
28330 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28331 + loff_t offset, u64 h_ino, unsigned int d_type)
28334 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28335 + struct aufs_rdu *rdu = arg->rdu;
28336 + struct au_rdu_ent ent;
28340 + au_fset_rdu(rdu->cookie.flags, CALLED);
28341 + len = au_rdu_len(nlen);
28342 + if (arg->ent.ul + len < arg->end) {
28344 + ent.bindex = rdu->cookie.bindex;
28345 + ent.type = d_type;
28347 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28348 + ent.type = DT_UNKNOWN;
28350 + /* unnecessary to support mmap_sem since this is a dir */
28352 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28354 + if (copy_to_user(arg->ent.e->name, name, nlen))
28356 + /* the terminating NULL */
28357 + if (__put_user(0, arg->ent.e->name + nlen))
28360 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28361 + arg->ent.ul += len;
28365 + au_fset_rdu(rdu->cookie.flags, FULL);
28367 + rdu->tail = arg->ent;
28371 + /* AuTraceErr(err); */
28375 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28379 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28381 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28382 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28384 + if (unlikely(offset != cookie->h_pos))
28390 + au_fclr_rdu(cookie->flags, CALLED);
28392 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28396 + && au_ftest_rdu(cookie->flags, CALLED)
28397 + && !au_ftest_rdu(cookie->flags, FULL));
28398 + cookie->h_pos = h_file->f_pos;
28405 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28408 + aufs_bindex_t bbot;
28409 + struct au_rdu_arg arg = {
28411 + .actor = au_rdu_fill
28414 + struct dentry *dentry;
28415 + struct inode *inode;
28416 + struct file *h_file;
28417 + struct au_rdu_cookie *cookie = &rdu->cookie;
28419 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28420 + if (unlikely(err)) {
28426 + rdu->tail = rdu->ent;
28429 + arg.ent = rdu->ent;
28430 + arg.end = arg.ent.ul;
28431 + arg.end += rdu->sz;
28434 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28437 + err = security_file_permission(file, MAY_READ);
28439 + if (unlikely(err))
28442 + dentry = file->f_path.dentry;
28443 + inode = d_inode(dentry);
28444 + inode_lock_shared(inode);
28446 + arg.sb = inode->i_sb;
28447 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28448 + if (unlikely(err))
28450 + err = au_alive_dir(dentry);
28451 + if (unlikely(err))
28453 + /* todo: reval? */
28454 + fi_read_lock(file);
28457 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28458 + && cookie->generation != au_figen(file)))
28463 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28465 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28467 + bbot = au_fbtop(file);
28468 + if (cookie->bindex < bbot)
28469 + cookie->bindex = bbot;
28470 + bbot = au_fbbot_dir(file);
28471 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28472 + for (; !err && cookie->bindex <= bbot;
28473 + cookie->bindex++, cookie->h_pos = 0) {
28474 + h_file = au_hf_dir(file, cookie->bindex);
28478 + au_fclr_rdu(cookie->flags, FULL);
28479 + err = au_rdu_do(h_file, &arg);
28481 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28484 + AuDbg("rent %llu\n", rdu->rent);
28486 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28487 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28488 + au_fset_rdu(cookie->flags, CONT);
28489 + cookie->generation = au_figen(file);
28492 + ii_read_lock_child(inode);
28493 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28494 + ii_read_unlock(inode);
28497 + fi_read_unlock(file);
28499 + si_read_unlock(arg.sb);
28501 + inode_unlock_shared(inode);
28507 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28511 + unsigned long long nent;
28512 + union au_rdu_ent_ul *u;
28513 + struct au_rdu_ent ent;
28514 + struct super_block *sb;
28517 + nent = rdu->nent;
28519 + sb = file->f_path.dentry->d_sb;
28520 + si_read_lock(sb, AuLock_FLUSH);
28521 + while (nent-- > 0) {
28522 + /* unnecessary to support mmap_sem since this is a dir */
28523 + err = copy_from_user(&ent, u->e, sizeof(ent));
28525 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28526 + if (unlikely(err)) {
28532 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28534 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28536 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28538 + if (unlikely(err)) {
28543 + err = __put_user(ino, &u->e->ino);
28544 + if (unlikely(err)) {
28549 + u->ul += au_rdu_len(ent.nlen);
28551 + si_read_unlock(sb);
28556 +/* ---------------------------------------------------------------------- */
28558 +static int au_rdu_verify(struct aufs_rdu *rdu)
28560 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28561 + "%llu, b%d, 0x%x, g%u}\n",
28562 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28564 + rdu->rent, rdu->shwh, rdu->full,
28565 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28566 + rdu->cookie.generation);
28568 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28572 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28576 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28579 + struct aufs_rdu rdu;
28580 + void __user *p = (void __user *)arg;
28582 + err = copy_from_user(&rdu, p, sizeof(rdu));
28583 + if (unlikely(err)) {
28588 + err = au_rdu_verify(&rdu);
28589 + if (unlikely(err))
28593 + case AUFS_CTL_RDU:
28594 + err = au_rdu(file, &rdu);
28595 + if (unlikely(err))
28598 + e = copy_to_user(p, &rdu, sizeof(rdu));
28599 + if (unlikely(e)) {
28604 + case AUFS_CTL_RDU_INO:
28605 + err = au_rdu_ino(file, &rdu);
28609 + /* err = -ENOTTY; */
28618 +#ifdef CONFIG_COMPAT
28619 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28622 + struct aufs_rdu rdu;
28623 + void __user *p = compat_ptr(arg);
28625 + /* todo: get_user()? */
28626 + err = copy_from_user(&rdu, p, sizeof(rdu));
28627 + if (unlikely(err)) {
28632 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28633 + err = au_rdu_verify(&rdu);
28634 + if (unlikely(err))
28638 + case AUFS_CTL_RDU:
28639 + err = au_rdu(file, &rdu);
28640 + if (unlikely(err))
28643 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28644 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28645 + e = copy_to_user(p, &rdu, sizeof(rdu));
28646 + if (unlikely(e)) {
28651 + case AUFS_CTL_RDU_INO:
28652 + err = au_rdu_ino(file, &rdu);
28656 + /* err = -ENOTTY; */
28665 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28666 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28667 +++ linux/fs/aufs/rwsem.h 2018-06-04 09:08:09.188079511 +0200
28670 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28672 + * This program, aufs is free software; you can redistribute it and/or modify
28673 + * it under the terms of the GNU General Public License as published by
28674 + * the Free Software Foundation; either version 2 of the License, or
28675 + * (at your option) any later version.
28677 + * This program is distributed in the hope that it will be useful,
28678 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28679 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28680 + * GNU General Public License for more details.
28682 + * You should have received a copy of the GNU General Public License
28683 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28687 + * simple read-write semaphore wrappers
28690 +#ifndef __AUFS_RWSEM_H__
28691 +#define __AUFS_RWSEM_H__
28695 +#include "debug.h"
28697 +/* in the futre, the name 'au_rwsem' will be totally gone */
28698 +#define au_rwsem rw_semaphore
28700 +/* to debug easier, do not make them inlined functions */
28701 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28702 +/* rwsem_is_locked() is unusable */
28703 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
28705 + && !lockdep_is_held_type(rw, 1))
28706 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
28708 + && !lockdep_is_held_type(rw, 0))
28709 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
28711 + && !lockdep_is_held(rw))
28712 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
28714 + && lockdep_is_held(rw))
28716 +#define au_rw_init(rw) init_rwsem(rw)
28718 +#define au_rw_init_wlock(rw) do { \
28719 + au_rw_init(rw); \
28720 + down_write(rw); \
28723 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28724 + au_rw_init(rw); \
28725 + down_write_nested(rw, lsc); \
28728 +#define au_rw_read_lock(rw) down_read(rw)
28729 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28730 +#define au_rw_read_unlock(rw) up_read(rw)
28731 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28732 +#define au_rw_write_lock(rw) down_write(rw)
28733 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28734 +#define au_rw_write_unlock(rw) up_write(rw)
28735 +/* why is not _nested version defined? */
28736 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28737 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28739 +#endif /* __KERNEL__ */
28740 +#endif /* __AUFS_RWSEM_H__ */
28741 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28742 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28743 +++ linux/fs/aufs/sbinfo.c 2018-06-04 09:08:09.188079511 +0200
28746 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28748 + * This program, aufs is free software; you can redistribute it and/or modify
28749 + * it under the terms of the GNU General Public License as published by
28750 + * the Free Software Foundation; either version 2 of the License, or
28751 + * (at your option) any later version.
28753 + * This program is distributed in the hope that it will be useful,
28754 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28755 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28756 + * GNU General Public License for more details.
28758 + * You should have received a copy of the GNU General Public License
28759 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28763 + * superblock private data
28769 + * they are necessary regardless sysfs is disabled.
28771 +void au_si_free(struct kobject *kobj)
28774 + struct au_sbinfo *sbinfo;
28775 + char *locked __maybe_unused; /* debug only */
28777 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28778 + for (i = 0; i < AuPlink_NHASH; i++)
28779 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
28780 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
28782 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
28783 + percpu_counter_destroy(&sbinfo->si_ninodes);
28784 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
28785 + percpu_counter_destroy(&sbinfo->si_nfiles);
28787 + au_rw_write_lock(&sbinfo->si_rwsem);
28788 + au_br_free(sbinfo);
28789 + au_rw_write_unlock(&sbinfo->si_rwsem);
28791 + kfree(sbinfo->si_branch);
28792 + mutex_destroy(&sbinfo->si_xib_mtx);
28793 + AuRwDestroy(&sbinfo->si_rwsem);
28798 +int au_si_alloc(struct super_block *sb)
28801 + struct au_sbinfo *sbinfo;
28804 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
28805 + if (unlikely(!sbinfo))
28808 + /* will be reallocated separately */
28809 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
28810 + if (unlikely(!sbinfo->si_branch))
28813 + err = sysaufs_si_init(sbinfo);
28814 + if (unlikely(err))
28817 + au_nwt_init(&sbinfo->si_nowait);
28818 + au_rw_init_wlock(&sbinfo->si_rwsem);
28820 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
28821 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
28823 + sbinfo->si_bbot = -1;
28824 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
28826 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
28827 + sbinfo->si_wbr_create = AuWbrCreate_Def;
28828 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
28829 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
28831 + au_fhsm_init(sbinfo);
28833 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
28835 + sbinfo->si_xino_jiffy = jiffies;
28836 + sbinfo->si_xino_expire
28837 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
28838 + mutex_init(&sbinfo->si_xib_mtx);
28839 + sbinfo->si_xino_brid = -1;
28840 + /* leave si_xib_last_pindex and si_xib_next_bit */
28842 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
28844 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
28845 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
28846 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
28847 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
28849 + for (i = 0; i < AuPlink_NHASH; i++)
28850 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
28851 + init_waitqueue_head(&sbinfo->si_plink_wq);
28852 + spin_lock_init(&sbinfo->si_plink_maint_lock);
28854 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
28856 + /* with getattr by default */
28857 + sbinfo->si_iop_array = aufs_iop;
28859 + /* leave other members for sysaufs and si_mnt. */
28860 + sbinfo->si_sb = sb;
28861 + sb->s_fs_info = sbinfo;
28863 + return 0; /* success */
28866 + kfree(sbinfo->si_branch);
28873 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
28876 + struct au_branch **brp;
28878 + AuRwMustWriteLock(&sbinfo->si_rwsem);
28881 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
28882 + if (unlikely(!sz))
28883 + sz = sizeof(*brp);
28884 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
28887 + sbinfo->si_branch = brp;
28894 +/* ---------------------------------------------------------------------- */
28896 +unsigned int au_sigen_inc(struct super_block *sb)
28898 + unsigned int gen;
28899 + struct inode *inode;
28901 + SiMustWriteLock(sb);
28903 + gen = ++au_sbi(sb)->si_generation;
28904 + au_update_digen(sb->s_root);
28905 + inode = d_inode(sb->s_root);
28906 + au_update_iigen(inode, /*half*/0);
28907 + inode_inc_iversion(inode);
28911 +aufs_bindex_t au_new_br_id(struct super_block *sb)
28913 + aufs_bindex_t br_id;
28915 + struct au_sbinfo *sbinfo;
28917 + SiMustWriteLock(sb);
28919 + sbinfo = au_sbi(sb);
28920 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
28921 + br_id = ++sbinfo->si_last_br_id;
28922 + AuDebugOn(br_id < 0);
28923 + if (br_id && au_br_index(sb, br_id) < 0)
28930 +/* ---------------------------------------------------------------------- */
28932 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
28933 +int si_read_lock(struct super_block *sb, int flags)
28938 + if (au_ftest_lock(flags, FLUSH))
28939 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28941 + si_noflush_read_lock(sb);
28942 + err = au_plink_maint(sb, flags);
28943 + if (unlikely(err))
28944 + si_read_unlock(sb);
28949 +int si_write_lock(struct super_block *sb, int flags)
28953 + if (au_ftest_lock(flags, FLUSH))
28954 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28956 + si_noflush_write_lock(sb);
28957 + err = au_plink_maint(sb, flags);
28958 + if (unlikely(err))
28959 + si_write_unlock(sb);
28964 +/* dentry and super_block lock. call at entry point */
28965 +int aufs_read_lock(struct dentry *dentry, int flags)
28968 + struct super_block *sb;
28970 + sb = dentry->d_sb;
28971 + err = si_read_lock(sb, flags);
28972 + if (unlikely(err))
28975 + if (au_ftest_lock(flags, DW))
28976 + di_write_lock_child(dentry);
28978 + di_read_lock_child(dentry, flags);
28980 + if (au_ftest_lock(flags, GEN)) {
28981 + err = au_digen_test(dentry, au_sigen(sb));
28982 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
28983 + AuDebugOn(!err && au_dbrange_test(dentry));
28985 + err = au_dbrange_test(dentry);
28986 + if (unlikely(err))
28987 + aufs_read_unlock(dentry, flags);
28994 +void aufs_read_unlock(struct dentry *dentry, int flags)
28996 + if (au_ftest_lock(flags, DW))
28997 + di_write_unlock(dentry);
28999 + di_read_unlock(dentry, flags);
29000 + si_read_unlock(dentry->d_sb);
29003 +void aufs_write_lock(struct dentry *dentry)
29005 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29006 + di_write_lock_child(dentry);
29009 +void aufs_write_unlock(struct dentry *dentry)
29011 + di_write_unlock(dentry);
29012 + si_write_unlock(dentry->d_sb);
29015 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29018 + unsigned int sigen;
29019 + struct super_block *sb;
29022 + err = si_read_lock(sb, flags);
29023 + if (unlikely(err))
29026 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29028 + if (au_ftest_lock(flags, GEN)) {
29029 + sigen = au_sigen(sb);
29030 + err = au_digen_test(d1, sigen);
29031 + AuDebugOn(!err && au_dbrange_test(d1));
29033 + err = au_digen_test(d2, sigen);
29034 + AuDebugOn(!err && au_dbrange_test(d2));
29036 + if (unlikely(err))
29037 + aufs_read_and_write_unlock2(d1, d2);
29044 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29046 + di_write_unlock2(d1, d2);
29047 + si_read_unlock(d1->d_sb);
29049 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29050 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29051 +++ linux/fs/aufs/super.c 2018-06-04 09:08:09.188079511 +0200
29054 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29056 + * This program, aufs is free software; you can redistribute it and/or modify
29057 + * it under the terms of the GNU General Public License as published by
29058 + * the Free Software Foundation; either version 2 of the License, or
29059 + * (at your option) any later version.
29061 + * This program is distributed in the hope that it will be useful,
29062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29064 + * GNU General Public License for more details.
29066 + * You should have received a copy of the GNU General Public License
29067 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29071 + * mount and super_block operations
29074 +#include <linux/mm.h>
29075 +#include <linux/seq_file.h>
29076 +#include <linux/statfs.h>
29077 +#include <linux/vmalloc.h>
29081 + * super_operations
29083 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29085 + struct au_icntnr *c;
29087 + c = au_cache_alloc_icntnr();
29089 + au_icntnr_init(c);
29090 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29091 + c->iinfo.ii_hinode = NULL;
29092 + return &c->vfs_inode;
29097 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29099 + struct inode *inode = container_of(head, struct inode, i_rcu);
29101 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29104 +static void aufs_destroy_inode(struct inode *inode)
29106 + if (!au_is_bad_inode(inode))
29107 + au_iinfo_fin(inode);
29108 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29111 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29113 + struct inode *inode;
29116 + inode = iget_locked(sb, ino);
29117 + if (unlikely(!inode)) {
29118 + inode = ERR_PTR(-ENOMEM);
29121 + if (!(inode->i_state & I_NEW))
29124 + err = au_xigen_new(inode);
29126 + err = au_iinfo_init(inode);
29128 + inode_inc_iversion(inode);
29130 + iget_failed(inode);
29131 + inode = ERR_PTR(err);
29135 + /* never return NULL */
29136 + AuDebugOn(!inode);
29137 + AuTraceErrPtr(inode);
29141 +/* lock free root dinfo */
29142 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29145 + aufs_bindex_t bindex, bbot;
29146 + struct path path;
29147 + struct au_hdentry *hdp;
29148 + struct au_branch *br;
29149 + au_br_perm_str_t perm;
29152 + bbot = au_sbbot(sb);
29154 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29155 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29156 + br = au_sbr(sb, bindex);
29157 + path.mnt = au_br_mnt(br);
29158 + path.dentry = hdp->hd_dentry;
29159 + err = au_seq_path(seq, &path);
29161 + au_optstr_br_perm(&perm, br->br_perm);
29162 + seq_printf(seq, "=%s", perm.a);
29163 + if (bindex != bbot)
29164 + seq_putc(seq, ':');
29167 + if (unlikely(err || seq_has_overflowed(seq)))
29173 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29174 + const char *append)
29179 + while (*pat != ':')
29182 + strcpy(p, append);
29183 + AuDebugOn(strlen(fmt) >= len);
29186 +static void au_show_wbr_create(struct seq_file *m, int v,
29187 + struct au_sbinfo *sbinfo)
29191 + struct au_wbr_mfs *mfs;
29193 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29195 + seq_puts(m, ",create=");
29196 + pat = au_optstr_wbr_create(v);
29197 + mfs = &sbinfo->si_wbr_mfs;
29199 + case AuWbrCreate_TDP:
29200 + case AuWbrCreate_RR:
29201 + case AuWbrCreate_MFS:
29202 + case AuWbrCreate_PMFS:
29203 + seq_puts(m, pat);
29205 + case AuWbrCreate_MFSRR:
29206 + case AuWbrCreate_TDMFS:
29207 + case AuWbrCreate_PMFSRR:
29208 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29209 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29211 + case AuWbrCreate_MFSV:
29212 + case AuWbrCreate_PMFSV:
29213 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29214 + seq_printf(m, fmt,
29215 + jiffies_to_msecs(mfs->mfs_expire)
29218 + case AuWbrCreate_MFSRRV:
29219 + case AuWbrCreate_TDMFSV:
29220 + case AuWbrCreate_PMFSRRV:
29221 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29222 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29223 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29230 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29232 +#ifdef CONFIG_SYSFS
29236 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29237 + aufs_bindex_t bindex, brid;
29238 + struct qstr *name;
29240 + struct dentry *d, *h_root;
29242 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29245 + f = au_sbi(sb)->si_xib;
29249 + /* stop printing the default xino path on the first writable branch */
29251 + brid = au_xino_brid(sb);
29253 + bindex = au_br_index(sb, brid);
29254 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
29256 + d = f->f_path.dentry;
29257 + name = &d->d_name;
29258 + /* safe ->d_parent because the file is unlinked */
29259 + if (d->d_parent == h_root
29260 + && name->len == len
29261 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29264 + seq_puts(seq, ",xino=");
29265 + err = au_xino_path(seq, f);
29272 +/* seq_file will re-call me in case of too long string */
29273 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29276 + unsigned int mnt_flags, v;
29277 + struct super_block *sb;
29278 + struct au_sbinfo *sbinfo;
29280 +#define AuBool(name, str) do { \
29281 + v = au_opt_test(mnt_flags, name); \
29282 + if (v != au_opt_test(AuOpt_Def, name)) \
29283 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29286 +#define AuStr(name, str) do { \
29287 + v = mnt_flags & AuOptMask_##name; \
29288 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29289 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29292 +#define AuUInt(name, str, val) do { \
29293 + if (val != AUFS_##name##_DEF) \
29294 + seq_printf(m, "," #str "=%u", val); \
29297 + sb = dentry->d_sb;
29298 + if (sb->s_flags & SB_POSIXACL)
29299 + seq_puts(m, ",acl");
29301 + if (sb->s_flags & SB_I_VERSION)
29302 + seq_puts(m, ",i_version");
29305 + /* lock free root dinfo */
29306 + si_noflush_read_lock(sb);
29307 + sbinfo = au_sbi(sb);
29308 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29310 + mnt_flags = au_mntflags(sb);
29311 + if (au_opt_test(mnt_flags, XINO)) {
29312 + err = au_show_xino(m, sb);
29313 + if (unlikely(err))
29316 + seq_puts(m, ",noxino");
29318 + AuBool(TRUNC_XINO, trunc_xino);
29319 + AuStr(UDBA, udba);
29320 + AuBool(SHWH, shwh);
29321 + AuBool(PLINK, plink);
29322 + AuBool(DIO, dio);
29323 + AuBool(DIRPERM1, dirperm1);
29325 + v = sbinfo->si_wbr_create;
29326 + if (v != AuWbrCreate_Def)
29327 + au_show_wbr_create(m, v, sbinfo);
29329 + v = sbinfo->si_wbr_copyup;
29330 + if (v != AuWbrCopyup_Def)
29331 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29333 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29334 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29335 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29337 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29339 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29340 + AuUInt(RDCACHE, rdcache, v);
29342 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29343 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29345 + au_fhsm_show(m, sbinfo);
29347 + AuBool(DIRREN, dirren);
29348 + AuBool(SUM, sum);
29349 + /* AuBool(SUM_W, wsum); */
29350 + AuBool(WARN_PERM, warn_perm);
29351 + AuBool(VERBOSE, verbose);
29354 + /* be sure to print "br:" last */
29355 + if (!sysaufs_brs) {
29356 + seq_puts(m, ",br:");
29357 + au_show_brs(m, sb);
29359 + si_read_unlock(sb);
29367 +/* ---------------------------------------------------------------------- */
29369 +/* sum mode which returns the summation for statfs(2) */
29371 +static u64 au_add_till_max(u64 a, u64 b)
29379 + return ULLONG_MAX;
29382 +static u64 au_mul_till_max(u64 a, long mul)
29390 + return ULLONG_MAX;
29393 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29396 + long bsize, factor;
29397 + u64 blocks, bfree, bavail, files, ffree;
29398 + aufs_bindex_t bbot, bindex, i;
29399 + unsigned char shared;
29400 + struct path h_path;
29401 + struct super_block *h_sb;
29404 + bsize = LONG_MAX;
29410 + bbot = au_sbbot(sb);
29411 + for (bindex = 0; bindex <= bbot; bindex++) {
29412 + h_path.mnt = au_sbr_mnt(sb, bindex);
29413 + h_sb = h_path.mnt->mnt_sb;
29415 + for (i = 0; !shared && i < bindex; i++)
29416 + shared = (au_sbr_sb(sb, i) == h_sb);
29420 + /* sb->s_root for NFS is unreliable */
29421 + h_path.dentry = h_path.mnt->mnt_root;
29422 + err = vfs_statfs(&h_path, buf);
29423 + if (unlikely(err))
29426 + if (bsize > buf->f_bsize) {
29428 + * we will reduce bsize, so we have to expand blocks
29429 + * etc. to match them again
29431 + factor = (bsize / buf->f_bsize);
29432 + blocks = au_mul_till_max(blocks, factor);
29433 + bfree = au_mul_till_max(bfree, factor);
29434 + bavail = au_mul_till_max(bavail, factor);
29435 + bsize = buf->f_bsize;
29438 + factor = (buf->f_bsize / bsize);
29439 + blocks = au_add_till_max(blocks,
29440 + au_mul_till_max(buf->f_blocks, factor));
29441 + bfree = au_add_till_max(bfree,
29442 + au_mul_till_max(buf->f_bfree, factor));
29443 + bavail = au_add_till_max(bavail,
29444 + au_mul_till_max(buf->f_bavail, factor));
29445 + files = au_add_till_max(files, buf->f_files);
29446 + ffree = au_add_till_max(ffree, buf->f_ffree);
29449 + buf->f_bsize = bsize;
29450 + buf->f_blocks = blocks;
29451 + buf->f_bfree = bfree;
29452 + buf->f_bavail = bavail;
29453 + buf->f_files = files;
29454 + buf->f_ffree = ffree;
29455 + buf->f_frsize = 0;
29461 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29464 + struct path h_path;
29465 + struct super_block *sb;
29467 + /* lock free root dinfo */
29468 + sb = dentry->d_sb;
29469 + si_noflush_read_lock(sb);
29470 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29471 + /* sb->s_root for NFS is unreliable */
29472 + h_path.mnt = au_sbr_mnt(sb, 0);
29473 + h_path.dentry = h_path.mnt->mnt_root;
29474 + err = vfs_statfs(&h_path, buf);
29476 + err = au_statfs_sum(sb, buf);
29477 + si_read_unlock(sb);
29480 + buf->f_type = AUFS_SUPER_MAGIC;
29481 + buf->f_namelen = AUFS_MAX_NAMELEN;
29482 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29484 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29489 +/* ---------------------------------------------------------------------- */
29491 +static int aufs_sync_fs(struct super_block *sb, int wait)
29494 + aufs_bindex_t bbot, bindex;
29495 + struct au_branch *br;
29496 + struct super_block *h_sb;
29499 + si_noflush_read_lock(sb);
29500 + bbot = au_sbbot(sb);
29501 + for (bindex = 0; bindex <= bbot; bindex++) {
29502 + br = au_sbr(sb, bindex);
29503 + if (!au_br_writable(br->br_perm))
29506 + h_sb = au_sbr_sb(sb, bindex);
29507 + e = vfsub_sync_filesystem(h_sb, wait);
29508 + if (unlikely(e && !err))
29510 + /* go on even if an error happens */
29512 + si_read_unlock(sb);
29517 +/* ---------------------------------------------------------------------- */
29519 +/* final actions when unmounting a file system */
29520 +static void aufs_put_super(struct super_block *sb)
29522 + struct au_sbinfo *sbinfo;
29524 + sbinfo = au_sbi(sb);
29528 + dbgaufs_si_fin(sbinfo);
29529 + kobject_put(&sbinfo->si_kobj);
29532 +/* ---------------------------------------------------------------------- */
29534 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29535 + struct super_block *sb, void *arg)
29538 + unsigned long long n, sz;
29545 + if (*hint > ULLONG_MAX / sizeof(array)) {
29546 + array = ERR_PTR(-EMFILE);
29547 + pr_err("hint %llu\n", *hint);
29551 + sz = sizeof(array) * *hint;
29552 + array = kzalloc(sz, GFP_NOFS);
29553 + if (unlikely(!array))
29554 + array = vzalloc(sz);
29555 + if (unlikely(!array)) {
29556 + array = ERR_PTR(-ENOMEM);
29560 + n = cb(sb, array, *hint, arg);
29561 + AuDebugOn(n > *hint);
29568 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29569 + unsigned long long max __maybe_unused,
29572 + unsigned long long n;
29573 + struct inode **p, *inode;
29574 + struct list_head *head;
29579 + spin_lock(&sb->s_inode_list_lock);
29580 + list_for_each_entry(inode, head, i_sb_list) {
29581 + if (!au_is_bad_inode(inode)
29582 + && au_ii(inode)->ii_btop >= 0) {
29583 + spin_lock(&inode->i_lock);
29584 + if (atomic_read(&inode->i_count)) {
29588 + AuDebugOn(n > max);
29590 + spin_unlock(&inode->i_lock);
29593 + spin_unlock(&sb->s_inode_list_lock);
29598 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29600 + *max = au_ninodes(sb);
29601 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29604 +void au_iarray_free(struct inode **a, unsigned long long max)
29606 + unsigned long long ull;
29608 + for (ull = 0; ull < max; ull++)
29613 +/* ---------------------------------------------------------------------- */
29616 + * refresh dentry and inode at remount time.
29618 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29619 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29620 + struct dentry *parent)
29624 + di_write_lock_child(dentry);
29625 + di_read_lock_parent(parent, AuLock_IR);
29626 + err = au_refresh_dentry(dentry, parent);
29627 + if (!err && dir_flags)
29628 + au_hn_reset(d_inode(dentry), dir_flags);
29629 + di_read_unlock(parent, AuLock_IR);
29630 + di_write_unlock(dentry);
29635 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29636 + struct au_sbinfo *sbinfo,
29637 + const unsigned int dir_flags, unsigned int do_idop)
29640 + struct dentry *parent;
29643 + parent = dget_parent(dentry);
29644 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29645 + if (d_really_is_positive(dentry)) {
29646 + if (!d_is_dir(dentry))
29647 + err = au_do_refresh(dentry, /*dir_flags*/0,
29650 + err = au_do_refresh(dentry, dir_flags, parent);
29651 + if (unlikely(err))
29652 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29655 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29656 + AuDbgDentry(dentry);
29662 + au_refresh_dop(dentry, /*force_reval*/0);
29664 + au_refresh_dop(dentry, /*force_reval*/1);
29670 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29672 + int err, i, j, ndentry, e;
29673 + unsigned int sigen;
29674 + struct au_dcsub_pages dpages;
29675 + struct au_dpage *dpage;
29676 + struct dentry **dentries, *d;
29677 + struct au_sbinfo *sbinfo;
29678 + struct dentry *root = sb->s_root;
29679 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29682 + au_refresh_dop(root, /*force_reval*/0);
29684 + err = au_dpages_init(&dpages, GFP_NOFS);
29685 + if (unlikely(err))
29687 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29688 + if (unlikely(err))
29691 + sigen = au_sigen(sb);
29692 + sbinfo = au_sbi(sb);
29693 + for (i = 0; i < dpages.ndpage; i++) {
29694 + dpage = dpages.dpages + i;
29695 + dentries = dpage->dentries;
29696 + ndentry = dpage->ndentry;
29697 + for (j = 0; j < ndentry; j++) {
29699 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29701 + if (unlikely(e && !err))
29703 + /* go on even err */
29708 + au_dpages_free(&dpages);
29713 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29716 + unsigned int sigen;
29717 + unsigned long long max, ull;
29718 + struct inode *inode, **array;
29720 + array = au_iarray_alloc(sb, &max);
29721 + err = PTR_ERR(array);
29722 + if (IS_ERR(array))
29726 + sigen = au_sigen(sb);
29727 + for (ull = 0; ull < max; ull++) {
29728 + inode = array[ull];
29729 + if (unlikely(!inode))
29733 + ii_write_lock_child(inode);
29734 + if (au_iigen(inode, NULL) != sigen) {
29735 + e = au_refresh_hinode_self(inode);
29736 + if (unlikely(e)) {
29737 + au_refresh_iop(inode, /*force_getattr*/1);
29738 + pr_err("error %d, i%lu\n", e, inode->i_ino);
29741 + /* go on even if err */
29744 + if (!e && do_idop)
29745 + au_refresh_iop(inode, /*force_getattr*/0);
29746 + ii_write_unlock(inode);
29749 + au_iarray_free(array, max);
29755 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
29758 + unsigned int udba;
29759 + aufs_bindex_t bindex, bbot;
29760 + struct dentry *root;
29761 + struct inode *inode;
29762 + struct au_branch *br;
29763 + struct au_sbinfo *sbi;
29765 + au_sigen_inc(sb);
29766 + sbi = au_sbi(sb);
29767 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
29769 + root = sb->s_root;
29770 + DiMustNoWaiters(root);
29771 + inode = d_inode(root);
29772 + IiMustNoWaiters(inode);
29774 + udba = au_opt_udba(sb);
29775 + bbot = au_sbbot(sb);
29776 + for (bindex = 0; bindex <= bbot; bindex++) {
29777 + br = au_sbr(sb, bindex);
29778 + err = au_hnotify_reset_br(udba, br, br->br_perm);
29779 + if (unlikely(err))
29780 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
29782 + /* go on even if err */
29784 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
29787 + if (au_ftest_si(sbi, NO_DREVAL)) {
29788 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
29789 + sb->s_d_op = &aufs_dop_noreval;
29790 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
29791 + sbi->si_iop_array = aufs_iop_nogetattr;
29793 + AuDebugOn(sb->s_d_op == &aufs_dop);
29794 + sb->s_d_op = &aufs_dop;
29795 + AuDebugOn(sbi->si_iop_array == aufs_iop);
29796 + sbi->si_iop_array = aufs_iop;
29798 + pr_info("reset to %pf and %pf\n",
29799 + sb->s_d_op, sbi->si_iop_array);
29802 + di_write_unlock(root);
29803 + err = au_refresh_d(sb, do_idop);
29804 + e = au_refresh_i(sb, do_idop);
29805 + if (unlikely(e && !err))
29807 + /* aufs_write_lock() calls ..._child() */
29808 + di_write_lock_child(root);
29810 + au_cpup_attr_all(inode, /*force*/1);
29812 + if (unlikely(err))
29813 + AuIOErr("refresh failed, ignored, %d\n", err);
29816 +/* stop extra interpretation of errno in mount(8), and strange error messages */
29817 +static int cvt_err(int err)
29831 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
29834 + unsigned int mntflags;
29835 + struct au_opts opts = {
29838 + struct dentry *root;
29839 + struct inode *inode;
29840 + struct au_sbinfo *sbinfo;
29843 + root = sb->s_root;
29844 + if (!data || !*data) {
29845 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29847 + di_write_lock_child(root);
29848 + err = au_opts_verify(sb, *flags, /*pending*/0);
29849 + aufs_write_unlock(root);
29855 + opts.opt = (void *)__get_free_page(GFP_NOFS);
29856 + if (unlikely(!opts.opt))
29858 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
29859 + opts.flags = AuOpts_REMOUNT;
29860 + opts.sb_flags = *flags;
29862 + /* parse it before aufs lock */
29863 + err = au_opts_parse(sb, data, &opts);
29864 + if (unlikely(err))
29867 + sbinfo = au_sbi(sb);
29868 + inode = d_inode(root);
29869 + inode_lock(inode);
29870 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29871 + if (unlikely(err))
29873 + di_write_lock_child(root);
29875 + /* au_opts_remount() may return an error */
29876 + err = au_opts_remount(sb, &opts);
29877 + au_opts_free(&opts);
29879 + if (au_ftest_opts(opts.flags, REFRESH))
29880 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
29882 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
29883 + mntflags = au_mntflags(sb);
29884 + do_dx = !!au_opt_test(mntflags, DIO);
29885 + au_dy_arefresh(do_dx);
29888 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
29889 + aufs_write_unlock(root);
29892 + inode_unlock(inode);
29894 + free_page((unsigned long)opts.opt);
29896 + err = cvt_err(err);
29901 +static const struct super_operations aufs_sop = {
29902 + .alloc_inode = aufs_alloc_inode,
29903 + .destroy_inode = aufs_destroy_inode,
29904 + /* always deleting, no clearing */
29905 + .drop_inode = generic_delete_inode,
29906 + .show_options = aufs_show_options,
29907 + .statfs = aufs_statfs,
29908 + .put_super = aufs_put_super,
29909 + .sync_fs = aufs_sync_fs,
29910 + .remount_fs = aufs_remount_fs
29913 +/* ---------------------------------------------------------------------- */
29915 +static int alloc_root(struct super_block *sb)
29918 + struct inode *inode;
29919 + struct dentry *root;
29922 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
29923 + err = PTR_ERR(inode);
29924 + if (IS_ERR(inode))
29927 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
29928 + inode->i_fop = &aufs_dir_fop;
29929 + inode->i_mode = S_IFDIR;
29930 + set_nlink(inode, 2);
29931 + unlock_new_inode(inode);
29933 + root = d_make_root(inode);
29934 + if (unlikely(!root))
29936 + err = PTR_ERR(root);
29937 + if (IS_ERR(root))
29940 + err = au_di_init(root);
29942 + sb->s_root = root;
29943 + return 0; /* success */
29951 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
29952 + int silent __maybe_unused)
29955 + struct au_opts opts = {
29958 + struct au_sbinfo *sbinfo;
29959 + struct dentry *root;
29960 + struct inode *inode;
29961 + char *arg = raw_data;
29963 + if (unlikely(!arg || !*arg)) {
29965 + pr_err("no arg\n");
29970 + opts.opt = (void *)__get_free_page(GFP_NOFS);
29971 + if (unlikely(!opts.opt))
29973 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
29974 + opts.sb_flags = sb->s_flags;
29976 + err = au_si_alloc(sb);
29977 + if (unlikely(err))
29979 + sbinfo = au_sbi(sb);
29981 + /* all timestamps always follow the ones on the branch */
29982 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
29983 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
29984 + sb->s_op = &aufs_sop;
29985 + sb->s_d_op = &aufs_dop;
29986 + sb->s_magic = AUFS_SUPER_MAGIC;
29987 + sb->s_maxbytes = 0;
29988 + sb->s_stack_depth = 1;
29989 + au_export_init(sb);
29990 + au_xattr_init(sb);
29992 + err = alloc_root(sb);
29993 + if (unlikely(err)) {
29994 + si_write_unlock(sb);
29997 + root = sb->s_root;
29998 + inode = d_inode(root);
30001 + * actually we can parse options regardless aufs lock here.
30002 + * but at remount time, parsing must be done before aufs lock.
30003 + * so we follow the same rule.
30005 + ii_write_lock_parent(inode);
30006 + aufs_write_unlock(root);
30007 + err = au_opts_parse(sb, arg, &opts);
30008 + if (unlikely(err))
30011 + /* lock vfs_inode first, then aufs. */
30012 + inode_lock(inode);
30013 + aufs_write_lock(root);
30014 + err = au_opts_mount(sb, &opts);
30015 + au_opts_free(&opts);
30016 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30017 + sb->s_d_op = &aufs_dop_noreval;
30018 + pr_info("%pf\n", sb->s_d_op);
30019 + au_refresh_dop(root, /*force_reval*/0);
30020 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30021 + au_refresh_iop(inode, /*force_getattr*/0);
30023 + aufs_write_unlock(root);
30024 + inode_unlock(inode);
30026 + goto out_opts; /* success */
30030 + sb->s_root = NULL;
30032 + dbgaufs_si_fin(sbinfo);
30033 + kobject_put(&sbinfo->si_kobj);
30034 + sb->s_fs_info = NULL;
30036 + free_page((unsigned long)opts.opt);
30039 + err = cvt_err(err);
30044 +/* ---------------------------------------------------------------------- */
30046 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30047 + const char *dev_name __maybe_unused,
30050 + struct dentry *root;
30051 + struct super_block *sb;
30053 + /* all timestamps always follow the ones on the branch */
30054 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30055 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30056 + if (IS_ERR(root))
30060 + si_write_lock(sb, !AuLock_FLUSH);
30061 + sysaufs_brs_add(sb, 0);
30062 + si_write_unlock(sb);
30063 + au_sbilist_add(sb);
30069 +static void aufs_kill_sb(struct super_block *sb)
30071 + struct au_sbinfo *sbinfo;
30073 + sbinfo = au_sbi(sb);
30075 + au_sbilist_del(sb);
30076 + aufs_write_lock(sb->s_root);
30078 + if (sbinfo->si_wbr_create_ops->fin)
30079 + sbinfo->si_wbr_create_ops->fin(sb);
30080 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30081 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30082 + au_remount_refresh(sb, /*do_idop*/0);
30084 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30085 + au_plink_put(sb, /*verbose*/1);
30087 + au_dr_opt_flush(sb);
30088 + sbinfo->si_sb = NULL;
30089 + aufs_write_unlock(sb->s_root);
30090 + au_nwt_flush(&sbinfo->si_nowait);
30092 + kill_anon_super(sb);
30095 +struct file_system_type aufs_fs_type = {
30096 + .name = AUFS_FSTYPE,
30097 + /* a race between rename and others */
30098 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30099 + .mount = aufs_mount,
30100 + .kill_sb = aufs_kill_sb,
30101 + /* no need to __module_get() and module_put(). */
30102 + .owner = THIS_MODULE,
30104 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30105 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30106 +++ linux/fs/aufs/super.h 2018-06-04 09:08:09.188079511 +0200
30109 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30111 + * This program, aufs is free software; you can redistribute it and/or modify
30112 + * it under the terms of the GNU General Public License as published by
30113 + * the Free Software Foundation; either version 2 of the License, or
30114 + * (at your option) any later version.
30116 + * This program is distributed in the hope that it will be useful,
30117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30119 + * GNU General Public License for more details.
30121 + * You should have received a copy of the GNU General Public License
30122 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30126 + * super_block operations
30129 +#ifndef __AUFS_SUPER_H__
30130 +#define __AUFS_SUPER_H__
30134 +#include <linux/fs.h>
30135 +#include <linux/kobject.h>
30137 +#include "rwsem.h"
30140 +/* policies to select one among multiple writable branches */
30141 +struct au_wbr_copyup_operations {
30142 + int (*copyup)(struct dentry *dentry);
30145 +#define AuWbr_DIR 1 /* target is a dir */
30146 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30148 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30149 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30150 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30152 +struct au_wbr_create_operations {
30153 + int (*create)(struct dentry *dentry, unsigned int flags);
30154 + int (*init)(struct super_block *sb);
30155 + int (*fin)(struct super_block *sb);
30158 +struct au_wbr_mfs {
30159 + struct mutex mfs_lock; /* protect this structure */
30160 + unsigned long mfs_jiffy;
30161 + unsigned long mfs_expire;
30162 + aufs_bindex_t mfs_bindex;
30164 + unsigned long long mfsrr_bytes;
30165 + unsigned long long mfsrr_watermark;
30168 +#define AuPlink_NHASH 100
30169 +static inline int au_plink_hash(ino_t ino)
30171 + return ino % AuPlink_NHASH;
30174 +/* File-based Hierarchical Storage Management */
30176 +#ifdef CONFIG_AUFS_FHSM
30177 + /* allow only one process who can receive the notification */
30178 + spinlock_t fhsm_spin;
30180 + wait_queue_head_t fhsm_wqh;
30181 + atomic_t fhsm_readable;
30183 + /* these are protected by si_rwsem */
30184 + unsigned long fhsm_expire;
30185 + aufs_bindex_t fhsm_bottom;
30190 +struct au_sbinfo {
30191 + /* nowait tasks in the system-wide workqueue */
30192 + struct au_nowait_tasks si_nowait;
30195 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
30196 + * rwsem for au_sbinfo is necessary.
30198 + struct au_rwsem si_rwsem;
30201 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30204 + struct percpu_counter si_ninodes, si_nfiles;
30206 + /* branch management */
30207 + unsigned int si_generation;
30209 + /* see AuSi_ flags */
30210 + unsigned char au_si_status;
30212 + aufs_bindex_t si_bbot;
30214 + /* dirty trick to keep br_id plus */
30215 + unsigned int si_last_br_id :
30216 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30217 + struct au_branch **si_branch;
30219 + /* policy to select a writable branch */
30220 + unsigned char si_wbr_copyup;
30221 + unsigned char si_wbr_create;
30222 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30223 + struct au_wbr_create_operations *si_wbr_create_ops;
30225 + /* round robin */
30226 + atomic_t si_wbr_rr_next;
30228 + /* most free space */
30229 + struct au_wbr_mfs si_wbr_mfs;
30231 + /* File-based Hierarchical Storage Management */
30232 + struct au_fhsm si_fhsm;
30234 + /* mount flags */
30235 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30236 + unsigned int si_mntflags;
30238 + /* external inode number (bitmap and translation table) */
30239 + vfs_readf_t si_xread;
30240 + vfs_writef_t si_xwrite;
30241 + struct file *si_xib;
30242 + struct mutex si_xib_mtx; /* protect xib members */
30243 + unsigned long *si_xib_buf;
30244 + unsigned long si_xib_last_pindex;
30245 + int si_xib_next_bit;
30246 + aufs_bindex_t si_xino_brid;
30247 + unsigned long si_xino_jiffy;
30248 + unsigned long si_xino_expire;
30249 + /* reserved for future use */
30250 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30252 +#ifdef CONFIG_AUFS_EXPORT
30253 + /* i_generation */
30254 + struct file *si_xigen;
30255 + atomic_t si_xigen_next;
30258 + /* dirty trick to suppoer atomic_open */
30259 + struct hlist_bl_head si_aopen;
30261 + /* vdir parameters */
30262 + unsigned long si_rdcache; /* max cache time in jiffies */
30263 + unsigned int si_rdblk; /* deblk size */
30264 + unsigned int si_rdhash; /* hash size */
30267 + * If the number of whiteouts are larger than si_dirwh, leave all of
30268 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30269 + * future fsck.aufs or kernel thread will remove them later.
30270 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30272 + unsigned int si_dirwh;
30274 + /* pseudo_link list */
30275 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30276 + wait_queue_head_t si_plink_wq;
30277 + spinlock_t si_plink_maint_lock;
30278 + pid_t si_plink_maint_pid;
30281 + struct hlist_bl_head si_files;
30283 + /* with/without getattr, brother of sb->s_d_op */
30284 + struct inode_operations *si_iop_array;
30287 + * sysfs and lifetime management.
30288 + * this is not a small structure and it may be a waste of memory in case
30289 + * of sysfs is disabled, particulary when many aufs-es are mounted.
30290 + * but using sysfs is majority.
30292 + struct kobject si_kobj;
30293 +#ifdef CONFIG_DEBUG_FS
30294 + struct dentry *si_dbgaufs;
30295 + struct dentry *si_dbgaufs_plink;
30296 + struct dentry *si_dbgaufs_xib;
30297 +#ifdef CONFIG_AUFS_EXPORT
30298 + struct dentry *si_dbgaufs_xigen;
30302 +#ifdef CONFIG_AUFS_SBILIST
30303 + struct hlist_bl_node si_list;
30306 + /* dirty, necessary for unmounting, sysfs and sysrq */
30307 + struct super_block *si_sb;
30310 +/* sbinfo status flags */
30312 + * set true when refresh_dirs() failed at remount time.
30313 + * then try refreshing dirs at access time again.
30314 + * if it is false, refreshing dirs at access time is unnecesary
30316 +#define AuSi_FAILED_REFRESH_DIR 1
30317 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30318 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30320 +#ifndef CONFIG_AUFS_FHSM
30322 +#define AuSi_FHSM 0
30325 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30326 + unsigned int flag)
30328 + AuRwMustAnyLock(&sbi->si_rwsem);
30329 + return sbi->au_si_status & flag;
30331 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30332 +#define au_fset_si(sbinfo, name) do { \
30333 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30334 + (sbinfo)->au_si_status |= AuSi_##name; \
30336 +#define au_fclr_si(sbinfo, name) do { \
30337 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30338 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30341 +/* ---------------------------------------------------------------------- */
30343 +/* policy to select one among writable branches */
30344 +#define AuWbrCopyup(sbinfo, ...) \
30345 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30346 +#define AuWbrCreate(sbinfo, ...) \
30347 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30349 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30350 +#define AuLock_DW 1 /* write-lock dentry */
30351 +#define AuLock_IR (1 << 1) /* read-lock inode */
30352 +#define AuLock_IW (1 << 2) /* write-lock inode */
30353 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30354 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30355 + /* except RENAME_EXCHANGE */
30356 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30357 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30358 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30359 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30360 +#define au_fset_lock(flags, name) \
30361 + do { (flags) |= AuLock_##name; } while (0)
30362 +#define au_fclr_lock(flags, name) \
30363 + do { (flags) &= ~AuLock_##name; } while (0)
30365 +/* ---------------------------------------------------------------------- */
30368 +extern struct file_system_type aufs_fs_type;
30369 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30370 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30371 + unsigned long long max, void *arg);
30372 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30373 + struct super_block *sb, void *arg);
30374 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30375 +void au_iarray_free(struct inode **a, unsigned long long max);
30378 +void au_si_free(struct kobject *kobj);
30379 +int au_si_alloc(struct super_block *sb);
30380 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30382 +unsigned int au_sigen_inc(struct super_block *sb);
30383 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30385 +int si_read_lock(struct super_block *sb, int flags);
30386 +int si_write_lock(struct super_block *sb, int flags);
30387 +int aufs_read_lock(struct dentry *dentry, int flags);
30388 +void aufs_read_unlock(struct dentry *dentry, int flags);
30389 +void aufs_write_lock(struct dentry *dentry);
30390 +void aufs_write_unlock(struct dentry *dentry);
30391 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30392 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30394 +/* wbr_policy.c */
30395 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30396 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30397 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30398 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30399 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30402 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30404 +#ifdef CONFIG_AUFS_FHSM
30407 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30411 + spin_lock(&fhsm->fhsm_spin);
30412 + pid = fhsm->fhsm_pid;
30413 + spin_unlock(&fhsm->fhsm_spin);
30418 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30419 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30420 +int au_fhsm_fd(struct super_block *sb, int oflags);
30421 +int au_fhsm_br_alloc(struct au_branch *br);
30422 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30423 +void au_fhsm_fin(struct super_block *sb);
30424 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30425 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30426 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30428 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30430 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30431 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30432 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30433 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30434 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30435 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30436 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30437 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30438 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30441 +/* ---------------------------------------------------------------------- */
30443 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30445 + return sb->s_fs_info;
30448 +/* ---------------------------------------------------------------------- */
30450 +#ifdef CONFIG_AUFS_EXPORT
30451 +int au_test_nfsd(void);
30452 +void au_export_init(struct super_block *sb);
30453 +void au_xigen_inc(struct inode *inode);
30454 +int au_xigen_new(struct inode *inode);
30455 +int au_xigen_set(struct super_block *sb, struct file *base);
30456 +void au_xigen_clr(struct super_block *sb);
30458 +static inline int au_busy_or_stale(void)
30460 + if (!au_test_nfsd())
30465 +AuStubInt0(au_test_nfsd, void)
30466 +AuStubVoid(au_export_init, struct super_block *sb)
30467 +AuStubVoid(au_xigen_inc, struct inode *inode)
30468 +AuStubInt0(au_xigen_new, struct inode *inode)
30469 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
30470 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30471 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30472 +#endif /* CONFIG_AUFS_EXPORT */
30474 +/* ---------------------------------------------------------------------- */
30476 +#ifdef CONFIG_AUFS_SBILIST
30478 +extern struct hlist_bl_head au_sbilist;
30480 +static inline void au_sbilist_init(void)
30482 + INIT_HLIST_BL_HEAD(&au_sbilist);
30485 +static inline void au_sbilist_add(struct super_block *sb)
30487 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30490 +static inline void au_sbilist_del(struct super_block *sb)
30492 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30495 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30496 +static inline void au_sbilist_lock(void)
30498 + hlist_bl_lock(&au_sbilist);
30501 +static inline void au_sbilist_unlock(void)
30503 + hlist_bl_unlock(&au_sbilist);
30505 +#define AuGFP_SBILIST GFP_ATOMIC
30507 +AuStubVoid(au_sbilist_lock, void)
30508 +AuStubVoid(au_sbilist_unlock, void)
30509 +#define AuGFP_SBILIST GFP_NOFS
30510 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30512 +AuStubVoid(au_sbilist_init, void)
30513 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30514 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30515 +AuStubVoid(au_sbilist_lock, void)
30516 +AuStubVoid(au_sbilist_unlock, void)
30517 +#define AuGFP_SBILIST GFP_NOFS
30520 +/* ---------------------------------------------------------------------- */
30522 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30525 + * This function is a dynamic '__init' function actually,
30526 + * so the tiny check for si_rwsem is unnecessary.
30528 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30529 +#ifdef CONFIG_DEBUG_FS
30530 + sbinfo->si_dbgaufs = NULL;
30531 + sbinfo->si_dbgaufs_plink = NULL;
30532 + sbinfo->si_dbgaufs_xib = NULL;
30533 +#ifdef CONFIG_AUFS_EXPORT
30534 + sbinfo->si_dbgaufs_xigen = NULL;
30539 +/* ---------------------------------------------------------------------- */
30541 +/* current->atomic_flags */
30542 +/* this value should never corrupt the ones defined in linux/sched.h */
30543 +#define PFA_AUFS 7
30545 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30546 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30547 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30549 +static inline int si_pid_test(struct super_block *sb)
30551 + return !!task_test_aufs(current);
30554 +static inline void si_pid_clr(struct super_block *sb)
30556 + AuDebugOn(!task_test_aufs(current));
30557 + task_clear_aufs(current);
30560 +static inline void si_pid_set(struct super_block *sb)
30562 + AuDebugOn(task_test_aufs(current));
30563 + task_set_aufs(current);
30566 +/* ---------------------------------------------------------------------- */
30568 +/* lock superblock. mainly for entry point functions */
30569 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30570 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30571 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30572 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30574 +#define __si_read_trylock_nested(sb) \
30575 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30576 +#define __si_write_trylock_nested(sb) \
30577 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30580 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30581 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30582 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30584 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30585 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30586 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30588 +static inline void si_noflush_read_lock(struct super_block *sb)
30590 + __si_read_lock(sb);
30594 +static inline int si_noflush_read_trylock(struct super_block *sb)
30598 + locked = __si_read_trylock(sb);
30604 +static inline void si_noflush_write_lock(struct super_block *sb)
30606 + __si_write_lock(sb);
30610 +static inline int si_noflush_write_trylock(struct super_block *sb)
30614 + locked = __si_write_trylock(sb);
30620 +#if 0 /* reserved */
30621 +static inline int si_read_trylock(struct super_block *sb, int flags)
30623 + if (au_ftest_lock(flags, FLUSH))
30624 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30625 + return si_noflush_read_trylock(sb);
30629 +static inline void si_read_unlock(struct super_block *sb)
30632 + __si_read_unlock(sb);
30635 +#if 0 /* reserved */
30636 +static inline int si_write_trylock(struct super_block *sb, int flags)
30638 + if (au_ftest_lock(flags, FLUSH))
30639 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30640 + return si_noflush_write_trylock(sb);
30644 +static inline void si_write_unlock(struct super_block *sb)
30647 + __si_write_unlock(sb);
30650 +#if 0 /* reserved */
30651 +static inline void si_downgrade_lock(struct super_block *sb)
30653 + __si_downgrade_lock(sb);
30657 +/* ---------------------------------------------------------------------- */
30659 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30661 + SiMustAnyLock(sb);
30662 + return au_sbi(sb)->si_bbot;
30665 +static inline unsigned int au_mntflags(struct super_block *sb)
30667 + SiMustAnyLock(sb);
30668 + return au_sbi(sb)->si_mntflags;
30671 +static inline unsigned int au_sigen(struct super_block *sb)
30673 + SiMustAnyLock(sb);
30674 + return au_sbi(sb)->si_generation;
30677 +static inline unsigned long long au_ninodes(struct super_block *sb)
30679 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
30685 +static inline void au_ninodes_inc(struct super_block *sb)
30687 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
30690 +static inline void au_ninodes_dec(struct super_block *sb)
30692 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
30695 +static inline unsigned long long au_nfiles(struct super_block *sb)
30697 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
30703 +static inline void au_nfiles_inc(struct super_block *sb)
30705 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
30708 +static inline void au_nfiles_dec(struct super_block *sb)
30710 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
30713 +static inline struct au_branch *au_sbr(struct super_block *sb,
30714 + aufs_bindex_t bindex)
30716 + SiMustAnyLock(sb);
30717 + return au_sbi(sb)->si_branch[0 + bindex];
30720 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
30722 + SiMustWriteLock(sb);
30723 + au_sbi(sb)->si_xino_brid = brid;
30726 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
30728 + SiMustAnyLock(sb);
30729 + return au_sbi(sb)->si_xino_brid;
30732 +#endif /* __KERNEL__ */
30733 +#endif /* __AUFS_SUPER_H__ */
30734 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30735 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30736 +++ linux/fs/aufs/sysaufs.c 2018-04-15 08:49:13.404484168 +0200
30739 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30741 + * This program, aufs is free software; you can redistribute it and/or modify
30742 + * it under the terms of the GNU General Public License as published by
30743 + * the Free Software Foundation; either version 2 of the License, or
30744 + * (at your option) any later version.
30746 + * This program is distributed in the hope that it will be useful,
30747 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30748 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30749 + * GNU General Public License for more details.
30751 + * You should have received a copy of the GNU General Public License
30752 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30756 + * sysfs interface and lifetime management
30757 + * they are necessary regardless sysfs is disabled.
30760 +#include <linux/random.h>
30763 +unsigned long sysaufs_si_mask;
30764 +struct kset *sysaufs_kset;
30766 +#define AuSiAttr(_name) { \
30767 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30768 + .show = sysaufs_si_##_name, \
30771 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30772 +struct attribute *sysaufs_si_attrs[] = {
30773 + &sysaufs_si_attr_xi_path.attr,
30777 +static const struct sysfs_ops au_sbi_ops = {
30778 + .show = sysaufs_si_show
30781 +static struct kobj_type au_sbi_ktype = {
30782 + .release = au_si_free,
30783 + .sysfs_ops = &au_sbi_ops,
30784 + .default_attrs = sysaufs_si_attrs
30787 +/* ---------------------------------------------------------------------- */
30789 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
30793 + sbinfo->si_kobj.kset = sysaufs_kset;
30794 + /* cf. sysaufs_name() */
30795 + err = kobject_init_and_add
30796 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
30797 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
30799 + dbgaufs_si_null(sbinfo);
30801 + err = dbgaufs_si_init(sbinfo);
30802 + if (unlikely(err))
30803 + kobject_put(&sbinfo->si_kobj);
30808 +void sysaufs_fin(void)
30811 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30812 + kset_unregister(sysaufs_kset);
30815 +int __init sysaufs_init(void)
30820 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
30821 + } while (!sysaufs_si_mask);
30824 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
30825 + if (unlikely(!sysaufs_kset))
30827 + err = PTR_ERR(sysaufs_kset);
30828 + if (IS_ERR(sysaufs_kset))
30830 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30831 + if (unlikely(err)) {
30832 + kset_unregister(sysaufs_kset);
30836 + err = dbgaufs_init();
30837 + if (unlikely(err))
30842 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
30843 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
30844 +++ linux/fs/aufs/sysaufs.h 2018-04-15 08:49:13.404484168 +0200
30847 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30849 + * This program, aufs is free software; you can redistribute it and/or modify
30850 + * it under the terms of the GNU General Public License as published by
30851 + * the Free Software Foundation; either version 2 of the License, or
30852 + * (at your option) any later version.
30854 + * This program is distributed in the hope that it will be useful,
30855 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30856 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30857 + * GNU General Public License for more details.
30859 + * You should have received a copy of the GNU General Public License
30860 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30864 + * sysfs interface and mount lifetime management
30867 +#ifndef __SYSAUFS_H__
30868 +#define __SYSAUFS_H__
30872 +#include <linux/sysfs.h>
30873 +#include "module.h"
30875 +struct super_block;
30878 +struct sysaufs_si_attr {
30879 + struct attribute attr;
30880 + int (*show)(struct seq_file *seq, struct super_block *sb);
30883 +/* ---------------------------------------------------------------------- */
30886 +extern unsigned long sysaufs_si_mask;
30887 +extern struct kset *sysaufs_kset;
30888 +extern struct attribute *sysaufs_si_attrs[];
30889 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
30890 +int __init sysaufs_init(void);
30891 +void sysaufs_fin(void);
30893 +/* ---------------------------------------------------------------------- */
30895 +/* some people doesn't like to show a pointer in kernel */
30896 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
30898 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
30901 +#define SysaufsSiNamePrefix "si_"
30902 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
30903 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
30905 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
30906 + sysaufs_si_id(sbinfo));
30910 +#ifdef CONFIG_SYSFS
30912 +extern struct attribute_group *sysaufs_attr_group;
30914 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
30915 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
30917 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
30918 +#ifdef CONFIG_COMPAT
30919 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
30922 +void sysaufs_br_init(struct au_branch *br);
30923 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
30924 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
30926 +#define sysaufs_brs_init() do {} while (0)
30929 +#define sysaufs_attr_group NULL
30931 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
30932 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
30933 + struct attribute *attr, char *buf)
30934 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
30935 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
30936 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
30938 +static inline void sysaufs_brs_init(void)
30943 +#endif /* CONFIG_SYSFS */
30945 +#endif /* __KERNEL__ */
30946 +#endif /* __SYSAUFS_H__ */
30947 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
30948 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
30949 +++ linux/fs/aufs/sysfs.c 2018-04-15 08:49:13.404484168 +0200
30952 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30954 + * This program, aufs is free software; you can redistribute it and/or modify
30955 + * it under the terms of the GNU General Public License as published by
30956 + * the Free Software Foundation; either version 2 of the License, or
30957 + * (at your option) any later version.
30959 + * This program is distributed in the hope that it will be useful,
30960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30962 + * GNU General Public License for more details.
30964 + * You should have received a copy of the GNU General Public License
30965 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30969 + * sysfs interface
30972 +#include <linux/compat.h>
30973 +#include <linux/seq_file.h>
30976 +#ifdef CONFIG_AUFS_FS_MODULE
30977 +/* this entry violates the "one line per file" policy of sysfs */
30978 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
30982 + static char *conf =
30983 +/* this file is generated at compiling */
30984 +#include "conf.str"
30987 + err = snprintf(buf, PAGE_SIZE, conf);
30988 + if (unlikely(err >= PAGE_SIZE))
30993 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
30996 +static struct attribute *au_attr[] = {
30997 +#ifdef CONFIG_AUFS_FS_MODULE
30998 + &au_config_attr.attr,
31000 + NULL, /* need to NULL terminate the list of attributes */
31003 +static struct attribute_group sysaufs_attr_group_body = {
31007 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31009 +/* ---------------------------------------------------------------------- */
31011 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31015 + SiMustAnyLock(sb);
31018 + if (au_opt_test(au_mntflags(sb), XINO)) {
31019 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31020 + seq_putc(seq, '\n');
31026 + * the lifetime of branch is independent from the entry under sysfs.
31027 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31030 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31031 + aufs_bindex_t bindex, int idx)
31034 + struct path path;
31035 + struct dentry *root;
31036 + struct au_branch *br;
31037 + au_br_perm_str_t perm;
31039 + AuDbg("b%d\n", bindex);
31042 + root = sb->s_root;
31043 + di_read_lock_parent(root, !AuLock_IR);
31044 + br = au_sbr(sb, bindex);
31047 + case AuBrSysfs_BR:
31048 + path.mnt = au_br_mnt(br);
31049 + path.dentry = au_h_dptr(root, bindex);
31050 + err = au_seq_path(seq, &path);
31052 + au_optstr_br_perm(&perm, br->br_perm);
31053 + seq_printf(seq, "=%s\n", perm.a);
31056 + case AuBrSysfs_BRID:
31057 + seq_printf(seq, "%d\n", br->br_id);
31060 + di_read_unlock(root, !AuLock_IR);
31061 + if (unlikely(err || seq_has_overflowed(seq)))
31067 +/* ---------------------------------------------------------------------- */
31069 +static struct seq_file *au_seq(char *p, ssize_t len)
31071 + struct seq_file *seq;
31073 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31075 + /* mutex_init(&seq.lock); */
31078 + return seq; /* success */
31081 + seq = ERR_PTR(-ENOMEM);
31085 +#define SysaufsBr_PREFIX "br"
31086 +#define SysaufsBrid_PREFIX "brid"
31088 +/* todo: file size may exceed PAGE_SIZE */
31089 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31095 + aufs_bindex_t bbot;
31096 + struct au_sbinfo *sbinfo;
31097 + struct super_block *sb;
31098 + struct seq_file *seq;
31100 + struct attribute **cattr;
31102 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31103 + sb = sbinfo->si_sb;
31106 + * prevent a race condition between sysfs and aufs.
31107 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31108 + * prohibits maintaining the sysfs entries.
31109 + * hew we acquire read lock after sysfs_get_active_two().
31110 + * on the other hand, the remount process may maintain the sysfs/aufs
31111 + * entries after acquiring write lock.
31112 + * it can cause a deadlock.
31113 + * simply we gave up processing read here.
31116 + if (unlikely(!si_noflush_read_trylock(sb)))
31119 + seq = au_seq(buf, PAGE_SIZE);
31120 + err = PTR_ERR(seq);
31124 + name = (void *)attr->name;
31125 + cattr = sysaufs_si_attrs;
31127 + if (!strcmp(name, (*cattr)->name)) {
31128 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31135 + if (!strncmp(name, SysaufsBrid_PREFIX,
31136 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31137 + idx = AuBrSysfs_BRID;
31138 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31139 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31140 + sizeof(SysaufsBr_PREFIX) - 1)) {
31141 + idx = AuBrSysfs_BR;
31142 + name += sizeof(SysaufsBr_PREFIX) - 1;
31146 + err = kstrtol(name, 10, &l);
31148 + bbot = au_sbbot(sb);
31150 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31157 + err = seq->count;
31158 + /* sysfs limit */
31159 + if (unlikely(err == PAGE_SIZE))
31164 + si_read_unlock(sb);
31169 +/* ---------------------------------------------------------------------- */
31171 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31175 + aufs_bindex_t bindex, bbot;
31178 + struct seq_file *seq;
31179 + struct au_branch *br;
31181 + si_read_lock(sb, AuLock_FLUSH);
31182 + bbot = au_sbbot(sb);
31188 + buf = (void *)__get_free_page(GFP_NOFS);
31189 + if (unlikely(!buf))
31192 + seq = au_seq(buf, PAGE_SIZE);
31193 + err = PTR_ERR(seq);
31197 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31198 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31199 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31200 + if (unlikely(err))
31203 + br = au_sbr(sb, bindex);
31204 + brid = br->br_id;
31205 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31206 + err = __put_user(brid, &arg->id);
31207 + if (unlikely(err))
31210 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31211 + err = __put_user(br->br_perm, &arg->perm);
31212 + if (unlikely(err))
31215 + err = au_seq_path(seq, &br->br_path);
31216 + if (unlikely(err))
31218 + seq_putc(seq, '\0');
31219 + if (!seq_has_overflowed(seq)) {
31220 + err = copy_to_user(arg->path, seq->buf, seq->count);
31222 + if (unlikely(err))
31229 + if (unlikely(err))
31235 + free_page((unsigned long)buf);
31237 + si_read_unlock(sb);
31241 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31243 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31246 +#ifdef CONFIG_COMPAT
31247 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31249 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31253 +/* ---------------------------------------------------------------------- */
31255 +void sysaufs_br_init(struct au_branch *br)
31258 + struct au_brsysfs *br_sysfs;
31259 + struct attribute *attr;
31261 + br_sysfs = br->br_sysfs;
31262 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31263 + attr = &br_sysfs->attr;
31264 + sysfs_attr_init(attr);
31265 + attr->name = br_sysfs->name;
31266 + attr->mode = S_IRUGO;
31271 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31273 + struct au_branch *br;
31274 + struct kobject *kobj;
31275 + struct au_brsysfs *br_sysfs;
31277 + aufs_bindex_t bbot;
31279 + dbgaufs_brs_del(sb, bindex);
31281 + if (!sysaufs_brs)
31284 + kobj = &au_sbi(sb)->si_kobj;
31285 + bbot = au_sbbot(sb);
31286 + for (; bindex <= bbot; bindex++) {
31287 + br = au_sbr(sb, bindex);
31288 + br_sysfs = br->br_sysfs;
31289 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31290 + sysfs_remove_file(kobj, &br_sysfs->attr);
31296 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31299 + aufs_bindex_t bbot;
31300 + struct kobject *kobj;
31301 + struct au_branch *br;
31302 + struct au_brsysfs *br_sysfs;
31304 + dbgaufs_brs_add(sb, bindex);
31306 + if (!sysaufs_brs)
31309 + kobj = &au_sbi(sb)->si_kobj;
31310 + bbot = au_sbbot(sb);
31311 + for (; bindex <= bbot; bindex++) {
31312 + br = au_sbr(sb, bindex);
31313 + br_sysfs = br->br_sysfs;
31314 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31315 + SysaufsBr_PREFIX "%d", bindex);
31316 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31317 + SysaufsBrid_PREFIX "%d", bindex);
31318 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31319 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31320 + if (unlikely(err))
31321 + pr_warn("failed %s under sysfs(%d)\n",
31322 + br_sysfs->name, err);
31327 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31328 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31329 +++ linux/fs/aufs/sysrq.c 2018-04-15 08:49:13.404484168 +0200
31332 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31334 + * This program, aufs is free software; you can redistribute it and/or modify
31335 + * it under the terms of the GNU General Public License as published by
31336 + * the Free Software Foundation; either version 2 of the License, or
31337 + * (at your option) any later version.
31339 + * This program is distributed in the hope that it will be useful,
31340 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31341 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31342 + * GNU General Public License for more details.
31344 + * You should have received a copy of the GNU General Public License
31345 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31349 + * magic sysrq hanlder
31352 +/* #include <linux/sysrq.h> */
31353 +#include <linux/writeback.h>
31356 +/* ---------------------------------------------------------------------- */
31358 +static void sysrq_sb(struct super_block *sb)
31361 + struct au_sbinfo *sbinfo;
31362 + struct file *file;
31363 + struct hlist_bl_head *files;
31364 + struct hlist_bl_node *pos;
31365 + struct au_finfo *finfo;
31367 + plevel = au_plevel;
31368 + au_plevel = KERN_WARNING;
31370 + /* since we define pr_fmt, call printk directly */
31371 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31373 + sbinfo = au_sbi(sb);
31374 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31375 + pr("superblock\n");
31379 + pr("root dentry\n");
31380 + au_dpri_dentry(sb->s_root);
31381 + pr("root inode\n");
31382 + au_dpri_inode(d_inode(sb->s_root));
31387 + int err, i, j, ndentry;
31388 + struct au_dcsub_pages dpages;
31389 + struct au_dpage *dpage;
31391 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31392 + if (unlikely(err))
31394 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31396 + for (i = 0; i < dpages.ndpage; i++) {
31397 + dpage = dpages.dpages + i;
31398 + ndentry = dpage->ndentry;
31399 + for (j = 0; j < ndentry; j++)
31400 + au_dpri_dentry(dpage->dentries[j]);
31402 + au_dpages_free(&dpages);
31410 + pr("isolated inode\n");
31411 + spin_lock(&sb->s_inode_list_lock);
31412 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31413 + spin_lock(&i->i_lock);
31414 + if (1 || hlist_empty(&i->i_dentry))
31415 + au_dpri_inode(i);
31416 + spin_unlock(&i->i_lock);
31418 + spin_unlock(&sb->s_inode_list_lock);
31422 + files = &au_sbi(sb)->si_files;
31423 + hlist_bl_lock(files);
31424 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31427 + file = finfo->fi_file;
31428 + mode = file_inode(file)->i_mode;
31429 + if (!special_file(mode))
31430 + au_dpri_file(file);
31432 + hlist_bl_unlock(files);
31436 + au_plevel = plevel;
31439 +/* ---------------------------------------------------------------------- */
31441 +/* module parameter */
31442 +static char *aufs_sysrq_key = "a";
31443 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
31444 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31446 +static void au_sysrq(int key __maybe_unused)
31448 + struct au_sbinfo *sbinfo;
31449 + struct hlist_bl_node *pos;
31452 + au_sbilist_lock();
31453 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31454 + sysrq_sb(sbinfo->si_sb);
31455 + au_sbilist_unlock();
31459 +static struct sysrq_key_op au_sysrq_op = {
31460 + .handler = au_sysrq,
31461 + .help_msg = "Aufs",
31462 + .action_msg = "Aufs",
31463 + .enable_mask = SYSRQ_ENABLE_DUMP
31466 +/* ---------------------------------------------------------------------- */
31468 +int __init au_sysrq_init(void)
31474 + key = *aufs_sysrq_key;
31475 + if ('a' <= key && key <= 'z')
31476 + err = register_sysrq_key(key, &au_sysrq_op);
31477 + if (unlikely(err))
31478 + pr_err("err %d, sysrq=%c\n", err, key);
31482 +void au_sysrq_fin(void)
31486 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31487 + if (unlikely(err))
31488 + pr_err("err %d (ignored)\n", err);
31490 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31491 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31492 +++ linux/fs/aufs/vdir.c 2018-06-04 09:08:09.188079511 +0200
31495 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31497 + * This program, aufs is free software; you can redistribute it and/or modify
31498 + * it under the terms of the GNU General Public License as published by
31499 + * the Free Software Foundation; either version 2 of the License, or
31500 + * (at your option) any later version.
31502 + * This program is distributed in the hope that it will be useful,
31503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31505 + * GNU General Public License for more details.
31507 + * You should have received a copy of the GNU General Public License
31508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31512 + * virtual or vertical directory
31517 +static unsigned int calc_size(int nlen)
31519 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31522 +static int set_deblk_end(union au_vdir_deblk_p *p,
31523 + union au_vdir_deblk_p *deblk_end)
31525 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31526 + p->de->de_str.len = 0;
31530 + return -1; /* error */
31533 +/* returns true or false */
31534 +static int is_deblk_end(union au_vdir_deblk_p *p,
31535 + union au_vdir_deblk_p *deblk_end)
31537 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31538 + return !p->de->de_str.len;
31542 +static unsigned char *last_deblk(struct au_vdir *vdir)
31544 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31547 +/* ---------------------------------------------------------------------- */
31549 +/* estimate the appropriate size for name hash table */
31550 +unsigned int au_rdhash_est(loff_t sz)
31558 + if (sz < AUFS_RDHASH_DEF)
31559 + n = AUFS_RDHASH_DEF;
31560 + /* pr_info("n %u\n", n); */
31565 + * the allocated memory has to be freed by
31566 + * au_nhash_wh_free() or au_nhash_de_free().
31568 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31570 + struct hlist_head *head;
31574 + sz = sizeof(*nhash->nh_head) * num_hash;
31575 + head = kmalloc(sz, gfp);
31577 + nhash->nh_num = num_hash;
31578 + nhash->nh_head = head;
31579 + for (u = 0; u < num_hash; u++)
31580 + INIT_HLIST_HEAD(head++);
31581 + return 0; /* success */
31587 +static void nhash_count(struct hlist_head *head)
31591 + struct hlist_node *pos;
31594 + hlist_for_each(pos, head)
31596 + pr_info("%lu\n", n);
31600 +static void au_nhash_wh_do_free(struct hlist_head *head)
31602 + struct au_vdir_wh *pos;
31603 + struct hlist_node *node;
31605 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31609 +static void au_nhash_de_do_free(struct hlist_head *head)
31611 + struct au_vdir_dehstr *pos;
31612 + struct hlist_node *node;
31614 + hlist_for_each_entry_safe(pos, node, head, hash)
31615 + au_cache_free_vdir_dehstr(pos);
31618 +static void au_nhash_do_free(struct au_nhash *nhash,
31619 + void (*free)(struct hlist_head *head))
31622 + struct hlist_head *head;
31624 + n = nhash->nh_num;
31628 + head = nhash->nh_head;
31629 + while (n-- > 0) {
31630 + nhash_count(head);
31633 + kfree(nhash->nh_head);
31636 +void au_nhash_wh_free(struct au_nhash *whlist)
31638 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31641 +static void au_nhash_de_free(struct au_nhash *delist)
31643 + au_nhash_do_free(delist, au_nhash_de_do_free);
31646 +/* ---------------------------------------------------------------------- */
31648 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31652 + unsigned int u, n;
31653 + struct hlist_head *head;
31654 + struct au_vdir_wh *pos;
31657 + n = whlist->nh_num;
31658 + head = whlist->nh_head;
31659 + for (u = 0; u < n; u++, head++)
31660 + hlist_for_each_entry(pos, head, wh_hash)
31661 + if (pos->wh_bindex == btgt && ++num > limit)
31666 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31667 + unsigned char *name,
31668 + unsigned int len)
31671 + /* const unsigned int magic_bit = 12; */
31673 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31680 + /* v = hash_long(v, magic_bit); */
31681 + v %= nhash->nh_num;
31682 + return nhash->nh_head + v;
31685 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31688 + return str->len == nlen && !memcmp(str->name, name, nlen);
31691 +/* returns found or not */
31692 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31694 + struct hlist_head *head;
31695 + struct au_vdir_wh *pos;
31696 + struct au_vdir_destr *str;
31698 + head = au_name_hash(whlist, name, nlen);
31699 + hlist_for_each_entry(pos, head, wh_hash) {
31700 + str = &pos->wh_str;
31701 + AuDbg("%.*s\n", str->len, str->name);
31702 + if (au_nhash_test_name(str, name, nlen))
31708 +/* returns found(true) or not */
31709 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31711 + struct hlist_head *head;
31712 + struct au_vdir_dehstr *pos;
31713 + struct au_vdir_destr *str;
31715 + head = au_name_hash(delist, name, nlen);
31716 + hlist_for_each_entry(pos, head, hash) {
31718 + AuDbg("%.*s\n", str->len, str->name);
31719 + if (au_nhash_test_name(str, name, nlen))
31725 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31726 + unsigned char d_type)
31728 +#ifdef CONFIG_AUFS_SHWH
31729 + wh->wh_ino = ino;
31730 + wh->wh_type = d_type;
31734 +/* ---------------------------------------------------------------------- */
31736 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31737 + unsigned int d_type, aufs_bindex_t bindex,
31738 + unsigned char shwh)
31741 + struct au_vdir_destr *str;
31742 + struct au_vdir_wh *wh;
31744 + AuDbg("%.*s\n", nlen, name);
31745 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31748 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31749 + if (unlikely(!wh))
31753 + wh->wh_bindex = bindex;
31755 + au_shwh_init_wh(wh, ino, d_type);
31756 + str = &wh->wh_str;
31758 + memcpy(str->name, name, nlen);
31759 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31766 +static int append_deblk(struct au_vdir *vdir)
31769 + unsigned long ul;
31770 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31771 + union au_vdir_deblk_p p, deblk_end;
31772 + unsigned char **o;
31775 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31776 + GFP_NOFS, /*may_shrink*/0);
31777 + if (unlikely(!o))
31780 + vdir->vd_deblk = o;
31781 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31783 + ul = vdir->vd_nblk++;
31784 + vdir->vd_deblk[ul] = p.deblk;
31785 + vdir->vd_last.ul = ul;
31786 + vdir->vd_last.p.deblk = p.deblk;
31787 + deblk_end.deblk = p.deblk + deblk_sz;
31788 + err = set_deblk_end(&p, &deblk_end);
31795 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31796 + unsigned int d_type, struct au_nhash *delist)
31800 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31801 + union au_vdir_deblk_p p, *room, deblk_end;
31802 + struct au_vdir_dehstr *dehstr;
31804 + p.deblk = last_deblk(vdir);
31805 + deblk_end.deblk = p.deblk + deblk_sz;
31806 + room = &vdir->vd_last.p;
31807 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
31808 + || !is_deblk_end(room, &deblk_end));
31810 + sz = calc_size(nlen);
31811 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
31812 + err = append_deblk(vdir);
31813 + if (unlikely(err))
31816 + p.deblk = last_deblk(vdir);
31817 + deblk_end.deblk = p.deblk + deblk_sz;
31819 + AuDebugOn(room->deblk != p.deblk);
31823 + dehstr = au_cache_alloc_vdir_dehstr();
31824 + if (unlikely(!dehstr))
31827 + dehstr->str = &room->de->de_str;
31828 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
31829 + room->de->de_ino = ino;
31830 + room->de->de_type = d_type;
31831 + room->de->de_str.len = nlen;
31832 + memcpy(room->de->de_str.name, name, nlen);
31835 + room->deblk += sz;
31836 + if (unlikely(set_deblk_end(room, &deblk_end)))
31837 + err = append_deblk(vdir);
31844 +/* ---------------------------------------------------------------------- */
31846 +void au_vdir_free(struct au_vdir *vdir)
31848 + unsigned char **deblk;
31850 + deblk = vdir->vd_deblk;
31851 + while (vdir->vd_nblk--)
31853 + kfree(vdir->vd_deblk);
31854 + au_cache_free_vdir(vdir);
31857 +static struct au_vdir *alloc_vdir(struct file *file)
31859 + struct au_vdir *vdir;
31860 + struct super_block *sb;
31863 + sb = file->f_path.dentry->d_sb;
31864 + SiMustAnyLock(sb);
31867 + vdir = au_cache_alloc_vdir();
31868 + if (unlikely(!vdir))
31871 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
31872 + if (unlikely(!vdir->vd_deblk))
31875 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
31876 + if (!vdir->vd_deblk_sz) {
31877 + /* estimate the appropriate size for deblk */
31878 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
31879 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
31881 + vdir->vd_nblk = 0;
31882 + vdir->vd_version = 0;
31883 + vdir->vd_jiffy = 0;
31884 + err = append_deblk(vdir);
31886 + return vdir; /* success */
31888 + kfree(vdir->vd_deblk);
31891 + au_cache_free_vdir(vdir);
31893 + vdir = ERR_PTR(err);
31897 +static int reinit_vdir(struct au_vdir *vdir)
31900 + union au_vdir_deblk_p p, deblk_end;
31902 + while (vdir->vd_nblk > 1) {
31903 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
31904 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
31907 + p.deblk = vdir->vd_deblk[0];
31908 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
31909 + err = set_deblk_end(&p, &deblk_end);
31910 + /* keep vd_dblk_sz */
31911 + vdir->vd_last.ul = 0;
31912 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
31913 + vdir->vd_version = 0;
31914 + vdir->vd_jiffy = 0;
31919 +/* ---------------------------------------------------------------------- */
31921 +#define AuFillVdir_CALLED 1
31922 +#define AuFillVdir_WHABLE (1 << 1)
31923 +#define AuFillVdir_SHWH (1 << 2)
31924 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
31925 +#define au_fset_fillvdir(flags, name) \
31926 + do { (flags) |= AuFillVdir_##name; } while (0)
31927 +#define au_fclr_fillvdir(flags, name) \
31928 + do { (flags) &= ~AuFillVdir_##name; } while (0)
31930 +#ifndef CONFIG_AUFS_SHWH
31931 +#undef AuFillVdir_SHWH
31932 +#define AuFillVdir_SHWH 0
31935 +struct fillvdir_arg {
31936 + struct dir_context ctx;
31937 + struct file *file;
31938 + struct au_vdir *vdir;
31939 + struct au_nhash delist;
31940 + struct au_nhash whlist;
31941 + aufs_bindex_t bindex;
31942 + unsigned int flags;
31946 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
31947 + loff_t offset __maybe_unused, u64 h_ino,
31948 + unsigned int d_type)
31950 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
31951 + char *name = (void *)__name;
31952 + struct super_block *sb;
31954 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
31957 + sb = arg->file->f_path.dentry->d_sb;
31958 + au_fset_fillvdir(arg->flags, CALLED);
31960 + if (nlen <= AUFS_WH_PFX_LEN
31961 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
31962 + if (test_known(&arg->delist, name, nlen)
31963 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
31964 + goto out; /* already exists or whiteouted */
31966 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
31968 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
31969 + d_type = DT_UNKNOWN;
31970 + arg->err = append_de(arg->vdir, name, nlen, ino,
31971 + d_type, &arg->delist);
31973 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
31974 + name += AUFS_WH_PFX_LEN;
31975 + nlen -= AUFS_WH_PFX_LEN;
31976 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
31977 + goto out; /* already whiteouted */
31980 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
31983 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
31984 + d_type = DT_UNKNOWN;
31985 + arg->err = au_nhash_append_wh
31986 + (&arg->whlist, name, nlen, ino, d_type,
31987 + arg->bindex, shwh);
31993 + arg->vdir->vd_jiffy = jiffies;
31995 + AuTraceErr(arg->err);
31999 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32000 + struct au_nhash *whlist, struct au_nhash *delist)
32002 +#ifdef CONFIG_AUFS_SHWH
32004 + unsigned int nh, u;
32005 + struct hlist_head *head;
32006 + struct au_vdir_wh *pos;
32007 + struct hlist_node *n;
32009 + struct au_vdir_destr *destr;
32011 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32014 + o = p = (void *)__get_free_page(GFP_NOFS);
32015 + if (unlikely(!p))
32019 + nh = whlist->nh_num;
32020 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32021 + p += AUFS_WH_PFX_LEN;
32022 + for (u = 0; u < nh; u++) {
32023 + head = whlist->nh_head + u;
32024 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32025 + destr = &pos->wh_str;
32026 + memcpy(p, destr->name, destr->len);
32027 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32028 + pos->wh_ino, pos->wh_type, delist);
32029 + if (unlikely(err))
32034 + free_page((unsigned long)o);
32044 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32047 + unsigned int rdhash;
32049 + aufs_bindex_t bbot, bindex, btop;
32050 + unsigned char shwh;
32051 + struct file *hf, *file;
32052 + struct super_block *sb;
32054 + file = arg->file;
32055 + sb = file->f_path.dentry->d_sb;
32056 + SiMustAnyLock(sb);
32058 + rdhash = au_sbi(sb)->si_rdhash;
32060 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32061 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32062 + if (unlikely(err))
32064 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32065 + if (unlikely(err))
32071 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32073 + au_fset_fillvdir(arg->flags, SHWH);
32075 + btop = au_fbtop(file);
32076 + bbot = au_fbbot_dir(file);
32077 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32078 + hf = au_hf_dir(file, bindex);
32082 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32084 + if (unlikely(offset))
32087 + arg->bindex = bindex;
32088 + au_fclr_fillvdir(arg->flags, WHABLE);
32090 + || (bindex != bbot
32091 + && au_br_whable(au_sbr_perm(sb, bindex))))
32092 + au_fset_fillvdir(arg->flags, WHABLE);
32095 + au_fclr_fillvdir(arg->flags, CALLED);
32097 + err = vfsub_iterate_dir(hf, &arg->ctx);
32100 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32103 + * dir_relax() may be good for concurrency, but aufs should not
32104 + * use it since it will cause a lockdep problem.
32108 + if (!err && shwh)
32109 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32111 + au_nhash_wh_free(&arg->whlist);
32114 + au_nhash_de_free(&arg->delist);
32119 +static int read_vdir(struct file *file, int may_read)
32122 + unsigned long expire;
32123 + unsigned char do_read;
32124 + struct fillvdir_arg arg = {
32126 + .actor = fillvdir
32129 + struct inode *inode;
32130 + struct au_vdir *vdir, *allocated;
32133 + inode = file_inode(file);
32134 + IMustLock(inode);
32135 + IiMustWriteLock(inode);
32136 + SiMustAnyLock(inode->i_sb);
32138 + allocated = NULL;
32140 + expire = au_sbi(inode->i_sb)->si_rdcache;
32141 + vdir = au_ivdir(inode);
32144 + vdir = alloc_vdir(file);
32145 + err = PTR_ERR(vdir);
32146 + if (IS_ERR(vdir))
32149 + allocated = vdir;
32150 + } else if (may_read
32151 + && (!inode_eq_iversion(inode, vdir->vd_version)
32152 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32154 + err = reinit_vdir(vdir);
32155 + if (unlikely(err))
32160 + return 0; /* success */
32164 + err = au_do_read_vdir(&arg);
32166 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32167 + vdir->vd_version = inode_query_iversion(inode);
32168 + vdir->vd_last.ul = 0;
32169 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32171 + au_set_ivdir(inode, allocated);
32172 + } else if (allocated)
32173 + au_vdir_free(allocated);
32179 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32182 + unsigned long ul, n;
32183 + const unsigned int deblk_sz = src->vd_deblk_sz;
32185 + AuDebugOn(tgt->vd_nblk != 1);
32188 + if (tgt->vd_nblk < src->vd_nblk) {
32189 + unsigned char **p;
32191 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32192 + GFP_NOFS, /*may_shrink*/0);
32193 + if (unlikely(!p))
32195 + tgt->vd_deblk = p;
32198 + if (tgt->vd_deblk_sz != deblk_sz) {
32199 + unsigned char *p;
32201 + tgt->vd_deblk_sz = deblk_sz;
32202 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32203 + /*may_shrink*/1);
32204 + if (unlikely(!p))
32206 + tgt->vd_deblk[0] = p;
32208 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32209 + tgt->vd_version = src->vd_version;
32210 + tgt->vd_jiffy = src->vd_jiffy;
32212 + n = src->vd_nblk;
32213 + for (ul = 1; ul < n; ul++) {
32214 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32216 + if (unlikely(!tgt->vd_deblk[ul]))
32220 + tgt->vd_nblk = n;
32221 + tgt->vd_last.ul = tgt->vd_last.ul;
32222 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32223 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32224 + - src->vd_deblk[src->vd_last.ul];
32226 + return 0; /* success */
32229 + rerr = reinit_vdir(tgt);
32234 +int au_vdir_init(struct file *file)
32237 + struct inode *inode;
32238 + struct au_vdir *vdir_cache, *allocated;
32240 + /* test file->f_pos here instead of ctx->pos */
32241 + err = read_vdir(file, !file->f_pos);
32242 + if (unlikely(err))
32245 + allocated = NULL;
32246 + vdir_cache = au_fvdir_cache(file);
32247 + if (!vdir_cache) {
32248 + vdir_cache = alloc_vdir(file);
32249 + err = PTR_ERR(vdir_cache);
32250 + if (IS_ERR(vdir_cache))
32252 + allocated = vdir_cache;
32253 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32254 + /* test file->f_pos here instead of ctx->pos */
32255 + err = reinit_vdir(vdir_cache);
32256 + if (unlikely(err))
32259 + return 0; /* success */
32261 + inode = file_inode(file);
32262 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32264 + file->f_version = inode_query_iversion(inode);
32266 + au_set_fvdir_cache(file, allocated);
32267 + } else if (allocated)
32268 + au_vdir_free(allocated);
32274 +static loff_t calc_offset(struct au_vdir *vdir)
32277 + union au_vdir_deblk_p p;
32279 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32280 + offset = vdir->vd_last.p.deblk - p.deblk;
32281 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32285 +/* returns true or false */
32286 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32289 + unsigned int deblk_sz;
32290 + unsigned long ul, n;
32292 + union au_vdir_deblk_p p, deblk_end;
32293 + struct au_vdir *vdir_cache;
32296 + vdir_cache = au_fvdir_cache(file);
32297 + offset = calc_offset(vdir_cache);
32298 + AuDbg("offset %lld\n", offset);
32299 + if (ctx->pos == offset)
32302 + vdir_cache->vd_last.ul = 0;
32303 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32308 + deblk_sz = vdir_cache->vd_deblk_sz;
32309 + ul = div64_u64(ctx->pos, deblk_sz);
32310 + AuDbg("ul %lu\n", ul);
32311 + if (ul >= vdir_cache->vd_nblk)
32314 + n = vdir_cache->vd_nblk;
32315 + for (; ul < n; ul++) {
32316 + p.deblk = vdir_cache->vd_deblk[ul];
32317 + deblk_end.deblk = p.deblk + deblk_sz;
32319 + offset *= deblk_sz;
32320 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32323 + l = calc_size(p.de->de_str.len);
32327 + if (!is_deblk_end(&p, &deblk_end)) {
32329 + vdir_cache->vd_last.ul = ul;
32330 + vdir_cache->vd_last.p = p;
32338 + AuDbg("valid %d\n", !valid);
32342 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32344 + unsigned int l, deblk_sz;
32345 + union au_vdir_deblk_p deblk_end;
32346 + struct au_vdir *vdir_cache;
32347 + struct au_vdir_de *de;
32349 + vdir_cache = au_fvdir_cache(file);
32350 + if (!seek_vdir(file, ctx))
32353 + deblk_sz = vdir_cache->vd_deblk_sz;
32355 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32356 + deblk_end.deblk += deblk_sz;
32357 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32358 + de = vdir_cache->vd_last.p.de;
32359 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32360 + de->de_str.len, de->de_str.name, ctx->pos,
32361 + (unsigned long)de->de_ino, de->de_type);
32362 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32363 + de->de_str.len, de->de_ino,
32365 + /* todo: ignore the error caused by udba? */
32366 + /* return err; */
32370 + l = calc_size(de->de_str.len);
32371 + vdir_cache->vd_last.p.deblk += l;
32374 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32375 + vdir_cache->vd_last.ul++;
32376 + vdir_cache->vd_last.p.deblk
32377 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32378 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32387 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32388 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32389 +++ linux/fs/aufs/vfsub.c 2018-06-15 11:15:15.400449109 +0200
32392 + * Copyright (C) 2005-2018 Junjiro R. Okajima
32394 + * This program, aufs is free software; you can redistribute it and/or modify
32395 + * it under the terms of the GNU General Public License as published by
32396 + * the Free Software Foundation; either version 2 of the License, or
32397 + * (at your option) any later version.
32399 + * This program is distributed in the hope that it will be useful,
32400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32402 + * GNU General Public License for more details.
32404 + * You should have received a copy of the GNU General Public License
32405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32409 + * sub-routines for VFS
32412 +#include <linux/mnt_namespace.h>
32413 +#include <linux/namei.h>
32414 +#include <linux/nsproxy.h>
32415 +#include <linux/security.h>
32416 +#include <linux/splice.h>
32419 +#ifdef CONFIG_AUFS_BR_FUSE
32420 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32422 + if (!au_test_fuse(h_sb) || !au_userns)
32425 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32429 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32434 + down_read(&h_sb->s_umount);
32435 + err = __sync_filesystem(h_sb, wait);
32436 + up_read(&h_sb->s_umount);
32442 +/* ---------------------------------------------------------------------- */
32444 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32448 + struct super_block *h_sb;
32450 + /* for remote fs, leave work for its getattr or d_revalidate */
32451 + /* for bad i_attr fs, handle them in aufs_getattr() */
32452 + /* still some fs may acquire i_mutex. we need to skip them */
32456 + h_sb = h_path->dentry->d_sb;
32457 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32459 + err = vfsub_getattr(h_path, &st);
32464 +/* ---------------------------------------------------------------------- */
32466 +struct file *vfsub_dentry_open(struct path *path, int flags)
32468 + struct file *file;
32470 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32472 + if (!IS_ERR_OR_NULL(file)
32473 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32474 + i_readcount_inc(d_inode(path->dentry));
32479 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32481 + struct file *file;
32484 + file = filp_open(path,
32485 + oflags /* | __FMODE_NONOTIFY */,
32488 + if (IS_ERR(file))
32490 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32497 + * Ideally this function should call VFS:do_last() in order to keep all its
32498 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32499 + * structure such as nameidata. This is a second (or third) best approach.
32500 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32502 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32503 + struct vfsub_aopen_args *args, struct au_branch *br)
32506 + struct file *file = args->file;
32507 + /* copied from linux/fs/namei.c:atomic_open() */
32508 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32511 + AuDebugOn(!dir->i_op->atomic_open);
32513 + err = au_br_test_oflag(args->open_flag, br);
32514 + if (unlikely(err))
32517 + args->file->f_path.dentry = DENTRY_NOT_SET;
32518 + args->file->f_path.mnt = au_br_mnt(br);
32519 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32520 + args->create_mode, args->opened);
32522 + /* some filesystems don't set FILE_CREATED while succeeded? */
32523 + if (*args->opened & FILE_CREATED)
32524 + fsnotify_create(dir, dentry);
32530 + /* todo: call VFS:may_open() here */
32531 + err = open_check_o_direct(file);
32532 + /* todo: ima_file_check() too? */
32533 + if (!err && (args->open_flag & __FMODE_EXEC))
32534 + err = deny_write_access(file);
32535 + if (unlikely(err))
32536 + /* note that the file is created and still opened */
32541 + fsnotify_open(file);
32547 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32551 + err = kern_path(name, flags, path);
32552 + if (!err && d_is_positive(path->dentry))
32553 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32557 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32558 + struct dentry *parent, int len)
32560 + struct path path = {
32564 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32565 + if (IS_ERR(path.dentry))
32567 + if (d_is_positive(path.dentry))
32568 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32571 + AuTraceErrPtr(path.dentry);
32572 + return path.dentry;
32575 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32578 + struct path path = {
32582 + /* VFS checks it too, but by WARN_ON_ONCE() */
32583 + IMustLock(d_inode(parent));
32585 + path.dentry = lookup_one_len(name, parent, len);
32586 + if (IS_ERR(path.dentry))
32588 + if (d_is_positive(path.dentry))
32589 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32592 + AuTraceErrPtr(path.dentry);
32593 + return path.dentry;
32596 +void vfsub_call_lkup_one(void *args)
32598 + struct vfsub_lkup_one_args *a = args;
32599 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32602 +/* ---------------------------------------------------------------------- */
32604 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32605 + struct dentry *d2, struct au_hinode *hdir2)
32607 + struct dentry *d;
32610 + d = lock_rename(d1, d2);
32612 + au_hn_suspend(hdir1);
32613 + if (hdir1 != hdir2)
32614 + au_hn_suspend(hdir2);
32619 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32620 + struct dentry *d2, struct au_hinode *hdir2)
32622 + au_hn_resume(hdir1);
32623 + if (hdir1 != hdir2)
32624 + au_hn_resume(hdir2);
32626 + unlock_rename(d1, d2);
32630 +/* ---------------------------------------------------------------------- */
32632 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32635 + struct dentry *d;
32639 + d = path->dentry;
32640 + path->dentry = d->d_parent;
32641 + err = security_path_mknod(path, d, mode, 0);
32642 + path->dentry = d;
32643 + if (unlikely(err))
32647 + err = vfs_create(dir, path->dentry, mode, want_excl);
32650 + struct path tmp = *path;
32653 + vfsub_update_h_iattr(&tmp, &did);
32655 + tmp.dentry = path->dentry->d_parent;
32656 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32665 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32668 + struct dentry *d;
32672 + d = path->dentry;
32673 + path->dentry = d->d_parent;
32674 + err = security_path_symlink(path, d, symname);
32675 + path->dentry = d;
32676 + if (unlikely(err))
32680 + err = vfs_symlink(dir, path->dentry, symname);
32683 + struct path tmp = *path;
32686 + vfsub_update_h_iattr(&tmp, &did);
32688 + tmp.dentry = path->dentry->d_parent;
32689 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32698 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32701 + struct dentry *d;
32705 + d = path->dentry;
32706 + path->dentry = d->d_parent;
32707 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32708 + path->dentry = d;
32709 + if (unlikely(err))
32713 + err = vfs_mknod(dir, path->dentry, mode, dev);
32716 + struct path tmp = *path;
32719 + vfsub_update_h_iattr(&tmp, &did);
32721 + tmp.dentry = path->dentry->d_parent;
32722 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32731 +static int au_test_nlink(struct inode *inode)
32733 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32735 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32736 + || inode->i_nlink < link_max)
32741 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32742 + struct inode **delegated_inode)
32745 + struct dentry *d;
32749 + err = au_test_nlink(d_inode(src_dentry));
32750 + if (unlikely(err))
32753 + /* we don't call may_linkat() */
32754 + d = path->dentry;
32755 + path->dentry = d->d_parent;
32756 + err = security_path_link(src_dentry, path, d);
32757 + path->dentry = d;
32758 + if (unlikely(err))
32762 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32765 + struct path tmp = *path;
32768 + /* fuse has different memory inode for the same inumber */
32769 + vfsub_update_h_iattr(&tmp, &did);
32771 + tmp.dentry = path->dentry->d_parent;
32772 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32773 + tmp.dentry = src_dentry;
32774 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32783 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32784 + struct inode *dir, struct path *path,
32785 + struct inode **delegated_inode, unsigned int flags)
32788 + struct path tmp = {
32791 + struct dentry *d;
32794 + IMustLock(src_dir);
32796 + d = path->dentry;
32797 + path->dentry = d->d_parent;
32798 + tmp.dentry = src_dentry->d_parent;
32799 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32800 + path->dentry = d;
32801 + if (unlikely(err))
32805 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
32806 + delegated_inode, flags);
32811 + tmp.dentry = d->d_parent;
32812 + vfsub_update_h_iattr(&tmp, &did);
32814 + tmp.dentry = src_dentry;
32815 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32816 + tmp.dentry = src_dentry->d_parent;
32817 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32826 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
32829 + struct dentry *d;
32833 + d = path->dentry;
32834 + path->dentry = d->d_parent;
32835 + err = security_path_mkdir(path, d, mode);
32836 + path->dentry = d;
32837 + if (unlikely(err))
32841 + err = vfs_mkdir(dir, path->dentry, mode);
32844 + struct path tmp = *path;
32847 + vfsub_update_h_iattr(&tmp, &did);
32849 + tmp.dentry = path->dentry->d_parent;
32850 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32859 +int vfsub_rmdir(struct inode *dir, struct path *path)
32862 + struct dentry *d;
32866 + d = path->dentry;
32867 + path->dentry = d->d_parent;
32868 + err = security_path_rmdir(path, d);
32869 + path->dentry = d;
32870 + if (unlikely(err))
32874 + err = vfs_rmdir(dir, path->dentry);
32877 + struct path tmp = {
32878 + .dentry = path->dentry->d_parent,
32882 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
32889 +/* ---------------------------------------------------------------------- */
32891 +/* todo: support mmap_sem? */
32892 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
32898 + err = vfs_read(file, ubuf, count, ppos);
32901 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32905 +/* todo: kernel_read()? */
32906 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
32910 + mm_segment_t oldfs;
32917 + oldfs = get_fs();
32918 + set_fs(KERNEL_DS);
32919 + err = vfsub_read_u(file, buf.u, count, ppos);
32924 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
32930 + err = vfs_write(file, ubuf, count, ppos);
32933 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32937 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
32940 + mm_segment_t oldfs;
32943 + const char __user *u;
32947 + oldfs = get_fs();
32948 + set_fs(KERNEL_DS);
32949 + err = vfsub_write_u(file, buf.u, count, ppos);
32954 +int vfsub_flush(struct file *file, fl_owner_t id)
32959 + if (file->f_op->flush) {
32960 + if (!au_test_nfs(file->f_path.dentry->d_sb))
32961 + err = file->f_op->flush(file, id);
32964 + err = file->f_op->flush(file, id);
32968 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
32974 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
32978 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
32981 + err = iterate_dir(file, ctx);
32984 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32989 +long vfsub_splice_to(struct file *in, loff_t *ppos,
32990 + struct pipe_inode_info *pipe, size_t len,
32991 + unsigned int flags)
32996 + err = do_splice_to(in, ppos, pipe, len, flags);
32998 + file_accessed(in);
33000 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33004 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33005 + loff_t *ppos, size_t len, unsigned int flags)
33010 + err = do_splice_from(pipe, out, ppos, len, flags);
33013 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33017 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33021 + /* file can be NULL */
33023 + err = vfs_fsync(file, datasync);
33027 + AuDebugOn(!file);
33028 + path = &file->f_path;
33030 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33035 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33036 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33037 + struct file *h_file)
33040 + struct inode *h_inode;
33041 + struct super_block *h_sb;
33044 + err = vfsub_truncate(h_path, length);
33048 + h_inode = d_inode(h_path->dentry);
33049 + h_sb = h_inode->i_sb;
33051 + sb_start_write(h_sb);
33053 + err = locks_verify_truncate(h_inode, h_file, length);
33055 + err = security_path_truncate(h_path);
33058 + err = do_truncate(h_path->dentry, length, attr, h_file);
33062 + sb_end_write(h_sb);
33069 +/* ---------------------------------------------------------------------- */
33071 +struct au_vfsub_mkdir_args {
33073 + struct inode *dir;
33074 + struct path *path;
33078 +static void au_call_vfsub_mkdir(void *args)
33080 + struct au_vfsub_mkdir_args *a = args;
33081 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33084 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33086 + int err, do_sio, wkq_err;
33088 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33091 + err = vfsub_mkdir(dir, path, mode);
33094 + struct au_vfsub_mkdir_args args = {
33100 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33101 + if (unlikely(wkq_err))
33108 +struct au_vfsub_rmdir_args {
33110 + struct inode *dir;
33111 + struct path *path;
33114 +static void au_call_vfsub_rmdir(void *args)
33116 + struct au_vfsub_rmdir_args *a = args;
33117 + *a->errp = vfsub_rmdir(a->dir, a->path);
33120 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33122 + int err, do_sio, wkq_err;
33124 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33127 + err = vfsub_rmdir(dir, path);
33130 + struct au_vfsub_rmdir_args args = {
33135 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33136 + if (unlikely(wkq_err))
33143 +/* ---------------------------------------------------------------------- */
33145 +struct notify_change_args {
33147 + struct path *path;
33148 + struct iattr *ia;
33149 + struct inode **delegated_inode;
33152 +static void call_notify_change(void *args)
33154 + struct notify_change_args *a = args;
33155 + struct inode *h_inode;
33157 + h_inode = d_inode(a->path->dentry);
33158 + IMustLock(h_inode);
33160 + *a->errp = -EPERM;
33161 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33163 + *a->errp = notify_change(a->path->dentry, a->ia,
33164 + a->delegated_inode);
33167 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33169 + AuTraceErr(*a->errp);
33172 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33173 + struct inode **delegated_inode)
33176 + struct notify_change_args args = {
33180 + .delegated_inode = delegated_inode
33183 + call_notify_change(&args);
33188 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33189 + struct inode **delegated_inode)
33191 + int err, wkq_err;
33192 + struct notify_change_args args = {
33196 + .delegated_inode = delegated_inode
33199 + wkq_err = au_wkq_wait(call_notify_change, &args);
33200 + if (unlikely(wkq_err))
33206 +/* ---------------------------------------------------------------------- */
33208 +struct unlink_args {
33210 + struct inode *dir;
33211 + struct path *path;
33212 + struct inode **delegated_inode;
33215 +static void call_unlink(void *args)
33217 + struct unlink_args *a = args;
33218 + struct dentry *d = a->path->dentry;
33219 + struct inode *h_inode;
33220 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33221 + && au_dcount(d) == 1);
33223 + IMustLock(a->dir);
33225 + a->path->dentry = d->d_parent;
33226 + *a->errp = security_path_unlink(a->path, d);
33227 + a->path->dentry = d;
33228 + if (unlikely(*a->errp))
33231 + if (!stop_sillyrename)
33234 + if (d_is_positive(d)) {
33235 + h_inode = d_inode(d);
33240 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33243 + struct path tmp = {
33244 + .dentry = d->d_parent,
33245 + .mnt = a->path->mnt
33247 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33250 + if (!stop_sillyrename)
33255 + AuTraceErr(*a->errp);
33259 + * @dir: must be locked.
33260 + * @dentry: target dentry.
33262 +int vfsub_unlink(struct inode *dir, struct path *path,
33263 + struct inode **delegated_inode, int force)
33266 + struct unlink_args args = {
33270 + .delegated_inode = delegated_inode
33274 + call_unlink(&args);
33278 + wkq_err = au_wkq_wait(call_unlink, &args);
33279 + if (unlikely(wkq_err))
33285 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33286 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33287 +++ linux/fs/aufs/vfsub.h 2018-06-15 11:15:15.400449109 +0200
33290 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33292 + * This program, aufs is free software; you can redistribute it and/or modify
33293 + * it under the terms of the GNU General Public License as published by
33294 + * the Free Software Foundation; either version 2 of the License, or
33295 + * (at your option) any later version.
33297 + * This program is distributed in the hope that it will be useful,
33298 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33299 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33300 + * GNU General Public License for more details.
33302 + * You should have received a copy of the GNU General Public License
33303 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33307 + * sub-routines for VFS
33310 +#ifndef __AUFS_VFSUB_H__
33311 +#define __AUFS_VFSUB_H__
33315 +#include <linux/fs.h>
33316 +#include <linux/iversion.h>
33317 +#include <linux/mount.h>
33318 +#include <linux/posix_acl.h>
33319 +#include <linux/xattr.h>
33320 +#include "debug.h"
33322 +/* copied from linux/fs/internal.h */
33323 +/* todo: BAD approach!! */
33324 +extern void __mnt_drop_write(struct vfsmount *);
33325 +extern int open_check_o_direct(struct file *f);
33327 +/* ---------------------------------------------------------------------- */
33329 +/* lock subclass for lower inode */
33330 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33331 +/* reduce? gave up. */
33333 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33334 + AuLsc_I_PARENT, /* lower inode, parent first */
33335 + AuLsc_I_PARENT2, /* copyup dirs */
33336 + AuLsc_I_PARENT3, /* copyup wh */
33342 +/* to debug easier, do not make them inlined functions */
33343 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33344 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33346 +/* ---------------------------------------------------------------------- */
33348 +static inline void vfsub_drop_nlink(struct inode *inode)
33350 + AuDebugOn(!inode->i_nlink);
33351 + drop_nlink(inode);
33354 +static inline void vfsub_dead_dir(struct inode *inode)
33356 + AuDebugOn(!S_ISDIR(inode->i_mode));
33357 + inode->i_flags |= S_DEAD;
33358 + clear_nlink(inode);
33361 +static inline int vfsub_native_ro(struct inode *inode)
33363 + return sb_rdonly(inode->i_sb)
33364 + || IS_RDONLY(inode)
33365 + /* || IS_APPEND(inode) */
33366 + || IS_IMMUTABLE(inode);
33369 +#ifdef CONFIG_AUFS_BR_FUSE
33370 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33372 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33375 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33377 +/* ---------------------------------------------------------------------- */
33379 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33380 +struct file *vfsub_dentry_open(struct path *path, int flags);
33381 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33382 +struct vfsub_aopen_args {
33383 + struct file *file;
33384 + unsigned int open_flag;
33385 + umode_t create_mode;
33389 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33390 + struct vfsub_aopen_args *args, struct au_branch *br);
33391 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33393 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33394 + struct dentry *parent, int len);
33395 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33398 +struct vfsub_lkup_one_args {
33399 + struct dentry **errp;
33400 + struct qstr *name;
33401 + struct dentry *parent;
33404 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33405 + struct dentry *parent)
33407 + return vfsub_lookup_one_len(name->name, parent, name->len);
33410 +void vfsub_call_lkup_one(void *args);
33412 +/* ---------------------------------------------------------------------- */
33414 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33419 + err = mnt_want_write(mnt);
33424 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33427 + mnt_drop_write(mnt);
33431 +#if 0 /* reserved */
33432 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33435 + mnt_drop_write_file(file);
33440 +/* ---------------------------------------------------------------------- */
33443 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33444 + struct dentry *d2, struct au_hinode *hdir2);
33445 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33446 + struct dentry *d2, struct au_hinode *hdir2);
33448 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33450 +int vfsub_symlink(struct inode *dir, struct path *path,
33451 + const char *symname);
33452 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33453 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33454 + struct path *path, struct inode **delegated_inode);
33455 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33456 + struct inode *hdir, struct path *path,
33457 + struct inode **delegated_inode, unsigned int flags);
33458 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33459 +int vfsub_rmdir(struct inode *dir, struct path *path);
33461 +/* ---------------------------------------------------------------------- */
33463 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33465 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33467 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33469 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33471 +int vfsub_flush(struct file *file, fl_owner_t id);
33472 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33474 +static inline loff_t vfsub_f_size_read(struct file *file)
33476 + return i_size_read(file_inode(file));
33479 +static inline unsigned int vfsub_file_flags(struct file *file)
33481 + unsigned int flags;
33483 + spin_lock(&file->f_lock);
33484 + flags = file->f_flags;
33485 + spin_unlock(&file->f_lock);
33490 +static inline int vfsub_file_execed(struct file *file)
33492 + /* todo: direct access f_flags */
33493 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33496 +#if 0 /* reserved */
33497 +static inline void vfsub_file_accessed(struct file *h_file)
33499 + file_accessed(h_file);
33500 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33504 +#if 0 /* reserved */
33505 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33506 + struct dentry *h_dentry)
33508 + struct path h_path = {
33509 + .dentry = h_dentry,
33512 + touch_atime(&h_path);
33513 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33517 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
33520 + return update_time(h_inode, ts, flags);
33521 + /* no vfsub_update_h_iattr() since we don't have struct path */
33524 +#ifdef CONFIG_FS_POSIX_ACL
33525 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33529 + err = posix_acl_chmod(h_inode, h_mode);
33530 + if (err == -EOPNOTSUPP)
33535 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33538 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33539 + struct pipe_inode_info *pipe, size_t len,
33540 + unsigned int flags);
33541 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33542 + loff_t *ppos, size_t len, unsigned int flags);
33544 +static inline long vfsub_truncate(struct path *path, loff_t length)
33549 + err = vfs_truncate(path, length);
33554 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33555 + struct file *h_file);
33556 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33559 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33562 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
33568 + err = vfs_clone_file_range(src, 0, dst, 0, len);
33574 +/* copy_file_range(2) is a systemcall */
33575 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33576 + struct file *dst, loff_t dst_pos,
33577 + size_t len, unsigned int flags)
33582 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33588 +/* ---------------------------------------------------------------------- */
33590 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33595 + err = vfs_llseek(file, offset, origin);
33600 +/* ---------------------------------------------------------------------- */
33602 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33603 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33604 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33605 + struct inode **delegated_inode);
33606 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33607 + struct inode **delegated_inode);
33608 +int vfsub_unlink(struct inode *dir, struct path *path,
33609 + struct inode **delegated_inode, int force);
33611 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33613 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33616 +/* ---------------------------------------------------------------------- */
33618 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33619 + const void *value, size_t size, int flags)
33624 + err = vfs_setxattr(dentry, name, value, size, flags);
33630 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33635 + err = vfs_removexattr(dentry, name);
33641 +#endif /* __KERNEL__ */
33642 +#endif /* __AUFS_VFSUB_H__ */
33643 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33644 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33645 +++ linux/fs/aufs/wbr_policy.c 2018-04-15 08:49:13.404484168 +0200
33648 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33650 + * This program, aufs is free software; you can redistribute it and/or modify
33651 + * it under the terms of the GNU General Public License as published by
33652 + * the Free Software Foundation; either version 2 of the License, or
33653 + * (at your option) any later version.
33655 + * This program is distributed in the hope that it will be useful,
33656 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33657 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33658 + * GNU General Public License for more details.
33660 + * You should have received a copy of the GNU General Public License
33661 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33665 + * policies for selecting one among multiple writable branches
33668 +#include <linux/statfs.h>
33671 +/* subset of cpup_attr() */
33672 +static noinline_for_stack
33673 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33677 + struct inode *h_isrc;
33679 + h_isrc = d_inode(h_src);
33680 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33681 + ia.ia_mode = h_isrc->i_mode;
33682 + ia.ia_uid = h_isrc->i_uid;
33683 + ia.ia_gid = h_isrc->i_gid;
33684 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33685 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33686 + /* no delegation since it is just created */
33687 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33689 + /* is this nfs only? */
33690 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33691 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33692 + ia.ia_mode = h_isrc->i_mode;
33693 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33699 +#define AuCpdown_PARENT_OPQ 1
33700 +#define AuCpdown_WHED (1 << 1)
33701 +#define AuCpdown_MADE_DIR (1 << 2)
33702 +#define AuCpdown_DIROPQ (1 << 3)
33703 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33704 +#define au_fset_cpdown(flags, name) \
33705 + do { (flags) |= AuCpdown_##name; } while (0)
33706 +#define au_fclr_cpdown(flags, name) \
33707 + do { (flags) &= ~AuCpdown_##name; } while (0)
33709 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33710 + unsigned int *flags)
33713 + struct dentry *opq_dentry;
33715 + opq_dentry = au_diropq_create(dentry, bdst);
33716 + err = PTR_ERR(opq_dentry);
33717 + if (IS_ERR(opq_dentry))
33719 + dput(opq_dentry);
33720 + au_fset_cpdown(*flags, DIROPQ);
33726 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33727 + struct inode *dir, aufs_bindex_t bdst)
33730 + struct path h_path;
33731 + struct au_branch *br;
33733 + br = au_sbr(dentry->d_sb, bdst);
33734 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33735 + err = PTR_ERR(h_path.dentry);
33736 + if (IS_ERR(h_path.dentry))
33740 + if (d_is_positive(h_path.dentry)) {
33741 + h_path.mnt = au_br_mnt(br);
33742 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33745 + dput(h_path.dentry);
33751 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33752 + struct au_pin *pin,
33753 + struct dentry *h_parent, void *arg)
33756 + aufs_bindex_t bopq, btop;
33757 + struct path h_path;
33758 + struct dentry *parent;
33759 + struct inode *h_dir, *h_inode, *inode, *dir;
33760 + unsigned int *flags = arg;
33762 + btop = au_dbtop(dentry);
33763 + /* dentry is di-locked */
33764 + parent = dget_parent(dentry);
33765 + dir = d_inode(parent);
33766 + h_dir = d_inode(h_parent);
33767 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33768 + IMustLock(h_dir);
33770 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33771 + if (unlikely(err < 0))
33773 + h_path.dentry = au_h_dptr(dentry, bdst);
33774 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33775 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
33776 + S_IRWXU | S_IRUGO | S_IXUGO);
33777 + if (unlikely(err))
33779 + au_fset_cpdown(*flags, MADE_DIR);
33781 + bopq = au_dbdiropq(dentry);
33782 + au_fclr_cpdown(*flags, WHED);
33783 + au_fclr_cpdown(*flags, DIROPQ);
33784 + if (au_dbwh(dentry) == bdst)
33785 + au_fset_cpdown(*flags, WHED);
33786 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33787 + au_fset_cpdown(*flags, PARENT_OPQ);
33788 + h_inode = d_inode(h_path.dentry);
33789 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33790 + if (au_ftest_cpdown(*flags, WHED)) {
33791 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33792 + if (unlikely(err)) {
33793 + inode_unlock(h_inode);
33798 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33799 + inode_unlock(h_inode);
33800 + if (unlikely(err))
33803 + if (au_ftest_cpdown(*flags, WHED)) {
33804 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33805 + if (unlikely(err))
33809 + inode = d_inode(dentry);
33810 + if (au_ibbot(inode) < bdst)
33811 + au_set_ibbot(inode, bdst);
33812 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
33813 + au_hi_flags(inode, /*isdir*/1));
33814 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
33815 + goto out; /* success */
33819 + if (au_ftest_cpdown(*flags, DIROPQ)) {
33820 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33821 + rerr = au_diropq_remove(dentry, bdst);
33822 + inode_unlock(h_inode);
33823 + if (unlikely(rerr)) {
33824 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
33825 + dentry, bdst, rerr);
33831 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
33832 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
33833 + if (unlikely(rerr)) {
33834 + AuIOErr("failed removing %pd b%d (%d)\n",
33835 + dentry, bdst, rerr);
33840 + au_set_h_dptr(dentry, bdst, NULL);
33841 + if (au_dbbot(dentry) == bdst)
33842 + au_update_dbbot(dentry);
33848 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
33851 + unsigned int flags;
33854 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
33859 +/* ---------------------------------------------------------------------- */
33861 +/* policies for create */
33863 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
33865 + int err, i, j, ndentry;
33866 + aufs_bindex_t bopq;
33867 + struct au_dcsub_pages dpages;
33868 + struct au_dpage *dpage;
33869 + struct dentry **dentries, *parent, *d;
33871 + err = au_dpages_init(&dpages, GFP_NOFS);
33872 + if (unlikely(err))
33874 + parent = dget_parent(dentry);
33875 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
33876 + if (unlikely(err))
33880 + for (i = 0; i < dpages.ndpage; i++) {
33881 + dpage = dpages.dpages + i;
33882 + dentries = dpage->dentries;
33883 + ndentry = dpage->ndentry;
33884 + for (j = 0; j < ndentry; j++) {
33886 + di_read_lock_parent2(d, !AuLock_IR);
33887 + bopq = au_dbdiropq(d);
33888 + di_read_unlock(d, !AuLock_IR);
33889 + if (bopq >= 0 && bopq < err)
33896 + au_dpages_free(&dpages);
33901 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
33903 + for (; bindex >= 0; bindex--)
33904 + if (!au_br_rdonly(au_sbr(sb, bindex)))
33909 +/* top down parent */
33910 +static int au_wbr_create_tdp(struct dentry *dentry,
33911 + unsigned int flags __maybe_unused)
33914 + aufs_bindex_t btop, bindex;
33915 + struct super_block *sb;
33916 + struct dentry *parent, *h_parent;
33918 + sb = dentry->d_sb;
33919 + btop = au_dbtop(dentry);
33921 + if (!au_br_rdonly(au_sbr(sb, btop)))
33925 + parent = dget_parent(dentry);
33926 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
33927 + h_parent = au_h_dptr(parent, bindex);
33928 + if (!h_parent || d_is_negative(h_parent))
33931 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
33938 + /* bottom up here */
33939 + if (unlikely(err < 0)) {
33940 + err = au_wbr_bu(sb, btop - 1);
33942 + err = au_wbr_nonopq(dentry, err);
33946 + AuDbg("b%d\n", err);
33950 +/* ---------------------------------------------------------------------- */
33952 +/* an exception for the policy other than tdp */
33953 +static int au_wbr_create_exp(struct dentry *dentry)
33956 + aufs_bindex_t bwh, bdiropq;
33957 + struct dentry *parent;
33960 + bwh = au_dbwh(dentry);
33961 + parent = dget_parent(dentry);
33962 + bdiropq = au_dbdiropq(parent);
33964 + if (bdiropq >= 0)
33965 + err = min(bdiropq, bwh);
33968 + AuDbg("%d\n", err);
33969 + } else if (bdiropq >= 0) {
33971 + AuDbg("%d\n", err);
33976 + err = au_wbr_nonopq(dentry, err);
33978 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
33981 + AuDbg("%d\n", err);
33985 +/* ---------------------------------------------------------------------- */
33988 +static int au_wbr_create_init_rr(struct super_block *sb)
33992 + err = au_wbr_bu(sb, au_sbbot(sb));
33993 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
33996 + AuDbg("b%d\n", err);
34000 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34004 + aufs_bindex_t bindex, bbot;
34005 + struct super_block *sb;
34008 + err = au_wbr_create_exp(dentry);
34012 + sb = dentry->d_sb;
34013 + next = &au_sbi(sb)->si_wbr_rr_next;
34014 + bbot = au_sbbot(sb);
34016 + for (bindex = 0; bindex <= bbot; bindex++) {
34017 + if (!au_ftest_wbr(flags, DIR)) {
34018 + err = atomic_dec_return(next) + 1;
34019 + /* modulo for 0 is meaningless */
34020 + if (unlikely(!err))
34021 + err = atomic_dec_return(next) + 1;
34023 + err = atomic_read(next);
34024 + AuDbg("%d\n", err);
34027 + AuDbg("%d\n", err);
34028 + if (!au_br_rdonly(au_sbr(sb, err)))
34034 + err = au_wbr_nonopq(dentry, err);
34037 + AuDbg("%d\n", err);
34041 +/* ---------------------------------------------------------------------- */
34043 +/* most free space */
34044 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34046 + struct super_block *sb;
34047 + struct au_branch *br;
34048 + struct au_wbr_mfs *mfs;
34049 + struct dentry *h_parent;
34050 + aufs_bindex_t bindex, bbot;
34052 + unsigned long long b, bavail;
34053 + struct path h_path;
34054 + /* reduce the stack usage */
34055 + struct kstatfs *st;
34057 + st = kmalloc(sizeof(*st), GFP_NOFS);
34058 + if (unlikely(!st)) {
34059 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34064 + sb = dentry->d_sb;
34065 + mfs = &au_sbi(sb)->si_wbr_mfs;
34066 + MtxMustLock(&mfs->mfs_lock);
34067 + mfs->mfs_bindex = -EROFS;
34068 + mfs->mfsrr_bytes = 0;
34071 + bbot = au_sbbot(sb);
34073 + bindex = au_dbtop(parent);
34074 + bbot = au_dbtaildir(parent);
34077 + for (; bindex <= bbot; bindex++) {
34079 + h_parent = au_h_dptr(parent, bindex);
34080 + if (!h_parent || d_is_negative(h_parent))
34083 + br = au_sbr(sb, bindex);
34084 + if (au_br_rdonly(br))
34087 + /* sb->s_root for NFS is unreliable */
34088 + h_path.mnt = au_br_mnt(br);
34089 + h_path.dentry = h_path.mnt->mnt_root;
34090 + err = vfs_statfs(&h_path, st);
34091 + if (unlikely(err)) {
34092 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34096 + /* when the available size is equal, select the lower one */
34097 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34098 + || sizeof(b) < sizeof(st->f_bsize));
34099 + b = st->f_bavail * st->f_bsize;
34100 + br->br_wbr->wbr_bytes = b;
34101 + if (b >= bavail) {
34103 + mfs->mfs_bindex = bindex;
34104 + mfs->mfs_jiffy = jiffies;
34108 + mfs->mfsrr_bytes = bavail;
34109 + AuDbg("b%d\n", mfs->mfs_bindex);
34113 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34116 + struct dentry *parent;
34117 + struct super_block *sb;
34118 + struct au_wbr_mfs *mfs;
34120 + err = au_wbr_create_exp(dentry);
34124 + sb = dentry->d_sb;
34126 + if (au_ftest_wbr(flags, PARENT))
34127 + parent = dget_parent(dentry);
34128 + mfs = &au_sbi(sb)->si_wbr_mfs;
34129 + mutex_lock(&mfs->mfs_lock);
34130 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34131 + || mfs->mfs_bindex < 0
34132 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34133 + au_mfs(dentry, parent);
34134 + mutex_unlock(&mfs->mfs_lock);
34135 + err = mfs->mfs_bindex;
34139 + err = au_wbr_nonopq(dentry, err);
34142 + AuDbg("b%d\n", err);
34146 +static int au_wbr_create_init_mfs(struct super_block *sb)
34148 + struct au_wbr_mfs *mfs;
34150 + mfs = &au_sbi(sb)->si_wbr_mfs;
34151 + mutex_init(&mfs->mfs_lock);
34152 + mfs->mfs_jiffy = 0;
34153 + mfs->mfs_bindex = -EROFS;
34158 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34160 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34164 +/* ---------------------------------------------------------------------- */
34166 +/* top down regardless parent, and then mfs */
34167 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34168 + unsigned int flags __maybe_unused)
34171 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34172 + unsigned long long watermark;
34173 + struct super_block *sb;
34174 + struct au_wbr_mfs *mfs;
34175 + struct au_branch *br;
34176 + struct dentry *parent;
34178 + sb = dentry->d_sb;
34179 + mfs = &au_sbi(sb)->si_wbr_mfs;
34180 + mutex_lock(&mfs->mfs_lock);
34181 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34182 + || mfs->mfs_bindex < 0)
34183 + au_mfs(dentry, /*parent*/NULL);
34184 + watermark = mfs->mfsrr_watermark;
34185 + bmfs = mfs->mfs_bindex;
34186 + mutex_unlock(&mfs->mfs_lock);
34188 + /* another style of au_wbr_create_exp() */
34189 + bwh = au_dbwh(dentry);
34190 + parent = dget_parent(dentry);
34191 + btail = au_dbtaildir(parent);
34192 + if (bwh >= 0 && bwh < btail)
34195 + err = au_wbr_nonopq(dentry, btail);
34196 + if (unlikely(err < 0))
34200 + for (bindex = 0; bindex <= btail; bindex++) {
34201 + br = au_sbr(sb, bindex);
34202 + if (au_br_rdonly(br))
34204 + if (br->br_wbr->wbr_bytes > watermark) {
34215 + AuDbg("b%d\n", err);
34219 +/* ---------------------------------------------------------------------- */
34221 +/* most free space and then round robin */
34222 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34225 + struct au_wbr_mfs *mfs;
34227 + err = au_wbr_create_mfs(dentry, flags);
34229 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34230 + mutex_lock(&mfs->mfs_lock);
34231 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34232 + err = au_wbr_create_rr(dentry, flags);
34233 + mutex_unlock(&mfs->mfs_lock);
34236 + AuDbg("b%d\n", err);
34240 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34244 + au_wbr_create_init_mfs(sb); /* ignore */
34245 + err = au_wbr_create_init_rr(sb);
34250 +/* ---------------------------------------------------------------------- */
34252 +/* top down parent and most free space */
34253 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34256 + unsigned long long b;
34257 + aufs_bindex_t bindex, btop, bbot;
34258 + struct super_block *sb;
34259 + struct dentry *parent, *h_parent;
34260 + struct au_branch *br;
34262 + err = au_wbr_create_tdp(dentry, flags);
34263 + if (unlikely(err < 0))
34265 + parent = dget_parent(dentry);
34266 + btop = au_dbtop(parent);
34267 + bbot = au_dbtaildir(parent);
34268 + if (btop == bbot)
34269 + goto out_parent; /* success */
34271 + e2 = au_wbr_create_mfs(dentry, flags);
34273 + goto out_parent; /* success */
34275 + /* when the available size is equal, select upper one */
34276 + sb = dentry->d_sb;
34277 + br = au_sbr(sb, err);
34278 + b = br->br_wbr->wbr_bytes;
34279 + AuDbg("b%d, %llu\n", err, b);
34281 + for (bindex = btop; bindex <= bbot; bindex++) {
34282 + h_parent = au_h_dptr(parent, bindex);
34283 + if (!h_parent || d_is_negative(h_parent))
34286 + br = au_sbr(sb, bindex);
34287 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34288 + b = br->br_wbr->wbr_bytes;
34290 + AuDbg("b%d, %llu\n", err, b);
34295 + err = au_wbr_nonopq(dentry, err);
34300 + AuDbg("b%d\n", err);
34304 +/* ---------------------------------------------------------------------- */
34307 + * - top down parent
34308 + * - most free space with parent
34309 + * - most free space round-robin regardless parent
34311 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34314 + unsigned long long watermark;
34315 + struct super_block *sb;
34316 + struct au_branch *br;
34317 + struct au_wbr_mfs *mfs;
34319 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34320 + if (unlikely(err < 0))
34323 + sb = dentry->d_sb;
34324 + br = au_sbr(sb, err);
34325 + mfs = &au_sbi(sb)->si_wbr_mfs;
34326 + mutex_lock(&mfs->mfs_lock);
34327 + watermark = mfs->mfsrr_watermark;
34328 + mutex_unlock(&mfs->mfs_lock);
34329 + if (br->br_wbr->wbr_bytes < watermark)
34330 + /* regardless the parent dir */
34331 + err = au_wbr_create_mfsrr(dentry, flags);
34334 + AuDbg("b%d\n", err);
34338 +/* ---------------------------------------------------------------------- */
34340 +/* policies for copyup */
34342 +/* top down parent */
34343 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34345 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34348 +/* bottom up parent */
34349 +static int au_wbr_copyup_bup(struct dentry *dentry)
34352 + aufs_bindex_t bindex, btop;
34353 + struct dentry *parent, *h_parent;
34354 + struct super_block *sb;
34357 + sb = dentry->d_sb;
34358 + parent = dget_parent(dentry);
34359 + btop = au_dbtop(parent);
34360 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34361 + h_parent = au_h_dptr(parent, bindex);
34362 + if (!h_parent || d_is_negative(h_parent))
34365 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34372 + /* bottom up here */
34373 + if (unlikely(err < 0))
34374 + err = au_wbr_bu(sb, btop - 1);
34376 + AuDbg("b%d\n", err);
34381 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34385 + err = au_wbr_bu(dentry->d_sb, btop);
34386 + AuDbg("b%d\n", err);
34388 + err = au_wbr_nonopq(dentry, err);
34390 + AuDbg("b%d\n", err);
34394 +static int au_wbr_copyup_bu(struct dentry *dentry)
34397 + aufs_bindex_t btop;
34399 + btop = au_dbtop(dentry);
34400 + err = au_wbr_do_copyup_bu(dentry, btop);
34404 +/* ---------------------------------------------------------------------- */
34406 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34407 + [AuWbrCopyup_TDP] = {
34408 + .copyup = au_wbr_copyup_tdp
34410 + [AuWbrCopyup_BUP] = {
34411 + .copyup = au_wbr_copyup_bup
34413 + [AuWbrCopyup_BU] = {
34414 + .copyup = au_wbr_copyup_bu
34418 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34419 + [AuWbrCreate_TDP] = {
34420 + .create = au_wbr_create_tdp
34422 + [AuWbrCreate_RR] = {
34423 + .create = au_wbr_create_rr,
34424 + .init = au_wbr_create_init_rr
34426 + [AuWbrCreate_MFS] = {
34427 + .create = au_wbr_create_mfs,
34428 + .init = au_wbr_create_init_mfs,
34429 + .fin = au_wbr_create_fin_mfs
34431 + [AuWbrCreate_MFSV] = {
34432 + .create = au_wbr_create_mfs,
34433 + .init = au_wbr_create_init_mfs,
34434 + .fin = au_wbr_create_fin_mfs
34436 + [AuWbrCreate_MFSRR] = {
34437 + .create = au_wbr_create_mfsrr,
34438 + .init = au_wbr_create_init_mfsrr,
34439 + .fin = au_wbr_create_fin_mfs
34441 + [AuWbrCreate_MFSRRV] = {
34442 + .create = au_wbr_create_mfsrr,
34443 + .init = au_wbr_create_init_mfsrr,
34444 + .fin = au_wbr_create_fin_mfs
34446 + [AuWbrCreate_TDMFS] = {
34447 + .create = au_wbr_create_tdmfs,
34448 + .init = au_wbr_create_init_mfs,
34449 + .fin = au_wbr_create_fin_mfs
34451 + [AuWbrCreate_TDMFSV] = {
34452 + .create = au_wbr_create_tdmfs,
34453 + .init = au_wbr_create_init_mfs,
34454 + .fin = au_wbr_create_fin_mfs
34456 + [AuWbrCreate_PMFS] = {
34457 + .create = au_wbr_create_pmfs,
34458 + .init = au_wbr_create_init_mfs,
34459 + .fin = au_wbr_create_fin_mfs
34461 + [AuWbrCreate_PMFSV] = {
34462 + .create = au_wbr_create_pmfs,
34463 + .init = au_wbr_create_init_mfs,
34464 + .fin = au_wbr_create_fin_mfs
34466 + [AuWbrCreate_PMFSRR] = {
34467 + .create = au_wbr_create_pmfsrr,
34468 + .init = au_wbr_create_init_mfsrr,
34469 + .fin = au_wbr_create_fin_mfs
34471 + [AuWbrCreate_PMFSRRV] = {
34472 + .create = au_wbr_create_pmfsrr,
34473 + .init = au_wbr_create_init_mfsrr,
34474 + .fin = au_wbr_create_fin_mfs
34477 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34478 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34479 +++ linux/fs/aufs/whout.c 2018-04-15 08:49:13.404484168 +0200
34482 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34484 + * This program, aufs is free software; you can redistribute it and/or modify
34485 + * it under the terms of the GNU General Public License as published by
34486 + * the Free Software Foundation; either version 2 of the License, or
34487 + * (at your option) any later version.
34489 + * This program is distributed in the hope that it will be useful,
34490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34492 + * GNU General Public License for more details.
34494 + * You should have received a copy of the GNU General Public License
34495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34499 + * whiteout for logical deletion and opaque directory
34504 +#define WH_MASK S_IRUGO
34507 + * If a directory contains this file, then it is opaque. We start with the
34508 + * .wh. flag so that it is blocked by lookup.
34510 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34511 + sizeof(AUFS_WH_DIROPQ) - 1);
34514 + * generate whiteout name, which is NOT terminated by NULL.
34515 + * @name: original d_name.name
34516 + * @len: original d_name.len
34517 + * @wh: whiteout qstr
34518 + * returns zero when succeeds, otherwise error.
34519 + * succeeded value as wh->name should be freed by kfree().
34521 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34525 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34526 + return -ENAMETOOLONG;
34528 + wh->len = name->len + AUFS_WH_PFX_LEN;
34529 + p = kmalloc(wh->len, GFP_NOFS);
34532 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34533 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34540 +/* ---------------------------------------------------------------------- */
34543 + * test if the @wh_name exists under @h_parent.
34544 + * @try_sio specifies the necessary of super-io.
34546 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34549 + struct dentry *wh_dentry;
34552 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34554 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34555 + err = PTR_ERR(wh_dentry);
34556 + if (IS_ERR(wh_dentry)) {
34557 + if (err == -ENAMETOOLONG)
34563 + if (d_is_negative(wh_dentry))
34564 + goto out_wh; /* success */
34567 + if (d_is_reg(wh_dentry))
34568 + goto out_wh; /* success */
34571 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34572 + wh_dentry, d_inode(wh_dentry)->i_mode);
34581 + * test if the @h_dentry sets opaque or not.
34583 +int au_diropq_test(struct dentry *h_dentry)
34586 + struct inode *h_dir;
34588 + h_dir = d_inode(h_dentry);
34589 + err = au_wh_test(h_dentry, &diropq_name,
34590 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34595 + * returns a negative dentry whose name is unique and temporary.
34597 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34598 + struct qstr *prefix)
34600 + struct dentry *dentry;
34602 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34604 + /* strict atomic_t is unnecessary here */
34605 + static unsigned short cnt;
34608 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34611 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34612 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34613 + dentry = ERR_PTR(-ENAMETOOLONG);
34614 + if (unlikely(qs.len > NAME_MAX))
34616 + dentry = ERR_PTR(-ENOMEM);
34617 + name = kmalloc(qs.len + 1, GFP_NOFS);
34618 + if (unlikely(!name))
34622 + /* doubly whiteout-ed */
34623 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34624 + p = name + AUFS_WH_PFX_LEN * 2;
34625 + memcpy(p, prefix->name, prefix->len);
34626 + p += prefix->len;
34628 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34631 + for (i = 0; i < 3; i++) {
34632 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34633 + dentry = au_sio_lkup_one(&qs, h_parent);
34634 + if (IS_ERR(dentry) || d_is_negative(dentry))
34638 + /* pr_warn("could not get random name\n"); */
34639 + dentry = ERR_PTR(-EEXIST);
34640 + AuDbg("%.*s\n", AuLNPair(&qs));
34644 + if (name != defname)
34647 + AuTraceErrPtr(dentry);
34652 + * rename the @h_dentry on @br to the whiteouted temporary name.
34654 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34657 + struct path h_path = {
34658 + .mnt = au_br_mnt(br)
34660 + struct inode *h_dir, *delegated;
34661 + struct dentry *h_parent;
34663 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34664 + h_dir = d_inode(h_parent);
34665 + IMustLock(h_dir);
34667 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34668 + err = PTR_ERR(h_path.dentry);
34669 + if (IS_ERR(h_path.dentry))
34672 + /* under the same dir, no need to lock_rename() */
34673 + delegated = NULL;
34674 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34677 + if (unlikely(err == -EWOULDBLOCK)) {
34678 + pr_warn("cannot retry for NFSv4 delegation"
34679 + " for an internal rename\n");
34682 + dput(h_path.dentry);
34689 +/* ---------------------------------------------------------------------- */
34691 + * functions for removing a whiteout
34694 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34697 + struct inode *delegated;
34700 + * forces superio when the dir has a sticky bit.
34701 + * this may be a violation of unix fs semantics.
34703 + force = (h_dir->i_mode & S_ISVTX)
34704 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34705 + delegated = NULL;
34706 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34707 + if (unlikely(err == -EWOULDBLOCK)) {
34708 + pr_warn("cannot retry for NFSv4 delegation"
34709 + " for an internal unlink\n");
34715 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34716 + struct dentry *dentry)
34720 + err = do_unlink_wh(h_dir, h_path);
34721 + if (!err && dentry)
34722 + au_set_dbwh(dentry, -1);
34727 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34728 + struct au_branch *br)
34731 + struct path h_path = {
34732 + .mnt = au_br_mnt(br)
34736 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34737 + if (IS_ERR(h_path.dentry))
34738 + err = PTR_ERR(h_path.dentry);
34740 + if (d_is_reg(h_path.dentry))
34741 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34742 + dput(h_path.dentry);
34748 +/* ---------------------------------------------------------------------- */
34750 + * initialize/clean whiteout for a branch
34753 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34757 + struct inode *delegated;
34759 + if (d_is_negative(whpath->dentry))
34763 + err = vfsub_rmdir(h_dir, whpath);
34765 + delegated = NULL;
34766 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34767 + if (unlikely(err == -EWOULDBLOCK)) {
34768 + pr_warn("cannot retry for NFSv4 delegation"
34769 + " for an internal unlink\n");
34773 + if (unlikely(err))
34774 + pr_warn("failed removing %pd (%d), ignored.\n",
34775 + whpath->dentry, err);
34778 +static int test_linkable(struct dentry *h_root)
34780 + struct inode *h_dir = d_inode(h_root);
34782 + if (h_dir->i_op->link)
34785 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34786 + h_root, au_sbtype(h_root->d_sb));
34790 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34791 +static int au_whdir(struct inode *h_dir, struct path *path)
34796 + if (d_is_negative(path->dentry)) {
34797 + int mode = S_IRWXU;
34799 + if (au_test_nfs(path->dentry->d_sb))
34801 + err = vfsub_mkdir(h_dir, path, mode);
34802 + } else if (d_is_dir(path->dentry))
34805 + pr_err("unknown %pd exists\n", path->dentry);
34810 +struct au_wh_base {
34811 + const struct qstr *name;
34812 + struct dentry *dentry;
34815 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
34816 + struct path *h_path)
34818 + h_path->dentry = base[AuBrWh_BASE].dentry;
34819 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34820 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34821 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34822 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34823 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34827 + * returns tri-state,
34828 + * minus: error, caller should print the message
34830 + * plus: error, caller should NOT print the message
34832 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
34833 + int do_plink, struct au_wh_base base[],
34834 + struct path *h_path)
34837 + struct inode *h_dir;
34839 + h_dir = d_inode(h_root);
34840 + h_path->dentry = base[AuBrWh_BASE].dentry;
34841 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34842 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34844 + err = test_linkable(h_root);
34845 + if (unlikely(err)) {
34850 + err = au_whdir(h_dir, h_path);
34851 + if (unlikely(err))
34853 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34855 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34856 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34857 + err = au_whdir(h_dir, h_path);
34858 + if (unlikely(err))
34860 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34867 + * for the moment, aufs supports the branch filesystem which does not support
34868 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
34869 + * copyup failed. finally, such filesystem will not be used as the writable
34872 + * returns tri-state, see above.
34874 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
34875 + int do_plink, struct au_wh_base base[],
34876 + struct path *h_path)
34879 + struct inode *h_dir;
34881 + WbrWhMustWriteLock(wbr);
34883 + err = test_linkable(h_root);
34884 + if (unlikely(err)) {
34890 + * todo: should this create be done in /sbin/mount.aufs helper?
34893 + h_dir = d_inode(h_root);
34894 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
34895 + h_path->dentry = base[AuBrWh_BASE].dentry;
34896 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
34897 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
34900 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
34901 + if (unlikely(err))
34904 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34906 + err = au_whdir(h_dir, h_path);
34907 + if (unlikely(err))
34909 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34911 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34912 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
34914 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34915 + err = au_whdir(h_dir, h_path);
34916 + if (unlikely(err))
34918 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34925 + * initialize the whiteout base file/dir for @br.
34927 +int au_wh_init(struct au_branch *br, struct super_block *sb)
34930 + const unsigned char do_plink
34931 + = !!au_opt_test(au_mntflags(sb), PLINK);
34932 + struct inode *h_dir;
34933 + struct path path = br->br_path;
34934 + struct dentry *h_root = path.dentry;
34935 + struct au_wbr *wbr = br->br_wbr;
34936 + static const struct qstr base_name[] = {
34937 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
34938 + sizeof(AUFS_BASE_NAME) - 1),
34939 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
34940 + sizeof(AUFS_PLINKDIR_NAME) - 1),
34941 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
34942 + sizeof(AUFS_ORPHDIR_NAME) - 1)
34944 + struct au_wh_base base[] = {
34945 + [AuBrWh_BASE] = {
34946 + .name = base_name + AuBrWh_BASE,
34949 + [AuBrWh_PLINK] = {
34950 + .name = base_name + AuBrWh_PLINK,
34953 + [AuBrWh_ORPH] = {
34954 + .name = base_name + AuBrWh_ORPH,
34960 + WbrWhMustWriteLock(wbr);
34962 + for (i = 0; i < AuBrWh_Last; i++) {
34963 + /* doubly whiteouted */
34964 + struct dentry *d;
34966 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
34967 + err = PTR_ERR(d);
34971 + base[i].dentry = d;
34973 + && wbr->wbr_wh[i]
34974 + && wbr->wbr_wh[i] != base[i].dentry);
34978 + for (i = 0; i < AuBrWh_Last; i++) {
34979 + dput(wbr->wbr_wh[i]);
34980 + wbr->wbr_wh[i] = NULL;
34984 + if (!au_br_writable(br->br_perm)) {
34985 + h_dir = d_inode(h_root);
34986 + au_wh_init_ro(h_dir, base, &path);
34987 + } else if (!au_br_wh_linkable(br->br_perm)) {
34988 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
34994 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35000 + goto out; /* success */
35003 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35004 + err, h_root, au_sbtype(h_root->d_sb));
35006 + for (i = 0; i < AuBrWh_Last; i++)
35007 + dput(base[i].dentry);
35011 +/* ---------------------------------------------------------------------- */
35013 + * whiteouts are all hard-linked usually.
35014 + * when its link count reaches a ceiling, we create a new whiteout base
35015 + * asynchronously.
35018 +struct reinit_br_wh {
35019 + struct super_block *sb;
35020 + struct au_branch *br;
35023 +static void reinit_br_wh(void *arg)
35026 + aufs_bindex_t bindex;
35027 + struct path h_path;
35028 + struct reinit_br_wh *a = arg;
35029 + struct au_wbr *wbr;
35030 + struct inode *dir, *delegated;
35031 + struct dentry *h_root;
35032 + struct au_hinode *hdir;
35035 + wbr = a->br->br_wbr;
35036 + /* big aufs lock */
35037 + si_noflush_write_lock(a->sb);
35038 + if (!au_br_writable(a->br->br_perm))
35040 + bindex = au_br_index(a->sb, a->br->br_id);
35041 + if (unlikely(bindex < 0))
35044 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35045 + dir = d_inode(a->sb->s_root);
35046 + hdir = au_hi(dir, bindex);
35047 + h_root = au_h_dptr(a->sb->s_root, bindex);
35048 + AuDebugOn(h_root != au_br_dentry(a->br));
35050 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35051 + wbr_wh_write_lock(wbr);
35052 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35055 + h_path.dentry = wbr->wbr_whbase;
35056 + h_path.mnt = au_br_mnt(a->br);
35057 + delegated = NULL;
35058 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35060 + if (unlikely(err == -EWOULDBLOCK)) {
35061 + pr_warn("cannot retry for NFSv4 delegation"
35062 + " for an internal unlink\n");
35066 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35069 + dput(wbr->wbr_whbase);
35070 + wbr->wbr_whbase = NULL;
35072 + err = au_wh_init(a->br, a->sb);
35073 + wbr_wh_write_unlock(wbr);
35074 + au_hn_inode_unlock(hdir);
35075 + di_read_unlock(a->sb->s_root, AuLock_IR);
35077 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35081 + atomic_dec(&wbr->wbr_wh_running);
35082 + au_br_put(a->br);
35083 + si_write_unlock(a->sb);
35084 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35086 + if (unlikely(err))
35087 + AuIOErr("err %d\n", err);
35090 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35092 + int do_dec, wkq_err;
35093 + struct reinit_br_wh *arg;
35096 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35099 + /* ignore ENOMEM */
35100 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35103 + * dec(wh_running), kfree(arg) and dec(br_count)
35104 + * in reinit function
35109 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35110 + if (unlikely(wkq_err)) {
35111 + atomic_dec(&br->br_wbr->wbr_wh_running);
35120 + atomic_dec(&br->br_wbr->wbr_wh_running);
35123 +/* ---------------------------------------------------------------------- */
35126 + * create the whiteout @wh.
35128 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35129 + struct dentry *wh)
35132 + struct path h_path = {
35135 + struct au_branch *br;
35136 + struct au_wbr *wbr;
35137 + struct dentry *h_parent;
35138 + struct inode *h_dir, *delegated;
35140 + h_parent = wh->d_parent; /* dir inode is locked */
35141 + h_dir = d_inode(h_parent);
35142 + IMustLock(h_dir);
35144 + br = au_sbr(sb, bindex);
35145 + h_path.mnt = au_br_mnt(br);
35146 + wbr = br->br_wbr;
35147 + wbr_wh_read_lock(wbr);
35148 + if (wbr->wbr_whbase) {
35149 + delegated = NULL;
35150 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35151 + if (unlikely(err == -EWOULDBLOCK)) {
35152 + pr_warn("cannot retry for NFSv4 delegation"
35153 + " for an internal link\n");
35156 + if (!err || err != -EMLINK)
35159 + /* link count full. re-initialize br_whbase. */
35160 + kick_reinit_br_wh(sb, br);
35163 + /* return this error in this context */
35164 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35166 + au_fhsm_wrote(sb, bindex, /*force*/0);
35169 + wbr_wh_read_unlock(wbr);
35173 +/* ---------------------------------------------------------------------- */
35176 + * create or remove the diropq.
35178 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35179 + unsigned int flags)
35181 + struct dentry *opq_dentry, *h_dentry;
35182 + struct super_block *sb;
35183 + struct au_branch *br;
35186 + sb = dentry->d_sb;
35187 + br = au_sbr(sb, bindex);
35188 + h_dentry = au_h_dptr(dentry, bindex);
35189 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35190 + if (IS_ERR(opq_dentry))
35193 + if (au_ftest_diropq(flags, CREATE)) {
35194 + err = link_or_create_wh(sb, bindex, opq_dentry);
35196 + au_set_dbdiropq(dentry, bindex);
35197 + goto out; /* success */
35200 + struct path tmp = {
35201 + .dentry = opq_dentry,
35202 + .mnt = au_br_mnt(br)
35204 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35206 + au_set_dbdiropq(dentry, -1);
35208 + dput(opq_dentry);
35209 + opq_dentry = ERR_PTR(err);
35212 + return opq_dentry;
35215 +struct do_diropq_args {
35216 + struct dentry **errp;
35217 + struct dentry *dentry;
35218 + aufs_bindex_t bindex;
35219 + unsigned int flags;
35222 +static void call_do_diropq(void *args)
35224 + struct do_diropq_args *a = args;
35225 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35228 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35229 + unsigned int flags)
35231 + struct dentry *diropq, *h_dentry;
35233 + h_dentry = au_h_dptr(dentry, bindex);
35234 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35235 + diropq = do_diropq(dentry, bindex, flags);
35238 + struct do_diropq_args args = {
35240 + .dentry = dentry,
35241 + .bindex = bindex,
35245 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35246 + if (unlikely(wkq_err))
35247 + diropq = ERR_PTR(wkq_err);
35253 +/* ---------------------------------------------------------------------- */
35256 + * lookup whiteout dentry.
35257 + * @h_parent: lower parent dentry which must exist and be locked
35258 + * @base_name: name of dentry which will be whiteouted
35259 + * returns dentry for whiteout.
35261 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35262 + struct au_branch *br)
35265 + struct qstr wh_name;
35266 + struct dentry *wh_dentry;
35268 + err = au_wh_name_alloc(&wh_name, base_name);
35269 + wh_dentry = ERR_PTR(err);
35271 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35272 + kfree(wh_name.name);
35274 + return wh_dentry;
35278 + * link/create a whiteout for @dentry on @bindex.
35280 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35281 + struct dentry *h_parent)
35283 + struct dentry *wh_dentry;
35284 + struct super_block *sb;
35287 + sb = dentry->d_sb;
35288 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35289 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35290 + err = link_or_create_wh(sb, bindex, wh_dentry);
35292 + au_set_dbwh(dentry, bindex);
35293 + au_fhsm_wrote(sb, bindex, /*force*/0);
35296 + wh_dentry = ERR_PTR(err);
35300 + return wh_dentry;
35303 +/* ---------------------------------------------------------------------- */
35305 +/* Delete all whiteouts in this directory on branch bindex. */
35306 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35307 + aufs_bindex_t bindex, struct au_branch *br)
35310 + unsigned long ul, n;
35311 + struct qstr wh_name;
35313 + struct hlist_head *head;
35314 + struct au_vdir_wh *pos;
35315 + struct au_vdir_destr *str;
35318 + p = (void *)__get_free_page(GFP_NOFS);
35319 + wh_name.name = p;
35320 + if (unlikely(!wh_name.name))
35324 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35325 + p += AUFS_WH_PFX_LEN;
35326 + n = whlist->nh_num;
35327 + head = whlist->nh_head;
35328 + for (ul = 0; !err && ul < n; ul++, head++) {
35329 + hlist_for_each_entry(pos, head, wh_hash) {
35330 + if (pos->wh_bindex != bindex)
35333 + str = &pos->wh_str;
35334 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35335 + memcpy(p, str->name, str->len);
35336 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35337 + err = unlink_wh_name(h_dentry, &wh_name, br);
35342 + AuIOErr("whiteout name too long %.*s\n",
35343 + str->len, str->name);
35348 + free_page((unsigned long)wh_name.name);
35354 +struct del_wh_children_args {
35356 + struct dentry *h_dentry;
35357 + struct au_nhash *whlist;
35358 + aufs_bindex_t bindex;
35359 + struct au_branch *br;
35362 +static void call_del_wh_children(void *args)
35364 + struct del_wh_children_args *a = args;
35365 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35368 +/* ---------------------------------------------------------------------- */
35370 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35372 + struct au_whtmp_rmdir *whtmp;
35374 + unsigned int rdhash;
35376 + SiMustAnyLock(sb);
35378 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35379 + if (unlikely(!whtmp)) {
35380 + whtmp = ERR_PTR(-ENOMEM);
35384 + /* no estimation for dir size */
35385 + rdhash = au_sbi(sb)->si_rdhash;
35387 + rdhash = AUFS_RDHASH_DEF;
35388 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35389 + if (unlikely(err)) {
35391 + whtmp = ERR_PTR(err);
35398 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35401 + au_br_put(whtmp->br);
35402 + dput(whtmp->wh_dentry);
35403 + iput(whtmp->dir);
35404 + au_nhash_wh_free(&whtmp->whlist);
35409 + * rmdir the whiteouted temporary named dir @h_dentry.
35410 + * @whlist: whiteouted children.
35412 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35413 + struct dentry *wh_dentry, struct au_nhash *whlist)
35416 + unsigned int h_nlink;
35417 + struct path h_tmp;
35418 + struct inode *wh_inode, *h_dir;
35419 + struct au_branch *br;
35421 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35422 + IMustLock(h_dir);
35424 + br = au_sbr(dir->i_sb, bindex);
35425 + wh_inode = d_inode(wh_dentry);
35426 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35429 + * someone else might change some whiteouts while we were sleeping.
35430 + * it means this whlist may have an obsoleted entry.
35432 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35433 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35436 + struct del_wh_children_args args = {
35438 + .h_dentry = wh_dentry,
35439 + .whlist = whlist,
35440 + .bindex = bindex,
35444 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35445 + if (unlikely(wkq_err))
35448 + inode_unlock(wh_inode);
35451 + h_tmp.dentry = wh_dentry;
35452 + h_tmp.mnt = au_br_mnt(br);
35453 + h_nlink = h_dir->i_nlink;
35454 + err = vfsub_rmdir(h_dir, &h_tmp);
35455 + /* some fs doesn't change the parent nlink in some cases */
35456 + h_nlink -= h_dir->i_nlink;
35460 + if (au_ibtop(dir) == bindex) {
35461 + /* todo: dir->i_mutex is necessary */
35462 + au_cpup_attr_timesizes(dir);
35464 + vfsub_drop_nlink(dir);
35466 + return 0; /* success */
35469 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35473 +static void call_rmdir_whtmp(void *args)
35476 + aufs_bindex_t bindex;
35477 + struct au_whtmp_rmdir *a = args;
35478 + struct super_block *sb;
35479 + struct dentry *h_parent;
35480 + struct inode *h_dir;
35481 + struct au_hinode *hdir;
35483 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35484 + /* inode_lock(a->dir); */
35486 + sb = a->dir->i_sb;
35487 + si_read_lock(sb, !AuLock_FLUSH);
35488 + if (!au_br_writable(a->br->br_perm))
35490 + bindex = au_br_index(sb, a->br->br_id);
35491 + if (unlikely(bindex < 0))
35495 + ii_write_lock_parent(a->dir);
35496 + h_parent = dget_parent(a->wh_dentry);
35497 + h_dir = d_inode(h_parent);
35498 + hdir = au_hi(a->dir, bindex);
35499 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35500 + if (unlikely(err))
35502 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35503 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35506 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35507 + au_hn_inode_unlock(hdir);
35508 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35512 + ii_write_unlock(a->dir);
35514 + /* inode_unlock(a->dir); */
35515 + au_whtmp_rmdir_free(a);
35516 + si_read_unlock(sb);
35517 + au_nwt_done(&au_sbi(sb)->si_nowait);
35518 + if (unlikely(err))
35519 + AuIOErr("err %d\n", err);
35522 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35523 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35526 + struct super_block *sb;
35530 + /* all post-process will be done in do_rmdir_whtmp(). */
35532 + args->dir = au_igrab(dir);
35533 + args->br = au_sbr(sb, bindex);
35534 + au_br_get(args->br);
35535 + args->wh_dentry = dget(wh_dentry);
35536 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35537 + if (unlikely(wkq_err)) {
35538 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35539 + au_whtmp_rmdir_free(args);
35542 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35543 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35544 +++ linux/fs/aufs/whout.h 2018-04-15 08:49:13.404484168 +0200
35547 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35549 + * This program, aufs is free software; you can redistribute it and/or modify
35550 + * it under the terms of the GNU General Public License as published by
35551 + * the Free Software Foundation; either version 2 of the License, or
35552 + * (at your option) any later version.
35554 + * This program is distributed in the hope that it will be useful,
35555 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35556 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35557 + * GNU General Public License for more details.
35559 + * You should have received a copy of the GNU General Public License
35560 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35564 + * whiteout for logical deletion and opaque directory
35567 +#ifndef __AUFS_WHOUT_H__
35568 +#define __AUFS_WHOUT_H__
35575 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35576 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35577 +int au_diropq_test(struct dentry *h_dentry);
35579 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35580 + struct qstr *prefix);
35581 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35582 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35583 + struct dentry *dentry);
35584 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35586 +/* diropq flags */
35587 +#define AuDiropq_CREATE 1
35588 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35589 +#define au_fset_diropq(flags, name) \
35590 + do { (flags) |= AuDiropq_##name; } while (0)
35591 +#define au_fclr_diropq(flags, name) \
35592 + do { (flags) &= ~AuDiropq_##name; } while (0)
35594 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35595 + unsigned int flags);
35596 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35597 + struct au_branch *br);
35598 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35599 + struct dentry *h_parent);
35601 +/* real rmdir for the whiteout-ed dir */
35602 +struct au_whtmp_rmdir {
35603 + struct inode *dir;
35604 + struct au_branch *br;
35605 + struct dentry *wh_dentry;
35606 + struct au_nhash whlist;
35609 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35610 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35611 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35612 + struct dentry *wh_dentry, struct au_nhash *whlist);
35613 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35614 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35616 +/* ---------------------------------------------------------------------- */
35618 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35619 + aufs_bindex_t bindex)
35621 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35624 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35626 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35629 +#endif /* __KERNEL__ */
35630 +#endif /* __AUFS_WHOUT_H__ */
35631 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35632 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35633 +++ linux/fs/aufs/wkq.c 2018-06-04 09:08:09.188079511 +0200
35636 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35638 + * This program, aufs is free software; you can redistribute it and/or modify
35639 + * it under the terms of the GNU General Public License as published by
35640 + * the Free Software Foundation; either version 2 of the License, or
35641 + * (at your option) any later version.
35643 + * This program is distributed in the hope that it will be useful,
35644 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35645 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35646 + * GNU General Public License for more details.
35648 + * You should have received a copy of the GNU General Public License
35649 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35653 + * workqueue for asynchronous/super-io operations
35654 + * todo: try new dredential scheme
35657 +#include <linux/module.h>
35660 +/* internal workqueue named AUFS_WKQ_NAME */
35662 +static struct workqueue_struct *au_wkq;
35664 +struct au_wkinfo {
35665 + struct work_struct wk;
35666 + struct kobject *kobj;
35668 + unsigned int flags; /* see wkq.h */
35670 + au_wkq_func_t func;
35673 +#ifdef CONFIG_LOCKDEP
35675 + struct held_lock **hlock;
35678 + struct completion *comp;
35681 +/* ---------------------------------------------------------------------- */
35683 + * Aufs passes some operations to the workqueue such as the internal copyup.
35684 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35685 + * job run by workqueue depends upon the locks acquired in the other task.
35686 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35687 + * information too. And the job in the workqueue restores the info in order to
35688 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35689 + * correctly and expectedly.
35692 +#ifndef CONFIG_LOCKDEP
35693 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35694 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35695 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35696 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35697 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35699 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35701 + wkinfo->hlock = NULL;
35702 + wkinfo->dont_check = 0;
35709 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35711 + static DEFINE_SPINLOCK(spin);
35714 + struct lock_class_key *key;
35716 + { .name = "&sbinfo->si_rwsem" },
35717 + { .name = "&finfo->fi_rwsem" },
35718 + { .name = "&dinfo->di_rwsem" },
35719 + { .name = "&iinfo->ii_rwsem" }
35724 + /* lockless read from 'set.' see below */
35725 + if (set == ARRAY_SIZE(a)) {
35726 + for (i = 0; i < ARRAY_SIZE(a); i++)
35727 + if (a[i].key == key)
35732 + spin_lock(&spin);
35734 + for (i = 0; i < ARRAY_SIZE(a); i++)
35735 + if (a[i].key == key) {
35736 + spin_unlock(&spin);
35739 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35741 + if (unlikely(a[i].key == key)) { /* rare but possible */
35742 + spin_unlock(&spin);
35747 + if (strstr(a[i].name, name)) {
35749 + * the order of these three lines is important for the
35750 + * lockless read above.
35753 + spin_unlock(&spin);
35755 + /* AuDbg("%d, %s\n", set, name); */
35759 + spin_unlock(&spin);
35768 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35771 + struct task_struct *curr;
35772 + struct held_lock **hl, *held_locks, *p;
35776 + wkinfo->dont_check = lockdep_recursing(curr);
35777 + if (wkinfo->dont_check)
35779 + n = curr->lockdep_depth;
35784 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35785 + if (unlikely(!wkinfo->hlock))
35790 + if (0 && au_debug_test()) /* left for debugging */
35791 + lockdep_print_held_locks(curr);
35793 + held_locks = curr->held_locks;
35794 + hl = wkinfo->hlock;
35796 + p = held_locks++;
35797 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35806 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35808 + kfree(wkinfo->hlock);
35811 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
35813 + struct held_lock *p, **hl = wkinfo->hlock;
35816 + if (wkinfo->dont_check)
35820 + while ((p = *hl++)) { /* assignment */
35821 + subclass = lockdep_hlock_class(p)->subclass;
35822 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
35824 + rwsem_acquire_read(p->instance, subclass, 0,
35825 + /*p->acquire_ip*/_RET_IP_);
35827 + rwsem_acquire(p->instance, subclass, 0,
35828 + /*p->acquire_ip*/_RET_IP_);
35832 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
35834 + struct held_lock *p, **hl = wkinfo->hlock;
35836 + if (wkinfo->dont_check)
35840 + while ((p = *hl++)) /* assignment */
35841 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
35845 +static void wkq_func(struct work_struct *wk)
35847 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
35849 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
35850 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
35852 + au_wkq_lockdep_pre(wkinfo);
35853 + wkinfo->func(wkinfo->args);
35854 + au_wkq_lockdep_post(wkinfo);
35855 + if (au_ftest_wkq(wkinfo->flags, WAIT))
35856 + complete(wkinfo->comp);
35858 + kobject_put(wkinfo->kobj);
35859 + module_put(THIS_MODULE); /* todo: ?? */
35865 + * Since struct completion is large, try allocating it dynamically.
35867 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
35868 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
35870 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
35872 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
35874 + init_completion(*comp);
35875 + wkinfo->comp = *comp;
35881 +static void au_wkq_comp_free(struct completion *comp)
35889 +#define AuWkqCompDeclare(name) \
35890 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
35891 + struct completion *comp = &_ ## name
35893 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
35895 + wkinfo->comp = *comp;
35899 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
35903 +#endif /* 4KSTACKS */
35905 +static void au_wkq_run(struct au_wkinfo *wkinfo)
35907 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
35908 + if (au_wkq_test()) {
35909 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
35910 + " due to a dead dir by UDBA?\n");
35911 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
35914 + au_dbg_verify_kthread();
35916 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
35917 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
35918 + queue_work(au_wkq, &wkinfo->wk);
35920 + INIT_WORK(&wkinfo->wk, wkq_func);
35921 + schedule_work(&wkinfo->wk);
35926 + * Be careful. It is easy to make deadlock happen.
35927 + * processA: lock, wkq and wait
35928 + * processB: wkq and wait, lock in wkq
35931 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
35934 + AuWkqCompDeclare(comp);
35935 + struct au_wkinfo wkinfo = {
35941 + err = au_wkq_comp_alloc(&wkinfo, &comp);
35942 + if (unlikely(err))
35944 + err = au_wkq_lockdep_alloc(&wkinfo);
35945 + if (unlikely(err))
35948 + au_wkq_run(&wkinfo);
35949 + /* no timeout, no interrupt */
35950 + wait_for_completion(wkinfo.comp);
35952 + au_wkq_lockdep_free(&wkinfo);
35955 + au_wkq_comp_free(comp);
35957 + destroy_work_on_stack(&wkinfo.wk);
35962 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
35963 + * problem in a concurrent umounting.
35965 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
35966 + unsigned int flags)
35969 + struct au_wkinfo *wkinfo;
35971 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
35974 + * wkq_func() must free this wkinfo.
35975 + * it highly depends upon the implementation of workqueue.
35978 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
35980 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
35981 + wkinfo->flags = flags & ~AuWkq_WAIT;
35982 + wkinfo->func = func;
35983 + wkinfo->args = args;
35984 + wkinfo->comp = NULL;
35985 + au_wkq_lockdep_init(wkinfo);
35986 + kobject_get(wkinfo->kobj);
35987 + __module_get(THIS_MODULE); /* todo: ?? */
35989 + au_wkq_run(wkinfo);
35992 + au_nwt_done(&au_sbi(sb)->si_nowait);
35998 +/* ---------------------------------------------------------------------- */
36000 +void au_nwt_init(struct au_nowait_tasks *nwt)
36002 + atomic_set(&nwt->nw_len, 0);
36003 + /* smp_mb(); */ /* atomic_set */
36004 + init_waitqueue_head(&nwt->nw_wq);
36007 +void au_wkq_fin(void)
36009 + destroy_workqueue(au_wkq);
36012 +int __init au_wkq_init(void)
36017 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36018 + if (IS_ERR(au_wkq))
36019 + err = PTR_ERR(au_wkq);
36020 + else if (!au_wkq)
36025 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36026 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36027 +++ linux/fs/aufs/wkq.h 2018-04-15 08:49:13.404484168 +0200
36030 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36032 + * This program, aufs is free software; you can redistribute it and/or modify
36033 + * it under the terms of the GNU General Public License as published by
36034 + * the Free Software Foundation; either version 2 of the License, or
36035 + * (at your option) any later version.
36037 + * This program is distributed in the hope that it will be useful,
36038 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36039 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36040 + * GNU General Public License for more details.
36042 + * You should have received a copy of the GNU General Public License
36043 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36047 + * workqueue for asynchronous/super-io operations
36048 + * todo: try new credentials management scheme
36051 +#ifndef __AUFS_WKQ_H__
36052 +#define __AUFS_WKQ_H__
36056 +#include <linux/wait.h>
36058 +struct super_block;
36060 +/* ---------------------------------------------------------------------- */
36063 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36065 +struct au_nowait_tasks {
36067 + wait_queue_head_t nw_wq;
36070 +/* ---------------------------------------------------------------------- */
36072 +typedef void (*au_wkq_func_t)(void *args);
36075 +#define AuWkq_WAIT 1
36076 +#define AuWkq_NEST (1 << 1)
36077 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36078 +#define au_fset_wkq(flags, name) \
36079 + do { (flags) |= AuWkq_##name; } while (0)
36080 +#define au_fclr_wkq(flags, name) \
36081 + do { (flags) &= ~AuWkq_##name; } while (0)
36083 +#ifndef CONFIG_AUFS_HNOTIFY
36085 +#define AuWkq_NEST 0
36089 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36090 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36091 + unsigned int flags);
36092 +void au_nwt_init(struct au_nowait_tasks *nwt);
36093 +int __init au_wkq_init(void);
36094 +void au_wkq_fin(void);
36096 +/* ---------------------------------------------------------------------- */
36098 +static inline int au_wkq_test(void)
36100 + return current->flags & PF_WQ_WORKER;
36103 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36105 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36108 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36110 + if (atomic_dec_and_test(&nwt->nw_len))
36111 + wake_up_all(&nwt->nw_wq);
36114 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36116 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36120 +#endif /* __KERNEL__ */
36121 +#endif /* __AUFS_WKQ_H__ */
36122 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36123 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36124 +++ linux/fs/aufs/xattr.c 2018-06-04 09:08:09.188079511 +0200
36127 + * Copyright (C) 2014-2018 Junjiro R. Okajima
36129 + * This program, aufs is free software; you can redistribute it and/or modify
36130 + * it under the terms of the GNU General Public License as published by
36131 + * the Free Software Foundation; either version 2 of the License, or
36132 + * (at your option) any later version.
36134 + * This program is distributed in the hope that it will be useful,
36135 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36136 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36137 + * GNU General Public License for more details.
36139 + * You should have received a copy of the GNU General Public License
36140 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36144 + * handling xattr functions
36147 +#include <linux/fs.h>
36148 +#include <linux/posix_acl_xattr.h>
36149 +#include <linux/xattr.h>
36152 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36154 + if (!ignore_flags)
36162 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36167 +#define cmp(brattr, prefix) do { \
36168 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36169 + XATTR_##prefix##_PREFIX_LEN)) { \
36170 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36176 + cmp(SEC, SECURITY);
36177 + cmp(SYS, SYSTEM);
36178 + cmp(TR, TRUSTED);
36182 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36189 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36191 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36192 + char *name, char **buf, unsigned int ignore_flags,
36193 + unsigned int verbose)
36197 + struct inode *h_idst;
36199 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36201 + if (unlikely(err <= 0)) {
36202 + if (err == -ENODATA
36203 + || (err == -EOPNOTSUPP
36204 + && ((ignore_flags & au_xattr_out_of_list)
36205 + || (au_test_nfs_noacl(d_inode(h_src))
36206 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36208 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36211 + if (err && (verbose || au_debug_test()))
36212 + pr_err("%s, err %d\n", name, err);
36216 + /* unlock it temporary */
36217 + h_idst = d_inode(h_dst);
36218 + inode_unlock(h_idst);
36219 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36220 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36221 + if (unlikely(err)) {
36222 + if (verbose || au_debug_test())
36223 + pr_err("%s, err %d\n", name, err);
36224 + err = au_xattr_ignore(err, name, ignore_flags);
36231 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36232 + unsigned int verbose)
36234 + int err, unlocked, acl_access, acl_default;
36236 + struct inode *h_isrc, *h_idst;
36237 + char *value, *p, *o, *e;
36239 + /* try stopping to update the source inode while we are referencing */
36240 + /* there should not be the parent-child relationship between them */
36241 + h_isrc = d_inode(h_src);
36242 + h_idst = d_inode(h_dst);
36243 + inode_unlock(h_idst);
36244 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36245 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36248 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36249 + ssz = vfs_listxattr(h_src, NULL, 0);
36251 + if (unlikely(err < 0)) {
36253 + if (err == -ENODATA
36254 + || err == -EOPNOTSUPP)
36255 + err = 0; /* ignore */
36264 + p = kmalloc(ssz, GFP_NOFS);
36266 + if (unlikely(!p))
36268 + err = vfs_listxattr(h_src, p, ssz);
36270 + inode_unlock_shared(h_isrc);
36272 + AuDbg("err %d, ssz %zd\n", err, ssz);
36273 + if (unlikely(err < 0))
36281 + while (!err && p < e) {
36282 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36283 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36284 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36285 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36287 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36289 + p += strlen(p) + 1;
36292 + ignore_flags |= au_xattr_out_of_list;
36293 + if (!err && !acl_access) {
36294 + err = au_do_cpup_xattr(h_dst, h_src,
36295 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36296 + ignore_flags, verbose);
36299 + if (!err && !acl_default) {
36300 + err = au_do_cpup_xattr(h_dst, h_src,
36301 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36302 + ignore_flags, verbose);
36312 + inode_unlock_shared(h_isrc);
36317 +/* ---------------------------------------------------------------------- */
36319 +static int au_smack_reentering(struct super_block *sb)
36321 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36323 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36324 + * i_op->getxattr(). ouch.
36326 + return si_pid_test(sb);
36337 +struct au_lgxattr {
36345 + const char *name;
36352 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36356 + struct path h_path;
36357 + struct super_block *sb;
36359 + sb = dentry->d_sb;
36360 + reenter = au_smack_reentering(sb);
36362 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36363 + if (unlikely(err))
36366 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36367 + if (unlikely(err))
36369 + if (unlikely(!h_path.dentry))
36370 + /* illegally overlapped or something */
36371 + goto out_di; /* pretending success */
36373 + /* always topmost entry only */
36374 + switch (arg->type) {
36375 + case AU_XATTR_LIST:
36376 + err = vfs_listxattr(h_path.dentry,
36377 + arg->u.list.list, arg->u.list.size);
36379 + case AU_XATTR_GET:
36380 + AuDebugOn(d_is_negative(h_path.dentry));
36381 + err = vfs_getxattr(h_path.dentry,
36382 + arg->u.get.name, arg->u.get.value,
36383 + arg->u.get.size);
36389 + di_read_unlock(dentry, AuLock_IR);
36392 + si_read_unlock(sb);
36398 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36400 + struct au_lgxattr arg = {
36401 + .type = AU_XATTR_LIST,
36408 + return au_lgxattr(dentry, &arg);
36411 +static ssize_t au_getxattr(struct dentry *dentry,
36412 + struct inode *inode __maybe_unused,
36413 + const char *name, void *value, size_t size)
36415 + struct au_lgxattr arg = {
36416 + .type = AU_XATTR_GET,
36424 + return au_lgxattr(dentry, &arg);
36427 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36428 + const char *name, const void *value, size_t size,
36431 + struct au_sxattr arg = {
36432 + .type = AU_XATTR_SET,
36441 + return au_sxattr(dentry, inode, &arg);
36444 +/* ---------------------------------------------------------------------- */
36446 +static int au_xattr_get(const struct xattr_handler *handler,
36447 + struct dentry *dentry, struct inode *inode,
36448 + const char *name, void *buffer, size_t size)
36450 + return au_getxattr(dentry, inode, name, buffer, size);
36453 +static int au_xattr_set(const struct xattr_handler *handler,
36454 + struct dentry *dentry, struct inode *inode,
36455 + const char *name, const void *value, size_t size,
36458 + return au_setxattr(dentry, inode, name, value, size, flags);
36461 +static const struct xattr_handler au_xattr_handler = {
36464 + .get = au_xattr_get,
36465 + .set = au_xattr_set
36468 +static const struct xattr_handler *au_xattr_handlers[] = {
36469 +#ifdef CONFIG_FS_POSIX_ACL
36470 + &posix_acl_access_xattr_handler,
36471 + &posix_acl_default_xattr_handler,
36473 + &au_xattr_handler, /* must be last */
36477 +void au_xattr_init(struct super_block *sb)
36479 + sb->s_xattr = au_xattr_handlers;
36481 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36482 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36483 +++ linux/fs/aufs/xino.c 2018-06-04 09:08:09.188079511 +0200
36486 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36488 + * This program, aufs is free software; you can redistribute it and/or modify
36489 + * it under the terms of the GNU General Public License as published by
36490 + * the Free Software Foundation; either version 2 of the License, or
36491 + * (at your option) any later version.
36493 + * This program is distributed in the hope that it will be useful,
36494 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36496 + * GNU General Public License for more details.
36498 + * You should have received a copy of the GNU General Public License
36499 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36503 + * external inode number translation table and bitmap
36506 +#include <linux/seq_file.h>
36507 +#include <linux/statfs.h>
36510 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
36511 + size_t size, loff_t *pos);
36513 +/* todo: unnecessary to support mmap_sem since kernel-space? */
36514 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
36518 + mm_segment_t oldfs;
36524 + const int prevent_endless = 10;
36528 + oldfs = get_fs();
36529 + set_fs(KERNEL_DS);
36531 + err = func(file, buf.u, size, pos);
36532 + if (err == -EINTR
36533 + && !au_wkq_test()
36534 + && fatal_signal_pending(current)) {
36536 + err = xino_fread_wkq(func, file, kbuf, size, pos);
36537 + BUG_ON(err == -EINTR);
36538 + oldfs = get_fs();
36539 + set_fs(KERNEL_DS);
36541 + } while (i++ < prevent_endless
36542 + && (err == -EAGAIN || err == -EINTR));
36545 +#if 0 /* reserved for future use */
36547 + fsnotify_access(file->f_path.dentry);
36553 +struct xino_fread_args {
36555 + vfs_readf_t func;
36556 + struct file *file;
36562 +static void call_xino_fread(void *args)
36564 + struct xino_fread_args *a = args;
36565 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
36568 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
36569 + size_t size, loff_t *pos)
36573 + struct xino_fread_args args = {
36582 + wkq_err = au_wkq_wait(call_xino_fread, &args);
36583 + if (unlikely(wkq_err))
36589 +/* ---------------------------------------------------------------------- */
36591 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
36592 + size_t size, loff_t *pos);
36594 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
36595 + size_t size, loff_t *pos)
36598 + mm_segment_t oldfs;
36601 + const char __user *u;
36604 + const int prevent_endless = 10;
36608 + oldfs = get_fs();
36609 + set_fs(KERNEL_DS);
36611 + err = func(file, buf.u, size, pos);
36612 + if (err == -EINTR
36613 + && !au_wkq_test()
36614 + && fatal_signal_pending(current)) {
36616 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
36617 + BUG_ON(err == -EINTR);
36618 + oldfs = get_fs();
36619 + set_fs(KERNEL_DS);
36621 + } while (i++ < prevent_endless
36622 + && (err == -EAGAIN || err == -EINTR));
36625 +#if 0 /* reserved for future use */
36627 + fsnotify_modify(file->f_path.dentry);
36633 +struct do_xino_fwrite_args {
36635 + vfs_writef_t func;
36636 + struct file *file;
36642 +static void call_do_xino_fwrite(void *args)
36644 + struct do_xino_fwrite_args *a = args;
36645 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
36648 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
36649 + size_t size, loff_t *pos)
36653 + struct do_xino_fwrite_args args = {
36663 + * it breaks RLIMIT_FSIZE and normal user's limit,
36664 + * users should care about quota and real 'filesystem full.'
36666 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
36667 + if (unlikely(wkq_err))
36673 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
36674 + size_t size, loff_t *pos)
36678 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
36680 + err = do_xino_fwrite(func, file, buf, size, pos);
36684 + err = xino_fwrite_wkq(func, file, buf, size, pos);
36691 +/* ---------------------------------------------------------------------- */
36694 + * create a new xinofile at the same place/path as @base_file.
36696 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
36698 + struct file *file;
36699 + struct dentry *base, *parent;
36700 + struct inode *dir, *delegated;
36701 + struct qstr *name;
36702 + struct path path;
36705 + base = base_file->f_path.dentry;
36706 + parent = base->d_parent; /* dir inode is locked */
36707 + dir = d_inode(parent);
36710 + file = ERR_PTR(-EINVAL);
36711 + name = &base->d_name;
36712 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36713 + if (IS_ERR(path.dentry)) {
36714 + file = (void *)path.dentry;
36715 + pr_err("%pd lookup err %ld\n",
36716 + base, PTR_ERR(path.dentry));
36720 + /* no need to mnt_want_write() since we call dentry_open() later */
36721 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
36722 + if (unlikely(err)) {
36723 + file = ERR_PTR(err);
36724 + pr_err("%pd create err %d\n", base, err);
36728 + path.mnt = base_file->f_path.mnt;
36729 + file = vfsub_dentry_open(&path,
36730 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36731 + /* | __FMODE_NONOTIFY */);
36732 + if (IS_ERR(file)) {
36733 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
36737 + delegated = NULL;
36738 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36739 + if (unlikely(err == -EWOULDBLOCK)) {
36740 + pr_warn("cannot retry for NFSv4 delegation"
36741 + " for an internal unlink\n");
36744 + if (unlikely(err)) {
36745 + pr_err("%pd unlink err %d\n", base, err);
36750 + /* no one can touch copy_src xino */
36751 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36752 + if (unlikely(err)) {
36753 + pr_err("%pd copy err %d\n", base, err);
36757 + goto out_dput; /* success */
36761 + file = ERR_PTR(err);
36763 + dput(path.dentry);
36768 +struct au_xino_lock_dir {
36769 + struct au_hinode *hdir;
36770 + struct dentry *parent;
36771 + struct inode *dir;
36774 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
36775 + struct au_xino_lock_dir *ldir)
36777 + aufs_bindex_t brid, bindex;
36779 + ldir->hdir = NULL;
36781 + brid = au_xino_brid(sb);
36783 + bindex = au_br_index(sb, brid);
36784 + if (bindex >= 0) {
36785 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36786 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36788 + ldir->parent = dget_parent(xino->f_path.dentry);
36789 + ldir->dir = d_inode(ldir->parent);
36790 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
36794 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36797 + au_hn_inode_unlock(ldir->hdir);
36799 + inode_unlock(ldir->dir);
36800 + dput(ldir->parent);
36804 +/* ---------------------------------------------------------------------- */
36806 +/* trucate xino files asynchronously */
36808 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
36811 + unsigned long jiffy;
36813 + aufs_bindex_t bi, bbot;
36814 + struct kstatfs *st;
36815 + struct au_branch *br;
36816 + struct file *new_xino, *file;
36817 + struct super_block *h_sb;
36818 + struct au_xino_lock_dir ldir;
36821 + st = kmalloc(sizeof(*st), GFP_NOFS);
36822 + if (unlikely(!st))
36826 + bbot = au_sbbot(sb);
36827 + if (unlikely(bindex < 0 || bbot < bindex))
36829 + br = au_sbr(sb, bindex);
36830 + file = br->br_xino.xi_file;
36834 + err = vfs_statfs(&file->f_path, st);
36835 + if (unlikely(err))
36836 + AuErr1("statfs err %d, ignored\n", err);
36838 + blocks = file_inode(file)->i_blocks;
36839 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36840 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
36842 + au_xino_lock_dir(sb, file, &ldir);
36843 + /* mnt_want_write() is unnecessary here */
36844 + new_xino = au_xino_create2(file, file);
36845 + au_xino_unlock_dir(&ldir);
36846 + err = PTR_ERR(new_xino);
36847 + if (IS_ERR(new_xino)) {
36848 + pr_err("err %d, ignored\n", err);
36853 + br->br_xino.xi_file = new_xino;
36855 + h_sb = au_br_sb(br);
36856 + for (bi = 0; bi <= bbot; bi++) {
36857 + if (unlikely(bi == bindex))
36859 + br = au_sbr(sb, bi);
36860 + if (au_br_sb(br) != h_sb)
36863 + fput(br->br_xino.xi_file);
36864 + br->br_xino.xi_file = new_xino;
36865 + get_file(new_xino);
36868 + err = vfs_statfs(&new_xino->f_path, st);
36870 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36871 + bindex, (u64)file_inode(new_xino)->i_blocks,
36872 + st->f_bfree, st->f_blocks);
36873 + if (file_inode(new_xino)->i_blocks < blocks)
36874 + au_sbi(sb)->si_xino_jiffy = jiffy;
36876 + AuErr1("statfs err %d, ignored\n", err);
36884 +struct xino_do_trunc_args {
36885 + struct super_block *sb;
36886 + struct au_branch *br;
36889 +static void xino_do_trunc(void *_args)
36891 + struct xino_do_trunc_args *args = _args;
36892 + struct super_block *sb;
36893 + struct au_branch *br;
36894 + struct inode *dir;
36896 + aufs_bindex_t bindex;
36900 + dir = d_inode(sb->s_root);
36903 + si_noflush_write_lock(sb);
36904 + ii_read_lock_parent(dir);
36905 + bindex = au_br_index(sb, br->br_id);
36906 + err = au_xino_trunc(sb, bindex);
36907 + ii_read_unlock(dir);
36908 + if (unlikely(err))
36909 + pr_warn("err b%d, (%d)\n", bindex, err);
36910 + atomic_dec(&br->br_xino_running);
36912 + si_write_unlock(sb);
36913 + au_nwt_done(&au_sbi(sb)->si_nowait);
36917 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
36920 + struct kstatfs st;
36921 + struct au_sbinfo *sbinfo;
36923 + /* todo: si_xino_expire and the ratio should be customizable */
36924 + sbinfo = au_sbi(sb);
36925 + if (time_before(jiffies,
36926 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
36929 + /* truncation border */
36930 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
36931 + if (unlikely(err)) {
36932 + AuErr1("statfs err %d, ignored\n", err);
36935 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
36941 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
36943 + struct xino_do_trunc_args *args;
36946 + if (!xino_trunc_test(sb, br))
36949 + if (atomic_inc_return(&br->br_xino_running) > 1)
36952 + /* lock and kfree() will be called in trunc_xino() */
36953 + args = kmalloc(sizeof(*args), GFP_NOFS);
36954 + if (unlikely(!args)) {
36955 + AuErr1("no memory\n");
36962 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
36964 + return; /* success */
36966 + pr_err("wkq %d\n", wkq_err);
36971 + atomic_dec(&br->br_xino_running);
36974 +/* ---------------------------------------------------------------------- */
36976 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
36977 + ino_t h_ino, ino_t ino)
36983 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
36984 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
36987 + pos *= sizeof(ino);
36988 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
36989 + if (sz == sizeof(ino))
36990 + return 0; /* success */
36992 + AuIOErr("write failed (%zd)\n", sz);
36997 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
36998 + * at the position of @h_ino.
36999 + * even if @ino is zero, it is written to the xinofile and means no entry.
37000 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37001 + * try truncating it.
37003 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37007 + unsigned int mnt_flags;
37008 + struct au_branch *br;
37010 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
37011 + || ((loff_t)-1) > 0);
37012 + SiMustAnyLock(sb);
37014 + mnt_flags = au_mntflags(sb);
37015 + if (!au_opt_test(mnt_flags, XINO))
37018 + br = au_sbr(sb, bindex);
37019 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
37022 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37023 + && au_test_fs_trunc_xino(au_br_sb(br)))
37024 + xino_try_trunc(sb, br);
37025 + return 0; /* success */
37028 + AuIOErr("write failed (%d)\n", err);
37032 +/* ---------------------------------------------------------------------- */
37034 +/* aufs inode number bitmap */
37036 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37037 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37041 + AuDebugOn(bit < 0 || page_bits <= bit);
37042 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37046 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37048 + AuDebugOn(ino < AUFS_FIRST_INO);
37049 + ino -= AUFS_FIRST_INO;
37050 + *pindex = ino / page_bits;
37051 + *bit = ino % page_bits;
37054 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37059 + struct au_sbinfo *sbinfo;
37060 + struct file *xib;
37061 + unsigned long *p;
37063 + sbinfo = au_sbi(sb);
37064 + MtxMustLock(&sbinfo->si_xib_mtx);
37065 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37066 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37068 + if (pindex == sbinfo->si_xib_last_pindex)
37071 + xib = sbinfo->si_xib;
37072 + p = sbinfo->si_xib_buf;
37073 + pos = sbinfo->si_xib_last_pindex;
37074 + pos *= PAGE_SIZE;
37075 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37076 + if (unlikely(sz != PAGE_SIZE))
37080 + pos *= PAGE_SIZE;
37081 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37082 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37084 + memset(p, 0, PAGE_SIZE);
37085 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37087 + if (sz == PAGE_SIZE) {
37088 + sbinfo->si_xib_last_pindex = pindex;
37089 + return 0; /* success */
37093 + AuIOErr1("write failed (%zd)\n", sz);
37100 +/* ---------------------------------------------------------------------- */
37102 +static void au_xib_clear_bit(struct inode *inode)
37105 + unsigned long pindex;
37106 + struct super_block *sb;
37107 + struct au_sbinfo *sbinfo;
37109 + AuDebugOn(inode->i_nlink);
37111 + sb = inode->i_sb;
37112 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37113 + AuDebugOn(page_bits <= bit);
37114 + sbinfo = au_sbi(sb);
37115 + mutex_lock(&sbinfo->si_xib_mtx);
37116 + err = xib_pindex(sb, pindex);
37118 + clear_bit(bit, sbinfo->si_xib_buf);
37119 + sbinfo->si_xib_next_bit = bit;
37121 + mutex_unlock(&sbinfo->si_xib_mtx);
37124 +/* for s_op->delete_inode() */
37125 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
37128 + unsigned int mnt_flags;
37129 + aufs_bindex_t bindex, bbot, bi;
37130 + unsigned char try_trunc;
37131 + struct au_iinfo *iinfo;
37132 + struct super_block *sb;
37133 + struct au_hinode *hi;
37134 + struct inode *h_inode;
37135 + struct au_branch *br;
37136 + vfs_writef_t xwrite;
37138 + AuDebugOn(au_is_bad_inode(inode));
37140 + sb = inode->i_sb;
37141 + mnt_flags = au_mntflags(sb);
37142 + if (!au_opt_test(mnt_flags, XINO)
37143 + || inode->i_ino == AUFS_ROOT_INO)
37147 + au_xigen_inc(inode);
37148 + au_xib_clear_bit(inode);
37151 + iinfo = au_ii(inode);
37152 + bindex = iinfo->ii_btop;
37156 + xwrite = au_sbi(sb)->si_xwrite;
37157 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
37158 + hi = au_hinode(iinfo, bindex);
37159 + bbot = iinfo->ii_bbot;
37160 + for (; bindex <= bbot; bindex++, hi++) {
37161 + h_inode = hi->hi_inode;
37163 + || (!unlinked && h_inode->i_nlink))
37166 + /* inode may not be revalidated */
37167 + bi = au_br_index(sb, hi->hi_id);
37171 + br = au_sbr(sb, bi);
37172 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
37173 + h_inode->i_ino, /*ino*/0);
37174 + if (!err && try_trunc
37175 + && au_test_fs_trunc_xino(au_br_sb(br)))
37176 + xino_try_trunc(sb, br);
37180 +/* get an unused inode number from bitmap */
37181 +ino_t au_xino_new_ino(struct super_block *sb)
37184 + unsigned long *p, pindex, ul, pend;
37185 + struct au_sbinfo *sbinfo;
37186 + struct file *file;
37187 + int free_bit, err;
37189 + if (!au_opt_test(au_mntflags(sb), XINO))
37190 + return iunique(sb, AUFS_FIRST_INO);
37192 + sbinfo = au_sbi(sb);
37193 + mutex_lock(&sbinfo->si_xib_mtx);
37194 + p = sbinfo->si_xib_buf;
37195 + free_bit = sbinfo->si_xib_next_bit;
37196 + if (free_bit < page_bits && !test_bit(free_bit, p))
37197 + goto out; /* success */
37198 + free_bit = find_first_zero_bit(p, page_bits);
37199 + if (free_bit < page_bits)
37200 + goto out; /* success */
37202 + pindex = sbinfo->si_xib_last_pindex;
37203 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
37204 + err = xib_pindex(sb, ul);
37205 + if (unlikely(err))
37207 + free_bit = find_first_zero_bit(p, page_bits);
37208 + if (free_bit < page_bits)
37209 + goto out; /* success */
37212 + file = sbinfo->si_xib;
37213 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
37214 + for (ul = pindex + 1; ul <= pend; ul++) {
37215 + err = xib_pindex(sb, ul);
37216 + if (unlikely(err))
37218 + free_bit = find_first_zero_bit(p, page_bits);
37219 + if (free_bit < page_bits)
37220 + goto out; /* success */
37225 + set_bit(free_bit, p);
37226 + sbinfo->si_xib_next_bit = free_bit + 1;
37227 + pindex = sbinfo->si_xib_last_pindex;
37228 + mutex_unlock(&sbinfo->si_xib_mtx);
37229 + ino = xib_calc_ino(pindex, free_bit);
37230 + AuDbg("i%lu\n", (unsigned long)ino);
37233 + mutex_unlock(&sbinfo->si_xib_mtx);
37239 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37240 + * at the position of @h_ino.
37241 + * if @ino does not exist and @do_new is true, get new one.
37243 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37249 + struct file *file;
37250 + struct au_sbinfo *sbinfo;
37253 + if (!au_opt_test(au_mntflags(sb), XINO))
37254 + return 0; /* no xino */
37257 + sbinfo = au_sbi(sb);
37259 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
37260 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
37263 + pos *= sizeof(*ino);
37265 + file = au_sbr(sb, bindex)->br_xino.xi_file;
37266 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
37267 + return 0; /* no ino */
37269 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
37270 + if (sz == sizeof(*ino))
37271 + return 0; /* success */
37274 + if (unlikely(sz >= 0)) {
37276 + AuIOErr("xino read error (%zd)\n", sz);
37282 +/* ---------------------------------------------------------------------- */
37284 +/* create and set a new xino file */
37286 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
37288 + struct file *file;
37289 + struct dentry *h_parent, *d;
37290 + struct inode *h_dir, *inode;
37294 + * at mount-time, and the xino file is the default path,
37295 + * hnotify is disabled so we have no notify events to ignore.
37296 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37298 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37299 + /* | __FMODE_NONOTIFY */,
37300 + S_IRUGO | S_IWUGO);
37301 + if (IS_ERR(file)) {
37303 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
37307 + /* keep file count */
37309 + inode = file_inode(file);
37310 + h_parent = dget_parent(file->f_path.dentry);
37311 + h_dir = d_inode(h_parent);
37312 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
37313 + /* mnt_want_write() is unnecessary here */
37314 + /* no delegation since it is just created */
37315 + if (inode->i_nlink)
37316 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37318 + inode_unlock(h_dir);
37320 + if (unlikely(err)) {
37322 + pr_err("unlink %s(%d)\n", fname, err);
37327 + d = file->f_path.dentry;
37328 + if (unlikely(sb == d->d_sb)) {
37330 + pr_err("%s must be outside\n", fname);
37333 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37335 + pr_err("xino doesn't support %s(%s)\n",
37336 + fname, au_sbtype(d->d_sb));
37339 + return file; /* success */
37343 + file = ERR_PTR(err);
37348 + * find another branch who is on the same filesystem of the specified
37349 + * branch{@btgt}. search until @bbot.
37351 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37352 + aufs_bindex_t bbot)
37354 + aufs_bindex_t bindex;
37355 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
37357 + for (bindex = 0; bindex < btgt; bindex++)
37358 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
37360 + for (bindex++; bindex <= bbot; bindex++)
37361 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
37366 +/* ---------------------------------------------------------------------- */
37369 + * initialize the xinofile for the specified branch @br
37370 + * at the place/path where @base_file indicates.
37371 + * test whether another branch is on the same filesystem or not,
37372 + * if @do_test is true.
37374 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
37375 + struct file *base_file, int do_test)
37379 + aufs_bindex_t bbot, bindex;
37380 + struct au_branch *shared_br, *b;
37381 + struct file *file;
37382 + struct super_block *tgt_sb;
37384 + shared_br = NULL;
37385 + bbot = au_sbbot(sb);
37387 + tgt_sb = au_br_sb(br);
37388 + for (bindex = 0; bindex <= bbot; bindex++) {
37389 + b = au_sbr(sb, bindex);
37390 + if (tgt_sb == au_br_sb(b)) {
37397 + if (!shared_br || !shared_br->br_xino.xi_file) {
37398 + struct au_xino_lock_dir ldir;
37400 + au_xino_lock_dir(sb, base_file, &ldir);
37401 + /* mnt_want_write() is unnecessary here */
37402 + file = au_xino_create2(base_file, NULL);
37403 + au_xino_unlock_dir(&ldir);
37404 + err = PTR_ERR(file);
37405 + if (IS_ERR(file))
37407 + br->br_xino.xi_file = file;
37409 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
37410 + get_file(br->br_xino.xi_file);
37413 + ino = AUFS_ROOT_INO;
37414 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
37416 + if (unlikely(err)) {
37417 + fput(br->br_xino.xi_file);
37418 + br->br_xino.xi_file = NULL;
37425 +/* ---------------------------------------------------------------------- */
37427 +/* trucate a xino bitmap file */
37430 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37434 + unsigned long pindex;
37435 + loff_t pos, pend;
37436 + struct au_sbinfo *sbinfo;
37437 + vfs_readf_t func;
37439 + unsigned long *p;
37442 + sbinfo = au_sbi(sb);
37443 + MtxMustLock(&sbinfo->si_xib_mtx);
37444 + p = sbinfo->si_xib_buf;
37445 + func = sbinfo->si_xread;
37446 + pend = vfsub_f_size_read(file);
37448 + while (pos < pend) {
37449 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37451 + if (unlikely(sz <= 0))
37455 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37456 + if (unlikely(*ino < AUFS_FIRST_INO))
37459 + xib_calc_bit(*ino, &pindex, &bit);
37460 + AuDebugOn(page_bits <= bit);
37461 + err = xib_pindex(sb, pindex);
37473 +static int xib_restore(struct super_block *sb)
37476 + aufs_bindex_t bindex, bbot;
37480 + page = (void *)__get_free_page(GFP_NOFS);
37481 + if (unlikely(!page))
37485 + bbot = au_sbbot(sb);
37486 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37487 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
37488 + err = do_xib_restore
37489 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
37491 + AuDbg("b%d\n", bindex);
37492 + free_page((unsigned long)page);
37498 +int au_xib_trunc(struct super_block *sb)
37503 + struct au_xino_lock_dir ldir;
37504 + struct au_sbinfo *sbinfo;
37505 + unsigned long *p;
37506 + struct file *file;
37508 + SiMustWriteLock(sb);
37511 + sbinfo = au_sbi(sb);
37512 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37515 + file = sbinfo->si_xib;
37516 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37519 + au_xino_lock_dir(sb, file, &ldir);
37520 + /* mnt_want_write() is unnecessary here */
37521 + file = au_xino_create2(sbinfo->si_xib, NULL);
37522 + au_xino_unlock_dir(&ldir);
37523 + err = PTR_ERR(file);
37524 + if (IS_ERR(file))
37526 + fput(sbinfo->si_xib);
37527 + sbinfo->si_xib = file;
37529 + p = sbinfo->si_xib_buf;
37530 + memset(p, 0, PAGE_SIZE);
37532 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
37533 + if (unlikely(sz != PAGE_SIZE)) {
37535 + AuIOErr("err %d\n", err);
37541 + mutex_lock(&sbinfo->si_xib_mtx);
37542 + /* mnt_want_write() is unnecessary here */
37543 + err = xib_restore(sb);
37544 + mutex_unlock(&sbinfo->si_xib_mtx);
37550 +/* ---------------------------------------------------------------------- */
37553 + * xino mount option handlers
37557 +static void xino_clear_xib(struct super_block *sb)
37559 + struct au_sbinfo *sbinfo;
37561 + SiMustWriteLock(sb);
37563 + sbinfo = au_sbi(sb);
37564 + sbinfo->si_xread = NULL;
37565 + sbinfo->si_xwrite = NULL;
37566 + if (sbinfo->si_xib)
37567 + fput(sbinfo->si_xib);
37568 + sbinfo->si_xib = NULL;
37569 + if (sbinfo->si_xib_buf)
37570 + free_page((unsigned long)sbinfo->si_xib_buf);
37571 + sbinfo->si_xib_buf = NULL;
37574 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
37578 + struct au_sbinfo *sbinfo;
37579 + struct file *file;
37581 + SiMustWriteLock(sb);
37583 + sbinfo = au_sbi(sb);
37584 + file = au_xino_create2(base, sbinfo->si_xib);
37585 + err = PTR_ERR(file);
37586 + if (IS_ERR(file))
37588 + if (sbinfo->si_xib)
37589 + fput(sbinfo->si_xib);
37590 + sbinfo->si_xib = file;
37591 + sbinfo->si_xread = vfs_readf(file);
37592 + sbinfo->si_xwrite = vfs_writef(file);
37595 + if (!sbinfo->si_xib_buf)
37596 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
37597 + if (unlikely(!sbinfo->si_xib_buf))
37600 + sbinfo->si_xib_last_pindex = 0;
37601 + sbinfo->si_xib_next_bit = 0;
37602 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
37604 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
37605 + PAGE_SIZE, &pos);
37606 + if (unlikely(err != PAGE_SIZE))
37610 + goto out; /* success */
37613 + if (sbinfo->si_xib_buf)
37614 + free_page((unsigned long)sbinfo->si_xib_buf);
37615 + sbinfo->si_xib_buf = NULL;
37619 + fput(sbinfo->si_xib);
37620 + sbinfo->si_xib = NULL;
37621 + sbinfo->si_xread = NULL;
37622 + sbinfo->si_xwrite = NULL;
37627 +/* xino for each branch */
37628 +static void xino_clear_br(struct super_block *sb)
37630 + aufs_bindex_t bindex, bbot;
37631 + struct au_branch *br;
37633 + bbot = au_sbbot(sb);
37634 + for (bindex = 0; bindex <= bbot; bindex++) {
37635 + br = au_sbr(sb, bindex);
37636 + if (!br || !br->br_xino.xi_file)
37639 + fput(br->br_xino.xi_file);
37640 + br->br_xino.xi_file = NULL;
37644 +static int au_xino_set_br(struct super_block *sb, struct file *base)
37648 + aufs_bindex_t bindex, bbot, bshared;
37650 + struct file *old, *new;
37652 + struct au_branch *br;
37653 + struct inode *inode;
37654 + vfs_writef_t writef;
37656 + SiMustWriteLock(sb);
37659 + bbot = au_sbbot(sb);
37660 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
37661 + if (unlikely(!fpair))
37664 + inode = d_inode(sb->s_root);
37665 + ino = AUFS_ROOT_INO;
37666 + writef = au_sbi(sb)->si_xwrite;
37667 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
37668 + bshared = is_sb_shared(sb, bindex, bindex - 1);
37669 + if (bshared >= 0) {
37670 + /* shared xino */
37671 + *p = fpair[bshared];
37672 + get_file(p->new);
37677 + br = au_sbr(sb, bindex);
37678 + p->old = br->br_xino.xi_file;
37679 + p->new = au_xino_create2(base, br->br_xino.xi_file);
37680 + err = PTR_ERR(p->new);
37681 + if (IS_ERR(p->new)) {
37687 + err = au_xino_do_write(writef, p->new,
37688 + au_h_iptr(inode, bindex)->i_ino, ino);
37689 + if (unlikely(err))
37693 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
37694 + br = au_sbr(sb, bindex);
37695 + if (br->br_xino.xi_file)
37696 + fput(br->br_xino.xi_file);
37697 + get_file(p->new);
37698 + br->br_xino.xi_file = p->new;
37702 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
37712 +void au_xino_clr(struct super_block *sb)
37714 + struct au_sbinfo *sbinfo;
37716 + au_xigen_clr(sb);
37717 + xino_clear_xib(sb);
37718 + xino_clear_br(sb);
37719 + sbinfo = au_sbi(sb);
37720 + /* lvalue, do not call au_mntflags() */
37721 + au_opt_clr(sbinfo->si_mntflags, XINO);
37724 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
37727 + struct dentry *parent, *cur_parent;
37728 + struct qstr *dname, *cur_name;
37729 + struct file *cur_xino;
37730 + struct inode *dir;
37731 + struct au_sbinfo *sbinfo;
37733 + SiMustWriteLock(sb);
37736 + sbinfo = au_sbi(sb);
37737 + parent = dget_parent(xino->file->f_path.dentry);
37740 + dname = &xino->file->f_path.dentry->d_name;
37741 + cur_xino = sbinfo->si_xib;
37743 + cur_parent = dget_parent(cur_xino->f_path.dentry);
37744 + cur_name = &cur_xino->f_path.dentry->d_name;
37745 + skip = (cur_parent == parent
37746 + && au_qstreq(dname, cur_name));
37747 + dput(cur_parent);
37753 + au_opt_set(sbinfo->si_mntflags, XINO);
37754 + dir = d_inode(parent);
37755 + inode_lock_nested(dir, AuLsc_I_PARENT);
37756 + /* mnt_want_write() is unnecessary here */
37757 + err = au_xino_set_xib(sb, xino->file);
37759 + err = au_xigen_set(sb, xino->file);
37761 + err = au_xino_set_br(sb, xino->file);
37762 + inode_unlock(dir);
37764 + goto out; /* success */
37767 + AuIOErr("failed creating xino(%d).\n", err);
37768 + au_xigen_clr(sb);
37769 + xino_clear_xib(sb);
37776 +/* ---------------------------------------------------------------------- */
37779 + * create a xinofile at the default place/path.
37781 +struct file *au_xino_def(struct super_block *sb)
37783 + struct file *file;
37785 + struct au_branch *br;
37786 + struct super_block *h_sb;
37787 + struct path path;
37788 + aufs_bindex_t bbot, bindex, bwr;
37791 + bbot = au_sbbot(sb);
37793 + for (bindex = 0; bindex <= bbot; bindex++) {
37794 + br = au_sbr(sb, bindex);
37795 + if (au_br_writable(br->br_perm)
37796 + && !au_test_fs_bad_xino(au_br_sb(br))) {
37803 + file = ERR_PTR(-ENOMEM);
37804 + page = (void *)__get_free_page(GFP_NOFS);
37805 + if (unlikely(!page))
37807 + path.mnt = au_br_mnt(br);
37808 + path.dentry = au_h_dptr(sb->s_root, bwr);
37809 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
37810 + file = (void *)p;
37811 + if (!IS_ERR(p)) {
37812 + strcat(p, "/" AUFS_XINO_FNAME);
37813 + AuDbg("%s\n", p);
37814 + file = au_xino_create(sb, p, /*silent*/0);
37815 + if (!IS_ERR(file))
37816 + au_xino_brid_set(sb, br->br_id);
37818 + free_page((unsigned long)page);
37820 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
37821 + if (IS_ERR(file))
37823 + h_sb = file->f_path.dentry->d_sb;
37824 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
37825 + pr_err("xino doesn't support %s(%s)\n",
37826 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
37828 + file = ERR_PTR(-EINVAL);
37830 + if (!IS_ERR(file))
37831 + au_xino_brid_set(sb, -1);
37838 +/* ---------------------------------------------------------------------- */
37840 +int au_xino_path(struct seq_file *seq, struct file *file)
37844 + err = au_seq_path(seq, &file->f_path);
37845 + if (unlikely(err))
37848 +#define Deleted "\\040(deleted)"
37849 + seq->count -= sizeof(Deleted) - 1;
37850 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
37851 + sizeof(Deleted) - 1));
37858 +/* ---------------------------------------------------------------------- */
37860 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
37861 + ino_t h_ino, int idx)
37863 + struct au_xino_file *xino;
37865 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
37866 + xino = &au_sbr(sb, bindex)->br_xino;
37867 + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx);
37869 + spin_lock(&xino->xi_nondir.spin);
37870 + AuDebugOn(xino->xi_nondir.array[idx] != h_ino);
37871 + xino->xi_nondir.array[idx] = 0;
37872 + spin_unlock(&xino->xi_nondir.spin);
37873 + wake_up_all(&xino->xi_nondir.wqh);
37876 +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino)
37878 + int found, total, i;
37881 + total = xino->xi_nondir.total;
37882 + for (i = 0; i < total; i++) {
37883 + if (xino->xi_nondir.array[i] != h_ino)
37892 +static int au_xinondir_expand(struct au_xino_file *xino)
37897 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
37900 + sz = xino->xi_nondir.total * sizeof(ino_t);
37901 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
37903 + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
37904 + /*may_shrink*/0);
37906 + xino->xi_nondir.array = p;
37907 + xino->xi_nondir.total <<= 1;
37908 + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total);
37916 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37919 + int err, found, empty;
37920 + struct au_xino_file *xino;
37924 + if (!au_opt_test(au_mntflags(sb), XINO))
37925 + goto out; /* no xino */
37927 + xino = &au_sbr(sb, bindex)->br_xino;
37930 + spin_lock(&xino->xi_nondir.spin);
37931 + found = au_xinondir_find(xino, h_ino);
37932 + if (found == -1) {
37933 + empty = au_xinondir_find(xino, /*h_ino*/0);
37934 + if (empty == -1) {
37935 + empty = xino->xi_nondir.total;
37936 + err = au_xinondir_expand(xino);
37937 + if (unlikely(err))
37940 + xino->xi_nondir.array[empty] = h_ino;
37943 + spin_unlock(&xino->xi_nondir.spin);
37944 + wait_event(xino->xi_nondir.wqh,
37945 + xino->xi_nondir.array[found] != h_ino);
37950 + spin_unlock(&xino->xi_nondir.spin);
37954 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
37955 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
37956 +++ linux/include/uapi/linux/aufs_type.h 2018-06-15 11:15:32.107607516 +0200
37959 + * Copyright (C) 2005-2018 Junjiro R. Okajima
37961 + * This program, aufs is free software; you can redistribute it and/or modify
37962 + * it under the terms of the GNU General Public License as published by
37963 + * the Free Software Foundation; either version 2 of the License, or
37964 + * (at your option) any later version.
37966 + * This program is distributed in the hope that it will be useful,
37967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37969 + * GNU General Public License for more details.
37971 + * You should have received a copy of the GNU General Public License
37972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37975 +#ifndef __AUFS_TYPE_H__
37976 +#define __AUFS_TYPE_H__
37978 +#define AUFS_NAME "aufs"
37982 + * define it before including all other headers.
37983 + * sched.h may use pr_* macros before defining "current", so define the
37984 + * no-current version first, and re-define later.
37986 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
37987 +#include <linux/sched.h>
37989 +#define pr_fmt(fmt) \
37990 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
37991 + (int)sizeof(current->comm), current->comm, current->pid
37993 +#include <stdint.h>
37994 +#include <sys/types.h>
37995 +#endif /* __KERNEL__ */
37997 +#include <linux/limits.h>
37999 +#define AUFS_VERSION "4.17-20180611"
38001 +/* todo? move this to linux-2.6.19/include/magic.h */
38002 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38004 +/* ---------------------------------------------------------------------- */
38006 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38007 +typedef int8_t aufs_bindex_t;
38008 +#define AUFS_BRANCH_MAX 127
38010 +typedef int16_t aufs_bindex_t;
38011 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38012 +#define AUFS_BRANCH_MAX 511
38013 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38014 +#define AUFS_BRANCH_MAX 1023
38015 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38016 +#define AUFS_BRANCH_MAX 32767
38021 +#ifndef AUFS_BRANCH_MAX
38022 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38024 +#endif /* __KERNEL__ */
38026 +/* ---------------------------------------------------------------------- */
38028 +#define AUFS_FSTYPE AUFS_NAME
38030 +#define AUFS_ROOT_INO 2
38031 +#define AUFS_FIRST_INO 11
38033 +#define AUFS_WH_PFX ".wh."
38034 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38035 +#define AUFS_WH_TMP_LEN 4
38036 +/* a limit for rmdir/rename a dir and copyup */
38037 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38038 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38040 + - AUFS_WH_TMP_LEN) /* hex */
38041 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38042 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38043 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38044 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38045 +#define AUFS_DIRWH_DEF 3
38046 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38047 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38048 +#define AUFS_RDBLK_DEF 512 /* bytes */
38049 +#define AUFS_RDHASH_DEF 32
38050 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38051 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38052 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38053 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38054 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38056 +/* pseudo-link maintenace under /proc */
38057 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38058 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38059 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38061 +/* dirren, renamed dir */
38062 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38063 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38064 +/* whiteouted doubly */
38065 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38066 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38068 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38069 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38071 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38072 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38073 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38075 +/* doubly whiteouted */
38076 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38077 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38078 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38080 +/* branch permissions and attributes */
38081 +#define AUFS_BRPERM_RW "rw"
38082 +#define AUFS_BRPERM_RO "ro"
38083 +#define AUFS_BRPERM_RR "rr"
38084 +#define AUFS_BRATTR_COO_REG "coo_reg"
38085 +#define AUFS_BRATTR_COO_ALL "coo_all"
38086 +#define AUFS_BRATTR_FHSM "fhsm"
38087 +#define AUFS_BRATTR_UNPIN "unpin"
38088 +#define AUFS_BRATTR_ICEX "icex"
38089 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38090 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38091 +#define AUFS_BRATTR_ICEX_TR "icextr"
38092 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38093 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38094 +#define AUFS_BRRATTR_WH "wh"
38095 +#define AUFS_BRWATTR_NLWH "nolwh"
38096 +#define AUFS_BRWATTR_MOO "moo"
38098 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38099 +#define AuBrPerm_RO (1 << 1) /* readonly */
38100 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38101 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38103 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38104 +#define AuBrAttr_COO_ALL (1 << 4)
38105 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38107 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38108 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38109 + branch. meaningless since
38110 + linux-3.18-rc1 */
38112 +/* ignore error in copying XATTR */
38113 +#define AuBrAttr_ICEX_SEC (1 << 7)
38114 +#define AuBrAttr_ICEX_SYS (1 << 8)
38115 +#define AuBrAttr_ICEX_TR (1 << 9)
38116 +#define AuBrAttr_ICEX_USR (1 << 10)
38117 +#define AuBrAttr_ICEX_OTH (1 << 11)
38118 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38119 + | AuBrAttr_ICEX_SYS \
38120 + | AuBrAttr_ICEX_TR \
38121 + | AuBrAttr_ICEX_USR \
38122 + | AuBrAttr_ICEX_OTH)
38124 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38125 +#define AuBrRAttr_Mask AuBrRAttr_WH
38127 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38128 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38129 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38131 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38133 +/* #warning test userspace */
38135 +#ifndef CONFIG_AUFS_FHSM
38136 +#undef AuBrAttr_FHSM
38137 +#define AuBrAttr_FHSM 0
38139 +#ifndef CONFIG_AUFS_XATTR
38140 +#undef AuBrAttr_ICEX
38141 +#define AuBrAttr_ICEX 0
38142 +#undef AuBrAttr_ICEX_SEC
38143 +#define AuBrAttr_ICEX_SEC 0
38144 +#undef AuBrAttr_ICEX_SYS
38145 +#define AuBrAttr_ICEX_SYS 0
38146 +#undef AuBrAttr_ICEX_TR
38147 +#define AuBrAttr_ICEX_TR 0
38148 +#undef AuBrAttr_ICEX_USR
38149 +#define AuBrAttr_ICEX_USR 0
38150 +#undef AuBrAttr_ICEX_OTH
38151 +#define AuBrAttr_ICEX_OTH 0
38155 +/* the longest combination */
38156 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38157 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38158 + "+" AUFS_BRATTR_COO_REG \
38159 + "+" AUFS_BRATTR_FHSM \
38160 + "+" AUFS_BRATTR_UNPIN \
38161 + "+" AUFS_BRATTR_ICEX_SEC \
38162 + "+" AUFS_BRATTR_ICEX_SYS \
38163 + "+" AUFS_BRATTR_ICEX_USR \
38164 + "+" AUFS_BRATTR_ICEX_OTH \
38165 + "+" AUFS_BRWATTR_NLWH)
38168 + char a[AuBrPermStrSz];
38169 +} au_br_perm_str_t;
38171 +static inline int au_br_writable(int brperm)
38173 + return brperm & AuBrPerm_RW;
38176 +static inline int au_br_whable(int brperm)
38178 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38181 +static inline int au_br_wh_linkable(int brperm)
38183 + return !(brperm & AuBrWAttr_NoLinkWH);
38186 +static inline int au_br_cmoo(int brperm)
38188 + return brperm & AuBrAttr_CMOO_Mask;
38191 +static inline int au_br_fhsm(int brperm)
38193 + return brperm & AuBrAttr_FHSM;
38196 +/* ---------------------------------------------------------------------- */
38200 + /* readdir in userspace */
38204 + AuCtl_WBR_FD, /* pathconf wrapper */
38205 + AuCtl_IBUSY, /* busy inode */
38206 + AuCtl_MVDOWN, /* move-down */
38207 + AuCtl_BR, /* info about branches */
38208 + AuCtl_FHSM_FD /* connection for fhsm */
38211 +/* borrowed from linux/include/linux/kernel.h */
38213 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38214 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38217 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38219 +#define __aligned(x) __attribute__((aligned(x)))
38224 +#define __packed __attribute__((packed))
38228 +struct au_rdu_cookie {
38233 + uint32_t generation;
38236 +struct au_rdu_ent {
38245 +static inline int au_rdu_len(int nlen)
38247 + /* include the terminating NULL */
38248 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38249 + sizeof(uint64_t));
38252 +union au_rdu_ent_ul {
38253 + struct au_rdu_ent __user *e;
38265 + uint64_t sz; /* AuCtl_RDU */
38266 + uint64_t nent; /* AuCtl_RDU_INO */
38268 + union au_rdu_ent_ul ent;
38269 + uint16_t verify[AufsCtlRduV_End];
38271 + /* input/output */
38275 + union au_rdu_ent_ul tail;
38276 + /* number of entries which were added in a single call */
38281 + struct au_rdu_cookie cookie;
38284 +/* ---------------------------------------------------------------------- */
38286 +/* dirren. the branch is identified by the filename who contains this */
38287 +struct au_drinfo {
38290 + uint8_t oldnamelen;
38291 + uint64_t _padding;
38293 + uint8_t oldname[0];
38296 +struct au_drinfo_fdata {
38298 + struct au_drinfo drinfo;
38301 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38303 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38305 +/* ---------------------------------------------------------------------- */
38307 +struct aufs_wbr_fd {
38312 +/* ---------------------------------------------------------------------- */
38314 +struct aufs_ibusy {
38315 + uint64_t ino, h_ino;
38319 +/* ---------------------------------------------------------------------- */
38321 +/* error code for move-down */
38322 +/* the actual message strings are implemented in aufs-util.git */
38324 + EAU_MVDOWN_OPAQUE = 1,
38325 + EAU_MVDOWN_WHITEOUT,
38326 + EAU_MVDOWN_UPPER,
38327 + EAU_MVDOWN_BOTTOM,
38328 + EAU_MVDOWN_NOUPPER,
38329 + EAU_MVDOWN_NOLOWERBR,
38333 +/* flags for move-down */
38334 +#define AUFS_MVDOWN_DMSG 1
38335 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38336 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38337 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38338 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38339 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38340 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38341 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38342 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38343 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38344 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38345 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38346 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38348 +/* index for move-down */
38350 + AUFS_MVDOWN_UPPER,
38351 + AUFS_MVDOWN_LOWER,
38352 + AUFS_MVDOWN_NARRAY
38356 + * additional info of move-down
38357 + * number of free blocks and inodes.
38358 + * subset of struct kstatfs, but smaller and always 64bit.
38360 +struct aufs_stfs {
38361 + uint64_t f_blocks;
38362 + uint64_t f_bavail;
38363 + uint64_t f_files;
38364 + uint64_t f_ffree;
38367 +struct aufs_stbr {
38368 + int16_t brid; /* optional input */
38369 + int16_t bindex; /* output */
38370 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
38373 +struct aufs_mvdown {
38374 + uint32_t flags; /* input/output */
38375 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
38376 + int8_t au_errno; /* output */
38379 +/* ---------------------------------------------------------------------- */
38381 +union aufs_brinfo {
38382 + /* PATH_MAX may differ between kernel-space and user-space */
38383 + char _spacer[4096];
38391 +/* ---------------------------------------------------------------------- */
38393 +#define AuCtlType 'A'
38394 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
38395 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
38396 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
38397 + struct aufs_wbr_fd)
38398 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
38399 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
38400 + struct aufs_mvdown)
38401 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
38402 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
38404 +#endif /* __AUFS_TYPE_H__ */
38405 SPDX-License-Identifier: GPL-2.0
38406 aufs4.17 loopback patch
38408 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38409 index bc965e5..852868a 100644
38410 --- a/drivers/block/loop.c
38411 +++ b/drivers/block/loop.c
38412 @@ -622,6 +622,15 @@ static inline void loop_update_dio(struct loop_device *lo)
38416 +static struct file *loop_real_file(struct file *file)
38418 + struct file *f = NULL;
38420 + if (file->f_path.dentry->d_sb->s_op->real_loop)
38421 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
38425 static void loop_reread_partitions(struct loop_device *lo,
38426 struct block_device *bdev)
38428 @@ -656,6 +665,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38431 struct file *file, *old_file;
38432 + struct file *f, *virt_file = NULL, *old_virt_file;
38433 struct inode *inode;
38436 @@ -672,9 +682,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38440 + f = loop_real_file(file);
38442 + virt_file = file;
38447 inode = file->f_mapping->host;
38448 old_file = lo->lo_backing_file;
38449 + old_virt_file = lo->lo_backing_virt_file;
38453 @@ -689,6 +706,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38454 blk_mq_freeze_queue(lo->lo_queue);
38455 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
38456 lo->lo_backing_file = file;
38457 + lo->lo_backing_virt_file = virt_file;
38458 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
38459 mapping_set_gfp_mask(file->f_mapping,
38460 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
38461 @@ -696,12 +714,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38462 blk_mq_unfreeze_queue(lo->lo_queue);
38465 + if (old_virt_file)
38466 + fput(old_virt_file);
38467 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
38468 loop_reread_partitions(lo, bdev);
38478 @@ -895,7 +917,7 @@ static int loop_prepare_queue(struct loop_device *lo)
38479 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38480 struct block_device *bdev, unsigned int arg)
38482 - struct file *file, *f;
38483 + struct file *file, *f, *virt_file = NULL;
38484 struct inode *inode;
38485 struct address_space *mapping;
38487 @@ -909,6 +931,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38491 + f = loop_real_file(file);
38493 + virt_file = file;
38499 if (lo->lo_state != Lo_unbound)
38500 @@ -957,6 +985,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38501 lo->lo_device = bdev;
38502 lo->lo_flags = lo_flags;
38503 lo->lo_backing_file = file;
38504 + lo->lo_backing_virt_file = virt_file;
38505 lo->transfer = NULL;
38507 lo->lo_sizelimit = 0;
38508 @@ -990,6 +1019,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38515 /* This is safe: open() is still holding a reference. */
38516 module_put(THIS_MODULE);
38517 @@ -1036,6 +1067,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
38518 static int loop_clr_fd(struct loop_device *lo)
38520 struct file *filp = lo->lo_backing_file;
38521 + struct file *virt_filp = lo->lo_backing_virt_file;
38522 gfp_t gfp = lo->old_gfp_mask;
38523 struct block_device *bdev = lo->lo_device;
38525 @@ -1067,6 +1099,7 @@ static int loop_clr_fd(struct loop_device *lo)
38526 spin_lock_irq(&lo->lo_lock);
38527 lo->lo_state = Lo_rundown;
38528 lo->lo_backing_file = NULL;
38529 + lo->lo_backing_virt_file = NULL;
38530 spin_unlock_irq(&lo->lo_lock);
38532 loop_release_xfer(lo);
38533 @@ -1115,6 +1148,8 @@ static int loop_clr_fd(struct loop_device *lo)
38534 * bd_mutex which is usually taken before lo_ctl_mutex.
38542 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
38543 index b78de98..2bbbd92 100644
38544 --- a/drivers/block/loop.h
38545 +++ b/drivers/block/loop.h
38546 @@ -46,7 +46,7 @@ struct loop_device {
38547 int (*ioctl)(struct loop_device *, int cmd,
38548 unsigned long arg);
38550 - struct file * lo_backing_file;
38551 + struct file * lo_backing_file, *lo_backing_virt_file;
38552 struct block_device *lo_device;
38555 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
38556 index ad30f42..5caf353 100644
38557 --- a/fs/aufs/f_op.c
38558 +++ b/fs/aufs/f_op.c
38559 @@ -358,7 +358,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
38560 if (IS_ERR(h_file))
38563 - if (au_test_loopback_kthread()) {
38564 + if (0 && au_test_loopback_kthread()) {
38565 au_warn_loopback(h_file->f_path.dentry->d_sb);
38566 if (file->f_mapping != h_file->f_mapping) {
38567 file->f_mapping = h_file->f_mapping;
38568 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
38569 index 3e9d59a..42811d3 100644
38570 --- a/fs/aufs/loop.c
38571 +++ b/fs/aufs/loop.c
38572 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
38573 symbol_put(loop_backing_file);
38574 kfree(au_warn_loopback_array);
38577 +/* ---------------------------------------------------------------------- */
38579 +/* support the loopback block device insude aufs */
38581 +struct file *aufs_real_loop(struct file *file)
38585 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
38586 + fi_read_lock(file);
38587 + f = au_hf_top(file);
38588 + fi_read_unlock(file);
38592 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
38593 index dc3f3be..c33d060 100644
38594 --- a/fs/aufs/loop.h
38595 +++ b/fs/aufs/loop.h
38596 @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb);
38598 int au_loopback_init(void);
38599 void au_loopback_fin(void);
38601 +struct file *aufs_real_loop(struct file *file);
38603 +AuStub(struct file *, loop_backing_file, return NULL)
38605 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
38606 struct dentry *h_adding)
38607 AuStubInt0(au_test_loopback_kthread, void)
38608 @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
38610 AuStubInt0(au_loopback_init, void)
38611 AuStubVoid(au_loopback_fin, void)
38613 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
38614 #endif /* BLK_DEV_LOOP */
38616 #endif /* __KERNEL__ */
38617 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
38618 index 80644ef..19cde48 100644
38619 --- a/fs/aufs/super.c
38620 +++ b/fs/aufs/super.c
38621 @@ -843,7 +843,10 @@ static const struct super_operations aufs_sop = {
38622 .statfs = aufs_statfs,
38623 .put_super = aufs_put_super,
38624 .sync_fs = aufs_sync_fs,
38625 - .remount_fs = aufs_remount_fs
38626 + .remount_fs = aufs_remount_fs,
38627 +#ifdef CONFIG_AUFS_BDEV_LOOP
38628 + .real_loop = aufs_real_loop
38632 /* ---------------------------------------------------------------------- */
38633 diff --git a/include/linux/fs.h b/include/linux/fs.h
38634 index 09a2542..11a6346 100644
38635 --- a/include/linux/fs.h
38636 +++ b/include/linux/fs.h
38637 @@ -1852,6 +1852,10 @@ struct super_operations {
38638 struct shrink_control *);
38639 long (*free_cached_objects)(struct super_block *,
38640 struct shrink_control *);
38641 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
38643 + struct file *(*real_loop)(struct file *);