1 aufs3.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index ec35851..a059d62 100644
7 @@ -218,6 +218,7 @@ source "fs/sysv/Kconfig"
8 source "fs/ufs/Kconfig"
9 source "fs/exofs/Kconfig"
10 source "fs/f2fs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index a88ac48..162500e 100644
19 @@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index 68ceb97..0352fa4 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -58,6 +58,7 @@ header-y += atmsvc.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
36 aufs3.x-rcN base patch
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 1de6afa..082a271 100644
42 @@ -1865,6 +1865,20 @@ F: include/linux/audit.h
43 F: include/uapi/linux/audit.h
46 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
47 +M: "J. R. Okajima" <hooanon05g@gmail.com>
48 +L: linux-unionfs@vger.kernel.org
49 +L: aufs-users@lists.sourceforge.net (members only)
50 +W: http://aufs.sourceforge.net
51 +T: git://git.code.sf.net/p/aufs/aufs3-linux
52 +T: git://github.com/sfjro/aufs3-linux.git
54 +F: Documentation/filesystems/aufs/
55 +F: Documentation/ABI/testing/debugfs-aufs
56 +F: Documentation/ABI/testing/sysfs-aufs
58 +F: include/uapi/linux/aufs_type.h
60 AUXILIARY DISPLAY DRIVERS
61 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
62 W: http://miguelojeda.es/auxdisplay.htm
63 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
64 index d1f168b..a0da519 100644
65 --- a/drivers/block/loop.c
66 +++ b/drivers/block/loop.c
67 @@ -592,6 +592,24 @@ static inline int is_loop_device(struct file *file)
68 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
73 + * no get/put for file.
75 +struct file *loop_backing_file(struct super_block *sb)
78 + struct loop_device *l;
81 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
82 + l = sb->s_bdev->bd_disk->private_data;
83 + ret = l->lo_backing_file;
87 +EXPORT_SYMBOL(loop_backing_file);
89 /* loop sysfs attributes */
91 static ssize_t loop_attr_show(struct device *dev, char *page,
92 diff --git a/fs/dcache.c b/fs/dcache.c
93 index c71e373..b93a9f2 100644
96 @@ -1130,7 +1130,7 @@ enum d_walk_ret {
98 * The @enter() and @finish() callbacks are called with d_lock held.
100 -static void d_walk(struct dentry *parent, void *data,
101 +void d_walk(struct dentry *parent, void *data,
102 enum d_walk_ret (*enter)(void *, struct dentry *),
103 void (*finish)(void *))
105 diff --git a/fs/splice.c b/fs/splice.c
106 index 7968da9..beb9993 100644
109 @@ -1099,8 +1099,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
111 * Attempt to initiate a splice from pipe to file.
113 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
114 - loff_t *ppos, size_t len, unsigned int flags)
115 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
116 + loff_t *ppos, size_t len, unsigned int flags)
118 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
119 loff_t *, size_t, unsigned int);
120 @@ -1116,9 +1116,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
122 * Attempt to initiate a splice from a file to a pipe.
124 -static long do_splice_to(struct file *in, loff_t *ppos,
125 - struct pipe_inode_info *pipe, size_t len,
126 - unsigned int flags)
127 +long do_splice_to(struct file *in, loff_t *ppos,
128 + struct pipe_inode_info *pipe, size_t len,
129 + unsigned int flags)
131 ssize_t (*splice_read)(struct file *, loff_t *,
132 struct pipe_inode_info *, size_t, unsigned int);
133 diff --git a/include/linux/splice.h b/include/linux/splice.h
134 index da2751d..2e0fca6 100644
135 --- a/include/linux/splice.h
136 +++ b/include/linux/splice.h
137 @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
138 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
140 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
142 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
143 + loff_t *ppos, size_t len, unsigned int flags);
144 +extern long do_splice_to(struct file *in, loff_t *ppos,
145 + struct pipe_inode_info *pipe, size_t len,
146 + unsigned int flags);
148 aufs3.x-rcN mmap patch
150 diff --git a/fs/buffer.c b/fs/buffer.c
151 index 20805db..363569f 100644
154 @@ -2450,7 +2450,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
155 * Update file times before taking page lock. We may end up failing the
156 * fault so this update may be superfluous but who really cares...
158 - file_update_time(vma->vm_file);
159 + vma_file_update_time(vma);
161 ret = __block_page_mkwrite(vma, vmf, get_block);
162 sb_end_pagefault(sb);
163 diff --git a/fs/proc/base.c b/fs/proc/base.c
164 index 3f3d7ae..426bcc7 100644
167 @@ -1735,7 +1735,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
168 down_read(&mm->mmap_sem);
169 vma = find_exact_vma(mm, vm_start, vm_end);
170 if (vma && vma->vm_file) {
171 - *path = vma->vm_file->f_path;
172 + *path = vma_pr_or_file(vma)->f_path;
176 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
177 index d4a3574..1397181 100644
178 --- a/fs/proc/nommu.c
179 +++ b/fs/proc/nommu.c
180 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
181 file = region->vm_file;
184 - struct inode *inode = file_inode(region->vm_file);
185 + struct inode *inode;
187 + file = vmr_pr_or_file(region);
188 + inode = file_inode(file);
189 dev = inode->i_sb->s_dev;
192 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
193 index 6dee68d..9afa35d 100644
194 --- a/fs/proc/task_mmu.c
195 +++ b/fs/proc/task_mmu.c
196 @@ -279,7 +279,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
197 const char *name = NULL;
200 - struct inode *inode = file_inode(vma->vm_file);
201 + struct inode *inode;
203 + file = vma_pr_or_file(vma);
204 + inode = file_inode(file);
205 dev = inode->i_sb->s_dev;
207 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
208 @@ -1479,7 +1482,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
209 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
210 struct vm_area_struct *vma = v;
211 struct numa_maps *md = &numa_priv->md;
212 - struct file *file = vma->vm_file;
213 + struct file *file = vma_pr_or_file(vma);
214 struct mm_struct *mm = vma->vm_mm;
215 struct mm_walk walk = {
216 .hugetlb_entry = gather_hugetlb_stats,
217 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
218 index 599ec2e..de6cd6e 100644
219 --- a/fs/proc/task_nommu.c
220 +++ b/fs/proc/task_nommu.c
221 @@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
225 - struct inode *inode = file_inode(vma->vm_file);
226 + struct inode *inode;
228 + file = vma_pr_or_file(file);
229 + inode = file_inode(file);
230 dev = inode->i_sb->s_dev;
232 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
233 diff --git a/include/linux/mm.h b/include/linux/mm.h
234 index 47a9392..60bc29c 100644
235 --- a/include/linux/mm.h
236 +++ b/include/linux/mm.h
237 @@ -1254,6 +1254,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
242 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
243 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
245 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
246 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
248 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
250 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
252 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
253 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
255 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
256 +extern void vmr_do_fput(struct vm_region *, const char[], int);
258 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
260 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
261 +#endif /* CONFIG_MMU */
263 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
264 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
265 void *buf, int len, int write);
266 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
267 index 199a03a..ed38ea3 100644
268 --- a/include/linux/mm_types.h
269 +++ b/include/linux/mm_types.h
270 @@ -241,6 +241,7 @@ struct vm_region {
271 unsigned long vm_top; /* region allocated to here */
272 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
273 struct file *vm_file; /* the backing file or NULL */
274 + struct file *vm_prfile; /* the virtual backing file or NULL */
276 int vm_usage; /* region usage count (access under nommu_region_sem) */
277 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
278 @@ -305,6 +306,7 @@ struct vm_area_struct {
279 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
280 units, *not* PAGE_CACHE_SIZE */
281 struct file * vm_file; /* File we map to (can be NULL). */
282 + struct file *vm_prfile; /* shadow of vm_file */
283 void * vm_private_data; /* was vm_pte (shared mem) */
286 diff --git a/kernel/fork.c b/kernel/fork.c
287 index cf65139..f28a048 100644
290 @@ -430,7 +430,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
291 struct inode *inode = file_inode(file);
292 struct address_space *mapping = file->f_mapping;
296 if (tmp->vm_flags & VM_DENYWRITE)
297 atomic_dec(&inode->i_writecount);
298 i_mmap_lock_write(mapping);
299 diff --git a/mm/Makefile b/mm/Makefile
300 index 15dbe99..88e25b5 100644
303 @@ -21,7 +21,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
304 mm_init.o mmu_context.o percpu.o slab_common.o \
305 compaction.o vmacache.o \
306 interval_tree.o list_lru.o workingset.o \
308 + prfile.o debug.o $(mmu-y)
312 diff --git a/mm/filemap.c b/mm/filemap.c
313 index ad72420..8885258 100644
316 @@ -2064,7 +2064,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
317 int ret = VM_FAULT_LOCKED;
319 sb_start_pagefault(inode->i_sb);
320 - file_update_time(vma->vm_file);
321 + vma_file_update_time(vma);
323 if (page->mapping != inode->i_mapping) {
325 diff --git a/mm/madvise.c b/mm/madvise.c
326 index d551475..1ebf71b 100644
329 @@ -320,12 +320,12 @@ static long madvise_remove(struct vm_area_struct *vma,
330 * vma's reference to the file) can go away as soon as we drop
335 up_read(¤t->mm->mmap_sem);
336 error = vfs_fallocate(f,
337 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
338 offset, end - start);
341 down_read(¤t->mm->mmap_sem);
344 diff --git a/mm/memory.c b/mm/memory.c
345 index 97839f5..5e5d491 100644
348 @@ -2132,7 +2132,7 @@ reuse:
352 - file_update_time(vma->vm_file);
353 + vma_file_update_time(vma);
357 diff --git a/mm/mmap.c b/mm/mmap.c
358 index 9ec50a3..4a6a641 100644
361 @@ -274,7 +274,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
362 if (vma->vm_ops && vma->vm_ops->close)
363 vma->vm_ops->close(vma);
365 - fput(vma->vm_file);
367 mpol_put(vma_policy(vma));
368 kmem_cache_free(vm_area_cachep, vma);
370 @@ -886,7 +886,7 @@ again: remove_next = 1 + (end > next->vm_end);
373 uprobe_munmap(next, next->vm_start, next->vm_end);
378 anon_vma_merge(vma, next);
379 @@ -1671,8 +1671,8 @@ out:
387 /* Undo any partial mapping done by a device driver. */
388 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
389 @@ -2473,7 +2473,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
393 - get_file(new->vm_file);
396 if (new->vm_ops && new->vm_ops->open)
397 new->vm_ops->open(new);
398 @@ -2492,7 +2492,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
399 if (new->vm_ops && new->vm_ops->close)
400 new->vm_ops->close(new);
402 - fput(new->vm_file);
404 unlink_anon_vmas(new);
406 mpol_put(vma_policy(new));
407 @@ -2635,7 +2635,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
408 struct vm_area_struct *vma;
409 unsigned long populate = 0;
410 unsigned long ret = -EINVAL;
413 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
414 "See Documentation/vm/remap_file_pages.txt.\n",
415 @@ -2679,10 +2678,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
416 munlock_vma_pages_range(vma, start, start + size);
419 - file = get_file(vma->vm_file);
421 ret = do_mmap_pgoff(vma->vm_file, start, size,
422 prot, flags, pgoff, &populate);
426 up_write(&mm->mmap_sem);
428 @@ -2950,7 +2949,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
429 if (anon_vma_clone(new_vma, vma))
430 goto out_free_mempol;
431 if (new_vma->vm_file)
432 - get_file(new_vma->vm_file);
433 + vma_get_file(new_vma);
434 if (new_vma->vm_ops && new_vma->vm_ops->open)
435 new_vma->vm_ops->open(new_vma);
436 vma_link(mm, new_vma, prev, rb_link, rb_parent);
437 diff --git a/mm/msync.c b/mm/msync.c
438 index bb04d53..5c24c54 100644
441 @@ -84,10 +84,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
443 if ((flags & MS_SYNC) && file &&
444 (vma->vm_flags & VM_SHARED)) {
447 up_read(&mm->mmap_sem);
448 error = vfs_fsync_range(file, fstart, fend, 1);
451 if (error || start >= end)
453 down_read(&mm->mmap_sem);
454 diff --git a/mm/nommu.c b/mm/nommu.c
455 index 3fba2dc..870ce96 100644
458 @@ -693,7 +693,7 @@ static void __put_nommu_region(struct vm_region *region)
459 up_write(&nommu_region_sem);
462 - fput(region->vm_file);
465 /* IO memory and memory shared directly out of the pagecache
466 * from ramfs/tmpfs mustn't be released here */
467 @@ -858,7 +858,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
468 if (vma->vm_ops && vma->vm_ops->close)
469 vma->vm_ops->close(vma);
471 - fput(vma->vm_file);
473 put_nommu_region(vma->vm_region);
474 kmem_cache_free(vm_area_cachep, vma);
476 @@ -1398,7 +1398,7 @@ unsigned long do_mmap_pgoff(struct file *file,
477 goto error_just_free;
480 - fput(region->vm_file);
482 kmem_cache_free(vm_region_jar, region);
485 @@ -1474,10 +1474,10 @@ error_just_free:
486 up_write(&nommu_region_sem);
489 - fput(region->vm_file);
491 kmem_cache_free(vm_region_jar, region);
493 - fput(vma->vm_file);
495 kmem_cache_free(vm_area_cachep, vma);
496 kleave(" = %d", ret);
498 diff --git a/mm/prfile.c b/mm/prfile.c
500 index 0000000..6c145eb
505 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
506 + * in /proc/PID/maps.
507 + * Call these functions via macros defined in linux/mm.h.
509 + * See Documentation/filesystems/aufs/design/06mmap.txt
511 + * Copyright (c) 2014 Junjro R. Okajima
512 + * Copyright (c) 2014 Ian Campbell
515 +#include <linux/mm.h>
516 +#include <linux/file.h>
517 +#include <linux/fs.h>
519 +/* #define PRFILE_TRACE */
520 +static inline void prfile_trace(struct file *f, struct file *pr,
521 + const char func[], int line, const char func2[])
525 + pr_info("%s:%d: %s, %p\n", func, line, func2,
526 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
531 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
534 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
536 + prfile_trace(f, pr, func, line, __func__);
537 + file_update_time(f);
539 + file_update_time(pr);
542 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
545 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
547 + prfile_trace(f, pr, func, line, __func__);
548 + return (f && pr) ? pr : f;
551 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
553 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
555 + prfile_trace(f, pr, func, line, __func__);
561 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
563 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
565 + prfile_trace(f, pr, func, line, __func__);
571 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
574 + struct file *f = region->vm_file, *pr = region->vm_prfile;
576 + prfile_trace(f, pr, func, line, __func__);
577 + return (f && pr) ? pr : f;
580 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
582 + struct file *f = region->vm_file, *pr = region->vm_prfile;
584 + prfile_trace(f, pr, func, line, __func__);
589 +#endif /* CONFIG_MMU */
590 aufs3.x-rcN standalone patch
592 diff --git a/fs/dcache.c b/fs/dcache.c
593 index b93a9f2..5a010ee 100644
596 @@ -1235,6 +1235,7 @@ rename_retry:
600 +EXPORT_SYMBOL(d_walk);
603 * Search for at least 1 mount point in the dentry's subdirs.
604 diff --git a/fs/inode.c b/fs/inode.c
605 index f00b16f..eb7b8b5 100644
608 @@ -58,6 +58,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
609 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
611 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
612 +EXPORT_SYMBOL(inode_sb_list_lock);
615 * Empty aops. Can be used for the cases where the user does not
616 diff --git a/fs/namespace.c b/fs/namespace.c
617 index 82ef140..a3aa4b9 100644
620 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
621 mnt_dec_writers(real_mount(mnt));
624 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
627 * mnt_drop_write - give up write access to a mount
628 @@ -1718,6 +1719,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
632 +EXPORT_SYMBOL(iterate_mounts);
634 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
636 diff --git a/fs/notify/group.c b/fs/notify/group.c
637 index d16b62c..06ca6bc 100644
638 --- a/fs/notify/group.c
639 +++ b/fs/notify/group.c
641 #include <linux/srcu.h>
642 #include <linux/rculist.h>
643 #include <linux/wait.h>
644 +#include <linux/module.h>
646 #include <linux/fsnotify_backend.h>
647 #include "fsnotify.h"
648 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
650 atomic_inc(&group->refcnt);
652 +EXPORT_SYMBOL(fsnotify_get_group);
655 * Drop a reference to a group. Free it if it's through.
656 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
657 if (atomic_dec_and_test(&group->refcnt))
658 fsnotify_final_destroy_group(group);
660 +EXPORT_SYMBOL(fsnotify_put_group);
663 * Create a new fsnotify_group and hold a reference for the group returned.
664 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
668 +EXPORT_SYMBOL(fsnotify_alloc_group);
670 int fsnotify_fasync(int fd, struct file *file, int on)
672 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
673 index 92e48c7..d2c4b68 100644
674 --- a/fs/notify/mark.c
675 +++ b/fs/notify/mark.c
676 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
677 mark->free_mark(mark);
680 +EXPORT_SYMBOL(fsnotify_put_mark);
682 /* Calculate mask of events for a list of marks */
683 u32 fsnotify_recalc_mask(struct hlist_head *head)
684 @@ -202,6 +203,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
685 fsnotify_destroy_mark_locked(mark, group);
686 mutex_unlock(&group->mark_mutex);
688 +EXPORT_SYMBOL(fsnotify_destroy_mark);
691 * Destroy all marks in the given list. The marks must be already detached from
692 @@ -376,6 +378,7 @@ err:
696 +EXPORT_SYMBOL(fsnotify_add_mark);
698 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
699 struct inode *inode, struct vfsmount *mnt, int allow_dups)
700 @@ -455,6 +458,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
701 atomic_set(&mark->refcnt, 1);
702 mark->free_mark = free_mark;
704 +EXPORT_SYMBOL(fsnotify_init_mark);
706 static int fsnotify_mark_destroy(void *ignored)
708 diff --git a/fs/open.c b/fs/open.c
709 index 33f9cbf..2c8bd72 100644
712 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
713 mutex_unlock(&dentry->d_inode->i_mutex);
716 +EXPORT_SYMBOL(do_truncate);
718 long vfs_truncate(struct path *path, loff_t length)
720 diff --git a/fs/splice.c b/fs/splice.c
721 index beb9993..813275a 100644
724 @@ -1112,6 +1112,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
726 return splice_write(pipe, out, ppos, len, flags);
728 +EXPORT_SYMBOL(do_splice_from);
731 * Attempt to initiate a splice from a file to a pipe.
732 @@ -1138,6 +1139,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
734 return splice_read(in, ppos, pipe, len, flags);
736 +EXPORT_SYMBOL(do_splice_to);
739 * splice_direct_to_actor - splices data directly between two non-pipes
740 diff --git a/fs/xattr.c b/fs/xattr.c
741 index 4ef6985..6bb6303 100644
744 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
745 *xattr_value = value;
748 +EXPORT_SYMBOL(vfs_getxattr_alloc);
750 /* Compare an extended attribute value with the given value */
751 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
752 diff --git a/security/commoncap.c b/security/commoncap.c
753 index f66713b..fd4c4b8 100644
754 --- a/security/commoncap.c
755 +++ b/security/commoncap.c
756 @@ -975,9 +975,11 @@ int cap_mmap_addr(unsigned long addr)
760 +EXPORT_SYMBOL(cap_mmap_addr);
762 int cap_mmap_file(struct file *file, unsigned long reqprot,
763 unsigned long prot, unsigned long flags)
767 +EXPORT_SYMBOL(cap_mmap_file);
768 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
769 index 188c1d2..426d9af 100644
770 --- a/security/device_cgroup.c
771 +++ b/security/device_cgroup.c
773 #include <linux/device_cgroup.h>
774 #include <linux/cgroup.h>
775 #include <linux/ctype.h>
776 +#include <linux/export.h>
777 #include <linux/list.h>
778 #include <linux/uaccess.h>
779 #include <linux/seq_file.h>
780 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
781 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
784 +EXPORT_SYMBOL(__devcgroup_inode_permission);
786 int devcgroup_inode_mknod(int mode, dev_t dev)
788 diff --git a/security/security.c b/security/security.c
789 index e81d5bb..0b7b840 100644
790 --- a/security/security.c
791 +++ b/security/security.c
792 @@ -430,6 +430,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
794 return security_ops->path_rmdir(dir, dentry);
796 +EXPORT_SYMBOL(security_path_rmdir);
798 int security_path_unlink(struct path *dir, struct dentry *dentry)
800 @@ -446,6 +447,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
802 return security_ops->path_symlink(dir, dentry, old_name);
804 +EXPORT_SYMBOL(security_path_symlink);
806 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
807 struct dentry *new_dentry)
808 @@ -454,6 +456,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
810 return security_ops->path_link(old_dentry, new_dir, new_dentry);
812 +EXPORT_SYMBOL(security_path_link);
814 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
815 struct path *new_dir, struct dentry *new_dentry,
816 @@ -481,6 +484,7 @@ int security_path_truncate(struct path *path)
818 return security_ops->path_truncate(path);
820 +EXPORT_SYMBOL(security_path_truncate);
822 int security_path_chmod(struct path *path, umode_t mode)
824 @@ -488,6 +492,7 @@ int security_path_chmod(struct path *path, umode_t mode)
826 return security_ops->path_chmod(path, mode);
828 +EXPORT_SYMBOL(security_path_chmod);
830 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
832 @@ -495,6 +500,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
834 return security_ops->path_chown(path, uid, gid);
836 +EXPORT_SYMBOL(security_path_chown);
838 int security_path_chroot(struct path *path)
840 @@ -580,6 +586,7 @@ int security_inode_readlink(struct dentry *dentry)
842 return security_ops->inode_readlink(dentry);
844 +EXPORT_SYMBOL(security_inode_readlink);
846 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
848 @@ -594,6 +601,7 @@ int security_inode_permission(struct inode *inode, int mask)
850 return security_ops->inode_permission(inode, mask);
852 +EXPORT_SYMBOL(security_inode_permission);
854 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
856 @@ -716,6 +724,7 @@ int security_file_permission(struct file *file, int mask)
858 return fsnotify_perm(file, mask);
860 +EXPORT_SYMBOL(security_file_permission);
862 int security_file_alloc(struct file *file)
864 @@ -775,6 +784,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
866 return ima_file_mmap(file, prot);
868 +EXPORT_SYMBOL(security_mmap_file);
870 int security_mmap_addr(unsigned long addr)
872 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
873 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
874 +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-04-13 15:10:20.773489965 +0200
876 +What: /debug/aufs/si_<id>/
878 +Contact: J. R. Okajima <hooanon05g@gmail.com>
880 + Under /debug/aufs, a directory named si_<id> is created
881 + per aufs mount, where <id> is a unique id generated
884 +What: /debug/aufs/si_<id>/plink
886 +Contact: J. R. Okajima <hooanon05g@gmail.com>
888 + It has three lines and shows the information about the
889 + pseudo-link. The first line is a single number
890 + representing a number of buckets. The second line is a
891 + number of pseudo-links per buckets (separated by a
892 + blank). The last line is a single number representing a
893 + total number of psedo-links.
894 + When the aufs mount option 'noplink' is specified, it
895 + will show "1\n0\n0\n".
897 +What: /debug/aufs/si_<id>/xib
899 +Contact: J. R. Okajima <hooanon05g@gmail.com>
901 + It shows the consumed blocks by xib (External Inode Number
902 + Bitmap), its block size and file size.
903 + When the aufs mount option 'noxino' is specified, it
904 + will be empty. About XINO files, see the aufs manual.
906 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
908 +Contact: J. R. Okajima <hooanon05g@gmail.com>
910 + It shows the consumed blocks by xino (External Inode Number
911 + Translation Table), its link count, block size and file
913 + When the aufs mount option 'noxino' is specified, it
914 + will be empty. About XINO files, see the aufs manual.
916 +What: /debug/aufs/si_<id>/xigen
918 +Contact: J. R. Okajima <hooanon05g@gmail.com>
920 + It shows the consumed blocks by xigen (External Inode
921 + Generation Table), its block size and file size.
922 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
924 + When the aufs mount option 'noxino' is specified, it
925 + will be empty. About XINO files, see the aufs manual.
926 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
927 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
928 +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-04-13 15:10:20.773489965 +0200
930 +What: /sys/fs/aufs/si_<id>/
932 +Contact: J. R. Okajima <hooanon05g@gmail.com>
934 + Under /sys/fs/aufs, a directory named si_<id> is created
935 + per aufs mount, where <id> is a unique id generated
938 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
940 +Contact: J. R. Okajima <hooanon05g@gmail.com>
942 + It shows the abolute path of a member directory (which
943 + is called branch) in aufs, and its permission.
945 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
947 +Contact: J. R. Okajima <hooanon05g@gmail.com>
949 + It shows the id of a member directory (which is called
952 +What: /sys/fs/aufs/si_<id>/xi_path
954 +Contact: J. R. Okajima <hooanon05g@gmail.com>
956 + It shows the abolute path of XINO (External Inode Number
957 + Bitmap, Translation Table and Generation Table) file
958 + even if it is the default path.
959 + When the aufs mount option 'noxino' is specified, it
960 + will be empty. About XINO files, see the aufs manual.
961 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
962 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
963 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-04-13 15:10:20.773489965 +0200
966 +# Copyright (C) 2005-2015 Junjiro R. Okajima
968 +# This program is free software; you can redistribute it and/or modify
969 +# it under the terms of the GNU General Public License as published by
970 +# the Free Software Foundation; either version 2 of the License, or
971 +# (at your option) any later version.
973 +# This program is distributed in the hope that it will be useful,
974 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
975 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
976 +# GNU General Public License for more details.
978 +# You should have received a copy of the GNU General Public License
979 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
982 +----------------------------------------
984 +aufs [ei ju: ef es] | [a u f s]
985 +1. abbrev. for "advanced multi-layered unification filesystem".
986 +2. abbrev. for "another unionfs".
987 +3. abbrev. for "auf das" in German which means "on the" in English.
988 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
989 + But "Filesystem aufs Filesystem" is hard to understand.
991 +AUFS is a filesystem with features:
992 +- multi layered stackable unification filesystem, the member directory
993 + is called as a branch.
994 +- branch permission and attribute, 'readonly', 'real-readonly',
995 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
997 +- internal "file copy-on-write".
998 +- logical deletion, whiteout.
999 +- dynamic branch manipulation, adding, deleting and changing permission.
1000 +- allow bypassing aufs, user's direct branch access.
1001 +- external inode number translation table and bitmap which maintains the
1002 + persistent aufs inode number.
1003 +- seekable directory, including NFS readdir.
1004 +- file mapping, mmap and sharing pages.
1005 +- pseudo-link, hardlink over branches.
1006 +- loopback mounted filesystem as a branch.
1007 +- several policies to select one among multiple writable branches.
1008 +- revert a single systemcall when an error occurs in aufs.
1012 +Multi Layered Stackable Unification Filesystem
1013 +----------------------------------------------------------------------
1014 +Most people already knows what it is.
1015 +It is a filesystem which unifies several directories and provides a
1016 +merged single directory. When users access a file, the access will be
1017 +passed/re-directed/converted (sorry, I am not sure which English word is
1018 +correct) to the real file on the member filesystem. The member
1019 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1020 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1021 +readonly branch is handled by creating 'whiteout' on the upper writable
1024 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1025 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1026 +different approaches to implement the merged-view.
1027 +The former tries putting it into VFS, and the latter implements as a
1028 +separate filesystem.
1029 +(If I misunderstand about these implementations, please let me know and
1030 +I shall correct it. Because it is a long time ago when I read their
1031 +source files last time).
1033 +UnionMount's approach will be able to small, but may be hard to share
1034 +branches between several UnionMount since the whiteout in it is
1035 +implemented in the inode on branch filesystem and always
1036 +shared. According to Bharata's post, readdir does not seems to be
1038 +There are several missing features known in this implementations such as
1039 +- for users, the inode number may change silently. eg. copy-up.
1040 +- link(2) may break by copy-up.
1041 +- read(2) may get an obsoleted filedata (fstat(2) too).
1042 +- fcntl(F_SETLK) may be broken by copy-up.
1043 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1046 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1047 +merged into mainline. This is another implementation of UnionMount as a
1048 +separated filesystem. All the limitations and known problems which
1049 +UnionMount are equally inherited to "overlay" filesystem.
1051 +Unionfs has a longer history. When I started implementing a stackable
1052 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1053 +inode, dentry and file objects and they have an array pointing lower
1054 +same kind objects. After contributing many patches for Unionfs, I
1055 +re-started my project AUFS (Jun 2006).
1057 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1058 +implemented my own ideas, approaches and enhancements and it became
1059 +totally different one.
1061 +Comparing DM snapshot and fs based implementation
1062 +- the number of bytes to be copied between devices is much smaller.
1063 +- the type of filesystem must be one and only.
1064 +- the fs must be writable, no readonly fs, even for the lower original
1065 + device. so the compression fs will not be usable. but if we use
1066 + loopback mount, we may address this issue.
1068 + mount /cdrom/squashfs.img /sq
1069 + losetup /sq/ext2.img
1070 + losetup /somewhere/cow
1071 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1072 +- it will be difficult (or needs more operations) to extract the
1073 + difference between the original device and COW.
1074 +- DM snapshot-merge may help a lot when users try merging. in the
1075 + fs-layer union, users will use rsync(1).
1077 +You may want to read my old paper "Filesystems in LiveCD"
1078 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1081 +Several characters/aspects/persona of aufs
1082 +----------------------------------------------------------------------
1084 +Aufs has several characters, aspects or persona.
1085 +1. a filesystem, callee of VFS helper
1086 +2. sub-VFS, caller of VFS helper for branches
1087 +3. a virtual filesystem which maintains persistent inode number
1088 +4. reader/writer of files on branches such like an application
1090 +1. Callee of VFS Helper
1091 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1092 +unlink(2) from an application reaches sys_unlink() kernel function and
1093 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1094 +calls filesystem specific unlink operation. Actually aufs implements the
1095 +unlink operation but it behaves like a redirector.
1097 +2. Caller of VFS Helper for Branches
1098 +aufs_unlink() passes the unlink request to the branch filesystem as if
1099 +it were called from VFS. So the called unlink operation of the branch
1100 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1101 +every necessary pre/post operation for the branch filesystem.
1102 +- acquire the lock for the parent dir on a branch
1103 +- lookup in a branch
1104 +- revalidate dentry on a branch
1105 +- mnt_want_write() for a branch
1106 +- vfs_unlink() for a branch
1107 +- mnt_drop_write() for a branch
1108 +- release the lock on a branch
1110 +3. Persistent Inode Number
1111 +One of the most important issue for a filesystem is to maintain inode
1112 +numbers. This is particularly important to support exporting a
1113 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1114 +backend block device for its own. But some storage is necessary to
1115 +keep and maintain the inode numbers. It may be a large space and may not
1116 +suit to keep in memory. Aufs rents some space from its first writable
1117 +branch filesystem (by default) and creates file(s) on it. These files
1118 +are created by aufs internally and removed soon (currently) keeping
1120 +Note: Because these files are removed, they are totally gone after
1121 + unmounting aufs. It means the inode numbers are not persistent
1122 + across unmount or reboot. I have a plan to make them really
1123 + persistent which will be important for aufs on NFS server.
1125 +4. Read/Write Files Internally (copy-on-write)
1126 +Because a branch can be readonly, when you write a file on it, aufs will
1127 +"copy-up" it to the upper writable branch internally. And then write the
1128 +originally requested thing to the file. Generally kernel doesn't
1129 +open/read/write file actively. In aufs, even a single write may cause a
1130 +internal "file copy". This behaviour is very similar to cp(1) command.
1132 +Some people may think it is better to pass such work to user space
1133 +helper, instead of doing in kernel space. Actually I am still thinking
1134 +about it. But currently I have implemented it in kernel space.
1135 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1136 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1137 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-04-13 15:10:20.773489965 +0200
1140 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1142 +# This program is free software; you can redistribute it and/or modify
1143 +# it under the terms of the GNU General Public License as published by
1144 +# the Free Software Foundation; either version 2 of the License, or
1145 +# (at your option) any later version.
1147 +# This program is distributed in the hope that it will be useful,
1148 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1149 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1150 +# GNU General Public License for more details.
1152 +# You should have received a copy of the GNU General Public License
1153 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1155 +Basic Aufs Internal Structure
1157 +Superblock/Inode/Dentry/File Objects
1158 +----------------------------------------------------------------------
1159 +As like an ordinary filesystem, aufs has its own
1160 +superblock/inode/dentry/file objects. All these objects have a
1161 +dynamically allocated array and store the same kind of pointers to the
1162 +lower filesystem, branch.
1163 +For example, when you build a union with one readwrite branch and one
1164 +readonly, mounted /au, /rw and /ro respectively.
1166 +- /ro/fileA exists but /rw/fileA
1168 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1169 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1170 +- [0] = NULL (because /rw/fileA doesn't exist)
1173 +This style of an array is essentially same to the aufs
1174 +superblock/inode/dentry/file objects.
1176 +Because aufs supports manipulating branches, ie. add/delete/change
1177 +branches dynamically, these objects has its own generation. When
1178 +branches are changed, the generation in aufs superblock is
1179 +incremented. And a generation in other object are compared when it is
1180 +accessed. When a generation in other objects are obsoleted, aufs
1181 +refreshes the internal array.
1185 +----------------------------------------------------------------------
1186 +Additionally aufs superblock has some data for policies to select one
1187 +among multiple writable branches, XIB files, pseudo-links and kobject.
1188 +See below in detail.
1189 +About the policies which supports copy-down a directory, see
1190 +wbr_policy.txt too.
1193 +Branch and XINO(External Inode Number Translation Table)
1194 +----------------------------------------------------------------------
1195 +Every branch has its own xino (external inode number translation table)
1196 +file. The xino file is created and unlinked by aufs internally. When two
1197 +members of a union exist on the same filesystem, they share the single
1199 +The struct of a xino file is simple, just a sequence of aufs inode
1200 +numbers which is indexed by the lower inode number.
1201 +In the above sample, assume the inode number of /ro/fileA is i111 and
1202 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1203 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1205 +When the inode numbers are not contiguous, the xino file will be sparse
1206 +which has a hole in it and doesn't consume as much disk space as it
1207 +might appear. If your branch filesystem consumes disk space for such
1208 +holes, then you should specify 'xino=' option at mounting aufs.
1210 +Aufs has a mount option to free the disk blocks for such holes in XINO
1211 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1212 +meet a problem of disk shortage due to XINO files, then you should try
1213 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1214 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1215 +the holes in XINO files.
1217 +Also a writable branch has three kinds of "whiteout bases". All these
1218 +are existed when the branch is joined to aufs, and their names are
1219 +whiteout-ed doubly, so that users will never see their names in aufs
1221 +1. a regular file which will be hardlinked to all whiteouts.
1222 +2. a directory to store a pseudo-link.
1223 +3. a directory to store an "orphan"-ed file temporary.
1226 + When you remove a file on a readonly branch, aufs handles it as a
1227 + logical deletion and creates a whiteout on the upper writable branch
1228 + as a hardlink of this file in order not to consume inode on the
1231 + See below, Pseudo-link.
1233 + When "fileC" exists on the lower readonly branch only and it is
1234 + opened and removed with its parent dir, and then user writes
1235 + something into it, then aufs copies-up fileC to this
1236 + directory. Because there is no other dir to store fileC. After
1237 + creating a file under this dir, the file is unlinked.
1239 +Because aufs supports manipulating branches, ie. add/delete/change
1240 +dynamically, a branch has its own id. When the branch order changes,
1241 +aufs finds the new index by searching the branch id.
1245 +----------------------------------------------------------------------
1246 +Assume "fileA" exists on the lower readonly branch only and it is
1247 +hardlinked to "fileB" on the branch. When you write something to fileA,
1248 +aufs copies-up it to the upper writable branch. Additionally aufs
1249 +creates a hardlink under the Pseudo-link Directory of the writable
1250 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1251 +simple list. If fileB is read after unlinking fileA, aufs returns
1252 +filedata from the pseudo-link instead of the lower readonly
1253 +branch. Because the pseudo-link is based upon the inode, to keep the
1254 +inode number by xino (see above) is essentially necessary.
1256 +All the hardlinks under the Pseudo-link Directory of the writable branch
1257 +should be restored in a proper location later. Aufs provides a utility
1258 +to do this. The userspace helpers executed at remounting and unmounting
1260 +During this utility is running, it puts aufs into the pseudo-link
1261 +maintenance mode. In this mode, only the process which began the
1262 +maintenance mode (and its child processes) is allowed to operate in
1263 +aufs. Some other processes which are not related to the pseudo-link will
1264 +be allowed to run too, but the rest have to return an error or wait
1265 +until the maintenance mode ends. If a process already acquires an inode
1266 +mutex (in VFS), it has to return an error.
1269 +XIB(external inode number bitmap)
1270 +----------------------------------------------------------------------
1271 +Addition to the xino file per a branch, aufs has an external inode number
1272 +bitmap in a superblock object. It is also an internal file such like a
1274 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1276 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1278 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1279 +reduce the number of consumed disk blocks for these files.
1282 +Virtual or Vertical Dir, and Readdir in Userspace
1283 +----------------------------------------------------------------------
1284 +In order to support multiple layers (branches), aufs readdir operation
1285 +constructs a virtual dir block on memory. For readdir, aufs calls
1286 +vfs_readdir() internally for each dir on branches, merges their entries
1287 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1288 +object. So the file object has its entry list until it is closed. The
1289 +entry list will be updated when the file position is zero and becomes
1290 +obsoleted. This decision is made in aufs automatically.
1292 +The dynamically allocated memory block for the name of entries has a
1293 +unit of 512 bytes (by default) and stores the names contiguously (no
1294 +padding). Another block for each entry is handled by kmem_cache too.
1295 +During building dir blocks, aufs creates hash list and judging whether
1296 +the entry is whiteouted by its upper branch or already listed.
1297 +The merged result is cached in the corresponding inode object and
1298 +maintained by a customizable life-time option.
1300 +Some people may call it can be a security hole or invite DoS attack
1301 +since the opened and once readdir-ed dir (file object) holds its entry
1302 +list and becomes a pressure for system memory. But I'd say it is similar
1303 +to files under /proc or /sys. The virtual files in them also holds a
1304 +memory page (generally) while they are opened. When an idea to reduce
1305 +memory for them is introduced, it will be applied to aufs too.
1306 +For those who really hate this situation, I've developed readdir(3)
1307 +library which operates this merging in userspace. You just need to set
1308 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1309 +kernel space for readdir(3).
1313 +----------------------------------------------------------------------
1314 +Aufs sometimes requires privilege access to a branch. For instance,
1315 +in copy-up/down operation. When a user process is going to make changes
1316 +to a file which exists in the lower readonly branch only, and the mode
1317 +of one of ancestor directories may not be writable by a user
1318 +process. Here aufs copy-up the file with its ancestors and they may
1319 +require privilege to set its owner/group/mode/etc.
1320 +This is a typical case of a application character of aufs (see
1323 +Aufs uses workqueue synchronously for this case. It creates its own
1324 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1325 +passes the request to call mkdir or write (for example), and wait for
1326 +its completion. This approach solves a problem of a signal handler
1328 +If aufs didn't adopt the workqueue and changed the privilege of the
1329 +process, then the process may receive the unexpected SIGXFSZ or other
1332 +Also aufs uses the system global workqueue ("events" kernel thread) too
1333 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1334 +whiteout base and etc. This is unrelated to a privilege.
1335 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1336 +superblock at the beginning, at the same time waits for the completion
1337 +of all queued asynchronous tasks.
1341 +----------------------------------------------------------------------
1342 +The whiteout in aufs is very similar to Unionfs's. That is represented
1343 +by its filename. UnionMount takes an approach of a file mode, but I am
1344 +afraid several utilities (find(1) or something) will have to support it.
1346 +Basically the whiteout represents "logical deletion" which stops aufs to
1347 +lookup further, but also it represents "dir is opaque" which also stop
1350 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1351 +In order to make several functions in a single systemcall to be
1352 +revertible, aufs adopts an approach to rename a directory to a temporary
1353 +unique whiteouted name.
1354 +For example, in rename(2) dir where the target dir already existed, aufs
1355 +renames the target dir to a temporary unique whiteouted name before the
1356 +actual rename on a branch, and then handles other actions (make it opaque,
1357 +update the attributes, etc). If an error happens in these actions, aufs
1358 +simply renames the whiteouted name back and returns an error. If all are
1359 +succeeded, aufs registers a function to remove the whiteouted unique
1360 +temporary name completely and asynchronously to the system global
1365 +----------------------------------------------------------------------
1366 +It is a well-known feature or concept.
1367 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1368 +internally and makes change to the new file on the upper writable branch.
1369 +When the trigger systemcall does not update the timestamps of the parent
1370 +dir, aufs reverts it after copy-up.
1373 +Move-down (aufs3.9 and later)
1374 +----------------------------------------------------------------------
1375 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1376 +the lower readonly branch to the upper writable branch when a user
1377 +changes something about the file.
1378 +"Move-down" is an opposite action of copy-up. Basically this action is
1379 +ran manually instead of automatically and internally.
1380 +For desgin and implementation, aufs has to consider these issues.
1381 +- whiteout for the file may exist on the lower branch.
1382 +- ancestor directories may not exist on the lower branch.
1383 +- diropq for the ancestor directories may exist on the upper branch.
1384 +- free space on the lower branch will reduce.
1385 +- another access to the file may happen during moving-down, including
1386 + UDBA (see "Revalidate Dentry and UDBA").
1387 +- the file should not be hard-linked nor pseudo-linked. they should be
1388 + handled by auplink utility later.
1390 +Sometimes users want to move-down a file from the upper writable branch
1391 +to the lower readonly or writable branch. For instance,
1392 +- the free space of the upper writable branch is going to run out.
1393 +- create a new intermediate branch between the upper and lower branch.
1396 +For this purpose, use "aumvdown" command in aufs-util.git.
1397 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1398 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1399 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-04-13 15:10:20.776823376 +0200
1402 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1404 +# This program is free software; you can redistribute it and/or modify
1405 +# it under the terms of the GNU General Public License as published by
1406 +# the Free Software Foundation; either version 2 of the License, or
1407 +# (at your option) any later version.
1409 +# This program is distributed in the hope that it will be useful,
1410 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1411 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1412 +# GNU General Public License for more details.
1414 +# You should have received a copy of the GNU General Public License
1415 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1418 +----------------------------------------------------------------------
1419 +Since aufs has a character of sub-VFS (see Introduction), it operates
1420 +lookup for branches as VFS does. It may be a heavy work. But almost all
1421 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1422 +directly connected to its parent. Digging down the directory hierarchy
1423 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1426 +When a branch is a remote filesystem, aufs basically relies upon its
1427 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1429 +For d_revalidate, aufs implements three levels of revalidate tests. See
1430 +"Revalidate Dentry and UDBA" in detail.
1433 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1434 +----------------------------------------------------------------------
1435 +Let's try case study.
1436 +- aufs has two branches, upper readwrite and lower readonly.
1438 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1439 +- user invoked "chmod a+rx /au/dirA"
1440 +- the internal copy-up is activated and "/rw/dirA" is created and its
1441 + permission bits are set to world readable.
1442 +- then "/au/dirA" becomes world readable?
1444 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1445 +or it may be a natively readonly filesystem. If aufs respects the lower
1446 +branch, it should not respond readdir request from other users. But user
1447 +allowed it by chmod. Should really aufs rejects showing the entries
1450 +To be honest, I don't have a good solution for this case. So aufs
1451 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1453 +When dirperm1 is specified, aufs checks only the highest one for the
1454 +directory permission, and shows the entries. Otherwise, as usual, checks
1455 +every dir existing on all branches and rejects the request.
1457 +As a side effect, dirperm1 option improves the performance of aufs
1458 +because the number of permission check is reduced when the number of
1462 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1463 +----------------------------------------------------------------------
1464 +Generally VFS helpers re-validate a dentry as a part of lookup.
1465 +0. digging down the directory hierarchy.
1466 +1. lock the parent dir by its i_mutex.
1467 +2. lookup the final (child) entry.
1469 +4. call the actual operation (create, unlink, etc.)
1470 +5. unlock the parent dir
1472 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1473 +called. Actually aufs implements it and checks the dentry on a branch is
1475 +But it is not enough. Because aufs has to release the lock for the
1476 +parent dir on a branch at the end of ->lookup() (step 2) and
1477 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1479 +If the file on a branch is changed directly, eg. bypassing aufs, after
1480 +aufs released the lock, then the subsequent operation may cause
1481 +something unpleasant result.
1483 +This situation is a result of VFS architecture, ->lookup() and
1484 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1485 +design from VFS's point of view. It is just not suitable for sub-VFS
1488 +Aufs supports such case by three level of revalidation which is
1489 +selectable by user.
1490 +1. Simple Revalidate
1491 + Addition to the native flow in VFS's, confirm the child-parent
1492 + relationship on the branch just after locking the parent dir on the
1493 + branch in the "actual operation" (step 4). When this validation
1494 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1495 + checks the validation of the dentry on branches.
1496 +2. Monitor Changes Internally by Inotify/Fsnotify
1497 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1498 + the dentry on the branch, and returns EBUSY if it finds different
1500 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1501 + during it is in cache. When the event is notified, aufs registers a
1502 + function to kernel 'events' thread by schedule_work(). And the
1503 + function sets some special status to the cached aufs dentry and inode
1504 + private data. If they are not cached, then aufs has nothing to
1505 + do. When the same file is accessed through aufs (step 0-3) later,
1506 + aufs will detect the status and refresh all necessary data.
1507 + In this mode, aufs has to ignore the event which is fired by aufs
1509 +3. No Extra Validation
1510 + This is the simplest test and doesn't add any additional revalidation
1511 + test, and skip the revalidation in step 4. It is useful and improves
1512 + aufs performance when system surely hide the aufs branches from user,
1513 + by over-mounting something (or another method).
1514 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1515 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1516 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-04-13 15:10:20.776823376 +0200
1519 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1521 +# This program is free software; you can redistribute it and/or modify
1522 +# it under the terms of the GNU General Public License as published by
1523 +# the Free Software Foundation; either version 2 of the License, or
1524 +# (at your option) any later version.
1526 +# This program is distributed in the hope that it will be useful,
1527 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1528 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1529 +# GNU General Public License for more details.
1531 +# You should have received a copy of the GNU General Public License
1532 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1534 +Branch Manipulation
1536 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1537 +and changing its permission/attribute, there are a lot of works to do.
1541 +----------------------------------------------------------------------
1542 +o Confirm the adding dir exists outside of aufs, including loopback
1543 + mount, and its various attributes.
1544 +o Initialize the xino file and whiteout bases if necessary.
1547 +o Check the owner/group/mode of the directory
1548 + When the owner/group/mode of the adding directory differs from the
1549 + existing branch, aufs issues a warning because it may impose a
1551 + For example, when a upper writable branch has a world writable empty
1552 + top directory, a malicious user can create any files on the writable
1553 + branch directly, like copy-up and modify manually. If something like
1554 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1555 + writable branch, and the writable branch is world-writable, then a
1556 + malicious guy may create /etc/passwd on the writable branch directly
1557 + and the infected file will be valid in aufs.
1558 + I am afraid it can be a security issue, but aufs can do nothing except
1559 + producing a warning.
1563 +----------------------------------------------------------------------
1564 +o Confirm the deleting branch is not busy
1565 + To be general, there is one merit to adopt "remount" interface to
1566 + manipulate branches. It is to discard caches. At deleting a branch,
1567 + aufs checks the still cached (and connected) dentries and inodes. If
1568 + there are any, then they are all in-use. An inode without its
1569 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1571 + For the cached one, aufs checks whether the same named entry exists on
1573 + If the cached one is a directory, because aufs provides a merged view
1574 + to users, as long as one dir is left on any branch aufs can show the
1575 + dir to users. In this case, the branch can be removed from aufs.
1576 + Otherwise aufs rejects deleting the branch.
1578 + If any file on the deleting branch is opened by aufs, then aufs
1582 +Modify the Permission of a Branch
1583 +----------------------------------------------------------------------
1584 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1587 +o rw --> ro: Confirm the modifying branch is not busy
1588 + Aufs rejects the request if any of these conditions are true.
1589 + - a file on the branch is mmap-ed.
1590 + - a regular file on the branch is opened for write and there is no
1591 + same named entry on the upper branch.
1592 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1593 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1594 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-04-13 15:10:20.776823376 +0200
1597 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1599 +# This program is free software; you can redistribute it and/or modify
1600 +# it under the terms of the GNU General Public License as published by
1601 +# the Free Software Foundation; either version 2 of the License, or
1602 +# (at your option) any later version.
1604 +# This program is distributed in the hope that it will be useful,
1605 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1606 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1607 +# GNU General Public License for more details.
1609 +# You should have received a copy of the GNU General Public License
1610 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1612 +Policies to Select One among Multiple Writable Branches
1613 +----------------------------------------------------------------------
1614 +When the number of writable branch is more than one, aufs has to decide
1615 +the target branch for file creation or copy-up. By default, the highest
1616 +writable branch which has the parent (or ancestor) dir of the target
1617 +file is chosen (top-down-parent policy).
1618 +By user's request, aufs implements some other policies to select the
1619 +writable branch, for file creation several policies, round-robin,
1620 +most-free-space, and other policies. For copy-up, top-down-parent,
1621 +bottom-up-parent, bottom-up and others.
1623 +As expected, the round-robin policy selects the branch in circular. When
1624 +you have two writable branches and creates 10 new files, 5 files will be
1625 +created for each branch. mkdir(2) systemcall is an exception. When you
1626 +create 10 new directories, all will be created on the same branch.
1627 +And the most-free-space policy selects the one which has most free
1628 +space among the writable branches. The amount of free space will be
1629 +checked by aufs internally, and users can specify its time interval.
1631 +The policies for copy-up is more simple,
1632 +top-down-parent is equivalent to the same named on in create policy,
1633 +bottom-up-parent selects the writable branch where the parent dir
1634 +exists and the nearest upper one from the copyup-source,
1635 +bottom-up selects the nearest upper writable branch from the
1636 +copyup-source, regardless the existence of the parent dir.
1638 +There are some rules or exceptions to apply these policies.
1639 +- If there is a readonly branch above the policy-selected branch and
1640 + the parent dir is marked as opaque (a variation of whiteout), or the
1641 + target (creating) file is whiteout-ed on the upper readonly branch,
1642 + then the result of the policy is ignored and the target file will be
1643 + created on the nearest upper writable branch than the readonly branch.
1644 +- If there is a writable branch above the policy-selected branch and
1645 + the parent dir is marked as opaque or the target file is whiteouted
1646 + on the branch, then the result of the policy is ignored and the target
1647 + file will be created on the highest one among the upper writable
1648 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1650 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1651 + They try selecting the branch where the source exists as possible
1652 + since copyup a large file will take long time. If it can't be,
1653 + ie. the branch where the source exists is readonly, then they will
1654 + follow the copyup policy.
1655 +- There is an exception for rename(2) when the target exists.
1656 + If the rename target exists, aufs compares the index of the branches
1657 + where the source and the target exists and selects the higher
1658 + one. If the selected branch is readonly, then aufs follows the
1660 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1661 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1662 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-04-13 15:10:20.776823376 +0200
1665 +# Copyright (C) 2011-2015 Junjiro R. Okajima
1667 +# This program is free software; you can redistribute it and/or modify
1668 +# it under the terms of the GNU General Public License as published by
1669 +# the Free Software Foundation; either version 2 of the License, or
1670 +# (at your option) any later version.
1672 +# This program is distributed in the hope that it will be useful,
1673 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1674 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1675 +# GNU General Public License for more details.
1677 +# You should have received a copy of the GNU General Public License
1678 +# along with this program; if not, write to the Free Software
1679 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1682 +File-based Hierarchical Storage Management (FHSM)
1683 +----------------------------------------------------------------------
1684 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1685 +storage world. Aufs provides this feature as file-based with multiple
1686 +writable branches, based upon the principle of "Colder, the Lower".
1687 +Here the word "colder" means that the less used files, and "lower" means
1688 +that the position in the order of the stacked branches vertically.
1689 +These multiple writable branches are prioritized, ie. the topmost one
1690 +should be the fastest drive and be used heavily.
1692 +o Characters in aufs FHSM story
1693 +- aufs itself and a new branch attribute.
1694 +- a new ioctl interface to move-down and to establish a connection with
1695 + the daemon ("move-down" is a converse of "copy-up").
1696 +- userspace tool and daemon.
1698 +The userspace daemon establishes a connection with aufs and waits for
1699 +the notification. The notified information is very similar to struct
1700 +statfs containing the number of consumed blocks and inodes.
1701 +When the consumed blocks/inodes of a branch exceeds the user-specified
1702 +upper watermark, the daemon activates its move-down process until the
1703 +consumed blocks/inodes reaches the user-specified lower watermark.
1705 +The actual move-down is done by aufs based upon the request from
1706 +user-space since we need to maintain the inode number and the internal
1707 +pointer arrays in aufs.
1709 +Currently aufs FHSM handles the regular files only. Additionally they
1710 +must not be hard-linked nor pseudo-linked.
1713 +o Cowork of aufs and the user-space daemon
1714 + During the userspace daemon established the connection, aufs sends a
1715 + small notification to it whenever aufs writes something into the
1716 + writable branch. But it may cost high since aufs issues statfs(2)
1717 + internally. So user can specify a new option to cache the
1718 + info. Actually the notification is controlled by these factors.
1719 + + the specified cache time.
1720 + + classified as "force" by aufs internally.
1721 + Until the specified time expires, aufs doesn't send the info
1722 + except the forced cases. When aufs decide forcing, the info is always
1723 + notified to userspace.
1724 + For example, the number of free inodes is generally large enough and
1725 + the shortage of it happens rarely. So aufs doesn't force the
1726 + notification when creating a new file, directory and others. This is
1727 + the typical case which aufs doesn't force.
1728 + When aufs writes the actual filedata and the files consumes any of new
1729 + blocks, the aufs forces notifying.
1732 +o Interfaces in aufs
1733 +- New branch attribute.
1735 + Specifies that the branch is managed by FHSM feature. In other word,
1736 + participant in the FHSM.
1737 + When nofhsm is set to the branch, it will not be the source/target
1738 + branch of the move-down operation. This attribute is set
1739 + independently from coo and moo attributes, and if you want full
1740 + FHSM, you should specify them as well.
1741 +- New mount option.
1743 + Specifies a second to suppress many less important info to be
1746 + + AUFS_CTL_FHSM_FD
1747 + create a new file descriptor which userspace can read the notification
1748 + (a subset of struct statfs) from aufs.
1749 +- Module parameter 'brs'
1750 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1752 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1753 + When there are two or more branches with fhsm attributes,
1754 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1755 + terminates it. As a result of remounting and branch-manipulation, the
1756 + number of branches with fhsm attribute can be one. In this case,
1757 + /sbin/mount.aufs will terminate the user-space daemon.
1760 +Finally the operation is done as these steps in kernel-space.
1762 + + no one else is using the file.
1763 + + the file is not hard-linked.
1764 + + the file is not pseudo-linked.
1765 + + the file is a regular file.
1766 + + the parent dir is not opaqued.
1767 +- find the target writable branch.
1768 +- make sure the file is not whiteout-ed by the upper (than the target)
1770 +- make the parent dir on the target branch.
1771 +- mutex lock the inode on the branch.
1772 +- unlink the whiteout on the target branch (if exists).
1773 +- lookup and create the whiteout-ed temporary name on the target branch.
1774 +- copy the file as the whiteout-ed temporary name on the target branch.
1775 +- rename the whiteout-ed temporary name to the original name.
1776 +- unlink the file on the source branch.
1777 +- maintain the internal pointer array and the external inode number
1779 +- maintain the timestamps and other attributes of the parent dir and the
1782 +And of course, in every step, an error may happen. So the operation
1783 +should restore the original file state after an error happens.
1784 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1785 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1786 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-04-13 15:10:20.776823376 +0200
1789 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1791 +# This program is free software; you can redistribute it and/or modify
1792 +# it under the terms of the GNU General Public License as published by
1793 +# the Free Software Foundation; either version 2 of the License, or
1794 +# (at your option) any later version.
1796 +# This program is distributed in the hope that it will be useful,
1797 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1798 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1799 +# GNU General Public License for more details.
1801 +# You should have received a copy of the GNU General Public License
1802 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1804 +mmap(2) -- File Memory Mapping
1805 +----------------------------------------------------------------------
1806 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1807 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1809 +This approach is simple and good, but there is one problem.
1810 +Under /proc, several entries show the mmapped files by its path (with
1811 +device and inode number), and the printed path will be the path on the
1812 +branch fs's instead of virtual aufs's.
1813 +This is not a problem in most cases, but some utilities lsof(1) (and its
1814 +user) may expect the path on aufs.
1816 +To address this issue, aufs adds a new member called vm_prfile in struct
1817 +vm_area_struct (and struct vm_region). The original vm_file points to
1818 +the file on the branch fs in order to handle everything correctly as
1819 +usual. The new vm_prfile points to a virtual file in aufs, and the
1820 +show-functions in procfs refers to vm_prfile if it is set.
1821 +Also we need to maintain several other places where touching vm_file
1823 +- fork()/clone() copies vma and the reference count of vm_file is
1825 +- merging vma maintains the ref count too.
1827 +This is not a good approach. It just fakes the printed path. But it
1828 +leaves all behaviour around f_mapping unchanged. This is surely an
1830 +Actually aufs had adopted another complicated approach which calls
1831 +generic_file_mmap() and handles struct vm_operations_struct. In this
1832 +approach, aufs met a hard problem and I could not solve it without
1833 +switching the approach.
1834 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
1835 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
1836 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-04-13 15:10:20.776823376 +0200
1839 +# Copyright (C) 2014-2015 Junjiro R. Okajima
1841 +# This program is free software; you can redistribute it and/or modify
1842 +# it under the terms of the GNU General Public License as published by
1843 +# the Free Software Foundation; either version 2 of the License, or
1844 +# (at your option) any later version.
1846 +# This program is distributed in the hope that it will be useful,
1847 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1848 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1849 +# GNU General Public License for more details.
1851 +# You should have received a copy of the GNU General Public License
1852 +# along with this program; if not, write to the Free Software
1853 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1856 +Listing XATTR/EA and getting the value
1857 +----------------------------------------------------------------------
1858 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
1859 +shows the values from the topmost existing file. This behaviour is good
1860 +for the non-dir entries since the bahaviour exactly matches the shown
1861 +information. But for the directories, aufs considers all the same named
1862 +entries on the lower branches. Which means, if one of the lower entry
1863 +rejects readdir call, then aufs returns an error even if the topmost
1864 +entry allows it. This behaviour is necessary to respect the branch fs's
1865 +security, but can make users confused since the user-visible standard
1866 +attributes don't match the behaviour.
1867 +To address this issue, aufs has a mount option called dirperm1 which
1868 +checks the permission for the topmost entry only, and ignores the lower
1869 +entry's permission.
1871 +A similar issue can happen around XATTR.
1872 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
1873 +always set. Otherwise these very unpleasant situation would happen.
1874 +- listxattr(2) may return the duplicated entries.
1875 +- users may not be able to remove or reset the XATTR forever,
1878 +XATTR/EA support in the internal (copy,move)-(up,down)
1879 +----------------------------------------------------------------------
1880 +Generally the extended attributes of inode are categorized as these.
1881 +- "security" for LSM and capability.
1882 +- "system" for posix ACL, 'acl' mount option is required for the branch
1884 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
1885 +- "user" for userspace, 'user_xattr' mount option is required for the
1886 + branch fs generally.
1888 +Moreover there are some other categories. Aufs handles these rather
1889 +unpopular categories as the ordinary ones, ie. there is no special
1890 +condition nor exception.
1892 +In copy-up, the support for XATTR on the dst branch may differ from the
1893 +src branch. In this case, the copy-up operation will get an error and
1894 +the original user operation which triggered the copy-up will fail. It
1895 +can happen that even all copy-up will fail.
1896 +When both of src and dst branches support XATTR and if an error occurs
1897 +during copying XATTR, then the copy-up should fail obviously. That is a
1898 +good reason and aufs should return an error to userspace. But when only
1899 +the src branch support that XATTR, aufs should not return an error.
1900 +For example, the src branch supports ACL but the dst branch doesn't
1901 +because the dst branch may natively un-support it or temporary
1902 +un-support it due to "noacl" mount option. Of course, the dst branch fs
1903 +may NOT return an error even if the XATTR is not supported. It is
1904 +totally up to the branch fs.
1906 +Anyway when the aufs internal copy-up gets an error from the dst branch
1907 +fs, then aufs tries removing the just copied entry and returns the error
1908 +to the userspace. The worst case of this situation will be all copy-up
1911 +For the copy-up operation, there two basic approaches.
1912 +- copy the specified XATTR only (by category above), and return the
1913 + error unconditionally if it happens.
1914 +- copy all XATTR, and ignore the error on the specified category only.
1916 +In order to support XATTR and to implement the correct behaviour, aufs
1917 +chooses the latter approach and introduces some new branch attributes,
1918 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
1919 +They correspond to the XATTR namespaces (see above). Additionally, to be
1920 +convenient, "icex" is also provided which means all "icex*" attributes
1921 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
1923 +The meaning of these attributes is to ignore the error from setting
1924 +XATTR on that branch.
1925 +Note that aufs tries copying all XATTR unconditionally, and ignores the
1926 +error from the dst branch according to the specified attributes.
1928 +Some XATTR may have its default value. The default value may come from
1929 +the parent dir or the environment. If the default value is set at the
1930 +file creating-time, it will be overwritten by copy-up.
1931 +Some contradiction may happen I am afraid.
1932 +Do we need another attribute to stop copying XATTR? I am unsure. For
1933 +now, aufs implements the branch attributes to ignore the error.
1934 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1935 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1936 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-04-13 15:10:20.776823376 +0200
1939 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1941 +# This program is free software; you can redistribute it and/or modify
1942 +# it under the terms of the GNU General Public License as published by
1943 +# the Free Software Foundation; either version 2 of the License, or
1944 +# (at your option) any later version.
1946 +# This program is distributed in the hope that it will be useful,
1947 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1948 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1949 +# GNU General Public License for more details.
1951 +# You should have received a copy of the GNU General Public License
1952 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1954 +Export Aufs via NFS
1955 +----------------------------------------------------------------------
1956 +Here is an approach.
1957 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1959 +- iget_locked(): initialize aufs inode generation for a new inode, and
1960 + store it in xigen file.
1961 +- destroy_inode(): increment aufs inode generation and store it in xigen
1962 + file. it is necessary even if it is not unlinked, because any data of
1963 + inode may be changed by UDBA.
1964 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1965 + build file handle by
1966 + + branch id (4 bytes)
1967 + + superblock generation (4 bytes)
1968 + + inode number (4 or 8 bytes)
1969 + + parent dir inode number (4 or 8 bytes)
1970 + + inode generation (4 bytes))
1971 + + return value of exportfs_encode_fh() for the parent on a branch (4
1973 + + file handle for a branch (by exportfs_encode_fh())
1975 + + find the index of a branch from its id in handle, and check it is
1976 + still exist in aufs.
1977 + + 1st level: get the inode number from handle and search it in cache.
1978 + + 2nd level: if not found in cache, get the parent inode number from
1979 + the handle and search it in cache. and then open the found parent
1980 + dir, find the matching inode number by vfs_readdir() and get its
1981 + name, and call lookup_one_len() for the target dentry.
1982 + + 3rd level: if the parent dir is not cached, call
1983 + exportfs_decode_fh() for a branch and get the parent on a branch,
1984 + build a pathname of it, convert it a pathname in aufs, call
1985 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1987 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1988 + for every branch, but not itself. to get this, (currently) aufs
1989 + searches in current->nsproxy->mnt_ns list. it may not be a good
1990 + idea, but I didn't get other approach.
1991 + + test the generation of the gotten inode.
1992 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1993 + convert it into ESTALE for NFSD.
1994 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1995 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1996 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1997 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1998 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-04-13 15:10:20.776823376 +0200
2001 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2003 +# This program is free software; you can redistribute it and/or modify
2004 +# it under the terms of the GNU General Public License as published by
2005 +# the Free Software Foundation; either version 2 of the License, or
2006 +# (at your option) any later version.
2008 +# This program is distributed in the hope that it will be useful,
2009 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2010 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2011 +# GNU General Public License for more details.
2013 +# You should have received a copy of the GNU General Public License
2014 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2016 +Show Whiteout Mode (shwh)
2017 +----------------------------------------------------------------------
2018 +Generally aufs hides the name of whiteouts. But in some cases, to show
2019 +them is very useful for users. For instance, creating a new middle layer
2020 +(branch) by merging existing layers.
2022 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2023 +When you have three branches,
2024 +- Bottom: 'system', squashfs (underlying base system), read-only
2025 +- Middle: 'mods', squashfs, read-only
2026 +- Top: 'overlay', ram (tmpfs), read-write
2028 +The top layer is loaded at boot time and saved at shutdown, to preserve
2029 +the changes made to the system during the session.
2030 +When larger changes have been made, or smaller changes have accumulated,
2031 +the size of the saved top layer data grows. At this point, it would be
2032 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2033 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2034 +restoring save and load speed.
2036 +This merging is simplified by the use of another aufs mount, of just the
2037 +two overlay branches using the 'shwh' option.
2038 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2039 + aufs /livesys/merge_union
2041 +A merged view of these two branches is then available at
2042 +/livesys/merge_union, and the new feature is that the whiteouts are
2044 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2045 +writing to all branches. Also the default mode for all branches is 'ro'.
2046 +It is now possible to save the combined contents of the two overlay
2047 +branches to a new squashfs, e.g.:
2048 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2050 +This new squashfs archive can be stored on the boot device and the
2051 +initramfs will use it to replace the old one at the next boot.
2052 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2053 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2054 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-04-13 15:10:20.776823376 +0200
2057 +# Copyright (C) 2010-2015 Junjiro R. Okajima
2059 +# This program is free software; you can redistribute it and/or modify
2060 +# it under the terms of the GNU General Public License as published by
2061 +# the Free Software Foundation; either version 2 of the License, or
2062 +# (at your option) any later version.
2064 +# This program is distributed in the hope that it will be useful,
2065 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2066 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067 +# GNU General Public License for more details.
2069 +# You should have received a copy of the GNU General Public License
2070 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2072 +Dynamically customizable FS operations
2073 +----------------------------------------------------------------------
2074 +Generally FS operations (struct inode_operations, struct
2075 +address_space_operations, struct file_operations, etc.) are defined as
2076 +"static const", but it never means that FS have only one set of
2077 +operation. Some FS have multiple sets of them. For instance, ext2 has
2078 +three sets, one for XIP, for NOBH, and for normal.
2079 +Since aufs overrides and redirects these operations, sometimes aufs has
2080 +to change its behaviour according to the branch FS type. More importantly
2081 +VFS acts differently if a function (member in the struct) is set or
2082 +not. It means aufs should have several sets of operations and select one
2083 +among them according to the branch FS definition.
2085 +In order to solve this problem and not to affect the behaviour of VFS,
2086 +aufs defines these operations dynamically. For instance, aufs defines
2087 +dummy direct_IO function for struct address_space_operations, but it may
2088 +not be set to the address_space_operations actually. When the branch FS
2089 +doesn't have it, aufs doesn't set it to its address_space_operations
2090 +while the function definition itself is still alive. So the behaviour
2091 +itself will not change, and it will return an error when direct_IO is
2094 +The lifetime of these dynamically generated operation object is
2095 +maintained by aufs branch object. When the branch is removed from aufs,
2096 +the reference counter of the object is decremented. When it reaches
2097 +zero, the dynamically generated operation object will be freed.
2099 +This approach is designed to support AIO (io_submit), Direct I/O and
2101 +Currently this approach is applied to address_space_operations for
2102 +regular files only.
2103 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
2104 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
2105 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2015-04-13 15:10:20.776823376 +0200
2108 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2110 +# This program is free software; you can redistribute it and/or modify
2111 +# it under the terms of the GNU General Public License as published by
2112 +# the Free Software Foundation; either version 2 of the License, or
2113 +# (at your option) any later version.
2115 +# This program is distributed in the hope that it will be useful,
2116 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2117 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2118 +# GNU General Public License for more details.
2120 +# You should have received a copy of the GNU General Public License
2121 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2125 +Restoring some features which was implemented in aufs1.
2126 +They were dropped in aufs2 in order to make source files simpler and
2127 +easier to be reviewed.
2130 +Being Another Aufs's Readonly Branch (robr)
2131 +----------------------------------------------------------------------
2132 +Aufs1 allows aufs to be another aufs's readonly branch.
2133 +This feature was developed by a user's request. But it may not be used
2137 +Refresh the Opened File (refrof)
2138 +----------------------------------------------------------------------
2139 +This option is implemented in aufs1 but incomplete.
2141 +When user reads from a file, he expects to get its latest filedata
2142 +generally. If the file is removed and a new same named file is created,
2143 +the content he gets is unchanged, ie. the unlinked filedata.
2145 +Let's try case study again.
2146 +- aufs has two branches.
2148 +- "fileA" exists under /ro, but /rw.
2149 +- user opened "/au/fileA".
2150 +- he or someone else inserts a branch (/new) between /rw and /ro.
2151 + /au = /rw + /new + /ro
2152 +- the new branch contains "fileA".
2153 +- user reads from the opened "fileA"
2154 +- which filedata should aufs return, from /ro or /new?
2156 +Some people says it has to be "from /ro" and it is a semantics of Unix.
2157 +The others say it should be "from /new" because the file is not removed
2158 +and it is equivalent to the case of someone else modifies the file.
2160 +Here again I don't have a best and final answer. I got an idea to
2161 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
2162 +Opened File) is specified (by default), aufs returns the filedata from
2163 +/new. Otherwise from /ro.
2164 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2165 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2166 +++ linux/Documentation/filesystems/aufs/README 2015-04-13 15:10:20.773489965 +0200
2169 +Aufs3 -- advanced multi layered unification filesystem version 3.x
2175 +----------------------------------------
2176 +In the early days, aufs was entirely re-designed and re-implemented
2177 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2178 +improvements and implementations, it becomes totally different from
2179 +Unionfs while keeping the basic features.
2180 +Recently, Unionfs Version 2.x series begin taking some of the same
2181 +approaches to aufs1's.
2182 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2183 +University and his team.
2185 +Aufs3 supports linux-3.0 and later.
2186 +If you want older kernel version support, try aufs2-2.6.git or
2187 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2189 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2190 + According to Christoph Hellwig, linux rejects all union-type
2191 + filesystems but UnionMount.
2192 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2194 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2195 + UnionMount, and he pointed out an issue around a directory mutex
2196 + lock and aufs addressed it. But it is still unsure whether aufs will
2197 + be merged (or any other union solution).
2198 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2202 +----------------------------------------
2203 +- unite several directories into a single virtual filesystem. The member
2204 + directory is called as a branch.
2205 +- you can specify the permission flags to the branch, which are 'readonly',
2206 + 'readwrite' and 'whiteout-able.'
2207 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2208 + readonly branch are modifiable logically.
2209 +- dynamic branch manipulation, add, del.
2212 +Also there are many enhancements in aufs, such as:
2213 +- test only the highest one for the directory permission (dirperm1)
2214 +- copyup on open (coo=)
2215 +- 'move' policy for copy-up between two writable branches, after
2216 + checking free space.
2218 +- readdir(3) in userspace.
2219 +- keep inode number by external inode number table
2220 +- keep the timestamps of file/dir in internal copyup operation
2221 +- seekable directory, supporting NFS readdir.
2222 +- whiteout is hardlinked in order to reduce the consumption of inodes
2224 +- do not copyup, nor create a whiteout when it is unnecessary
2225 +- revert a single systemcall when an error occurs in aufs
2226 +- remount interface instead of ioctl
2227 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2228 +- loopback mounted filesystem as a branch
2229 +- kernel thread for removing the dir who has a plenty of whiteouts
2230 +- support copyup sparse file (a file which has a 'hole' in it)
2231 +- default permission flags for branches
2232 +- selectable permission flags for ro branch, whether whiteout can
2235 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2236 +- support multiple writable branches, some policies to select one
2237 + among multiple writable branches.
2238 +- a new semantics for link(2) and rename(2) to support multiple
2239 + writable branches.
2240 +- no glibc changes are required.
2241 +- pseudo hardlink (hardlink over branches)
2242 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2243 + including NFS or remote filesystem branch.
2244 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2247 +Currently these features are dropped temporary from aufs3.
2248 +See design/08plan.txt in detail.
2249 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2251 +- statistics of aufs thread (/sys/fs/aufs/stat)
2253 +Features or just an idea in the future (see also design/*.txt),
2254 +- reorder the branch index without del/re-add.
2255 +- permanent xino files for NFSD
2256 +- an option for refreshing the opened files after add/del branches
2257 +- light version, without branch manipulation. (unnecessary?)
2258 +- copyup in userspace
2259 +- inotify in userspace
2264 +----------------------------------------
2265 +There were three GIT trees for aufs3, aufs3-linux.git,
2266 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
2268 +While the aufs-util is always necessary, you need either of aufs3-linux
2269 +or aufs3-standalone.
2271 +The aufs3-linux tree includes the whole linux mainline GIT tree,
2272 +git://git.kernel.org/.../torvalds/linux.git.
2273 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2274 +build aufs3 as an external kernel module.
2275 +Several extra patches are not included in this tree. Only
2276 +aufs3-standalong tree contains them. They are describe in the later
2277 +section "Configuration and Compilation."
2279 +On the other hand, the aufs3-standalone tree has only aufs source files
2280 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2281 +But you need to apply all aufs patches manually.
2283 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
2284 +represents the linux kernel version, "linux-3.x". For instance,
2285 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
2286 +"aufs3.x-rcN" branch.
2289 +$ git clone --reference /your/linux/git/tree \
2290 + git://git.code.sf.net/p/aufs/aufs3-linux aufs3-linux.git
2291 +- if you don't have linux GIT tree, then remove "--reference ..."
2292 +$ cd aufs3-linux.git
2293 +$ git checkout origin/aufs3.0
2295 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2296 +leave the patch-work to GIT.
2297 +$ cd /your/linux/git/tree
2298 +$ git remote add aufs3 https://github.com/sfjro/aufs3-linux.git
2299 +- aufs3-linux.git tree also exists on github.
2301 +$ git checkout -b my3.14 v3.14
2302 +$ (add your change...)
2303 +$ git pull aufs3 aufs3.14
2304 +- now you have v3.14 + your_changes + aufs3.14 in you my3.14 branch.
2305 +- you may need to solve some conflicts between your_changes and
2306 + aufs3.14. in this case, git-rerere is recommended so that you can
2307 + solve the similar confilicts automatically when you upgrade to 3.15 or
2308 + later in the future.
2310 +o aufs3-standalone tree
2311 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
2312 + aufs3-standalone.git
2313 +$ cd aufs3-standalone.git
2314 +$ git checkout origin/aufs3.0
2317 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2320 +$ git checkout origin/aufs3.0
2322 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2323 +The minor version number, 'x' in '3.x', of aufs may not always
2324 +follow the minor version number of the kernel.
2325 +Because changes in the kernel that cause the use of a new
2326 +minor version number do not always require changes to aufs-util.
2328 +Since aufs-util has its own minor version number, you may not be
2329 +able to find a GIT branch in aufs-util for your kernel's
2330 +exact minor version number.
2331 +In this case, you should git-checkout the branch for the
2332 +nearest lower number.
2334 +For (an unreleased) example:
2335 +If you are using "linux-3.10" and the "aufs3.10" branch
2336 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2337 +or something numerically smaller is the branch for your kernel.
2339 +Also you can view all branches by
2343 +3. Configuration and Compilation
2344 +----------------------------------------
2345 +Make sure you have git-checkout'ed the correct branch.
2347 +For aufs3-linux tree,
2348 +- enable CONFIG_AUFS_FS.
2349 +- set other aufs configurations if necessary.
2351 +For aufs3-standalone tree,
2352 +There are several ways to build.
2355 +- apply ./aufs3-kbuild.patch to your kernel source files.
2356 +- apply ./aufs3-base.patch too.
2357 +- apply ./aufs3-mmap.patch too.
2358 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2359 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2360 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2361 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2362 +- enable CONFIG_AUFS_FS, you can select either
2364 +- and build your kernel as usual.
2365 +- install the built kernel.
2366 + Note: Since linux-3.9, every filesystem module requires an alias
2367 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2368 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2369 +- install the header files too by "make headers_install" to the
2370 + directory where you specify. By default, it is $PWD/usr.
2371 + "make help" shows a brief note for headers_install.
2372 +- and reboot your system.
2375 +- module only (CONFIG_AUFS_FS=m).
2376 +- apply ./aufs3-base.patch to your kernel source files.
2377 +- apply ./aufs3-mmap.patch too.
2378 +- apply ./aufs3-standalone.patch too.
2379 +- build your kernel, don't forget "make headers_install", and reboot.
2380 +- edit ./config.mk and set other aufs configurations if necessary.
2381 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2382 + every aufs configurations.
2383 +- build the module by simple "make".
2384 + Note: Since linux-3.9, every filesystem module requires an alias
2385 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2386 + modules.aliases file.
2387 +- you can specify ${KDIR} make variable which points to your kernel
2389 +- install the files
2390 + + run "make install" to install the aufs module, or copy the built
2391 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2392 + + run "make install_headers" (instead of headers_install) to install
2393 + the modified aufs header file (you can specify DESTDIR which is
2394 + available in aufs standalone version's Makefile only), or copy
2395 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2396 + you like manually. By default, the target directory is $PWD/usr.
2397 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2398 + kernel source tree.
2400 +Note: The header file aufs_type.h is necessary to build aufs-util
2401 + as well as "make headers_install" in the kernel source tree.
2402 + headers_install is subject to be forgotten, but it is essentially
2403 + necessary, not only for building aufs-util.
2404 + You may not meet problems without headers_install in some older
2408 +- read README in aufs-util, build and install it
2409 +- note that your distribution may contain an obsoleted version of
2410 + aufs_type.h in /usr/include/linux or something. When you build aufs
2411 + utilities, make sure that your compiler refers the correct aufs header
2412 + file which is built by "make headers_install."
2413 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2414 + then run "make install_ulib" too. And refer to the aufs manual in
2417 +There several other patches in aufs3-standalone.git. They are all
2418 +optional. When you meet some problems, they will help you.
2419 +- aufs3-loopback.patch
2420 + Supports a nested loopback mount in a branch-fs. This patch is
2421 + unnecessary until aufs produces a message like "you may want to try
2422 + another patch for loopback file".
2424 + Modifies a system global kernel internal function get_next_ino() in
2425 + order to stop assigning 0 for an inode-number. Not directly related to
2426 + aufs, but recommended generally.
2428 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2429 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2430 + duplication of inode number, which is important for backup tools and
2431 + other utilities. When you find aufs XINO files for tmpfs branch
2432 + growing too much, try this patch.
2436 +----------------------------------------
2437 +At first, make sure aufs-util are installed, and please read the aufs
2438 +manual, aufs.5 in aufs-util.git tree.
2442 +$ mkdir /tmp/rw /tmp/aufs
2443 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2445 +Here is another example. The result is equivalent.
2446 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2448 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2449 +# mount -o remount,append:${HOME} /tmp/aufs
2451 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2452 +you modify a file under /tmp/aufs, the one on your home directory is
2453 +not affected, instead the same named file will be newly created under
2454 +/tmp/rw. And all of your modification to a file will be applied to
2455 +the one under /tmp/rw. This is called the file based Copy on Write
2457 +Aufs mount options are described in aufs.5.
2458 +If you run chroot or something and make your aufs as a root directory,
2459 +then you need to customize the shutdown script. See the aufs manual in
2462 +Additionally, there are some sample usages of aufs which are a
2463 +diskless system with network booting, and LiveCD over NFS.
2464 +See sample dir in CVS tree on SourceForge.
2468 +----------------------------------------
2469 +When you have any problems or strange behaviour in aufs, please let me
2471 +- /proc/mounts (instead of the output of mount(8))
2472 +- /sys/module/aufs/*
2473 +- /sys/fs/aufs/* (if you have them)
2474 +- /debug/aufs/* (if you have them)
2475 +- linux kernel version
2476 + if your kernel is not plain, for example modified by distributor,
2477 + the url where i can download its source is necessary too.
2478 +- aufs version which was printed at loading the module or booting the
2479 + system, instead of the date you downloaded.
2480 +- configuration (define/undefine CONFIG_AUFS_xxx)
2481 +- kernel configuration or /proc/config.gz (if you have it)
2482 +- behaviour which you think to be incorrect
2483 +- actual operation, reproducible one is better
2484 +- mailto: aufs-users at lists.sourceforge.net
2486 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2487 +and Feature Requests) on SourceForge. Please join and write to
2491 +6. Acknowledgements
2492 +----------------------------------------
2493 +Thanks to everyone who have tried and are using aufs, whoever
2494 +have reported a bug or any feedback.
2496 +Especially donators:
2497 +Tomas Matejicek(slax.org) made a donation (much more than once).
2498 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2499 + scripts) is making "doubling" donations.
2500 + Unfortunately I cannot list all of the donators, but I really
2502 + It ends Aug 2010, but the ordinary donation URL is still available.
2503 + <http://sourceforge.net/donate/index.php?group_id=167503>
2504 +Dai Itasaka made a donation (2007/8).
2505 +Chuck Smith made a donation (2008/4, 10 and 12).
2506 +Henk Schoneveld made a donation (2008/9).
2507 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2508 +Francois Dupoux made a donation (2008/11).
2509 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2510 + aufs2 GIT tree (2009/2).
2511 +William Grant made a donation (2009/3).
2512 +Patrick Lane made a donation (2009/4).
2513 +The Mail Archive (mail-archive.com) made donations (2009/5).
2514 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2515 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2516 +Pavel Pronskiy made a donation (2011/2).
2517 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2518 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2519 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2521 +Sam Liddicott made a donation (2011/9).
2522 +Era Scarecrow made a donation (2013/4).
2523 +Bor Ratajc made a donation (2013/4).
2524 +Alessandro Gorreta made a donation (2013/4).
2525 +POIRETTE Marc made a donation (2013/4).
2526 +Alessandro Gorreta made a donation (2013/4).
2527 +lauri kasvandik made a donation (2013/5).
2528 +"pemasu from Finland" made a donation (2013/7).
2529 +The Parted Magic Project made a donation (2013/9 and 11).
2530 +Pavel Barta made a donation (2013/10).
2531 +Nikolay Pertsev made a donation (2014/5).
2532 +James B made a donation (2014/7).
2533 +Stefano Di Biase made a donation (2014/8).
2534 +Daniel Epellei made a donation (2015/1).
2536 +Thank you very much.
2537 +Donations are always, including future donations, very important and
2538 +helpful for me to keep on developing aufs.
2542 +----------------------------------------
2543 +If you are an experienced user, no explanation is needed. Aufs is
2544 +just a linux filesystem.
2549 +# Local variables: ;
2552 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2553 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2554 +++ linux/fs/aufs/aufs.h 2015-04-13 15:10:20.776823376 +0200
2557 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2559 + * This program, aufs is free software; you can redistribute it and/or modify
2560 + * it under the terms of the GNU General Public License as published by
2561 + * the Free Software Foundation; either version 2 of the License, or
2562 + * (at your option) any later version.
2564 + * This program is distributed in the hope that it will be useful,
2565 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2566 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2567 + * GNU General Public License for more details.
2569 + * You should have received a copy of the GNU General Public License
2570 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2574 + * all header files
2582 +#define AuStub(type, name, body, ...) \
2583 + static inline type name(__VA_ARGS__) { body; }
2585 +#define AuStubVoid(name, ...) \
2586 + AuStub(void, name, , __VA_ARGS__)
2587 +#define AuStubInt0(name, ...) \
2588 + AuStub(int, name, return 0, __VA_ARGS__)
2592 +#include "branch.h"
2595 +#include "dbgaufs.h"
2596 +#include "dentry.h"
2600 +#include "fstype.h"
2603 +#include "module.h"
2608 +#include "sysaufs.h"
2613 +#endif /* __KERNEL__ */
2614 +#endif /* __AUFS_H__ */
2615 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2616 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2617 +++ linux/fs/aufs/branch.c 2015-04-13 15:10:20.780156788 +0200
2620 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2622 + * This program, aufs is free software; you can redistribute it and/or modify
2623 + * it under the terms of the GNU General Public License as published by
2624 + * the Free Software Foundation; either version 2 of the License, or
2625 + * (at your option) any later version.
2627 + * This program is distributed in the hope that it will be useful,
2628 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2629 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2630 + * GNU General Public License for more details.
2632 + * You should have received a copy of the GNU General Public License
2633 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2637 + * branch management
2640 +#include <linux/compat.h>
2641 +#include <linux/statfs.h>
2645 + * free a single branch
2647 +static void au_br_do_free(struct au_branch *br)
2650 + struct au_wbr *wbr;
2651 + struct au_dykey **key;
2653 + au_hnotify_fin_br(br);
2655 + if (br->br_xino.xi_file)
2656 + fput(br->br_xino.xi_file);
2657 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2659 + AuDebugOn(atomic_read(&br->br_count));
2663 + for (i = 0; i < AuBrWh_Last; i++)
2664 + dput(wbr->wbr_wh[i]);
2665 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2666 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2669 + if (br->br_fhsm) {
2670 + au_br_fhsm_fin(br->br_fhsm);
2671 + kfree(br->br_fhsm);
2674 + key = br->br_dykey;
2675 + for (i = 0; i < AuBrDynOp; i++, key++)
2681 + /* recursive lock, s_umount of branch's */
2683 + path_put(&br->br_path);
2690 + * frees all branches
2692 +void au_br_free(struct au_sbinfo *sbinfo)
2694 + aufs_bindex_t bmax;
2695 + struct au_branch **br;
2697 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2699 + bmax = sbinfo->si_bend + 1;
2700 + br = sbinfo->si_branch;
2702 + au_br_do_free(*br++);
2706 + * find the index of a branch which is specified by @br_id.
2708 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2710 + aufs_bindex_t bindex, bend;
2712 + bend = au_sbend(sb);
2713 + for (bindex = 0; bindex <= bend; bindex++)
2714 + if (au_sbr_id(sb, bindex) == br_id)
2719 +/* ---------------------------------------------------------------------- */
2725 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2726 + struct dentry *h_root)
2728 + if (unlikely(h_adding == h_root
2729 + || au_test_loopback_overlap(sb, h_adding)))
2731 + if (h_adding->d_sb != h_root->d_sb)
2733 + return au_test_subdir(h_adding, h_root)
2734 + || au_test_subdir(h_root, h_adding);
2738 + * returns a newly allocated branch. @new_nbranch is a number of branches
2739 + * after adding a branch.
2741 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2744 + struct au_branch *add_branch;
2745 + struct dentry *root;
2749 + root = sb->s_root;
2750 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2751 + if (unlikely(!add_branch))
2754 + err = au_hnotify_init_br(add_branch, perm);
2755 + if (unlikely(err))
2758 + add_branch->br_wbr = NULL;
2759 + if (au_br_writable(perm)) {
2760 + /* may be freed separately at changing the branch permission */
2761 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2763 + if (unlikely(!add_branch->br_wbr))
2767 + add_branch->br_fhsm = NULL;
2768 + if (au_br_fhsm(perm)) {
2769 + err = au_fhsm_br_alloc(add_branch);
2770 + if (unlikely(err))
2774 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2776 + err = au_di_realloc(au_di(root), new_nbranch);
2778 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2780 + return add_branch; /* success */
2783 + kfree(add_branch->br_wbr);
2785 + au_hnotify_fin_br(add_branch);
2787 + kfree(add_branch);
2789 + return ERR_PTR(err);
2793 + * test if the branch permission is legal or not.
2795 +static int test_br(struct inode *inode, int brperm, char *path)
2799 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2804 + pr_err("write permission for readonly mount or inode, %s\n", path);
2812 + * 0: success, the caller will add it
2813 + * plus: success, it is already unified, the caller should ignore it
2816 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2819 + aufs_bindex_t bend, bindex;
2820 + struct dentry *root;
2821 + struct inode *inode, *h_inode;
2823 + root = sb->s_root;
2824 + bend = au_sbend(sb);
2825 + if (unlikely(bend >= 0
2826 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2830 + pr_err("%s duplicated\n", add->pathname);
2835 + err = -ENOSPC; /* -E2BIG; */
2836 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2837 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2838 + pr_err("number of branches exceeded %s\n", add->pathname);
2843 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2844 + pr_err("bad index %d\n", add->bindex);
2848 + inode = add->path.dentry->d_inode;
2850 + if (unlikely(!inode->i_nlink)) {
2851 + pr_err("no existence %s\n", add->pathname);
2856 + if (unlikely(inode->i_sb == sb)) {
2857 + pr_err("%s must be outside\n", add->pathname);
2861 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2862 + pr_err("unsupported filesystem, %s (%s)\n",
2863 + add->pathname, au_sbtype(inode->i_sb));
2867 + if (unlikely(inode->i_sb->s_stack_depth)) {
2868 + pr_err("already stacked, %s (%s)\n",
2869 + add->pathname, au_sbtype(inode->i_sb));
2873 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2874 + if (unlikely(err))
2878 + return 0; /* success */
2881 + for (bindex = 0; bindex <= bend; bindex++)
2882 + if (unlikely(test_overlap(sb, add->path.dentry,
2883 + au_h_dptr(root, bindex)))) {
2884 + pr_err("%s is overlapped\n", add->pathname);
2889 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2890 + h_inode = au_h_dptr(root, 0)->d_inode;
2891 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2892 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2893 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2894 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2896 + i_uid_read(inode), i_gid_read(inode),
2897 + (inode->i_mode & S_IALLUGO),
2898 + i_uid_read(h_inode), i_gid_read(h_inode),
2899 + (h_inode->i_mode & S_IALLUGO));
2907 + * initialize or clean the whiteouts for an adding branch
2909 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2912 + int err, old_perm;
2913 + aufs_bindex_t bindex;
2914 + struct mutex *h_mtx;
2915 + struct au_wbr *wbr;
2916 + struct au_hinode *hdir;
2918 + err = vfsub_mnt_want_write(au_br_mnt(br));
2919 + if (unlikely(err))
2923 + old_perm = br->br_perm;
2924 + br->br_perm = new_perm;
2927 + bindex = au_br_index(sb, br->br_id);
2928 + if (0 <= bindex) {
2929 + hdir = au_hi(sb->s_root->d_inode, bindex);
2930 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2932 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2933 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2936 + err = au_wh_init(br, sb);
2938 + wbr_wh_write_lock(wbr);
2939 + err = au_wh_init(br, sb);
2940 + wbr_wh_write_unlock(wbr);
2943 + au_hn_imtx_unlock(hdir);
2945 + mutex_unlock(h_mtx);
2946 + vfsub_mnt_drop_write(au_br_mnt(br));
2947 + br->br_perm = old_perm;
2949 + if (!err && wbr && !au_br_writable(new_perm)) {
2951 + br->br_wbr = NULL;
2958 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2962 + struct kstatfs kst;
2963 + struct au_wbr *wbr;
2966 + au_rw_init(&wbr->wbr_wh_rwsem);
2967 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2968 + atomic_set(&wbr->wbr_wh_running, 0);
2969 + wbr->wbr_bytes = 0;
2972 + * a limit for rmdir/rename a dir
2973 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
2975 + err = vfs_statfs(&br->br_path, &kst);
2976 + if (unlikely(err))
2979 + if (kst.f_namelen >= NAME_MAX)
2980 + err = au_br_init_wh(sb, br, perm);
2982 + pr_err("%pd(%s), unsupported namelen %ld\n",
2984 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2990 +/* initialize a new branch */
2991 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2992 + struct au_opt_add *add)
2997 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2998 + mutex_init(&br->br_xino.xi_nondir_mtx);
2999 + br->br_perm = add->perm;
3000 + br->br_path = add->path; /* set first, path_get() later */
3001 + spin_lock_init(&br->br_dykey_lock);
3002 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
3003 + atomic_set(&br->br_count, 0);
3004 + atomic_set(&br->br_xino_running, 0);
3005 + br->br_id = au_new_br_id(sb);
3006 + AuDebugOn(br->br_id < 0);
3008 + if (au_br_writable(add->perm)) {
3009 + err = au_wbr_init(br, sb, add->perm);
3010 + if (unlikely(err))
3014 + if (au_opt_test(au_mntflags(sb), XINO)) {
3015 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
3016 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3017 + if (unlikely(err)) {
3018 + AuDebugOn(br->br_xino.xi_file);
3023 + sysaufs_br_init(br);
3024 + path_get(&br->br_path);
3025 + goto out; /* success */
3028 + memset(&br->br_path, 0, sizeof(br->br_path));
3033 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3034 + struct au_branch *br, aufs_bindex_t bend,
3035 + aufs_bindex_t amount)
3037 + struct au_branch **brp;
3039 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3041 + brp = sbinfo->si_branch + bindex;
3042 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3044 + sbinfo->si_bend++;
3045 + if (unlikely(bend < 0))
3046 + sbinfo->si_bend = 0;
3049 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3050 + aufs_bindex_t bend, aufs_bindex_t amount)
3052 + struct au_hdentry *hdp;
3054 + AuRwMustWriteLock(&dinfo->di_rwsem);
3056 + hdp = dinfo->di_hdentry + bindex;
3057 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3058 + au_h_dentry_init(hdp);
3060 + if (unlikely(bend < 0))
3061 + dinfo->di_bstart = 0;
3064 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3065 + aufs_bindex_t bend, aufs_bindex_t amount)
3067 + struct au_hinode *hip;
3069 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3071 + hip = iinfo->ii_hinode + bindex;
3072 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3073 + hip->hi_inode = NULL;
3076 + if (unlikely(bend < 0))
3077 + iinfo->ii_bstart = 0;
3080 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3081 + aufs_bindex_t bindex)
3083 + struct dentry *root, *h_dentry;
3084 + struct inode *root_inode;
3085 + aufs_bindex_t bend, amount;
3087 + root = sb->s_root;
3088 + root_inode = root->d_inode;
3089 + bend = au_sbend(sb);
3090 + amount = bend + 1 - bindex;
3091 + h_dentry = au_br_dentry(br);
3092 + au_sbilist_lock();
3093 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3094 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3095 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3096 + au_set_h_dptr(root, bindex, dget(h_dentry));
3097 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
3099 + au_sbilist_unlock();
3102 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3105 + aufs_bindex_t bend, add_bindex;
3106 + struct dentry *root, *h_dentry;
3107 + struct inode *root_inode;
3108 + struct au_branch *add_branch;
3110 + root = sb->s_root;
3111 + root_inode = root->d_inode;
3112 + IMustLock(root_inode);
3113 + err = test_add(sb, add, remount);
3114 + if (unlikely(err < 0))
3118 + goto out; /* success */
3121 + bend = au_sbend(sb);
3122 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3123 + err = PTR_ERR(add_branch);
3124 + if (IS_ERR(add_branch))
3127 + err = au_br_init(add_branch, sb, add);
3128 + if (unlikely(err)) {
3129 + au_br_do_free(add_branch);
3133 + add_bindex = add->bindex;
3135 + au_br_do_add(sb, add_branch, add_bindex);
3137 + sysaufs_brs_del(sb, add_bindex);
3138 + au_br_do_add(sb, add_branch, add_bindex);
3139 + sysaufs_brs_add(sb, add_bindex);
3142 + h_dentry = add->path.dentry;
3143 + if (!add_bindex) {
3144 + au_cpup_attr_all(root_inode, /*force*/1);
3145 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3147 + au_add_nlink(root_inode, h_dentry->d_inode);
3150 + * this test/set prevents aufs from handling unnecesary notify events
3151 + * of xino files, in case of re-adding a writable branch which was
3152 + * once detached from aufs.
3154 + if (au_xino_brid(sb) < 0
3155 + && au_br_writable(add_branch->br_perm)
3156 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3157 + && add_branch->br_xino.xi_file
3158 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3159 + au_xino_brid_set(sb, add_branch->br_id);
3165 +/* ---------------------------------------------------------------------- */
3167 +static unsigned long long au_farray_cb(void *a,
3168 + unsigned long long max __maybe_unused,
3171 + unsigned long long n;
3172 + struct file **p, *f;
3173 + struct au_sphlhead *files;
3174 + struct au_finfo *finfo;
3175 + struct super_block *sb = arg;
3179 + files = &au_sbi(sb)->si_files;
3180 + spin_lock(&files->spin);
3181 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3182 + f = finfo->fi_file;
3184 + && !special_file(file_inode(f)->i_mode)) {
3188 + AuDebugOn(n > max);
3191 + spin_unlock(&files->spin);
3196 +static struct file **au_farray_alloc(struct super_block *sb,
3197 + unsigned long long *max)
3199 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3200 + return au_array_alloc(max, au_farray_cb, sb);
3203 +static void au_farray_free(struct file **a, unsigned long long max)
3205 + unsigned long long ull;
3207 + for (ull = 0; ull < max; ull++)
3213 +/* ---------------------------------------------------------------------- */
3219 +/* to show the line number, do not make it inlined function */
3220 +#define AuVerbose(do_info, fmt, ...) do { \
3222 + pr_info(fmt, ##__VA_ARGS__); \
3225 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3226 + aufs_bindex_t bend)
3228 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3231 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3232 + aufs_bindex_t bend)
3234 + return au_test_ibusy(dentry->d_inode, bstart, bend);
3238 + * test if the branch is deletable or not.
3240 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3241 + unsigned int sigen, const unsigned int verbose)
3243 + int err, i, j, ndentry;
3244 + aufs_bindex_t bstart, bend;
3245 + struct au_dcsub_pages dpages;
3246 + struct au_dpage *dpage;
3249 + err = au_dpages_init(&dpages, GFP_NOFS);
3250 + if (unlikely(err))
3252 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3253 + if (unlikely(err))
3256 + for (i = 0; !err && i < dpages.ndpage; i++) {
3257 + dpage = dpages.dpages + i;
3258 + ndentry = dpage->ndentry;
3259 + for (j = 0; !err && j < ndentry; j++) {
3260 + d = dpage->dentries[j];
3261 + AuDebugOn(au_dcount(d) <= 0);
3262 + if (!au_digen_test(d, sigen)) {
3263 + di_read_lock_child(d, AuLock_IR);
3264 + if (unlikely(au_dbrange_test(d))) {
3265 + di_read_unlock(d, AuLock_IR);
3269 + di_write_lock_child(d);
3270 + if (unlikely(au_dbrange_test(d))) {
3271 + di_write_unlock(d);
3274 + err = au_reval_dpath(d, sigen);
3276 + di_downgrade_lock(d, AuLock_IR);
3278 + di_write_unlock(d);
3283 + /* AuDbgDentry(d); */
3284 + bstart = au_dbstart(d);
3285 + bend = au_dbend(d);
3286 + if (bstart <= bindex
3288 + && au_h_dptr(d, bindex)
3289 + && au_test_dbusy(d, bstart, bend)) {
3291 + AuVerbose(verbose, "busy %pd\n", d);
3294 + di_read_unlock(d, AuLock_IR);
3299 + au_dpages_free(&dpages);
3304 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3305 + unsigned int sigen, const unsigned int verbose)
3308 + unsigned long long max, ull;
3309 + struct inode *i, **array;
3310 + aufs_bindex_t bstart, bend;
3312 + array = au_iarray_alloc(sb, &max);
3313 + err = PTR_ERR(array);
3314 + if (IS_ERR(array))
3318 + AuDbg("b%d\n", bindex);
3319 + for (ull = 0; !err && ull < max; ull++) {
3323 + if (i->i_ino == AUFS_ROOT_INO)
3326 + /* AuDbgInode(i); */
3327 + if (au_iigen(i, NULL) == sigen)
3328 + ii_read_lock_child(i);
3330 + ii_write_lock_child(i);
3331 + err = au_refresh_hinode_self(i);
3334 + ii_downgrade_lock(i);
3336 + ii_write_unlock(i);
3341 + bstart = au_ibstart(i);
3342 + bend = au_ibend(i);
3343 + if (bstart <= bindex
3345 + && au_h_iptr(i, bindex)
3346 + && au_test_ibusy(i, bstart, bend)) {
3348 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3351 + ii_read_unlock(i);
3353 + au_iarray_free(array, max);
3359 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3360 + const unsigned int verbose)
3363 + unsigned int sigen;
3365 + sigen = au_sigen(root->d_sb);
3366 + DiMustNoWaiters(root);
3367 + IiMustNoWaiters(root->d_inode);
3368 + di_write_unlock(root);
3369 + err = test_dentry_busy(root, bindex, sigen, verbose);
3371 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3372 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3377 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3378 + struct file **to_free, int *idx)
3381 + unsigned char matched, root;
3382 + aufs_bindex_t bindex, bend;
3383 + struct au_fidir *fidir;
3384 + struct au_hfile *hfile;
3387 + root = IS_ROOT(file->f_path.dentry);
3390 + to_free[*idx] = file;
3396 + fidir = au_fi(file)->fi_hdir;
3397 + AuDebugOn(!fidir);
3398 + bend = au_fbend_dir(file);
3399 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3400 + hfile = fidir->fd_hfile + bindex;
3401 + if (!hfile->hf_file)
3404 + if (hfile->hf_br->br_id == br_id) {
3416 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3417 + struct file **to_free, int opened)
3420 + unsigned long long ull, max;
3421 + aufs_bindex_t bstart;
3422 + struct file *file, **array;
3423 + struct dentry *root;
3424 + struct au_hfile *hfile;
3426 + array = au_farray_alloc(sb, &max);
3427 + err = PTR_ERR(array);
3428 + if (IS_ERR(array))
3433 + root = sb->s_root;
3434 + di_write_unlock(root);
3435 + for (ull = 0; ull < max; ull++) {
3436 + file = array[ull];
3437 + if (unlikely(!file))
3440 + /* AuDbg("%pD\n", file); */
3441 + fi_read_lock(file);
3442 + bstart = au_fbstart(file);
3443 + if (!d_is_dir(file->f_path.dentry)) {
3444 + hfile = &au_fi(file)->fi_htop;
3445 + if (hfile->hf_br->br_id == br_id)
3448 + err = test_dir_busy(file, br_id, to_free, &idx);
3449 + fi_read_unlock(file);
3450 + if (unlikely(err))
3453 + di_write_lock_child(root);
3454 + au_farray_free(array, max);
3455 + AuDebugOn(idx > opened);
3461 +static void br_del_file(struct file **to_free, unsigned long long opened,
3462 + aufs_bindex_t br_id)
3464 + unsigned long long ull;
3465 + aufs_bindex_t bindex, bstart, bend, bfound;
3466 + struct file *file;
3467 + struct au_fidir *fidir;
3468 + struct au_hfile *hfile;
3470 + for (ull = 0; ull < opened; ull++) {
3471 + file = to_free[ull];
3472 + if (unlikely(!file))
3475 + /* AuDbg("%pD\n", file); */
3476 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3478 + fidir = au_fi(file)->fi_hdir;
3479 + AuDebugOn(!fidir);
3480 + fi_write_lock(file);
3481 + bstart = au_fbstart(file);
3482 + bend = au_fbend_dir(file);
3483 + for (bindex = bstart; bindex <= bend; bindex++) {
3484 + hfile = fidir->fd_hfile + bindex;
3485 + if (!hfile->hf_file)
3488 + if (hfile->hf_br->br_id == br_id) {
3493 + AuDebugOn(bfound < 0);
3494 + au_set_h_fptr(file, bfound, NULL);
3495 + if (bfound == bstart) {
3496 + for (bstart++; bstart <= bend; bstart++)
3497 + if (au_hf_dir(file, bstart)) {
3498 + au_set_fbstart(file, bstart);
3502 + fi_write_unlock(file);
3506 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3507 + const aufs_bindex_t bindex,
3508 + const aufs_bindex_t bend)
3510 + struct au_branch **brp, **p;
3512 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3514 + brp = sbinfo->si_branch + bindex;
3515 + if (bindex < bend)
3516 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3517 + sbinfo->si_branch[0 + bend] = NULL;
3518 + sbinfo->si_bend--;
3520 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3522 + sbinfo->si_branch = p;
3523 + /* harmless error */
3526 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3527 + const aufs_bindex_t bend)
3529 + struct au_hdentry *hdp, *p;
3531 + AuRwMustWriteLock(&dinfo->di_rwsem);
3533 + hdp = dinfo->di_hdentry;
3534 + if (bindex < bend)
3535 + memmove(hdp + bindex, hdp + bindex + 1,
3536 + sizeof(*hdp) * (bend - bindex));
3537 + hdp[0 + bend].hd_dentry = NULL;
3540 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3542 + dinfo->di_hdentry = p;
3543 + /* harmless error */
3546 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3547 + const aufs_bindex_t bend)
3549 + struct au_hinode *hip, *p;
3551 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3553 + hip = iinfo->ii_hinode + bindex;
3554 + if (bindex < bend)
3555 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3556 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3557 + au_hn_init(iinfo->ii_hinode + bend);
3560 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3562 + iinfo->ii_hinode = p;
3563 + /* harmless error */
3566 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3567 + struct au_branch *br)
3569 + aufs_bindex_t bend;
3570 + struct au_sbinfo *sbinfo;
3571 + struct dentry *root, *h_root;
3572 + struct inode *inode, *h_inode;
3573 + struct au_hinode *hinode;
3575 + SiMustWriteLock(sb);
3577 + root = sb->s_root;
3578 + inode = root->d_inode;
3579 + sbinfo = au_sbi(sb);
3580 + bend = sbinfo->si_bend;
3582 + h_root = au_h_dptr(root, bindex);
3583 + hinode = au_hi(inode, bindex);
3584 + h_inode = au_igrab(hinode->hi_inode);
3587 + au_sbilist_lock();
3588 + au_br_do_del_brp(sbinfo, bindex, bend);
3589 + au_br_do_del_hdp(au_di(root), bindex, bend);
3590 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3591 + au_sbilist_unlock();
3595 + au_br_do_free(br);
3598 +static unsigned long long empty_cb(void *array, unsigned long long max,
3604 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3607 + unsigned long long opened;
3608 + unsigned int mnt_flags;
3609 + aufs_bindex_t bindex, bend, br_id;
3610 + unsigned char do_wh, verbose;
3611 + struct au_branch *br;
3612 + struct au_wbr *wbr;
3613 + struct dentry *root;
3614 + struct file **to_free;
3619 + root = sb->s_root;
3620 + bindex = au_find_dbindex(root, del->h_path.dentry);
3623 + goto out; /* success */
3625 + pr_err("%s no such branch\n", del->pathname);
3628 + AuDbg("bindex b%d\n", bindex);
3631 + mnt_flags = au_mntflags(sb);
3632 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3633 + bend = au_sbend(sb);
3634 + if (unlikely(!bend)) {
3635 + AuVerbose(verbose, "no more branches left\n");
3638 + br = au_sbr(sb, bindex);
3639 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3641 + br_id = br->br_id;
3642 + opened = atomic_read(&br->br_count);
3643 + if (unlikely(opened)) {
3644 + to_free = au_array_alloc(&opened, empty_cb, NULL);
3645 + err = PTR_ERR(to_free);
3646 + if (IS_ERR(to_free))
3649 + err = test_file_busy(sb, br_id, to_free, opened);
3650 + if (unlikely(err)) {
3651 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3657 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3659 + /* instead of WbrWhMustWriteLock(wbr) */
3660 + SiMustWriteLock(sb);
3661 + for (i = 0; i < AuBrWh_Last; i++) {
3662 + dput(wbr->wbr_wh[i]);
3663 + wbr->wbr_wh[i] = NULL;
3667 + err = test_children_busy(root, bindex, verbose);
3668 + if (unlikely(err)) {
3677 + * now we confirmed the branch is deletable.
3678 + * let's free the remaining opened dirs on the branch.
3680 + di_write_unlock(root);
3681 + br_del_file(to_free, opened, br_id);
3682 + di_write_lock_child(root);
3686 + au_br_do_del(sb, bindex, br);
3688 + sysaufs_brs_del(sb, bindex);
3689 + au_br_do_del(sb, bindex, br);
3690 + sysaufs_brs_add(sb, bindex);
3694 + au_cpup_attr_all(root->d_inode, /*force*/1);
3695 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3697 + au_sub_nlink(root->d_inode, del->h_path.dentry->d_inode);
3698 + if (au_opt_test(mnt_flags, PLINK))
3699 + au_plink_half_refresh(sb, br_id);
3701 + if (au_xino_brid(sb) == br_id)
3702 + au_xino_brid_set(sb, -1);
3703 + goto out; /* success */
3707 + rerr = au_br_init_wh(sb, br, br->br_perm);
3709 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3710 + del->pathname, rerr);
3713 + au_farray_free(to_free, opened);
3717 +/* ---------------------------------------------------------------------- */
3719 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3722 + aufs_bindex_t bstart, bend;
3723 + struct aufs_ibusy ibusy;
3724 + struct inode *inode, *h_inode;
3727 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3730 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3732 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3733 + if (unlikely(err)) {
3740 + si_read_lock(sb, AuLock_FLUSH);
3741 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3745 + ibusy.h_ino = 0; /* invalid */
3746 + inode = ilookup(sb, ibusy.ino);
3748 + || inode->i_ino == AUFS_ROOT_INO
3749 + || is_bad_inode(inode))
3752 + ii_read_lock_child(inode);
3753 + bstart = au_ibstart(inode);
3754 + bend = au_ibend(inode);
3755 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3756 + h_inode = au_h_iptr(inode, ibusy.bindex);
3757 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3758 + ibusy.h_ino = h_inode->i_ino;
3760 + ii_read_unlock(inode);
3764 + si_read_unlock(sb);
3766 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3767 + if (unlikely(err)) {
3776 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3778 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
3781 +#ifdef CONFIG_COMPAT
3782 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3784 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
3788 +/* ---------------------------------------------------------------------- */
3791 + * change a branch permission
3794 +static void au_warn_ima(void)
3797 + /* since it doesn't support mark_files_ro() */
3798 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3802 +static int do_need_sigen_inc(int a, int b)
3804 + return au_br_whable(a) && !au_br_whable(b);
3807 +static int need_sigen_inc(int old, int new)
3809 + return do_need_sigen_inc(old, new)
3810 + || do_need_sigen_inc(new, old);
3813 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3816 + unsigned int mnt_flags;
3817 + unsigned long long ull, max;
3818 + aufs_bindex_t br_id;
3819 + unsigned char verbose, writer;
3820 + struct file *file, *hf, **array;
3821 + struct au_hfile *hfile;
3823 + mnt_flags = au_mntflags(sb);
3824 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3826 + array = au_farray_alloc(sb, &max);
3827 + err = PTR_ERR(array);
3828 + if (IS_ERR(array))
3832 + br_id = au_sbr_id(sb, bindex);
3833 + for (ull = 0; ull < max; ull++) {
3834 + file = array[ull];
3835 + if (unlikely(!file))
3838 + /* AuDbg("%pD\n", file); */
3839 + fi_read_lock(file);
3840 + if (unlikely(au_test_mmapped(file))) {
3842 + AuVerbose(verbose, "mmapped %pD\n", file);
3844 + FiMustNoWaiters(file);
3845 + fi_read_unlock(file);
3849 + hfile = &au_fi(file)->fi_htop;
3850 + hf = hfile->hf_file;
3851 + if (!d_is_reg(file->f_path.dentry)
3852 + || !(file->f_mode & FMODE_WRITE)
3853 + || hfile->hf_br->br_id != br_id
3854 + || !(hf->f_mode & FMODE_WRITE))
3855 + array[ull] = NULL;
3861 + FiMustNoWaiters(file);
3862 + fi_read_unlock(file);
3870 + for (ull = 0; ull < max; ull++) {
3871 + file = array[ull];
3875 + /* todo: already flushed? */
3877 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3878 + * approach which resets f_mode and calls mnt_drop_write() and
3879 + * file_release_write() for each file, because the branch
3880 + * attribute in aufs world is totally different from the native
3883 + /* fi_read_lock(file); */
3884 + hfile = &au_fi(file)->fi_htop;
3885 + hf = hfile->hf_file;
3886 + /* fi_read_unlock(file); */
3887 + spin_lock(&hf->f_lock);
3888 + writer = !!(hf->f_mode & FMODE_WRITER);
3889 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
3890 + spin_unlock(&hf->f_lock);
3892 + put_write_access(file_inode(hf));
3893 + __mnt_drop_write(hf->f_path.mnt);
3898 + au_farray_free(array, max);
3904 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3908 + aufs_bindex_t bindex;
3909 + struct dentry *root;
3910 + struct au_branch *br;
3911 + struct au_br_fhsm *bf;
3913 + root = sb->s_root;
3914 + bindex = au_find_dbindex(root, mod->h_root);
3917 + return 0; /* success */
3919 + pr_err("%s no such branch\n", mod->path);
3922 + AuDbg("bindex b%d\n", bindex);
3924 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3925 + if (unlikely(err))
3928 + br = au_sbr(sb, bindex);
3929 + AuDebugOn(mod->h_root != au_br_dentry(br));
3930 + if (br->br_perm == mod->perm)
3931 + return 0; /* success */
3933 + /* pre-allocate for non-fhsm --> fhsm */
3935 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
3936 + err = au_fhsm_br_alloc(br);
3937 + if (unlikely(err))
3940 + br->br_fhsm = NULL;
3943 + if (au_br_writable(br->br_perm)) {
3944 + /* remove whiteout base */
3945 + err = au_br_init_wh(sb, br, mod->perm);
3946 + if (unlikely(err))
3949 + if (!au_br_writable(mod->perm)) {
3950 + /* rw --> ro, file might be mmapped */
3951 + DiMustNoWaiters(root);
3952 + IiMustNoWaiters(root->d_inode);
3953 + di_write_unlock(root);
3954 + err = au_br_mod_files_ro(sb, bindex);
3955 + /* aufs_write_lock() calls ..._child() */
3956 + di_write_lock_child(root);
3958 + if (unlikely(err)) {
3960 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3963 + rerr = au_wbr_init(br, sb, br->br_perm);
3964 + if (unlikely(rerr)) {
3965 + AuIOErr("nested error %d (%d)\n",
3967 + br->br_perm = mod->perm;
3971 + } else if (au_br_writable(mod->perm)) {
3974 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3976 + err = au_wbr_init(br, sb, mod->perm);
3977 + if (unlikely(err)) {
3978 + kfree(br->br_wbr);
3979 + br->br_wbr = NULL;
3983 + if (unlikely(err))
3986 + if (au_br_fhsm(br->br_perm)) {
3987 + if (!au_br_fhsm(mod->perm)) {
3988 + /* fhsm --> non-fhsm */
3989 + au_br_fhsm_fin(br->br_fhsm);
3990 + kfree(br->br_fhsm);
3991 + br->br_fhsm = NULL;
3993 + } else if (au_br_fhsm(mod->perm))
3994 + /* non-fhsm --> fhsm */
3997 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3998 + br->br_perm = mod->perm;
3999 + goto out; /* success */
4008 +/* ---------------------------------------------------------------------- */
4010 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4013 + struct kstatfs kstfs;
4015 + err = vfs_statfs(&br->br_path, &kstfs);
4017 + stfs->f_blocks = kstfs.f_blocks;
4018 + stfs->f_bavail = kstfs.f_bavail;
4019 + stfs->f_files = kstfs.f_files;
4020 + stfs->f_ffree = kstfs.f_ffree;
4025 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4026 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4027 +++ linux/fs/aufs/branch.h 2015-04-13 15:10:20.780156788 +0200
4030 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4032 + * This program, aufs is free software; you can redistribute it and/or modify
4033 + * it under the terms of the GNU General Public License as published by
4034 + * the Free Software Foundation; either version 2 of the License, or
4035 + * (at your option) any later version.
4037 + * This program is distributed in the hope that it will be useful,
4038 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4039 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4040 + * GNU General Public License for more details.
4042 + * You should have received a copy of the GNU General Public License
4043 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4047 + * branch filesystems and xino for them
4050 +#ifndef __AUFS_BRANCH_H__
4051 +#define __AUFS_BRANCH_H__
4055 +#include <linux/mount.h>
4060 +/* ---------------------------------------------------------------------- */
4063 +struct au_xino_file {
4064 + struct file *xi_file;
4065 + struct mutex xi_nondir_mtx;
4067 + /* todo: make xino files an array to support huge inode number */
4069 +#ifdef CONFIG_DEBUG_FS
4070 + struct dentry *xi_dbgaufs;
4074 +/* File-based Hierarchical Storage Management */
4075 +struct au_br_fhsm {
4076 +#ifdef CONFIG_AUFS_FHSM
4077 + struct mutex bf_lock;
4078 + unsigned long bf_jiffy;
4079 + struct aufs_stfs bf_stfs;
4084 +/* members for writable branch only */
4085 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4087 + struct au_rwsem wbr_wh_rwsem;
4088 + struct dentry *wbr_wh[AuBrWh_Last];
4089 + atomic_t wbr_wh_running;
4090 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4091 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4092 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4095 + unsigned long long wbr_bytes;
4098 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4099 +#define AuBrDynOp (AuDyLast * 4)
4101 +#ifdef CONFIG_AUFS_HFSNOTIFY
4102 +/* support for asynchronous destruction */
4103 +struct au_br_hfsnotify {
4104 + struct fsnotify_group *hfsn_group;
4108 +/* sysfs entries */
4109 +struct au_brsysfs {
4111 + struct attribute attr;
4120 +/* protected by superblock rwsem */
4122 + struct au_xino_file br_xino;
4124 + aufs_bindex_t br_id;
4127 + struct path br_path;
4128 + spinlock_t br_dykey_lock;
4129 + struct au_dykey *br_dykey[AuBrDynOp];
4130 + atomic_t br_count;
4132 + struct au_wbr *br_wbr;
4133 + struct au_br_fhsm *br_fhsm;
4135 + /* xino truncation */
4136 + atomic_t br_xino_running;
4138 +#ifdef CONFIG_AUFS_HFSNOTIFY
4139 + struct au_br_hfsnotify *br_hfsn;
4142 +#ifdef CONFIG_SYSFS
4143 + /* entries under sysfs per mount-point */
4144 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4148 +/* ---------------------------------------------------------------------- */
4150 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4152 + return br->br_path.mnt;
4155 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4157 + return br->br_path.dentry;
4160 +static inline struct super_block *au_br_sb(struct au_branch *br)
4162 + return au_br_mnt(br)->mnt_sb;
4165 +static inline int au_br_rdonly(struct au_branch *br)
4167 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4168 + || !au_br_writable(br->br_perm))
4172 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4174 +#ifdef CONFIG_AUFS_HNOTIFY
4175 + return !(brperm & AuBrPerm_RR);
4181 +/* ---------------------------------------------------------------------- */
4185 +void au_br_free(struct au_sbinfo *sinfo);
4186 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4188 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4190 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4191 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4192 +#ifdef CONFIG_COMPAT
4193 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4196 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4199 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4202 +static const loff_t au_loff_max = LLONG_MAX;
4204 +int au_xib_trunc(struct super_block *sb);
4205 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
4207 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
4209 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4210 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4211 +ino_t au_xino_new_ino(struct super_block *sb);
4212 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4213 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4215 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4217 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4218 + struct file *base_file, int do_test);
4219 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4221 +struct au_opt_xino;
4222 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4223 +void au_xino_clr(struct super_block *sb);
4224 +struct file *au_xino_def(struct super_block *sb);
4225 +int au_xino_path(struct seq_file *seq, struct file *file);
4227 +/* ---------------------------------------------------------------------- */
4229 +/* Superblock to branch */
4231 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4233 + return au_sbr(sb, bindex)->br_id;
4237 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4239 + return au_br_mnt(au_sbr(sb, bindex));
4243 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4245 + return au_br_sb(au_sbr(sb, bindex));
4248 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4250 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4253 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4255 + return au_sbr(sb, bindex)->br_perm;
4258 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4260 + return au_br_whable(au_sbr_perm(sb, bindex));
4263 +/* ---------------------------------------------------------------------- */
4266 + * wbr_wh_read_lock, wbr_wh_write_lock
4267 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4269 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4271 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4272 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4273 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4275 +/* ---------------------------------------------------------------------- */
4277 +#ifdef CONFIG_AUFS_FHSM
4278 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4280 + mutex_init(&brfhsm->bf_lock);
4281 + brfhsm->bf_jiffy = 0;
4282 + brfhsm->bf_readable = 0;
4285 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4287 + mutex_destroy(&brfhsm->bf_lock);
4290 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4291 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4294 +#endif /* __KERNEL__ */
4295 +#endif /* __AUFS_BRANCH_H__ */
4296 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4297 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4298 +++ linux/fs/aufs/conf.mk 2015-04-13 15:10:20.780156788 +0200
4301 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4305 +AuConfStr += ${1}=${${1}}
4309 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4311 + HNOTIFY HFSNOTIFY \
4322 +$(foreach i, ${AuConfAll}, \
4323 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4325 +AuConfName = ${obj}/conf.str
4326 +${AuConfName}.tmp: FORCE
4327 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4328 +${AuConfName}: ${AuConfName}.tmp
4329 + @diff -q $< $@ > /dev/null 2>&1 || { \
4330 + echo ' GEN ' $@; \
4334 +clean-files += ${AuConfName} ${AuConfName}.tmp
4335 +${obj}/sysfs.o: ${AuConfName}
4337 +-include ${srctree}/${src}/conf_priv.mk
4338 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4339 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4340 +++ linux/fs/aufs/cpup.c 2015-04-13 15:10:20.780156788 +0200
4343 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4345 + * This program, aufs is free software; you can redistribute it and/or modify
4346 + * it under the terms of the GNU General Public License as published by
4347 + * the Free Software Foundation; either version 2 of the License, or
4348 + * (at your option) any later version.
4350 + * This program is distributed in the hope that it will be useful,
4351 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4352 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4353 + * GNU General Public License for more details.
4355 + * You should have received a copy of the GNU General Public License
4356 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4360 + * copy-up functions, see wbr_policy.c for copy-down
4363 +#include <linux/fs_stack.h>
4364 +#include <linux/mm.h>
4367 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4369 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4370 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4372 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4374 + dst->i_flags |= iflags & ~mask;
4375 + if (au_test_fs_notime(dst->i_sb))
4376 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4379 +void au_cpup_attr_timesizes(struct inode *inode)
4381 + struct inode *h_inode;
4383 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4384 + fsstack_copy_attr_times(inode, h_inode);
4385 + fsstack_copy_inode_size(inode, h_inode);
4388 +void au_cpup_attr_nlink(struct inode *inode, int force)
4390 + struct inode *h_inode;
4391 + struct super_block *sb;
4392 + aufs_bindex_t bindex, bend;
4395 + bindex = au_ibstart(inode);
4396 + h_inode = au_h_iptr(inode, bindex);
4398 + && !S_ISDIR(h_inode->i_mode)
4399 + && au_opt_test(au_mntflags(sb), PLINK)
4400 + && au_plink_test(inode))
4404 + * 0 can happen in revalidating.
4405 + * h_inode->i_mutex may not be held here, but it is harmless since once
4406 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4408 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4409 + * the incorrect link count.
4411 + set_nlink(inode, h_inode->i_nlink);
4414 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4415 + * it may includes whplink directory.
4417 + if (S_ISDIR(h_inode->i_mode)) {
4418 + bend = au_ibend(inode);
4419 + for (bindex++; bindex <= bend; bindex++) {
4420 + h_inode = au_h_iptr(inode, bindex);
4422 + au_add_nlink(inode, h_inode);
4427 +void au_cpup_attr_changeable(struct inode *inode)
4429 + struct inode *h_inode;
4431 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4432 + inode->i_mode = h_inode->i_mode;
4433 + inode->i_uid = h_inode->i_uid;
4434 + inode->i_gid = h_inode->i_gid;
4435 + au_cpup_attr_timesizes(inode);
4436 + au_cpup_attr_flags(inode, h_inode->i_flags);
4439 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4441 + struct au_iinfo *iinfo = au_ii(inode);
4443 + IiMustWriteLock(inode);
4445 + iinfo->ii_higen = h_inode->i_generation;
4446 + iinfo->ii_hsb1 = h_inode->i_sb;
4449 +void au_cpup_attr_all(struct inode *inode, int force)
4451 + struct inode *h_inode;
4453 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4454 + au_cpup_attr_changeable(inode);
4455 + if (inode->i_nlink > 0)
4456 + au_cpup_attr_nlink(inode, force);
4457 + inode->i_rdev = h_inode->i_rdev;
4458 + inode->i_blkbits = h_inode->i_blkbits;
4459 + au_cpup_igen(inode, h_inode);
4462 +/* ---------------------------------------------------------------------- */
4464 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4466 +/* keep the timestamps of the parent dir when cpup */
4467 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4468 + struct path *h_path)
4470 + struct inode *h_inode;
4472 + dt->dt_dentry = dentry;
4473 + dt->dt_h_path = *h_path;
4474 + h_inode = h_path->dentry->d_inode;
4475 + dt->dt_atime = h_inode->i_atime;
4476 + dt->dt_mtime = h_inode->i_mtime;
4480 +void au_dtime_revert(struct au_dtime *dt)
4482 + struct iattr attr;
4485 + attr.ia_atime = dt->dt_atime;
4486 + attr.ia_mtime = dt->dt_mtime;
4487 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4488 + | ATTR_ATIME | ATTR_ATIME_SET;
4490 + /* no delegation since this is a directory */
4491 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4492 + if (unlikely(err))
4493 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4496 +/* ---------------------------------------------------------------------- */
4498 +/* internal use only */
4499 +struct au_cpup_reg_attr {
4502 + unsigned int iflags; /* inode->i_flags */
4505 +static noinline_for_stack
4506 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4507 + struct au_cpup_reg_attr *h_src_attr)
4509 + int err, sbits, icex;
4510 + unsigned int mnt_flags;
4511 + unsigned char verbose;
4513 + struct path h_path;
4514 + struct inode *h_isrc, *h_idst;
4515 + struct kstat *h_st;
4516 + struct au_branch *br;
4518 + h_path.dentry = au_h_dptr(dst, bindex);
4519 + h_idst = h_path.dentry->d_inode;
4520 + br = au_sbr(dst->d_sb, bindex);
4521 + h_path.mnt = au_br_mnt(br);
4522 + h_isrc = h_src->d_inode;
4523 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4524 + | ATTR_ATIME | ATTR_MTIME
4525 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4526 + if (h_src_attr && h_src_attr->valid) {
4527 + h_st = &h_src_attr->st;
4528 + ia.ia_uid = h_st->uid;
4529 + ia.ia_gid = h_st->gid;
4530 + ia.ia_atime = h_st->atime;
4531 + ia.ia_mtime = h_st->mtime;
4532 + if (h_idst->i_mode != h_st->mode
4533 + && !S_ISLNK(h_idst->i_mode)) {
4534 + ia.ia_valid |= ATTR_MODE;
4535 + ia.ia_mode = h_st->mode;
4537 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4538 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4540 + ia.ia_uid = h_isrc->i_uid;
4541 + ia.ia_gid = h_isrc->i_gid;
4542 + ia.ia_atime = h_isrc->i_atime;
4543 + ia.ia_mtime = h_isrc->i_mtime;
4544 + if (h_idst->i_mode != h_isrc->i_mode
4545 + && !S_ISLNK(h_idst->i_mode)) {
4546 + ia.ia_valid |= ATTR_MODE;
4547 + ia.ia_mode = h_isrc->i_mode;
4549 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4550 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4552 + /* no delegation since it is just created */
4553 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4555 + /* is this nfs only? */
4556 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4557 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4558 + ia.ia_mode = h_isrc->i_mode;
4559 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4562 + icex = br->br_perm & AuBrAttr_ICEX;
4564 + mnt_flags = au_mntflags(dst->d_sb);
4565 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4566 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4572 +/* ---------------------------------------------------------------------- */
4574 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4575 + char *buf, unsigned long blksize)
4578 + size_t sz, rbytes, wbytes;
4579 + unsigned char all_zero;
4581 + struct mutex *h_mtx;
4582 + /* reduce stack usage */
4585 + zp = page_address(ZERO_PAGE(0));
4586 + if (unlikely(!zp))
4587 + return -ENOMEM; /* possible? */
4592 + AuDbg("len %lld\n", len);
4594 + if (len < blksize)
4598 + /* todo: signal_pending? */
4599 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4600 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4603 + if (unlikely(err < 0))
4607 + if (len >= rbytes && rbytes == blksize)
4608 + all_zero = !memcmp(buf, zp, rbytes);
4615 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4617 + /* todo: signal_pending? */
4618 + if (unlikely(err == -EAGAIN || err == -EINTR))
4620 + if (unlikely(err < 0))
4625 + if (unlikely(err < 0))
4631 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4633 + if (unlikely(res < 0))
4640 + /* the last block may be a hole */
4641 + if (!err && all_zero) {
4642 + AuLabel(last hole);
4645 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4646 + /* nfs requires this step to make last hole */
4647 + /* is this only nfs? */
4649 + /* todo: signal_pending? */
4650 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4651 + } while (err == -EAGAIN || err == -EINTR);
4658 + ia->ia_size = dst->f_pos;
4659 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4660 + ia->ia_file = dst;
4661 + h_mtx = &file_inode(dst)->i_mutex;
4662 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4663 + /* no delegation since it is just created */
4664 + err = vfsub_notify_change(&dst->f_path, ia,
4665 + /*delegated*/NULL);
4666 + mutex_unlock(h_mtx);
4673 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4676 + unsigned long blksize;
4677 + unsigned char do_kfree;
4681 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4682 + if (!blksize || PAGE_SIZE < blksize)
4683 + blksize = PAGE_SIZE;
4684 + AuDbg("blksize %lu\n", blksize);
4685 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4687 + buf = kmalloc(blksize, GFP_NOFS);
4689 + buf = (void *)__get_free_page(GFP_NOFS);
4690 + if (unlikely(!buf))
4693 + if (len > (1 << 22))
4694 + AuDbg("copying a large file %lld\n", (long long)len);
4698 + err = au_do_copy_file(dst, src, len, buf, blksize);
4702 + free_page((unsigned long)buf);
4709 + * to support a sparse file which is opened with O_APPEND,
4710 + * we need to close the file.
4712 +static int au_cp_regular(struct au_cp_generic *cpg)
4715 + enum { SRC, DST };
4717 + aufs_bindex_t bindex;
4718 + unsigned int flags;
4719 + struct dentry *dentry;
4721 + struct file *file;
4725 + .bindex = cpg->bsrc,
4726 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4730 + .bindex = cpg->bdst,
4731 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4732 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4733 + .label = &&out_src
4736 + struct super_block *sb;
4738 + /* bsrc branch can be ro/rw. */
4739 + sb = cpg->dentry->d_sb;
4741 + for (i = 0; i < 2; i++, f++) {
4742 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4743 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4744 + /*file*/NULL, f->force_wr);
4745 + err = PTR_ERR(f->file);
4746 + if (IS_ERR(f->file))
4750 + /* try stopping to update while we copyup */
4751 + IMustLock(file[SRC].dentry->d_inode);
4752 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4754 + fput(file[DST].file);
4755 + au_sbr_put(sb, file[DST].bindex);
4758 + fput(file[SRC].file);
4759 + au_sbr_put(sb, file[SRC].bindex);
4764 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4765 + struct au_cpup_reg_attr *h_src_attr)
4769 + struct path h_path;
4770 + struct inode *h_src_inode, *h_dst_inode;
4773 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4774 + l = i_size_read(h_src_inode);
4775 + if (cpg->len == -1 || l < cpg->len)
4778 + /* try stopping to update while we are referencing */
4779 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4780 + au_pin_hdir_unlock(cpg->pin);
4782 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4783 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4784 + h_src_attr->iflags = h_src_inode->i_flags;
4785 + err = vfs_getattr(&h_path, &h_src_attr->st);
4786 + if (unlikely(err)) {
4787 + mutex_unlock(&h_src_inode->i_mutex);
4790 + h_src_attr->valid = 1;
4791 + err = au_cp_regular(cpg);
4792 + mutex_unlock(&h_src_inode->i_mutex);
4793 + rerr = au_pin_hdir_relock(cpg->pin);
4797 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4798 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4799 + h_dst_inode = h_path.dentry->d_inode;
4800 + spin_lock(&h_dst_inode->i_lock);
4801 + h_dst_inode->i_state |= I_LINKABLE;
4802 + spin_unlock(&h_dst_inode->i_lock);
4809 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4810 + struct inode *h_dir)
4813 + mm_segment_t old_fs;
4820 + if (unlikely(!h_src->d_inode->i_op->readlink))
4824 + sym.k = (void *)__get_free_page(GFP_NOFS);
4825 + if (unlikely(!sym.k))
4828 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4829 + old_fs = get_fs();
4830 + set_fs(KERNEL_DS);
4831 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
4836 + sym.k[symlen] = 0;
4837 + err = vfsub_symlink(h_dir, h_path, sym.k);
4839 + free_page((unsigned long)sym.k);
4845 +static noinline_for_stack
4846 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4847 + struct au_cpup_reg_attr *h_src_attr)
4851 + unsigned int mnt_flags;
4852 + unsigned char isdir, isreg, force;
4853 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4854 + struct au_dtime dt;
4855 + struct path h_path;
4856 + struct dentry *h_src, *h_dst, *h_parent;
4857 + struct inode *h_inode, *h_dir;
4858 + struct super_block *sb;
4860 + /* bsrc branch can be ro/rw. */
4861 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4862 + h_inode = h_src->d_inode;
4863 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
4865 + /* try stopping to be referenced while we are creating */
4866 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4867 + if (au_ftest_cpup(cpg->flags, RENAME))
4868 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4869 + AUFS_WH_PFX_LEN));
4870 + h_parent = h_dst->d_parent; /* dir inode is locked */
4871 + h_dir = h_parent->d_inode;
4873 + AuDebugOn(h_parent != h_dst->d_parent);
4875 + sb = cpg->dentry->d_sb;
4876 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4878 + h_path.dentry = h_parent;
4879 + au_dtime_store(&dt, dst_parent, &h_path);
4881 + h_path.dentry = h_dst;
4885 + mode = h_inode->i_mode;
4886 + switch (mode & S_IFMT) {
4889 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4890 + /*want_excl*/true);
4892 + err = au_do_cpup_regular(cpg, h_src_attr);
4896 + err = vfsub_mkdir(h_dir, &h_path, mode);
4899 + * strange behaviour from the users view,
4900 + * particularry setattr case
4902 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4903 + au_cpup_attr_nlink(dst_parent->d_inode,
4905 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4909 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4913 + AuDebugOn(!capable(CAP_MKNOD));
4917 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4920 + AuIOErr("Unknown inode type 0%o\n", mode);
4924 + mnt_flags = au_mntflags(sb);
4925 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4927 + && au_opt_test(mnt_flags, XINO)
4928 + && (h_inode->i_nlink == 1
4929 + || (h_inode->i_state & I_LINKABLE))
4930 + /* todo: unnecessary? */
4931 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4932 + && cpg->bdst < cpg->bsrc
4933 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4934 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4935 + /* ignore this error */
4940 + force = !!cpg->len;
4941 + if (cpg->len == -1)
4942 + force = !!i_size_read(h_inode);
4944 + au_fhsm_wrote(sb, cpg->bdst, force);
4948 + au_dtime_revert(&dt);
4952 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4955 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4956 + struct inode *h_dir;
4957 + aufs_bindex_t bdst;
4959 + dentry = cpg->dentry;
4961 + h_dentry = au_h_dptr(dentry, bdst);
4962 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4964 + au_set_h_dptr(dentry, bdst, NULL);
4965 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4967 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4968 + au_set_h_dptr(dentry, bdst, h_dentry);
4971 + parent = dget_parent(dentry);
4972 + h_parent = au_h_dptr(parent, bdst);
4974 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4975 + if (IS_ERR(h_path->dentry))
4976 + err = PTR_ERR(h_path->dentry);
4978 + if (unlikely(err))
4981 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4982 + h_dir = h_parent->d_inode;
4984 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
4985 + /* no delegation since it is just created */
4986 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
4987 + dput(h_path->dentry);
4994 + * copyup the @dentry from @bsrc to @bdst.
4995 + * the caller must set the both of lower dentries.
4996 + * @len is for truncating when it is -1 copyup the entire file.
4997 + * in link/rename cases, @dst_parent may be different from the real one.
4998 + * basic->bsrc can be larger than basic->bdst.
5000 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5003 + aufs_bindex_t old_ibstart;
5004 + unsigned char isdir, plink;
5005 + struct dentry *h_src, *h_dst, *h_parent;
5006 + struct inode *dst_inode, *h_dir, *inode, *delegated;
5007 + struct super_block *sb;
5008 + struct au_branch *br;
5009 + /* to reuduce stack size */
5011 + struct au_dtime dt;
5012 + struct path h_path;
5013 + struct au_cpup_reg_attr h_src_attr;
5017 + a = kmalloc(sizeof(*a), GFP_NOFS);
5020 + a->h_src_attr.valid = 0;
5022 + sb = cpg->dentry->d_sb;
5023 + br = au_sbr(sb, cpg->bdst);
5024 + a->h_path.mnt = au_br_mnt(br);
5025 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5026 + h_parent = h_dst->d_parent; /* dir inode is locked */
5027 + h_dir = h_parent->d_inode;
5030 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5031 + inode = cpg->dentry->d_inode;
5034 + dst_parent = dget_parent(cpg->dentry);
5038 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5039 + dst_inode = au_h_iptr(inode, cpg->bdst);
5041 + if (unlikely(!plink)) {
5043 + AuIOErr("hi%lu(i%lu) exists on b%d "
5044 + "but plink is disabled\n",
5045 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5049 + if (dst_inode->i_nlink) {
5050 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5052 + h_src = au_plink_lkup(inode, cpg->bdst);
5053 + err = PTR_ERR(h_src);
5054 + if (IS_ERR(h_src))
5056 + if (unlikely(!h_src->d_inode)) {
5058 + AuIOErr("i%lu exists on a upper branch "
5059 + "but not pseudo-linked\n",
5066 + a->h_path.dentry = h_parent;
5067 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5070 + a->h_path.dentry = h_dst;
5072 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5073 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5074 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5076 + au_dtime_revert(&a->dt);
5077 + if (unlikely(err == -EWOULDBLOCK)) {
5078 + pr_warn("cannot retry for NFSv4 delegation"
5079 + " for an internal link\n");
5085 + /* todo: cpup_wh_file? */
5087 + au_update_ibrange(inode, /*do_put_zero*/1);
5090 + isdir = S_ISDIR(inode->i_mode);
5091 + old_ibstart = au_ibstart(inode);
5092 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5093 + if (unlikely(err))
5095 + dst_inode = h_dst->d_inode;
5096 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5097 + /* todo: necessary? */
5098 + /* au_pin_hdir_unlock(cpg->pin); */
5100 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5101 + if (unlikely(err)) {
5102 + /* todo: necessary? */
5103 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5104 + mutex_unlock(&dst_inode->i_mutex);
5108 + if (cpg->bdst < old_ibstart) {
5109 + if (S_ISREG(inode->i_mode)) {
5110 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5111 + if (unlikely(err)) {
5112 + /* ignore an error */
5113 + /* au_pin_hdir_relock(cpg->pin); */
5114 + mutex_unlock(&dst_inode->i_mutex);
5118 + au_set_ibstart(inode, cpg->bdst);
5120 + au_set_ibend(inode, cpg->bdst);
5121 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5122 + au_hi_flags(inode, isdir));
5124 + /* todo: necessary? */
5125 + /* err = au_pin_hdir_relock(cpg->pin); */
5126 + mutex_unlock(&dst_inode->i_mutex);
5127 + if (unlikely(err))
5131 + && (h_src->d_inode->i_nlink > 1
5132 + || h_src->d_inode->i_state & I_LINKABLE)
5134 + au_plink_append(inode, cpg->bdst, h_dst);
5136 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5137 + a->h_path.dentry = h_dst;
5138 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5141 + goto out_parent; /* success */
5145 + a->h_path.dentry = h_parent;
5146 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5147 + a->h_path.dentry = h_dst;
5149 + if (h_dst->d_inode) {
5151 + /* no delegation since it is just created */
5152 + rerr = vfsub_unlink(h_dir, &a->h_path,
5153 + /*delegated*/NULL, /*force*/0);
5155 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5157 + au_dtime_revert(&a->dt);
5159 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5169 +#if 0 /* reserved */
5170 +struct au_cpup_single_args {
5172 + struct au_cp_generic *cpg;
5173 + struct dentry *dst_parent;
5176 +static void au_call_cpup_single(void *args)
5178 + struct au_cpup_single_args *a = args;
5180 + au_pin_hdir_acquire_nest(a->cpg->pin);
5181 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5182 + au_pin_hdir_release(a->cpg->pin);
5187 + * prevent SIGXFSZ in copy-up.
5188 + * testing CAP_MKNOD is for generic fs,
5189 + * but CAP_FSETID is for xfs only, currently.
5191 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5194 + struct super_block *sb;
5195 + struct inode *h_dir;
5198 + sb = au_pinned_parent(pin)->d_sb;
5199 + if (!au_wkq_test()
5200 + && (!au_sbi(sb)->si_plink_maint_pid
5201 + || au_plink_maint(sb, AuLock_NOPLM))) {
5202 + switch (mode & S_IFMT) {
5204 + /* no condition about RLIMIT_FSIZE and the file size */
5209 + do_sio = !capable(CAP_MKNOD);
5213 + do_sio = ((mode & (S_ISUID | S_ISGID))
5214 + && !capable(CAP_FSETID));
5215 + /* this workaround may be removed in the future */
5217 + h_dir = au_pinned_h_dir(pin);
5218 + do_sio = h_dir->i_mode & S_ISVTX;
5225 +#if 0 /* reserved */
5226 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5229 + struct dentry *h_dentry;
5231 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5232 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
5233 + err = au_cpup_single(cpg, dst_parent);
5235 + struct au_cpup_single_args args = {
5238 + .dst_parent = dst_parent
5240 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5241 + if (unlikely(wkq_err))
5250 + * copyup the @dentry from the first active lower branch to @bdst,
5251 + * using au_cpup_single().
5253 +static int au_cpup_simple(struct au_cp_generic *cpg)
5256 + unsigned int flags_orig;
5257 + struct dentry *dentry;
5259 + AuDebugOn(cpg->bsrc < 0);
5261 + dentry = cpg->dentry;
5262 + DiMustWriteLock(dentry);
5264 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5266 + flags_orig = cpg->flags;
5267 + au_fset_cpup(cpg->flags, RENAME);
5268 + err = au_cpup_single(cpg, NULL);
5269 + cpg->flags = flags_orig;
5271 + return 0; /* success */
5274 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5275 + au_set_dbstart(dentry, cpg->bsrc);
5281 +struct au_cpup_simple_args {
5283 + struct au_cp_generic *cpg;
5286 +static void au_call_cpup_simple(void *args)
5288 + struct au_cpup_simple_args *a = args;
5290 + au_pin_hdir_acquire_nest(a->cpg->pin);
5291 + *a->errp = au_cpup_simple(a->cpg);
5292 + au_pin_hdir_release(a->cpg->pin);
5295 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5298 + struct dentry *dentry, *parent;
5299 + struct file *h_file;
5300 + struct inode *h_dir;
5302 + dentry = cpg->dentry;
5304 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5305 + AuDebugOn(cpg->bsrc < 0);
5306 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5307 + err = PTR_ERR(h_file);
5308 + if (IS_ERR(h_file))
5312 + parent = dget_parent(dentry);
5313 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
5314 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5315 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5316 + err = au_cpup_simple(cpg);
5318 + struct au_cpup_simple_args args = {
5322 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5323 + if (unlikely(wkq_err))
5329 + au_h_open_post(dentry, cpg->bsrc, h_file);
5335 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5337 + aufs_bindex_t bsrc, bend;
5338 + struct dentry *dentry, *h_dentry;
5340 + if (cpg->bsrc < 0) {
5341 + dentry = cpg->dentry;
5342 + bend = au_dbend(dentry);
5343 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5344 + h_dentry = au_h_dptr(dentry, bsrc);
5346 + AuDebugOn(!h_dentry->d_inode);
5350 + AuDebugOn(bsrc > bend);
5353 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5354 + return au_do_sio_cpup_simple(cpg);
5357 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5359 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5360 + return au_do_sio_cpup_simple(cpg);
5363 +/* ---------------------------------------------------------------------- */
5366 + * copyup the deleted file for writing.
5368 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5369 + struct file *file)
5372 + unsigned int flags_orig;
5373 + aufs_bindex_t bsrc_orig;
5374 + struct dentry *h_d_dst, *h_d_start;
5375 + struct au_dinfo *dinfo;
5376 + struct au_hdentry *hdp;
5378 + dinfo = au_di(cpg->dentry);
5379 + AuRwMustWriteLock(&dinfo->di_rwsem);
5381 + bsrc_orig = cpg->bsrc;
5382 + cpg->bsrc = dinfo->di_bstart;
5383 + hdp = dinfo->di_hdentry;
5384 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5385 + dinfo->di_bstart = cpg->bdst;
5386 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5389 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5390 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
5392 + flags_orig = cpg->flags;
5393 + cpg->flags = !AuCpup_DTIME;
5394 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5395 + cpg->flags = flags_orig;
5398 + err = au_reopen_nondir(file);
5399 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5401 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5402 + dinfo->di_bstart = cpg->bsrc;
5403 + cpg->bsrc = bsrc_orig;
5408 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5411 + aufs_bindex_t bdst;
5412 + struct au_dtime dt;
5413 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5414 + struct au_branch *br;
5415 + struct path h_path;
5417 + dentry = cpg->dentry;
5419 + br = au_sbr(dentry->d_sb, bdst);
5420 + parent = dget_parent(dentry);
5421 + h_parent = au_h_dptr(parent, bdst);
5422 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5423 + err = PTR_ERR(wh_dentry);
5424 + if (IS_ERR(wh_dentry))
5427 + h_path.dentry = h_parent;
5428 + h_path.mnt = au_br_mnt(br);
5429 + au_dtime_store(&dt, parent, &h_path);
5430 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5431 + if (unlikely(err))
5435 + h_path.dentry = wh_dentry;
5436 + if (!d_is_dir(wh_dentry)) {
5437 + /* no delegation since it is just created */
5438 + err = vfsub_unlink(h_parent->d_inode, &h_path,
5439 + /*delegated*/NULL, /*force*/0);
5441 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
5442 + if (unlikely(err)) {
5443 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5447 + au_dtime_revert(&dt);
5448 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
5457 +struct au_cpup_wh_args {
5459 + struct au_cp_generic *cpg;
5460 + struct file *file;
5463 +static void au_call_cpup_wh(void *args)
5465 + struct au_cpup_wh_args *a = args;
5467 + au_pin_hdir_acquire_nest(a->cpg->pin);
5468 + *a->errp = au_cpup_wh(a->cpg, a->file);
5469 + au_pin_hdir_release(a->cpg->pin);
5472 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5475 + aufs_bindex_t bdst;
5476 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5477 + struct inode *dir, *h_dir, *h_tmpdir;
5478 + struct au_wbr *wbr;
5479 + struct au_pin wh_pin, *pin_orig;
5481 + dentry = cpg->dentry;
5483 + parent = dget_parent(dentry);
5484 + dir = parent->d_inode;
5487 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5490 + if (!h_dir->i_nlink) {
5491 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5492 + h_orph = wbr->wbr_orph;
5494 + h_parent = dget(au_h_dptr(parent, bdst));
5495 + au_set_h_dptr(parent, bdst, dget(h_orph));
5496 + h_tmpdir = h_orph->d_inode;
5497 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5499 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5500 + /* todo: au_h_open_pre()? */
5502 + pin_orig = cpg->pin;
5503 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5504 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5505 + cpg->pin = &wh_pin;
5508 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5509 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5510 + err = au_cpup_wh(cpg, file);
5512 + struct au_cpup_wh_args args = {
5517 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5518 + if (unlikely(wkq_err))
5523 + mutex_unlock(&h_tmpdir->i_mutex);
5524 + /* todo: au_h_open_post()? */
5525 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5526 + au_set_h_dptr(parent, bdst, h_parent);
5527 + AuDebugOn(!pin_orig);
5528 + cpg->pin = pin_orig;
5536 +/* ---------------------------------------------------------------------- */
5539 + * generic routine for both of copy-up and copy-down.
5541 +/* cf. revalidate function in file.c */
5542 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5543 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5544 + struct au_pin *pin,
5545 + struct dentry *h_parent, void *arg),
5549 + struct au_pin pin;
5550 + struct dentry *d, *parent, *h_parent, *real_parent;
5553 + parent = dget_parent(dentry);
5554 + if (IS_ROOT(parent))
5557 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5558 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5560 + /* do not use au_dpage */
5561 + real_parent = parent;
5564 + parent = dget_parent(dentry);
5565 + h_parent = au_h_dptr(parent, bdst);
5567 + goto out; /* success */
5569 + /* find top dir which is necessary to cpup */
5573 + parent = dget_parent(d);
5574 + di_read_lock_parent3(parent, !AuLock_IR);
5575 + h_parent = au_h_dptr(parent, bdst);
5576 + di_read_unlock(parent, !AuLock_IR);
5577 + } while (!h_parent);
5579 + if (d != real_parent)
5580 + di_write_lock_child3(d);
5582 + /* somebody else might create while we were sleeping */
5583 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5584 + if (au_h_dptr(d, bdst))
5585 + au_update_dbstart(d);
5587 + au_pin_set_dentry(&pin, d);
5588 + err = au_do_pin(&pin);
5590 + err = cp(d, bdst, &pin, h_parent, arg);
5595 + if (d != real_parent)
5596 + di_write_unlock(d);
5597 + if (unlikely(err))
5606 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5607 + struct au_pin *pin,
5608 + struct dentry *h_parent __maybe_unused,
5609 + void *arg __maybe_unused)
5611 + struct au_cp_generic cpg = {
5617 + .flags = AuCpup_DTIME
5619 + return au_sio_cpup_simple(&cpg);
5622 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5624 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5627 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5630 + struct dentry *parent;
5631 + struct inode *dir;
5633 + parent = dget_parent(dentry);
5634 + dir = parent->d_inode;
5636 + if (au_h_iptr(dir, bdst))
5639 + di_read_unlock(parent, AuLock_IR);
5640 + di_write_lock_parent(parent);
5641 + /* someone else might change our inode while we were sleeping */
5642 + if (!au_h_iptr(dir, bdst))
5643 + err = au_cpup_dirs(dentry, bdst);
5644 + di_downgrade_lock(parent, AuLock_IR);
5650 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5651 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5652 +++ linux/fs/aufs/cpup.h 2015-04-13 15:10:20.780156788 +0200
5655 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5657 + * This program, aufs is free software; you can redistribute it and/or modify
5658 + * it under the terms of the GNU General Public License as published by
5659 + * the Free Software Foundation; either version 2 of the License, or
5660 + * (at your option) any later version.
5662 + * This program is distributed in the hope that it will be useful,
5663 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5664 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5665 + * GNU General Public License for more details.
5667 + * You should have received a copy of the GNU General Public License
5668 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5672 + * copy-up/down functions
5675 +#ifndef __AUFS_CPUP_H__
5676 +#define __AUFS_CPUP_H__
5680 +#include <linux/path.h>
5686 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5687 +void au_cpup_attr_timesizes(struct inode *inode);
5688 +void au_cpup_attr_nlink(struct inode *inode, int force);
5689 +void au_cpup_attr_changeable(struct inode *inode);
5690 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5691 +void au_cpup_attr_all(struct inode *inode, int force);
5693 +/* ---------------------------------------------------------------------- */
5695 +struct au_cp_generic {
5696 + struct dentry *dentry;
5697 + aufs_bindex_t bdst, bsrc;
5699 + struct au_pin *pin;
5700 + unsigned int flags;
5704 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5705 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5707 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5708 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5710 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5712 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5713 + the branch is marked as RO */
5715 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5716 +#define au_fset_cpup(flags, name) \
5717 + do { (flags) |= AuCpup_##name; } while (0)
5718 +#define au_fclr_cpup(flags, name) \
5719 + do { (flags) &= ~AuCpup_##name; } while (0)
5721 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5722 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5723 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5724 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5726 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5727 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5728 + struct au_pin *pin,
5729 + struct dentry *h_parent, void *arg),
5731 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5732 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5734 +/* ---------------------------------------------------------------------- */
5736 +/* keep timestamps when copyup */
5738 + struct dentry *dt_dentry;
5739 + struct path dt_h_path;
5740 + struct timespec dt_atime, dt_mtime;
5742 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5743 + struct path *h_path);
5744 +void au_dtime_revert(struct au_dtime *dt);
5746 +#endif /* __KERNEL__ */
5747 +#endif /* __AUFS_CPUP_H__ */
5748 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5749 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5750 +++ linux/fs/aufs/dbgaufs.c 2015-04-13 15:10:20.780156788 +0200
5753 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5755 + * This program, aufs is free software; you can redistribute it and/or modify
5756 + * it under the terms of the GNU General Public License as published by
5757 + * the Free Software Foundation; either version 2 of the License, or
5758 + * (at your option) any later version.
5760 + * This program is distributed in the hope that it will be useful,
5761 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5762 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5763 + * GNU General Public License for more details.
5765 + * You should have received a copy of the GNU General Public License
5766 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5770 + * debugfs interface
5773 +#include <linux/debugfs.h>
5776 +#ifndef CONFIG_SYSFS
5777 +#error DEBUG_FS depends upon SYSFS
5780 +static struct dentry *dbgaufs;
5781 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5783 +/* 20 is max digits length of ulong 64 */
5784 +struct dbgaufs_arg {
5790 + * common function for all XINO files
5792 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5793 + struct file *file)
5795 + kfree(file->private_data);
5799 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5803 + struct dbgaufs_arg *p;
5806 + p = kmalloc(sizeof(*p), GFP_NOFS);
5812 + file->private_data = p;
5816 + err = vfs_getattr(&xf->f_path, &st);
5820 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5821 + (long)file_count(xf), st.blocks, st.blksize,
5822 + (long long)st.size);
5824 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5825 + st.blocks, st.blksize,
5826 + (long long)st.size);
5827 + AuDebugOn(p->n >= sizeof(p->a));
5829 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5838 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5839 + size_t count, loff_t *ppos)
5841 + struct dbgaufs_arg *p;
5843 + p = file->private_data;
5844 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5847 +/* ---------------------------------------------------------------------- */
5849 +struct dbgaufs_plink_arg {
5854 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5855 + struct file *file)
5857 + free_page((unsigned long)file->private_data);
5861 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5863 + int err, i, limit;
5864 + unsigned long n, sum;
5865 + struct dbgaufs_plink_arg *p;
5866 + struct au_sbinfo *sbinfo;
5867 + struct super_block *sb;
5868 + struct au_sphlhead *sphl;
5871 + p = (void *)get_zeroed_page(GFP_NOFS);
5876 + sbinfo = inode->i_private;
5877 + sb = sbinfo->si_sb;
5878 + si_noflush_read_lock(sb);
5879 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5880 + limit = PAGE_SIZE - sizeof(p->n);
5882 + /* the number of buckets */
5883 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5888 + for (i = 0, sphl = sbinfo->si_plink;
5889 + i < AuPlink_NHASH;
5891 + n = au_sphl_count(sphl);
5894 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5897 + if (unlikely(limit <= 0))
5900 + p->a[p->n - 1] = '\n';
5902 + /* the sum of plinks */
5903 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5906 + if (unlikely(limit <= 0))
5909 +#define str "1\n0\n0\n"
5910 + p->n = sizeof(str) - 1;
5911 + strcpy(p->a, str);
5914 + si_read_unlock(sb);
5917 + file->private_data = p;
5918 + goto out; /* success */
5921 + free_page((unsigned long)p);
5926 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5927 + size_t count, loff_t *ppos)
5929 + struct dbgaufs_plink_arg *p;
5931 + p = file->private_data;
5932 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5935 +static const struct file_operations dbgaufs_plink_fop = {
5936 + .owner = THIS_MODULE,
5937 + .open = dbgaufs_plink_open,
5938 + .release = dbgaufs_plink_release,
5939 + .read = dbgaufs_plink_read
5942 +/* ---------------------------------------------------------------------- */
5944 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5947 + struct au_sbinfo *sbinfo;
5948 + struct super_block *sb;
5950 + sbinfo = inode->i_private;
5951 + sb = sbinfo->si_sb;
5952 + si_noflush_read_lock(sb);
5953 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5954 + si_read_unlock(sb);
5958 +static const struct file_operations dbgaufs_xib_fop = {
5959 + .owner = THIS_MODULE,
5960 + .open = dbgaufs_xib_open,
5961 + .release = dbgaufs_xi_release,
5962 + .read = dbgaufs_xi_read
5965 +/* ---------------------------------------------------------------------- */
5967 +#define DbgaufsXi_PREFIX "xi"
5969 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5973 + struct au_sbinfo *sbinfo;
5974 + struct super_block *sb;
5976 + struct qstr *name;
5980 + name = &file->f_path.dentry->d_name;
5981 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5982 + || memcmp(name->name, DbgaufsXi_PREFIX,
5983 + sizeof(DbgaufsXi_PREFIX) - 1)))
5985 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5986 + if (unlikely(err))
5989 + sbinfo = inode->i_private;
5990 + sb = sbinfo->si_sb;
5991 + si_noflush_read_lock(sb);
5992 + if (l <= au_sbend(sb)) {
5993 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5994 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5997 + si_read_unlock(sb);
6003 +static const struct file_operations dbgaufs_xino_fop = {
6004 + .owner = THIS_MODULE,
6005 + .open = dbgaufs_xino_open,
6006 + .release = dbgaufs_xi_release,
6007 + .read = dbgaufs_xi_read
6010 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6012 + aufs_bindex_t bend;
6013 + struct au_branch *br;
6014 + struct au_xino_file *xi;
6016 + if (!au_sbi(sb)->si_dbgaufs)
6019 + bend = au_sbend(sb);
6020 + for (; bindex <= bend; bindex++) {
6021 + br = au_sbr(sb, bindex);
6022 + xi = &br->br_xino;
6023 + debugfs_remove(xi->xi_dbgaufs);
6024 + xi->xi_dbgaufs = NULL;
6028 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6030 + struct au_sbinfo *sbinfo;
6031 + struct dentry *parent;
6032 + struct au_branch *br;
6033 + struct au_xino_file *xi;
6034 + aufs_bindex_t bend;
6035 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6037 + sbinfo = au_sbi(sb);
6038 + parent = sbinfo->si_dbgaufs;
6042 + bend = au_sbend(sb);
6043 + for (; bindex <= bend; bindex++) {
6044 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6045 + br = au_sbr(sb, bindex);
6046 + xi = &br->br_xino;
6047 + AuDebugOn(xi->xi_dbgaufs);
6048 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6049 + sbinfo, &dbgaufs_xino_fop);
6050 + /* ignore an error */
6051 + if (unlikely(!xi->xi_dbgaufs))
6052 + AuWarn1("failed %s under debugfs\n", name);
6056 +/* ---------------------------------------------------------------------- */
6058 +#ifdef CONFIG_AUFS_EXPORT
6059 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6062 + struct au_sbinfo *sbinfo;
6063 + struct super_block *sb;
6065 + sbinfo = inode->i_private;
6066 + sb = sbinfo->si_sb;
6067 + si_noflush_read_lock(sb);
6068 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6069 + si_read_unlock(sb);
6073 +static const struct file_operations dbgaufs_xigen_fop = {
6074 + .owner = THIS_MODULE,
6075 + .open = dbgaufs_xigen_open,
6076 + .release = dbgaufs_xi_release,
6077 + .read = dbgaufs_xi_read
6080 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6085 + * This function is a dynamic '__init' function actually,
6086 + * so the tiny check for si_rwsem is unnecessary.
6088 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6091 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6092 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6093 + &dbgaufs_xigen_fop);
6094 + if (sbinfo->si_dbgaufs_xigen)
6100 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6104 +#endif /* CONFIG_AUFS_EXPORT */
6106 +/* ---------------------------------------------------------------------- */
6108 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6111 + * This function is a dynamic '__fin' function actually,
6112 + * so the tiny check for si_rwsem is unnecessary.
6114 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6116 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6117 + sbinfo->si_dbgaufs = NULL;
6118 + kobject_put(&sbinfo->si_kobj);
6121 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6124 + char name[SysaufsSiNameLen];
6127 + * This function is a dynamic '__init' function actually,
6128 + * so the tiny check for si_rwsem is unnecessary.
6130 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6134 + AuErr1("/debug/aufs is uninitialized\n");
6139 + sysaufs_name(sbinfo, name);
6140 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6141 + if (unlikely(!sbinfo->si_dbgaufs))
6143 + kobject_get(&sbinfo->si_kobj);
6145 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6146 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6147 + &dbgaufs_xib_fop);
6148 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6151 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6152 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6153 + &dbgaufs_plink_fop);
6154 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6157 + err = dbgaufs_xigen_init(sbinfo);
6159 + goto out; /* success */
6162 + dbgaufs_si_fin(sbinfo);
6167 +/* ---------------------------------------------------------------------- */
6169 +void dbgaufs_fin(void)
6171 + debugfs_remove(dbgaufs);
6174 +int __init dbgaufs_init(void)
6179 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6184 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6185 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6186 +++ linux/fs/aufs/dbgaufs.h 2015-04-13 15:10:20.780156788 +0200
6189 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6191 + * This program, aufs is free software; you can redistribute it and/or modify
6192 + * it under the terms of the GNU General Public License as published by
6193 + * the Free Software Foundation; either version 2 of the License, or
6194 + * (at your option) any later version.
6196 + * This program is distributed in the hope that it will be useful,
6197 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6198 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6199 + * GNU General Public License for more details.
6201 + * You should have received a copy of the GNU General Public License
6202 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6206 + * debugfs interface
6209 +#ifndef __DBGAUFS_H__
6210 +#define __DBGAUFS_H__
6214 +struct super_block;
6217 +#ifdef CONFIG_DEBUG_FS
6219 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6220 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6221 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6222 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6223 +void dbgaufs_fin(void);
6224 +int __init dbgaufs_init(void);
6226 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6227 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6228 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6229 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6230 +AuStubVoid(dbgaufs_fin, void)
6231 +AuStubInt0(__init dbgaufs_init, void)
6232 +#endif /* CONFIG_DEBUG_FS */
6234 +#endif /* __KERNEL__ */
6235 +#endif /* __DBGAUFS_H__ */
6236 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6237 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6238 +++ linux/fs/aufs/dcsub.c 2015-04-13 15:10:20.780156788 +0200
6241 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6243 + * This program, aufs is free software; you can redistribute it and/or modify
6244 + * it under the terms of the GNU General Public License as published by
6245 + * the Free Software Foundation; either version 2 of the License, or
6246 + * (at your option) any later version.
6248 + * This program is distributed in the hope that it will be useful,
6249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6251 + * GNU General Public License for more details.
6253 + * You should have received a copy of the GNU General Public License
6254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6258 + * sub-routines for dentry cache
6263 +static void au_dpage_free(struct au_dpage *dpage)
6266 + struct dentry **p;
6268 + p = dpage->dentries;
6269 + for (i = 0; i < dpage->ndentry; i++)
6271 + free_page((unsigned long)dpage->dentries);
6274 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6280 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6281 + if (unlikely(!dpages->dpages))
6284 + p = (void *)__get_free_page(gfp);
6288 + dpages->dpages[0].ndentry = 0;
6289 + dpages->dpages[0].dentries = p;
6290 + dpages->ndpage = 1;
6291 + return 0; /* success */
6294 + kfree(dpages->dpages);
6299 +void au_dpages_free(struct au_dcsub_pages *dpages)
6302 + struct au_dpage *p;
6304 + p = dpages->dpages;
6305 + for (i = 0; i < dpages->ndpage; i++)
6306 + au_dpage_free(p++);
6307 + kfree(dpages->dpages);
6310 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6311 + struct dentry *dentry, gfp_t gfp)
6314 + struct au_dpage *dpage;
6317 + dpage = dpages->dpages + dpages->ndpage - 1;
6318 + sz = PAGE_SIZE / sizeof(dentry);
6319 + if (unlikely(dpage->ndentry >= sz)) {
6320 + AuLabel(new dpage);
6322 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6323 + p = au_kzrealloc(dpages->dpages, sz,
6324 + sz + sizeof(*dpages->dpages), gfp);
6328 + dpages->dpages = p;
6329 + dpage = dpages->dpages + dpages->ndpage;
6330 + p = (void *)__get_free_page(gfp);
6334 + dpage->ndentry = 0;
6335 + dpage->dentries = p;
6339 + AuDebugOn(au_dcount(dentry) <= 0);
6340 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6341 + return 0; /* success */
6347 +/* todo: BAD approach */
6348 +/* copied from linux/fs/dcache.c */
6356 +extern void d_walk(struct dentry *parent, void *data,
6357 + enum d_walk_ret (*enter)(void *, struct dentry *),
6358 + void (*finish)(void *));
6360 +struct ac_dpages_arg {
6362 + struct au_dcsub_pages *dpages;
6363 + struct super_block *sb;
6364 + au_dpages_test test;
6368 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6370 + enum d_walk_ret ret;
6371 + struct ac_dpages_arg *arg = _arg;
6373 + ret = D_WALK_CONTINUE;
6374 + if (dentry->d_sb == arg->sb
6375 + && !IS_ROOT(dentry)
6376 + && au_dcount(dentry) > 0
6378 + && (!arg->test || arg->test(dentry, arg->arg))) {
6379 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6380 + if (unlikely(arg->err))
6381 + ret = D_WALK_QUIT;
6387 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6388 + au_dpages_test test, void *arg)
6390 + struct ac_dpages_arg args = {
6398 + d_walk(root, &args, au_call_dpages_append, NULL);
6403 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6404 + int do_include, au_dpages_test test, void *arg)
6409 + write_seqlock(&rename_lock);
6410 + spin_lock(&dentry->d_lock);
6412 + && au_dcount(dentry) > 0
6413 + && (!test || test(dentry, arg)))
6414 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6415 + spin_unlock(&dentry->d_lock);
6416 + if (unlikely(err))
6420 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6423 + while (!IS_ROOT(dentry)) {
6424 + dentry = dentry->d_parent; /* rename_lock is locked */
6425 + spin_lock(&dentry->d_lock);
6426 + if (au_dcount(dentry) > 0
6427 + && (!test || test(dentry, arg)))
6428 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6429 + spin_unlock(&dentry->d_lock);
6430 + if (unlikely(err))
6435 + write_sequnlock(&rename_lock);
6439 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6441 + return au_di(dentry) && dentry->d_sb == arg;
6444 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6445 + struct dentry *dentry, int do_include)
6447 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6448 + au_dcsub_dpages_aufs, dentry->d_sb);
6451 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6453 + struct path path[2] = {
6462 + return path_is_under(path + 0, path + 1);
6464 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6465 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6466 +++ linux/fs/aufs/dcsub.h 2015-04-13 15:10:20.780156788 +0200
6469 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6471 + * This program, aufs is free software; you can redistribute it and/or modify
6472 + * it under the terms of the GNU General Public License as published by
6473 + * the Free Software Foundation; either version 2 of the License, or
6474 + * (at your option) any later version.
6476 + * This program is distributed in the hope that it will be useful,
6477 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6478 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6479 + * GNU General Public License for more details.
6481 + * You should have received a copy of the GNU General Public License
6482 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6486 + * sub-routines for dentry cache
6489 +#ifndef __AUFS_DCSUB_H__
6490 +#define __AUFS_DCSUB_H__
6494 +#include <linux/dcache.h>
6495 +#include <linux/fs.h>
6499 + struct dentry **dentries;
6502 +struct au_dcsub_pages {
6504 + struct au_dpage *dpages;
6507 +/* ---------------------------------------------------------------------- */
6510 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6511 +void au_dpages_free(struct au_dcsub_pages *dpages);
6512 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6513 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6514 + au_dpages_test test, void *arg);
6515 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6516 + int do_include, au_dpages_test test, void *arg);
6517 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6518 + struct dentry *dentry, int do_include);
6519 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6521 +/* ---------------------------------------------------------------------- */
6524 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6525 + * include/linux/dcache.h. Try them (in the future).
6528 +static inline int au_d_hashed_positive(struct dentry *d)
6531 + struct inode *inode = d->d_inode;
6534 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
6539 +static inline int au_d_linkable(struct dentry *d)
6542 + struct inode *inode = d->d_inode;
6544 + err = au_d_hashed_positive(d);
6547 + && (inode->i_state & I_LINKABLE))
6552 +static inline int au_d_alive(struct dentry *d)
6555 + struct inode *inode;
6559 + err = au_d_hashed_positive(d);
6561 + inode = d->d_inode;
6562 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6568 +static inline int au_alive_dir(struct dentry *d)
6572 + err = au_d_alive(d);
6573 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6578 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6580 + return a->len == b->len
6581 + && !memcmp(a->name, b->name, a->len);
6586 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6588 + * the type of d_lockref.count became int, but the inlined function d_count()
6589 + * still returns unsigned int.
6590 + * I don't know why. Maybe it is for every d_count() users?
6591 + * Anyway au_dcount() lives on.
6593 +static inline int au_dcount(struct dentry *d)
6595 + return (int)d_count(d);
6598 +#endif /* __KERNEL__ */
6599 +#endif /* __AUFS_DCSUB_H__ */
6600 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6601 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6602 +++ linux/fs/aufs/debug.c 2015-04-13 15:10:20.780156788 +0200
6605 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6607 + * This program, aufs is free software; you can redistribute it and/or modify
6608 + * it under the terms of the GNU General Public License as published by
6609 + * the Free Software Foundation; either version 2 of the License, or
6610 + * (at your option) any later version.
6612 + * This program is distributed in the hope that it will be useful,
6613 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6614 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6615 + * GNU General Public License for more details.
6617 + * You should have received a copy of the GNU General Public License
6618 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6622 + * debug print functions
6627 +/* Returns 0, or -errno. arg is in kp->arg. */
6628 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6632 + err = kstrtoint(val, 0, &n);
6642 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6643 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6648 + return sprintf(buffer, "%d", atomic_read(a));
6651 +static struct kernel_param_ops param_ops_atomic_t = {
6652 + .set = param_atomic_t_set,
6653 + .get = param_atomic_t_get
6654 + /* void (*free)(void *arg) */
6657 +atomic_t aufs_debug = ATOMIC_INIT(0);
6658 +MODULE_PARM_DESC(debug, "debug print");
6659 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6661 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6662 +char *au_plevel = KERN_DEBUG;
6663 +#define dpri(fmt, ...) do { \
6665 + && strcmp(au_plevel, KERN_DEBUG)) \
6666 + || au_debug_test()) \
6667 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6670 +/* ---------------------------------------------------------------------- */
6672 +void au_dpri_whlist(struct au_nhash *whlist)
6674 + unsigned long ul, n;
6675 + struct hlist_head *head;
6676 + struct au_vdir_wh *pos;
6678 + n = whlist->nh_num;
6679 + head = whlist->nh_head;
6680 + for (ul = 0; ul < n; ul++) {
6681 + hlist_for_each_entry(pos, head, wh_hash)
6682 + dpri("b%d, %.*s, %d\n",
6684 + pos->wh_str.len, pos->wh_str.name,
6690 +void au_dpri_vdir(struct au_vdir *vdir)
6693 + union au_vdir_deblk_p p;
6696 + if (!vdir || IS_ERR(vdir)) {
6697 + dpri("err %ld\n", PTR_ERR(vdir));
6701 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6702 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6703 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6704 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6705 + p.deblk = vdir->vd_deblk[ul];
6707 + dpri("[%lu]: %p\n", ul, o);
6711 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6712 + struct dentry *wh)
6717 + if (!inode || IS_ERR(inode)) {
6718 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6722 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6723 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6724 + && sizeof(inode->i_blocks) != sizeof(u64));
6726 + n = (void *)wh->d_name.name;
6727 + l = wh->d_name.len;
6730 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6731 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6733 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6734 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6735 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6736 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6737 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6738 + inode->i_state, inode->i_flags, inode->i_version,
6739 + inode->i_generation,
6740 + l ? ", wh " : "", l, n);
6744 +void au_dpri_inode(struct inode *inode)
6746 + struct au_iinfo *iinfo;
6747 + aufs_bindex_t bindex;
6750 + err = do_pri_inode(-1, inode, -1, NULL);
6751 + if (err || !au_test_aufs(inode->i_sb))
6754 + iinfo = au_ii(inode);
6757 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6758 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6759 + if (iinfo->ii_bstart < 0)
6762 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6763 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6764 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6765 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6769 +void au_dpri_dalias(struct inode *inode)
6773 + spin_lock(&inode->i_lock);
6774 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6775 + au_dpri_dentry(d);
6776 + spin_unlock(&inode->i_lock);
6779 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6781 + struct dentry *wh = NULL;
6783 + struct au_iinfo *iinfo;
6785 + if (!dentry || IS_ERR(dentry)) {
6786 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6789 + /* do not call dget_parent() here */
6790 + /* note: access d_xxx without d_lock */
6791 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6792 + bindex, dentry, dentry,
6793 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6794 + au_dcount(dentry), dentry->d_flags,
6795 + d_unhashed(dentry) ? "un" : "");
6797 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6798 + iinfo = au_ii(dentry->d_inode);
6800 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6801 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6804 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6808 +void au_dpri_dentry(struct dentry *dentry)
6810 + struct au_dinfo *dinfo;
6811 + aufs_bindex_t bindex;
6813 + struct au_hdentry *hdp;
6815 + err = do_pri_dentry(-1, dentry);
6816 + if (err || !au_test_aufs(dentry->d_sb))
6819 + dinfo = au_di(dentry);
6822 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6823 + dinfo->di_bstart, dinfo->di_bend,
6824 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6825 + dinfo->di_tmpfile);
6826 + if (dinfo->di_bstart < 0)
6828 + hdp = dinfo->di_hdentry;
6829 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6830 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6833 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6837 + if (!file || IS_ERR(file)) {
6838 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6843 + && file->f_path.dentry
6844 + && au_test_aufs(file->f_path.dentry->d_sb)
6846 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6847 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6848 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6849 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6850 + file->f_version, file->f_pos, a);
6851 + if (file->f_path.dentry)
6852 + do_pri_dentry(bindex, file->f_path.dentry);
6856 +void au_dpri_file(struct file *file)
6858 + struct au_finfo *finfo;
6859 + struct au_fidir *fidir;
6860 + struct au_hfile *hfile;
6861 + aufs_bindex_t bindex;
6864 + err = do_pri_file(-1, file);
6866 + || !file->f_path.dentry
6867 + || !au_test_aufs(file->f_path.dentry->d_sb))
6870 + finfo = au_fi(file);
6873 + if (finfo->fi_btop < 0)
6875 + fidir = finfo->fi_hdir;
6877 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6879 + for (bindex = finfo->fi_btop;
6880 + bindex >= 0 && bindex <= fidir->fd_bbot;
6882 + hfile = fidir->fd_hfile + bindex;
6883 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6887 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6889 + struct vfsmount *mnt;
6890 + struct super_block *sb;
6892 + if (!br || IS_ERR(br))
6894 + mnt = au_br_mnt(br);
6895 + if (!mnt || IS_ERR(mnt))
6898 + if (!sb || IS_ERR(sb))
6901 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6902 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6904 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6905 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6906 + sb->s_flags, sb->s_count,
6907 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6911 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6915 +void au_dpri_sb(struct super_block *sb)
6917 + struct au_sbinfo *sbinfo;
6918 + aufs_bindex_t bindex;
6920 + /* to reuduce stack size */
6922 + struct vfsmount mnt;
6923 + struct au_branch fake;
6926 + /* this function can be called from magic sysrq */
6927 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6928 + if (unlikely(!a)) {
6929 + dpri("no memory\n");
6933 + a->mnt.mnt_sb = sb;
6934 + a->fake.br_perm = 0;
6935 + a->fake.br_path.mnt = &a->mnt;
6936 + a->fake.br_xino.xi_file = NULL;
6937 + atomic_set(&a->fake.br_count, 0);
6938 + smp_mb(); /* atomic_set */
6939 + err = do_pri_br(-1, &a->fake);
6941 + dpri("dev 0x%x\n", sb->s_dev);
6942 + if (err || !au_test_aufs(sb))
6945 + sbinfo = au_sbi(sb);
6948 + dpri("nw %d, gen %u, kobj %d\n",
6949 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6950 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6951 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6952 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6955 +/* ---------------------------------------------------------------------- */
6957 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6959 + struct inode *h_inode, *inode = dentry->d_inode;
6960 + struct dentry *h_dentry;
6961 + aufs_bindex_t bindex, bend, bi;
6963 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6966 + bend = au_dbend(dentry);
6967 + bi = au_ibend(inode);
6970 + bindex = au_dbstart(dentry);
6971 + bi = au_ibstart(inode);
6975 + for (; bindex <= bend; bindex++) {
6976 + h_dentry = au_h_dptr(dentry, bindex);
6979 + h_inode = au_h_iptr(inode, bindex);
6980 + if (unlikely(h_inode != h_dentry->d_inode)) {
6982 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6983 + AuDbgDentry(dentry);
6984 + AuDbgInode(inode);
6991 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6994 + struct au_dcsub_pages dpages;
6995 + struct au_dpage *dpage;
6996 + struct dentry **dentries;
6998 + err = au_dpages_init(&dpages, GFP_NOFS);
7000 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7002 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7003 + dpage = dpages.dpages + i;
7004 + dentries = dpage->dentries;
7005 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7006 + AuDebugOn(au_digen_test(dentries[j], sigen));
7008 + au_dpages_free(&dpages);
7011 +void au_dbg_verify_kthread(void)
7013 + if (au_wkq_test()) {
7016 + * It may be recursive, but udba=notify between two aufs mounts,
7017 + * where a single ro branch is shared, is not a problem.
7023 +/* ---------------------------------------------------------------------- */
7025 +int __init au_debug_init(void)
7027 + aufs_bindex_t bindex;
7028 + struct au_vdir_destr destr;
7031 + AuDebugOn(bindex >= 0);
7034 + AuDebugOn(destr.len < NAME_MAX);
7036 +#ifdef CONFIG_4KSTACKS
7037 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7042 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7043 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7044 +++ linux/fs/aufs/debug.h 2015-04-13 15:10:20.780156788 +0200
7047 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7049 + * This program, aufs is free software; you can redistribute it and/or modify
7050 + * it under the terms of the GNU General Public License as published by
7051 + * the Free Software Foundation; either version 2 of the License, or
7052 + * (at your option) any later version.
7054 + * This program is distributed in the hope that it will be useful,
7055 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7056 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7057 + * GNU General Public License for more details.
7059 + * You should have received a copy of the GNU General Public License
7060 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7064 + * debug print functions
7067 +#ifndef __AUFS_DEBUG_H__
7068 +#define __AUFS_DEBUG_H__
7072 +#include <linux/atomic.h>
7073 +#include <linux/module.h>
7074 +#include <linux/kallsyms.h>
7075 +#include <linux/sysrq.h>
7077 +#ifdef CONFIG_AUFS_DEBUG
7078 +#define AuDebugOn(a) BUG_ON(a)
7080 +/* module parameter */
7081 +extern atomic_t aufs_debug;
7082 +static inline void au_debug_on(void)
7084 + atomic_inc(&aufs_debug);
7086 +static inline void au_debug_off(void)
7088 + atomic_dec_if_positive(&aufs_debug);
7091 +static inline int au_debug_test(void)
7093 + return atomic_read(&aufs_debug) > 0;
7096 +#define AuDebugOn(a) do {} while (0)
7097 +AuStubVoid(au_debug_on, void)
7098 +AuStubVoid(au_debug_off, void)
7099 +AuStubInt0(au_debug_test, void)
7100 +#endif /* CONFIG_AUFS_DEBUG */
7102 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7104 +/* ---------------------------------------------------------------------- */
7108 +#define AuDbg(fmt, ...) do { \
7109 + if (au_debug_test()) \
7110 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7112 +#define AuLabel(l) AuDbg(#l "\n")
7113 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7114 +#define AuWarn1(fmt, ...) do { \
7115 + static unsigned char _c; \
7117 + pr_warn(fmt, ##__VA_ARGS__); \
7120 +#define AuErr1(fmt, ...) do { \
7121 + static unsigned char _c; \
7123 + pr_err(fmt, ##__VA_ARGS__); \
7126 +#define AuIOErr1(fmt, ...) do { \
7127 + static unsigned char _c; \
7129 + AuIOErr(fmt, ##__VA_ARGS__); \
7132 +#define AuUnsupportMsg "This operation is not supported." \
7133 + " Please report this application to aufs-users ML."
7134 +#define AuUnsupport(fmt, ...) do { \
7135 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7139 +#define AuTraceErr(e) do { \
7140 + if (unlikely((e) < 0)) \
7141 + AuDbg("err %d\n", (int)(e)); \
7144 +#define AuTraceErrPtr(p) do { \
7146 + AuDbg("err %ld\n", PTR_ERR(p)); \
7149 +/* dirty macros for debug print, use with "%.*s" and caution */
7150 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7152 +/* ---------------------------------------------------------------------- */
7155 +#ifdef CONFIG_AUFS_DEBUG
7156 +extern struct mutex au_dbg_mtx;
7157 +extern char *au_plevel;
7159 +void au_dpri_whlist(struct au_nhash *whlist);
7161 +void au_dpri_vdir(struct au_vdir *vdir);
7163 +void au_dpri_inode(struct inode *inode);
7164 +void au_dpri_dalias(struct inode *inode);
7165 +void au_dpri_dentry(struct dentry *dentry);
7167 +void au_dpri_file(struct file *filp);
7168 +struct super_block;
7169 +void au_dpri_sb(struct super_block *sb);
7171 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7172 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7173 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7174 +void au_dbg_verify_kthread(void);
7176 +int __init au_debug_init(void);
7178 +#define AuDbgWhlist(w) do { \
7179 + mutex_lock(&au_dbg_mtx); \
7181 + au_dpri_whlist(w); \
7182 + mutex_unlock(&au_dbg_mtx); \
7185 +#define AuDbgVdir(v) do { \
7186 + mutex_lock(&au_dbg_mtx); \
7188 + au_dpri_vdir(v); \
7189 + mutex_unlock(&au_dbg_mtx); \
7192 +#define AuDbgInode(i) do { \
7193 + mutex_lock(&au_dbg_mtx); \
7195 + au_dpri_inode(i); \
7196 + mutex_unlock(&au_dbg_mtx); \
7199 +#define AuDbgDAlias(i) do { \
7200 + mutex_lock(&au_dbg_mtx); \
7202 + au_dpri_dalias(i); \
7203 + mutex_unlock(&au_dbg_mtx); \
7206 +#define AuDbgDentry(d) do { \
7207 + mutex_lock(&au_dbg_mtx); \
7209 + au_dpri_dentry(d); \
7210 + mutex_unlock(&au_dbg_mtx); \
7213 +#define AuDbgFile(f) do { \
7214 + mutex_lock(&au_dbg_mtx); \
7216 + au_dpri_file(f); \
7217 + mutex_unlock(&au_dbg_mtx); \
7220 +#define AuDbgSb(sb) do { \
7221 + mutex_lock(&au_dbg_mtx); \
7222 + AuDbg(#sb "\n"); \
7224 + mutex_unlock(&au_dbg_mtx); \
7227 +#define AuDbgSym(addr) do { \
7228 + char sym[KSYM_SYMBOL_LEN]; \
7229 + sprint_symbol(sym, (unsigned long)addr); \
7230 + AuDbg("%s\n", sym); \
7233 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7234 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
7235 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
7236 + unsigned int sigen)
7237 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7238 +AuStubVoid(au_dbg_verify_kthread, void)
7239 +AuStubInt0(__init au_debug_init, void)
7241 +#define AuDbgWhlist(w) do {} while (0)
7242 +#define AuDbgVdir(v) do {} while (0)
7243 +#define AuDbgInode(i) do {} while (0)
7244 +#define AuDbgDAlias(i) do {} while (0)
7245 +#define AuDbgDentry(d) do {} while (0)
7246 +#define AuDbgFile(f) do {} while (0)
7247 +#define AuDbgSb(sb) do {} while (0)
7248 +#define AuDbgSym(addr) do {} while (0)
7249 +#endif /* CONFIG_AUFS_DEBUG */
7251 +/* ---------------------------------------------------------------------- */
7253 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7254 +int __init au_sysrq_init(void);
7255 +void au_sysrq_fin(void);
7257 +#ifdef CONFIG_HW_CONSOLE
7258 +#define au_dbg_blocked() do { \
7260 + handle_sysrq('w'); \
7263 +AuStubVoid(au_dbg_blocked, void)
7267 +AuStubInt0(__init au_sysrq_init, void)
7268 +AuStubVoid(au_sysrq_fin, void)
7269 +AuStubVoid(au_dbg_blocked, void)
7270 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7272 +#endif /* __KERNEL__ */
7273 +#endif /* __AUFS_DEBUG_H__ */
7274 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7275 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7276 +++ linux/fs/aufs/dentry.c 2015-04-13 15:10:20.780156788 +0200
7279 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7281 + * This program, aufs is free software; you can redistribute it and/or modify
7282 + * it under the terms of the GNU General Public License as published by
7283 + * the Free Software Foundation; either version 2 of the License, or
7284 + * (at your option) any later version.
7286 + * This program is distributed in the hope that it will be useful,
7287 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7288 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7289 + * GNU General Public License for more details.
7291 + * You should have received a copy of the GNU General Public License
7292 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7296 + * lookup and dentry operations
7299 +#include <linux/namei.h>
7302 +#define AuLkup_ALLOW_NEG 1
7303 +#define AuLkup_IGNORE_PERM (1 << 1)
7304 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7305 +#define au_fset_lkup(flags, name) \
7306 + do { (flags) |= AuLkup_##name; } while (0)
7307 +#define au_fclr_lkup(flags, name) \
7308 + do { (flags) &= ~AuLkup_##name; } while (0)
7310 +struct au_do_lookup_args {
7311 + unsigned int flags;
7316 + * returns positive/negative dentry, NULL or an error.
7317 + * NULL means whiteout-ed or not-found.
7319 +static struct dentry*
7320 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7321 + aufs_bindex_t bindex, struct qstr *wh_name,
7322 + struct au_do_lookup_args *args)
7324 + struct dentry *h_dentry;
7325 + struct inode *h_inode;
7326 + struct au_branch *br;
7327 + int wh_found, opq;
7328 + unsigned char wh_able;
7329 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7330 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7334 + br = au_sbr(dentry->d_sb, bindex);
7335 + wh_able = !!au_br_whable(br->br_perm);
7337 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7338 + h_dentry = ERR_PTR(wh_found);
7341 + if (unlikely(wh_found < 0))
7344 + /* We found a whiteout */
7345 + /* au_set_dbend(dentry, bindex); */
7346 + au_set_dbwh(dentry, bindex);
7348 + return NULL; /* success */
7352 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7354 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7355 + if (IS_ERR(h_dentry)) {
7356 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7362 + h_inode = h_dentry->d_inode;
7366 + } else if (wh_found
7367 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7370 + if (au_dbend(dentry) <= bindex)
7371 + au_set_dbend(dentry, bindex);
7372 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7373 + au_set_dbstart(dentry, bindex);
7374 + au_set_h_dptr(dentry, bindex, h_dentry);
7376 + if (!d_is_dir(h_dentry)
7378 + || (d_is_positive(dentry) && !d_is_dir(dentry)))
7379 + goto out; /* success */
7381 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7382 + opq = au_diropq_test(h_dentry);
7383 + mutex_unlock(&h_inode->i_mutex);
7385 + au_set_dbdiropq(dentry, bindex);
7386 + else if (unlikely(opq < 0)) {
7387 + au_set_h_dptr(dentry, bindex, NULL);
7388 + h_dentry = ERR_PTR(opq);
7399 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7401 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7402 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7408 + * returns the number of lower positive dentries,
7409 + * otherwise an error.
7410 + * can be called at unlinking with @type is zero.
7412 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7414 + int npositive, err;
7415 + aufs_bindex_t bindex, btail, bdiropq;
7416 + unsigned char isdir, dirperm1;
7417 + struct qstr whname;
7418 + struct au_do_lookup_args args = {
7422 + const struct qstr *name = &dentry->d_name;
7423 + struct dentry *parent;
7424 + struct inode *inode;
7425 + struct super_block *sb;
7427 + sb = dentry->d_sb;
7428 + err = au_test_shwh(sb, name);
7429 + if (unlikely(err))
7432 + err = au_wh_name_alloc(&whname, name);
7433 + if (unlikely(err))
7436 + inode = dentry->d_inode;
7437 + isdir = !!d_is_dir(dentry);
7439 + au_fset_lkup(args.flags, ALLOW_NEG);
7440 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7443 + parent = dget_parent(dentry);
7444 + btail = au_dbtaildir(parent);
7445 + for (bindex = bstart; bindex <= btail; bindex++) {
7446 + struct dentry *h_parent, *h_dentry;
7447 + struct inode *h_inode, *h_dir;
7449 + h_dentry = au_h_dptr(dentry, bindex);
7451 + if (h_dentry->d_inode)
7453 + if (type != S_IFDIR)
7457 + h_parent = au_h_dptr(parent, bindex);
7458 + if (!h_parent || !d_is_dir(h_parent))
7461 + h_dir = h_parent->d_inode;
7462 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7463 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7465 + mutex_unlock(&h_dir->i_mutex);
7466 + err = PTR_ERR(h_dentry);
7467 + if (IS_ERR(h_dentry))
7470 + au_fclr_lkup(args.flags, ALLOW_NEG);
7472 + au_fset_lkup(args.flags, IGNORE_PERM);
7474 + if (au_dbwh(dentry) >= 0)
7478 + h_inode = h_dentry->d_inode;
7483 + args.type = h_inode->i_mode & S_IFMT;
7484 + if (args.type != S_IFDIR)
7487 + /* the type of lower may be different */
7488 + bdiropq = au_dbdiropq(dentry);
7489 + if (bdiropq >= 0 && bdiropq <= bindex)
7495 + AuLabel(positive);
7496 + au_update_dbstart(dentry);
7499 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7500 + && au_dbstart(dentry) < 0)) {
7502 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7508 + kfree(whname.name);
7513 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7515 + struct dentry *dentry;
7518 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7519 + dentry = vfsub_lkup_one(name, parent);
7521 + struct vfsub_lkup_one_args args = {
7527 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7528 + if (unlikely(wkq_err))
7529 + dentry = ERR_PTR(wkq_err);
7536 + * lookup @dentry on @bindex which should be negative.
7538 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7541 + struct dentry *parent, *h_parent, *h_dentry;
7542 + struct au_branch *br;
7544 + parent = dget_parent(dentry);
7545 + h_parent = au_h_dptr(parent, bindex);
7546 + br = au_sbr(dentry->d_sb, bindex);
7548 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7550 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7551 + err = PTR_ERR(h_dentry);
7552 + if (IS_ERR(h_dentry))
7554 + if (unlikely(h_dentry->d_inode)) {
7556 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7562 + if (bindex < au_dbstart(dentry))
7563 + au_set_dbstart(dentry, bindex);
7564 + if (au_dbend(dentry) < bindex)
7565 + au_set_dbend(dentry, bindex);
7566 + au_set_h_dptr(dentry, bindex, h_dentry);
7573 +/* ---------------------------------------------------------------------- */
7575 +/* subset of struct inode */
7577 + unsigned long i_ino;
7578 + /* unsigned int i_nlink; */
7584 + blkcnt_t i_blocks;
7589 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7591 + ia->i_ino = h_inode->i_ino;
7592 + /* ia->i_nlink = h_inode->i_nlink; */
7593 + ia->i_uid = h_inode->i_uid;
7594 + ia->i_gid = h_inode->i_gid;
7595 + ia->i_version = h_inode->i_version;
7597 + ia->i_size = h_inode->i_size;
7598 + ia->i_blocks = h_inode->i_blocks;
7600 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7603 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7605 + return ia->i_ino != h_inode->i_ino
7606 + /* || ia->i_nlink != h_inode->i_nlink */
7607 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7608 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7609 + || ia->i_version != h_inode->i_version
7611 + || ia->i_size != h_inode->i_size
7612 + || ia->i_blocks != h_inode->i_blocks
7614 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7617 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7618 + struct au_branch *br)
7621 + struct au_iattr ia;
7622 + struct inode *h_inode;
7623 + struct dentry *h_d;
7624 + struct super_block *h_sb;
7627 + memset(&ia, -1, sizeof(ia));
7628 + h_sb = h_dentry->d_sb;
7629 + h_inode = h_dentry->d_inode;
7631 + au_iattr_save(&ia, h_inode);
7632 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7633 + /* nfs d_revalidate may return 0 for negative dentry */
7634 + /* fuse d_revalidate always return 0 for negative dentry */
7637 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7638 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7639 + err = PTR_ERR(h_d);
7644 + if (unlikely(h_d != h_dentry
7645 + || h_d->d_inode != h_inode
7646 + || (h_inode && au_iattr_test(&ia, h_inode))))
7647 + err = au_busy_or_stale();
7655 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7656 + struct dentry *h_parent, struct au_branch *br)
7661 + if (udba == AuOpt_UDBA_REVAL
7662 + && !au_test_fs_remote(h_dentry->d_sb)) {
7664 + err = (h_dentry->d_parent->d_inode != h_dir);
7665 + } else if (udba != AuOpt_UDBA_NONE)
7666 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7671 +/* ---------------------------------------------------------------------- */
7673 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7676 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7677 + struct au_hdentry tmp, *p, *q;
7678 + struct au_dinfo *dinfo;
7679 + struct super_block *sb;
7681 + DiMustWriteLock(dentry);
7683 + sb = dentry->d_sb;
7684 + dinfo = au_di(dentry);
7685 + bend = dinfo->di_bend;
7686 + bwh = dinfo->di_bwh;
7687 + bdiropq = dinfo->di_bdiropq;
7688 + p = dinfo->di_hdentry + dinfo->di_bstart;
7689 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7690 + if (!p->hd_dentry)
7693 + new_bindex = au_br_index(sb, p->hd_id);
7694 + if (new_bindex == bindex)
7697 + if (dinfo->di_bwh == bindex)
7699 + if (dinfo->di_bdiropq == bindex)
7700 + bdiropq = new_bindex;
7701 + if (new_bindex < 0) {
7703 + p->hd_dentry = NULL;
7707 + /* swap two lower dentries, and loop again */
7708 + q = dinfo->di_hdentry + new_bindex;
7712 + if (tmp.hd_dentry) {
7718 + dinfo->di_bwh = -1;
7719 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7720 + dinfo->di_bwh = bwh;
7722 + dinfo->di_bdiropq = -1;
7724 + && bdiropq <= au_sbend(sb)
7725 + && au_sbr_whable(sb, bdiropq))
7726 + dinfo->di_bdiropq = bdiropq;
7729 + dinfo->di_bstart = -1;
7730 + dinfo->di_bend = -1;
7731 + bend = au_dbend(parent);
7732 + p = dinfo->di_hdentry;
7733 + for (bindex = 0; bindex <= bend; bindex++, p++)
7734 + if (p->hd_dentry) {
7735 + dinfo->di_bstart = bindex;
7739 + if (dinfo->di_bstart >= 0) {
7740 + p = dinfo->di_hdentry + bend;
7741 + for (bindex = bend; bindex >= 0; bindex--, p--)
7742 + if (p->hd_dentry) {
7743 + dinfo->di_bend = bindex;
7752 +static void au_do_hide(struct dentry *dentry)
7754 + struct inode *inode;
7756 + inode = dentry->d_inode;
7758 + if (!S_ISDIR(inode->i_mode)) {
7759 + if (inode->i_nlink && !d_unhashed(dentry))
7760 + drop_nlink(inode);
7762 + clear_nlink(inode);
7763 + /* stop next lookup */
7764 + inode->i_flags |= S_DEAD;
7766 + smp_mb(); /* necessary? */
7771 +static int au_hide_children(struct dentry *parent)
7773 + int err, i, j, ndentry;
7774 + struct au_dcsub_pages dpages;
7775 + struct au_dpage *dpage;
7776 + struct dentry *dentry;
7778 + err = au_dpages_init(&dpages, GFP_NOFS);
7779 + if (unlikely(err))
7781 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7782 + if (unlikely(err))
7785 + /* in reverse order */
7786 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7787 + dpage = dpages.dpages + i;
7788 + ndentry = dpage->ndentry;
7789 + for (j = ndentry - 1; j >= 0; j--) {
7790 + dentry = dpage->dentries[j];
7791 + if (dentry != parent)
7792 + au_do_hide(dentry);
7797 + au_dpages_free(&dpages);
7802 +static void au_hide(struct dentry *dentry)
7806 + AuDbgDentry(dentry);
7807 + if (d_is_dir(dentry)) {
7808 + /* shrink_dcache_parent(dentry); */
7809 + err = au_hide_children(dentry);
7810 + if (unlikely(err))
7811 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7814 + au_do_hide(dentry);
7818 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7820 + * a dirty branch is added
7821 + * - on the top of layers
7822 + * - in the middle of layers
7823 + * - to the bottom of layers
7825 + * on the added branch there exists
7828 + * - a same named entry
7830 + * * negative --> positive
7831 + * * positive --> positive
7832 + * - type is unchanged
7833 + * - type is changed
7835 + * * negative --> negative
7836 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7839 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7840 + struct au_dinfo *tmp)
7843 + aufs_bindex_t bindex, bend;
7845 + struct dentry *dentry;
7846 + struct inode *inode;
7849 + struct au_hdentry *hd;
7850 + struct inode *inode, *h_inode;
7851 + struct dentry *h_dentry;
7854 + AuDebugOn(dinfo->di_bstart < 0);
7855 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
7856 + orig_h.inode = orig_h.dentry->d_inode;
7859 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
7860 + memset(&tmp_h, 0, sizeof(tmp_h));
7861 + if (tmp->di_bstart >= 0) {
7862 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
7863 + tmp_h.inode = tmp_h.dentry->d_inode;
7865 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
7868 + inode = dentry->d_inode;
7869 + if (!orig_h.inode) {
7870 + AuDbg("nagative originally\n");
7876 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7877 + AuDebugOn(dinfo->di_bdiropq != -1);
7879 + if (!tmp_h.inode) {
7880 + AuDbg("negative --> negative\n");
7881 + /* should have only one negative lower */
7882 + if (tmp->di_bstart >= 0
7883 + && tmp->di_bstart < dinfo->di_bstart) {
7884 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7885 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7886 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7887 + au_di_cp(dinfo, tmp);
7888 + hd = tmp->di_hdentry + tmp->di_bstart;
7889 + au_set_h_dptr(dentry, tmp->di_bstart,
7890 + dget(hd->hd_dentry));
7892 + au_dbg_verify_dinode(dentry);
7894 + AuDbg("negative --> positive\n");
7896 + * similar to the behaviour of creating with bypassing
7898 + * unhash it in order to force an error in the
7899 + * succeeding create operation.
7900 + * we should not set S_DEAD here.
7903 + /* au_di_swap(tmp, dinfo); */
7904 + au_dbg_verify_dinode(dentry);
7907 + AuDbg("positive originally\n");
7908 + /* inode may be NULL */
7909 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7910 + if (!tmp_h.inode) {
7911 + AuDbg("positive --> negative\n");
7912 + /* or bypassing aufs */
7914 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7915 + dinfo->di_bwh = tmp->di_bwh;
7917 + err = au_refresh_hinode_self(inode);
7918 + au_dbg_verify_dinode(dentry);
7919 + } else if (orig_h.mode == tmp_h.mode) {
7920 + AuDbg("positive --> positive, same type\n");
7921 + if (!S_ISDIR(orig_h.mode)
7922 + && dinfo->di_bstart > tmp->di_bstart) {
7924 + * similar to the behaviour of removing and
7929 + err = au_refresh_hinode_self(inode);
7930 + au_dbg_verify_dinode(dentry);
7932 + /* fill empty slots */
7933 + if (dinfo->di_bstart > tmp->di_bstart)
7934 + dinfo->di_bstart = tmp->di_bstart;
7935 + if (dinfo->di_bend < tmp->di_bend)
7936 + dinfo->di_bend = tmp->di_bend;
7937 + dinfo->di_bwh = tmp->di_bwh;
7938 + dinfo->di_bdiropq = tmp->di_bdiropq;
7939 + hd = tmp->di_hdentry;
7940 + bend = dinfo->di_bend;
7941 + for (bindex = tmp->di_bstart; bindex <= bend;
7943 + if (au_h_dptr(dentry, bindex))
7945 + h_dentry = hd[bindex].hd_dentry;
7948 + h_inode = h_dentry->d_inode;
7949 + AuDebugOn(!h_inode);
7950 + AuDebugOn(orig_h.mode
7951 + != (h_inode->i_mode
7953 + au_set_h_dptr(dentry, bindex,
7956 + err = au_refresh_hinode(inode, dentry);
7957 + au_dbg_verify_dinode(dentry);
7960 + AuDbg("positive --> positive, different type\n");
7961 + /* similar to the behaviour of removing and creating */
7964 + err = au_refresh_hinode_self(inode);
7965 + au_dbg_verify_dinode(dentry);
7973 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7976 + unsigned int sigen;
7977 + struct au_dinfo *dinfo, *tmp;
7978 + struct super_block *sb;
7979 + struct inode *inode;
7981 + DiMustWriteLock(dentry);
7982 + AuDebugOn(IS_ROOT(dentry));
7983 + AuDebugOn(!parent->d_inode);
7985 + sb = dentry->d_sb;
7986 + inode = dentry->d_inode;
7987 + sigen = au_sigen(sb);
7988 + err = au_digen_test(parent, sigen);
7989 + if (unlikely(err))
7992 + dinfo = au_di(dentry);
7993 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7994 + if (unlikely(err))
7996 + ebrange = au_dbrange_test(dentry);
7998 + ebrange = au_do_refresh_hdentry(dentry, parent);
8000 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8001 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8003 + err = au_refresh_hinode_self(inode);
8004 + au_dbg_verify_dinode(dentry);
8006 + goto out_dgen; /* success */
8010 + /* temporary dinfo */
8011 + AuDbgDentry(dentry);
8013 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8014 + if (unlikely(!tmp))
8016 + au_di_swap(tmp, dinfo);
8017 + /* returns the number of positive dentries */
8019 + * if current working dir is removed, it returns an error.
8020 + * but the dentry is legal.
8022 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8023 + AuDbgDentry(dentry);
8024 + au_di_swap(tmp, dinfo);
8025 + if (err == -ENOENT)
8028 + /* compare/refresh by dinfo */
8029 + AuDbgDentry(dentry);
8030 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8031 + au_dbg_verify_dinode(dentry);
8034 + au_rw_write_unlock(&tmp->di_rwsem);
8036 + if (unlikely(err))
8040 + au_update_digen(dentry);
8042 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8043 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8044 + AuDbgDentry(dentry);
8050 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8051 + struct dentry *dentry, aufs_bindex_t bindex)
8056 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8059 + AuDbg("b%d\n", bindex);
8061 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8062 + * due to whiteout and branch permission.
8064 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8065 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8066 + /* it may return tri-state */
8067 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8069 + if (unlikely(valid < 0))
8079 +/* todo: remove this */
8080 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8081 + unsigned int flags, int do_udba)
8084 + umode_t mode, h_mode;
8085 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8086 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8087 + struct inode *h_inode, *h_cached_inode;
8088 + struct dentry *h_dentry;
8089 + struct qstr *name, *h_name;
8096 + unhashed = !!d_unhashed(dentry);
8097 + is_root = !!IS_ROOT(dentry);
8098 + name = &dentry->d_name;
8099 + tmpfile = au_di(dentry)->di_tmpfile;
8102 + * Theoretically, REVAL test should be unnecessary in case of
8104 + * But {fs,i}notify doesn't fire some necessary events,
8105 + * IN_ATTRIB for atime/nlink/pageio
8106 + * Let's do REVAL test too.
8108 + if (do_udba && inode) {
8109 + mode = (inode->i_mode & S_IFMT);
8110 + plus = (inode->i_nlink > 0);
8111 + ibs = au_ibstart(inode);
8112 + ibe = au_ibend(inode);
8115 + bstart = au_dbstart(dentry);
8117 + if (inode && S_ISDIR(inode->i_mode))
8118 + btail = au_dbtaildir(dentry);
8119 + for (bindex = bstart; bindex <= btail; bindex++) {
8120 + h_dentry = au_h_dptr(dentry, bindex);
8124 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8125 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8126 + spin_lock(&h_dentry->d_lock);
8127 + h_name = &h_dentry->d_name;
8128 + if (unlikely(do_udba
8131 + && (unhashed != !!d_unhashed(h_dentry)
8133 + && !au_qstreq(name, h_name))
8136 + && !(flags & LOOKUP_OPEN)
8137 + && (h_dentry->d_flags
8138 + & DCACHE_NFSFS_RENAMED)))
8142 + h_unhashed = d_unhashed(h_dentry);
8143 + spin_unlock(&h_dentry->d_lock);
8144 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8145 + unhashed, h_unhashed, dentry, h_dentry);
8148 + spin_unlock(&h_dentry->d_lock);
8150 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8151 + if (unlikely(err))
8152 + /* do not goto err, to keep the errno */
8155 + /* todo: plink too? */
8160 + h_inode = h_dentry->d_inode;
8161 + if (unlikely(!!inode != !!h_inode))
8166 + h_cached_inode = h_inode;
8168 + h_mode = (h_inode->i_mode & S_IFMT);
8169 + h_plus = (h_inode->i_nlink > 0);
8171 + if (inode && ibs <= bindex && bindex <= ibe)
8172 + h_cached_inode = au_h_iptr(inode, bindex);
8175 + if (unlikely(plus != h_plus && !tmpfile))
8178 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8180 + && !IS_ROOT(h_dentry)
8181 + && unhashed != d_unhashed(h_dentry)))
8184 + if (unlikely(mode != h_mode
8185 + || h_cached_inode != h_inode))
8198 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8199 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8202 + struct dentry *parent;
8204 + if (!au_digen_test(dentry, sigen))
8207 + parent = dget_parent(dentry);
8208 + di_read_lock_parent(parent, AuLock_IR);
8209 + AuDebugOn(au_digen_test(parent, sigen));
8210 + au_dbg_verify_gen(parent, sigen);
8211 + err = au_refresh_dentry(dentry, parent);
8212 + di_read_unlock(parent, AuLock_IR);
8218 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8221 + struct dentry *d, *parent;
8222 + struct inode *inode;
8224 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8225 + return simple_reval_dpath(dentry, sigen);
8227 + /* slow loop, keep it simple and stupid */
8228 + /* cf: au_cpup_dirs() */
8231 + while (au_digen_test(dentry, sigen)) {
8235 + parent = dget_parent(d);
8236 + if (!au_digen_test(parent, sigen))
8241 + inode = d->d_inode;
8243 + di_write_lock_child2(d);
8245 + /* someone might update our dentry while we were sleeping */
8246 + if (au_digen_test(d, sigen)) {
8248 + * todo: consolidate with simple_reval_dpath(),
8249 + * do_refresh() and au_reval_for_attr().
8251 + di_read_lock_parent(parent, AuLock_IR);
8252 + err = au_refresh_dentry(d, parent);
8253 + di_read_unlock(parent, AuLock_IR);
8257 + di_write_unlock(d);
8259 + if (unlikely(err))
8267 + * if valid returns 1, otherwise 0.
8269 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8272 + unsigned int sigen;
8273 + unsigned char do_udba;
8274 + struct super_block *sb;
8275 + struct inode *inode;
8277 + /* todo: support rcu-walk? */
8278 + if (flags & LOOKUP_RCU)
8282 + if (unlikely(!au_di(dentry)))
8286 + sb = dentry->d_sb;
8289 + * i_mutex of parent dir may be held,
8290 + * but we should not return 'invalid' due to busy.
8292 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8293 + if (unlikely(err)) {
8298 + inode = dentry->d_inode;
8299 + if (unlikely(inode && is_bad_inode(inode))) {
8304 + if (unlikely(au_dbrange_test(dentry))) {
8310 + sigen = au_sigen(sb);
8311 + if (au_digen_test(dentry, sigen)) {
8312 + AuDebugOn(IS_ROOT(dentry));
8313 + err = au_reval_dpath(dentry, sigen);
8314 + if (unlikely(err)) {
8319 + di_downgrade_lock(dentry, AuLock_IR);
8322 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8324 + && !(inode->i_state && I_LINKABLE)
8325 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8328 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8329 + if (do_udba && inode) {
8330 + aufs_bindex_t bstart = au_ibstart(inode);
8331 + struct inode *h_inode;
8333 + if (bstart >= 0) {
8334 + h_inode = au_h_iptr(inode, bstart);
8335 + if (h_inode && au_test_higen(inode, h_inode))
8340 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8341 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8343 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8349 + di_downgrade_lock(dentry, AuLock_IR);
8351 + aufs_read_unlock(dentry, AuLock_IR);
8356 + AuDbg("%pd invalid, %d\n", dentry, valid);
8362 +static void aufs_d_release(struct dentry *dentry)
8364 + if (au_di(dentry)) {
8365 + au_di_fin(dentry);
8366 + au_hn_di_reinit(dentry);
8370 +const struct dentry_operations aufs_dop = {
8371 + .d_revalidate = aufs_d_revalidate,
8372 + .d_weak_revalidate = aufs_d_revalidate,
8373 + .d_release = aufs_d_release
8375 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8376 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8377 +++ linux/fs/aufs/dentry.h 2015-04-13 15:10:20.780156788 +0200
8380 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8382 + * This program, aufs is free software; you can redistribute it and/or modify
8383 + * it under the terms of the GNU General Public License as published by
8384 + * the Free Software Foundation; either version 2 of the License, or
8385 + * (at your option) any later version.
8387 + * This program is distributed in the hope that it will be useful,
8388 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8389 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8390 + * GNU General Public License for more details.
8392 + * You should have received a copy of the GNU General Public License
8393 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8397 + * lookup and dentry operations
8400 +#ifndef __AUFS_DENTRY_H__
8401 +#define __AUFS_DENTRY_H__
8405 +#include <linux/dcache.h>
8408 +struct au_hdentry {
8409 + struct dentry *hd_dentry;
8410 + aufs_bindex_t hd_id;
8414 + atomic_t di_generation;
8416 + struct au_rwsem di_rwsem;
8417 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8418 + unsigned char di_tmpfile; /* to allow the different name */
8419 + struct au_hdentry *di_hdentry;
8420 +} ____cacheline_aligned_in_smp;
8422 +/* ---------------------------------------------------------------------- */
8425 +extern const struct dentry_operations aufs_dop;
8427 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8428 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8429 + struct dentry *h_parent, struct au_branch *br);
8431 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8432 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8433 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8434 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8437 +void au_di_init_once(void *_di);
8438 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8439 +void au_di_free(struct au_dinfo *dinfo);
8440 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8441 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8442 +int au_di_init(struct dentry *dentry);
8443 +void au_di_fin(struct dentry *dentry);
8444 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8446 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8447 +void di_read_unlock(struct dentry *d, int flags);
8448 +void di_downgrade_lock(struct dentry *d, int flags);
8449 +void di_write_lock(struct dentry *d, unsigned int lsc);
8450 +void di_write_unlock(struct dentry *d);
8451 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8452 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8453 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8455 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8456 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8457 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8458 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8460 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8461 + struct dentry *h_dentry);
8462 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8463 +int au_dbrange_test(struct dentry *dentry);
8464 +void au_update_digen(struct dentry *dentry);
8465 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8466 +void au_update_dbstart(struct dentry *dentry);
8467 +void au_update_dbend(struct dentry *dentry);
8468 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8470 +/* ---------------------------------------------------------------------- */
8472 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8474 + return dentry->d_fsdata;
8477 +/* ---------------------------------------------------------------------- */
8479 +/* lock subclass for dinfo */
8481 + AuLsc_DI_CHILD, /* child first */
8482 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8483 + AuLsc_DI_CHILD3, /* copyup dirs */
8487 + AuLsc_DI_TMP /* temp for replacing dinfo */
8491 + * di_read_lock_child, di_write_lock_child,
8492 + * di_read_lock_child2, di_write_lock_child2,
8493 + * di_read_lock_child3, di_write_lock_child3,
8494 + * di_read_lock_parent, di_write_lock_parent,
8495 + * di_read_lock_parent2, di_write_lock_parent2,
8496 + * di_read_lock_parent3, di_write_lock_parent3,
8498 +#define AuReadLockFunc(name, lsc) \
8499 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8500 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8502 +#define AuWriteLockFunc(name, lsc) \
8503 +static inline void di_write_lock_##name(struct dentry *d) \
8504 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8506 +#define AuRWLockFuncs(name, lsc) \
8507 + AuReadLockFunc(name, lsc) \
8508 + AuWriteLockFunc(name, lsc)
8510 +AuRWLockFuncs(child, CHILD);
8511 +AuRWLockFuncs(child2, CHILD2);
8512 +AuRWLockFuncs(child3, CHILD3);
8513 +AuRWLockFuncs(parent, PARENT);
8514 +AuRWLockFuncs(parent2, PARENT2);
8515 +AuRWLockFuncs(parent3, PARENT3);
8517 +#undef AuReadLockFunc
8518 +#undef AuWriteLockFunc
8519 +#undef AuRWLockFuncs
8521 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8522 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8523 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8525 +/* ---------------------------------------------------------------------- */
8527 +/* todo: memory barrier? */
8528 +static inline unsigned int au_digen(struct dentry *d)
8530 + return atomic_read(&au_di(d)->di_generation);
8533 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8535 + hdentry->hd_dentry = NULL;
8538 +static inline void au_hdput(struct au_hdentry *hd)
8541 + dput(hd->hd_dentry);
8544 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8546 + DiMustAnyLock(dentry);
8547 + return au_di(dentry)->di_bstart;
8550 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8552 + DiMustAnyLock(dentry);
8553 + return au_di(dentry)->di_bend;
8556 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8558 + DiMustAnyLock(dentry);
8559 + return au_di(dentry)->di_bwh;
8562 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8564 + DiMustAnyLock(dentry);
8565 + return au_di(dentry)->di_bdiropq;
8568 +/* todo: hard/soft set? */
8569 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8571 + DiMustWriteLock(dentry);
8572 + au_di(dentry)->di_bstart = bindex;
8575 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8577 + DiMustWriteLock(dentry);
8578 + au_di(dentry)->di_bend = bindex;
8581 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8583 + DiMustWriteLock(dentry);
8584 + /* dbwh can be outside of bstart - bend range */
8585 + au_di(dentry)->di_bwh = bindex;
8588 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8590 + DiMustWriteLock(dentry);
8591 + au_di(dentry)->di_bdiropq = bindex;
8594 +/* ---------------------------------------------------------------------- */
8596 +#ifdef CONFIG_AUFS_HNOTIFY
8597 +static inline void au_digen_dec(struct dentry *d)
8599 + atomic_dec(&au_di(d)->di_generation);
8602 +static inline void au_hn_di_reinit(struct dentry *dentry)
8604 + dentry->d_fsdata = NULL;
8607 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8608 +#endif /* CONFIG_AUFS_HNOTIFY */
8610 +#endif /* __KERNEL__ */
8611 +#endif /* __AUFS_DENTRY_H__ */
8612 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8613 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8614 +++ linux/fs/aufs/dinfo.c 2015-04-13 15:10:20.783490201 +0200
8617 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8619 + * This program, aufs is free software; you can redistribute it and/or modify
8620 + * it under the terms of the GNU General Public License as published by
8621 + * the Free Software Foundation; either version 2 of the License, or
8622 + * (at your option) any later version.
8624 + * This program is distributed in the hope that it will be useful,
8625 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8626 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8627 + * GNU General Public License for more details.
8629 + * You should have received a copy of the GNU General Public License
8630 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8634 + * dentry private data
8639 +void au_di_init_once(void *_dinfo)
8641 + struct au_dinfo *dinfo = _dinfo;
8642 + static struct lock_class_key aufs_di;
8644 + au_rw_init(&dinfo->di_rwsem);
8645 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8648 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8650 + struct au_dinfo *dinfo;
8653 + dinfo = au_cache_alloc_dinfo();
8654 + if (unlikely(!dinfo))
8657 + nbr = au_sbend(sb) + 1;
8660 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8661 + if (dinfo->di_hdentry) {
8662 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8663 + dinfo->di_bstart = -1;
8664 + dinfo->di_bend = -1;
8665 + dinfo->di_bwh = -1;
8666 + dinfo->di_bdiropq = -1;
8667 + dinfo->di_tmpfile = 0;
8668 + for (i = 0; i < nbr; i++)
8669 + dinfo->di_hdentry[i].hd_id = -1;
8673 + au_cache_free_dinfo(dinfo);
8680 +void au_di_free(struct au_dinfo *dinfo)
8682 + struct au_hdentry *p;
8683 + aufs_bindex_t bend, bindex;
8685 + /* dentry may not be revalidated */
8686 + bindex = dinfo->di_bstart;
8687 + if (bindex >= 0) {
8688 + bend = dinfo->di_bend;
8689 + p = dinfo->di_hdentry + bindex;
8690 + while (bindex++ <= bend)
8693 + kfree(dinfo->di_hdentry);
8694 + au_cache_free_dinfo(dinfo);
8697 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8699 + struct au_hdentry *p;
8702 + AuRwMustWriteLock(&a->di_rwsem);
8703 + AuRwMustWriteLock(&b->di_rwsem);
8705 +#define DiSwap(v, name) \
8707 + v = a->di_##name; \
8708 + a->di_##name = b->di_##name; \
8709 + b->di_##name = v; \
8712 + DiSwap(p, hdentry);
8713 + DiSwap(bi, bstart);
8716 + DiSwap(bi, bdiropq);
8722 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8724 + AuRwMustWriteLock(&dst->di_rwsem);
8725 + AuRwMustWriteLock(&src->di_rwsem);
8727 + dst->di_bstart = src->di_bstart;
8728 + dst->di_bend = src->di_bend;
8729 + dst->di_bwh = src->di_bwh;
8730 + dst->di_bdiropq = src->di_bdiropq;
8734 +int au_di_init(struct dentry *dentry)
8737 + struct super_block *sb;
8738 + struct au_dinfo *dinfo;
8741 + sb = dentry->d_sb;
8742 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8744 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8745 + /* smp_mb(); */ /* atomic_set */
8746 + dentry->d_fsdata = dinfo;
8753 +void au_di_fin(struct dentry *dentry)
8755 + struct au_dinfo *dinfo;
8757 + dinfo = au_di(dentry);
8758 + AuRwDestroy(&dinfo->di_rwsem);
8759 + au_di_free(dinfo);
8762 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8765 + struct au_hdentry *hdp;
8767 + AuRwMustWriteLock(&dinfo->di_rwsem);
8770 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8772 + sz = sizeof(*hdp);
8773 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8775 + dinfo->di_hdentry = hdp;
8782 +/* ---------------------------------------------------------------------- */
8784 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8787 + case AuLsc_DI_CHILD:
8788 + ii_write_lock_child(inode);
8790 + case AuLsc_DI_CHILD2:
8791 + ii_write_lock_child2(inode);
8793 + case AuLsc_DI_CHILD3:
8794 + ii_write_lock_child3(inode);
8796 + case AuLsc_DI_PARENT:
8797 + ii_write_lock_parent(inode);
8799 + case AuLsc_DI_PARENT2:
8800 + ii_write_lock_parent2(inode);
8802 + case AuLsc_DI_PARENT3:
8803 + ii_write_lock_parent3(inode);
8810 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8813 + case AuLsc_DI_CHILD:
8814 + ii_read_lock_child(inode);
8816 + case AuLsc_DI_CHILD2:
8817 + ii_read_lock_child2(inode);
8819 + case AuLsc_DI_CHILD3:
8820 + ii_read_lock_child3(inode);
8822 + case AuLsc_DI_PARENT:
8823 + ii_read_lock_parent(inode);
8825 + case AuLsc_DI_PARENT2:
8826 + ii_read_lock_parent2(inode);
8828 + case AuLsc_DI_PARENT3:
8829 + ii_read_lock_parent3(inode);
8836 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8838 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8840 + if (au_ftest_lock(flags, IW))
8841 + do_ii_write_lock(d->d_inode, lsc);
8842 + else if (au_ftest_lock(flags, IR))
8843 + do_ii_read_lock(d->d_inode, lsc);
8847 +void di_read_unlock(struct dentry *d, int flags)
8850 + if (au_ftest_lock(flags, IW)) {
8851 + au_dbg_verify_dinode(d);
8852 + ii_write_unlock(d->d_inode);
8853 + } else if (au_ftest_lock(flags, IR)) {
8854 + au_dbg_verify_dinode(d);
8855 + ii_read_unlock(d->d_inode);
8858 + au_rw_read_unlock(&au_di(d)->di_rwsem);
8861 +void di_downgrade_lock(struct dentry *d, int flags)
8863 + if (d->d_inode && au_ftest_lock(flags, IR))
8864 + ii_downgrade_lock(d->d_inode);
8865 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
8868 +void di_write_lock(struct dentry *d, unsigned int lsc)
8870 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
8872 + do_ii_write_lock(d->d_inode, lsc);
8875 +void di_write_unlock(struct dentry *d)
8877 + au_dbg_verify_dinode(d);
8879 + ii_write_unlock(d->d_inode);
8880 + au_rw_write_unlock(&au_di(d)->di_rwsem);
8883 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
8885 + AuDebugOn(d1 == d2
8886 + || d1->d_inode == d2->d_inode
8887 + || d1->d_sb != d2->d_sb);
8889 + if (isdir && au_test_subdir(d1, d2)) {
8890 + di_write_lock_child(d1);
8891 + di_write_lock_child2(d2);
8893 + /* there should be no races */
8894 + di_write_lock_child(d2);
8895 + di_write_lock_child2(d1);
8899 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8901 + AuDebugOn(d1 == d2
8902 + || d1->d_inode == d2->d_inode
8903 + || d1->d_sb != d2->d_sb);
8905 + if (isdir && au_test_subdir(d1, d2)) {
8906 + di_write_lock_parent(d1);
8907 + di_write_lock_parent2(d2);
8909 + /* there should be no races */
8910 + di_write_lock_parent(d2);
8911 + di_write_lock_parent2(d1);
8915 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8917 + di_write_unlock(d1);
8918 + if (d1->d_inode == d2->d_inode)
8919 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8921 + di_write_unlock(d2);
8924 +/* ---------------------------------------------------------------------- */
8926 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8930 + DiMustAnyLock(dentry);
8932 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8934 + AuDebugOn(bindex < 0);
8935 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8936 + AuDebugOn(d && au_dcount(d) <= 0);
8941 + * extended version of au_h_dptr().
8942 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
8945 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8947 + struct dentry *h_dentry;
8948 + struct inode *inode, *h_inode;
8950 + inode = dentry->d_inode;
8951 + AuDebugOn(!inode);
8954 + if (au_dbstart(dentry) <= bindex
8955 + && bindex <= au_dbend(dentry))
8956 + h_dentry = au_h_dptr(dentry, bindex);
8957 + if (h_dentry && !au_d_linkable(h_dentry)) {
8959 + goto out; /* success */
8962 + AuDebugOn(bindex < au_ibstart(inode));
8963 + AuDebugOn(au_ibend(inode) < bindex);
8964 + h_inode = au_h_iptr(inode, bindex);
8965 + h_dentry = d_find_alias(h_inode);
8967 + if (!IS_ERR(h_dentry)) {
8968 + if (!au_d_linkable(h_dentry))
8969 + goto out; /* success */
8975 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8976 + h_dentry = au_plink_lkup(inode, bindex);
8977 + AuDebugOn(!h_dentry);
8978 + if (!IS_ERR(h_dentry)) {
8979 + if (!au_d_hashed_positive(h_dentry))
8980 + goto out; /* success */
8987 + AuDbgDentry(h_dentry);
8991 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8993 + aufs_bindex_t bend, bwh;
8995 + bend = au_dbend(dentry);
8997 + bwh = au_dbwh(dentry);
9000 + if (0 < bwh && bwh < bend)
9006 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9008 + aufs_bindex_t bend, bopq;
9010 + bend = au_dbtail(dentry);
9012 + bopq = au_dbdiropq(dentry);
9013 + if (0 <= bopq && bopq < bend)
9019 +/* ---------------------------------------------------------------------- */
9021 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9022 + struct dentry *h_dentry)
9024 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9025 + struct au_branch *br;
9027 + DiMustWriteLock(dentry);
9030 + hd->hd_dentry = h_dentry;
9032 + br = au_sbr(dentry->d_sb, bindex);
9033 + hd->hd_id = br->br_id;
9037 +int au_dbrange_test(struct dentry *dentry)
9040 + aufs_bindex_t bstart, bend;
9043 + bstart = au_dbstart(dentry);
9044 + bend = au_dbend(dentry);
9046 + AuDebugOn(bend < 0 && bstart > bend);
9049 + AuDebugOn(bend >= 0);
9055 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9060 + if (unlikely(au_digen(dentry) != sigen
9061 + || au_iigen_test(dentry->d_inode, sigen)))
9067 +void au_update_digen(struct dentry *dentry)
9069 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9070 + /* smp_mb(); */ /* atomic_set */
9073 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9075 + struct au_dinfo *dinfo;
9076 + struct dentry *h_d;
9077 + struct au_hdentry *hdp;
9079 + DiMustWriteLock(dentry);
9081 + dinfo = au_di(dentry);
9082 + if (!dinfo || dinfo->di_bstart < 0)
9085 + hdp = dinfo->di_hdentry;
9086 + if (do_put_zero) {
9087 + aufs_bindex_t bindex, bend;
9089 + bend = dinfo->di_bend;
9090 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9091 + h_d = hdp[0 + bindex].hd_dentry;
9092 + if (h_d && !h_d->d_inode)
9093 + au_set_h_dptr(dentry, bindex, NULL);
9097 + dinfo->di_bstart = -1;
9098 + while (++dinfo->di_bstart <= dinfo->di_bend)
9099 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9101 + if (dinfo->di_bstart > dinfo->di_bend) {
9102 + dinfo->di_bstart = -1;
9103 + dinfo->di_bend = -1;
9108 + while (0 <= --dinfo->di_bend)
9109 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9111 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9114 +void au_update_dbstart(struct dentry *dentry)
9116 + aufs_bindex_t bindex, bend;
9117 + struct dentry *h_dentry;
9119 + bend = au_dbend(dentry);
9120 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9121 + h_dentry = au_h_dptr(dentry, bindex);
9124 + if (h_dentry->d_inode) {
9125 + au_set_dbstart(dentry, bindex);
9128 + au_set_h_dptr(dentry, bindex, NULL);
9132 +void au_update_dbend(struct dentry *dentry)
9134 + aufs_bindex_t bindex, bstart;
9135 + struct dentry *h_dentry;
9137 + bstart = au_dbstart(dentry);
9138 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9139 + h_dentry = au_h_dptr(dentry, bindex);
9142 + if (h_dentry->d_inode) {
9143 + au_set_dbend(dentry, bindex);
9146 + au_set_h_dptr(dentry, bindex, NULL);
9150 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9152 + aufs_bindex_t bindex, bend;
9154 + bend = au_dbend(dentry);
9155 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9156 + if (au_h_dptr(dentry, bindex) == h_dentry)
9160 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9161 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9162 +++ linux/fs/aufs/dir.c 2015-04-13 15:10:20.783490201 +0200
9165 + * Copyright (C) 2005-2015 Junjiro R. Okajima
9167 + * This program, aufs is free software; you can redistribute it and/or modify
9168 + * it under the terms of the GNU General Public License as published by
9169 + * the Free Software Foundation; either version 2 of the License, or
9170 + * (at your option) any later version.
9172 + * This program is distributed in the hope that it will be useful,
9173 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9174 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9175 + * GNU General Public License for more details.
9177 + * You should have received a copy of the GNU General Public License
9178 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9182 + * directory operations
9185 +#include <linux/fs_stack.h>
9188 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9190 + unsigned int nlink;
9192 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9194 + nlink = dir->i_nlink;
9195 + nlink += h_dir->i_nlink - 2;
9196 + if (h_dir->i_nlink < 2)
9198 + smp_mb(); /* for i_nlink */
9199 + /* 0 can happen in revaliding */
9200 + set_nlink(dir, nlink);
9203 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9205 + unsigned int nlink;
9207 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9209 + nlink = dir->i_nlink;
9210 + nlink -= h_dir->i_nlink - 2;
9211 + if (h_dir->i_nlink < 2)
9213 + smp_mb(); /* for i_nlink */
9214 + /* nlink == 0 means the branch-fs is broken */
9215 + set_nlink(dir, nlink);
9218 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9221 + aufs_bindex_t bindex, bend;
9222 + struct file *h_file;
9223 + struct dentry *h_dentry;
9227 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9229 + bend = au_fbend_dir(file);
9230 + for (bindex = au_fbstart(file);
9231 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9233 + h_file = au_hf_dir(file, bindex);
9234 + if (h_file && file_inode(h_file))
9235 + sz += vfsub_f_size_read(h_file);
9238 + AuDebugOn(!dentry);
9239 + AuDebugOn(!d_is_dir(dentry));
9241 + bend = au_dbtaildir(dentry);
9242 + for (bindex = au_dbstart(dentry);
9243 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9245 + h_dentry = au_h_dptr(dentry, bindex);
9246 + if (h_dentry && h_dentry->d_inode)
9247 + sz += i_size_read(h_dentry->d_inode);
9250 + if (sz < KMALLOC_MAX_SIZE)
9251 + sz = roundup_pow_of_two(sz);
9252 + if (sz > KMALLOC_MAX_SIZE)
9253 + sz = KMALLOC_MAX_SIZE;
9254 + else if (sz < NAME_MAX) {
9255 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9256 + sz = AUFS_RDBLK_DEF;
9261 +/* ---------------------------------------------------------------------- */
9263 +static int reopen_dir(struct file *file)
9266 + unsigned int flags;
9267 + aufs_bindex_t bindex, btail, bstart;
9268 + struct dentry *dentry, *h_dentry;
9269 + struct file *h_file;
9271 + /* open all lower dirs */
9272 + dentry = file->f_path.dentry;
9273 + bstart = au_dbstart(dentry);
9274 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9275 + au_set_h_fptr(file, bindex, NULL);
9276 + au_set_fbstart(file, bstart);
9278 + btail = au_dbtaildir(dentry);
9279 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9280 + au_set_h_fptr(file, bindex, NULL);
9281 + au_set_fbend_dir(file, btail);
9283 + flags = vfsub_file_flags(file);
9284 + for (bindex = bstart; bindex <= btail; bindex++) {
9285 + h_dentry = au_h_dptr(dentry, bindex);
9288 + h_file = au_hf_dir(file, bindex);
9292 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9293 + err = PTR_ERR(h_file);
9294 + if (IS_ERR(h_file))
9295 + goto out; /* close all? */
9296 + au_set_h_fptr(file, bindex, h_file);
9298 + au_update_figen(file);
9299 + /* todo: necessary? */
9300 + /* file->f_ra = h_file->f_ra; */
9307 +static int do_open_dir(struct file *file, int flags)
9310 + aufs_bindex_t bindex, btail;
9311 + struct dentry *dentry, *h_dentry;
9312 + struct file *h_file;
9314 + FiMustWriteLock(file);
9317 + dentry = file->f_path.dentry;
9318 + file->f_version = dentry->d_inode->i_version;
9319 + bindex = au_dbstart(dentry);
9320 + au_set_fbstart(file, bindex);
9321 + btail = au_dbtaildir(dentry);
9322 + au_set_fbend_dir(file, btail);
9323 + for (; !err && bindex <= btail; bindex++) {
9324 + h_dentry = au_h_dptr(dentry, bindex);
9328 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9329 + if (IS_ERR(h_file)) {
9330 + err = PTR_ERR(h_file);
9333 + au_set_h_fptr(file, bindex, h_file);
9335 + au_update_figen(file);
9336 + /* todo: necessary? */
9337 + /* file->f_ra = h_file->f_ra; */
9339 + return 0; /* success */
9342 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9343 + au_set_h_fptr(file, bindex, NULL);
9344 + au_set_fbstart(file, -1);
9345 + au_set_fbend_dir(file, -1);
9350 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9351 + struct file *file)
9354 + struct super_block *sb;
9355 + struct au_fidir *fidir;
9358 + sb = file->f_path.dentry->d_sb;
9359 + si_read_lock(sb, AuLock_FLUSH);
9360 + fidir = au_fidir_alloc(sb);
9362 + err = au_do_open(file, do_open_dir, fidir);
9363 + if (unlikely(err))
9366 + si_read_unlock(sb);
9370 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9371 + struct file *file)
9373 + struct au_vdir *vdir_cache;
9374 + struct au_finfo *finfo;
9375 + struct au_fidir *fidir;
9376 + aufs_bindex_t bindex, bend;
9378 + finfo = au_fi(file);
9379 + fidir = finfo->fi_hdir;
9381 + au_sphl_del(&finfo->fi_hlist,
9382 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9383 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9385 + au_vdir_free(vdir_cache);
9387 + bindex = finfo->fi_btop;
9388 + if (bindex >= 0) {
9390 + * calls fput() instead of filp_close(),
9391 + * since no dnotify or lock for the lower file.
9393 + bend = fidir->fd_bbot;
9394 + for (; bindex <= bend; bindex++)
9395 + au_set_h_fptr(file, bindex, NULL);
9398 + finfo->fi_hdir = NULL;
9400 + au_finfo_fin(file);
9404 +/* ---------------------------------------------------------------------- */
9406 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9409 + aufs_bindex_t bindex, bend;
9410 + struct file *h_file;
9413 + bend = au_fbend_dir(file);
9414 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9415 + h_file = au_hf_dir(file, bindex);
9417 + err = vfsub_flush(h_file, id);
9422 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9424 + return au_do_flush(file, id, au_do_flush_dir);
9427 +/* ---------------------------------------------------------------------- */
9429 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9432 + aufs_bindex_t bend, bindex;
9433 + struct inode *inode;
9434 + struct super_block *sb;
9437 + sb = dentry->d_sb;
9438 + inode = dentry->d_inode;
9440 + bend = au_dbend(dentry);
9441 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9442 + struct path h_path;
9444 + if (au_test_ro(sb, bindex, inode))
9446 + h_path.dentry = au_h_dptr(dentry, bindex);
9447 + if (!h_path.dentry)
9450 + h_path.mnt = au_sbr_mnt(sb, bindex);
9451 + err = vfsub_fsync(NULL, &h_path, datasync);
9457 +static int au_do_fsync_dir(struct file *file, int datasync)
9460 + aufs_bindex_t bend, bindex;
9461 + struct file *h_file;
9462 + struct super_block *sb;
9463 + struct inode *inode;
9465 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9466 + if (unlikely(err))
9469 + sb = file->f_path.dentry->d_sb;
9470 + inode = file_inode(file);
9471 + bend = au_fbend_dir(file);
9472 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9473 + h_file = au_hf_dir(file, bindex);
9474 + if (!h_file || au_test_ro(sb, bindex, inode))
9477 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9485 + * @file may be NULL
9487 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9491 + struct dentry *dentry;
9492 + struct super_block *sb;
9493 + struct mutex *mtx;
9496 + dentry = file->f_path.dentry;
9497 + mtx = &dentry->d_inode->i_mutex;
9499 + sb = dentry->d_sb;
9500 + si_noflush_read_lock(sb);
9502 + err = au_do_fsync_dir(file, datasync);
9504 + di_write_lock_child(dentry);
9505 + err = au_do_fsync_dir_no_file(dentry, datasync);
9507 + au_cpup_attr_timesizes(dentry->d_inode);
9508 + di_write_unlock(dentry);
9510 + fi_write_unlock(file);
9512 + si_read_unlock(sb);
9513 + mutex_unlock(mtx);
9517 +/* ---------------------------------------------------------------------- */
9519 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9522 + struct dentry *dentry;
9523 + struct inode *inode, *h_inode;
9524 + struct super_block *sb;
9526 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9528 + dentry = file->f_path.dentry;
9529 + inode = dentry->d_inode;
9532 + sb = dentry->d_sb;
9533 + si_read_lock(sb, AuLock_FLUSH);
9534 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9535 + if (unlikely(err))
9537 + err = au_alive_dir(dentry);
9539 + err = au_vdir_init(file);
9540 + di_downgrade_lock(dentry, AuLock_IR);
9541 + if (unlikely(err))
9544 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9545 + if (!au_test_nfsd()) {
9546 + err = au_vdir_fill_de(file, ctx);
9547 + fsstack_copy_attr_atime(inode, h_inode);
9550 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9551 + * encode_fh() and others.
9553 + atomic_inc(&h_inode->i_count);
9554 + di_read_unlock(dentry, AuLock_IR);
9555 + si_read_unlock(sb);
9556 + err = au_vdir_fill_de(file, ctx);
9557 + fsstack_copy_attr_atime(inode, h_inode);
9558 + fi_write_unlock(file);
9566 + di_read_unlock(dentry, AuLock_IR);
9567 + fi_write_unlock(file);
9569 + si_read_unlock(sb);
9573 +/* ---------------------------------------------------------------------- */
9575 +#define AuTestEmpty_WHONLY 1
9576 +#define AuTestEmpty_CALLED (1 << 1)
9577 +#define AuTestEmpty_SHWH (1 << 2)
9578 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9579 +#define au_fset_testempty(flags, name) \
9580 + do { (flags) |= AuTestEmpty_##name; } while (0)
9581 +#define au_fclr_testempty(flags, name) \
9582 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9584 +#ifndef CONFIG_AUFS_SHWH
9585 +#undef AuTestEmpty_SHWH
9586 +#define AuTestEmpty_SHWH 0
9589 +struct test_empty_arg {
9590 + struct dir_context ctx;
9591 + struct au_nhash *whlist;
9592 + unsigned int flags;
9594 + aufs_bindex_t bindex;
9597 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9598 + int namelen, loff_t offset __maybe_unused, u64 ino,
9599 + unsigned int d_type)
9601 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9603 + char *name = (void *)__name;
9606 + au_fset_testempty(arg->flags, CALLED);
9608 + if (name[0] == '.'
9609 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9610 + goto out; /* success */
9612 + if (namelen <= AUFS_WH_PFX_LEN
9613 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9614 + if (au_ftest_testempty(arg->flags, WHONLY)
9615 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9616 + arg->err = -ENOTEMPTY;
9620 + name += AUFS_WH_PFX_LEN;
9621 + namelen -= AUFS_WH_PFX_LEN;
9622 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9623 + arg->err = au_nhash_append_wh
9624 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9625 + au_ftest_testempty(arg->flags, SHWH));
9629 + AuTraceErr(arg->err);
9633 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9636 + struct file *h_file;
9638 + h_file = au_h_open(dentry, arg->bindex,
9639 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9640 + /*file*/NULL, /*force_wr*/0);
9641 + err = PTR_ERR(h_file);
9642 + if (IS_ERR(h_file))
9646 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9647 + && !file_inode(h_file)->i_nlink)
9652 + au_fclr_testempty(arg->flags, CALLED);
9654 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9657 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9661 + au_sbr_put(dentry->d_sb, arg->bindex);
9666 +struct do_test_empty_args {
9668 + struct dentry *dentry;
9669 + struct test_empty_arg *arg;
9672 +static void call_do_test_empty(void *args)
9674 + struct do_test_empty_args *a = args;
9675 + *a->errp = do_test_empty(a->dentry, a->arg);
9678 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9681 + struct dentry *h_dentry;
9682 + struct inode *h_inode;
9684 + h_dentry = au_h_dptr(dentry, arg->bindex);
9685 + h_inode = h_dentry->d_inode;
9686 + /* todo: i_mode changes anytime? */
9687 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9688 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9689 + mutex_unlock(&h_inode->i_mutex);
9691 + err = do_test_empty(dentry, arg);
9693 + struct do_test_empty_args args = {
9698 + unsigned int flags = arg->flags;
9700 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9701 + if (unlikely(wkq_err))
9703 + arg->flags = flags;
9709 +int au_test_empty_lower(struct dentry *dentry)
9712 + unsigned int rdhash;
9713 + aufs_bindex_t bindex, bstart, btail;
9714 + struct au_nhash whlist;
9715 + struct test_empty_arg arg = {
9717 + .actor = test_empty_cb
9720 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
9722 + SiMustAnyLock(dentry->d_sb);
9724 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9726 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9727 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9728 + if (unlikely(err))
9732 + arg.whlist = &whlist;
9733 + bstart = au_dbstart(dentry);
9734 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9735 + au_fset_testempty(arg.flags, SHWH);
9736 + test_empty = do_test_empty;
9737 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
9738 + test_empty = sio_test_empty;
9739 + arg.bindex = bstart;
9740 + err = test_empty(dentry, &arg);
9741 + if (unlikely(err))
9744 + au_fset_testempty(arg.flags, WHONLY);
9745 + btail = au_dbtaildir(dentry);
9746 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9747 + struct dentry *h_dentry;
9749 + h_dentry = au_h_dptr(dentry, bindex);
9750 + if (h_dentry && h_dentry->d_inode) {
9751 + arg.bindex = bindex;
9752 + err = test_empty(dentry, &arg);
9757 + au_nhash_wh_free(&whlist);
9762 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9765 + struct test_empty_arg arg = {
9767 + .actor = test_empty_cb
9770 + aufs_bindex_t bindex, btail;
9773 + arg.whlist = whlist;
9774 + arg.flags = AuTestEmpty_WHONLY;
9775 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9776 + au_fset_testempty(arg.flags, SHWH);
9777 + btail = au_dbtaildir(dentry);
9778 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9779 + struct dentry *h_dentry;
9781 + h_dentry = au_h_dptr(dentry, bindex);
9782 + if (h_dentry && h_dentry->d_inode) {
9783 + arg.bindex = bindex;
9784 + err = sio_test_empty(dentry, &arg);
9791 +/* ---------------------------------------------------------------------- */
9793 +const struct file_operations aufs_dir_fop = {
9794 + .owner = THIS_MODULE,
9795 + .llseek = default_llseek,
9796 + .read = generic_read_dir,
9797 + .iterate = aufs_iterate,
9798 + .unlocked_ioctl = aufs_ioctl_dir,
9799 +#ifdef CONFIG_COMPAT
9800 + .compat_ioctl = aufs_compat_ioctl_dir,
9802 + .open = aufs_open_dir,
9803 + .release = aufs_release_dir,
9804 + .flush = aufs_flush_dir,
9805 + .fsync = aufs_fsync_dir
9807 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
9808 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9809 +++ linux/fs/aufs/dir.h 2015-04-13 15:10:20.783490201 +0200
9812 + * Copyright (C) 2005-2015 Junjiro R. Okajima
9814 + * This program, aufs is free software; you can redistribute it and/or modify
9815 + * it under the terms of the GNU General Public License as published by
9816 + * the Free Software Foundation; either version 2 of the License, or
9817 + * (at your option) any later version.
9819 + * This program is distributed in the hope that it will be useful,
9820 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9821 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9822 + * GNU General Public License for more details.
9824 + * You should have received a copy of the GNU General Public License
9825 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9829 + * directory operations
9832 +#ifndef __AUFS_DIR_H__
9833 +#define __AUFS_DIR_H__
9837 +#include <linux/fs.h>
9839 +/* ---------------------------------------------------------------------- */
9841 +/* need to be faster and smaller */
9844 + unsigned int nh_num;
9845 + struct hlist_head *nh_head;
9848 +struct au_vdir_destr {
9849 + unsigned char len;
9850 + unsigned char name[0];
9853 +struct au_vdir_dehstr {
9854 + struct hlist_node hash;
9855 + struct au_vdir_destr *str;
9856 +} ____cacheline_aligned_in_smp;
9858 +struct au_vdir_de {
9860 + unsigned char de_type;
9861 + /* caution: packed */
9862 + struct au_vdir_destr de_str;
9865 +struct au_vdir_wh {
9866 + struct hlist_node wh_hash;
9867 +#ifdef CONFIG_AUFS_SHWH
9869 + aufs_bindex_t wh_bindex;
9870 + unsigned char wh_type;
9872 + aufs_bindex_t wh_bindex;
9874 + /* caution: packed */
9875 + struct au_vdir_destr wh_str;
9878 +union au_vdir_deblk_p {
9879 + unsigned char *deblk;
9880 + struct au_vdir_de *de;
9884 + unsigned char **vd_deblk;
9885 + unsigned long vd_nblk;
9888 + union au_vdir_deblk_p p;
9891 + unsigned long vd_version;
9892 + unsigned int vd_deblk_sz;
9893 + unsigned long vd_jiffy;
9894 +} ____cacheline_aligned_in_smp;
9896 +/* ---------------------------------------------------------------------- */
9899 +extern const struct file_operations aufs_dir_fop;
9900 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9901 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9902 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9903 +int au_test_empty_lower(struct dentry *dentry);
9904 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9907 +unsigned int au_rdhash_est(loff_t sz);
9908 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9909 +void au_nhash_wh_free(struct au_nhash *whlist);
9910 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9912 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9913 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9914 + unsigned int d_type, aufs_bindex_t bindex,
9915 + unsigned char shwh);
9916 +void au_vdir_free(struct au_vdir *vdir);
9917 +int au_vdir_init(struct file *file);
9918 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9921 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9923 +#ifdef CONFIG_AUFS_RDU
9925 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9926 +#ifdef CONFIG_COMPAT
9927 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9928 + unsigned long arg);
9931 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
9932 + unsigned int cmd, unsigned long arg)
9933 +#ifdef CONFIG_COMPAT
9934 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
9935 + unsigned int cmd, unsigned long arg)
9939 +#endif /* __KERNEL__ */
9940 +#endif /* __AUFS_DIR_H__ */
9941 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
9942 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9943 +++ linux/fs/aufs/dynop.c 2015-04-13 15:10:20.783490201 +0200
9946 + * Copyright (C) 2010-2015 Junjiro R. Okajima
9948 + * This program, aufs is free software; you can redistribute it and/or modify
9949 + * it under the terms of the GNU General Public License as published by
9950 + * the Free Software Foundation; either version 2 of the License, or
9951 + * (at your option) any later version.
9953 + * This program is distributed in the hope that it will be useful,
9954 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9955 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9956 + * GNU General Public License for more details.
9958 + * You should have received a copy of the GNU General Public License
9959 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9963 + * dynamically customizable operations for regular files
9968 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9971 + * How large will these lists be?
9972 + * Usually just a few elements, 20-30 at most for each, I guess.
9974 +static struct au_splhead dynop[AuDyLast];
9976 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9978 + struct au_dykey *key, *tmp;
9979 + struct list_head *head;
9982 + head = &spl->head;
9984 + list_for_each_entry_rcu(tmp, head, dk_list)
9985 + if (tmp->dk_op.dy_hop == h_op) {
9987 + kref_get(&key->dk_kref);
9990 + rcu_read_unlock();
9995 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9997 + struct au_dykey **k, *found;
9998 + const void *h_op = key->dk_op.dy_hop;
10002 + k = br->br_dykey;
10003 + for (i = 0; i < AuBrDynOp; i++)
10005 + if (k[i]->dk_op.dy_hop == h_op) {
10012 + spin_lock(&br->br_dykey_lock);
10013 + for (; i < AuBrDynOp; i++)
10015 + if (k[i]->dk_op.dy_hop == h_op) {
10023 + spin_unlock(&br->br_dykey_lock);
10024 + BUG_ON(i == AuBrDynOp); /* expand the array */
10030 +/* kref_get() if @key is already added */
10031 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10033 + struct au_dykey *tmp, *found;
10034 + struct list_head *head;
10035 + const void *h_op = key->dk_op.dy_hop;
10038 + head = &spl->head;
10039 + spin_lock(&spl->spin);
10040 + list_for_each_entry(tmp, head, dk_list)
10041 + if (tmp->dk_op.dy_hop == h_op) {
10042 + kref_get(&tmp->dk_kref);
10047 + list_add_rcu(&key->dk_list, head);
10048 + spin_unlock(&spl->spin);
10055 +static void dy_free_rcu(struct rcu_head *rcu)
10057 + struct au_dykey *key;
10059 + key = container_of(rcu, struct au_dykey, dk_rcu);
10064 +static void dy_free(struct kref *kref)
10066 + struct au_dykey *key;
10067 + struct au_splhead *spl;
10069 + key = container_of(kref, struct au_dykey, dk_kref);
10070 + spl = dynop + key->dk_op.dy_type;
10071 + au_spl_del_rcu(&key->dk_list, spl);
10072 + call_rcu(&key->dk_rcu, dy_free_rcu);
10075 +void au_dy_put(struct au_dykey *key)
10077 + kref_put(&key->dk_kref, dy_free);
10080 +/* ---------------------------------------------------------------------- */
10082 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10084 +#ifdef CONFIG_AUFS_DEBUG
10085 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10086 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10088 +#define DyDbgDeclare(cnt) do {} while (0)
10089 +#define DyDbgInc(cnt) do {} while (0)
10092 +#define DySet(func, dst, src, h_op, h_sb) do { \
10094 + if (h_op->func) { \
10096 + dst.func = src.func; \
10098 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10102 +#define DySetForce(func, dst, src) do { \
10103 + AuDebugOn(!src.func); \
10105 + dst.func = src.func; \
10108 +#define DySetAop(func) \
10109 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10110 +#define DySetAopForce(func) \
10111 + DySetForce(func, dyaop->da_op, aufs_aop)
10113 +static void dy_aop(struct au_dykey *key, const void *h_op,
10114 + struct super_block *h_sb __maybe_unused)
10116 + struct au_dyaop *dyaop = (void *)key;
10117 + const struct address_space_operations *h_aop = h_op;
10118 + DyDbgDeclare(cnt);
10120 + AuDbg("%s\n", au_sbtype(h_sb));
10122 + DySetAop(writepage);
10123 + DySetAopForce(readpage); /* force */
10124 + DySetAop(writepages);
10125 + DySetAop(set_page_dirty);
10126 + DySetAop(readpages);
10127 + DySetAop(write_begin);
10128 + DySetAop(write_end);
10130 + DySetAop(invalidatepage);
10131 + DySetAop(releasepage);
10132 + DySetAop(freepage);
10133 + /* this one will be changed according to an aufs mount option */
10134 + DySetAop(direct_IO);
10135 + DySetAop(migratepage);
10136 + DySetAop(launder_page);
10137 + DySetAop(is_partially_uptodate);
10138 + DySetAop(is_dirty_writeback);
10139 + DySetAop(error_remove_page);
10140 + DySetAop(swap_activate);
10141 + DySetAop(swap_deactivate);
10143 + DyDbgSize(cnt, *h_aop);
10146 +/* ---------------------------------------------------------------------- */
10148 +static void dy_bug(struct kref *kref)
10153 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10155 + struct au_dykey *key, *old;
10156 + struct au_splhead *spl;
10159 + void (*set)(struct au_dykey *key, const void *h_op,
10160 + struct super_block *h_sb __maybe_unused);
10162 + static const struct op a[] = {
10164 + .sz = sizeof(struct au_dyaop),
10168 + const struct op *p;
10170 + spl = dynop + op->dy_type;
10171 + key = dy_gfind_get(spl, op->dy_hop);
10173 + goto out_add; /* success */
10175 + p = a + op->dy_type;
10176 + key = kzalloc(p->sz, GFP_NOFS);
10177 + if (unlikely(!key)) {
10178 + key = ERR_PTR(-ENOMEM);
10182 + key->dk_op.dy_hop = op->dy_hop;
10183 + kref_init(&key->dk_kref);
10184 + p->set(key, op->dy_hop, au_br_sb(br));
10185 + old = dy_gadd(spl, key);
10192 + old = dy_bradd(br, key);
10194 + /* its ref-count should never be zero here */
10195 + kref_put(&key->dk_kref, dy_bug);
10200 +/* ---------------------------------------------------------------------- */
10202 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10203 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10204 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10205 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10206 + * See the aufs manual in detail.
10208 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10211 + dyaop->da_op.direct_IO = NULL;
10213 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10216 +static struct au_dyaop *dy_aget(struct au_branch *br,
10217 + const struct address_space_operations *h_aop,
10220 + struct au_dyaop *dyaop;
10221 + struct au_dynop op;
10223 + op.dy_type = AuDy_AOP;
10224 + op.dy_haop = h_aop;
10225 + dyaop = (void *)dy_get(&op, br);
10226 + if (IS_ERR(dyaop))
10228 + dy_adx(dyaop, do_dx);
10234 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10235 + struct inode *h_inode)
10238 + struct super_block *sb;
10239 + struct au_branch *br;
10240 + struct au_dyaop *dyaop;
10242 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10243 + IiMustWriteLock(inode);
10245 + sb = inode->i_sb;
10246 + br = au_sbr(sb, bindex);
10247 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10248 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10249 + err = PTR_ERR(dyaop);
10250 + if (IS_ERR(dyaop))
10251 + /* unnecessary to call dy_fput() */
10255 + inode->i_mapping->a_ops = &dyaop->da_op;
10262 + * Is it safe to replace a_ops during the inode/file is in operation?
10263 + * Yes, I hope so.
10265 +int au_dy_irefresh(struct inode *inode)
10268 + aufs_bindex_t bstart;
10269 + struct inode *h_inode;
10272 + if (S_ISREG(inode->i_mode)) {
10273 + bstart = au_ibstart(inode);
10274 + h_inode = au_h_iptr(inode, bstart);
10275 + err = au_dy_iaop(inode, bstart, h_inode);
10280 +void au_dy_arefresh(int do_dx)
10282 + struct au_splhead *spl;
10283 + struct list_head *head;
10284 + struct au_dykey *key;
10286 + spl = dynop + AuDy_AOP;
10287 + head = &spl->head;
10288 + spin_lock(&spl->spin);
10289 + list_for_each_entry(key, head, dk_list)
10290 + dy_adx((void *)key, do_dx);
10291 + spin_unlock(&spl->spin);
10294 +/* ---------------------------------------------------------------------- */
10296 +void __init au_dy_init(void)
10300 + /* make sure that 'struct au_dykey *' can be any type */
10301 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10303 + for (i = 0; i < AuDyLast; i++)
10304 + au_spl_init(dynop + i);
10307 +void au_dy_fin(void)
10311 + for (i = 0; i < AuDyLast; i++)
10312 + WARN_ON(!list_empty(&dynop[i].head));
10314 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10315 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10316 +++ linux/fs/aufs/dynop.h 2015-04-13 15:10:20.783490201 +0200
10319 + * Copyright (C) 2010-2015 Junjiro R. Okajima
10321 + * This program, aufs is free software; you can redistribute it and/or modify
10322 + * it under the terms of the GNU General Public License as published by
10323 + * the Free Software Foundation; either version 2 of the License, or
10324 + * (at your option) any later version.
10326 + * This program is distributed in the hope that it will be useful,
10327 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10329 + * GNU General Public License for more details.
10331 + * You should have received a copy of the GNU General Public License
10332 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10336 + * dynamically customizable operations (for regular files only)
10339 +#ifndef __AUFS_DYNOP_H__
10340 +#define __AUFS_DYNOP_H__
10344 +#include <linux/fs.h>
10345 +#include <linux/kref.h>
10347 +enum {AuDy_AOP, AuDyLast};
10352 + const void *dy_hop;
10353 + const struct address_space_operations *dy_haop;
10359 + struct list_head dk_list;
10360 + struct rcu_head dk_rcu;
10362 + struct au_dynop dk_op;
10365 + * during I am in the branch local array, kref is gotten. when the
10366 + * branch is removed, kref is put.
10368 + struct kref dk_kref;
10371 +/* stop unioning since their sizes are very different from each other */
10373 + struct au_dykey da_key;
10374 + struct address_space_operations da_op; /* not const */
10377 +/* ---------------------------------------------------------------------- */
10381 +void au_dy_put(struct au_dykey *key);
10382 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10383 + struct inode *h_inode);
10384 +int au_dy_irefresh(struct inode *inode);
10385 +void au_dy_arefresh(int do_dio);
10387 +void __init au_dy_init(void);
10388 +void au_dy_fin(void);
10390 +#endif /* __KERNEL__ */
10391 +#endif /* __AUFS_DYNOP_H__ */
10392 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10393 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10394 +++ linux/fs/aufs/export.c 2015-04-13 15:10:20.783490201 +0200
10397 + * Copyright (C) 2005-2015 Junjiro R. Okajima
10399 + * This program, aufs is free software; you can redistribute it and/or modify
10400 + * it under the terms of the GNU General Public License as published by
10401 + * the Free Software Foundation; either version 2 of the License, or
10402 + * (at your option) any later version.
10404 + * This program is distributed in the hope that it will be useful,
10405 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10407 + * GNU General Public License for more details.
10409 + * You should have received a copy of the GNU General Public License
10410 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10417 +#include <linux/exportfs.h>
10418 +#include <linux/fs_struct.h>
10419 +#include <linux/namei.h>
10420 +#include <linux/nsproxy.h>
10421 +#include <linux/random.h>
10422 +#include <linux/writeback.h>
10423 +#include "../fs/mount.h"
10427 +#ifdef CONFIG_AUFS_INO_T_64
10435 +static ino_t decode_ino(__u32 *a)
10439 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10441 +#ifdef CONFIG_AUFS_INO_T_64
10447 +static void encode_ino(__u32 *a, ino_t ino)
10453 +#ifdef CONFIG_AUFS_INO_T_64
10458 +/* NFS file handle */
10462 +#ifdef CONFIG_AUFS_INO_T_64
10463 + /* support 64bit inode number */
10476 + Fh_ino = Fh_ino1,
10477 + Fh_dir_ino = Fh_dir_ino1
10480 +static int au_test_anon(struct dentry *dentry)
10482 + /* note: read d_flags without d_lock */
10483 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10486 +int au_test_nfsd(void)
10489 + struct task_struct *tsk = current;
10490 + char comm[sizeof(tsk->comm)];
10493 + if (tsk->flags & PF_KTHREAD) {
10494 + get_task_comm(comm, tsk);
10495 + ret = !strcmp(comm, "nfsd");
10501 +/* ---------------------------------------------------------------------- */
10502 +/* inode generation external table */
10504 +void au_xigen_inc(struct inode *inode)
10509 + struct super_block *sb;
10510 + struct au_sbinfo *sbinfo;
10512 + sb = inode->i_sb;
10513 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10515 + sbinfo = au_sbi(sb);
10516 + pos = inode->i_ino;
10517 + pos *= sizeof(igen);
10518 + igen = inode->i_generation + 1;
10519 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10520 + sizeof(igen), &pos);
10521 + if (sz == sizeof(igen))
10522 + return; /* success */
10524 + if (unlikely(sz >= 0))
10525 + AuIOErr("xigen error (%zd)\n", sz);
10528 +int au_xigen_new(struct inode *inode)
10533 + struct super_block *sb;
10534 + struct au_sbinfo *sbinfo;
10535 + struct file *file;
10538 + /* todo: dirty, at mount time */
10539 + if (inode->i_ino == AUFS_ROOT_INO)
10541 + sb = inode->i_sb;
10542 + SiMustAnyLock(sb);
10543 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10547 + pos = inode->i_ino;
10548 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10549 + AuIOErr1("too large i%lld\n", pos);
10552 + pos *= sizeof(inode->i_generation);
10555 + sbinfo = au_sbi(sb);
10556 + file = sbinfo->si_xigen;
10559 + if (vfsub_f_size_read(file)
10560 + < pos + sizeof(inode->i_generation)) {
10561 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10562 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10563 + sizeof(inode->i_generation), &pos);
10565 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10566 + sizeof(inode->i_generation), &pos);
10567 + if (sz == sizeof(inode->i_generation))
10568 + goto out; /* success */
10571 + if (unlikely(sz >= 0)) {
10573 + AuIOErr("xigen error (%zd)\n", sz);
10580 +int au_xigen_set(struct super_block *sb, struct file *base)
10583 + struct au_sbinfo *sbinfo;
10584 + struct file *file;
10586 + SiMustWriteLock(sb);
10588 + sbinfo = au_sbi(sb);
10589 + file = au_xino_create2(base, sbinfo->si_xigen);
10590 + err = PTR_ERR(file);
10591 + if (IS_ERR(file))
10594 + if (sbinfo->si_xigen)
10595 + fput(sbinfo->si_xigen);
10596 + sbinfo->si_xigen = file;
10602 +void au_xigen_clr(struct super_block *sb)
10604 + struct au_sbinfo *sbinfo;
10606 + SiMustWriteLock(sb);
10608 + sbinfo = au_sbi(sb);
10609 + if (sbinfo->si_xigen) {
10610 + fput(sbinfo->si_xigen);
10611 + sbinfo->si_xigen = NULL;
10615 +/* ---------------------------------------------------------------------- */
10617 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10620 + struct dentry *dentry, *d;
10621 + struct inode *inode;
10622 + unsigned int sigen;
10625 + inode = ilookup(sb, ino);
10629 + dentry = ERR_PTR(-ESTALE);
10630 + sigen = au_sigen(sb);
10631 + if (unlikely(is_bad_inode(inode)
10632 + || IS_DEADDIR(inode)
10633 + || sigen != au_iigen(inode, NULL)))
10637 + if (!dir_ino || S_ISDIR(inode->i_mode))
10638 + dentry = d_find_alias(inode);
10640 + spin_lock(&inode->i_lock);
10641 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10642 + spin_lock(&d->d_lock);
10643 + if (!au_test_anon(d)
10644 + && d->d_parent->d_inode->i_ino == dir_ino) {
10645 + dentry = dget_dlock(d);
10646 + spin_unlock(&d->d_lock);
10649 + spin_unlock(&d->d_lock);
10651 + spin_unlock(&inode->i_lock);
10653 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10654 + /* need to refresh */
10662 + AuTraceErrPtr(dentry);
10666 +/* ---------------------------------------------------------------------- */
10668 +/* todo: dirty? */
10669 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10671 +struct au_compare_mnt_args {
10673 + struct super_block *sb;
10676 + struct vfsmount *mnt;
10679 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10681 + struct au_compare_mnt_args *a = arg;
10683 + if (mnt->mnt_sb != a->sb)
10685 + a->mnt = mntget(mnt);
10689 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10692 + struct path root;
10693 + struct au_compare_mnt_args args = {
10697 + get_fs_root(current->fs, &root);
10699 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10700 + rcu_read_unlock();
10703 + AuDebugOn(!args.mnt);
10707 +struct au_nfsd_si_lock {
10708 + unsigned int sigen;
10709 + aufs_bindex_t bindex, br_id;
10710 + unsigned char force_lock;
10713 +static int si_nfsd_read_lock(struct super_block *sb,
10714 + struct au_nfsd_si_lock *nsi_lock)
10717 + aufs_bindex_t bindex;
10719 + si_read_lock(sb, AuLock_FLUSH);
10721 + /* branch id may be wrapped around */
10723 + bindex = au_br_index(sb, nsi_lock->br_id);
10724 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10725 + goto out; /* success */
10729 + if (!nsi_lock->force_lock)
10730 + si_read_unlock(sb);
10733 + nsi_lock->bindex = bindex;
10737 +struct find_name_by_ino {
10738 + struct dir_context ctx;
10739 + int called, found;
10746 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10747 + loff_t offset, u64 ino, unsigned int d_type)
10749 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10753 + if (a->ino != ino)
10756 + memcpy(a->name, name, namelen);
10757 + a->namelen = namelen;
10762 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10763 + struct au_nfsd_si_lock *nsi_lock)
10765 + struct dentry *dentry, *parent;
10766 + struct file *file;
10767 + struct inode *dir;
10768 + struct find_name_by_ino arg = {
10770 + .actor = find_name_by_ino
10775 + parent = path->dentry;
10777 + si_read_unlock(parent->d_sb);
10778 + file = vfsub_dentry_open(path, au_dir_roflags);
10779 + dentry = (void *)file;
10780 + if (IS_ERR(file))
10783 + dentry = ERR_PTR(-ENOMEM);
10784 + arg.name = (void *)__get_free_page(GFP_NOFS);
10785 + if (unlikely(!arg.name))
10792 + err = vfsub_iterate_dir(file, &arg.ctx);
10793 + } while (!err && !arg.found && arg.called);
10794 + dentry = ERR_PTR(err);
10795 + if (unlikely(err))
10797 + /* instead of ENOENT */
10798 + dentry = ERR_PTR(-ESTALE);
10802 + /* do not call vfsub_lkup_one() */
10803 + dir = parent->d_inode;
10804 + mutex_lock(&dir->i_mutex);
10805 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10806 + mutex_unlock(&dir->i_mutex);
10807 + AuTraceErrPtr(dentry);
10808 + if (IS_ERR(dentry))
10810 + AuDebugOn(au_test_anon(dentry));
10811 + if (unlikely(!dentry->d_inode)) {
10813 + dentry = ERR_PTR(-ENOENT);
10817 + free_page((unsigned long)arg.name);
10821 + if (unlikely(nsi_lock
10822 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10823 + if (!IS_ERR(dentry)) {
10825 + dentry = ERR_PTR(-ESTALE);
10827 + AuTraceErrPtr(dentry);
10831 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10833 + struct au_nfsd_si_lock *nsi_lock)
10835 + struct dentry *dentry;
10836 + struct path path;
10838 + if (dir_ino != AUFS_ROOT_INO) {
10839 + path.dentry = decode_by_ino(sb, dir_ino, 0);
10840 + dentry = path.dentry;
10841 + if (!path.dentry || IS_ERR(path.dentry))
10843 + AuDebugOn(au_test_anon(path.dentry));
10845 + path.dentry = dget(sb->s_root);
10847 + path.mnt = au_mnt_get(sb);
10848 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
10852 + AuTraceErrPtr(dentry);
10856 +/* ---------------------------------------------------------------------- */
10858 +static int h_acceptable(void *expv, struct dentry *dentry)
10863 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
10864 + char *buf, int len, struct super_block *sb)
10868 + struct path path;
10870 + p = d_path(h_rootpath, buf, len);
10875 + path.mnt = h_rootpath->mnt;
10876 + path.dentry = h_parent;
10877 + p = d_path(&path, buf, len);
10883 + path.mnt = au_mnt_get(sb);
10884 + path.dentry = sb->s_root;
10885 + p = d_path(&path, buf, len - strlen(p));
10886 + mntput(path.mnt);
10890 + p[strlen(p)] = '/';
10893 + AuTraceErrPtr(p);
10898 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10899 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10901 + struct dentry *dentry, *h_parent, *root;
10902 + struct super_block *h_sb;
10903 + char *pathname, *p;
10904 + struct vfsmount *h_mnt;
10905 + struct au_branch *br;
10907 + struct path path;
10909 + br = au_sbr(sb, nsi_lock->bindex);
10910 + h_mnt = au_br_mnt(br);
10911 + h_sb = h_mnt->mnt_sb;
10912 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10913 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10914 + fh_len - Fh_tail, fh[Fh_h_type],
10915 + h_acceptable, /*context*/NULL);
10916 + dentry = h_parent;
10917 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10918 + AuWarn1("%s decode_fh failed, %ld\n",
10919 + au_sbtype(h_sb), PTR_ERR(h_parent));
10923 + if (unlikely(au_test_anon(h_parent))) {
10924 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10925 + au_sbtype(h_sb));
10926 + goto out_h_parent;
10929 + dentry = ERR_PTR(-ENOMEM);
10930 + pathname = (void *)__get_free_page(GFP_NOFS);
10931 + if (unlikely(!pathname))
10932 + goto out_h_parent;
10934 + root = sb->s_root;
10935 + path.mnt = h_mnt;
10936 + di_read_lock_parent(root, !AuLock_IR);
10937 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10938 + di_read_unlock(root, !AuLock_IR);
10939 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10940 + dentry = (void *)p;
10942 + goto out_pathname;
10944 + si_read_unlock(sb);
10945 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10946 + dentry = ERR_PTR(err);
10947 + if (unlikely(err))
10950 + dentry = ERR_PTR(-ENOENT);
10951 + AuDebugOn(au_test_anon(path.dentry));
10952 + if (unlikely(!path.dentry->d_inode))
10955 + if (ino != path.dentry->d_inode->i_ino)
10956 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10958 + dentry = dget(path.dentry);
10963 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10964 + if (!IS_ERR(dentry)) {
10966 + dentry = ERR_PTR(-ESTALE);
10969 + free_page((unsigned long)pathname);
10973 + AuTraceErrPtr(dentry);
10977 +/* ---------------------------------------------------------------------- */
10979 +static struct dentry *
10980 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10983 + struct dentry *dentry;
10984 + __u32 *fh = fid->raw;
10985 + struct au_branch *br;
10986 + ino_t ino, dir_ino;
10987 + struct au_nfsd_si_lock nsi_lock = {
10991 + dentry = ERR_PTR(-ESTALE);
10992 + /* it should never happen, but the file handle is unreliable */
10993 + if (unlikely(fh_len < Fh_tail))
10995 + nsi_lock.sigen = fh[Fh_sigen];
10996 + nsi_lock.br_id = fh[Fh_br_id];
10998 + /* branch id may be wrapped around */
11000 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11002 + nsi_lock.force_lock = 1;
11004 + /* is this inode still cached? */
11005 + ino = decode_ino(fh + Fh_ino);
11006 + /* it should never happen */
11007 + if (unlikely(ino == AUFS_ROOT_INO))
11010 + dir_ino = decode_ino(fh + Fh_dir_ino);
11011 + dentry = decode_by_ino(sb, ino, dir_ino);
11012 + if (IS_ERR(dentry))
11017 + /* is the parent dir cached? */
11018 + br = au_sbr(sb, nsi_lock.bindex);
11019 + atomic_inc(&br->br_count);
11020 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11021 + if (IS_ERR(dentry))
11026 + /* lookup path */
11027 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11028 + if (IS_ERR(dentry))
11030 + if (unlikely(!dentry))
11031 + /* todo?: make it ESTALE */
11035 + if (!au_digen_test(dentry, au_sigen(sb))
11036 + && dentry->d_inode->i_generation == fh[Fh_igen])
11037 + goto out_unlock; /* success */
11040 + dentry = ERR_PTR(-ESTALE);
11043 + atomic_dec(&br->br_count);
11044 + si_read_unlock(sb);
11046 + AuTraceErrPtr(dentry);
11050 +#if 0 /* reserved for future use */
11051 +/* support subtreecheck option */
11052 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11053 + int fh_len, int fh_type)
11055 + struct dentry *parent;
11056 + __u32 *fh = fid->raw;
11059 + dir_ino = decode_ino(fh + Fh_dir_ino);
11060 + parent = decode_by_ino(sb, dir_ino, 0);
11061 + if (IS_ERR(parent))
11064 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11065 + dir_ino, fh, fh_len);
11068 + AuTraceErrPtr(parent);
11073 +/* ---------------------------------------------------------------------- */
11075 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11076 + struct inode *dir)
11079 + aufs_bindex_t bindex;
11080 + struct super_block *sb, *h_sb;
11081 + struct dentry *dentry, *parent, *h_parent;
11082 + struct inode *h_dir;
11083 + struct au_branch *br;
11086 + if (unlikely(*max_len <= Fh_tail)) {
11087 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11091 + err = FILEID_ROOT;
11092 + if (inode->i_ino == AUFS_ROOT_INO) {
11093 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11098 + sb = inode->i_sb;
11099 + err = si_read_lock(sb, AuLock_FLUSH);
11100 + if (unlikely(err))
11103 +#ifdef CONFIG_AUFS_DEBUG
11104 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11105 + AuWarn1("NFS-exporting requires xino\n");
11109 + ii_read_lock_child(inode);
11110 + bindex = au_ibstart(inode);
11112 + dentry = d_find_any_alias(inode);
11113 + if (unlikely(!dentry))
11115 + AuDebugOn(au_test_anon(dentry));
11116 + parent = dget_parent(dentry);
11118 + if (unlikely(!parent))
11120 + dir = parent->d_inode;
11123 + ii_read_lock_parent(dir);
11124 + h_dir = au_h_iptr(dir, bindex);
11125 + ii_read_unlock(dir);
11126 + if (unlikely(!h_dir))
11128 + h_parent = d_find_any_alias(h_dir);
11129 + if (unlikely(!h_parent))
11130 + goto out_hparent;
11133 + br = au_sbr(sb, bindex);
11134 + h_sb = au_br_sb(br);
11135 + if (unlikely(!h_sb->s_export_op)) {
11136 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11137 + goto out_hparent;
11140 + fh[Fh_br_id] = br->br_id;
11141 + fh[Fh_sigen] = au_sigen(sb);
11142 + encode_ino(fh + Fh_ino, inode->i_ino);
11143 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11144 + fh[Fh_igen] = inode->i_generation;
11146 + *max_len -= Fh_tail;
11147 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11149 + /*connectable or subtreecheck*/0);
11150 + err = fh[Fh_h_type];
11151 + *max_len += Fh_tail;
11152 + /* todo: macros? */
11153 + if (err != FILEID_INVALID)
11156 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11163 + ii_read_unlock(inode);
11164 + si_read_unlock(sb);
11166 + if (unlikely(err < 0))
11167 + err = FILEID_INVALID;
11171 +/* ---------------------------------------------------------------------- */
11173 +static int aufs_commit_metadata(struct inode *inode)
11176 + aufs_bindex_t bindex;
11177 + struct super_block *sb;
11178 + struct inode *h_inode;
11179 + int (*f)(struct inode *inode);
11181 + sb = inode->i_sb;
11182 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11183 + ii_write_lock_child(inode);
11184 + bindex = au_ibstart(inode);
11185 + AuDebugOn(bindex < 0);
11186 + h_inode = au_h_iptr(inode, bindex);
11188 + f = h_inode->i_sb->s_export_op->commit_metadata;
11190 + err = f(h_inode);
11192 + struct writeback_control wbc = {
11193 + .sync_mode = WB_SYNC_ALL,
11194 + .nr_to_write = 0 /* metadata only */
11197 + err = sync_inode(h_inode, &wbc);
11200 + au_cpup_attr_timesizes(inode);
11201 + ii_write_unlock(inode);
11202 + si_read_unlock(sb);
11206 +/* ---------------------------------------------------------------------- */
11208 +static struct export_operations aufs_export_op = {
11209 + .fh_to_dentry = aufs_fh_to_dentry,
11210 + /* .fh_to_parent = aufs_fh_to_parent, */
11211 + .encode_fh = aufs_encode_fh,
11212 + .commit_metadata = aufs_commit_metadata
11215 +void au_export_init(struct super_block *sb)
11217 + struct au_sbinfo *sbinfo;
11220 + sb->s_export_op = &aufs_export_op;
11221 + sbinfo = au_sbi(sb);
11222 + sbinfo->si_xigen = NULL;
11223 + get_random_bytes(&u, sizeof(u));
11224 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11225 + atomic_set(&sbinfo->si_xigen_next, u);
11227 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11228 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11229 +++ linux/fs/aufs/fhsm.c 2015-04-13 15:10:20.783490201 +0200
11232 + * Copyright (C) 2011-2015 Junjiro R. Okajima
11234 + * This program, aufs is free software; you can redistribute it and/or modify
11235 + * it under the terms of the GNU General Public License as published by
11236 + * the Free Software Foundation; either version 2 of the License, or
11237 + * (at your option) any later version.
11239 + * This program is distributed in the hope that it will be useful,
11240 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11241 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11242 + * GNU General Public License for more details.
11244 + * You should have received a copy of the GNU General Public License
11245 + * along with this program; if not, write to the Free Software
11246 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11250 + * File-based Hierarchy Storage Management
11253 +#include <linux/anon_inodes.h>
11254 +#include <linux/poll.h>
11255 +#include <linux/seq_file.h>
11256 +#include <linux/statfs.h>
11259 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11261 + struct au_sbinfo *sbinfo;
11262 + struct au_fhsm *fhsm;
11264 + SiMustAnyLock(sb);
11266 + sbinfo = au_sbi(sb);
11267 + fhsm = &sbinfo->si_fhsm;
11268 + AuDebugOn(!fhsm);
11269 + return fhsm->fhsm_bottom;
11272 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11274 + struct au_sbinfo *sbinfo;
11275 + struct au_fhsm *fhsm;
11277 + SiMustWriteLock(sb);
11279 + sbinfo = au_sbi(sb);
11280 + fhsm = &sbinfo->si_fhsm;
11281 + AuDebugOn(!fhsm);
11282 + fhsm->fhsm_bottom = bindex;
11285 +/* ---------------------------------------------------------------------- */
11287 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11289 + struct au_br_fhsm *bf;
11291 + bf = br->br_fhsm;
11292 + MtxMustLock(&bf->bf_lock);
11294 + return !bf->bf_readable
11295 + || time_after(jiffies,
11296 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11299 +/* ---------------------------------------------------------------------- */
11301 +static void au_fhsm_notify(struct super_block *sb, int val)
11303 + struct au_sbinfo *sbinfo;
11304 + struct au_fhsm *fhsm;
11306 + SiMustAnyLock(sb);
11308 + sbinfo = au_sbi(sb);
11309 + fhsm = &sbinfo->si_fhsm;
11310 + if (au_fhsm_pid(fhsm)
11311 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11312 + atomic_set(&fhsm->fhsm_readable, val);
11314 + wake_up(&fhsm->fhsm_wqh);
11318 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11319 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11322 + struct au_branch *br;
11323 + struct au_br_fhsm *bf;
11325 + br = au_sbr(sb, bindex);
11326 + AuDebugOn(au_br_rdonly(br));
11327 + bf = br->br_fhsm;
11331 + mutex_lock(&bf->bf_lock);
11333 + MtxMustLock(&bf->bf_lock);
11335 + /* sb->s_root for NFS is unreliable */
11336 + err = au_br_stfs(br, &bf->bf_stfs);
11337 + if (unlikely(err)) {
11338 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11342 + bf->bf_jiffy = jiffies;
11343 + bf->bf_readable = 1;
11345 + au_fhsm_notify(sb, /*val*/1);
11347 + *rstfs = bf->bf_stfs;
11351 + mutex_unlock(&bf->bf_lock);
11352 + au_fhsm_notify(sb, /*val*/1);
11357 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11360 + struct au_sbinfo *sbinfo;
11361 + struct au_fhsm *fhsm;
11362 + struct au_branch *br;
11363 + struct au_br_fhsm *bf;
11365 + AuDbg("b%d, force %d\n", bindex, force);
11366 + SiMustAnyLock(sb);
11368 + sbinfo = au_sbi(sb);
11369 + fhsm = &sbinfo->si_fhsm;
11370 + if (!au_ftest_si(sbinfo, FHSM)
11371 + || fhsm->fhsm_bottom == bindex)
11374 + br = au_sbr(sb, bindex);
11375 + bf = br->br_fhsm;
11377 + mutex_lock(&bf->bf_lock);
11379 + || au_fhsm_pid(fhsm)
11380 + || au_fhsm_test_jiffy(sbinfo, br))
11381 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11383 + mutex_unlock(&bf->bf_lock);
11386 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11388 + aufs_bindex_t bindex, bend;
11389 + struct au_branch *br;
11391 + /* exclude the bottom */
11392 + bend = au_fhsm_bottom(sb);
11393 + for (bindex = 0; bindex < bend; bindex++) {
11394 + br = au_sbr(sb, bindex);
11395 + if (au_br_fhsm(br->br_perm))
11396 + au_fhsm_wrote(sb, bindex, force);
11400 +/* ---------------------------------------------------------------------- */
11402 +static unsigned int au_fhsm_poll(struct file *file,
11403 + struct poll_table_struct *wait)
11405 + unsigned int mask;
11406 + struct au_sbinfo *sbinfo;
11407 + struct au_fhsm *fhsm;
11410 + sbinfo = file->private_data;
11411 + fhsm = &sbinfo->si_fhsm;
11412 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11413 + if (atomic_read(&fhsm->fhsm_readable))
11414 + mask = POLLIN /* | POLLRDNORM */;
11416 + AuTraceErr((int)mask);
11420 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11421 + struct aufs_stfs *stfs, __s16 brid)
11425 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11427 + err = __put_user(brid, &stbr->brid);
11428 + if (unlikely(err))
11434 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11435 + struct aufs_stbr __user *stbr, size_t count)
11439 + aufs_bindex_t bindex, bend;
11440 + struct au_branch *br;
11441 + struct au_br_fhsm *bf;
11443 + /* except the bottom branch */
11446 + bend = au_fhsm_bottom(sb);
11447 + for (bindex = 0; !err && bindex < bend; bindex++) {
11448 + br = au_sbr(sb, bindex);
11449 + if (!au_br_fhsm(br->br_perm))
11452 + bf = br->br_fhsm;
11453 + mutex_lock(&bf->bf_lock);
11454 + if (bf->bf_readable) {
11456 + if (count >= sizeof(*stbr))
11457 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11460 + bf->bf_readable = 0;
11461 + count -= sizeof(*stbr);
11465 + mutex_unlock(&bf->bf_lock);
11468 + err = sizeof(*stbr) * nstbr;
11473 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11478 + aufs_bindex_t nfhsm, bindex, bend;
11479 + struct au_sbinfo *sbinfo;
11480 + struct au_fhsm *fhsm;
11481 + struct au_branch *br;
11482 + struct super_block *sb;
11485 + sbinfo = file->private_data;
11486 + fhsm = &sbinfo->si_fhsm;
11488 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11489 + if (!atomic_read(&fhsm->fhsm_readable)) {
11490 + if (vfsub_file_flags(file) & O_NONBLOCK)
11493 + err = wait_event_interruptible_locked_irq
11495 + atomic_read(&fhsm->fhsm_readable));
11497 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11498 + if (unlikely(err))
11501 + /* sb may already be dead */
11502 + au_rw_read_lock(&sbinfo->si_rwsem);
11503 + readable = atomic_read(&fhsm->fhsm_readable);
11504 + if (readable > 0) {
11505 + sb = sbinfo->si_sb;
11507 + /* exclude the bottom branch */
11509 + bend = au_fhsm_bottom(sb);
11510 + for (bindex = 0; bindex < bend; bindex++) {
11511 + br = au_sbr(sb, bindex);
11512 + if (au_br_fhsm(br->br_perm))
11516 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11517 + atomic_set(&fhsm->fhsm_readable, 0);
11518 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11522 + au_rw_read_unlock(&sbinfo->si_rwsem);
11530 +static int au_fhsm_release(struct inode *inode, struct file *file)
11532 + struct au_sbinfo *sbinfo;
11533 + struct au_fhsm *fhsm;
11535 + /* sb may already be dead */
11536 + sbinfo = file->private_data;
11537 + fhsm = &sbinfo->si_fhsm;
11538 + spin_lock(&fhsm->fhsm_spin);
11539 + fhsm->fhsm_pid = 0;
11540 + spin_unlock(&fhsm->fhsm_spin);
11541 + kobject_put(&sbinfo->si_kobj);
11546 +static const struct file_operations au_fhsm_fops = {
11547 + .owner = THIS_MODULE,
11548 + .llseek = noop_llseek,
11549 + .read = au_fhsm_read,
11550 + .poll = au_fhsm_poll,
11551 + .release = au_fhsm_release
11554 +int au_fhsm_fd(struct super_block *sb, int oflags)
11557 + struct au_sbinfo *sbinfo;
11558 + struct au_fhsm *fhsm;
11561 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11565 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11569 + sbinfo = au_sbi(sb);
11570 + fhsm = &sbinfo->si_fhsm;
11571 + spin_lock(&fhsm->fhsm_spin);
11572 + if (!fhsm->fhsm_pid)
11573 + fhsm->fhsm_pid = current->pid;
11576 + spin_unlock(&fhsm->fhsm_spin);
11577 + if (unlikely(err))
11580 + oflags |= O_RDONLY;
11581 + /* oflags |= FMODE_NONOTIFY; */
11582 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11584 + if (unlikely(fd < 0))
11587 + /* succeed reglardless 'fhsm' status */
11588 + kobject_get(&sbinfo->si_kobj);
11589 + si_noflush_read_lock(sb);
11590 + if (au_ftest_si(sbinfo, FHSM))
11591 + au_fhsm_wrote_all(sb, /*force*/0);
11592 + si_read_unlock(sb);
11593 + goto out; /* success */
11596 + spin_lock(&fhsm->fhsm_spin);
11597 + fhsm->fhsm_pid = 0;
11598 + spin_unlock(&fhsm->fhsm_spin);
11604 +/* ---------------------------------------------------------------------- */
11606 +int au_fhsm_br_alloc(struct au_branch *br)
11611 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
11613 + au_br_fhsm_init(br->br_fhsm);
11620 +/* ---------------------------------------------------------------------- */
11622 +void au_fhsm_fin(struct super_block *sb)
11624 + au_fhsm_notify(sb, /*val*/-1);
11627 +void au_fhsm_init(struct au_sbinfo *sbinfo)
11629 + struct au_fhsm *fhsm;
11631 + fhsm = &sbinfo->si_fhsm;
11632 + spin_lock_init(&fhsm->fhsm_spin);
11633 + init_waitqueue_head(&fhsm->fhsm_wqh);
11634 + atomic_set(&fhsm->fhsm_readable, 0);
11635 + fhsm->fhsm_expire
11636 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
11637 + fhsm->fhsm_bottom = -1;
11640 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
11642 + sbinfo->si_fhsm.fhsm_expire
11643 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
11646 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
11650 + if (!au_ftest_si(sbinfo, FHSM))
11653 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
11654 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
11655 + seq_printf(seq, ",fhsm_sec=%u", u);
11657 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11658 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11659 +++ linux/fs/aufs/file.c 2015-04-13 15:10:20.783490201 +0200
11662 + * Copyright (C) 2005-2015 Junjiro R. Okajima
11664 + * This program, aufs is free software; you can redistribute it and/or modify
11665 + * it under the terms of the GNU General Public License as published by
11666 + * the Free Software Foundation; either version 2 of the License, or
11667 + * (at your option) any later version.
11669 + * This program is distributed in the hope that it will be useful,
11670 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11671 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11672 + * GNU General Public License for more details.
11674 + * You should have received a copy of the GNU General Public License
11675 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11679 + * handling file/dir, and address_space operation
11682 +#ifdef CONFIG_AUFS_DEBUG
11683 +#include <linux/migrate.h>
11685 +#include <linux/pagemap.h>
11688 +/* drop flags for writing */
11689 +unsigned int au_file_roflags(unsigned int flags)
11691 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
11692 + flags |= O_RDONLY | O_NOATIME;
11696 +/* common functions to regular file and dir */
11697 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11698 + struct file *file, int force_wr)
11700 + struct file *h_file;
11701 + struct dentry *h_dentry;
11702 + struct inode *h_inode;
11703 + struct super_block *sb;
11704 + struct au_branch *br;
11705 + struct path h_path;
11706 + int err, exec_flag;
11708 + /* a race condition can happen between open and unlink/rmdir */
11709 + h_file = ERR_PTR(-ENOENT);
11710 + h_dentry = au_h_dptr(dentry, bindex);
11711 + if (au_test_nfsd() && !h_dentry)
11713 + h_inode = h_dentry->d_inode;
11714 + if (au_test_nfsd() && !h_inode)
11716 + spin_lock(&h_dentry->d_lock);
11717 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
11719 + /* || !dentry->d_inode->i_nlink */
11721 + spin_unlock(&h_dentry->d_lock);
11722 + if (unlikely(err))
11725 + sb = dentry->d_sb;
11726 + br = au_sbr(sb, bindex);
11727 + h_file = ERR_PTR(-EACCES);
11728 + exec_flag = flags & __FMODE_EXEC;
11729 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
11732 + /* drop flags for writing */
11733 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
11734 + if (force_wr && !(flags & O_WRONLY))
11736 + flags = au_file_roflags(flags);
11738 + h_file = ERR_PTR(-EROFS);
11739 + flags = au_file_roflags(flags);
11740 + if (unlikely(vfsub_native_ro(h_inode)
11741 + || IS_APPEND(h_inode)))
11743 + flags &= ~O_ACCMODE;
11744 + flags |= O_WRONLY;
11747 + flags &= ~O_CREAT;
11748 + atomic_inc(&br->br_count);
11749 + h_path.dentry = h_dentry;
11750 + h_path.mnt = au_br_mnt(br);
11751 + h_file = vfsub_dentry_open(&h_path, flags);
11752 + if (IS_ERR(h_file))
11756 + err = deny_write_access(h_file);
11757 + if (unlikely(err)) {
11759 + h_file = ERR_PTR(err);
11763 + fsnotify_open(h_file);
11764 + goto out; /* success */
11767 + atomic_dec(&br->br_count);
11772 +static int au_cmoo(struct dentry *dentry)
11775 + unsigned int udba;
11776 + struct path h_path;
11777 + struct au_pin pin;
11778 + struct au_cp_generic cpg = {
11779 + .dentry = dentry,
11784 + .flags = AuCpup_DTIME | AuCpup_HOPEN
11786 + struct inode *delegated;
11787 + struct super_block *sb;
11788 + struct au_sbinfo *sbinfo;
11789 + struct au_fhsm *fhsm;
11791 + struct au_branch *br;
11792 + struct dentry *parent;
11793 + struct au_hinode *hdir;
11795 + DiMustWriteLock(dentry);
11796 + IiMustWriteLock(dentry->d_inode);
11799 + if (IS_ROOT(dentry))
11801 + cpg.bsrc = au_dbstart(dentry);
11805 + sb = dentry->d_sb;
11806 + sbinfo = au_sbi(sb);
11807 + fhsm = &sbinfo->si_fhsm;
11808 + pid = au_fhsm_pid(fhsm);
11810 + && (current->pid == pid
11811 + || current->real_parent->pid == pid))
11814 + br = au_sbr(sb, cpg.bsrc);
11815 + cmoo = au_br_cmoo(br->br_perm);
11818 + if (!d_is_reg(dentry))
11819 + cmoo &= AuBrAttr_COO_ALL;
11823 + parent = dget_parent(dentry);
11824 + di_write_lock_parent(parent);
11825 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
11827 + if (unlikely(err < 0)) {
11828 + err = 0; /* there is no upper writable branch */
11831 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
11833 + /* do not respect the coo attrib for the target branch */
11834 + err = au_cpup_dirs(dentry, cpg.bdst);
11835 + if (unlikely(err))
11838 + di_downgrade_lock(parent, AuLock_IR);
11839 + udba = au_opt_udba(sb);
11840 + err = au_pin(&pin, dentry, cpg.bdst, udba,
11841 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11842 + if (unlikely(err))
11845 + err = au_sio_cpup_simple(&cpg);
11847 + if (unlikely(err))
11849 + if (!(cmoo & AuBrWAttr_MOO))
11850 + goto out_parent; /* success */
11852 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
11853 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11854 + if (unlikely(err))
11857 + h_path.mnt = au_br_mnt(br);
11858 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
11859 + hdir = au_hi(parent->d_inode, cpg.bsrc);
11860 + delegated = NULL;
11861 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
11863 + /* todo: keep h_dentry or not? */
11864 + if (unlikely(err == -EWOULDBLOCK)) {
11865 + pr_warn("cannot retry for NFSv4 delegation"
11866 + " for an internal unlink\n");
11869 + if (unlikely(err)) {
11870 + pr_err("unlink %pd after coo failed (%d), ignored\n",
11874 + goto out_parent; /* success */
11877 + di_downgrade_lock(parent, AuLock_IR);
11879 + di_read_unlock(parent, AuLock_IR);
11886 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11887 + struct au_fidir *fidir)
11890 + struct dentry *dentry;
11891 + struct au_finfo *finfo;
11893 + err = au_finfo_init(file, fidir);
11894 + if (unlikely(err))
11897 + dentry = file->f_path.dentry;
11898 + di_write_lock_child(dentry);
11899 + err = au_cmoo(dentry);
11900 + di_downgrade_lock(dentry, AuLock_IR);
11902 + err = open(file, vfsub_file_flags(file));
11903 + di_read_unlock(dentry, AuLock_IR);
11905 + finfo = au_fi(file);
11907 + finfo->fi_file = file;
11908 + au_sphl_add(&finfo->fi_hlist,
11909 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
11911 + fi_write_unlock(file);
11912 + if (unlikely(err)) {
11913 + finfo->fi_hdir = NULL;
11914 + au_finfo_fin(file);
11921 +int au_reopen_nondir(struct file *file)
11924 + aufs_bindex_t bstart;
11925 + struct dentry *dentry;
11926 + struct file *h_file, *h_file_tmp;
11928 + dentry = file->f_path.dentry;
11929 + bstart = au_dbstart(dentry);
11930 + h_file_tmp = NULL;
11931 + if (au_fbstart(file) == bstart) {
11932 + h_file = au_hf_top(file);
11933 + if (file->f_mode == h_file->f_mode)
11934 + return 0; /* success */
11935 + h_file_tmp = h_file;
11936 + get_file(h_file_tmp);
11937 + au_set_h_fptr(file, bstart, NULL);
11939 + AuDebugOn(au_fi(file)->fi_hdir);
11942 + * file exists on both of rw and ro
11943 + * open --> dbstart and fbstart are both 0
11944 + * prepend a branch as rw, "rw" become ro
11946 + * delete the top branch, "rw" becomes rw again
11947 + * --> dbstart is 1, fbstart is still 0
11948 + * write --> fbstart is 0 but dbstart is 1
11950 + /* AuDebugOn(au_fbstart(file) < bstart); */
11952 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
11953 + file, /*force_wr*/0);
11954 + err = PTR_ERR(h_file);
11955 + if (IS_ERR(h_file)) {
11956 + if (h_file_tmp) {
11957 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
11958 + au_set_h_fptr(file, bstart, h_file_tmp);
11959 + h_file_tmp = NULL;
11961 + goto out; /* todo: close all? */
11965 + au_set_fbstart(file, bstart);
11966 + au_set_h_fptr(file, bstart, h_file);
11967 + au_update_figen(file);
11968 + /* todo: necessary? */
11969 + /* file->f_ra = h_file->f_ra; */
11973 + fput(h_file_tmp);
11977 +/* ---------------------------------------------------------------------- */
11979 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
11980 + struct dentry *hi_wh)
11983 + aufs_bindex_t bstart;
11984 + struct au_dinfo *dinfo;
11985 + struct dentry *h_dentry;
11986 + struct au_hdentry *hdp;
11988 + dinfo = au_di(file->f_path.dentry);
11989 + AuRwMustWriteLock(&dinfo->di_rwsem);
11991 + bstart = dinfo->di_bstart;
11992 + dinfo->di_bstart = btgt;
11993 + hdp = dinfo->di_hdentry;
11994 + h_dentry = hdp[0 + btgt].hd_dentry;
11995 + hdp[0 + btgt].hd_dentry = hi_wh;
11996 + err = au_reopen_nondir(file);
11997 + hdp[0 + btgt].hd_dentry = h_dentry;
11998 + dinfo->di_bstart = bstart;
12003 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12004 + aufs_bindex_t bcpup, struct au_pin *pin)
12007 + struct inode *inode, *h_inode;
12008 + struct dentry *h_dentry, *hi_wh;
12009 + struct au_cp_generic cpg = {
12010 + .dentry = file->f_path.dentry,
12017 + au_update_dbstart(cpg.dentry);
12018 + inode = cpg.dentry->d_inode;
12020 + if (au_dbstart(cpg.dentry) <= bcpup
12021 + && au_dbend(cpg.dentry) >= bcpup) {
12022 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12024 + h_inode = h_dentry->d_inode;
12026 + hi_wh = au_hi_wh(inode, bcpup);
12027 + if (!hi_wh && !h_inode)
12028 + err = au_sio_cpup_wh(&cpg, file);
12030 + /* already copied-up after unlink */
12031 + err = au_reopen_wh(file, bcpup, hi_wh);
12034 + && (inode->i_nlink > 1
12035 + || (inode->i_state & I_LINKABLE))
12036 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12037 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12043 + * prepare the @file for writing.
12045 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12048 + aufs_bindex_t dbstart;
12049 + struct dentry *parent;
12050 + struct inode *inode;
12051 + struct super_block *sb;
12052 + struct file *h_file;
12053 + struct au_cp_generic cpg = {
12054 + .dentry = file->f_path.dentry,
12059 + .flags = AuCpup_DTIME
12062 + sb = cpg.dentry->d_sb;
12063 + inode = cpg.dentry->d_inode;
12064 + cpg.bsrc = au_fbstart(file);
12065 + err = au_test_ro(sb, cpg.bsrc, inode);
12066 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12067 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12072 + /* need to cpup or reopen */
12073 + parent = dget_parent(cpg.dentry);
12074 + di_write_lock_parent(parent);
12075 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12077 + if (unlikely(err < 0))
12081 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12082 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12083 + if (unlikely(err))
12087 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12088 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12089 + if (unlikely(err))
12092 + dbstart = au_dbstart(cpg.dentry);
12093 + if (dbstart <= cpg.bdst)
12094 + cpg.bsrc = cpg.bdst;
12096 + if (dbstart <= cpg.bdst /* just reopen */
12097 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12099 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12100 + if (IS_ERR(h_file))
12101 + err = PTR_ERR(h_file);
12103 + di_downgrade_lock(parent, AuLock_IR);
12104 + if (dbstart > cpg.bdst)
12105 + err = au_sio_cpup_simple(&cpg);
12107 + err = au_reopen_nondir(file);
12108 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12110 + } else { /* copyup as wh and reopen */
12112 + * since writable hfsplus branch is not supported,
12113 + * h_open_pre/post() are unnecessary.
12115 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12116 + di_downgrade_lock(parent, AuLock_IR);
12120 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12121 + goto out_dput; /* success */
12127 + di_downgrade_lock(parent, AuLock_IR);
12129 + di_read_unlock(parent, AuLock_IR);
12136 +/* ---------------------------------------------------------------------- */
12138 +int au_do_flush(struct file *file, fl_owner_t id,
12139 + int (*flush)(struct file *file, fl_owner_t id))
12142 + struct super_block *sb;
12143 + struct inode *inode;
12145 + inode = file_inode(file);
12146 + sb = inode->i_sb;
12147 + si_noflush_read_lock(sb);
12148 + fi_read_lock(file);
12149 + ii_read_lock_child(inode);
12151 + err = flush(file, id);
12152 + au_cpup_attr_timesizes(inode);
12154 + ii_read_unlock(inode);
12155 + fi_read_unlock(file);
12156 + si_read_unlock(sb);
12160 +/* ---------------------------------------------------------------------- */
12162 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12165 + struct au_pin pin;
12166 + struct au_finfo *finfo;
12167 + struct dentry *parent, *hi_wh;
12168 + struct inode *inode;
12169 + struct super_block *sb;
12170 + struct au_cp_generic cpg = {
12171 + .dentry = file->f_path.dentry,
12176 + .flags = AuCpup_DTIME
12179 + FiMustWriteLock(file);
12182 + finfo = au_fi(file);
12183 + sb = cpg.dentry->d_sb;
12184 + inode = cpg.dentry->d_inode;
12185 + cpg.bdst = au_ibstart(inode);
12186 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12189 + parent = dget_parent(cpg.dentry);
12190 + if (au_test_ro(sb, cpg.bdst, inode)) {
12191 + di_read_lock_parent(parent, !AuLock_IR);
12192 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12194 + di_read_unlock(parent, !AuLock_IR);
12195 + if (unlikely(err < 0))
12200 + di_read_lock_parent(parent, AuLock_IR);
12201 + hi_wh = au_hi_wh(inode, cpg.bdst);
12202 + if (!S_ISDIR(inode->i_mode)
12203 + && au_opt_test(au_mntflags(sb), PLINK)
12204 + && au_plink_test(inode)
12205 + && !d_unhashed(cpg.dentry)
12206 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12207 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12208 + if (unlikely(err))
12211 + /* always superio. */
12212 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12213 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12215 + err = au_sio_cpup_simple(&cpg);
12218 + } else if (hi_wh) {
12219 + /* already copied-up after unlink */
12220 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12221 + *need_reopen = 0;
12225 + di_read_unlock(parent, AuLock_IR);
12232 +static void au_do_refresh_dir(struct file *file)
12234 + aufs_bindex_t bindex, bend, new_bindex, brid;
12235 + struct au_hfile *p, tmp, *q;
12236 + struct au_finfo *finfo;
12237 + struct super_block *sb;
12238 + struct au_fidir *fidir;
12240 + FiMustWriteLock(file);
12242 + sb = file->f_path.dentry->d_sb;
12243 + finfo = au_fi(file);
12244 + fidir = finfo->fi_hdir;
12245 + AuDebugOn(!fidir);
12246 + p = fidir->fd_hfile + finfo->fi_btop;
12247 + brid = p->hf_br->br_id;
12248 + bend = fidir->fd_bbot;
12249 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12253 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12254 + if (new_bindex == bindex)
12256 + if (new_bindex < 0) {
12257 + au_set_h_fptr(file, bindex, NULL);
12261 + /* swap two lower inode, and loop again */
12262 + q = fidir->fd_hfile + new_bindex;
12266 + if (tmp.hf_file) {
12272 + p = fidir->fd_hfile;
12273 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12274 + bend = au_sbend(sb);
12275 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12276 + finfo->fi_btop++, p++)
12277 + if (p->hf_file) {
12278 + if (file_inode(p->hf_file))
12280 + au_hfput(p, file);
12283 + bend = au_br_index(sb, brid);
12284 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12285 + finfo->fi_btop++, p++)
12287 + au_hfput(p, file);
12288 + bend = au_sbend(sb);
12291 + p = fidir->fd_hfile + bend;
12292 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12293 + fidir->fd_bbot--, p--)
12294 + if (p->hf_file) {
12295 + if (file_inode(p->hf_file))
12297 + au_hfput(p, file);
12299 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12303 + * after branch manipulating, refresh the file.
12305 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12307 + int err, need_reopen;
12308 + aufs_bindex_t bend, bindex;
12309 + struct dentry *dentry;
12310 + struct au_finfo *finfo;
12311 + struct au_hfile *hfile;
12313 + dentry = file->f_path.dentry;
12314 + finfo = au_fi(file);
12315 + if (!finfo->fi_hdir) {
12316 + hfile = &finfo->fi_htop;
12317 + AuDebugOn(!hfile->hf_file);
12318 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12319 + AuDebugOn(bindex < 0);
12320 + if (bindex != finfo->fi_btop)
12321 + au_set_fbstart(file, bindex);
12323 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12324 + if (unlikely(err))
12326 + au_do_refresh_dir(file);
12331 + if (!au_test_mmapped(file))
12332 + err = au_file_refresh_by_inode(file, &need_reopen);
12333 + if (!err && need_reopen && !d_unlinked(dentry))
12334 + err = reopen(file);
12336 + au_update_figen(file);
12337 + goto out; /* success */
12340 + /* error, close all lower files */
12341 + if (finfo->fi_hdir) {
12342 + bend = au_fbend_dir(file);
12343 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12344 + au_set_h_fptr(file, bindex, NULL);
12351 +/* common function to regular file and dir */
12352 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12356 + unsigned int sigen, figen;
12357 + aufs_bindex_t bstart;
12358 + unsigned char pseudo_link;
12359 + struct dentry *dentry;
12360 + struct inode *inode;
12363 + dentry = file->f_path.dentry;
12364 + inode = dentry->d_inode;
12365 + sigen = au_sigen(dentry->d_sb);
12366 + fi_write_lock(file);
12367 + figen = au_figen(file);
12368 + di_write_lock_child(dentry);
12369 + bstart = au_dbstart(dentry);
12370 + pseudo_link = (bstart != au_ibstart(inode));
12371 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12373 + di_downgrade_lock(dentry, AuLock_IR);
12374 + fi_downgrade_lock(file);
12376 + goto out; /* success */
12379 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12380 + if (au_digen_test(dentry, sigen)) {
12381 + err = au_reval_dpath(dentry, sigen);
12382 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12386 + err = refresh_file(file, reopen);
12389 + di_downgrade_lock(dentry, AuLock_IR);
12390 + fi_downgrade_lock(file);
12393 + di_write_unlock(dentry);
12394 + fi_write_unlock(file);
12401 +/* ---------------------------------------------------------------------- */
12403 +/* cf. aufs_nopage() */
12404 +/* for madvise(2) */
12405 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12407 + unlock_page(page);
12411 +/* it will never be called, but necessary to support O_DIRECT */
12412 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
12413 + struct iov_iter *iter, loff_t offset)
12414 +{ BUG(); return 0; }
12416 +/* they will never be called. */
12417 +#ifdef CONFIG_AUFS_DEBUG
12418 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12419 + loff_t pos, unsigned len, unsigned flags,
12420 + struct page **pagep, void **fsdata)
12421 +{ AuUnsupport(); return 0; }
12422 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12423 + loff_t pos, unsigned len, unsigned copied,
12424 + struct page *page, void *fsdata)
12425 +{ AuUnsupport(); return 0; }
12426 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12427 +{ AuUnsupport(); return 0; }
12429 +static int aufs_set_page_dirty(struct page *page)
12430 +{ AuUnsupport(); return 0; }
12431 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12432 + unsigned int length)
12433 +{ AuUnsupport(); }
12434 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12435 +{ AuUnsupport(); return 0; }
12436 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12437 + struct page *page, enum migrate_mode mode)
12438 +{ AuUnsupport(); return 0; }
12439 +static int aufs_launder_page(struct page *page)
12440 +{ AuUnsupport(); return 0; }
12441 +static int aufs_is_partially_uptodate(struct page *page,
12442 + unsigned long from,
12443 + unsigned long count)
12444 +{ AuUnsupport(); return 0; }
12445 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12447 +{ AuUnsupport(); }
12448 +static int aufs_error_remove_page(struct address_space *mapping,
12449 + struct page *page)
12450 +{ AuUnsupport(); return 0; }
12451 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12453 +{ AuUnsupport(); return 0; }
12454 +static void aufs_swap_deactivate(struct file *file)
12455 +{ AuUnsupport(); }
12456 +#endif /* CONFIG_AUFS_DEBUG */
12458 +const struct address_space_operations aufs_aop = {
12459 + .readpage = aufs_readpage,
12460 + .direct_IO = aufs_direct_IO,
12461 +#ifdef CONFIG_AUFS_DEBUG
12462 + .writepage = aufs_writepage,
12463 + /* no writepages, because of writepage */
12464 + .set_page_dirty = aufs_set_page_dirty,
12465 + /* no readpages, because of readpage */
12466 + .write_begin = aufs_write_begin,
12467 + .write_end = aufs_write_end,
12468 + /* no bmap, no block device */
12469 + .invalidatepage = aufs_invalidatepage,
12470 + .releasepage = aufs_releasepage,
12471 + .migratepage = aufs_migratepage,
12472 + .launder_page = aufs_launder_page,
12473 + .is_partially_uptodate = aufs_is_partially_uptodate,
12474 + .is_dirty_writeback = aufs_is_dirty_writeback,
12475 + .error_remove_page = aufs_error_remove_page,
12476 + .swap_activate = aufs_swap_activate,
12477 + .swap_deactivate = aufs_swap_deactivate
12478 +#endif /* CONFIG_AUFS_DEBUG */
12480 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12481 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12482 +++ linux/fs/aufs/file.h 2015-04-13 15:10:20.783490201 +0200
12485 + * Copyright (C) 2005-2015 Junjiro R. Okajima
12487 + * This program, aufs is free software; you can redistribute it and/or modify
12488 + * it under the terms of the GNU General Public License as published by
12489 + * the Free Software Foundation; either version 2 of the License, or
12490 + * (at your option) any later version.
12492 + * This program is distributed in the hope that it will be useful,
12493 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12494 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12495 + * GNU General Public License for more details.
12497 + * You should have received a copy of the GNU General Public License
12498 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12502 + * file operations
12505 +#ifndef __AUFS_FILE_H__
12506 +#define __AUFS_FILE_H__
12510 +#include <linux/file.h>
12511 +#include <linux/fs.h>
12512 +#include <linux/poll.h>
12513 +#include "rwsem.h"
12517 + struct file *hf_file;
12518 + struct au_branch *hf_br;
12523 + aufs_bindex_t fd_bbot;
12524 + aufs_bindex_t fd_nent;
12525 + struct au_vdir *fd_vdir_cache;
12526 + struct au_hfile fd_hfile[];
12529 +static inline int au_fidir_sz(int nent)
12531 + AuDebugOn(nent < 0);
12532 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12536 + atomic_t fi_generation;
12538 + struct au_rwsem fi_rwsem;
12539 + aufs_bindex_t fi_btop;
12541 + /* do not union them */
12542 + struct { /* for non-dir */
12543 + struct au_hfile fi_htop;
12544 + atomic_t fi_mmapped;
12546 + struct au_fidir *fi_hdir; /* for dir only */
12548 + struct hlist_node fi_hlist;
12549 + struct file *fi_file; /* very ugly */
12550 +} ____cacheline_aligned_in_smp;
12552 +/* ---------------------------------------------------------------------- */
12555 +extern const struct address_space_operations aufs_aop;
12556 +unsigned int au_file_roflags(unsigned int flags);
12557 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12558 + struct file *file, int force_wr);
12559 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
12560 + struct au_fidir *fidir);
12561 +int au_reopen_nondir(struct file *file);
12563 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12564 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12566 +int au_do_flush(struct file *file, fl_owner_t id,
12567 + int (*flush)(struct file *file, fl_owner_t id));
12570 +#ifdef CONFIG_AUFS_POLL
12571 +unsigned int aufs_poll(struct file *file, poll_table *wait);
12574 +#ifdef CONFIG_AUFS_BR_HFSPLUS
12576 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12578 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12579 + struct file *h_file);
12581 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
12582 + aufs_bindex_t bindex, int force_wr)
12583 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
12584 + struct file *h_file);
12588 +extern const struct file_operations aufs_file_fop;
12589 +int au_do_open_nondir(struct file *file, int flags);
12590 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
12593 +void au_hfput(struct au_hfile *hf, struct file *file);
12594 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
12595 + struct file *h_file);
12597 +void au_update_figen(struct file *file);
12598 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
12599 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
12601 +void au_fi_init_once(void *_fi);
12602 +void au_finfo_fin(struct file *file);
12603 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
12606 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
12607 +#ifdef CONFIG_COMPAT
12608 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
12609 + unsigned long arg);
12610 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
12611 + unsigned long arg);
12614 +/* ---------------------------------------------------------------------- */
12616 +static inline struct au_finfo *au_fi(struct file *file)
12618 + return file->private_data;
12621 +/* ---------------------------------------------------------------------- */
12624 + * fi_read_lock, fi_write_lock,
12625 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
12627 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
12629 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
12630 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
12631 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
12633 +/* ---------------------------------------------------------------------- */
12635 +/* todo: hard/soft set? */
12636 +static inline aufs_bindex_t au_fbstart(struct file *file)
12638 + FiMustAnyLock(file);
12639 + return au_fi(file)->fi_btop;
12642 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
12644 + FiMustAnyLock(file);
12645 + AuDebugOn(!au_fi(file)->fi_hdir);
12646 + return au_fi(file)->fi_hdir->fd_bbot;
12649 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
12651 + FiMustAnyLock(file);
12652 + AuDebugOn(!au_fi(file)->fi_hdir);
12653 + return au_fi(file)->fi_hdir->fd_vdir_cache;
12656 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
12658 + FiMustWriteLock(file);
12659 + au_fi(file)->fi_btop = bindex;
12662 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
12664 + FiMustWriteLock(file);
12665 + AuDebugOn(!au_fi(file)->fi_hdir);
12666 + au_fi(file)->fi_hdir->fd_bbot = bindex;
12669 +static inline void au_set_fvdir_cache(struct file *file,
12670 + struct au_vdir *vdir_cache)
12672 + FiMustWriteLock(file);
12673 + AuDebugOn(!au_fi(file)->fi_hdir);
12674 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
12677 +static inline struct file *au_hf_top(struct file *file)
12679 + FiMustAnyLock(file);
12680 + AuDebugOn(au_fi(file)->fi_hdir);
12681 + return au_fi(file)->fi_htop.hf_file;
12684 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
12686 + FiMustAnyLock(file);
12687 + AuDebugOn(!au_fi(file)->fi_hdir);
12688 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
12691 +/* todo: memory barrier? */
12692 +static inline unsigned int au_figen(struct file *f)
12694 + return atomic_read(&au_fi(f)->fi_generation);
12697 +static inline void au_set_mmapped(struct file *f)
12699 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
12701 + pr_warn("fi_mmapped wrapped around\n");
12702 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
12706 +static inline void au_unset_mmapped(struct file *f)
12708 + atomic_dec(&au_fi(f)->fi_mmapped);
12711 +static inline int au_test_mmapped(struct file *f)
12713 + return atomic_read(&au_fi(f)->fi_mmapped);
12716 +/* customize vma->vm_file */
12718 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
12719 + struct file *file)
12723 + f = vma->vm_file;
12725 + vma->vm_file = file;
12730 +#define AuDbgVmRegion(file, vma) do {} while (0)
12732 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12733 + struct file *file)
12735 + au_do_vm_file_reset(vma, file);
12738 +#define AuDbgVmRegion(file, vma) \
12739 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
12741 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12742 + struct file *file)
12746 + au_do_vm_file_reset(vma, file);
12747 + f = vma->vm_region->vm_file;
12749 + vma->vm_region->vm_file = file;
12752 +#endif /* CONFIG_MMU */
12754 +/* handle vma->vm_prfile */
12755 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
12756 + struct file *file)
12759 + vma->vm_prfile = file;
12760 +#ifndef CONFIG_MMU
12762 + vma->vm_region->vm_prfile = file;
12766 +#endif /* __KERNEL__ */
12767 +#endif /* __AUFS_FILE_H__ */
12768 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
12769 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
12770 +++ linux/fs/aufs/finfo.c 2015-04-13 15:10:20.783490201 +0200
12773 + * Copyright (C) 2005-2015 Junjiro R. Okajima
12775 + * This program, aufs is free software; you can redistribute it and/or modify
12776 + * it under the terms of the GNU General Public License as published by
12777 + * the Free Software Foundation; either version 2 of the License, or
12778 + * (at your option) any later version.
12780 + * This program is distributed in the hope that it will be useful,
12781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12783 + * GNU General Public License for more details.
12785 + * You should have received a copy of the GNU General Public License
12786 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12790 + * file private data
12795 +void au_hfput(struct au_hfile *hf, struct file *file)
12797 + /* todo: direct access f_flags */
12798 + if (vfsub_file_flags(file) & __FMODE_EXEC)
12799 + allow_write_access(hf->hf_file);
12800 + fput(hf->hf_file);
12801 + hf->hf_file = NULL;
12802 + atomic_dec(&hf->hf_br->br_count);
12803 + hf->hf_br = NULL;
12806 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
12808 + struct au_finfo *finfo = au_fi(file);
12809 + struct au_hfile *hf;
12810 + struct au_fidir *fidir;
12812 + fidir = finfo->fi_hdir;
12814 + AuDebugOn(finfo->fi_btop != bindex);
12815 + hf = &finfo->fi_htop;
12817 + hf = fidir->fd_hfile + bindex;
12819 + if (hf && hf->hf_file)
12820 + au_hfput(hf, file);
12822 + FiMustWriteLock(file);
12823 + hf->hf_file = val;
12824 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
12828 +void au_update_figen(struct file *file)
12830 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
12831 + /* smp_mb(); */ /* atomic_set */
12834 +/* ---------------------------------------------------------------------- */
12836 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
12838 + struct au_fidir *fidir;
12841 + nbr = au_sbend(sb) + 1;
12843 + nbr = 2; /* initial allocate for 2 branches */
12844 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
12846 + fidir->fd_bbot = -1;
12847 + fidir->fd_nent = nbr;
12848 + fidir->fd_vdir_cache = NULL;
12854 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
12857 + struct au_fidir *fidir, *p;
12859 + AuRwMustWriteLock(&finfo->fi_rwsem);
12860 + fidir = finfo->fi_hdir;
12861 + AuDebugOn(!fidir);
12864 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
12867 + p->fd_nent = nbr;
12868 + finfo->fi_hdir = p;
12875 +/* ---------------------------------------------------------------------- */
12877 +void au_finfo_fin(struct file *file)
12879 + struct au_finfo *finfo;
12881 + au_nfiles_dec(file->f_path.dentry->d_sb);
12883 + finfo = au_fi(file);
12884 + AuDebugOn(finfo->fi_hdir);
12885 + AuRwDestroy(&finfo->fi_rwsem);
12886 + au_cache_free_finfo(finfo);
12889 +void au_fi_init_once(void *_finfo)
12891 + struct au_finfo *finfo = _finfo;
12892 + static struct lock_class_key aufs_fi;
12894 + au_rw_init(&finfo->fi_rwsem);
12895 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
12898 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
12901 + struct au_finfo *finfo;
12902 + struct dentry *dentry;
12905 + dentry = file->f_path.dentry;
12906 + finfo = au_cache_alloc_finfo();
12907 + if (unlikely(!finfo))
12911 + au_nfiles_inc(dentry->d_sb);
12912 + /* verbose coding for lock class name */
12914 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
12916 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
12917 + au_rw_write_lock(&finfo->fi_rwsem);
12918 + finfo->fi_btop = -1;
12919 + finfo->fi_hdir = fidir;
12920 + atomic_set(&finfo->fi_generation, au_digen(dentry));
12921 + /* smp_mb(); */ /* atomic_set */
12923 + file->private_data = finfo;
12928 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
12929 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
12930 +++ linux/fs/aufs/f_op.c 2015-04-13 15:10:20.783490201 +0200
12933 + * Copyright (C) 2005-2015 Junjiro R. Okajima
12935 + * This program, aufs is free software; you can redistribute it and/or modify
12936 + * it under the terms of the GNU General Public License as published by
12937 + * the Free Software Foundation; either version 2 of the License, or
12938 + * (at your option) any later version.
12940 + * This program is distributed in the hope that it will be useful,
12941 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12942 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12943 + * GNU General Public License for more details.
12945 + * You should have received a copy of the GNU General Public License
12946 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12950 + * file and vm operations
12953 +#include <linux/aio.h>
12954 +#include <linux/fs_stack.h>
12955 +#include <linux/mman.h>
12956 +#include <linux/security.h>
12959 +int au_do_open_nondir(struct file *file, int flags)
12962 + aufs_bindex_t bindex;
12963 + struct file *h_file;
12964 + struct dentry *dentry;
12965 + struct au_finfo *finfo;
12966 + struct inode *h_inode;
12968 + FiMustWriteLock(file);
12971 + dentry = file->f_path.dentry;
12972 + finfo = au_fi(file);
12973 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
12974 + atomic_set(&finfo->fi_mmapped, 0);
12975 + bindex = au_dbstart(dentry);
12976 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
12977 + if (IS_ERR(h_file))
12978 + err = PTR_ERR(h_file);
12980 + if ((flags & __O_TMPFILE)
12981 + && !(flags & O_EXCL)) {
12982 + h_inode = file_inode(h_file);
12983 + spin_lock(&h_inode->i_lock);
12984 + h_inode->i_state |= I_LINKABLE;
12985 + spin_unlock(&h_inode->i_lock);
12987 + au_set_fbstart(file, bindex);
12988 + au_set_h_fptr(file, bindex, h_file);
12989 + au_update_figen(file);
12990 + /* todo: necessary? */
12991 + /* file->f_ra = h_file->f_ra; */
12997 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
12998 + struct file *file)
13001 + struct super_block *sb;
13003 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13004 + file, vfsub_file_flags(file), file->f_mode);
13006 + sb = file->f_path.dentry->d_sb;
13007 + si_read_lock(sb, AuLock_FLUSH);
13008 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
13009 + si_read_unlock(sb);
13013 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13015 + struct au_finfo *finfo;
13016 + aufs_bindex_t bindex;
13018 + finfo = au_fi(file);
13019 + au_sphl_del(&finfo->fi_hlist,
13020 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13021 + bindex = finfo->fi_btop;
13023 + au_set_h_fptr(file, bindex, NULL);
13025 + au_finfo_fin(file);
13029 +/* ---------------------------------------------------------------------- */
13031 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13034 + struct file *h_file;
13037 + h_file = au_hf_top(file);
13039 + err = vfsub_flush(h_file, id);
13043 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13045 + return au_do_flush(file, id, au_do_flush_nondir);
13048 +/* ---------------------------------------------------------------------- */
13050 + * read and write functions acquire [fdi]_rwsem once, but release before
13051 + * mmap_sem. This is because to stop a race condition between mmap(2).
13052 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13053 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13054 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13057 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13061 + struct dentry *dentry;
13062 + struct file *h_file;
13063 + struct super_block *sb;
13065 + dentry = file->f_path.dentry;
13066 + sb = dentry->d_sb;
13067 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13068 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13069 + if (unlikely(err))
13072 + h_file = au_hf_top(file);
13073 + get_file(h_file);
13074 + di_read_unlock(dentry, AuLock_IR);
13075 + fi_read_unlock(file);
13077 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13078 + err = vfsub_read_u(h_file, buf, count, ppos);
13079 + /* todo: necessary? */
13080 + /* file->f_ra = h_file->f_ra; */
13081 + /* update without lock, I don't think it a problem */
13082 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13086 + si_read_unlock(sb);
13091 + * todo: very ugly
13092 + * it locks both of i_mutex and si_rwsem for read in safe.
13093 + * if the plink maintenance mode continues forever (that is the problem),
13094 + * may loop forever.
13096 +static void au_mtx_and_read_lock(struct inode *inode)
13099 + struct super_block *sb = inode->i_sb;
13102 + mutex_lock(&inode->i_mutex);
13103 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13106 + mutex_unlock(&inode->i_mutex);
13107 + si_read_lock(sb, AuLock_NOPLMW);
13108 + si_read_unlock(sb);
13112 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13113 + size_t count, loff_t *ppos)
13117 + aufs_bindex_t bstart;
13118 + struct au_pin pin;
13119 + struct dentry *dentry;
13120 + struct inode *inode, *h_inode;
13121 + struct super_block *sb;
13122 + struct file *h_file;
13123 + char __user *buf = (char __user *)ubuf;
13125 + dentry = file->f_path.dentry;
13126 + sb = dentry->d_sb;
13127 + inode = dentry->d_inode;
13128 + au_mtx_and_read_lock(inode);
13130 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13131 + if (unlikely(err))
13134 + err = au_ready_to_write(file, -1, &pin);
13135 + di_downgrade_lock(dentry, AuLock_IR);
13136 + if (unlikely(err)) {
13137 + di_read_unlock(dentry, AuLock_IR);
13138 + fi_write_unlock(file);
13142 + bstart = au_fbstart(file);
13143 + h_file = au_hf_top(file);
13144 + get_file(h_file);
13145 + h_inode = file_inode(h_file);
13146 + blks = h_inode->i_blocks;
13148 + di_read_unlock(dentry, AuLock_IR);
13149 + fi_write_unlock(file);
13151 + err = vfsub_write_u(h_file, buf, count, ppos);
13152 + ii_write_lock_child(inode);
13153 + au_cpup_attr_timesizes(inode);
13154 + inode->i_mode = file_inode(h_file)->i_mode;
13155 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13157 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13158 + ii_write_unlock(inode);
13162 + si_read_unlock(sb);
13163 + mutex_unlock(&inode->i_mutex);
13167 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13168 + struct iov_iter *iov_iter)
13171 + struct file *file;
13172 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13173 + ssize_t (*aio)(struct kiocb *, const struct iovec *, unsigned long,
13176 + err = security_file_permission(h_file, rw);
13177 + if (unlikely(err))
13183 + if (rw == MAY_READ) {
13184 + iter = h_file->f_op->read_iter;
13185 + aio = h_file->f_op->aio_read;
13186 + } else if (rw == MAY_WRITE) {
13187 + iter = h_file->f_op->write_iter;
13188 + aio = h_file->f_op->aio_write;
13191 + file = kio->ki_filp;
13192 + kio->ki_filp = h_file;
13195 + err = iter(kio, iov_iter);
13197 + } else if (aio) {
13199 + err = aio(kio, iov_iter->iov, iov_iter->nr_segs, kio->ki_pos);
13202 + /* currently there is no such fs */
13204 + kio->ki_filp = file;
13210 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13213 + struct file *file, *h_file;
13214 + struct dentry *dentry;
13215 + struct super_block *sb;
13217 + file = kio->ki_filp;
13218 + dentry = file->f_path.dentry;
13219 + sb = dentry->d_sb;
13220 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13221 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13222 + if (unlikely(err))
13225 + h_file = au_hf_top(file);
13226 + get_file(h_file);
13227 + di_read_unlock(dentry, AuLock_IR);
13228 + fi_read_unlock(file);
13230 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13231 + /* todo: necessary? */
13232 + /* file->f_ra = h_file->f_ra; */
13233 + /* update without lock, I don't think it a problem */
13234 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13238 + si_read_unlock(sb);
13242 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13246 + aufs_bindex_t bstart;
13247 + struct au_pin pin;
13248 + struct dentry *dentry;
13249 + struct inode *inode, *h_inode;
13250 + struct file *file, *h_file;
13251 + struct super_block *sb;
13253 + file = kio->ki_filp;
13254 + dentry = file->f_path.dentry;
13255 + sb = dentry->d_sb;
13256 + inode = dentry->d_inode;
13257 + au_mtx_and_read_lock(inode);
13259 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13260 + if (unlikely(err))
13263 + err = au_ready_to_write(file, -1, &pin);
13264 + di_downgrade_lock(dentry, AuLock_IR);
13265 + if (unlikely(err)) {
13266 + di_read_unlock(dentry, AuLock_IR);
13267 + fi_write_unlock(file);
13271 + bstart = au_fbstart(file);
13272 + h_file = au_hf_top(file);
13273 + get_file(h_file);
13274 + h_inode = file_inode(h_file);
13275 + blks = h_inode->i_blocks;
13277 + di_read_unlock(dentry, AuLock_IR);
13278 + fi_write_unlock(file);
13280 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13281 + ii_write_lock_child(inode);
13282 + au_cpup_attr_timesizes(inode);
13283 + inode->i_mode = file_inode(h_file)->i_mode;
13284 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13286 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13287 + ii_write_unlock(inode);
13291 + si_read_unlock(sb);
13292 + mutex_unlock(&inode->i_mutex);
13296 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13297 + struct pipe_inode_info *pipe, size_t len,
13298 + unsigned int flags)
13301 + struct file *h_file;
13302 + struct dentry *dentry;
13303 + struct super_block *sb;
13305 + dentry = file->f_path.dentry;
13306 + sb = dentry->d_sb;
13307 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13308 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13309 + if (unlikely(err))
13313 + h_file = au_hf_top(file);
13314 + get_file(h_file);
13315 + if (au_test_loopback_kthread()) {
13316 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13317 + if (file->f_mapping != h_file->f_mapping) {
13318 + file->f_mapping = h_file->f_mapping;
13319 + smp_mb(); /* unnecessary? */
13322 + di_read_unlock(dentry, AuLock_IR);
13323 + fi_read_unlock(file);
13325 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13326 + /* todo: necessasry? */
13327 + /* file->f_ra = h_file->f_ra; */
13328 + /* update without lock, I don't think it a problem */
13329 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13333 + si_read_unlock(sb);
13338 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13339 + size_t len, unsigned int flags)
13343 + aufs_bindex_t bstart;
13344 + struct au_pin pin;
13345 + struct dentry *dentry;
13346 + struct inode *inode, *h_inode;
13347 + struct super_block *sb;
13348 + struct file *h_file;
13350 + dentry = file->f_path.dentry;
13351 + sb = dentry->d_sb;
13352 + inode = dentry->d_inode;
13353 + au_mtx_and_read_lock(inode);
13355 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13356 + if (unlikely(err))
13359 + err = au_ready_to_write(file, -1, &pin);
13360 + di_downgrade_lock(dentry, AuLock_IR);
13361 + if (unlikely(err)) {
13362 + di_read_unlock(dentry, AuLock_IR);
13363 + fi_write_unlock(file);
13367 + bstart = au_fbstart(file);
13368 + h_file = au_hf_top(file);
13369 + get_file(h_file);
13370 + h_inode = file_inode(h_file);
13371 + blks = h_inode->i_blocks;
13373 + di_read_unlock(dentry, AuLock_IR);
13374 + fi_write_unlock(file);
13376 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13377 + ii_write_lock_child(inode);
13378 + au_cpup_attr_timesizes(inode);
13379 + inode->i_mode = file_inode(h_file)->i_mode;
13380 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13382 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13383 + ii_write_unlock(inode);
13387 + si_read_unlock(sb);
13388 + mutex_unlock(&inode->i_mutex);
13392 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13396 + struct au_pin pin;
13397 + struct dentry *dentry;
13398 + struct super_block *sb;
13399 + struct inode *inode;
13400 + struct file *h_file;
13402 + dentry = file->f_path.dentry;
13403 + sb = dentry->d_sb;
13404 + inode = dentry->d_inode;
13405 + au_mtx_and_read_lock(inode);
13407 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13408 + if (unlikely(err))
13411 + err = au_ready_to_write(file, -1, &pin);
13412 + di_downgrade_lock(dentry, AuLock_IR);
13413 + if (unlikely(err)) {
13414 + di_read_unlock(dentry, AuLock_IR);
13415 + fi_write_unlock(file);
13419 + h_file = au_hf_top(file);
13420 + get_file(h_file);
13422 + di_read_unlock(dentry, AuLock_IR);
13423 + fi_write_unlock(file);
13426 + err = vfs_fallocate(h_file, mode, offset, len);
13428 + ii_write_lock_child(inode);
13429 + au_cpup_attr_timesizes(inode);
13430 + inode->i_mode = file_inode(h_file)->i_mode;
13431 + ii_write_unlock(inode);
13435 + si_read_unlock(sb);
13436 + mutex_unlock(&inode->i_mutex);
13440 +/* ---------------------------------------------------------------------- */
13443 + * The locking order around current->mmap_sem.
13444 + * - in most and regular cases
13445 + * file I/O syscall -- aufs_read() or something
13446 + * -- si_rwsem for read -- mmap_sem
13447 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13449 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13450 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13451 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13452 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13453 + * It means that when aufs acquires si_rwsem for write, the process should never
13454 + * acquire mmap_sem.
13456 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13457 + * problem either since any directory is not able to be mmap-ed.
13458 + * The similar scenario is applied to aufs_readlink() too.
13461 +#if 0 /* stop calling security_file_mmap() */
13462 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13463 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13465 +static unsigned long au_arch_prot_conv(unsigned long flags)
13467 + /* currently ppc64 only */
13468 +#ifdef CONFIG_PPC64
13469 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13470 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13471 + return AuConv_VM_PROT(flags, SAO);
13473 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13478 +static unsigned long au_prot_conv(unsigned long flags)
13480 + return AuConv_VM_PROT(flags, READ)
13481 + | AuConv_VM_PROT(flags, WRITE)
13482 + | AuConv_VM_PROT(flags, EXEC)
13483 + | au_arch_prot_conv(flags);
13486 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13487 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13489 +static unsigned long au_flag_conv(unsigned long flags)
13491 + return AuConv_VM_MAP(flags, GROWSDOWN)
13492 + | AuConv_VM_MAP(flags, DENYWRITE)
13493 + | AuConv_VM_MAP(flags, LOCKED);
13497 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13500 + aufs_bindex_t bstart;
13501 + const unsigned char wlock
13502 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13503 + struct dentry *dentry;
13504 + struct super_block *sb;
13505 + struct file *h_file;
13506 + struct au_branch *br;
13507 + struct au_pin pin;
13509 + AuDbgVmRegion(file, vma);
13511 + dentry = file->f_path.dentry;
13512 + sb = dentry->d_sb;
13514 + si_read_lock(sb, AuLock_NOPLMW);
13515 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13516 + if (unlikely(err))
13520 + err = au_ready_to_write(file, -1, &pin);
13521 + di_write_unlock(dentry);
13522 + if (unlikely(err)) {
13523 + fi_write_unlock(file);
13528 + di_write_unlock(dentry);
13530 + bstart = au_fbstart(file);
13531 + br = au_sbr(sb, bstart);
13532 + h_file = au_hf_top(file);
13533 + get_file(h_file);
13534 + au_set_mmapped(file);
13535 + fi_write_unlock(file);
13538 + au_vm_file_reset(vma, h_file);
13540 + * we cannot call security_mmap_file() here since it may acquire
13541 + * mmap_sem or i_mutex.
13543 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13544 + * au_flag_conv(vma->vm_flags));
13547 + err = h_file->f_op->mmap(h_file, vma);
13548 + if (unlikely(err))
13551 + au_vm_prfile_set(vma, file);
13552 + /* update without lock, I don't think it a problem */
13553 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
13554 + goto out_fput; /* success */
13557 + au_unset_mmapped(file);
13558 + au_vm_file_reset(vma, file);
13563 + si_read_unlock(sb);
13569 +/* ---------------------------------------------------------------------- */
13571 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13575 + struct au_pin pin;
13576 + struct dentry *dentry;
13577 + struct inode *inode;
13578 + struct file *h_file;
13579 + struct super_block *sb;
13581 + dentry = file->f_path.dentry;
13582 + inode = dentry->d_inode;
13583 + sb = dentry->d_sb;
13584 + mutex_lock(&inode->i_mutex);
13585 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13586 + if (unlikely(err))
13589 + err = 0; /* -EBADF; */ /* posix? */
13590 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13592 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13593 + if (unlikely(err))
13596 + err = au_ready_to_write(file, -1, &pin);
13597 + di_downgrade_lock(dentry, AuLock_IR);
13598 + if (unlikely(err))
13603 + h_file = au_hf_top(file);
13604 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13605 + au_cpup_attr_timesizes(inode);
13608 + di_read_unlock(dentry, AuLock_IR);
13609 + fi_write_unlock(file);
13611 + si_read_unlock(sb);
13613 + mutex_unlock(&inode->i_mutex);
13617 +/* no one supports this operation, currently */
13619 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13622 + struct au_pin pin;
13623 + struct dentry *dentry;
13624 + struct inode *inode;
13625 + struct file *file, *h_file;
13627 + file = kio->ki_filp;
13628 + dentry = file->f_path.dentry;
13629 + inode = dentry->d_inode;
13630 + au_mtx_and_read_lock(inode);
13632 + err = 0; /* -EBADF; */ /* posix? */
13633 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13635 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13636 + if (unlikely(err))
13639 + err = au_ready_to_write(file, -1, &pin);
13640 + di_downgrade_lock(dentry, AuLock_IR);
13641 + if (unlikely(err))
13646 + h_file = au_hf_top(file);
13647 + if (h_file->f_op->aio_fsync) {
13648 + struct mutex *h_mtx;
13650 + h_mtx = &file_inode(h_file)->i_mutex;
13651 + if (!is_sync_kiocb(kio)) {
13652 + get_file(h_file);
13655 + kio->ki_filp = h_file;
13656 + err = h_file->f_op->aio_fsync(kio, datasync);
13657 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13659 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
13661 + au_cpup_attr_timesizes(inode);
13662 + mutex_unlock(h_mtx);
13666 + di_read_unlock(dentry, AuLock_IR);
13667 + fi_write_unlock(file);
13669 + si_read_unlock(inode->sb);
13670 + mutex_unlock(&inode->i_mutex);
13675 +static int aufs_fasync(int fd, struct file *file, int flag)
13678 + struct file *h_file;
13679 + struct dentry *dentry;
13680 + struct super_block *sb;
13682 + dentry = file->f_path.dentry;
13683 + sb = dentry->d_sb;
13684 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13685 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13686 + if (unlikely(err))
13689 + h_file = au_hf_top(file);
13690 + if (h_file->f_op->fasync)
13691 + err = h_file->f_op->fasync(fd, h_file, flag);
13693 + di_read_unlock(dentry, AuLock_IR);
13694 + fi_read_unlock(file);
13697 + si_read_unlock(sb);
13701 +/* ---------------------------------------------------------------------- */
13703 +/* no one supports this operation, currently */
13705 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
13706 + size_t len, loff_t *pos, int more)
13711 +/* ---------------------------------------------------------------------- */
13713 +const struct file_operations aufs_file_fop = {
13714 + .owner = THIS_MODULE,
13716 + .llseek = default_llseek,
13718 + .read = aufs_read,
13719 + .write = aufs_write,
13720 + .read_iter = aufs_read_iter,
13721 + .write_iter = aufs_write_iter,
13723 +#ifdef CONFIG_AUFS_POLL
13724 + .poll = aufs_poll,
13726 + .unlocked_ioctl = aufs_ioctl_nondir,
13727 +#ifdef CONFIG_COMPAT
13728 + .compat_ioctl = aufs_compat_ioctl_nondir,
13730 + .mmap = aufs_mmap,
13731 + .open = aufs_open_nondir,
13732 + .flush = aufs_flush_nondir,
13733 + .release = aufs_release_nondir,
13734 + .fsync = aufs_fsync_nondir,
13735 + /* .aio_fsync = aufs_aio_fsync_nondir, */
13736 + .fasync = aufs_fasync,
13737 + /* .sendpage = aufs_sendpage, */
13738 + .splice_write = aufs_splice_write,
13739 + .splice_read = aufs_splice_read,
13741 + .aio_splice_write = aufs_aio_splice_write,
13742 + .aio_splice_read = aufs_aio_splice_read,
13744 + .fallocate = aufs_fallocate
13746 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13747 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13748 +++ linux/fs/aufs/fstype.h 2015-04-13 15:10:20.783490201 +0200
13751 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13753 + * This program, aufs is free software; you can redistribute it and/or modify
13754 + * it under the terms of the GNU General Public License as published by
13755 + * the Free Software Foundation; either version 2 of the License, or
13756 + * (at your option) any later version.
13758 + * This program is distributed in the hope that it will be useful,
13759 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13760 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13761 + * GNU General Public License for more details.
13763 + * You should have received a copy of the GNU General Public License
13764 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13768 + * judging filesystem type
13771 +#ifndef __AUFS_FSTYPE_H__
13772 +#define __AUFS_FSTYPE_H__
13776 +#include <linux/fs.h>
13777 +#include <linux/magic.h>
13778 +#include <linux/romfs_fs.h>
13780 +static inline int au_test_aufs(struct super_block *sb)
13782 + return sb->s_magic == AUFS_SUPER_MAGIC;
13785 +static inline const char *au_sbtype(struct super_block *sb)
13787 + return sb->s_type->name;
13790 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
13792 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
13793 + return sb->s_magic == ISOFS_SUPER_MAGIC;
13799 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
13801 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
13802 + return sb->s_magic == ROMFS_MAGIC;
13808 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
13810 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
13811 + return sb->s_magic == CRAMFS_MAGIC;
13816 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
13818 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
13819 + return sb->s_magic == NFS_SUPER_MAGIC;
13825 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
13827 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
13828 + return sb->s_magic == FUSE_SUPER_MAGIC;
13834 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
13836 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
13837 + return sb->s_magic == XFS_SB_MAGIC;
13843 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
13845 +#ifdef CONFIG_TMPFS
13846 + return sb->s_magic == TMPFS_MAGIC;
13852 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
13854 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
13855 + return !strcmp(au_sbtype(sb), "ecryptfs");
13861 +static inline int au_test_ramfs(struct super_block *sb)
13863 + return sb->s_magic == RAMFS_MAGIC;
13866 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
13868 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
13869 + return sb->s_magic == UBIFS_SUPER_MAGIC;
13875 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
13877 +#ifdef CONFIG_PROC_FS
13878 + return sb->s_magic == PROC_SUPER_MAGIC;
13884 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
13886 +#ifdef CONFIG_SYSFS
13887 + return sb->s_magic == SYSFS_MAGIC;
13893 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
13895 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
13896 + return sb->s_magic == CONFIGFS_MAGIC;
13902 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
13904 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
13905 + return sb->s_magic == MINIX3_SUPER_MAGIC
13906 + || sb->s_magic == MINIX2_SUPER_MAGIC
13907 + || sb->s_magic == MINIX2_SUPER_MAGIC2
13908 + || sb->s_magic == MINIX_SUPER_MAGIC
13909 + || sb->s_magic == MINIX_SUPER_MAGIC2;
13915 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
13917 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
13918 + return sb->s_magic == MSDOS_SUPER_MAGIC;
13924 +static inline int au_test_msdos(struct super_block *sb)
13926 + return au_test_fat(sb);
13929 +static inline int au_test_vfat(struct super_block *sb)
13931 + return au_test_fat(sb);
13934 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
13936 +#ifdef CONFIG_SECURITYFS
13937 + return sb->s_magic == SECURITYFS_MAGIC;
13943 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
13945 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
13946 + return sb->s_magic == SQUASHFS_MAGIC;
13952 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
13954 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
13955 + return sb->s_magic == BTRFS_SUPER_MAGIC;
13961 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
13963 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
13964 + return sb->s_magic == XENFS_SUPER_MAGIC;
13970 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
13972 +#ifdef CONFIG_DEBUG_FS
13973 + return sb->s_magic == DEBUGFS_MAGIC;
13979 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
13981 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
13982 + return sb->s_magic == NILFS_SUPER_MAGIC;
13988 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
13990 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
13991 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
13997 +/* ---------------------------------------------------------------------- */
13999 + * they can't be an aufs branch.
14001 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14004 +#ifndef CONFIG_AUFS_BR_RAMFS
14005 + au_test_ramfs(sb) ||
14007 + au_test_procfs(sb)
14008 + || au_test_sysfs(sb)
14009 + || au_test_configfs(sb)
14010 + || au_test_debugfs(sb)
14011 + || au_test_securityfs(sb)
14012 + || au_test_xenfs(sb)
14013 + || au_test_ecryptfs(sb)
14014 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14015 + || au_test_aufs(sb); /* will be supported in next version */
14018 +static inline int au_test_fs_remote(struct super_block *sb)
14020 + return !au_test_tmpfs(sb)
14021 +#ifdef CONFIG_AUFS_BR_RAMFS
14022 + && !au_test_ramfs(sb)
14024 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14027 +/* ---------------------------------------------------------------------- */
14030 + * Note: these functions (below) are created after reading ->getattr() in all
14031 + * filesystems under linux/fs. it means we have to do so in every update...
14035 + * some filesystems require getattr to refresh the inode attributes before
14037 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14038 + * and leave the work for d_revalidate()
14040 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14042 + return au_test_nfs(sb)
14043 + || au_test_fuse(sb)
14044 + /* || au_test_btrfs(sb) */ /* untested */
14049 + * filesystems which don't maintain i_size or i_blocks.
14051 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14053 + return au_test_xfs(sb)
14054 + || au_test_btrfs(sb)
14055 + || au_test_ubifs(sb)
14056 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14057 + /* || au_test_minix(sb) */ /* untested */
14062 + * filesystems which don't store the correct value in some of their inode
14065 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14067 + return au_test_fs_bad_iattr_size(sb)
14068 + || au_test_fat(sb)
14069 + || au_test_msdos(sb)
14070 + || au_test_vfat(sb);
14073 +/* they don't check i_nlink in link(2) */
14074 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14076 + return au_test_tmpfs(sb)
14077 +#ifdef CONFIG_AUFS_BR_RAMFS
14078 + || au_test_ramfs(sb)
14080 + || au_test_ubifs(sb)
14081 + || au_test_hfsplus(sb);
14085 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14087 +static inline int au_test_fs_notime(struct super_block *sb)
14089 + return au_test_nfs(sb)
14090 + || au_test_fuse(sb)
14091 + || au_test_ubifs(sb)
14095 +/* temporary support for i#1 in cramfs */
14096 +static inline int au_test_fs_unique_ino(struct inode *inode)
14098 + if (au_test_cramfs(inode->i_sb))
14099 + return inode->i_ino != 1;
14103 +/* ---------------------------------------------------------------------- */
14106 + * the filesystem where the xino files placed must support i/o after unlink and
14107 + * maintain i_size and i_blocks.
14109 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14111 + return au_test_fs_remote(sb)
14112 + || au_test_fs_bad_iattr_size(sb)
14113 + /* don't want unnecessary work for xino */
14114 + || au_test_aufs(sb)
14115 + || au_test_ecryptfs(sb)
14116 + || au_test_nilfs(sb);
14119 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14121 + return au_test_tmpfs(sb)
14122 + || au_test_ramfs(sb);
14126 + * test if the @sb is real-readonly.
14128 +static inline int au_test_fs_rr(struct super_block *sb)
14130 + return au_test_squashfs(sb)
14131 + || au_test_iso9660(sb)
14132 + || au_test_cramfs(sb)
14133 + || au_test_romfs(sb);
14136 +#endif /* __KERNEL__ */
14137 +#endif /* __AUFS_FSTYPE_H__ */
14138 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14139 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14140 +++ linux/fs/aufs/hfsnotify.c 2015-04-13 15:10:20.783490201 +0200
14143 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14145 + * This program, aufs is free software; you can redistribute it and/or modify
14146 + * it under the terms of the GNU General Public License as published by
14147 + * the Free Software Foundation; either version 2 of the License, or
14148 + * (at your option) any later version.
14150 + * This program is distributed in the hope that it will be useful,
14151 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14152 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14153 + * GNU General Public License for more details.
14155 + * You should have received a copy of the GNU General Public License
14156 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14160 + * fsnotify for the lower directories
14165 +/* FS_IN_IGNORED is unnecessary */
14166 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14167 + | FS_CREATE | FS_EVENT_ON_CHILD);
14168 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14169 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14171 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14173 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14176 + au_cache_free_hnotify(hn);
14177 + smp_mb__before_atomic();
14178 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14179 + wake_up(&au_hfsn_wq);
14182 +static int au_hfsn_alloc(struct au_hinode *hinode)
14185 + struct au_hnotify *hn;
14186 + struct super_block *sb;
14187 + struct au_branch *br;
14188 + struct fsnotify_mark *mark;
14189 + aufs_bindex_t bindex;
14191 + hn = hinode->hi_notify;
14192 + sb = hn->hn_aufs_inode->i_sb;
14193 + bindex = au_br_index(sb, hinode->hi_id);
14194 + br = au_sbr(sb, bindex);
14195 + AuDebugOn(!br->br_hfsn);
14197 + mark = &hn->hn_mark;
14198 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14199 + mark->mask = AuHfsnMask;
14201 + * by udba rename or rmdir, aufs assign a new inode to the known
14202 + * h_inode, so specify 1 to allow dups.
14205 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14206 + /*mnt*/NULL, /*allow_dups*/1);
14207 + /* even if err */
14208 + fsnotify_put_mark(mark);
14214 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14216 + struct fsnotify_mark *mark;
14217 + unsigned long long ull;
14218 + struct fsnotify_group *group;
14220 + ull = atomic64_inc_return(&au_hfsn_ifree);
14223 + mark = &hn->hn_mark;
14224 + spin_lock(&mark->lock);
14225 + group = mark->group;
14226 + fsnotify_get_group(group);
14227 + spin_unlock(&mark->lock);
14229 + fsnotify_destroy_mark(mark, group);
14230 + fsnotify_put_group(group);
14233 + /* free hn by myself */
14237 +/* ---------------------------------------------------------------------- */
14239 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14241 + struct fsnotify_mark *mark;
14243 + mark = &hinode->hi_notify->hn_mark;
14244 + spin_lock(&mark->lock);
14246 + AuDebugOn(mark->mask & AuHfsnMask);
14247 + mark->mask |= AuHfsnMask;
14249 + AuDebugOn(!(mark->mask & AuHfsnMask));
14250 + mark->mask &= ~AuHfsnMask;
14252 + spin_unlock(&mark->lock);
14253 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14256 +/* ---------------------------------------------------------------------- */
14258 +/* #define AuDbgHnotify */
14259 +#ifdef AuDbgHnotify
14260 +static char *au_hfsn_name(u32 mask)
14262 +#ifdef CONFIG_AUFS_DEBUG
14263 +#define test_ret(flag) \
14265 + if (mask & flag) \
14268 + test_ret(FS_ACCESS);
14269 + test_ret(FS_MODIFY);
14270 + test_ret(FS_ATTRIB);
14271 + test_ret(FS_CLOSE_WRITE);
14272 + test_ret(FS_CLOSE_NOWRITE);
14273 + test_ret(FS_OPEN);
14274 + test_ret(FS_MOVED_FROM);
14275 + test_ret(FS_MOVED_TO);
14276 + test_ret(FS_CREATE);
14277 + test_ret(FS_DELETE);
14278 + test_ret(FS_DELETE_SELF);
14279 + test_ret(FS_MOVE_SELF);
14280 + test_ret(FS_UNMOUNT);
14281 + test_ret(FS_Q_OVERFLOW);
14282 + test_ret(FS_IN_IGNORED);
14283 + test_ret(FS_IN_ISDIR);
14284 + test_ret(FS_IN_ONESHOT);
14285 + test_ret(FS_EVENT_ON_CHILD);
14294 +/* ---------------------------------------------------------------------- */
14296 +static void au_hfsn_free_group(struct fsnotify_group *group)
14298 + struct au_br_hfsnotify *hfsn = group->private;
14304 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14305 + struct inode *inode,
14306 + struct fsnotify_mark *inode_mark,
14307 + struct fsnotify_mark *vfsmount_mark,
14308 + u32 mask, void *data, int data_type,
14309 + const unsigned char *file_name, u32 cookie)
14312 + struct au_hnotify *hnotify;
14313 + struct inode *h_dir, *h_inode;
14314 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14316 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14319 + /* if FS_UNMOUNT happens, there must be another bug */
14320 + AuDebugOn(mask & FS_UNMOUNT);
14321 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14326 +#ifdef AuDbgHnotify
14328 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14329 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14330 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14331 + h_dir->i_ino, mask, au_hfsn_name(mask),
14332 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14333 + /* WARN_ON(1); */
14338 + AuDebugOn(!inode_mark);
14339 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14340 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14346 +static struct fsnotify_ops au_hfsn_ops = {
14347 + .handle_event = au_hfsn_handle_event,
14348 + .free_group_priv = au_hfsn_free_group
14351 +/* ---------------------------------------------------------------------- */
14353 +static void au_hfsn_fin_br(struct au_branch *br)
14355 + struct au_br_hfsnotify *hfsn;
14357 + hfsn = br->br_hfsn;
14360 + fsnotify_put_group(hfsn->hfsn_group);
14365 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14368 + struct fsnotify_group *group;
14369 + struct au_br_hfsnotify *hfsn;
14372 + br->br_hfsn = NULL;
14373 + if (!au_br_hnotifyable(perm))
14377 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14378 + if (unlikely(!hfsn))
14382 + group = fsnotify_alloc_group(&au_hfsn_ops);
14383 + if (IS_ERR(group)) {
14384 + err = PTR_ERR(group);
14385 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14389 + group->private = hfsn;
14390 + hfsn->hfsn_group = group;
14391 + br->br_hfsn = hfsn;
14392 + goto out; /* success */
14400 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14405 + if (!br->br_hfsn)
14406 + err = au_hfsn_init_br(br, perm);
14411 +/* ---------------------------------------------------------------------- */
14413 +static void au_hfsn_fin(void)
14415 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14416 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14419 +const struct au_hnotify_op au_hnotify_op = {
14420 + .ctl = au_hfsn_ctl,
14421 + .alloc = au_hfsn_alloc,
14422 + .free = au_hfsn_free,
14424 + .fin = au_hfsn_fin,
14426 + .reset_br = au_hfsn_reset_br,
14427 + .fin_br = au_hfsn_fin_br,
14428 + .init_br = au_hfsn_init_br
14430 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14431 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14432 +++ linux/fs/aufs/hfsplus.c 2015-04-13 15:10:20.783490201 +0200
14435 + * Copyright (C) 2010-2015 Junjiro R. Okajima
14437 + * This program, aufs is free software; you can redistribute it and/or modify
14438 + * it under the terms of the GNU General Public License as published by
14439 + * the Free Software Foundation; either version 2 of the License, or
14440 + * (at your option) any later version.
14442 + * This program is distributed in the hope that it will be useful,
14443 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14444 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14445 + * GNU General Public License for more details.
14447 + * You should have received a copy of the GNU General Public License
14448 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14452 + * special support for filesystems which aqucires an inode mutex
14453 + * at final closing a file, eg, hfsplus.
14455 + * This trick is very simple and stupid, just to open the file before really
14456 + * neceeary open to tell hfsplus that this is not the final closing.
14457 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14458 + * and au_h_open_post() after releasing it.
14463 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14466 + struct file *h_file;
14467 + struct dentry *h_dentry;
14469 + h_dentry = au_h_dptr(dentry, bindex);
14470 + AuDebugOn(!h_dentry);
14471 + AuDebugOn(!h_dentry->d_inode);
14474 + if (au_test_hfsplus(h_dentry->d_sb)
14475 + && d_is_reg(h_dentry))
14476 + h_file = au_h_open(dentry, bindex,
14477 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14478 + /*file*/NULL, force_wr);
14482 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14483 + struct file *h_file)
14487 + au_sbr_put(dentry->d_sb, bindex);
14490 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14491 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14492 +++ linux/fs/aufs/hnotify.c 2015-04-13 15:10:20.783490201 +0200
14495 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14497 + * This program, aufs is free software; you can redistribute it and/or modify
14498 + * it under the terms of the GNU General Public License as published by
14499 + * the Free Software Foundation; either version 2 of the License, or
14500 + * (at your option) any later version.
14502 + * This program is distributed in the hope that it will be useful,
14503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14505 + * GNU General Public License for more details.
14507 + * You should have received a copy of the GNU General Public License
14508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14512 + * abstraction to notify the direct changes on lower directories
14517 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14520 + struct au_hnotify *hn;
14523 + hn = au_cache_alloc_hnotify();
14525 + hn->hn_aufs_inode = inode;
14526 + hinode->hi_notify = hn;
14527 + err = au_hnotify_op.alloc(hinode);
14529 + if (unlikely(err)) {
14530 + hinode->hi_notify = NULL;
14531 + au_cache_free_hnotify(hn);
14533 + * The upper dir was removed by udba, but the same named
14534 + * dir left. In this case, aufs assignes a new inode
14535 + * number and set the monitor again.
14536 + * For the lower dir, the old monitnor is still left.
14538 + if (err == -EEXIST)
14547 +void au_hn_free(struct au_hinode *hinode)
14549 + struct au_hnotify *hn;
14551 + hn = hinode->hi_notify;
14553 + hinode->hi_notify = NULL;
14554 + if (au_hnotify_op.free(hinode, hn))
14555 + au_cache_free_hnotify(hn);
14559 +/* ---------------------------------------------------------------------- */
14561 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14563 + if (hinode->hi_notify)
14564 + au_hnotify_op.ctl(hinode, do_set);
14567 +void au_hn_reset(struct inode *inode, unsigned int flags)
14569 + aufs_bindex_t bindex, bend;
14570 + struct inode *hi;
14571 + struct dentry *iwhdentry;
14573 + bend = au_ibend(inode);
14574 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14575 + hi = au_h_iptr(inode, bindex);
14579 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14580 + iwhdentry = au_hi_wh(inode, bindex);
14584 + au_set_h_iptr(inode, bindex, NULL, 0);
14585 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14586 + flags & ~AuHi_XINO);
14589 + /* mutex_unlock(&hi->i_mutex); */
14593 +/* ---------------------------------------------------------------------- */
14595 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14598 + aufs_bindex_t bindex, bend, bfound, bstart;
14599 + struct inode *h_i;
14602 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14603 + pr_warn("branch root dir was changed\n");
14608 + bend = au_ibend(inode);
14609 + bstart = au_ibstart(inode);
14610 +#if 0 /* reserved for future use */
14611 + if (bindex == bend) {
14612 + /* keep this ino in rename case */
14616 + for (bindex = bstart; bindex <= bend; bindex++)
14617 + if (au_h_iptr(inode, bindex) == h_inode) {
14624 + for (bindex = bstart; bindex <= bend; bindex++) {
14625 + h_i = au_h_iptr(inode, bindex);
14629 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14630 + /* ignore this error */
14631 + /* bad action? */
14634 + /* children inode number will be broken */
14641 +static int hn_gen_tree(struct dentry *dentry)
14643 + int err, i, j, ndentry;
14644 + struct au_dcsub_pages dpages;
14645 + struct au_dpage *dpage;
14646 + struct dentry **dentries;
14648 + err = au_dpages_init(&dpages, GFP_NOFS);
14649 + if (unlikely(err))
14651 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14652 + if (unlikely(err))
14655 + for (i = 0; i < dpages.ndpage; i++) {
14656 + dpage = dpages.dpages + i;
14657 + dentries = dpage->dentries;
14658 + ndentry = dpage->ndentry;
14659 + for (j = 0; j < ndentry; j++) {
14660 + struct dentry *d;
14668 + /* todo: reset children xino?
14669 + cached children only? */
14670 + au_iigen_dec(d->d_inode);
14675 + au_dpages_free(&dpages);
14678 + /* discard children */
14679 + dentry_unhash(dentry);
14687 + * return 0 if processed.
14689 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14690 + const unsigned int isdir)
14693 + struct dentry *d;
14694 + struct qstr *dname;
14697 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14698 + pr_warn("branch root dir was changed\n");
14704 + AuDebugOn(!name);
14705 + au_iigen_dec(inode);
14706 + spin_lock(&inode->i_lock);
14707 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14708 + spin_lock(&d->d_lock);
14709 + dname = &d->d_name;
14710 + if (dname->len != nlen
14711 + && memcmp(dname->name, name, nlen)) {
14712 + spin_unlock(&d->d_lock);
14717 + spin_unlock(&d->d_lock);
14720 + spin_unlock(&inode->i_lock);
14722 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14723 + d = d_find_any_alias(inode);
14725 + au_iigen_dec(inode);
14729 + spin_lock(&d->d_lock);
14730 + dname = &d->d_name;
14731 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14732 + spin_unlock(&d->d_lock);
14733 + err = hn_gen_tree(d);
14734 + spin_lock(&d->d_lock);
14736 + spin_unlock(&d->d_lock);
14745 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
14748 + struct inode *inode;
14750 + inode = dentry->d_inode;
14751 + if (IS_ROOT(dentry)
14752 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
14754 + pr_warn("branch root dir was changed\n");
14760 + au_digen_dec(dentry);
14762 + au_iigen_dec(inode);
14764 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
14766 + err = hn_gen_tree(dentry);
14773 +/* ---------------------------------------------------------------------- */
14775 +/* hnotify job flags */
14776 +#define AuHnJob_XINO0 1
14777 +#define AuHnJob_GEN (1 << 1)
14778 +#define AuHnJob_DIRENT (1 << 2)
14779 +#define AuHnJob_ISDIR (1 << 3)
14780 +#define AuHnJob_TRYXINO0 (1 << 4)
14781 +#define AuHnJob_MNTPNT (1 << 5)
14782 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
14783 +#define au_fset_hnjob(flags, name) \
14784 + do { (flags) |= AuHnJob_##name; } while (0)
14785 +#define au_fclr_hnjob(flags, name) \
14786 + do { (flags) &= ~AuHnJob_##name; } while (0)
14794 +struct au_hnotify_args {
14795 + struct inode *h_dir, *dir, *h_child_inode;
14797 + unsigned int flags[AuHnLast];
14798 + unsigned int h_child_nlen;
14799 + char h_child_name[];
14802 +struct hn_job_args {
14803 + unsigned int flags;
14804 + struct inode *inode, *h_inode, *dir, *h_dir;
14805 + struct dentry *dentry;
14810 +static int hn_job(struct hn_job_args *a)
14812 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
14816 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
14817 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14819 + if (au_ftest_hnjob(a->flags, TRYXINO0)
14822 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
14823 + if (!a->h_inode->i_nlink
14824 + && !(a->h_inode->i_state & I_LINKABLE))
14825 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14826 + mutex_unlock(&a->h_inode->i_mutex);
14829 + /* make the generation obsolete */
14830 + if (au_ftest_hnjob(a->flags, GEN)) {
14833 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
14835 + if (e && a->dentry)
14836 + hn_gen_by_name(a->dentry, isdir);
14837 + /* ignore this error */
14840 + /* make dir entries obsolete */
14841 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
14842 + struct au_vdir *vdir;
14844 + vdir = au_ivdir(a->inode);
14846 + vdir->vd_jiffy = 0;
14847 + /* IMustLock(a->inode); */
14848 + /* a->inode->i_version++; */
14851 + /* can do nothing but warn */
14852 + if (au_ftest_hnjob(a->flags, MNTPNT)
14854 + && d_mountpoint(a->dentry))
14855 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
14860 +/* ---------------------------------------------------------------------- */
14862 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
14863 + struct inode *dir)
14865 + struct dentry *dentry, *d, *parent;
14866 + struct qstr *dname;
14868 + parent = d_find_any_alias(dir);
14873 + spin_lock(&parent->d_lock);
14874 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
14875 + /* AuDbg("%pd\n", d); */
14876 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
14877 + dname = &d->d_name;
14878 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
14879 + goto cont_unlock;
14883 + goto cont_unlock;
14884 + if (au_dcount(d) > 0) {
14885 + dentry = dget_dlock(d);
14886 + spin_unlock(&d->d_lock);
14891 + spin_unlock(&d->d_lock);
14893 + spin_unlock(&parent->d_lock);
14897 + di_write_lock_child(dentry);
14902 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
14903 + aufs_bindex_t bindex, ino_t h_ino)
14905 + struct inode *inode;
14910 + err = au_xino_read(sb, bindex, h_ino, &ino);
14912 + inode = ilookup(sb, ino);
14916 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14917 + pr_warn("wrong root branch\n");
14923 + ii_write_lock_child(inode);
14929 +static void au_hn_bh(void *_args)
14931 + struct au_hnotify_args *a = _args;
14932 + struct super_block *sb;
14933 + aufs_bindex_t bindex, bend, bfound;
14934 + unsigned char xino, try_iput;
14936 + struct inode *inode;
14938 + struct hn_job_args args;
14939 + struct dentry *dentry;
14940 + struct au_sbinfo *sbinfo;
14942 + AuDebugOn(!_args);
14943 + AuDebugOn(!a->h_dir);
14944 + AuDebugOn(!a->dir);
14945 + AuDebugOn(!a->mask);
14946 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
14947 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
14948 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
14953 + * do not lock a->dir->i_mutex here
14954 + * because of d_revalidate() may cause a deadlock.
14956 + sb = a->dir->i_sb;
14958 + sbinfo = au_sbi(sb);
14959 + AuDebugOn(!sbinfo);
14960 + si_write_lock(sb, AuLock_NOPLMW);
14962 + ii_read_lock_parent(a->dir);
14964 + bend = au_ibend(a->dir);
14965 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
14966 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
14970 + ii_read_unlock(a->dir);
14971 + if (unlikely(bfound < 0))
14974 + xino = !!au_opt_test(au_mntflags(sb), XINO);
14976 + if (a->h_child_inode)
14977 + h_ino = a->h_child_inode->i_ino;
14979 + if (a->h_child_nlen
14980 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
14981 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
14982 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
14986 + inode = dentry->d_inode;
14987 + if (xino && !inode && h_ino
14988 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
14989 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
14990 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
14991 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
14995 + args.flags = a->flags[AuHn_CHILD];
14996 + args.dentry = dentry;
14997 + args.inode = inode;
14998 + args.h_inode = a->h_child_inode;
14999 + args.dir = a->dir;
15000 + args.h_dir = a->h_dir;
15001 + args.h_name = a->h_child_name;
15002 + args.h_nlen = a->h_child_nlen;
15003 + err = hn_job(&args);
15005 + if (au_di(dentry))
15006 + di_write_unlock(dentry);
15009 + if (inode && try_iput) {
15010 + ii_write_unlock(inode);
15014 + ii_write_lock_parent(a->dir);
15015 + args.flags = a->flags[AuHn_PARENT];
15016 + args.dentry = NULL;
15017 + args.inode = a->dir;
15018 + args.h_inode = a->h_dir;
15020 + args.h_dir = NULL;
15021 + args.h_name = NULL;
15023 + err = hn_job(&args);
15024 + ii_write_unlock(a->dir);
15027 + iput(a->h_child_inode);
15030 + si_write_unlock(sb);
15031 + au_nwt_done(&sbinfo->si_nowait);
15035 +/* ---------------------------------------------------------------------- */
15037 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15038 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15041 + unsigned int flags[AuHnLast], f;
15042 + unsigned char isdir, isroot, wh;
15043 + struct inode *dir;
15044 + struct au_hnotify_args *args;
15045 + char *p, *h_child_name;
15048 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15049 + dir = igrab(hnotify->hn_aufs_inode);
15053 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15055 + h_child_name = (void *)h_child_qstr->name;
15056 + len = h_child_qstr->len;
15057 + if (h_child_name) {
15058 + if (len > AUFS_WH_PFX_LEN
15059 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15060 + h_child_name += AUFS_WH_PFX_LEN;
15061 + len -= AUFS_WH_PFX_LEN;
15067 + if (h_child_inode)
15068 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15069 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15070 + flags[AuHn_CHILD] = 0;
15072 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15073 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15074 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15075 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15076 + case FS_MOVED_FROM:
15077 + case FS_MOVED_TO:
15078 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15079 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15082 + AuDebugOn(!h_child_name);
15087 + * aufs never be able to get this child inode.
15088 + * revalidation should be in d_revalidate()
15089 + * by checking i_nlink, i_generation or d_unhashed().
15091 + AuDebugOn(!h_child_name);
15092 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15093 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15101 + h_child_inode = NULL;
15104 + /* iput() and kfree() will be called in au_hnotify() */
15105 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15106 + if (unlikely(!args)) {
15107 + AuErr1("no memory\n");
15111 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15112 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15113 + args->mask = mask;
15115 + args->h_dir = igrab(h_dir);
15116 + if (h_child_inode)
15117 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15118 + args->h_child_inode = h_child_inode;
15119 + args->h_child_nlen = len;
15121 + p = (void *)args;
15122 + p += sizeof(*args);
15123 + memcpy(p, h_child_name, len);
15127 + /* NFS fires the event for silly-renamed one from kworker */
15129 + if (!dir->i_nlink
15130 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15132 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15133 + if (unlikely(err)) {
15134 + pr_err("wkq %d\n", err);
15135 + iput(args->h_child_inode);
15136 + iput(args->h_dir);
15145 +/* ---------------------------------------------------------------------- */
15147 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15151 + AuDebugOn(!(udba & AuOptMask_UDBA));
15154 + if (au_hnotify_op.reset_br)
15155 + err = au_hnotify_op.reset_br(udba, br, perm);
15160 +int au_hnotify_init_br(struct au_branch *br, int perm)
15165 + if (au_hnotify_op.init_br)
15166 + err = au_hnotify_op.init_br(br, perm);
15171 +void au_hnotify_fin_br(struct au_branch *br)
15173 + if (au_hnotify_op.fin_br)
15174 + au_hnotify_op.fin_br(br);
15177 +static void au_hn_destroy_cache(void)
15179 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15180 + au_cachep[AuCache_HNOTIFY] = NULL;
15183 +int __init au_hnotify_init(void)
15188 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15189 + if (au_cachep[AuCache_HNOTIFY]) {
15191 + if (au_hnotify_op.init)
15192 + err = au_hnotify_op.init();
15193 + if (unlikely(err))
15194 + au_hn_destroy_cache();
15200 +void au_hnotify_fin(void)
15202 + if (au_hnotify_op.fin)
15203 + au_hnotify_op.fin();
15204 + /* cf. au_cache_fin() */
15205 + if (au_cachep[AuCache_HNOTIFY])
15206 + au_hn_destroy_cache();
15208 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15209 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15210 +++ linux/fs/aufs/iinfo.c 2015-04-13 15:10:20.786823613 +0200
15213 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15215 + * This program, aufs is free software; you can redistribute it and/or modify
15216 + * it under the terms of the GNU General Public License as published by
15217 + * the Free Software Foundation; either version 2 of the License, or
15218 + * (at your option) any later version.
15220 + * This program is distributed in the hope that it will be useful,
15221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15223 + * GNU General Public License for more details.
15225 + * You should have received a copy of the GNU General Public License
15226 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15230 + * inode private data
15235 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15237 + struct inode *h_inode;
15239 + IiMustAnyLock(inode);
15241 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15242 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15246 +/* todo: hard/soft set? */
15247 +void au_hiput(struct au_hinode *hinode)
15249 + au_hn_free(hinode);
15250 + dput(hinode->hi_whdentry);
15251 + iput(hinode->hi_inode);
15254 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15256 + unsigned int flags;
15257 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15260 + if (au_opt_test(mnt_flags, XINO))
15261 + au_fset_hi(flags, XINO);
15262 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15263 + au_fset_hi(flags, HNOTIFY);
15267 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15268 + struct inode *h_inode, unsigned int flags)
15270 + struct au_hinode *hinode;
15271 + struct inode *hi;
15272 + struct au_iinfo *iinfo = au_ii(inode);
15274 + IiMustWriteLock(inode);
15276 + hinode = iinfo->ii_hinode + bindex;
15277 + hi = hinode->hi_inode;
15278 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15281 + au_hiput(hinode);
15282 + hinode->hi_inode = h_inode;
15285 + struct super_block *sb = inode->i_sb;
15286 + struct au_branch *br;
15288 + AuDebugOn(inode->i_mode
15289 + && (h_inode->i_mode & S_IFMT)
15290 + != (inode->i_mode & S_IFMT));
15291 + if (bindex == iinfo->ii_bstart)
15292 + au_cpup_igen(inode, h_inode);
15293 + br = au_sbr(sb, bindex);
15294 + hinode->hi_id = br->br_id;
15295 + if (au_ftest_hi(flags, XINO)) {
15296 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15298 + if (unlikely(err))
15299 + AuIOErr1("failed au_xino_write() %d\n", err);
15302 + if (au_ftest_hi(flags, HNOTIFY)
15303 + && au_br_hnotifyable(br->br_perm)) {
15304 + err = au_hn_alloc(hinode, inode);
15305 + if (unlikely(err))
15306 + AuIOErr1("au_hn_alloc() %d\n", err);
15311 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15312 + struct dentry *h_wh)
15314 + struct au_hinode *hinode;
15316 + IiMustWriteLock(inode);
15318 + hinode = au_ii(inode)->ii_hinode + bindex;
15319 + AuDebugOn(hinode->hi_whdentry);
15320 + hinode->hi_whdentry = h_wh;
15323 +void au_update_iigen(struct inode *inode, int half)
15325 + struct au_iinfo *iinfo;
15326 + struct au_iigen *iigen;
15327 + unsigned int sigen;
15329 + sigen = au_sigen(inode->i_sb);
15330 + iinfo = au_ii(inode);
15331 + iigen = &iinfo->ii_generation;
15332 + spin_lock(&iinfo->ii_genspin);
15333 + iigen->ig_generation = sigen;
15335 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15337 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15338 + spin_unlock(&iinfo->ii_genspin);
15341 +/* it may be called at remount time, too */
15342 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15344 + struct au_iinfo *iinfo;
15345 + aufs_bindex_t bindex, bend;
15347 + iinfo = au_ii(inode);
15351 + IiMustWriteLock(inode);
15353 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15354 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15356 + struct inode *h_i;
15358 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15361 + && !(h_i->i_state & I_LINKABLE))
15362 + au_set_h_iptr(inode, bindex, NULL, 0);
15366 + iinfo->ii_bstart = -1;
15367 + iinfo->ii_bend = -1;
15368 + bend = au_sbend(inode->i_sb);
15369 + for (bindex = 0; bindex <= bend; bindex++)
15370 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15371 + iinfo->ii_bstart = bindex;
15374 + if (iinfo->ii_bstart >= 0)
15375 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15376 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15377 + iinfo->ii_bend = bindex;
15380 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15383 +/* ---------------------------------------------------------------------- */
15385 +void au_icntnr_init_once(void *_c)
15387 + struct au_icntnr *c = _c;
15388 + struct au_iinfo *iinfo = &c->iinfo;
15389 + static struct lock_class_key aufs_ii;
15391 + spin_lock_init(&iinfo->ii_genspin);
15392 + au_rw_init(&iinfo->ii_rwsem);
15393 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15394 + inode_init_once(&c->vfs_inode);
15397 +int au_iinfo_init(struct inode *inode)
15399 + struct au_iinfo *iinfo;
15400 + struct super_block *sb;
15403 + sb = inode->i_sb;
15404 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15405 + nbr = au_sbend(sb) + 1;
15406 + if (unlikely(nbr <= 0))
15408 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15409 + if (iinfo->ii_hinode) {
15410 + au_ninodes_inc(sb);
15411 + for (i = 0; i < nbr; i++)
15412 + iinfo->ii_hinode[i].hi_id = -1;
15414 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15415 + iinfo->ii_bstart = -1;
15416 + iinfo->ii_bend = -1;
15417 + iinfo->ii_vdir = NULL;
15423 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15426 + struct au_hinode *hip;
15428 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15431 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15433 + sz = sizeof(*hip);
15434 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15436 + iinfo->ii_hinode = hip;
15443 +void au_iinfo_fin(struct inode *inode)
15445 + struct au_iinfo *iinfo;
15446 + struct au_hinode *hi;
15447 + struct super_block *sb;
15448 + aufs_bindex_t bindex, bend;
15449 + const unsigned char unlinked = !inode->i_nlink;
15451 + iinfo = au_ii(inode);
15452 + /* bad_inode case */
15456 + sb = inode->i_sb;
15457 + au_ninodes_dec(sb);
15458 + if (si_pid_test(sb))
15459 + au_xino_delete_inode(inode, unlinked);
15462 + * it is safe to hide the dependency between sbinfo and
15466 + si_noflush_read_lock(sb);
15467 + au_xino_delete_inode(inode, unlinked);
15468 + si_read_unlock(sb);
15472 + if (iinfo->ii_vdir)
15473 + au_vdir_free(iinfo->ii_vdir);
15475 + bindex = iinfo->ii_bstart;
15476 + if (bindex >= 0) {
15477 + hi = iinfo->ii_hinode + bindex;
15478 + bend = iinfo->ii_bend;
15479 + while (bindex++ <= bend) {
15480 + if (hi->hi_inode)
15485 + kfree(iinfo->ii_hinode);
15486 + iinfo->ii_hinode = NULL;
15487 + AuRwDestroy(&iinfo->ii_rwsem);
15489 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15490 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15491 +++ linux/fs/aufs/inode.c 2015-04-13 15:10:20.786823613 +0200
15494 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15496 + * This program, aufs is free software; you can redistribute it and/or modify
15497 + * it under the terms of the GNU General Public License as published by
15498 + * the Free Software Foundation; either version 2 of the License, or
15499 + * (at your option) any later version.
15501 + * This program is distributed in the hope that it will be useful,
15502 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15503 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15504 + * GNU General Public License for more details.
15506 + * You should have received a copy of the GNU General Public License
15507 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15511 + * inode functions
15516 +struct inode *au_igrab(struct inode *inode)
15519 + AuDebugOn(!atomic_read(&inode->i_count));
15525 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15527 + au_cpup_attr_all(inode, /*force*/0);
15528 + au_update_iigen(inode, /*half*/1);
15530 + inode->i_version++;
15533 +static int au_ii_refresh(struct inode *inode, int *update)
15537 + aufs_bindex_t bindex, new_bindex;
15538 + struct super_block *sb;
15539 + struct au_iinfo *iinfo;
15540 + struct au_hinode *p, *q, tmp;
15542 + IiMustWriteLock(inode);
15545 + sb = inode->i_sb;
15546 + type = inode->i_mode & S_IFMT;
15547 + iinfo = au_ii(inode);
15548 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15549 + if (unlikely(err))
15552 + AuDebugOn(iinfo->ii_bstart < 0);
15553 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15554 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15556 + if (!p->hi_inode)
15559 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15560 + new_bindex = au_br_index(sb, p->hi_id);
15561 + if (new_bindex == bindex)
15564 + if (new_bindex < 0) {
15567 + p->hi_inode = NULL;
15571 + if (new_bindex < iinfo->ii_bstart)
15572 + iinfo->ii_bstart = new_bindex;
15573 + if (iinfo->ii_bend < new_bindex)
15574 + iinfo->ii_bend = new_bindex;
15575 + /* swap two lower inode, and loop again */
15576 + q = iinfo->ii_hinode + new_bindex;
15580 + if (tmp.hi_inode) {
15585 + au_update_ibrange(inode, /*do_put_zero*/0);
15586 + e = au_dy_irefresh(inode);
15587 + if (unlikely(e && !err))
15595 +int au_refresh_hinode_self(struct inode *inode)
15599 + err = au_ii_refresh(inode, &update);
15601 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15607 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15609 + int err, e, update;
15610 + unsigned int flags;
15612 + aufs_bindex_t bindex, bend;
15613 + unsigned char isdir;
15614 + struct au_hinode *p;
15615 + struct au_iinfo *iinfo;
15617 + err = au_ii_refresh(inode, &update);
15618 + if (unlikely(err))
15622 + iinfo = au_ii(inode);
15623 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15624 + mode = (inode->i_mode & S_IFMT);
15625 + isdir = S_ISDIR(mode);
15626 + flags = au_hi_flags(inode, isdir);
15627 + bend = au_dbend(dentry);
15628 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15629 + struct inode *h_i;
15630 + struct dentry *h_d;
15632 + h_d = au_h_dptr(dentry, bindex);
15633 + if (!h_d || !h_d->d_inode)
15636 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
15637 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15638 + h_i = au_h_iptr(inode, bindex);
15640 + if (h_i == h_d->d_inode)
15646 + if (bindex < iinfo->ii_bstart)
15647 + iinfo->ii_bstart = bindex;
15648 + if (iinfo->ii_bend < bindex)
15649 + iinfo->ii_bend = bindex;
15650 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
15653 + au_update_ibrange(inode, /*do_put_zero*/0);
15654 + e = au_dy_irefresh(inode);
15655 + if (unlikely(e && !err))
15658 + au_refresh_hinode_attr(inode, update && isdir);
15665 +static int set_inode(struct inode *inode, struct dentry *dentry)
15668 + unsigned int flags;
15670 + aufs_bindex_t bindex, bstart, btail;
15671 + unsigned char isdir;
15672 + struct dentry *h_dentry;
15673 + struct inode *h_inode;
15674 + struct au_iinfo *iinfo;
15676 + IiMustWriteLock(inode);
15680 + bstart = au_dbstart(dentry);
15681 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
15682 + mode = h_inode->i_mode;
15683 + switch (mode & S_IFMT) {
15685 + btail = au_dbtail(dentry);
15686 + inode->i_op = &aufs_iop;
15687 + inode->i_fop = &aufs_file_fop;
15688 + err = au_dy_iaop(inode, bstart, h_inode);
15689 + if (unlikely(err))
15694 + btail = au_dbtaildir(dentry);
15695 + inode->i_op = &aufs_dir_iop;
15696 + inode->i_fop = &aufs_dir_fop;
15699 + btail = au_dbtail(dentry);
15700 + inode->i_op = &aufs_symlink_iop;
15706 + btail = au_dbtail(dentry);
15707 + inode->i_op = &aufs_iop;
15708 + init_special_inode(inode, mode, h_inode->i_rdev);
15711 + AuIOErr("Unknown file type 0%o\n", mode);
15716 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15717 + flags = au_hi_flags(inode, isdir);
15718 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15719 + && au_ftest_hi(flags, HNOTIFY)
15720 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15721 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15722 + au_fclr_hi(flags, HNOTIFY);
15723 + iinfo = au_ii(inode);
15724 + iinfo->ii_bstart = bstart;
15725 + iinfo->ii_bend = btail;
15726 + for (bindex = bstart; bindex <= btail; bindex++) {
15727 + h_dentry = au_h_dptr(dentry, bindex);
15729 + au_set_h_iptr(inode, bindex,
15730 + au_igrab(h_dentry->d_inode), flags);
15732 + au_cpup_attr_all(inode, /*force*/1);
15734 + * to force calling aufs_get_acl() every time,
15735 + * do not call cache_no_acl() for aufs inode.
15743 + * successful returns with iinfo write_locked
15745 + * zero: success, matched
15746 + * plus: no error, but unmatched
15748 +static int reval_inode(struct inode *inode, struct dentry *dentry)
15751 + unsigned int gen;
15752 + struct au_iigen iigen;
15753 + aufs_bindex_t bindex, bend;
15754 + struct inode *h_inode, *h_dinode;
15757 + * before this function, if aufs got any iinfo lock, it must be only
15758 + * one, the parent dir.
15759 + * it can happen by UDBA and the obsoleted inode number.
15762 + if (unlikely(inode->i_ino == parent_ino(dentry)))
15766 + ii_write_lock_new_child(inode);
15767 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
15768 + bend = au_ibend(inode);
15769 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
15770 + h_inode = au_h_iptr(inode, bindex);
15771 + if (!h_inode || h_inode != h_dinode)
15775 + gen = au_iigen(inode, &iigen);
15776 + if (gen == au_digen(dentry)
15777 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
15780 + /* fully refresh inode using dentry */
15781 + err = au_refresh_hinode(inode, dentry);
15783 + au_update_iigen(inode, /*half*/0);
15787 + if (unlikely(err))
15788 + ii_write_unlock(inode);
15793 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15794 + unsigned int d_type, ino_t *ino)
15797 + struct mutex *mtx;
15799 + /* prevent hardlinked inode number from race condition */
15801 + if (d_type != DT_DIR) {
15802 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
15805 + err = au_xino_read(sb, bindex, h_ino, ino);
15806 + if (unlikely(err))
15811 + *ino = au_xino_new_ino(sb);
15812 + if (unlikely(!*ino))
15814 + err = au_xino_write(sb, bindex, h_ino, *ino);
15815 + if (unlikely(err))
15821 + mutex_unlock(mtx);
15825 +/* successful returns with iinfo write_locked */
15826 +/* todo: return with unlocked? */
15827 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
15829 + struct inode *inode;
15830 + struct dentry *h_dentry;
15831 + struct super_block *sb;
15832 + struct mutex *mtx;
15833 + ino_t h_ino, ino;
15835 + aufs_bindex_t bstart;
15837 + sb = dentry->d_sb;
15838 + bstart = au_dbstart(dentry);
15839 + h_dentry = au_h_dptr(dentry, bstart);
15840 + h_ino = h_dentry->d_inode->i_ino;
15843 + * stop 'race'-ing between hardlinks under different
15847 + if (!d_is_dir(h_dentry))
15848 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
15853 + err = au_xino_read(sb, bstart, h_ino, &ino);
15854 + inode = ERR_PTR(err);
15855 + if (unlikely(err))
15859 + ino = au_xino_new_ino(sb);
15860 + if (unlikely(!ino)) {
15861 + inode = ERR_PTR(-EIO);
15866 + AuDbg("i%lu\n", (unsigned long)ino);
15867 + inode = au_iget_locked(sb, ino);
15868 + err = PTR_ERR(inode);
15869 + if (IS_ERR(inode))
15872 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
15873 + if (inode->i_state & I_NEW) {
15874 + /* verbose coding for lock class name */
15875 + if (unlikely(d_is_symlink(h_dentry)))
15876 + au_rw_class(&au_ii(inode)->ii_rwsem,
15877 + au_lc_key + AuLcSymlink_IIINFO);
15878 + else if (unlikely(d_is_dir(h_dentry)))
15879 + au_rw_class(&au_ii(inode)->ii_rwsem,
15880 + au_lc_key + AuLcDir_IIINFO);
15881 + else /* likely */
15882 + au_rw_class(&au_ii(inode)->ii_rwsem,
15883 + au_lc_key + AuLcNonDir_IIINFO);
15885 + ii_write_lock_new_child(inode);
15886 + err = set_inode(inode, dentry);
15888 + unlock_new_inode(inode);
15889 + goto out; /* success */
15893 + * iget_failed() calls iput(), but we need to call
15894 + * ii_write_unlock() after iget_failed(). so dirty hack for
15897 + atomic_inc(&inode->i_count);
15898 + iget_failed(inode);
15899 + ii_write_unlock(inode);
15900 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
15901 + /* ignore this error */
15903 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
15905 + * horrible race condition between lookup, readdir and copyup
15906 + * (or something).
15909 + mutex_unlock(mtx);
15910 + err = reval_inode(inode, dentry);
15911 + if (unlikely(err < 0)) {
15918 + goto out; /* success */
15923 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
15924 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
15925 + " b%d, %s, %pd, hi%lu, i%lu.\n",
15926 + bstart, au_sbtype(h_dentry->d_sb), dentry,
15927 + (unsigned long)h_ino, (unsigned long)ino);
15929 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
15933 + mutex_unlock(mtx);
15939 + inode = ERR_PTR(err);
15942 + mutex_unlock(mtx);
15946 +/* ---------------------------------------------------------------------- */
15948 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15949 + struct inode *inode)
15952 + struct inode *hi;
15954 + err = au_br_rdonly(au_sbr(sb, bindex));
15956 + /* pseudo-link after flushed may happen out of bounds */
15959 + && au_ibstart(inode) <= bindex
15960 + && bindex <= au_ibend(inode)) {
15962 + * permission check is unnecessary since vfsub routine
15963 + * will be called later
15965 + hi = au_h_iptr(inode, bindex);
15967 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
15973 +int au_test_h_perm(struct inode *h_inode, int mask)
15975 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
15977 + return inode_permission(h_inode, mask);
15980 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
15982 + if (au_test_nfs(h_inode->i_sb)
15983 + && (mask & MAY_WRITE)
15984 + && S_ISDIR(h_inode->i_mode))
15985 + mask |= MAY_READ; /* force permission check */
15986 + return au_test_h_perm(h_inode, mask);
15988 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
15989 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
15990 +++ linux/fs/aufs/inode.h 2015-04-13 15:10:20.786823613 +0200
15993 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15995 + * This program, aufs is free software; you can redistribute it and/or modify
15996 + * it under the terms of the GNU General Public License as published by
15997 + * the Free Software Foundation; either version 2 of the License, or
15998 + * (at your option) any later version.
16000 + * This program is distributed in the hope that it will be useful,
16001 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16002 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16003 + * GNU General Public License for more details.
16005 + * You should have received a copy of the GNU General Public License
16006 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16010 + * inode operations
16013 +#ifndef __AUFS_INODE_H__
16014 +#define __AUFS_INODE_H__
16018 +#include <linux/fsnotify.h>
16019 +#include "rwsem.h"
16023 +struct au_hnotify {
16024 +#ifdef CONFIG_AUFS_HNOTIFY
16025 +#ifdef CONFIG_AUFS_HFSNOTIFY
16026 + /* never use fsnotify_add_vfsmount_mark() */
16027 + struct fsnotify_mark hn_mark;
16029 + struct inode *hn_aufs_inode; /* no get/put */
16031 +} ____cacheline_aligned_in_smp;
16033 +struct au_hinode {
16034 + struct inode *hi_inode;
16035 + aufs_bindex_t hi_id;
16036 +#ifdef CONFIG_AUFS_HNOTIFY
16037 + struct au_hnotify *hi_notify;
16040 + /* reference to the copied-up whiteout with get/put */
16041 + struct dentry *hi_whdentry;
16045 +#define AuIG_HALF_REFRESHED 1
16046 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16047 +#define au_ig_fset(flags, name) \
16048 + do { (flags) |= AuIG_##name; } while (0)
16049 +#define au_ig_fclr(flags, name) \
16050 + do { (flags) &= ~AuIG_##name; } while (0)
16053 + __u32 ig_generation, ig_flags;
16058 + spinlock_t ii_genspin;
16059 + struct au_iigen ii_generation;
16060 + struct super_block *ii_hsb1; /* no get/put */
16062 + struct au_rwsem ii_rwsem;
16063 + aufs_bindex_t ii_bstart, ii_bend;
16065 + struct au_hinode *ii_hinode;
16066 + struct au_vdir *ii_vdir;
16069 +struct au_icntnr {
16070 + struct au_iinfo iinfo;
16071 + struct inode vfs_inode;
16072 +} ____cacheline_aligned_in_smp;
16074 +/* au_pin flags */
16075 +#define AuPin_DI_LOCKED 1
16076 +#define AuPin_MNT_WRITE (1 << 1)
16077 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16078 +#define au_fset_pin(flags, name) \
16079 + do { (flags) |= AuPin_##name; } while (0)
16080 +#define au_fclr_pin(flags, name) \
16081 + do { (flags) &= ~AuPin_##name; } while (0)
16085 + struct dentry *dentry;
16086 + unsigned int udba;
16087 + unsigned char lsc_di, lsc_hi, flags;
16088 + aufs_bindex_t bindex;
16091 + struct dentry *parent;
16092 + struct au_hinode *hdir;
16093 + struct vfsmount *h_mnt;
16095 + /* temporary unlock/relock for copyup */
16096 + struct dentry *h_dentry, *h_parent;
16097 + struct au_branch *br;
16098 + struct task_struct *task;
16101 +void au_pin_hdir_unlock(struct au_pin *p);
16102 +int au_pin_hdir_lock(struct au_pin *p);
16103 +int au_pin_hdir_relock(struct au_pin *p);
16104 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16105 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16106 +void au_pin_hdir_release(struct au_pin *p);
16108 +/* ---------------------------------------------------------------------- */
16110 +static inline struct au_iinfo *au_ii(struct inode *inode)
16112 + struct au_iinfo *iinfo;
16114 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16115 + if (iinfo->ii_hinode)
16117 + return NULL; /* debugging bad_inode case */
16120 +/* ---------------------------------------------------------------------- */
16123 +struct inode *au_igrab(struct inode *inode);
16124 +int au_refresh_hinode_self(struct inode *inode);
16125 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16126 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16127 + unsigned int d_type, ino_t *ino);
16128 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16129 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16130 + struct inode *inode);
16131 +int au_test_h_perm(struct inode *h_inode, int mask);
16132 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16134 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16135 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16137 +#ifdef CONFIG_AUFS_SHWH
16138 + return au_ino(sb, bindex, h_ino, d_type, ino);
16145 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
16147 +/* au_wr_dir flags */
16148 +#define AuWrDir_ADD_ENTRY 1
16149 +#define AuWrDir_ISDIR (1 << 1)
16150 +#define AuWrDir_TMPFILE (1 << 2)
16151 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16152 +#define au_fset_wrdir(flags, name) \
16153 + do { (flags) |= AuWrDir_##name; } while (0)
16154 +#define au_fclr_wrdir(flags, name) \
16155 + do { (flags) &= ~AuWrDir_##name; } while (0)
16157 +struct au_wr_dir_args {
16158 + aufs_bindex_t force_btgt;
16159 + unsigned char flags;
16161 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16162 + struct au_wr_dir_args *args);
16164 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16165 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16166 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16167 + unsigned int udba, unsigned char flags);
16168 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16169 + unsigned int udba, unsigned char flags) __must_check;
16170 +int au_do_pin(struct au_pin *pin) __must_check;
16171 +void au_unpin(struct au_pin *pin);
16172 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16174 +#define AuIcpup_DID_CPUP 1
16175 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16176 +#define au_fset_icpup(flags, name) \
16177 + do { (flags) |= AuIcpup_##name; } while (0)
16178 +#define au_fclr_icpup(flags, name) \
16179 + do { (flags) &= ~AuIcpup_##name; } while (0)
16181 +struct au_icpup_args {
16182 + unsigned char flags;
16183 + unsigned char pin_flags;
16184 + aufs_bindex_t btgt;
16185 + unsigned int udba;
16186 + struct au_pin pin;
16187 + struct path h_path;
16188 + struct inode *h_inode;
16191 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16192 + struct au_icpup_args *a);
16194 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16197 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16198 + struct dentry *h_parent, int isdir);
16199 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16201 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16202 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16204 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16205 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16206 + struct dentry *dentry);
16207 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16210 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16211 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16212 + struct dentry *h_parent, int isdir);
16213 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16214 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16217 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16218 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16219 + struct inode *dir, struct dentry *dentry);
16222 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16223 +void au_hiput(struct au_hinode *hinode);
16224 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16225 + struct dentry *h_wh);
16226 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16228 +/* hinode flags */
16229 +#define AuHi_XINO 1
16230 +#define AuHi_HNOTIFY (1 << 1)
16231 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16232 +#define au_fset_hi(flags, name) \
16233 + do { (flags) |= AuHi_##name; } while (0)
16234 +#define au_fclr_hi(flags, name) \
16235 + do { (flags) &= ~AuHi_##name; } while (0)
16237 +#ifndef CONFIG_AUFS_HNOTIFY
16238 +#undef AuHi_HNOTIFY
16239 +#define AuHi_HNOTIFY 0
16242 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16243 + struct inode *h_inode, unsigned int flags);
16245 +void au_update_iigen(struct inode *inode, int half);
16246 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16248 +void au_icntnr_init_once(void *_c);
16249 +int au_iinfo_init(struct inode *inode);
16250 +void au_iinfo_fin(struct inode *inode);
16251 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16253 +#ifdef CONFIG_PROC_FS
16255 +int au_plink_maint(struct super_block *sb, int flags);
16257 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16258 +int au_plink_maint_enter(struct super_block *sb);
16259 +#ifdef CONFIG_AUFS_DEBUG
16260 +void au_plink_list(struct super_block *sb);
16262 +AuStubVoid(au_plink_list, struct super_block *sb)
16264 +int au_plink_test(struct inode *inode);
16265 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16266 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16267 + struct dentry *h_dentry);
16268 +void au_plink_put(struct super_block *sb, int verbose);
16269 +void au_plink_clean(struct super_block *sb, int verbose);
16270 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16272 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16273 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16274 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16275 +AuStubVoid(au_plink_list, struct super_block *sb);
16276 +AuStubInt0(au_plink_test, struct inode *inode);
16277 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16278 + struct inode *inode, aufs_bindex_t bindex);
16279 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16280 + struct dentry *h_dentry);
16281 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16282 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16283 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16284 +#endif /* CONFIG_PROC_FS */
16286 +#ifdef CONFIG_AUFS_XATTR
16288 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16289 + unsigned int verbose);
16290 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16291 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16293 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16294 + size_t size, int flags);
16295 +int aufs_removexattr(struct dentry *dentry, const char *name);
16297 +/* void au_xattr_init(struct super_block *sb); */
16299 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16300 + int ignore_flags, unsigned int verbose);
16301 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16304 +#ifdef CONFIG_FS_POSIX_ACL
16305 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16306 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16309 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16316 +struct au_srxattr {
16320 + const char *name;
16321 + const void *value;
16326 + const char *name;
16329 + struct posix_acl *acl;
16334 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16337 +/* ---------------------------------------------------------------------- */
16339 +/* lock subclass for iinfo */
16341 + AuLsc_II_CHILD, /* child first */
16342 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16343 + AuLsc_II_CHILD3, /* copyup dirs */
16344 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16345 + AuLsc_II_PARENT2,
16346 + AuLsc_II_PARENT3, /* copyup dirs */
16347 + AuLsc_II_NEW_CHILD
16351 + * ii_read_lock_child, ii_write_lock_child,
16352 + * ii_read_lock_child2, ii_write_lock_child2,
16353 + * ii_read_lock_child3, ii_write_lock_child3,
16354 + * ii_read_lock_parent, ii_write_lock_parent,
16355 + * ii_read_lock_parent2, ii_write_lock_parent2,
16356 + * ii_read_lock_parent3, ii_write_lock_parent3,
16357 + * ii_read_lock_new_child, ii_write_lock_new_child,
16359 +#define AuReadLockFunc(name, lsc) \
16360 +static inline void ii_read_lock_##name(struct inode *i) \
16362 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16365 +#define AuWriteLockFunc(name, lsc) \
16366 +static inline void ii_write_lock_##name(struct inode *i) \
16368 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16371 +#define AuRWLockFuncs(name, lsc) \
16372 + AuReadLockFunc(name, lsc) \
16373 + AuWriteLockFunc(name, lsc)
16375 +AuRWLockFuncs(child, CHILD);
16376 +AuRWLockFuncs(child2, CHILD2);
16377 +AuRWLockFuncs(child3, CHILD3);
16378 +AuRWLockFuncs(parent, PARENT);
16379 +AuRWLockFuncs(parent2, PARENT2);
16380 +AuRWLockFuncs(parent3, PARENT3);
16381 +AuRWLockFuncs(new_child, NEW_CHILD);
16383 +#undef AuReadLockFunc
16384 +#undef AuWriteLockFunc
16385 +#undef AuRWLockFuncs
16388 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16390 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16392 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16393 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16394 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16396 +/* ---------------------------------------------------------------------- */
16398 +static inline void au_icntnr_init(struct au_icntnr *c)
16400 +#ifdef CONFIG_AUFS_DEBUG
16401 + c->vfs_inode.i_mode = 0;
16405 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
16407 + unsigned int gen;
16408 + struct au_iinfo *iinfo;
16410 + iinfo = au_ii(inode);
16411 + spin_lock(&iinfo->ii_genspin);
16413 + *iigen = iinfo->ii_generation;
16414 + gen = iinfo->ii_generation.ig_generation;
16415 + spin_unlock(&iinfo->ii_genspin);
16420 +/* tiny test for inode number */
16421 +/* tmpfs generation is too rough */
16422 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16424 + struct au_iinfo *iinfo;
16426 + iinfo = au_ii(inode);
16427 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16428 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16429 + && iinfo->ii_higen == h_inode->i_generation);
16432 +static inline void au_iigen_dec(struct inode *inode)
16434 + struct au_iinfo *iinfo;
16436 + iinfo = au_ii(inode);
16437 + spin_lock(&iinfo->ii_genspin);
16438 + iinfo->ii_generation.ig_generation--;
16439 + spin_unlock(&iinfo->ii_genspin);
16442 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16447 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16453 +/* ---------------------------------------------------------------------- */
16455 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16456 + aufs_bindex_t bindex)
16458 + IiMustAnyLock(inode);
16459 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16462 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16464 + IiMustAnyLock(inode);
16465 + return au_ii(inode)->ii_bstart;
16468 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16470 + IiMustAnyLock(inode);
16471 + return au_ii(inode)->ii_bend;
16474 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16476 + IiMustAnyLock(inode);
16477 + return au_ii(inode)->ii_vdir;
16480 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16482 + IiMustAnyLock(inode);
16483 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16486 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16488 + IiMustWriteLock(inode);
16489 + au_ii(inode)->ii_bstart = bindex;
16492 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16494 + IiMustWriteLock(inode);
16495 + au_ii(inode)->ii_bend = bindex;
16498 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16500 + IiMustWriteLock(inode);
16501 + au_ii(inode)->ii_vdir = vdir;
16504 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16506 + IiMustAnyLock(inode);
16507 + return au_ii(inode)->ii_hinode + bindex;
16510 +/* ---------------------------------------------------------------------- */
16512 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16515 + return pin->parent;
16519 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16521 + if (pin && pin->hdir)
16522 + return pin->hdir->hi_inode;
16526 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16529 + return pin->hdir;
16533 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16536 + pin->dentry = dentry;
16539 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16540 + unsigned char lflag)
16544 + au_fset_pin(pin->flags, DI_LOCKED);
16546 + au_fclr_pin(pin->flags, DI_LOCKED);
16550 +#if 0 /* reserved */
16551 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16554 + dput(pin->parent);
16555 + pin->parent = dget(parent);
16560 +/* ---------------------------------------------------------------------- */
16563 +#ifdef CONFIG_AUFS_HNOTIFY
16564 +struct au_hnotify_op {
16565 + void (*ctl)(struct au_hinode *hinode, int do_set);
16566 + int (*alloc)(struct au_hinode *hinode);
16569 + * if it returns true, the the caller should free hinode->hi_notify,
16570 + * otherwise ->free() frees it.
16572 + int (*free)(struct au_hinode *hinode,
16573 + struct au_hnotify *hn) __must_check;
16575 + void (*fin)(void);
16576 + int (*init)(void);
16578 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16579 + void (*fin_br)(struct au_branch *br);
16580 + int (*init_br)(struct au_branch *br, int perm);
16584 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16585 +void au_hn_free(struct au_hinode *hinode);
16586 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16587 +void au_hn_reset(struct inode *inode, unsigned int flags);
16588 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16589 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16590 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16591 +int au_hnotify_init_br(struct au_branch *br, int perm);
16592 +void au_hnotify_fin_br(struct au_branch *br);
16593 +int __init au_hnotify_init(void);
16594 +void au_hnotify_fin(void);
16597 +extern const struct au_hnotify_op au_hnotify_op;
16600 +void au_hn_init(struct au_hinode *hinode)
16602 + hinode->hi_notify = NULL;
16605 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16607 + return hinode->hi_notify;
16611 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
16612 + struct au_hinode *hinode __maybe_unused,
16613 + struct inode *inode __maybe_unused)
16614 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
16615 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16616 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16617 + int do_set __maybe_unused)
16618 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16619 + unsigned int flags __maybe_unused)
16620 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16621 + struct au_branch *br __maybe_unused,
16622 + int perm __maybe_unused)
16623 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16624 + int perm __maybe_unused)
16625 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16626 +AuStubInt0(__init au_hnotify_init, void)
16627 +AuStubVoid(au_hnotify_fin, void)
16628 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16629 +#endif /* CONFIG_AUFS_HNOTIFY */
16631 +static inline void au_hn_suspend(struct au_hinode *hdir)
16633 + au_hn_ctl(hdir, /*do_set*/0);
16636 +static inline void au_hn_resume(struct au_hinode *hdir)
16638 + au_hn_ctl(hdir, /*do_set*/1);
16641 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16643 + mutex_lock(&hdir->hi_inode->i_mutex);
16644 + au_hn_suspend(hdir);
16647 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16648 + unsigned int sc __maybe_unused)
16650 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16651 + au_hn_suspend(hdir);
16654 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16656 + au_hn_resume(hdir);
16657 + mutex_unlock(&hdir->hi_inode->i_mutex);
16660 +#endif /* __KERNEL__ */
16661 +#endif /* __AUFS_INODE_H__ */
16662 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16663 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16664 +++ linux/fs/aufs/ioctl.c 2015-04-13 15:10:20.786823613 +0200
16667 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16669 + * This program, aufs is free software; you can redistribute it and/or modify
16670 + * it under the terms of the GNU General Public License as published by
16671 + * the Free Software Foundation; either version 2 of the License, or
16672 + * (at your option) any later version.
16674 + * This program is distributed in the hope that it will be useful,
16675 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16676 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16677 + * GNU General Public License for more details.
16679 + * You should have received a copy of the GNU General Public License
16680 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16685 + * plink-management and readdir in userspace.
16686 + * assist the pathconf(3) wrapper library.
16688 + * File-based Hierarchical Storage Management.
16691 +#include <linux/compat.h>
16692 +#include <linux/file.h>
16695 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16698 + aufs_bindex_t wbi, bindex, bend;
16699 + struct file *h_file;
16700 + struct super_block *sb;
16701 + struct dentry *root;
16702 + struct au_branch *br;
16703 + struct aufs_wbr_fd wbrfd = {
16704 + .oflags = au_dir_roflags,
16707 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16708 + | O_NOATIME | O_CLOEXEC;
16710 + AuDebugOn(wbrfd.oflags & ~valid);
16713 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16714 + if (unlikely(err)) {
16720 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16721 + wbrfd.oflags |= au_dir_roflags;
16722 + AuDbg("0%o\n", wbrfd.oflags);
16723 + if (unlikely(wbrfd.oflags & ~valid))
16727 + fd = get_unused_fd_flags(0);
16729 + if (unlikely(fd < 0))
16732 + h_file = ERR_PTR(-EINVAL);
16735 + sb = path->dentry->d_sb;
16736 + root = sb->s_root;
16737 + aufs_read_lock(root, AuLock_IR);
16738 + bend = au_sbend(sb);
16739 + if (wbrfd.brid >= 0) {
16740 + wbi = au_br_index(sb, wbrfd.brid);
16741 + if (unlikely(wbi < 0 || wbi > bend))
16745 + h_file = ERR_PTR(-ENOENT);
16746 + br = au_sbr(sb, wbi);
16747 + if (!au_br_writable(br->br_perm)) {
16751 + bindex = wbi + 1;
16753 + for (; bindex <= bend; bindex++) {
16754 + br = au_sbr(sb, bindex);
16755 + if (au_br_writable(br->br_perm)) {
16757 + br = au_sbr(sb, wbi);
16762 + AuDbg("wbi %d\n", wbi);
16764 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
16768 + aufs_read_unlock(root, AuLock_IR);
16769 + err = PTR_ERR(h_file);
16770 + if (IS_ERR(h_file))
16773 + atomic_dec(&br->br_count); /* cf. au_h_open() */
16774 + fd_install(fd, h_file);
16776 + goto out; /* success */
16779 + put_unused_fd(fd);
16785 +/* ---------------------------------------------------------------------- */
16787 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
16790 + struct dentry *dentry;
16793 + case AUFS_CTL_RDU:
16794 + case AUFS_CTL_RDU_INO:
16795 + err = au_rdu_ioctl(file, cmd, arg);
16798 + case AUFS_CTL_WBR_FD:
16799 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16802 + case AUFS_CTL_IBUSY:
16803 + err = au_ibusy_ioctl(file, arg);
16806 + case AUFS_CTL_BRINFO:
16807 + err = au_brinfo_ioctl(file, arg);
16810 + case AUFS_CTL_FHSM_FD:
16811 + dentry = file->f_path.dentry;
16812 + if (IS_ROOT(dentry))
16813 + err = au_fhsm_fd(dentry->d_sb, arg);
16819 + /* do not call the lower */
16820 + AuDbg("0x%x\n", cmd);
16828 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
16833 + case AUFS_CTL_MVDOWN:
16834 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
16837 + case AUFS_CTL_WBR_FD:
16838 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16842 + /* do not call the lower */
16843 + AuDbg("0x%x\n", cmd);
16851 +#ifdef CONFIG_COMPAT
16852 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
16853 + unsigned long arg)
16858 + case AUFS_CTL_RDU:
16859 + case AUFS_CTL_RDU_INO:
16860 + err = au_rdu_compat_ioctl(file, cmd, arg);
16863 + case AUFS_CTL_IBUSY:
16864 + err = au_ibusy_compat_ioctl(file, arg);
16867 + case AUFS_CTL_BRINFO:
16868 + err = au_brinfo_compat_ioctl(file, arg);
16872 + err = aufs_ioctl_dir(file, cmd, arg);
16879 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
16880 + unsigned long arg)
16882 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
16885 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
16886 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
16887 +++ linux/fs/aufs/i_op_add.c 2015-04-13 15:10:20.786823613 +0200
16890 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16892 + * This program, aufs is free software; you can redistribute it and/or modify
16893 + * it under the terms of the GNU General Public License as published by
16894 + * the Free Software Foundation; either version 2 of the License, or
16895 + * (at your option) any later version.
16897 + * This program is distributed in the hope that it will be useful,
16898 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16899 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16900 + * GNU General Public License for more details.
16902 + * You should have received a copy of the GNU General Public License
16903 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16907 + * inode operations (add entry)
16913 + * final procedure of adding a new entry, except link(2).
16914 + * remove whiteout, instantiate, copyup the parent dir's times and size
16915 + * and update version.
16916 + * if it failed, re-create the removed whiteout.
16918 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
16919 + struct dentry *wh_dentry, struct dentry *dentry)
16922 + aufs_bindex_t bwh;
16923 + struct path h_path;
16924 + struct super_block *sb;
16925 + struct inode *inode, *h_dir;
16926 + struct dentry *wh;
16931 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
16932 + IMustLock(h_dir);
16933 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
16934 + bwh = au_dbwh(dentry);
16935 + h_path.dentry = wh_dentry;
16936 + h_path.mnt = au_sbr_mnt(sb, bindex);
16937 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
16939 + if (unlikely(err))
16943 + inode = au_new_inode(dentry, /*must_new*/1);
16944 + if (!IS_ERR(inode)) {
16945 + d_instantiate(dentry, inode);
16946 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
16948 + if (au_ibstart(dir) == au_dbstart(dentry))
16949 + au_cpup_attr_timesizes(dir);
16950 + dir->i_version++;
16951 + au_fhsm_wrote(sb, bindex, /*force*/0);
16952 + return 0; /* success */
16955 + err = PTR_ERR(inode);
16960 + /* dir inode is locked */
16961 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
16962 + rerr = PTR_ERR(wh);
16963 + if (IS_ERR(wh)) {
16964 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
16965 + dentry, err, rerr);
16974 +static int au_d_may_add(struct dentry *dentry)
16979 + if (unlikely(d_unhashed(dentry)))
16981 + if (unlikely(dentry->d_inode))
16987 + * simple tests for the adding inode operations.
16988 + * following the checks in vfs, plus the parent-child relationship.
16990 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16991 + struct dentry *h_parent, int isdir)
16995 + struct dentry *h_dentry;
16996 + struct inode *h_inode;
16998 + err = -ENAMETOOLONG;
16999 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17002 + h_dentry = au_h_dptr(dentry, bindex);
17003 + h_inode = h_dentry->d_inode;
17004 + if (!dentry->d_inode) {
17006 + if (unlikely(h_inode))
17009 + /* rename(2) case */
17011 + if (unlikely(!h_inode || !h_inode->i_nlink))
17014 + h_mode = h_inode->i_mode;
17017 + if (unlikely(S_ISDIR(h_mode)))
17019 + } else if (unlikely(!S_ISDIR(h_mode))) {
17026 + /* expected parent dir is locked */
17027 + if (unlikely(h_parent != h_dentry->d_parent))
17036 + * initial procedure of adding a new entry.
17037 + * prepare writable branch and the parent dir, lock it,
17038 + * and lookup whiteout for the new entry.
17040 +static struct dentry*
17041 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17042 + struct dentry *src_dentry, struct au_pin *pin,
17043 + struct au_wr_dir_args *wr_dir_args)
17045 + struct dentry *wh_dentry, *h_parent;
17046 + struct super_block *sb;
17047 + struct au_branch *br;
17049 + unsigned int udba;
17050 + aufs_bindex_t bcpup;
17052 + AuDbg("%pd\n", dentry);
17054 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17056 + wh_dentry = ERR_PTR(err);
17057 + if (unlikely(err < 0))
17060 + sb = dentry->d_sb;
17061 + udba = au_opt_udba(sb);
17062 + err = au_pin(pin, dentry, bcpup, udba,
17063 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17064 + wh_dentry = ERR_PTR(err);
17065 + if (unlikely(err))
17068 + h_parent = au_pinned_h_parent(pin);
17069 + if (udba != AuOpt_UDBA_NONE
17070 + && au_dbstart(dentry) == bcpup)
17071 + err = au_may_add(dentry, bcpup, h_parent,
17072 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17073 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17074 + err = -ENAMETOOLONG;
17075 + wh_dentry = ERR_PTR(err);
17076 + if (unlikely(err))
17079 + br = au_sbr(sb, bcpup);
17081 + struct path tmp = {
17082 + .dentry = h_parent,
17083 + .mnt = au_br_mnt(br)
17085 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17088 + wh_dentry = NULL;
17089 + if (bcpup != au_dbwh(dentry))
17090 + goto out; /* success */
17093 + * ENAMETOOLONG here means that if we allowed create such name, then it
17094 + * would not be able to removed in the future. So we don't allow such
17095 + * name here and we don't handle ENAMETOOLONG differently here.
17097 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17100 + if (IS_ERR(wh_dentry))
17103 + return wh_dentry;
17106 +/* ---------------------------------------------------------------------- */
17108 +enum { Mknod, Symlink, Creat };
17109 +struct simple_arg {
17117 + const char *symname;
17126 +static int add_simple(struct inode *dir, struct dentry *dentry,
17127 + struct simple_arg *arg)
17130 + aufs_bindex_t bstart;
17131 + unsigned char created;
17132 + struct dentry *wh_dentry, *parent;
17133 + struct inode *h_dir;
17134 + /* to reuduce stack size */
17136 + struct au_dtime dt;
17137 + struct au_pin pin;
17138 + struct path h_path;
17139 + struct au_wr_dir_args wr_dir_args;
17142 + AuDbg("%pd\n", dentry);
17146 + a = kmalloc(sizeof(*a), GFP_NOFS);
17147 + if (unlikely(!a))
17149 + a->wr_dir_args.force_btgt = -1;
17150 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17152 + parent = dentry->d_parent; /* dir inode is locked */
17153 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17154 + if (unlikely(err))
17156 + err = au_d_may_add(dentry);
17157 + if (unlikely(err))
17159 + di_write_lock_parent(parent);
17160 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17161 + &a->pin, &a->wr_dir_args);
17162 + err = PTR_ERR(wh_dentry);
17163 + if (IS_ERR(wh_dentry))
17166 + bstart = au_dbstart(dentry);
17167 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17168 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17169 + h_dir = au_pinned_h_dir(&a->pin);
17170 + switch (arg->type) {
17172 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17173 + arg->u.c.want_excl);
17176 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17179 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17187 + err = epilog(dir, bstart, wh_dentry, dentry);
17190 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
17191 + /* no delegation since it is just created */
17192 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17195 + AuIOErr("%pd revert failure(%d, %d)\n",
17196 + dentry, err, rerr);
17199 + au_dtime_revert(&a->dt);
17202 + au_unpin(&a->pin);
17206 + di_write_unlock(parent);
17208 + if (unlikely(err)) {
17209 + au_update_dbstart(dentry);
17212 + aufs_read_unlock(dentry, AuLock_DW);
17219 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17222 + struct simple_arg arg = {
17229 + return add_simple(dir, dentry, &arg);
17232 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17234 + struct simple_arg arg = {
17236 + .u.s.symname = symname
17238 + return add_simple(dir, dentry, &arg);
17241 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17244 + struct simple_arg arg = {
17248 + .want_excl = want_excl
17251 + return add_simple(dir, dentry, &arg);
17254 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17257 + aufs_bindex_t bindex;
17258 + struct super_block *sb;
17259 + struct dentry *parent, *h_parent, *h_dentry;
17260 + struct inode *h_dir, *inode;
17261 + struct vfsmount *h_mnt;
17262 + struct au_wr_dir_args wr_dir_args = {
17263 + .force_btgt = -1,
17264 + .flags = AuWrDir_TMPFILE
17267 + /* copy-up may happen */
17268 + mutex_lock(&dir->i_mutex);
17271 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17272 + if (unlikely(err))
17275 + err = au_di_init(dentry);
17276 + if (unlikely(err))
17280 + parent = d_find_any_alias(dir);
17281 + AuDebugOn(!parent);
17282 + di_write_lock_parent(parent);
17283 + if (unlikely(parent->d_inode != dir))
17286 + err = au_digen_test(parent, au_sigen(sb));
17287 + if (unlikely(err))
17290 + bindex = au_dbstart(parent);
17291 + au_set_dbstart(dentry, bindex);
17292 + au_set_dbend(dentry, bindex);
17293 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17295 + if (unlikely(err < 0))
17298 + err = -EOPNOTSUPP;
17299 + h_dir = au_h_iptr(dir, bindex);
17300 + if (unlikely(!h_dir->i_op->tmpfile))
17303 + h_mnt = au_sbr_mnt(sb, bindex);
17304 + err = vfsub_mnt_want_write(h_mnt);
17305 + if (unlikely(err))
17308 + h_parent = au_h_dptr(parent, bindex);
17309 + err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
17310 + if (unlikely(err))
17314 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17315 + if (unlikely(!h_dentry))
17318 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17319 + if (unlikely(err))
17322 + au_set_dbstart(dentry, bindex);
17323 + au_set_dbend(dentry, bindex);
17324 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17325 + inode = au_new_inode(dentry, /*must_new*/1);
17326 + if (IS_ERR(inode)) {
17327 + err = PTR_ERR(inode);
17328 + au_set_h_dptr(dentry, bindex, NULL);
17329 + au_set_dbstart(dentry, -1);
17330 + au_set_dbend(dentry, -1);
17332 + if (!inode->i_nlink)
17333 + set_nlink(inode, 1);
17334 + d_tmpfile(dentry, inode);
17335 + au_di(dentry)->di_tmpfile = 1;
17337 + /* update without i_mutex */
17338 + if (au_ibstart(dir) == au_dbstart(dentry))
17339 + au_cpup_attr_timesizes(dir);
17345 + vfsub_mnt_drop_write(h_mnt);
17347 + di_write_unlock(parent);
17349 + di_write_unlock(dentry);
17352 + /* verbose coding for lock class name */
17353 + au_rw_class(&au_di(dentry)->di_rwsem,
17354 + au_lc_key + AuLcNonDir_DIINFO);
17359 + au_di_fin(dentry);
17360 + dentry->d_fsdata = NULL;
17363 + si_read_unlock(sb);
17365 + mutex_unlock(&dir->i_mutex);
17369 +/* ---------------------------------------------------------------------- */
17371 +struct au_link_args {
17372 + aufs_bindex_t bdst, bsrc;
17373 + struct au_pin pin;
17374 + struct path h_path;
17375 + struct dentry *src_parent, *parent;
17378 +static int au_cpup_before_link(struct dentry *src_dentry,
17379 + struct au_link_args *a)
17382 + struct dentry *h_src_dentry;
17383 + struct au_cp_generic cpg = {
17384 + .dentry = src_dentry,
17389 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17392 + di_read_lock_parent(a->src_parent, AuLock_IR);
17393 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17394 + if (unlikely(err))
17397 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17398 + err = au_pin(&a->pin, src_dentry, a->bdst,
17399 + au_opt_udba(src_dentry->d_sb),
17400 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17401 + if (unlikely(err))
17404 + err = au_sio_cpup_simple(&cpg);
17405 + au_unpin(&a->pin);
17408 + di_read_unlock(a->src_parent, AuLock_IR);
17412 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17413 + struct au_link_args *a)
17416 + unsigned char plink;
17417 + aufs_bindex_t bend;
17418 + struct dentry *h_src_dentry;
17419 + struct inode *h_inode, *inode, *delegated;
17420 + struct super_block *sb;
17421 + struct file *h_file;
17425 + sb = src_dentry->d_sb;
17426 + inode = src_dentry->d_inode;
17427 + if (au_ibstart(inode) <= a->bdst)
17428 + h_inode = au_h_iptr(inode, a->bdst);
17429 + if (!h_inode || !h_inode->i_nlink) {
17430 + /* copyup src_dentry as the name of dentry. */
17431 + bend = au_dbend(dentry);
17432 + if (bend < a->bsrc)
17433 + au_set_dbend(dentry, a->bsrc);
17434 + au_set_h_dptr(dentry, a->bsrc,
17435 + dget(au_h_dptr(src_dentry, a->bsrc)));
17436 + dget(a->h_path.dentry);
17437 + au_set_h_dptr(dentry, a->bdst, NULL);
17438 + AuDbg("temporary d_inode...\n");
17439 + spin_lock(&dentry->d_lock);
17440 + dentry->d_inode = src_dentry->d_inode; /* tmp */
17441 + spin_unlock(&dentry->d_lock);
17442 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17443 + if (IS_ERR(h_file))
17444 + err = PTR_ERR(h_file);
17446 + struct au_cp_generic cpg = {
17447 + .dentry = dentry,
17452 + .flags = AuCpup_KEEPLINO
17454 + err = au_sio_cpup_simple(&cpg);
17455 + au_h_open_post(dentry, a->bsrc, h_file);
17457 + dput(a->h_path.dentry);
17458 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17460 + au_set_h_dptr(dentry, a->bdst,
17461 + a->h_path.dentry);
17463 + spin_lock(&dentry->d_lock);
17464 + dentry->d_inode = NULL; /* restore */
17465 + spin_unlock(&dentry->d_lock);
17466 + AuDbg("temporary d_inode...done\n");
17467 + au_set_h_dptr(dentry, a->bsrc, NULL);
17468 + au_set_dbend(dentry, bend);
17470 + /* the inode of src_dentry already exists on a.bdst branch */
17471 + h_src_dentry = d_find_alias(h_inode);
17472 + if (!h_src_dentry && au_plink_test(inode)) {
17474 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17475 + err = PTR_ERR(h_src_dentry);
17476 + if (IS_ERR(h_src_dentry))
17479 + if (unlikely(!h_src_dentry->d_inode)) {
17480 + dput(h_src_dentry);
17481 + h_src_dentry = NULL;
17485 + if (h_src_dentry) {
17486 + delegated = NULL;
17487 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17488 + &a->h_path, &delegated);
17489 + if (unlikely(err == -EWOULDBLOCK)) {
17490 + pr_warn("cannot retry for NFSv4 delegation"
17491 + " for an internal link\n");
17494 + dput(h_src_dentry);
17496 + AuIOErr("no dentry found for hi%lu on b%d\n",
17497 + h_inode->i_ino, a->bdst);
17502 + if (!err && !plink)
17503 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17510 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17511 + struct dentry *dentry)
17514 + struct au_dtime dt;
17515 + struct au_link_args *a;
17516 + struct dentry *wh_dentry, *h_src_dentry;
17517 + struct inode *inode, *delegated;
17518 + struct super_block *sb;
17519 + struct au_wr_dir_args wr_dir_args = {
17520 + /* .force_btgt = -1, */
17521 + .flags = AuWrDir_ADD_ENTRY
17525 + inode = src_dentry->d_inode;
17526 + IMustLock(inode);
17529 + a = kzalloc(sizeof(*a), GFP_NOFS);
17530 + if (unlikely(!a))
17533 + a->parent = dentry->d_parent; /* dir inode is locked */
17534 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17535 + AuLock_NOPLM | AuLock_GEN);
17536 + if (unlikely(err))
17538 + err = au_d_linkable(src_dentry);
17539 + if (unlikely(err))
17541 + err = au_d_may_add(dentry);
17542 + if (unlikely(err))
17545 + a->src_parent = dget_parent(src_dentry);
17546 + wr_dir_args.force_btgt = au_ibstart(inode);
17548 + di_write_lock_parent(a->parent);
17549 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17550 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17552 + err = PTR_ERR(wh_dentry);
17553 + if (IS_ERR(wh_dentry))
17557 + sb = dentry->d_sb;
17558 + a->bdst = au_dbstart(dentry);
17559 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17560 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17561 + a->bsrc = au_ibstart(inode);
17562 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17563 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17564 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17565 + if (!h_src_dentry) {
17566 + a->bsrc = au_dbstart(src_dentry);
17567 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17568 + AuDebugOn(!h_src_dentry);
17569 + } else if (IS_ERR(h_src_dentry)) {
17570 + err = PTR_ERR(h_src_dentry);
17574 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17575 + if (a->bdst < a->bsrc
17576 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17577 + err = au_cpup_or_link(src_dentry, dentry, a);
17579 + delegated = NULL;
17580 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17581 + &a->h_path, &delegated);
17582 + if (unlikely(err == -EWOULDBLOCK)) {
17583 + pr_warn("cannot retry for NFSv4 delegation"
17584 + " for an internal link\n");
17588 + dput(h_src_dentry);
17591 + * copyup src_dentry to the branch we process,
17592 + * and then link(2) to it.
17594 + dput(h_src_dentry);
17595 + if (a->bdst < a->bsrc
17596 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17597 + au_unpin(&a->pin);
17598 + di_write_unlock(a->parent);
17599 + err = au_cpup_before_link(src_dentry, a);
17600 + di_write_lock_parent(a->parent);
17602 + err = au_pin(&a->pin, dentry, a->bdst,
17604 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17605 + if (unlikely(err))
17609 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17611 + if (h_src_dentry && h_src_dentry->d_inode) {
17612 + delegated = NULL;
17613 + err = vfsub_link(h_src_dentry,
17614 + au_pinned_h_dir(&a->pin),
17615 + &a->h_path, &delegated);
17616 + if (unlikely(err == -EWOULDBLOCK)) {
17617 + pr_warn("cannot retry"
17618 + " for NFSv4 delegation"
17619 + " for an internal link\n");
17625 + if (unlikely(err))
17629 + a->h_path.dentry = wh_dentry;
17630 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17632 + if (unlikely(err))
17636 + dir->i_version++;
17637 + if (au_ibstart(dir) == au_dbstart(dentry))
17638 + au_cpup_attr_timesizes(dir);
17639 + inc_nlink(inode);
17640 + inode->i_ctime = dir->i_ctime;
17641 + d_instantiate(dentry, au_igrab(inode));
17642 + if (d_unhashed(a->h_path.dentry))
17643 + /* some filesystem calls d_drop() */
17645 + /* some filesystems consume an inode even hardlink */
17646 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17647 + goto out_unpin; /* success */
17650 + /* no delegation since it is just created */
17651 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17652 + /*delegated*/NULL, /*force*/0);
17653 + if (unlikely(rerr)) {
17654 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17657 + au_dtime_revert(&dt);
17659 + au_unpin(&a->pin);
17663 + di_write_unlock(a->parent);
17664 + dput(a->src_parent);
17666 + if (unlikely(err)) {
17667 + au_update_dbstart(dentry);
17670 + aufs_read_and_write_unlock2(dentry, src_dentry);
17678 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17681 + aufs_bindex_t bindex;
17682 + unsigned char diropq;
17683 + struct path h_path;
17684 + struct dentry *wh_dentry, *parent, *opq_dentry;
17685 + struct mutex *h_mtx;
17686 + struct super_block *sb;
17688 + struct au_pin pin;
17689 + struct au_dtime dt;
17690 + } *a; /* reduce the stack usage */
17691 + struct au_wr_dir_args wr_dir_args = {
17692 + .force_btgt = -1,
17693 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17699 + a = kmalloc(sizeof(*a), GFP_NOFS);
17700 + if (unlikely(!a))
17703 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17704 + if (unlikely(err))
17706 + err = au_d_may_add(dentry);
17707 + if (unlikely(err))
17710 + parent = dentry->d_parent; /* dir inode is locked */
17711 + di_write_lock_parent(parent);
17712 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17713 + &a->pin, &wr_dir_args);
17714 + err = PTR_ERR(wh_dentry);
17715 + if (IS_ERR(wh_dentry))
17718 + sb = dentry->d_sb;
17719 + bindex = au_dbstart(dentry);
17720 + h_path.dentry = au_h_dptr(dentry, bindex);
17721 + h_path.mnt = au_sbr_mnt(sb, bindex);
17722 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
17723 + if (unlikely(err))
17726 + /* make the dir opaque */
17728 + h_mtx = &h_path.dentry->d_inode->i_mutex;
17730 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
17731 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17732 + opq_dentry = au_diropq_create(dentry, bindex);
17733 + mutex_unlock(h_mtx);
17734 + err = PTR_ERR(opq_dentry);
17735 + if (IS_ERR(opq_dentry))
17737 + dput(opq_dentry);
17741 + err = epilog(dir, bindex, wh_dentry, dentry);
17744 + goto out_unpin; /* success */
17749 + AuLabel(revert opq);
17750 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17751 + rerr = au_diropq_remove(dentry, bindex);
17752 + mutex_unlock(h_mtx);
17754 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
17755 + dentry, err, rerr);
17761 + AuLabel(revert dir);
17762 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
17764 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
17765 + dentry, err, rerr);
17768 + au_dtime_revert(&a->dt);
17770 + au_unpin(&a->pin);
17773 + di_write_unlock(parent);
17775 + if (unlikely(err)) {
17776 + au_update_dbstart(dentry);
17779 + aufs_read_unlock(dentry, AuLock_DW);
17785 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
17786 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
17787 +++ linux/fs/aufs/i_op.c 2015-04-13 15:10:20.786823613 +0200
17790 + * Copyright (C) 2005-2015 Junjiro R. Okajima
17792 + * This program, aufs is free software; you can redistribute it and/or modify
17793 + * it under the terms of the GNU General Public License as published by
17794 + * the Free Software Foundation; either version 2 of the License, or
17795 + * (at your option) any later version.
17797 + * This program is distributed in the hope that it will be useful,
17798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17800 + * GNU General Public License for more details.
17802 + * You should have received a copy of the GNU General Public License
17803 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17807 + * inode operations (except add/del/rename)
17810 +#include <linux/device_cgroup.h>
17811 +#include <linux/fs_stack.h>
17812 +#include <linux/mm.h>
17813 +#include <linux/namei.h>
17814 +#include <linux/security.h>
17817 +static int h_permission(struct inode *h_inode, int mask,
17818 + struct vfsmount *h_mnt, int brperm)
17821 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
17824 + if ((write_mask && IS_IMMUTABLE(h_inode))
17825 + || ((mask & MAY_EXEC)
17826 + && S_ISREG(h_inode->i_mode)
17827 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
17828 + || !(h_inode->i_mode & S_IXUGO))))
17832 + * - skip the lower fs test in the case of write to ro branch.
17833 + * - nfs dir permission write check is optimized, but a policy for
17834 + * link/rename requires a real check.
17836 + if ((write_mask && !au_br_writable(brperm))
17837 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
17838 + && write_mask && !(mask & MAY_READ))
17839 + || !h_inode->i_op->permission) {
17840 + /* AuLabel(generic_permission); */
17841 + err = generic_permission(h_inode, mask);
17843 + /* AuLabel(h_inode->permission); */
17844 + err = h_inode->i_op->permission(h_inode, mask);
17849 + err = devcgroup_inode_permission(h_inode, mask);
17851 + err = security_inode_permission(h_inode, mask);
17855 + /* todo: do we need to call ima_path_check()? */
17856 + struct path h_path = {
17860 + err = ima_path_check(&h_path,
17861 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
17862 + IMA_COUNT_LEAVE);
17870 +static int aufs_permission(struct inode *inode, int mask)
17873 + aufs_bindex_t bindex, bend;
17874 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
17875 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
17876 + struct inode *h_inode;
17877 + struct super_block *sb;
17878 + struct au_branch *br;
17880 + /* todo: support rcu-walk? */
17881 + if (mask & MAY_NOT_BLOCK)
17884 + sb = inode->i_sb;
17885 + si_read_lock(sb, AuLock_FLUSH);
17886 + ii_read_lock_child(inode);
17888 + err = au_iigen_test(inode, au_sigen(sb));
17889 + if (unlikely(err))
17895 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
17896 + err = au_busy_or_stale();
17897 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17898 + if (unlikely(!h_inode
17899 + || (h_inode->i_mode & S_IFMT)
17900 + != (inode->i_mode & S_IFMT)))
17904 + bindex = au_ibstart(inode);
17905 + br = au_sbr(sb, bindex);
17906 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
17909 + && !special_file(h_inode->i_mode)) {
17910 + /* test whether the upper writable branch exists */
17912 + for (; bindex >= 0; bindex--)
17913 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
17921 + /* non-write to dir */
17923 + bend = au_ibend(inode);
17924 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
17925 + h_inode = au_h_iptr(inode, bindex);
17927 + err = au_busy_or_stale();
17928 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
17931 + br = au_sbr(sb, bindex);
17932 + err = h_permission(h_inode, mask, au_br_mnt(br),
17938 + ii_read_unlock(inode);
17939 + si_read_unlock(sb);
17943 +/* ---------------------------------------------------------------------- */
17945 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
17946 + unsigned int flags)
17948 + struct dentry *ret, *parent;
17949 + struct inode *inode;
17950 + struct super_block *sb;
17951 + int err, npositive;
17955 + /* todo: support rcu-walk? */
17956 + ret = ERR_PTR(-ECHILD);
17957 + if (flags & LOOKUP_RCU)
17960 + ret = ERR_PTR(-ENAMETOOLONG);
17961 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17965 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17966 + ret = ERR_PTR(err);
17967 + if (unlikely(err))
17970 + err = au_di_init(dentry);
17971 + ret = ERR_PTR(err);
17972 + if (unlikely(err))
17976 + npositive = 0; /* suppress a warning */
17977 + parent = dentry->d_parent; /* dir inode is locked */
17978 + di_read_lock_parent(parent, AuLock_IR);
17979 + err = au_alive_dir(parent);
17981 + err = au_digen_test(parent, au_sigen(sb));
17983 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
17987 + di_read_unlock(parent, AuLock_IR);
17988 + ret = ERR_PTR(err);
17989 + if (unlikely(err < 0))
17993 + inode = au_new_inode(dentry, /*must_new*/0);
17994 + if (IS_ERR(inode)) {
17995 + ret = (void *)inode;
18002 + atomic_inc(&inode->i_count);
18003 + ret = d_splice_alias(inode, dentry);
18005 + if (unlikely(d_need_lookup(dentry))) {
18006 + spin_lock(&dentry->d_lock);
18007 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18008 + spin_unlock(&dentry->d_lock);
18012 + if (!IS_ERR(ret)) {
18014 + if (ret && ret != dentry)
18015 + ii_write_unlock(inode);
18017 + ii_write_unlock(inode);
18024 + di_write_unlock(dentry);
18026 + /* verbose coding for lock class name */
18027 + if (unlikely(S_ISLNK(inode->i_mode)))
18028 + au_rw_class(&au_di(dentry)->di_rwsem,
18029 + au_lc_key + AuLcSymlink_DIINFO);
18030 + else if (unlikely(S_ISDIR(inode->i_mode)))
18031 + au_rw_class(&au_di(dentry)->di_rwsem,
18032 + au_lc_key + AuLcDir_DIINFO);
18033 + else /* likely */
18034 + au_rw_class(&au_di(dentry)->di_rwsem,
18035 + au_lc_key + AuLcNonDir_DIINFO);
18038 + si_read_unlock(sb);
18043 +/* ---------------------------------------------------------------------- */
18045 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18046 + const unsigned char add_entry, aufs_bindex_t bcpup,
18047 + aufs_bindex_t bstart)
18050 + struct dentry *h_parent;
18051 + struct inode *h_dir;
18054 + IMustLock(parent->d_inode);
18056 + di_write_lock_parent(parent);
18059 + if (!au_h_dptr(parent, bcpup)) {
18060 + if (bstart > bcpup)
18061 + err = au_cpup_dirs(dentry, bcpup);
18062 + else if (bstart < bcpup)
18063 + err = au_cpdown_dirs(dentry, bcpup);
18067 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18068 + h_parent = au_h_dptr(parent, bcpup);
18069 + h_dir = h_parent->d_inode;
18070 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18071 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18072 + /* todo: no unlock here */
18073 + mutex_unlock(&h_dir->i_mutex);
18075 + AuDbg("bcpup %d\n", bcpup);
18077 + if (!dentry->d_inode)
18078 + au_set_h_dptr(dentry, bstart, NULL);
18079 + au_update_dbrange(dentry, /*do_put_zero*/0);
18084 + di_write_unlock(parent);
18086 + err = bcpup; /* success */
18093 + * decide the branch and the parent dir where we will create a new entry.
18094 + * returns new bindex or an error.
18095 + * copyup the parent dir if needed.
18097 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18098 + struct au_wr_dir_args *args)
18101 + unsigned int flags;
18102 + aufs_bindex_t bcpup, bstart, src_bstart;
18103 + const unsigned char add_entry
18104 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18105 + | au_ftest_wrdir(args->flags, TMPFILE);
18106 + struct super_block *sb;
18107 + struct dentry *parent;
18108 + struct au_sbinfo *sbinfo;
18110 + sb = dentry->d_sb;
18111 + sbinfo = au_sbi(sb);
18112 + parent = dget_parent(dentry);
18113 + bstart = au_dbstart(dentry);
18115 + if (args->force_btgt < 0) {
18116 + if (src_dentry) {
18117 + src_bstart = au_dbstart(src_dentry);
18118 + if (src_bstart < bstart)
18119 + bcpup = src_bstart;
18120 + } else if (add_entry) {
18122 + if (au_ftest_wrdir(args->flags, ISDIR))
18123 + au_fset_wbr(flags, DIR);
18124 + err = AuWbrCreate(sbinfo, dentry, flags);
18128 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
18130 + err = AuWbrCopyup(sbinfo, dentry);
18132 + if (!IS_ROOT(dentry)) {
18133 + di_read_lock_parent(parent, !AuLock_IR);
18134 + err = AuWbrCopyup(sbinfo, dentry);
18135 + di_read_unlock(parent, !AuLock_IR);
18137 + err = AuWbrCopyup(sbinfo, dentry);
18140 + if (unlikely(err < 0))
18144 + bcpup = args->force_btgt;
18145 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
18148 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18150 + if (bcpup == bstart)
18151 + goto out; /* success */
18153 + /* copyup the new parent into the branch we process */
18154 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18156 + if (!dentry->d_inode) {
18157 + au_set_h_dptr(dentry, bstart, NULL);
18158 + au_set_dbstart(dentry, bcpup);
18159 + au_set_dbend(dentry, bcpup);
18161 + AuDebugOn(add_entry
18162 + && !au_ftest_wrdir(args->flags, TMPFILE)
18163 + && !au_h_dptr(dentry, bcpup));
18171 +/* ---------------------------------------------------------------------- */
18173 +void au_pin_hdir_unlock(struct au_pin *p)
18176 + au_hn_imtx_unlock(p->hdir);
18179 +int au_pin_hdir_lock(struct au_pin *p)
18187 + /* even if an error happens later, keep this lock */
18188 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18191 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
18196 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18197 + p->h_parent, p->br);
18203 +int au_pin_hdir_relock(struct au_pin *p)
18206 + struct inode *h_i;
18207 + struct dentry *h_d[] = {
18212 + err = au_pin_hdir_lock(p);
18213 + if (unlikely(err))
18216 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18219 + h_i = h_d[i]->d_inode;
18221 + err = !h_i->i_nlink;
18228 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18230 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18231 + p->hdir->hi_inode->i_mutex.owner = task;
18235 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18238 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18239 + p->lsc_hi, 0, NULL, _RET_IP_);
18240 + au_pin_hdir_set_owner(p, current);
18244 +void au_pin_hdir_release(struct au_pin *p)
18247 + au_pin_hdir_set_owner(p, p->task);
18248 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18252 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18254 + if (pin && pin->parent)
18255 + return au_h_dptr(pin->parent, pin->bindex);
18259 +void au_unpin(struct au_pin *p)
18262 + au_pin_hdir_unlock(p);
18263 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18264 + vfsub_mnt_drop_write(p->h_mnt);
18268 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18269 + di_read_unlock(p->parent, AuLock_IR);
18270 + iput(p->hdir->hi_inode);
18272 + p->parent = NULL;
18275 + /* do not clear p->task */
18278 +int au_do_pin(struct au_pin *p)
18281 + struct super_block *sb;
18282 + struct inode *h_dir;
18285 + sb = p->dentry->d_sb;
18286 + p->br = au_sbr(sb, p->bindex);
18287 + if (IS_ROOT(p->dentry)) {
18288 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18289 + p->h_mnt = au_br_mnt(p->br);
18290 + err = vfsub_mnt_want_write(p->h_mnt);
18291 + if (unlikely(err)) {
18292 + au_fclr_pin(p->flags, MNT_WRITE);
18299 + p->h_dentry = NULL;
18300 + if (p->bindex <= au_dbend(p->dentry))
18301 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18303 + p->parent = dget_parent(p->dentry);
18304 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18305 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18308 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18309 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
18311 + h_dir = p->hdir->hi_inode;
18315 + * if DI_LOCKED is not set, then p->parent may be different
18316 + * and h_parent can be NULL.
18318 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18320 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18321 + di_read_unlock(p->parent, AuLock_IR);
18323 + p->parent = NULL;
18327 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18328 + p->h_mnt = au_br_mnt(p->br);
18329 + err = vfsub_mnt_want_write(p->h_mnt);
18330 + if (unlikely(err)) {
18331 + au_fclr_pin(p->flags, MNT_WRITE);
18332 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18333 + di_read_unlock(p->parent, AuLock_IR);
18335 + p->parent = NULL;
18341 + err = au_pin_hdir_lock(p);
18343 + goto out; /* success */
18348 + pr_err("err %d\n", err);
18349 + err = au_busy_or_stale();
18354 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18355 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18356 + unsigned int udba, unsigned char flags)
18358 + p->dentry = dentry;
18360 + p->lsc_di = lsc_di;
18361 + p->lsc_hi = lsc_hi;
18362 + p->flags = flags;
18363 + p->bindex = bindex;
18365 + p->parent = NULL;
18369 + p->h_dentry = NULL;
18370 + p->h_parent = NULL;
18372 + p->task = current;
18375 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18376 + unsigned int udba, unsigned char flags)
18378 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18380 + return au_do_pin(pin);
18383 +/* ---------------------------------------------------------------------- */
18386 + * ->setattr() and ->getattr() are called in various cases.
18387 + * chmod, stat: dentry is revalidated.
18388 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18390 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18392 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18393 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18396 + struct inode *inode;
18397 + struct dentry *parent;
18400 + inode = dentry->d_inode;
18401 + if (au_digen_test(dentry, sigen)) {
18402 + parent = dget_parent(dentry);
18403 + di_read_lock_parent(parent, AuLock_IR);
18404 + err = au_refresh_dentry(dentry, parent);
18405 + di_read_unlock(parent, AuLock_IR);
18413 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18414 + struct au_icpup_args *a)
18418 + aufs_bindex_t bstart, ibstart;
18419 + struct dentry *hi_wh, *parent;
18420 + struct inode *inode;
18421 + struct au_wr_dir_args wr_dir_args = {
18422 + .force_btgt = -1,
18426 + if (d_is_dir(dentry))
18427 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18428 + /* plink or hi_wh() case */
18429 + bstart = au_dbstart(dentry);
18430 + inode = dentry->d_inode;
18431 + ibstart = au_ibstart(inode);
18432 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
18433 + wr_dir_args.force_btgt = ibstart;
18434 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18435 + if (unlikely(err < 0))
18438 + if (err != bstart)
18439 + au_fset_icpup(a->flags, DID_CPUP);
18442 + a->pin_flags = AuPin_MNT_WRITE;
18444 + if (!IS_ROOT(dentry)) {
18445 + au_fset_pin(a->pin_flags, DI_LOCKED);
18446 + parent = dget_parent(dentry);
18447 + di_write_lock_parent(parent);
18450 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
18451 + if (unlikely(err))
18454 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18455 + a->h_inode = a->h_path.dentry->d_inode;
18457 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
18458 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18459 + if (ia->ia_size < i_size_read(a->h_inode))
18460 + sz = ia->ia_size;
18461 + mutex_unlock(&a->h_inode->i_mutex);
18465 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
18466 + hi_wh = au_hi_wh(inode, a->btgt);
18468 + struct au_cp_generic cpg = {
18469 + .dentry = dentry,
18475 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
18476 + if (unlikely(err))
18478 + hi_wh = au_hi_wh(inode, a->btgt);
18479 + /* todo: revalidate hi_wh? */
18484 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
18485 + di_downgrade_lock(parent, AuLock_IR);
18489 + if (!au_ftest_icpup(a->flags, DID_CPUP))
18490 + goto out; /* success */
18492 + if (!d_unhashed(dentry)) {
18493 + struct au_cp_generic cpg = {
18494 + .dentry = dentry,
18499 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18501 + err = au_sio_cpup_simple(&cpg);
18503 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18504 + } else if (!hi_wh)
18505 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18507 + a->h_path.dentry = hi_wh; /* do not dget here */
18510 + a->h_inode = a->h_path.dentry->d_inode;
18512 + goto out; /* success */
18513 + au_unpin(&a->pin);
18516 + di_write_unlock(parent);
18521 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18525 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
18528 + struct inode *inode, *delegated;
18529 + struct super_block *sb;
18530 + struct file *file;
18531 + struct au_icpup_args *a;
18533 + inode = dentry->d_inode;
18534 + IMustLock(inode);
18537 + a = kzalloc(sizeof(*a), GFP_NOFS);
18538 + if (unlikely(!a))
18541 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
18542 + ia->ia_valid &= ~ATTR_MODE;
18545 + sb = dentry->d_sb;
18546 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18547 + if (unlikely(err))
18550 + if (ia->ia_valid & ATTR_FILE) {
18551 + /* currently ftruncate(2) only */
18552 + AuDebugOn(!d_is_reg(dentry));
18553 + file = ia->ia_file;
18554 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
18555 + if (unlikely(err))
18557 + ia->ia_file = au_hf_top(file);
18558 + a->udba = AuOpt_UDBA_NONE;
18560 + /* fchmod() doesn't pass ia_file */
18561 + a->udba = au_opt_udba(sb);
18562 + di_write_lock_child(dentry);
18563 + /* no d_unlinked(), to set UDBA_NONE for root */
18564 + if (d_unhashed(dentry))
18565 + a->udba = AuOpt_UDBA_NONE;
18566 + if (a->udba != AuOpt_UDBA_NONE) {
18567 + AuDebugOn(IS_ROOT(dentry));
18568 + err = au_reval_for_attr(dentry, au_sigen(sb));
18569 + if (unlikely(err))
18574 + err = au_pin_and_icpup(dentry, ia, a);
18575 + if (unlikely(err < 0))
18577 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
18578 + ia->ia_file = NULL;
18579 + ia->ia_valid &= ~ATTR_FILE;
18582 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
18583 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
18584 + == (ATTR_MODE | ATTR_CTIME)) {
18585 + err = security_path_chmod(&a->h_path, ia->ia_mode);
18586 + if (unlikely(err))
18588 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
18589 + && (ia->ia_valid & ATTR_CTIME)) {
18590 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
18591 + if (unlikely(err))
18595 + if (ia->ia_valid & ATTR_SIZE) {
18598 + if (ia->ia_size < i_size_read(inode))
18600 + truncate_setsize(inode, ia->ia_size);
18603 + if (ia->ia_valid & ATTR_FILE)
18605 + mutex_unlock(&a->h_inode->i_mutex);
18606 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
18607 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18609 + delegated = NULL;
18611 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
18613 + err = break_deleg_wait(&delegated);
18621 + au_cpup_attr_changeable(inode);
18624 + mutex_unlock(&a->h_inode->i_mutex);
18625 + au_unpin(&a->pin);
18626 + if (unlikely(err))
18627 + au_update_dbstart(dentry);
18629 + di_write_unlock(dentry);
18631 + fi_write_unlock(file);
18632 + ia->ia_file = file;
18633 + ia->ia_valid |= ATTR_FILE;
18636 + si_read_unlock(sb);
18644 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18645 +static int au_h_path_to_set_attr(struct dentry *dentry,
18646 + struct au_icpup_args *a, struct path *h_path)
18649 + struct super_block *sb;
18651 + sb = dentry->d_sb;
18652 + a->udba = au_opt_udba(sb);
18653 + /* no d_unlinked(), to set UDBA_NONE for root */
18654 + if (d_unhashed(dentry))
18655 + a->udba = AuOpt_UDBA_NONE;
18656 + if (a->udba != AuOpt_UDBA_NONE) {
18657 + AuDebugOn(IS_ROOT(dentry));
18658 + err = au_reval_for_attr(dentry, au_sigen(sb));
18659 + if (unlikely(err))
18662 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
18663 + if (unlikely(err < 0))
18666 + h_path->dentry = a->h_path.dentry;
18667 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
18673 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
18676 + struct path h_path;
18677 + struct super_block *sb;
18678 + struct au_icpup_args *a;
18679 + struct inode *inode, *h_inode;
18681 + inode = dentry->d_inode;
18682 + IMustLock(inode);
18685 + a = kzalloc(sizeof(*a), GFP_NOFS);
18686 + if (unlikely(!a))
18689 + sb = dentry->d_sb;
18690 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18691 + if (unlikely(err))
18694 + h_path.dentry = NULL; /* silence gcc */
18695 + di_write_lock_child(dentry);
18696 + err = au_h_path_to_set_attr(dentry, a, &h_path);
18697 + if (unlikely(err))
18700 + mutex_unlock(&a->h_inode->i_mutex);
18701 + switch (arg->type) {
18702 + case AU_XATTR_SET:
18703 + err = vfsub_setxattr(h_path.dentry,
18704 + arg->u.set.name, arg->u.set.value,
18705 + arg->u.set.size, arg->u.set.flags);
18707 + case AU_XATTR_REMOVE:
18708 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
18711 + err = -EOPNOTSUPP;
18712 + h_inode = h_path.dentry->d_inode;
18713 + if (h_inode->i_op->set_acl)
18714 + err = h_inode->i_op->set_acl(h_inode,
18715 + arg->u.acl_set.acl,
18716 + arg->u.acl_set.type);
18720 + au_cpup_attr_timesizes(inode);
18722 + au_unpin(&a->pin);
18723 + if (unlikely(err))
18724 + au_update_dbstart(dentry);
18727 + di_write_unlock(dentry);
18728 + si_read_unlock(sb);
18737 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
18738 + unsigned int nlink)
18742 + inode->i_mode = st->mode;
18743 + /* don't i_[ug]id_write() here */
18744 + inode->i_uid = st->uid;
18745 + inode->i_gid = st->gid;
18746 + inode->i_atime = st->atime;
18747 + inode->i_mtime = st->mtime;
18748 + inode->i_ctime = st->ctime;
18750 + au_cpup_attr_nlink(inode, /*force*/0);
18751 + if (S_ISDIR(inode->i_mode)) {
18752 + n = inode->i_nlink;
18755 + smp_mb(); /* for i_nlink */
18756 + /* 0 can happen */
18757 + set_nlink(inode, n);
18760 + spin_lock(&inode->i_lock);
18761 + inode->i_blocks = st->blocks;
18762 + i_size_write(inode, st->size);
18763 + spin_unlock(&inode->i_lock);
18767 + * common routine for aufs_getattr() and aufs_getxattr().
18768 + * returns zero or negative (an error).
18769 + * @dentry will be read-locked in success.
18771 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
18774 + unsigned int mnt_flags, sigen;
18775 + unsigned char udba_none;
18776 + aufs_bindex_t bindex;
18777 + struct super_block *sb, *h_sb;
18778 + struct inode *inode;
18780 + h_path->mnt = NULL;
18781 + h_path->dentry = NULL;
18784 + sb = dentry->d_sb;
18785 + mnt_flags = au_mntflags(sb);
18786 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
18788 + /* support fstat(2) */
18789 + if (!d_unlinked(dentry) && !udba_none) {
18790 + sigen = au_sigen(sb);
18791 + err = au_digen_test(dentry, sigen);
18793 + di_read_lock_child(dentry, AuLock_IR);
18794 + err = au_dbrange_test(dentry);
18795 + if (unlikely(err)) {
18796 + di_read_unlock(dentry, AuLock_IR);
18800 + AuDebugOn(IS_ROOT(dentry));
18801 + di_write_lock_child(dentry);
18802 + err = au_dbrange_test(dentry);
18804 + err = au_reval_for_attr(dentry, sigen);
18806 + di_downgrade_lock(dentry, AuLock_IR);
18808 + di_write_unlock(dentry);
18813 + di_read_lock_child(dentry, AuLock_IR);
18815 + inode = dentry->d_inode;
18816 + bindex = au_ibstart(inode);
18817 + h_path->mnt = au_sbr_mnt(sb, bindex);
18818 + h_sb = h_path->mnt->mnt_sb;
18820 + && !au_test_fs_bad_iattr(h_sb)
18822 + goto out; /* success */
18824 + if (au_dbstart(dentry) == bindex)
18825 + h_path->dentry = au_h_dptr(dentry, bindex);
18826 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
18827 + h_path->dentry = au_plink_lkup(inode, bindex);
18828 + if (IS_ERR(h_path->dentry))
18829 + /* pretending success */
18830 + h_path->dentry = NULL;
18832 + dput(h_path->dentry);
18839 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
18840 + struct dentry *dentry, struct kstat *st)
18843 + unsigned char positive;
18844 + struct path h_path;
18845 + struct inode *inode;
18846 + struct super_block *sb;
18848 + inode = dentry->d_inode;
18849 + sb = dentry->d_sb;
18850 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18851 + if (unlikely(err))
18853 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
18854 + if (unlikely(err))
18856 + if (unlikely(!h_path.dentry))
18857 + /* illegally overlapped or something */
18858 + goto out_fill; /* pretending success */
18860 + positive = !!h_path.dentry->d_inode;
18862 + err = vfs_getattr(&h_path, st);
18865 + au_refresh_iattr(inode, st,
18866 + h_path.dentry->d_inode->i_nlink);
18867 + goto out_fill; /* success */
18873 + generic_fillattr(inode, st);
18875 + di_read_unlock(dentry, AuLock_IR);
18877 + si_read_unlock(sb);
18883 +/* ---------------------------------------------------------------------- */
18885 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
18889 + struct super_block *sb;
18890 + struct dentry *h_dentry;
18893 + h_dentry = au_h_dptr(dentry, bindex);
18894 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
18897 + err = security_inode_readlink(h_dentry);
18898 + if (unlikely(err))
18901 + sb = dentry->d_sb;
18902 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
18903 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
18904 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
18906 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
18912 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
18916 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
18917 + if (unlikely(err))
18919 + err = au_d_hashed_positive(dentry);
18921 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
18922 + aufs_read_unlock(dentry, AuLock_IR);
18928 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
18931 + mm_segment_t old_fs;
18938 + buf.k = (void *)__get_free_page(GFP_NOFS);
18939 + if (unlikely(!buf.k))
18942 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
18943 + if (unlikely(err))
18946 + err = au_d_hashed_positive(dentry);
18948 + old_fs = get_fs();
18949 + set_fs(KERNEL_DS);
18950 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
18953 + aufs_read_unlock(dentry, AuLock_IR);
18957 + /* will be freed by put_link */
18958 + nd_set_link(nd, buf.k);
18959 + return NULL; /* success */
18963 + free_page((unsigned long)buf.k);
18966 + return ERR_PTR(err);
18969 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
18970 + struct nameidata *nd, void *cookie __maybe_unused)
18974 + p = nd_get_link(nd);
18975 + if (!IS_ERR_OR_NULL(p))
18976 + free_page((unsigned long)p);
18979 +/* ---------------------------------------------------------------------- */
18981 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
18984 + struct super_block *sb;
18985 + struct inode *h_inode;
18987 + sb = inode->i_sb;
18988 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
18990 + si_read_lock(sb, AuLock_FLUSH);
18991 + ii_write_lock_child(inode);
18993 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18994 + err = vfsub_update_time(h_inode, ts, flags);
18997 + au_cpup_attr_timesizes(inode);
18998 + ii_write_unlock(inode);
18999 + si_read_unlock(sb);
19002 + if (!err && (flags & S_VERSION))
19003 + inode_inc_iversion(inode);
19008 +/* ---------------------------------------------------------------------- */
19010 +struct inode_operations aufs_symlink_iop = {
19011 + .permission = aufs_permission,
19012 +#ifdef CONFIG_FS_POSIX_ACL
19013 + .get_acl = aufs_get_acl,
19014 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19017 + .setattr = aufs_setattr,
19018 + .getattr = aufs_getattr,
19020 +#ifdef CONFIG_AUFS_XATTR
19021 + .setxattr = aufs_setxattr,
19022 + .getxattr = aufs_getxattr,
19023 + .listxattr = aufs_listxattr,
19024 + .removexattr = aufs_removexattr,
19027 + .readlink = aufs_readlink,
19028 + .follow_link = aufs_follow_link,
19029 + .put_link = aufs_put_link,
19031 + /* .update_time = aufs_update_time */
19034 +struct inode_operations aufs_dir_iop = {
19035 + .create = aufs_create,
19036 + .lookup = aufs_lookup,
19037 + .link = aufs_link,
19038 + .unlink = aufs_unlink,
19039 + .symlink = aufs_symlink,
19040 + .mkdir = aufs_mkdir,
19041 + .rmdir = aufs_rmdir,
19042 + .mknod = aufs_mknod,
19043 + .rename = aufs_rename,
19045 + .permission = aufs_permission,
19046 +#ifdef CONFIG_FS_POSIX_ACL
19047 + .get_acl = aufs_get_acl,
19048 + .set_acl = aufs_set_acl,
19051 + .setattr = aufs_setattr,
19052 + .getattr = aufs_getattr,
19054 +#ifdef CONFIG_AUFS_XATTR
19055 + .setxattr = aufs_setxattr,
19056 + .getxattr = aufs_getxattr,
19057 + .listxattr = aufs_listxattr,
19058 + .removexattr = aufs_removexattr,
19061 + .update_time = aufs_update_time,
19062 + /* no support for atomic_open() */
19064 + .tmpfile = aufs_tmpfile
19067 +struct inode_operations aufs_iop = {
19068 + .permission = aufs_permission,
19069 +#ifdef CONFIG_FS_POSIX_ACL
19070 + .get_acl = aufs_get_acl,
19071 + .set_acl = aufs_set_acl,
19074 + .setattr = aufs_setattr,
19075 + .getattr = aufs_getattr,
19077 +#ifdef CONFIG_AUFS_XATTR
19078 + .setxattr = aufs_setxattr,
19079 + .getxattr = aufs_getxattr,
19080 + .listxattr = aufs_listxattr,
19081 + .removexattr = aufs_removexattr,
19084 + .update_time = aufs_update_time
19086 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19087 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19088 +++ linux/fs/aufs/i_op_del.c 2015-04-13 15:10:20.786823613 +0200
19091 + * Copyright (C) 2005-2015 Junjiro R. Okajima
19093 + * This program, aufs is free software; you can redistribute it and/or modify
19094 + * it under the terms of the GNU General Public License as published by
19095 + * the Free Software Foundation; either version 2 of the License, or
19096 + * (at your option) any later version.
19098 + * This program is distributed in the hope that it will be useful,
19099 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19101 + * GNU General Public License for more details.
19103 + * You should have received a copy of the GNU General Public License
19104 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19108 + * inode operations (del entry)
19114 + * decide if a new whiteout for @dentry is necessary or not.
19115 + * when it is necessary, prepare the parent dir for the upper branch whose
19116 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19117 + * be done by caller.
19119 + * 0: wh is unnecessary
19120 + * plus: wh is necessary
19123 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19125 + int need_wh, err;
19126 + aufs_bindex_t bstart;
19127 + struct super_block *sb;
19129 + sb = dentry->d_sb;
19130 + bstart = au_dbstart(dentry);
19131 + if (*bcpup < 0) {
19133 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
19134 + err = AuWbrCopyup(au_sbi(sb), dentry);
19136 + if (unlikely(err < 0))
19140 + AuDebugOn(bstart < *bcpup
19141 + || au_test_ro(sb, *bcpup, dentry->d_inode));
19142 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19144 + if (*bcpup != bstart) {
19145 + err = au_cpup_dirs(dentry, *bcpup);
19146 + if (unlikely(err))
19150 + struct au_dinfo *dinfo, *tmp;
19152 + need_wh = -ENOMEM;
19153 + dinfo = au_di(dentry);
19154 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19156 + au_di_cp(tmp, dinfo);
19157 + au_di_swap(tmp, dinfo);
19158 + /* returns the number of positive dentries */
19159 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19160 + au_di_swap(tmp, dinfo);
19161 + au_rw_write_unlock(&tmp->di_rwsem);
19165 + AuDbg("need_wh %d\n", need_wh);
19173 + * simple tests for the del-entry operations.
19174 + * following the checks in vfs, plus the parent-child relationship.
19176 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19177 + struct dentry *h_parent, int isdir)
19181 + struct dentry *h_dentry, *h_latest;
19182 + struct inode *h_inode;
19184 + h_dentry = au_h_dptr(dentry, bindex);
19185 + h_inode = h_dentry->d_inode;
19186 + if (dentry->d_inode) {
19188 + if (unlikely(!h_inode || !h_inode->i_nlink))
19191 + h_mode = h_inode->i_mode;
19194 + if (unlikely(S_ISDIR(h_mode)))
19196 + } else if (unlikely(!S_ISDIR(h_mode))) {
19201 + /* rename(2) case */
19203 + if (unlikely(h_inode))
19208 + /* expected parent dir is locked */
19209 + if (unlikely(h_parent != h_dentry->d_parent))
19214 + * rmdir a dir may break the consistency on some filesystem.
19215 + * let's try heavy test.
19218 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19219 + && au_test_h_perm(h_parent->d_inode,
19220 + MAY_EXEC | MAY_WRITE)))
19223 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19225 + if (IS_ERR(h_latest))
19227 + if (h_latest == h_dentry)
19236 + * decide the branch where we operate for @dentry. the branch index will be set
19237 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19238 + * dir for reverting.
19239 + * when a new whiteout is necessary, create it.
19241 +static struct dentry*
19242 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19243 + struct au_dtime *dt, struct au_pin *pin)
19245 + struct dentry *wh_dentry;
19246 + struct super_block *sb;
19247 + struct path h_path;
19248 + int err, need_wh;
19249 + unsigned int udba;
19250 + aufs_bindex_t bcpup;
19252 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19253 + wh_dentry = ERR_PTR(need_wh);
19254 + if (unlikely(need_wh < 0))
19257 + sb = dentry->d_sb;
19258 + udba = au_opt_udba(sb);
19260 + err = au_pin(pin, dentry, bcpup, udba,
19261 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19262 + wh_dentry = ERR_PTR(err);
19263 + if (unlikely(err))
19266 + h_path.dentry = au_pinned_h_parent(pin);
19267 + if (udba != AuOpt_UDBA_NONE
19268 + && au_dbstart(dentry) == bcpup) {
19269 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19270 + wh_dentry = ERR_PTR(err);
19271 + if (unlikely(err))
19275 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19276 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19277 + wh_dentry = NULL;
19279 + goto out; /* success, no need to create whiteout */
19281 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19282 + if (IS_ERR(wh_dentry))
19285 + /* returns with the parent is locked and wh_dentry is dget-ed */
19286 + goto out; /* success */
19291 + return wh_dentry;
19295 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19296 + * in order to be revertible and save time for removing many child whiteouts
19298 + * returns 1 when there are too many child whiteout and caller should remove
19299 + * them asynchronously. returns 0 when the number of children is enough small to
19300 + * remove now or the branch fs is a remote fs.
19301 + * otherwise return an error.
19303 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19304 + struct au_nhash *whlist, struct inode *dir)
19306 + int rmdir_later, err, dirwh;
19307 + struct dentry *h_dentry;
19308 + struct super_block *sb;
19310 + sb = dentry->d_sb;
19311 + SiMustAnyLock(sb);
19312 + h_dentry = au_h_dptr(dentry, bindex);
19313 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19314 + if (unlikely(err))
19317 + /* stop monitoring */
19318 + au_hn_free(au_hi(dentry->d_inode, bindex));
19320 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19321 + dirwh = au_sbi(sb)->si_dirwh;
19322 + rmdir_later = (dirwh <= 1);
19323 + if (!rmdir_later)
19324 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19327 + return rmdir_later;
19330 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19331 + if (unlikely(err)) {
19332 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19333 + h_dentry, bindex, err);
19343 + * final procedure for deleting a entry.
19344 + * maintain dentry and iattr.
19346 +static void epilog(struct inode *dir, struct dentry *dentry,
19347 + aufs_bindex_t bindex)
19349 + struct inode *inode;
19351 + inode = dentry->d_inode;
19353 + inode->i_ctime = dir->i_ctime;
19355 + if (au_ibstart(dir) == bindex)
19356 + au_cpup_attr_timesizes(dir);
19357 + dir->i_version++;
19361 + * when an error happened, remove the created whiteout and revert everything.
19363 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
19364 + aufs_bindex_t bwh, struct dentry *wh_dentry,
19365 + struct dentry *dentry, struct au_dtime *dt)
19368 + struct path h_path = {
19369 + .dentry = wh_dentry,
19370 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
19373 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
19375 + au_set_dbwh(dentry, bwh);
19376 + au_dtime_revert(dt);
19380 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
19384 +/* ---------------------------------------------------------------------- */
19386 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
19389 + aufs_bindex_t bwh, bindex, bstart;
19390 + struct inode *inode, *h_dir, *delegated;
19391 + struct dentry *parent, *wh_dentry;
19392 + /* to reuduce stack size */
19394 + struct au_dtime dt;
19395 + struct au_pin pin;
19396 + struct path h_path;
19402 + a = kmalloc(sizeof(*a), GFP_NOFS);
19403 + if (unlikely(!a))
19406 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19407 + if (unlikely(err))
19409 + err = au_d_hashed_positive(dentry);
19410 + if (unlikely(err))
19412 + inode = dentry->d_inode;
19413 + IMustLock(inode);
19415 + if (unlikely(d_is_dir(dentry)))
19416 + goto out_unlock; /* possible? */
19418 + bstart = au_dbstart(dentry);
19419 + bwh = au_dbwh(dentry);
19421 + parent = dentry->d_parent; /* dir inode is locked */
19422 + di_write_lock_parent(parent);
19423 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
19425 + err = PTR_ERR(wh_dentry);
19426 + if (IS_ERR(wh_dentry))
19429 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
19430 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19431 + dget(a->h_path.dentry);
19432 + if (bindex == bstart) {
19433 + h_dir = au_pinned_h_dir(&a->pin);
19434 + delegated = NULL;
19435 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
19436 + if (unlikely(err == -EWOULDBLOCK)) {
19437 + pr_warn("cannot retry for NFSv4 delegation"
19438 + " for an internal unlink\n");
19442 + /* dir inode is locked */
19443 + h_dir = wh_dentry->d_parent->d_inode;
19444 + IMustLock(h_dir);
19449 + vfsub_drop_nlink(inode);
19450 + epilog(dir, dentry, bindex);
19452 + /* update target timestamps */
19453 + if (bindex == bstart) {
19454 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
19456 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19458 + /* todo: this timestamp may be reverted later */
19459 + inode->i_ctime = h_dir->i_ctime;
19460 + goto out_unpin; /* success */
19467 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19474 + au_unpin(&a->pin);
19476 + dput(a->h_path.dentry);
19478 + di_write_unlock(parent);
19480 + aufs_read_unlock(dentry, AuLock_DW);
19487 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
19489 + int err, rmdir_later;
19490 + aufs_bindex_t bwh, bindex, bstart;
19491 + struct inode *inode;
19492 + struct dentry *parent, *wh_dentry, *h_dentry;
19493 + struct au_whtmp_rmdir *args;
19494 + /* to reuduce stack size */
19496 + struct au_dtime dt;
19497 + struct au_pin pin;
19503 + a = kmalloc(sizeof(*a), GFP_NOFS);
19504 + if (unlikely(!a))
19507 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
19508 + if (unlikely(err))
19510 + err = au_alive_dir(dentry);
19511 + if (unlikely(err))
19513 + inode = dentry->d_inode;
19514 + IMustLock(inode);
19516 + if (unlikely(!d_is_dir(dentry)))
19517 + goto out_unlock; /* possible? */
19520 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
19521 + if (unlikely(!args))
19524 + parent = dentry->d_parent; /* dir inode is locked */
19525 + di_write_lock_parent(parent);
19526 + err = au_test_empty(dentry, &args->whlist);
19527 + if (unlikely(err))
19530 + bstart = au_dbstart(dentry);
19531 + bwh = au_dbwh(dentry);
19533 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
19535 + err = PTR_ERR(wh_dentry);
19536 + if (IS_ERR(wh_dentry))
19539 + h_dentry = au_h_dptr(dentry, bstart);
19542 + if (bindex == bstart) {
19543 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
19545 + rmdir_later = err;
19549 + /* stop monitoring */
19550 + au_hn_free(au_hi(inode, bstart));
19552 + /* dir inode is locked */
19553 + IMustLock(wh_dentry->d_parent->d_inode);
19558 + vfsub_dead_dir(inode);
19559 + au_set_dbdiropq(dentry, -1);
19560 + epilog(dir, dentry, bindex);
19562 + if (rmdir_later) {
19563 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
19567 + goto out_unpin; /* success */
19575 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19582 + au_unpin(&a->pin);
19586 + di_write_unlock(parent);
19588 + au_whtmp_rmdir_free(args);
19590 + aufs_read_unlock(dentry, AuLock_DW);
19597 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
19598 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
19599 +++ linux/fs/aufs/i_op_ren.c 2015-04-13 15:10:20.786823613 +0200
19602 + * Copyright (C) 2005-2015 Junjiro R. Okajima
19604 + * This program, aufs is free software; you can redistribute it and/or modify
19605 + * it under the terms of the GNU General Public License as published by
19606 + * the Free Software Foundation; either version 2 of the License, or
19607 + * (at your option) any later version.
19609 + * This program is distributed in the hope that it will be useful,
19610 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19611 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19612 + * GNU General Public License for more details.
19614 + * You should have received a copy of the GNU General Public License
19615 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19619 + * inode operation (rename entry)
19620 + * todo: this is crazy monster
19625 +enum { AuSRC, AuDST, AuSrcDst };
19626 +enum { AuPARENT, AuCHILD, AuParentChild };
19628 +#define AuRen_ISDIR 1
19629 +#define AuRen_ISSAMEDIR (1 << 1)
19630 +#define AuRen_WHSRC (1 << 2)
19631 +#define AuRen_WHDST (1 << 3)
19632 +#define AuRen_MNT_WRITE (1 << 4)
19633 +#define AuRen_DT_DSTDIR (1 << 5)
19634 +#define AuRen_DIROPQ (1 << 6)
19635 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
19636 +#define au_fset_ren(flags, name) \
19637 + do { (flags) |= AuRen_##name; } while (0)
19638 +#define au_fclr_ren(flags, name) \
19639 + do { (flags) &= ~AuRen_##name; } while (0)
19641 +struct au_ren_args {
19643 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
19645 + struct inode *dir, *inode;
19646 + struct au_hinode *hdir;
19647 + struct au_dtime dt[AuParentChild];
19648 + aufs_bindex_t bstart;
19651 +#define src_dentry sd[AuSRC].dentry
19652 +#define src_dir sd[AuSRC].dir
19653 +#define src_inode sd[AuSRC].inode
19654 +#define src_h_dentry sd[AuSRC].h_dentry
19655 +#define src_parent sd[AuSRC].parent
19656 +#define src_h_parent sd[AuSRC].h_parent
19657 +#define src_wh_dentry sd[AuSRC].wh_dentry
19658 +#define src_hdir sd[AuSRC].hdir
19659 +#define src_h_dir sd[AuSRC].hdir->hi_inode
19660 +#define src_dt sd[AuSRC].dt
19661 +#define src_bstart sd[AuSRC].bstart
19663 +#define dst_dentry sd[AuDST].dentry
19664 +#define dst_dir sd[AuDST].dir
19665 +#define dst_inode sd[AuDST].inode
19666 +#define dst_h_dentry sd[AuDST].h_dentry
19667 +#define dst_parent sd[AuDST].parent
19668 +#define dst_h_parent sd[AuDST].h_parent
19669 +#define dst_wh_dentry sd[AuDST].wh_dentry
19670 +#define dst_hdir sd[AuDST].hdir
19671 +#define dst_h_dir sd[AuDST].hdir->hi_inode
19672 +#define dst_dt sd[AuDST].dt
19673 +#define dst_bstart sd[AuDST].bstart
19675 + struct dentry *h_trap;
19676 + struct au_branch *br;
19677 + struct au_hinode *src_hinode;
19678 + struct path h_path;
19679 + struct au_nhash whlist;
19680 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
19682 + unsigned int flags;
19684 + struct au_whtmp_rmdir *thargs;
19685 + struct dentry *h_dst;
19688 +/* ---------------------------------------------------------------------- */
19691 + * functions for reverting.
19692 + * when an error happened in a single rename systemcall, we should revert
19693 + * everything as if nothing happend.
19694 + * we don't need to revert the copied-up/down the parent dir since they are
19698 +#define RevertFailure(fmt, ...) do { \
19699 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
19700 + ##__VA_ARGS__, err, rerr); \
19704 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
19708 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
19709 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
19710 + au_hn_imtx_unlock(a->src_hinode);
19711 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
19713 + RevertFailure("remove diropq %pd", a->src_dentry);
19716 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
19719 + struct inode *delegated;
19721 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
19722 + a->src_h_parent);
19723 + rerr = PTR_ERR(a->h_path.dentry);
19724 + if (IS_ERR(a->h_path.dentry)) {
19725 + RevertFailure("lkup one %pd", a->src_dentry);
19729 + delegated = NULL;
19730 + rerr = vfsub_rename(a->dst_h_dir,
19731 + au_h_dptr(a->src_dentry, a->btgt),
19732 + a->src_h_dir, &a->h_path, &delegated);
19733 + if (unlikely(rerr == -EWOULDBLOCK)) {
19734 + pr_warn("cannot retry for NFSv4 delegation"
19735 + " for an internal rename\n");
19738 + d_drop(a->h_path.dentry);
19739 + dput(a->h_path.dentry);
19740 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
19742 + RevertFailure("rename %pd", a->src_dentry);
19745 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
19748 + struct inode *delegated;
19750 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
19751 + a->dst_h_parent);
19752 + rerr = PTR_ERR(a->h_path.dentry);
19753 + if (IS_ERR(a->h_path.dentry)) {
19754 + RevertFailure("lkup one %pd", a->dst_dentry);
19757 + if (a->h_path.dentry->d_inode) {
19758 + d_drop(a->h_path.dentry);
19759 + dput(a->h_path.dentry);
19763 + delegated = NULL;
19764 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
19766 + if (unlikely(rerr == -EWOULDBLOCK)) {
19767 + pr_warn("cannot retry for NFSv4 delegation"
19768 + " for an internal rename\n");
19771 + d_drop(a->h_path.dentry);
19772 + dput(a->h_path.dentry);
19774 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
19776 + RevertFailure("rename %pd", a->h_dst);
19779 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
19783 + a->h_path.dentry = a->src_wh_dentry;
19784 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
19785 + au_set_dbwh(a->src_dentry, a->src_bwh);
19787 + RevertFailure("unlink %pd", a->src_wh_dentry);
19789 +#undef RevertFailure
19791 +/* ---------------------------------------------------------------------- */
19794 + * when we have to copyup the renaming entry, do it with the rename-target name
19795 + * in order to minimize the cost (the later actual rename is unnecessary).
19796 + * otherwise rename it on the target branch.
19798 +static int au_ren_or_cpup(struct au_ren_args *a)
19801 + struct dentry *d;
19802 + struct inode *delegated;
19804 + d = a->src_dentry;
19805 + if (au_dbstart(d) == a->btgt) {
19806 + a->h_path.dentry = a->dst_h_dentry;
19807 + if (au_ftest_ren(a->flags, DIROPQ)
19808 + && au_dbdiropq(d) == a->btgt)
19809 + au_fclr_ren(a->flags, DIROPQ);
19810 + AuDebugOn(au_dbstart(d) != a->btgt);
19811 + delegated = NULL;
19812 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
19813 + a->dst_h_dir, &a->h_path, &delegated);
19814 + if (unlikely(err == -EWOULDBLOCK)) {
19815 + pr_warn("cannot retry for NFSv4 delegation"
19816 + " for an internal rename\n");
19822 + if (!err && a->h_dst)
19823 + /* it will be set to dinfo later */
19829 +/* cf. aufs_rmdir() */
19830 +static int au_ren_del_whtmp(struct au_ren_args *a)
19833 + struct inode *dir;
19835 + dir = a->dst_dir;
19836 + SiMustAnyLock(dir->i_sb);
19837 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
19838 + au_sbi(dir->i_sb)->si_dirwh)
19839 + || au_test_fs_remote(a->h_dst->d_sb)) {
19840 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
19841 + if (unlikely(err))
19842 + pr_warn("failed removing whtmp dir %pd (%d), "
19843 + "ignored.\n", a->h_dst, err);
19845 + au_nhash_wh_free(&a->thargs->whlist);
19846 + a->thargs->whlist = a->whlist;
19847 + a->whlist.nh_num = 0;
19848 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
19850 + a->thargs = NULL;
19856 +/* make it 'opaque' dir. */
19857 +static int au_ren_diropq(struct au_ren_args *a)
19860 + struct dentry *diropq;
19863 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
19864 + a->src_hinode = au_hi(a->src_inode, a->btgt);
19865 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
19866 + diropq = au_diropq_create(a->src_dentry, a->btgt);
19867 + au_hn_imtx_unlock(a->src_hinode);
19868 + if (IS_ERR(diropq))
19869 + err = PTR_ERR(diropq);
19876 +static int do_rename(struct au_ren_args *a)
19879 + struct dentry *d, *h_d;
19881 + /* prepare workqueue args for asynchronous rmdir */
19882 + h_d = a->dst_h_dentry;
19883 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
19885 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
19886 + if (unlikely(!a->thargs))
19888 + a->h_dst = dget(h_d);
19891 + /* create whiteout for src_dentry */
19892 + if (au_ftest_ren(a->flags, WHSRC)) {
19893 + a->src_bwh = au_dbwh(a->src_dentry);
19894 + AuDebugOn(a->src_bwh >= 0);
19896 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
19897 + err = PTR_ERR(a->src_wh_dentry);
19898 + if (IS_ERR(a->src_wh_dentry))
19902 + /* lookup whiteout for dentry */
19903 + if (au_ftest_ren(a->flags, WHDST)) {
19904 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
19906 + err = PTR_ERR(h_d);
19909 + if (!h_d->d_inode)
19912 + a->dst_wh_dentry = h_d;
19915 + /* rename dentry to tmpwh */
19917 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
19918 + if (unlikely(err))
19921 + d = a->dst_dentry;
19922 + au_set_h_dptr(d, a->btgt, NULL);
19923 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
19924 + if (unlikely(err))
19926 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
19929 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
19931 + /* rename by vfs_rename or cpup */
19932 + d = a->dst_dentry;
19933 + if (au_ftest_ren(a->flags, ISDIR)
19934 + && (a->dst_wh_dentry
19935 + || au_dbdiropq(d) == a->btgt
19936 + /* hide the lower to keep xino */
19937 + || a->btgt < au_dbend(d)
19938 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
19939 + au_fset_ren(a->flags, DIROPQ);
19940 + err = au_ren_or_cpup(a);
19941 + if (unlikely(err))
19942 + /* leave the copied-up one */
19945 + /* make dir opaque */
19946 + if (au_ftest_ren(a->flags, DIROPQ)) {
19947 + err = au_ren_diropq(a);
19948 + if (unlikely(err))
19952 + /* update target timestamps */
19953 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
19954 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
19955 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
19956 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19958 + /* remove whiteout for dentry */
19959 + if (a->dst_wh_dentry) {
19960 + a->h_path.dentry = a->dst_wh_dentry;
19961 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
19963 + if (unlikely(err))
19967 + /* remove whtmp */
19969 + au_ren_del_whtmp(a); /* ignore this error */
19971 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
19973 + goto out_success;
19976 + if (au_ftest_ren(a->flags, DIROPQ))
19977 + au_ren_rev_diropq(err, a);
19979 + au_ren_rev_rename(err, a);
19983 + au_ren_rev_whtmp(err, a);
19985 + dput(a->dst_wh_dentry);
19986 + a->dst_wh_dentry = NULL;
19988 + if (a->src_wh_dentry)
19989 + au_ren_rev_whsrc(err, a);
19991 + dput(a->src_wh_dentry);
19992 + dput(a->dst_wh_dentry);
19996 + au_whtmp_rmdir_free(a->thargs);
19997 + a->thargs = NULL;
20003 +/* ---------------------------------------------------------------------- */
20006 + * test if @dentry dir can be rename destination or not.
20007 + * success means, it is a logically empty dir.
20009 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20011 + return au_test_empty(dentry, whlist);
20015 + * test if @dentry dir can be rename source or not.
20016 + * if it can, return 0 and @children is filled.
20018 + * - it is a logically empty dir.
20019 + * - or, it exists on writable branch and has no children including whiteouts
20020 + * on the lower branch.
20022 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20025 + unsigned int rdhash;
20026 + aufs_bindex_t bstart;
20028 + bstart = au_dbstart(dentry);
20029 + if (bstart != btgt) {
20030 + struct au_nhash whlist;
20032 + SiMustAnyLock(dentry->d_sb);
20033 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20035 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20037 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20038 + if (unlikely(err))
20040 + err = au_test_empty(dentry, &whlist);
20041 + au_nhash_wh_free(&whlist);
20045 + if (bstart == au_dbtaildir(dentry))
20046 + return 0; /* success */
20048 + err = au_test_empty_lower(dentry);
20051 + if (err == -ENOTEMPTY) {
20052 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20053 + " is not supported\n");
20059 +/* side effect: sets whlist and h_dentry */
20060 +static int au_ren_may_dir(struct au_ren_args *a)
20063 + unsigned int rdhash;
20064 + struct dentry *d;
20066 + d = a->dst_dentry;
20067 + SiMustAnyLock(d->d_sb);
20070 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20071 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20073 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20074 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20075 + if (unlikely(err))
20078 + au_set_dbstart(d, a->dst_bstart);
20079 + err = may_rename_dstdir(d, &a->whlist);
20080 + au_set_dbstart(d, a->btgt);
20082 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20083 + if (unlikely(err))
20086 + d = a->src_dentry;
20087 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20088 + if (au_ftest_ren(a->flags, ISDIR)) {
20089 + err = may_rename_srcdir(d, a->btgt);
20090 + if (unlikely(err)) {
20091 + au_nhash_wh_free(&a->whlist);
20092 + a->whlist.nh_num = 0;
20099 +/* ---------------------------------------------------------------------- */
20102 + * simple tests for rename.
20103 + * following the checks in vfs, plus the parent-child relationship.
20105 +static int au_may_ren(struct au_ren_args *a)
20108 + struct inode *h_inode;
20110 + if (a->src_bstart == a->btgt) {
20111 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20112 + au_ftest_ren(a->flags, ISDIR));
20113 + if (unlikely(err))
20116 + if (unlikely(a->src_h_dentry == a->h_trap))
20121 + if (a->dst_bstart != a->btgt)
20124 + err = -ENOTEMPTY;
20125 + if (unlikely(a->dst_h_dentry == a->h_trap))
20129 + h_inode = a->dst_h_dentry->d_inode;
20130 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20131 + if (!a->dst_dentry->d_inode) {
20132 + if (unlikely(h_inode))
20134 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
20137 + if (unlikely(!h_inode || !h_inode->i_nlink))
20139 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
20141 + if (unlikely(err))
20146 + if (unlikely(err == -ENOENT || err == -EEXIST))
20152 +/* ---------------------------------------------------------------------- */
20157 + * - src_dir and dir by lock_rename()
20158 + * - inode if exitsts
20161 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20163 + * + di_write_lock2_child()
20164 + * + di_write_lock_child()
20165 + * + ii_write_lock_child()
20166 + * + di_write_lock_child2()
20167 + * + ii_write_lock_child2()
20168 + * + src_parent and parent
20169 + * + di_write_lock_parent()
20170 + * + ii_write_lock_parent()
20171 + * + di_write_lock_parent2()
20172 + * + ii_write_lock_parent2()
20173 + * + lower src_dir and dir by vfsub_lock_rename()
20174 + * + verify the every relationships between child and parent. if any
20175 + * of them failed, unlock all and return -EBUSY.
20177 +static void au_ren_unlock(struct au_ren_args *a)
20179 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20180 + a->dst_h_parent, a->dst_hdir);
20181 + if (au_ftest_ren(a->flags, MNT_WRITE))
20182 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20185 +static int au_ren_lock(struct au_ren_args *a)
20188 + unsigned int udba;
20191 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20192 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20193 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20194 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20196 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20197 + if (unlikely(err))
20199 + au_fset_ren(a->flags, MNT_WRITE);
20200 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20201 + a->dst_h_parent, a->dst_hdir);
20202 + udba = au_opt_udba(a->src_dentry->d_sb);
20203 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
20204 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
20205 + err = au_busy_or_stale();
20206 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20207 + err = au_h_verify(a->src_h_dentry, udba,
20208 + a->src_h_parent->d_inode, a->src_h_parent,
20210 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20211 + err = au_h_verify(a->dst_h_dentry, udba,
20212 + a->dst_h_parent->d_inode, a->dst_h_parent,
20215 + goto out; /* success */
20217 + err = au_busy_or_stale();
20218 + au_ren_unlock(a);
20224 +/* ---------------------------------------------------------------------- */
20226 +static void au_ren_refresh_dir(struct au_ren_args *a)
20228 + struct inode *dir;
20230 + dir = a->dst_dir;
20231 + dir->i_version++;
20232 + if (au_ftest_ren(a->flags, ISDIR)) {
20233 + /* is this updating defined in POSIX? */
20234 + au_cpup_attr_timesizes(a->src_inode);
20235 + au_cpup_attr_nlink(dir, /*force*/1);
20238 + if (au_ibstart(dir) == a->btgt)
20239 + au_cpup_attr_timesizes(dir);
20241 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20244 + dir = a->src_dir;
20245 + dir->i_version++;
20246 + if (au_ftest_ren(a->flags, ISDIR))
20247 + au_cpup_attr_nlink(dir, /*force*/1);
20248 + if (au_ibstart(dir) == a->btgt)
20249 + au_cpup_attr_timesizes(dir);
20252 +static void au_ren_refresh(struct au_ren_args *a)
20254 + aufs_bindex_t bend, bindex;
20255 + struct dentry *d, *h_d;
20256 + struct inode *i, *h_i;
20257 + struct super_block *sb;
20259 + d = a->dst_dentry;
20262 + /* already dget-ed by au_ren_or_cpup() */
20263 + au_set_h_dptr(d, a->btgt, a->h_dst);
20265 + i = a->dst_inode;
20267 + if (!au_ftest_ren(a->flags, ISDIR))
20268 + vfsub_drop_nlink(i);
20270 + vfsub_dead_dir(i);
20271 + au_cpup_attr_timesizes(i);
20273 + au_update_dbrange(d, /*do_put_zero*/1);
20276 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20277 + au_set_h_dptr(d, bindex, NULL);
20278 + bend = au_dbend(d);
20279 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20280 + au_set_h_dptr(d, bindex, NULL);
20281 + au_update_dbrange(d, /*do_put_zero*/0);
20284 + d = a->src_dentry;
20285 + au_set_dbwh(d, -1);
20286 + bend = au_dbend(d);
20287 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20288 + h_d = au_h_dptr(d, bindex);
20290 + au_set_h_dptr(d, bindex, NULL);
20292 + au_set_dbend(d, a->btgt);
20295 + i = a->src_inode;
20296 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20297 + return; /* success */
20299 + bend = au_ibend(i);
20300 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20301 + h_i = au_h_iptr(i, bindex);
20303 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20304 + /* ignore this error */
20305 + au_set_h_iptr(i, bindex, NULL, 0);
20308 + au_set_ibend(i, a->btgt);
20311 +/* ---------------------------------------------------------------------- */
20313 +/* mainly for link(2) and rename(2) */
20314 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20316 + aufs_bindex_t bdiropq, bwh;
20317 + struct dentry *parent;
20318 + struct au_branch *br;
20320 + parent = dentry->d_parent;
20321 + IMustLock(parent->d_inode); /* dir is locked */
20323 + bdiropq = au_dbdiropq(parent);
20324 + bwh = au_dbwh(dentry);
20325 + br = au_sbr(dentry->d_sb, btgt);
20326 + if (au_br_rdonly(br)
20327 + || (0 <= bdiropq && bdiropq < btgt)
20328 + || (0 <= bwh && bwh < btgt))
20331 + AuDbg("btgt %d\n", btgt);
20335 +/* sets src_bstart, dst_bstart and btgt */
20336 +static int au_ren_wbr(struct au_ren_args *a)
20339 + struct au_wr_dir_args wr_dir_args = {
20340 + /* .force_btgt = -1, */
20341 + .flags = AuWrDir_ADD_ENTRY
20344 + a->src_bstart = au_dbstart(a->src_dentry);
20345 + a->dst_bstart = au_dbstart(a->dst_dentry);
20346 + if (au_ftest_ren(a->flags, ISDIR))
20347 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20348 + wr_dir_args.force_btgt = a->src_bstart;
20349 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20350 + wr_dir_args.force_btgt = a->dst_bstart;
20351 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20352 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
20358 +static void au_ren_dt(struct au_ren_args *a)
20360 + a->h_path.dentry = a->src_h_parent;
20361 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
20362 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
20363 + a->h_path.dentry = a->dst_h_parent;
20364 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
20367 + au_fclr_ren(a->flags, DT_DSTDIR);
20368 + if (!au_ftest_ren(a->flags, ISDIR))
20371 + a->h_path.dentry = a->src_h_dentry;
20372 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
20373 + if (a->dst_h_dentry->d_inode) {
20374 + au_fset_ren(a->flags, DT_DSTDIR);
20375 + a->h_path.dentry = a->dst_h_dentry;
20376 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
20380 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
20382 + struct dentry *h_d;
20383 + struct mutex *h_mtx;
20385 + au_dtime_revert(a->src_dt + AuPARENT);
20386 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
20387 + au_dtime_revert(a->dst_dt + AuPARENT);
20389 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
20390 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
20391 + h_mtx = &h_d->d_inode->i_mutex;
20392 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20393 + au_dtime_revert(a->src_dt + AuCHILD);
20394 + mutex_unlock(h_mtx);
20396 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
20397 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
20398 + h_mtx = &h_d->d_inode->i_mutex;
20399 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20400 + au_dtime_revert(a->dst_dt + AuCHILD);
20401 + mutex_unlock(h_mtx);
20406 +/* ---------------------------------------------------------------------- */
20408 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
20409 + struct inode *_dst_dir, struct dentry *_dst_dentry)
20412 + /* reduce stack space */
20413 + struct au_ren_args *a;
20415 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
20416 + IMustLock(_src_dir);
20417 + IMustLock(_dst_dir);
20420 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
20421 + a = kzalloc(sizeof(*a), GFP_NOFS);
20422 + if (unlikely(!a))
20425 + a->src_dir = _src_dir;
20426 + a->src_dentry = _src_dentry;
20427 + a->src_inode = a->src_dentry->d_inode;
20428 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
20429 + a->dst_dir = _dst_dir;
20430 + a->dst_dentry = _dst_dentry;
20431 + a->dst_inode = a->dst_dentry->d_inode;
20432 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
20433 + if (a->dst_inode) {
20434 + IMustLock(a->dst_inode);
20435 + au_igrab(a->dst_inode);
20439 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
20440 + if (d_is_dir(a->src_dentry)) {
20441 + au_fset_ren(a->flags, ISDIR);
20442 + if (unlikely(d_is_positive(a->dst_dentry)
20443 + && !d_is_dir(a->dst_dentry)))
20445 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20446 + AuLock_DIR | flags);
20448 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20450 + if (unlikely(err))
20453 + err = au_d_hashed_positive(a->src_dentry);
20454 + if (unlikely(err))
20457 + if (a->dst_inode) {
20459 + * If it is a dir, VFS unhash dst_dentry before this
20460 + * function. It means we cannot rely upon d_unhashed().
20462 + if (unlikely(!a->dst_inode->i_nlink))
20464 + if (!S_ISDIR(a->dst_inode->i_mode)) {
20465 + err = au_d_hashed_positive(a->dst_dentry);
20466 + if (unlikely(err))
20468 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
20470 + } else if (unlikely(d_unhashed(a->dst_dentry)))
20474 + * is it possible?
20475 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
20476 + * there may exist a problem somewhere else.
20479 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
20482 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
20483 + di_write_lock_parent(a->dst_parent);
20485 + /* which branch we process */
20486 + err = au_ren_wbr(a);
20487 + if (unlikely(err < 0))
20489 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
20490 + a->h_path.mnt = au_br_mnt(a->br);
20492 + /* are they available to be renamed */
20493 + err = au_ren_may_dir(a);
20494 + if (unlikely(err))
20495 + goto out_children;
20497 + /* prepare the writable parent dir on the same branch */
20498 + if (a->dst_bstart == a->btgt) {
20499 + au_fset_ren(a->flags, WHDST);
20501 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
20502 + if (unlikely(err))
20503 + goto out_children;
20506 + if (a->src_dir != a->dst_dir) {
20508 + * this temporary unlock is safe,
20509 + * because both dir->i_mutex are locked.
20511 + di_write_unlock(a->dst_parent);
20512 + di_write_lock_parent(a->src_parent);
20513 + err = au_wr_dir_need_wh(a->src_dentry,
20514 + au_ftest_ren(a->flags, ISDIR),
20516 + di_write_unlock(a->src_parent);
20517 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
20518 + au_fclr_ren(a->flags, ISSAMEDIR);
20520 + err = au_wr_dir_need_wh(a->src_dentry,
20521 + au_ftest_ren(a->flags, ISDIR),
20523 + if (unlikely(err < 0))
20524 + goto out_children;
20526 + au_fset_ren(a->flags, WHSRC);
20529 + if (a->src_bstart != a->btgt) {
20530 + struct au_pin pin;
20532 + err = au_pin(&pin, a->src_dentry, a->btgt,
20533 + au_opt_udba(a->src_dentry->d_sb),
20534 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20536 + struct au_cp_generic cpg = {
20537 + .dentry = a->src_dentry,
20539 + .bsrc = a->src_bstart,
20542 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20544 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
20545 + err = au_sio_cpup_simple(&cpg);
20548 + if (unlikely(err))
20549 + goto out_children;
20550 + a->src_bstart = a->btgt;
20551 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
20552 + au_fset_ren(a->flags, WHSRC);
20555 + /* lock them all */
20556 + err = au_ren_lock(a);
20557 + if (unlikely(err))
20558 + /* leave the copied-up one */
20559 + goto out_children;
20561 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
20562 + err = au_may_ren(a);
20563 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
20564 + err = -ENAMETOOLONG;
20565 + if (unlikely(err))
20568 + /* store timestamps to be revertible */
20572 + err = do_rename(a);
20573 + if (unlikely(err))
20576 + /* update dir attributes */
20577 + au_ren_refresh_dir(a);
20579 + /* dput/iput all lower dentries */
20580 + au_ren_refresh(a);
20582 + goto out_hdir; /* success */
20585 + au_ren_rev_dt(err, a);
20587 + au_ren_unlock(a);
20589 + au_nhash_wh_free(&a->whlist);
20590 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
20591 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
20592 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
20593 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
20597 + d_move(a->src_dentry, a->dst_dentry);
20599 + au_update_dbstart(a->dst_dentry);
20600 + if (!a->dst_inode)
20601 + d_drop(a->dst_dentry);
20603 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20604 + di_write_unlock(a->dst_parent);
20606 + di_write_unlock2(a->src_parent, a->dst_parent);
20608 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
20610 + iput(a->dst_inode);
20612 + au_whtmp_rmdir_free(a->thargs);
20618 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
20619 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
20620 +++ linux/fs/aufs/Kconfig 2015-04-13 15:10:20.776823376 +0200
20623 + tristate "Aufs (Advanced multi layered unification filesystem) support"
20625 + Aufs is a stackable unification filesystem such as Unionfs,
20626 + which unifies several directories and provides a merged single
20628 + In the early days, aufs was entirely re-designed and
20629 + re-implemented Unionfs Version 1.x series. Introducing many
20630 + original ideas, approaches and improvements, it becomes totally
20631 + different from Unionfs while keeping the basic features.
20635 + prompt "Maximum number of branches"
20636 + default AUFS_BRANCH_MAX_127
20638 + Specifies the maximum number of branches (or member directories)
20639 + in a single aufs. The larger value consumes more system
20640 + resources and has a minor impact to performance.
20641 +config AUFS_BRANCH_MAX_127
20644 + Specifies the maximum number of branches (or member directories)
20645 + in a single aufs. The larger value consumes more system
20646 + resources and has a minor impact to performance.
20647 +config AUFS_BRANCH_MAX_511
20650 + Specifies the maximum number of branches (or member directories)
20651 + in a single aufs. The larger value consumes more system
20652 + resources and has a minor impact to performance.
20653 +config AUFS_BRANCH_MAX_1023
20656 + Specifies the maximum number of branches (or member directories)
20657 + in a single aufs. The larger value consumes more system
20658 + resources and has a minor impact to performance.
20659 +config AUFS_BRANCH_MAX_32767
20662 + Specifies the maximum number of branches (or member directories)
20663 + in a single aufs. The larger value consumes more system
20664 + resources and has a minor impact to performance.
20667 +config AUFS_SBILIST
20669 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
20672 + Automatic configuration for internal use.
20673 + When aufs supports Magic SysRq or /proc, enabled automatically.
20675 +config AUFS_HNOTIFY
20676 + bool "Detect direct branch access (bypassing aufs)"
20678 + If you want to modify files on branches directly, eg. bypassing aufs,
20679 + and want aufs to detect the changes of them fully, then enable this
20680 + option and use 'udba=notify' mount option.
20681 + Currently there is only one available configuration, "fsnotify".
20682 + It will have a negative impact to the performance.
20683 + See detail in aufs.5.
20686 + prompt "method" if AUFS_HNOTIFY
20687 + default AUFS_HFSNOTIFY
20688 +config AUFS_HFSNOTIFY
20693 +config AUFS_EXPORT
20694 + bool "NFS-exportable aufs"
20695 + depends on EXPORTFS
20697 + If you want to export your mounted aufs via NFS, then enable this
20698 + option. There are several requirements for this configuration.
20699 + See detail in aufs.5.
20701 +config AUFS_INO_T_64
20703 + depends on AUFS_EXPORT
20704 + depends on 64BIT && !(ALPHA || S390)
20707 + Automatic configuration for internal use.
20708 + /* typedef unsigned long/int __kernel_ino_t */
20709 + /* alpha and s390x are int */
20712 + bool "support for XATTR/EA (including Security Labels)"
20714 + If your branch fs supports XATTR/EA and you want to make them
20715 + available in aufs too, then enable this opsion and specify the
20716 + branch attributes for EA.
20717 + See detail in aufs.5.
20720 + bool "File-based Hierarchical Storage Management"
20722 + Hierarchical Storage Management (or HSM) is a well-known feature
20723 + in the storage world. Aufs provides this feature as file-based.
20724 + with multiple branches.
20725 + These multiple branches are prioritized, ie. the topmost one
20726 + should be the fastest drive and be used heavily.
20729 + bool "Readdir in userspace"
20731 + Aufs has two methods to provide a merged view for a directory,
20732 + by a user-space library and by kernel-space natively. The latter
20733 + is always enabled but sometimes large and slow.
20734 + If you enable this option, install the library in aufs2-util
20735 + package, and set some environment variables for your readdir(3),
20736 + then the work will be handled in user-space which generally
20737 + shows better performance in most cases.
20738 + See detail in aufs.5.
20741 + bool "Show whiteouts"
20743 + If you want to make the whiteouts in aufs visible, then enable
20744 + this option and specify 'shwh' mount option. Although it may
20745 + sounds like philosophy or something, but in technically it
20746 + simply shows the name of whiteout with keeping its behaviour.
20748 +config AUFS_BR_RAMFS
20749 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
20751 + If you want to use ramfs as an aufs branch fs, then enable this
20752 + option. Generally tmpfs is recommended.
20753 + Aufs prohibited them to be a branch fs by default, because
20754 + initramfs becomes unusable after switch_root or something
20755 + generally. If you sets initramfs as an aufs branch and boot your
20756 + system by switch_root, you will meet a problem easily since the
20757 + files in initramfs may be inaccessible.
20758 + Unless you are going to use ramfs as an aufs branch fs without
20759 + switch_root or something, leave it N.
20761 +config AUFS_BR_FUSE
20762 + bool "Fuse fs as an aufs branch"
20763 + depends on FUSE_FS
20766 + If you want to use fuse-based userspace filesystem as an aufs
20767 + branch fs, then enable this option.
20768 + It implements the internal poll(2) operation which is
20769 + implemented by fuse only (curretnly).
20774 + Automatic configuration for internal use.
20776 +config AUFS_BR_HFSPLUS
20777 + bool "Hfsplus as an aufs branch"
20778 + depends on HFSPLUS_FS
20781 + If you want to use hfsplus fs as an aufs branch fs, then enable
20782 + this option. This option introduces a small overhead at
20783 + copying-up a file on hfsplus.
20785 +config AUFS_BDEV_LOOP
20787 + depends on BLK_DEV_LOOP
20790 + Automatic configuration for internal use.
20791 + Convert =[ym] into =y.
20794 + bool "Debug aufs"
20796 + Enable this to compile aufs internal debug code.
20797 + It will have a negative impact to the performance.
20799 +config AUFS_MAGIC_SYSRQ
20801 + depends on AUFS_DEBUG && MAGIC_SYSRQ
20804 + Automatic configuration for internal use.
20805 + When aufs supports Magic SysRq, enabled automatically.
20807 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
20808 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
20809 +++ linux/fs/aufs/loop.c 2015-04-13 15:10:20.786823613 +0200
20812 + * Copyright (C) 2005-2015 Junjiro R. Okajima
20814 + * This program, aufs is free software; you can redistribute it and/or modify
20815 + * it under the terms of the GNU General Public License as published by
20816 + * the Free Software Foundation; either version 2 of the License, or
20817 + * (at your option) any later version.
20819 + * This program is distributed in the hope that it will be useful,
20820 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20821 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20822 + * GNU General Public License for more details.
20824 + * You should have received a copy of the GNU General Public License
20825 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20829 + * support for loopback block device as a branch
20834 +/* added into drivers/block/loop.c */
20835 +static struct file *(*backing_file_func)(struct super_block *sb);
20838 + * test if two lower dentries have overlapping branches.
20840 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
20842 + struct super_block *h_sb;
20843 + struct file *backing_file;
20845 + if (unlikely(!backing_file_func)) {
20846 + /* don't load "loop" module here */
20847 + backing_file_func = symbol_get(loop_backing_file);
20848 + if (unlikely(!backing_file_func))
20849 + /* "loop" module is not loaded */
20853 + h_sb = h_adding->d_sb;
20854 + backing_file = backing_file_func(h_sb);
20855 + if (!backing_file)
20858 + h_adding = backing_file->f_path.dentry;
20860 + * h_adding can be local NFS.
20861 + * in this case aufs cannot detect the loop.
20863 + if (unlikely(h_adding->d_sb == sb))
20865 + return !!au_test_subdir(h_adding, sb->s_root);
20868 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
20869 +int au_test_loopback_kthread(void)
20872 + struct task_struct *tsk = current;
20873 + char c, comm[sizeof(tsk->comm)];
20876 + if (tsk->flags & PF_KTHREAD) {
20877 + get_task_comm(comm, tsk);
20879 + ret = ('0' <= c && c <= '9'
20880 + && !strncmp(comm, "loop", 4));
20886 +/* ---------------------------------------------------------------------- */
20888 +#define au_warn_loopback_step 16
20889 +static int au_warn_loopback_nelem = au_warn_loopback_step;
20890 +static unsigned long *au_warn_loopback_array;
20892 +void au_warn_loopback(struct super_block *h_sb)
20894 + int i, new_nelem;
20895 + unsigned long *a, magic;
20896 + static DEFINE_SPINLOCK(spin);
20898 + magic = h_sb->s_magic;
20899 + spin_lock(&spin);
20900 + a = au_warn_loopback_array;
20901 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
20902 + if (a[i] == magic) {
20903 + spin_unlock(&spin);
20907 + /* h_sb is new to us, print it */
20908 + if (i < au_warn_loopback_nelem) {
20913 + /* expand the array */
20914 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
20915 + a = au_kzrealloc(au_warn_loopback_array,
20916 + au_warn_loopback_nelem * sizeof(unsigned long),
20917 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
20919 + au_warn_loopback_nelem = new_nelem;
20920 + au_warn_loopback_array = a;
20925 + spin_unlock(&spin);
20926 + AuWarn1("realloc failed, ignored\n");
20930 + spin_unlock(&spin);
20931 + pr_warn("you may want to try another patch for loopback file "
20932 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
20935 +int au_loopback_init(void)
20938 + struct super_block *sb __maybe_unused;
20940 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
20943 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
20944 + sizeof(unsigned long), GFP_NOFS);
20945 + if (unlikely(!au_warn_loopback_array))
20951 +void au_loopback_fin(void)
20953 + symbol_put(loop_backing_file);
20954 + kfree(au_warn_loopback_array);
20956 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
20957 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
20958 +++ linux/fs/aufs/loop.h 2015-04-13 15:10:20.786823613 +0200
20961 + * Copyright (C) 2005-2015 Junjiro R. Okajima
20963 + * This program, aufs is free software; you can redistribute it and/or modify
20964 + * it under the terms of the GNU General Public License as published by
20965 + * the Free Software Foundation; either version 2 of the License, or
20966 + * (at your option) any later version.
20968 + * This program is distributed in the hope that it will be useful,
20969 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20970 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20971 + * GNU General Public License for more details.
20973 + * You should have received a copy of the GNU General Public License
20974 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20978 + * support for loopback mount as a branch
20981 +#ifndef __AUFS_LOOP_H__
20982 +#define __AUFS_LOOP_H__
20987 +struct super_block;
20989 +#ifdef CONFIG_AUFS_BDEV_LOOP
20990 +/* drivers/block/loop.c */
20991 +struct file *loop_backing_file(struct super_block *sb);
20994 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
20995 +int au_test_loopback_kthread(void);
20996 +void au_warn_loopback(struct super_block *h_sb);
20998 +int au_loopback_init(void);
20999 +void au_loopback_fin(void);
21001 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21002 + struct dentry *h_adding)
21003 +AuStubInt0(au_test_loopback_kthread, void)
21004 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21006 +AuStubInt0(au_loopback_init, void)
21007 +AuStubVoid(au_loopback_fin, void)
21008 +#endif /* BLK_DEV_LOOP */
21010 +#endif /* __KERNEL__ */
21011 +#endif /* __AUFS_LOOP_H__ */
21012 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21013 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21014 +++ linux/fs/aufs/magic.mk 2015-04-13 15:10:20.786823613 +0200
21017 +# defined in ${srctree}/fs/fuse/inode.c
21019 +ifdef CONFIG_FUSE_FS
21020 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21023 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21025 +ifdef CONFIG_XFS_FS
21026 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21029 +# defined in ${srctree}/fs/configfs/mount.c
21031 +ifdef CONFIG_CONFIGFS_FS
21032 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21035 +# defined in ${srctree}/fs/ubifs/ubifs.h
21037 +ifdef CONFIG_UBIFS_FS
21038 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21041 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21043 +ifdef CONFIG_HFSPLUS_FS
21044 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21046 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21047 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21048 +++ linux/fs/aufs/Makefile 2015-04-13 15:10:20.776823376 +0200
21051 +include ${src}/magic.mk
21052 +ifeq (${CONFIG_AUFS_FS},m)
21053 +include ${src}/conf.mk
21055 +-include ${src}/priv_def.mk
21057 +# cf. include/linux/kernel.h
21059 +ccflags-y += -DDEBUG
21060 +# sparse requires the full pathname
21062 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21064 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21067 +obj-$(CONFIG_AUFS_FS) += aufs.o
21068 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21069 + wkq.o vfsub.o dcsub.o \
21070 + cpup.o whout.o wbr_policy.o \
21071 + dinfo.o dentry.o \
21073 + finfo.o file.o f_op.o \
21075 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21079 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21080 +aufs-$(CONFIG_SYSFS) += sysfs.o
21081 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21082 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21083 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21084 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21085 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21086 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21087 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21088 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21089 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21090 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21091 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21092 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21093 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21094 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21095 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21096 +++ linux/fs/aufs/module.c 2015-04-13 15:10:20.786823613 +0200
21099 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21101 + * This program, aufs is free software; you can redistribute it and/or modify
21102 + * it under the terms of the GNU General Public License as published by
21103 + * the Free Software Foundation; either version 2 of the License, or
21104 + * (at your option) any later version.
21106 + * This program is distributed in the hope that it will be useful,
21107 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21109 + * GNU General Public License for more details.
21111 + * You should have received a copy of the GNU General Public License
21112 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21116 + * module global variables and operations
21119 +#include <linux/module.h>
21120 +#include <linux/seq_file.h>
21123 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21125 + if (new_sz <= nused)
21128 + p = krealloc(p, new_sz, gfp);
21130 + memset(p + nused, 0, new_sz - nused);
21134 +/* ---------------------------------------------------------------------- */
21139 +struct kmem_cache *au_cachep[AuCache_Last];
21140 +static int __init au_cache_init(void)
21142 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21143 + if (au_cachep[AuCache_DINFO])
21144 + /* SLAB_DESTROY_BY_RCU */
21145 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21146 + au_icntnr_init_once);
21147 + if (au_cachep[AuCache_ICNTNR])
21148 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21149 + au_fi_init_once);
21150 + if (au_cachep[AuCache_FINFO])
21151 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21152 + if (au_cachep[AuCache_VDIR])
21153 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21154 + if (au_cachep[AuCache_DEHSTR])
21160 +static void au_cache_fin(void)
21165 + * Make sure all delayed rcu free inodes are flushed before we
21170 + /* excluding AuCache_HNOTIFY */
21171 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21172 + for (i = 0; i < AuCache_HNOTIFY; i++)
21173 + if (au_cachep[i]) {
21174 + kmem_cache_destroy(au_cachep[i]);
21175 + au_cachep[i] = NULL;
21179 +/* ---------------------------------------------------------------------- */
21181 +int au_dir_roflags;
21183 +#ifdef CONFIG_AUFS_SBILIST
21185 + * iterate_supers_type() doesn't protect us from
21186 + * remounting (branch management)
21188 +struct au_splhead au_sbilist;
21191 +struct lock_class_key au_lc_key[AuLcKey_Last];
21194 + * functions for module interface.
21196 +MODULE_LICENSE("GPL");
21197 +/* MODULE_LICENSE("GPL v2"); */
21198 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21199 +MODULE_DESCRIPTION(AUFS_NAME
21200 + " -- Advanced multi layered unification filesystem");
21201 +MODULE_VERSION(AUFS_VERSION);
21202 +MODULE_ALIAS_FS(AUFS_NAME);
21204 +/* this module parameter has no meaning when SYSFS is disabled */
21205 +int sysaufs_brs = 1;
21206 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21207 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21209 +/* this module parameter has no meaning when USER_NS is disabled */
21210 +static bool au_userns;
21211 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21212 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21214 +/* ---------------------------------------------------------------------- */
21216 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21218 +int au_seq_path(struct seq_file *seq, struct path *path)
21220 + return seq_path(seq, path, au_esc_chars);
21223 +/* ---------------------------------------------------------------------- */
21225 +static int __init aufs_init(void)
21230 + p = au_esc_chars;
21231 + for (i = 1; i <= ' '; i++)
21237 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21239 + au_sbilist_init();
21240 + sysaufs_brs_init();
21243 + err = sysaufs_init();
21244 + if (unlikely(err))
21246 + err = au_procfs_init();
21247 + if (unlikely(err))
21248 + goto out_sysaufs;
21249 + err = au_wkq_init();
21250 + if (unlikely(err))
21252 + err = au_loopback_init();
21253 + if (unlikely(err))
21255 + err = au_hnotify_init();
21256 + if (unlikely(err))
21257 + goto out_loopback;
21258 + err = au_sysrq_init();
21259 + if (unlikely(err))
21261 + err = au_cache_init();
21262 + if (unlikely(err))
21265 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21266 + err = register_filesystem(&aufs_fs_type);
21267 + if (unlikely(err))
21270 + /* since we define pr_fmt, call printk directly */
21271 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21272 + goto out; /* success */
21279 + au_hnotify_fin();
21281 + au_loopback_fin();
21293 +static void __exit aufs_exit(void)
21295 + unregister_filesystem(&aufs_fs_type);
21298 + au_hnotify_fin();
21299 + au_loopback_fin();
21306 +module_init(aufs_init);
21307 +module_exit(aufs_exit);
21308 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21309 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21310 +++ linux/fs/aufs/module.h 2015-04-13 15:10:20.786823613 +0200
21313 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21315 + * This program, aufs is free software; you can redistribute it and/or modify
21316 + * it under the terms of the GNU General Public License as published by
21317 + * the Free Software Foundation; either version 2 of the License, or
21318 + * (at your option) any later version.
21320 + * This program is distributed in the hope that it will be useful,
21321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21323 + * GNU General Public License for more details.
21325 + * You should have received a copy of the GNU General Public License
21326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21330 + * module initialization and module-global
21333 +#ifndef __AUFS_MODULE_H__
21334 +#define __AUFS_MODULE_H__
21338 +#include <linux/slab.h>
21343 +/* module parameters */
21344 +extern int sysaufs_brs;
21346 +/* ---------------------------------------------------------------------- */
21348 +extern int au_dir_roflags;
21351 + AuLcNonDir_FIINFO,
21352 + AuLcNonDir_DIINFO,
21353 + AuLcNonDir_IIINFO,
21359 + AuLcSymlink_DIINFO,
21360 + AuLcSymlink_IIINFO,
21364 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21366 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21367 +int au_seq_path(struct seq_file *seq, struct path *path);
21369 +#ifdef CONFIG_PROC_FS
21371 +int __init au_procfs_init(void);
21372 +void au_procfs_fin(void);
21374 +AuStubInt0(au_procfs_init, void);
21375 +AuStubVoid(au_procfs_fin, void);
21378 +/* ---------------------------------------------------------------------- */
21387 + AuCache_HNOTIFY, /* must be last */
21391 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21392 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21393 +#define AuCacheCtor(type, ctor) \
21394 + kmem_cache_create(#type, sizeof(struct type), \
21395 + __alignof__(struct type), AuCacheFlags, ctor)
21397 +extern struct kmem_cache *au_cachep[];
21399 +#define AuCacheFuncs(name, index) \
21400 +static inline struct au_##name *au_cache_alloc_##name(void) \
21401 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21402 +static inline void au_cache_free_##name(struct au_##name *p) \
21403 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21405 +AuCacheFuncs(dinfo, DINFO);
21406 +AuCacheFuncs(icntnr, ICNTNR);
21407 +AuCacheFuncs(finfo, FINFO);
21408 +AuCacheFuncs(vdir, VDIR);
21409 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21410 +#ifdef CONFIG_AUFS_HNOTIFY
21411 +AuCacheFuncs(hnotify, HNOTIFY);
21414 +#endif /* __KERNEL__ */
21415 +#endif /* __AUFS_MODULE_H__ */
21416 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
21417 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21418 +++ linux/fs/aufs/mvdown.c 2015-04-13 15:10:20.786823613 +0200
21421 + * Copyright (C) 2011-2015 Junjiro R. Okajima
21423 + * This program, aufs is free software; you can redistribute it and/or modify
21424 + * it under the terms of the GNU General Public License as published by
21425 + * the Free Software Foundation; either version 2 of the License, or
21426 + * (at your option) any later version.
21428 + * This program is distributed in the hope that it will be useful,
21429 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21430 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21431 + * GNU General Public License for more details.
21433 + * You should have received a copy of the GNU General Public License
21434 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21438 + * move-down, opposite of copy-up
21443 +struct au_mvd_args {
21445 + struct super_block *h_sb;
21446 + struct dentry *h_parent;
21447 + struct au_hinode *hdir;
21448 + struct inode *h_dir, *h_inode;
21449 + struct au_pin pin;
21450 + } info[AUFS_MVDOWN_NARRAY];
21452 + struct aufs_mvdown mvdown;
21453 + struct dentry *dentry, *parent;
21454 + struct inode *inode, *dir;
21455 + struct super_block *sb;
21456 + aufs_bindex_t bopq, bwh, bfound;
21457 + unsigned char rename_lock;
21460 +#define mvd_errno mvdown.au_errno
21461 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21462 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21463 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21464 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21466 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21467 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21468 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21469 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21470 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21471 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
21473 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21474 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21475 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21476 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21477 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21478 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
21480 +#define AU_MVD_PR(flag, ...) do { \
21482 + pr_err(__VA_ARGS__); \
21485 +static int find_lower_writable(struct au_mvd_args *a)
21487 + struct super_block *sb;
21488 + aufs_bindex_t bindex, bend;
21489 + struct au_branch *br;
21492 + bindex = a->mvd_bsrc;
21493 + bend = au_sbend(sb);
21494 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21495 + for (bindex++; bindex <= bend; bindex++) {
21496 + br = au_sbr(sb, bindex);
21497 + if (au_br_fhsm(br->br_perm)
21498 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21501 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21502 + for (bindex++; bindex <= bend; bindex++) {
21503 + br = au_sbr(sb, bindex);
21504 + if (!au_br_rdonly(br))
21508 + for (bindex++; bindex <= bend; bindex++) {
21509 + br = au_sbr(sb, bindex);
21510 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21511 + if (au_br_rdonly(br))
21513 + |= AUFS_MVDOWN_ROLOWER_R;
21521 +/* make the parent dir on bdst */
21522 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
21527 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
21528 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
21529 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
21530 + a->mvd_h_dst_parent = NULL;
21531 + if (au_dbend(a->parent) >= a->mvd_bdst)
21532 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21533 + if (!a->mvd_h_dst_parent) {
21534 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
21535 + if (unlikely(err)) {
21536 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
21539 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21547 +/* lock them all */
21548 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
21551 + struct dentry *h_trap;
21553 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
21554 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
21555 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
21556 + au_opt_udba(a->sb),
21557 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21559 + if (unlikely(err)) {
21560 + AU_MVD_PR(dmsg, "pin_dst failed\n");
21564 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
21565 + a->rename_lock = 0;
21566 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21567 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
21568 + au_opt_udba(a->sb),
21569 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21570 + err = au_do_pin(&a->mvd_pin_src);
21572 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
21573 + if (unlikely(err)) {
21574 + AU_MVD_PR(dmsg, "pin_src failed\n");
21577 + goto out; /* success */
21580 + a->rename_lock = 1;
21581 + au_pin_hdir_unlock(&a->mvd_pin_dst);
21582 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21583 + au_opt_udba(a->sb),
21584 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21586 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
21587 + if (unlikely(err)) {
21588 + AU_MVD_PR(dmsg, "pin_src failed\n");
21589 + au_pin_hdir_lock(&a->mvd_pin_dst);
21592 + au_pin_hdir_unlock(&a->mvd_pin_src);
21593 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21594 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21596 + err = (h_trap != a->mvd_h_src_parent);
21598 + err = (h_trap != a->mvd_h_dst_parent);
21600 + BUG_ON(err); /* it should never happen */
21601 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
21604 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21605 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21606 + au_pin_hdir_lock(&a->mvd_pin_src);
21607 + au_unpin(&a->mvd_pin_src);
21608 + au_pin_hdir_lock(&a->mvd_pin_dst);
21611 + goto out; /* success */
21614 + au_unpin(&a->mvd_pin_dst);
21620 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
21622 + if (!a->rename_lock)
21623 + au_unpin(&a->mvd_pin_src);
21625 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21626 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21627 + au_pin_hdir_lock(&a->mvd_pin_src);
21628 + au_unpin(&a->mvd_pin_src);
21629 + au_pin_hdir_lock(&a->mvd_pin_dst);
21631 + au_unpin(&a->mvd_pin_dst);
21634 +/* copy-down the file */
21635 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
21638 + struct au_cp_generic cpg = {
21639 + .dentry = a->dentry,
21640 + .bdst = a->mvd_bdst,
21641 + .bsrc = a->mvd_bsrc,
21643 + .pin = &a->mvd_pin_dst,
21644 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21647 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
21648 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21649 + au_fset_cpup(cpg.flags, OVERWRITE);
21650 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
21651 + au_fset_cpup(cpg.flags, RWDST);
21652 + err = au_sio_cpdown_simple(&cpg);
21653 + if (unlikely(err))
21654 + AU_MVD_PR(dmsg, "cpdown failed\n");
21661 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
21664 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
21667 + struct path h_path;
21668 + struct au_branch *br;
21669 + struct inode *delegated;
21671 + br = au_sbr(a->sb, a->mvd_bdst);
21672 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
21673 + err = PTR_ERR(h_path.dentry);
21674 + if (IS_ERR(h_path.dentry)) {
21675 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
21680 + if (h_path.dentry->d_inode) {
21681 + h_path.mnt = au_br_mnt(br);
21682 + delegated = NULL;
21683 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
21684 + &delegated, /*force*/0);
21685 + if (unlikely(err == -EWOULDBLOCK)) {
21686 + pr_warn("cannot retry for NFSv4 delegation"
21687 + " for an internal unlink\n");
21690 + if (unlikely(err))
21691 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
21693 + dput(h_path.dentry);
21701 + * unlink the topmost h_dentry
21703 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
21706 + struct path h_path;
21707 + struct inode *delegated;
21709 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
21710 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
21711 + delegated = NULL;
21712 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
21713 + if (unlikely(err == -EWOULDBLOCK)) {
21714 + pr_warn("cannot retry for NFSv4 delegation"
21715 + " for an internal unlink\n");
21718 + if (unlikely(err))
21719 + AU_MVD_PR(dmsg, "unlink failed\n");
21725 +/* Since mvdown succeeded, we ignore an error of this function */
21726 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
21729 + struct au_branch *br;
21731 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
21732 + br = au_sbr(a->sb, a->mvd_bsrc);
21733 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
21735 + br = au_sbr(a->sb, a->mvd_bdst);
21736 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
21737 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
21740 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
21742 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
21746 + * copy-down the file and unlink the bsrc file.
21747 + * - unlink the bdst whout if exist
21748 + * - copy-down the file (with whtmp name and rename)
21749 + * - unlink the bsrc file
21751 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
21755 + err = au_do_mkdir(dmsg, a);
21757 + err = au_do_lock(dmsg, a);
21758 + if (unlikely(err))
21762 + * do not revert the activities we made on bdst since they should be
21763 + * harmless in aufs.
21766 + err = au_do_cpdown(dmsg, a);
21768 + err = au_do_unlink_wh(dmsg, a);
21769 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
21770 + err = au_do_unlink(dmsg, a);
21771 + if (unlikely(err))
21774 + AuDbg("%pd2, 0x%x, %d --> %d\n",
21775 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
21776 + if (find_lower_writable(a) < 0)
21777 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
21779 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
21780 + au_do_stfs(dmsg, a);
21782 + /* maintain internal array */
21783 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
21784 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
21785 + au_set_dbstart(a->dentry, a->mvd_bdst);
21786 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
21787 + au_set_ibstart(a->inode, a->mvd_bdst);
21789 + if (au_dbend(a->dentry) < a->mvd_bdst)
21790 + au_set_dbend(a->dentry, a->mvd_bdst);
21791 + if (au_ibend(a->inode) < a->mvd_bdst)
21792 + au_set_ibend(a->inode, a->mvd_bdst);
21795 + au_do_unlock(dmsg, a);
21801 +/* ---------------------------------------------------------------------- */
21803 +/* make sure the file is idle */
21804 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
21806 + int err, plinked;
21809 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
21810 + if (au_dbstart(a->dentry) == a->mvd_bsrc
21811 + && au_dcount(a->dentry) == 1
21812 + && atomic_read(&a->inode->i_count) == 1
21813 + /* && a->mvd_h_src_inode->i_nlink == 1 */
21814 + && (!plinked || !au_plink_test(a->inode))
21815 + && a->inode->i_nlink == 1)
21820 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
21821 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
21822 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
21823 + a->mvd_h_src_inode->i_nlink,
21824 + plinked, plinked ? au_plink_test(a->inode) : 0);
21831 +/* make sure the parent dir is fine */
21832 +static int au_mvd_args_parent(const unsigned char dmsg,
21833 + struct au_mvd_args *a)
21836 + aufs_bindex_t bindex;
21839 + if (unlikely(au_alive_dir(a->parent))) {
21841 + AU_MVD_PR(dmsg, "parent dir is dead\n");
21845 + a->bopq = au_dbdiropq(a->parent);
21846 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
21847 + AuDbg("b%d\n", bindex);
21848 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
21849 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
21851 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
21852 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
21853 + a->bopq, a->mvd_bdst);
21861 +static int au_mvd_args_intermediate(const unsigned char dmsg,
21862 + struct au_mvd_args *a)
21865 + struct au_dinfo *dinfo, *tmp;
21867 + /* lookup the next lower positive entry */
21869 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
21870 + if (unlikely(!tmp))
21875 + dinfo = au_di(a->dentry);
21876 + au_di_cp(tmp, dinfo);
21877 + au_di_swap(tmp, dinfo);
21879 + /* returns the number of positive dentries */
21880 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
21882 + a->bwh = au_dbwh(a->dentry);
21883 + else if (err > 0)
21884 + a->bfound = au_dbstart(a->dentry);
21886 + au_di_swap(tmp, dinfo);
21887 + au_rw_write_unlock(&tmp->di_rwsem);
21889 + if (unlikely(err < 0))
21890 + AU_MVD_PR(dmsg, "failed look-up lower\n");
21893 + * here, we have these cases.
21895 + * no positive dentry under bsrc. there are more sub-cases.
21897 + * there no whiteout, we can safely move-down.
21900 + * bsrc < bwh && bwh < bdst
21901 + * there is a whiteout on RO branch. cannot proceed.
21903 + * there is a whiteout on the RW target branch. it should
21906 + * there is a whiteout somewhere unrelated branch.
21907 + * -1 < bfound && bfound <= bsrc
21910 + * found, but it is on RO branch between bsrc and bdst. cannot
21913 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
21916 + * found, after we create the file on bdst, it will be hidden.
21919 + AuDebugOn(a->bfound == -1
21921 + && a->bwh <= a->mvd_bsrc);
21922 + AuDebugOn(-1 < a->bfound
21923 + && a->bfound <= a->mvd_bsrc);
21926 + if (a->bfound == -1
21927 + && a->mvd_bsrc < a->bwh
21929 + && a->bwh < a->mvd_bdst) {
21930 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
21931 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
21932 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
21934 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
21935 + a->mvd_errno = EAU_MVDOWN_UPPER;
21936 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
21937 + a->mvd_bdst, a->bfound);
21941 + err = 0; /* success */
21948 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
21953 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21954 + && a->bfound == a->mvd_bdst)
21960 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
21963 + struct au_branch *br;
21966 + if (unlikely(S_ISDIR(a->inode->i_mode)))
21970 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
21971 + a->mvd_bsrc = au_ibstart(a->inode);
21973 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
21974 + if (unlikely(a->mvd_bsrc < 0
21975 + || (a->mvd_bsrc < au_dbstart(a->dentry)
21976 + || au_dbend(a->dentry) < a->mvd_bsrc
21977 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
21978 + || (a->mvd_bsrc < au_ibstart(a->inode)
21979 + || au_ibend(a->inode) < a->mvd_bsrc
21980 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
21981 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
21982 + AU_MVD_PR(dmsg, "no upper\n");
21986 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
21987 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
21988 + AU_MVD_PR(dmsg, "on the bottom\n");
21991 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
21992 + br = au_sbr(a->sb, a->mvd_bsrc);
21993 + err = au_br_rdonly(br);
21994 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
21995 + if (unlikely(err))
21997 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
21998 + || IS_APPEND(a->mvd_h_src_inode))) {
22000 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22006 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22007 + a->mvd_bdst = find_lower_writable(a);
22008 + if (unlikely(a->mvd_bdst < 0)) {
22009 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22010 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22014 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22015 + if (unlikely(a->mvd_bdst < 0
22016 + || au_sbend(a->sb) < a->mvd_bdst)) {
22017 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22018 + AU_MVD_PR(dmsg, "no lower brid\n");
22023 + err = au_mvd_args_busy(dmsg, a);
22025 + err = au_mvd_args_parent(dmsg, a);
22027 + err = au_mvd_args_intermediate(dmsg, a);
22029 + err = au_mvd_args_exist(dmsg, a);
22031 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22038 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22041 + unsigned char dmsg;
22042 + struct au_mvd_args *args;
22045 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22049 + args = kmalloc(sizeof(*args), GFP_NOFS);
22050 + if (unlikely(!args))
22053 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22055 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22056 + if (unlikely(err)) {
22061 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22062 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22063 + args->mvdown.au_errno = 0;
22064 + args->dentry = dentry;
22065 + args->inode = dentry->d_inode;
22066 + args->sb = dentry->d_sb;
22069 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22070 + args->parent = dget_parent(dentry);
22071 + args->dir = args->parent->d_inode;
22072 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22073 + dput(args->parent);
22074 + if (unlikely(args->parent != dentry->d_parent)) {
22075 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22079 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
22080 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
22081 + if (unlikely(err))
22084 + di_write_lock_parent(args->parent);
22085 + err = au_mvd_args(dmsg, args);
22086 + if (unlikely(err))
22089 + err = au_do_mvdown(dmsg, args);
22090 + if (unlikely(err))
22093 + au_cpup_attr_timesizes(args->dir);
22094 + au_cpup_attr_timesizes(args->inode);
22095 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
22096 + /* au_digen_dec(dentry); */
22099 + di_write_unlock(args->parent);
22100 + aufs_read_unlock(dentry, AuLock_DW);
22102 + mutex_unlock(&args->inode->i_mutex);
22104 + mutex_unlock(&args->dir->i_mutex);
22106 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22114 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22115 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22116 +++ linux/fs/aufs/opts.c 2015-04-13 15:10:20.786823613 +0200
22119 + * Copyright (C) 2005-2015 Junjiro R. Okajima
22121 + * This program, aufs is free software; you can redistribute it and/or modify
22122 + * it under the terms of the GNU General Public License as published by
22123 + * the Free Software Foundation; either version 2 of the License, or
22124 + * (at your option) any later version.
22126 + * This program is distributed in the hope that it will be useful,
22127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22129 + * GNU General Public License for more details.
22131 + * You should have received a copy of the GNU General Public License
22132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22136 + * mount options/flags
22139 +#include <linux/namei.h>
22140 +#include <linux/types.h> /* a distribution requires */
22141 +#include <linux/parser.h>
22144 +/* ---------------------------------------------------------------------- */
22148 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22149 + Opt_idel, Opt_imod,
22150 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22151 + Opt_rdblk_def, Opt_rdhash_def,
22152 + Opt_xino, Opt_noxino,
22153 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22154 + Opt_trunc_xino_path, Opt_itrunc_xino,
22155 + Opt_trunc_xib, Opt_notrunc_xib,
22156 + Opt_shwh, Opt_noshwh,
22157 + Opt_plink, Opt_noplink, Opt_list_plink,
22159 + Opt_dio, Opt_nodio,
22160 + Opt_diropq_a, Opt_diropq_w,
22161 + Opt_warn_perm, Opt_nowarn_perm,
22162 + Opt_wbr_copyup, Opt_wbr_create,
22164 + Opt_refrof, Opt_norefrof,
22165 + Opt_verbose, Opt_noverbose,
22166 + Opt_sum, Opt_nosum, Opt_wsum,
22167 + Opt_dirperm1, Opt_nodirperm1,
22168 + Opt_acl, Opt_noacl,
22169 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22172 +static match_table_t options = {
22173 + {Opt_br, "br=%s"},
22174 + {Opt_br, "br:%s"},
22176 + {Opt_add, "add=%d:%s"},
22177 + {Opt_add, "add:%d:%s"},
22178 + {Opt_add, "ins=%d:%s"},
22179 + {Opt_add, "ins:%d:%s"},
22180 + {Opt_append, "append=%s"},
22181 + {Opt_append, "append:%s"},
22182 + {Opt_prepend, "prepend=%s"},
22183 + {Opt_prepend, "prepend:%s"},
22185 + {Opt_del, "del=%s"},
22186 + {Opt_del, "del:%s"},
22187 + /* {Opt_idel, "idel:%d"}, */
22188 + {Opt_mod, "mod=%s"},
22189 + {Opt_mod, "mod:%s"},
22190 + /* {Opt_imod, "imod:%d:%s"}, */
22192 + {Opt_dirwh, "dirwh=%d"},
22194 + {Opt_xino, "xino=%s"},
22195 + {Opt_noxino, "noxino"},
22196 + {Opt_trunc_xino, "trunc_xino"},
22197 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22198 + {Opt_notrunc_xino, "notrunc_xino"},
22199 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22200 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22201 + /* {Opt_zxino, "zxino=%s"}, */
22202 + {Opt_trunc_xib, "trunc_xib"},
22203 + {Opt_notrunc_xib, "notrunc_xib"},
22205 +#ifdef CONFIG_PROC_FS
22206 + {Opt_plink, "plink"},
22208 + {Opt_ignore_silent, "plink"},
22211 + {Opt_noplink, "noplink"},
22213 +#ifdef CONFIG_AUFS_DEBUG
22214 + {Opt_list_plink, "list_plink"},
22217 + {Opt_udba, "udba=%s"},
22219 + {Opt_dio, "dio"},
22220 + {Opt_nodio, "nodio"},
22222 +#ifdef CONFIG_AUFS_FHSM
22223 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22225 + {Opt_ignore_silent, "fhsm_sec=%d"},
22228 + {Opt_diropq_a, "diropq=always"},
22229 + {Opt_diropq_a, "diropq=a"},
22230 + {Opt_diropq_w, "diropq=whiteouted"},
22231 + {Opt_diropq_w, "diropq=w"},
22233 + {Opt_warn_perm, "warn_perm"},
22234 + {Opt_nowarn_perm, "nowarn_perm"},
22236 + /* keep them temporary */
22237 + {Opt_ignore_silent, "nodlgt"},
22238 + {Opt_ignore_silent, "clean_plink"},
22240 +#ifdef CONFIG_AUFS_SHWH
22241 + {Opt_shwh, "shwh"},
22243 + {Opt_noshwh, "noshwh"},
22245 + {Opt_dirperm1, "dirperm1"},
22246 + {Opt_nodirperm1, "nodirperm1"},
22248 + {Opt_refrof, "refrof"},
22249 + {Opt_norefrof, "norefrof"},
22251 + {Opt_verbose, "verbose"},
22252 + {Opt_verbose, "v"},
22253 + {Opt_noverbose, "noverbose"},
22254 + {Opt_noverbose, "quiet"},
22255 + {Opt_noverbose, "q"},
22256 + {Opt_noverbose, "silent"},
22258 + {Opt_sum, "sum"},
22259 + {Opt_nosum, "nosum"},
22260 + {Opt_wsum, "wsum"},
22262 + {Opt_rdcache, "rdcache=%d"},
22263 + {Opt_rdblk, "rdblk=%d"},
22264 + {Opt_rdblk_def, "rdblk=def"},
22265 + {Opt_rdhash, "rdhash=%d"},
22266 + {Opt_rdhash_def, "rdhash=def"},
22268 + {Opt_wbr_create, "create=%s"},
22269 + {Opt_wbr_create, "create_policy=%s"},
22270 + {Opt_wbr_copyup, "cpup=%s"},
22271 + {Opt_wbr_copyup, "copyup=%s"},
22272 + {Opt_wbr_copyup, "copyup_policy=%s"},
22274 + /* generic VFS flag */
22275 +#ifdef CONFIG_FS_POSIX_ACL
22276 + {Opt_acl, "acl"},
22277 + {Opt_noacl, "noacl"},
22279 + {Opt_ignore_silent, "acl"},
22280 + {Opt_ignore_silent, "noacl"},
22283 + /* internal use for the scripts */
22284 + {Opt_ignore_silent, "si=%s"},
22286 + {Opt_br, "dirs=%s"},
22287 + {Opt_ignore, "debug=%d"},
22288 + {Opt_ignore, "delete=whiteout"},
22289 + {Opt_ignore, "delete=all"},
22290 + {Opt_ignore, "imap=%s"},
22292 + /* temporary workaround, due to old mount(8)? */
22293 + {Opt_ignore_silent, "relatime"},
22298 +/* ---------------------------------------------------------------------- */
22300 +static const char *au_parser_pattern(int val, match_table_t tbl)
22302 + struct match_token *p;
22305 + while (p->pattern) {
22306 + if (p->token == val)
22307 + return p->pattern;
22314 +static const char *au_optstr(int *val, match_table_t tbl)
22316 + struct match_token *p;
22323 + while (p->pattern) {
22325 + && (v & p->token) == p->token) {
22326 + *val &= ~p->token;
22327 + return p->pattern;
22336 +/* ---------------------------------------------------------------------- */
22338 +static match_table_t brperm = {
22339 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22340 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22341 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22345 +static match_table_t brattr = {
22347 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22348 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22349 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
22350 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22351 +#ifdef CONFIG_AUFS_FHSM
22352 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22354 +#ifdef CONFIG_AUFS_XATTR
22355 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
22356 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
22357 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
22358 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
22359 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
22360 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
22363 + /* ro/rr branch */
22364 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22367 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22368 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22373 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22380 + p = strchr(str, '+');
22383 + v = match_token(str, table, args);
22385 + if (v & AuBrAttr_CMOO_Mask)
22386 + attr &= ~AuBrAttr_CMOO_Mask;
22391 + pr_warn("ignored branch attribute %s\n", str);
22401 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22409 + p = au_optstr(&perm, brattr);
22412 + memcpy(q, p, sz + 1);
22418 + p = au_optstr(&perm, brattr);
22422 + memcpy(q, p, sz + 1);
22428 + return q - str->a;
22431 +static int noinline_for_stack br_perm_val(char *perm)
22433 + int val, bad, sz;
22435 + substring_t args[MAX_OPT_ARGS];
22436 + au_br_perm_str_t attr;
22438 + p = strchr(perm, '+');
22441 + val = match_token(perm, brperm, args);
22445 + pr_warn("ignored branch permission %s\n", perm);
22446 + val = AuBrPerm_RO;
22452 + val |= br_attr_val(p + 1, brattr, args);
22455 + switch (val & AuBrPerm_Mask) {
22456 + case AuBrPerm_RO:
22457 + case AuBrPerm_RR:
22458 + bad = val & AuBrWAttr_Mask;
22459 + val &= ~AuBrWAttr_Mask;
22461 + case AuBrPerm_RW:
22462 + bad = val & AuBrRAttr_Mask;
22463 + val &= ~AuBrRAttr_Mask;
22468 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
22469 + * does not treat it as an error, just warning.
22470 + * this is a tiny guard for the user operation.
22472 + if (val & AuBrAttr_UNPIN) {
22473 + bad |= AuBrAttr_UNPIN;
22474 + val &= ~AuBrAttr_UNPIN;
22477 + if (unlikely(bad)) {
22478 + sz = au_do_optstr_br_attr(&attr, bad);
22480 + pr_warn("ignored branch attribute %s\n", attr.a);
22487 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22489 + au_br_perm_str_t attr;
22495 + p = au_optstr(&perm, brperm);
22496 + AuDebugOn(!p || !*p);
22498 + memcpy(q, p, sz + 1);
22501 + sz = au_do_optstr_br_attr(&attr, perm);
22504 + memcpy(q, attr.a, sz + 1);
22507 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22510 +/* ---------------------------------------------------------------------- */
22512 +static match_table_t udbalevel = {
22513 + {AuOpt_UDBA_REVAL, "reval"},
22514 + {AuOpt_UDBA_NONE, "none"},
22515 +#ifdef CONFIG_AUFS_HNOTIFY
22516 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22517 +#ifdef CONFIG_AUFS_HFSNOTIFY
22518 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
22524 +static int noinline_for_stack udba_val(char *str)
22526 + substring_t args[MAX_OPT_ARGS];
22528 + return match_token(str, udbalevel, args);
22531 +const char *au_optstr_udba(int udba)
22533 + return au_parser_pattern(udba, udbalevel);
22536 +/* ---------------------------------------------------------------------- */
22538 +static match_table_t au_wbr_create_policy = {
22539 + {AuWbrCreate_TDP, "tdp"},
22540 + {AuWbrCreate_TDP, "top-down-parent"},
22541 + {AuWbrCreate_RR, "rr"},
22542 + {AuWbrCreate_RR, "round-robin"},
22543 + {AuWbrCreate_MFS, "mfs"},
22544 + {AuWbrCreate_MFS, "most-free-space"},
22545 + {AuWbrCreate_MFSV, "mfs:%d"},
22546 + {AuWbrCreate_MFSV, "most-free-space:%d"},
22548 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
22549 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
22550 + {AuWbrCreate_PMFS, "pmfs"},
22551 + {AuWbrCreate_PMFSV, "pmfs:%d"},
22552 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
22553 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
22559 + * cf. linux/lib/parser.c and cmdline.c
22560 + * gave up calling memparse() since it uses simple_strtoull() instead of
22563 +static int noinline_for_stack
22564 +au_match_ull(substring_t *s, unsigned long long *result)
22567 + unsigned int len;
22571 + len = s->to - s->from;
22572 + if (len + 1 <= sizeof(a)) {
22573 + memcpy(a, s->from, len);
22575 + err = kstrtoull(a, 0, result);
22580 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
22581 + struct au_opt_wbr_create *create)
22584 + unsigned long long ull;
22587 + if (!au_match_ull(arg, &ull))
22588 + create->mfsrr_watermark = ull;
22590 + pr_err("bad integer in %s\n", str);
22597 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
22598 + struct au_opt_wbr_create *create)
22603 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
22604 + create->mfs_second = n;
22606 + pr_err("bad integer in %s\n", str);
22613 +static int noinline_for_stack
22614 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
22617 + substring_t args[MAX_OPT_ARGS];
22619 + err = match_token(str, au_wbr_create_policy, args);
22620 + create->wbr_create = err;
22622 + case AuWbrCreate_MFSRRV:
22623 + case AuWbrCreate_PMFSRRV:
22624 + e = au_wbr_mfs_wmark(&args[0], str, create);
22626 + e = au_wbr_mfs_sec(&args[1], str, create);
22630 + case AuWbrCreate_MFSRR:
22631 + case AuWbrCreate_PMFSRR:
22632 + e = au_wbr_mfs_wmark(&args[0], str, create);
22633 + if (unlikely(e)) {
22638 + case AuWbrCreate_MFS:
22639 + case AuWbrCreate_PMFS:
22640 + create->mfs_second = AUFS_MFS_DEF_SEC;
22642 + case AuWbrCreate_MFSV:
22643 + case AuWbrCreate_PMFSV:
22644 + e = au_wbr_mfs_sec(&args[0], str, create);
22653 +const char *au_optstr_wbr_create(int wbr_create)
22655 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
22658 +static match_table_t au_wbr_copyup_policy = {
22659 + {AuWbrCopyup_TDP, "tdp"},
22660 + {AuWbrCopyup_TDP, "top-down-parent"},
22661 + {AuWbrCopyup_BUP, "bup"},
22662 + {AuWbrCopyup_BUP, "bottom-up-parent"},
22663 + {AuWbrCopyup_BU, "bu"},
22664 + {AuWbrCopyup_BU, "bottom-up"},
22668 +static int noinline_for_stack au_wbr_copyup_val(char *str)
22670 + substring_t args[MAX_OPT_ARGS];
22672 + return match_token(str, au_wbr_copyup_policy, args);
22675 +const char *au_optstr_wbr_copyup(int wbr_copyup)
22677 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
22680 +/* ---------------------------------------------------------------------- */
22682 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
22684 +static void dump_opts(struct au_opts *opts)
22686 +#ifdef CONFIG_AUFS_DEBUG
22687 + /* reduce stack space */
22689 + struct au_opt_add *add;
22690 + struct au_opt_del *del;
22691 + struct au_opt_mod *mod;
22692 + struct au_opt_xino *xino;
22693 + struct au_opt_xino_itrunc *xino_itrunc;
22694 + struct au_opt_wbr_create *create;
22696 + struct au_opt *opt;
22699 + while (opt->type != Opt_tail) {
22700 + switch (opt->type) {
22702 + u.add = &opt->add;
22703 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
22704 + u.add->bindex, u.add->pathname, u.add->perm,
22705 + u.add->path.dentry);
22709 + u.del = &opt->del;
22710 + AuDbg("del {%s, %p}\n",
22711 + u.del->pathname, u.del->h_path.dentry);
22715 + u.mod = &opt->mod;
22716 + AuDbg("mod {%s, 0x%x, %p}\n",
22717 + u.mod->path, u.mod->perm, u.mod->h_root);
22720 + u.add = &opt->add;
22721 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
22722 + u.add->bindex, u.add->pathname, u.add->perm,
22723 + u.add->path.dentry);
22725 + case Opt_prepend:
22726 + u.add = &opt->add;
22727 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
22728 + u.add->bindex, u.add->pathname, u.add->perm,
22729 + u.add->path.dentry);
22732 + AuDbg("dirwh %d\n", opt->dirwh);
22734 + case Opt_rdcache:
22735 + AuDbg("rdcache %d\n", opt->rdcache);
22738 + AuDbg("rdblk %u\n", opt->rdblk);
22740 + case Opt_rdblk_def:
22741 + AuDbg("rdblk_def\n");
22744 + AuDbg("rdhash %u\n", opt->rdhash);
22746 + case Opt_rdhash_def:
22747 + AuDbg("rdhash_def\n");
22750 + u.xino = &opt->xino;
22751 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
22753 + case Opt_trunc_xino:
22754 + AuLabel(trunc_xino);
22756 + case Opt_notrunc_xino:
22757 + AuLabel(notrunc_xino);
22759 + case Opt_trunc_xino_path:
22760 + case Opt_itrunc_xino:
22761 + u.xino_itrunc = &opt->xino_itrunc;
22762 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
22767 + case Opt_trunc_xib:
22768 + AuLabel(trunc_xib);
22770 + case Opt_notrunc_xib:
22771 + AuLabel(notrunc_xib);
22779 + case Opt_dirperm1:
22780 + AuLabel(dirperm1);
22782 + case Opt_nodirperm1:
22783 + AuLabel(nodirperm1);
22788 + case Opt_noplink:
22789 + AuLabel(noplink);
22791 + case Opt_list_plink:
22792 + AuLabel(list_plink);
22795 + AuDbg("udba %d, %s\n",
22796 + opt->udba, au_optstr_udba(opt->udba));
22804 + case Opt_diropq_a:
22805 + AuLabel(diropq_a);
22807 + case Opt_diropq_w:
22808 + AuLabel(diropq_w);
22810 + case Opt_warn_perm:
22811 + AuLabel(warn_perm);
22813 + case Opt_nowarn_perm:
22814 + AuLabel(nowarn_perm);
22819 + case Opt_norefrof:
22820 + AuLabel(norefrof);
22822 + case Opt_verbose:
22823 + AuLabel(verbose);
22825 + case Opt_noverbose:
22826 + AuLabel(noverbose);
22837 + case Opt_wbr_create:
22838 + u.create = &opt->wbr_create;
22839 + AuDbg("create %d, %s\n", u.create->wbr_create,
22840 + au_optstr_wbr_create(u.create->wbr_create));
22841 + switch (u.create->wbr_create) {
22842 + case AuWbrCreate_MFSV:
22843 + case AuWbrCreate_PMFSV:
22844 + AuDbg("%d sec\n", u.create->mfs_second);
22846 + case AuWbrCreate_MFSRR:
22847 + AuDbg("%llu watermark\n",
22848 + u.create->mfsrr_watermark);
22850 + case AuWbrCreate_MFSRRV:
22851 + case AuWbrCreate_PMFSRRV:
22852 + AuDbg("%llu watermark, %d sec\n",
22853 + u.create->mfsrr_watermark,
22854 + u.create->mfs_second);
22858 + case Opt_wbr_copyup:
22859 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
22860 + au_optstr_wbr_copyup(opt->wbr_copyup));
22862 + case Opt_fhsm_sec:
22863 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
22879 +void au_opts_free(struct au_opts *opts)
22881 + struct au_opt *opt;
22884 + while (opt->type != Opt_tail) {
22885 + switch (opt->type) {
22888 + case Opt_prepend:
22889 + path_put(&opt->add.path);
22893 + path_put(&opt->del.h_path);
22897 + dput(opt->mod.h_root);
22900 + fput(opt->xino.file);
22907 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
22908 + aufs_bindex_t bindex)
22911 + struct au_opt_add *add = &opt->add;
22914 + add->bindex = bindex;
22915 + add->perm = AuBrPerm_RO;
22916 + add->pathname = opt_str;
22917 + p = strchr(opt_str, '=');
22921 + add->perm = br_perm_val(p);
22924 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
22927 + add->perm = AuBrPerm_RO;
22928 + if (au_test_fs_rr(add->path.dentry->d_sb))
22929 + add->perm = AuBrPerm_RR;
22930 + else if (!bindex && !(sb_flags & MS_RDONLY))
22931 + add->perm = AuBrPerm_RW;
22933 + opt->type = Opt_add;
22936 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
22943 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
22947 + del->pathname = args[0].from;
22948 + AuDbg("del path %s\n", del->pathname);
22950 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
22951 + if (unlikely(err))
22952 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
22957 +#if 0 /* reserved for future use */
22958 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
22959 + struct au_opt_del *del, substring_t args[])
22962 + struct dentry *root;
22965 + root = sb->s_root;
22966 + aufs_read_lock(root, AuLock_FLUSH);
22967 + if (bindex < 0 || au_sbend(sb) < bindex) {
22968 + pr_err("out of bounds, %d\n", bindex);
22973 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
22974 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
22977 + aufs_read_unlock(root, !AuLock_IR);
22982 +static int noinline_for_stack
22983 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
22986 + struct path path;
22990 + mod->path = args[0].from;
22991 + p = strchr(mod->path, '=');
22992 + if (unlikely(!p)) {
22993 + pr_err("no permssion %s\n", args[0].from);
22998 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
22999 + if (unlikely(err)) {
23000 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23004 + mod->perm = br_perm_val(p);
23005 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23006 + mod->h_root = dget(path.dentry);
23013 +#if 0 /* reserved for future use */
23014 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23015 + struct au_opt_mod *mod, substring_t args[])
23018 + struct dentry *root;
23021 + root = sb->s_root;
23022 + aufs_read_lock(root, AuLock_FLUSH);
23023 + if (bindex < 0 || au_sbend(sb) < bindex) {
23024 + pr_err("out of bounds, %d\n", bindex);
23029 + mod->perm = br_perm_val(args[1].from);
23030 + AuDbg("mod path %s, perm 0x%x, %s\n",
23031 + mod->path, mod->perm, args[1].from);
23032 + mod->h_root = dget(au_h_dptr(root, bindex));
23035 + aufs_read_unlock(root, !AuLock_IR);
23040 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23041 + substring_t args[])
23044 + struct file *file;
23046 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23047 + err = PTR_ERR(file);
23048 + if (IS_ERR(file))
23052 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23054 + pr_err("%s must be outside\n", args[0].from);
23059 + xino->file = file;
23060 + xino->path = args[0].from;
23066 +static int noinline_for_stack
23067 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23068 + struct au_opt_xino_itrunc *xino_itrunc,
23069 + substring_t args[])
23072 + aufs_bindex_t bend, bindex;
23073 + struct path path;
23074 + struct dentry *root;
23076 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23077 + if (unlikely(err)) {
23078 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23082 + xino_itrunc->bindex = -1;
23083 + root = sb->s_root;
23084 + aufs_read_lock(root, AuLock_FLUSH);
23085 + bend = au_sbend(sb);
23086 + for (bindex = 0; bindex <= bend; bindex++) {
23087 + if (au_h_dptr(root, bindex) == path.dentry) {
23088 + xino_itrunc->bindex = bindex;
23092 + aufs_read_unlock(root, !AuLock_IR);
23095 + if (unlikely(xino_itrunc->bindex < 0)) {
23096 + pr_err("no such branch %s\n", args[0].from);
23104 +/* called without aufs lock */
23105 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23107 + int err, n, token;
23108 + aufs_bindex_t bindex;
23109 + unsigned char skipped;
23110 + struct dentry *root;
23111 + struct au_opt *opt, *opt_tail;
23113 + /* reduce the stack space */
23115 + struct au_opt_xino_itrunc *xino_itrunc;
23116 + struct au_opt_wbr_create *create;
23119 + substring_t args[MAX_OPT_ARGS];
23123 + a = kmalloc(sizeof(*a), GFP_NOFS);
23124 + if (unlikely(!a))
23127 + root = sb->s_root;
23131 + opt_tail = opt + opts->max_opt - 1;
23132 + opt->type = Opt_tail;
23133 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23136 + token = match_token(opt_str, options, a->args);
23140 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23142 + err = opt_add(opt, opt_str, opts->sb_flags,
23144 + if (unlikely(!err && ++opt > opt_tail)) {
23148 + opt->type = Opt_tail;
23153 + if (unlikely(match_int(&a->args[0], &n))) {
23154 + pr_err("bad integer in %s\n", opt_str);
23158 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23161 + opt->type = token;
23164 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23165 + /*dummy bindex*/1);
23167 + opt->type = token;
23169 + case Opt_prepend:
23170 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23173 + opt->type = token;
23176 + err = au_opts_parse_del(&opt->del, a->args);
23178 + opt->type = token;
23180 +#if 0 /* reserved for future use */
23182 + del->pathname = "(indexed)";
23183 + if (unlikely(match_int(&args[0], &n))) {
23184 + pr_err("bad integer in %s\n", opt_str);
23187 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23189 + opt->type = token;
23193 + err = au_opts_parse_mod(&opt->mod, a->args);
23195 + opt->type = token;
23197 +#ifdef IMOD /* reserved for future use */
23199 + u.mod->path = "(indexed)";
23200 + if (unlikely(match_int(&a->args[0], &n))) {
23201 + pr_err("bad integer in %s\n", opt_str);
23204 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23206 + opt->type = token;
23210 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23212 + opt->type = token;
23215 + case Opt_trunc_xino_path:
23216 + err = au_opts_parse_xino_itrunc_path
23217 + (sb, &opt->xino_itrunc, a->args);
23219 + opt->type = token;
23222 + case Opt_itrunc_xino:
23223 + u.xino_itrunc = &opt->xino_itrunc;
23224 + if (unlikely(match_int(&a->args[0], &n))) {
23225 + pr_err("bad integer in %s\n", opt_str);
23228 + u.xino_itrunc->bindex = n;
23229 + aufs_read_lock(root, AuLock_FLUSH);
23230 + if (n < 0 || au_sbend(sb) < n) {
23231 + pr_err("out of bounds, %d\n", n);
23232 + aufs_read_unlock(root, !AuLock_IR);
23235 + aufs_read_unlock(root, !AuLock_IR);
23237 + opt->type = token;
23241 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23244 + opt->type = token;
23247 + case Opt_rdcache:
23248 + if (unlikely(match_int(&a->args[0], &n))) {
23249 + pr_err("bad integer in %s\n", opt_str);
23252 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23253 + pr_err("rdcache must be smaller than %d\n",
23254 + AUFS_RDCACHE_MAX);
23257 + opt->rdcache = n;
23259 + opt->type = token;
23262 + if (unlikely(match_int(&a->args[0], &n)
23264 + || n > KMALLOC_MAX_SIZE)) {
23265 + pr_err("bad integer in %s\n", opt_str);
23268 + if (unlikely(n && n < NAME_MAX)) {
23269 + pr_err("rdblk must be larger than %d\n",
23275 + opt->type = token;
23278 + if (unlikely(match_int(&a->args[0], &n)
23280 + || n * sizeof(struct hlist_head)
23281 + > KMALLOC_MAX_SIZE)) {
23282 + pr_err("bad integer in %s\n", opt_str);
23287 + opt->type = token;
23290 + case Opt_trunc_xino:
23291 + case Opt_notrunc_xino:
23293 + case Opt_trunc_xib:
23294 + case Opt_notrunc_xib:
23297 + case Opt_dirperm1:
23298 + case Opt_nodirperm1:
23300 + case Opt_noplink:
23301 + case Opt_list_plink:
23304 + case Opt_diropq_a:
23305 + case Opt_diropq_w:
23306 + case Opt_warn_perm:
23307 + case Opt_nowarn_perm:
23309 + case Opt_norefrof:
23310 + case Opt_verbose:
23311 + case Opt_noverbose:
23315 + case Opt_rdblk_def:
23316 + case Opt_rdhash_def:
23320 + opt->type = token;
23324 + opt->udba = udba_val(a->args[0].from);
23325 + if (opt->udba >= 0) {
23327 + opt->type = token;
23329 + pr_err("wrong value, %s\n", opt_str);
23332 + case Opt_wbr_create:
23333 + u.create = &opt->wbr_create;
23334 + u.create->wbr_create
23335 + = au_wbr_create_val(a->args[0].from, u.create);
23336 + if (u.create->wbr_create >= 0) {
23338 + opt->type = token;
23340 + pr_err("wrong value, %s\n", opt_str);
23342 + case Opt_wbr_copyup:
23343 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23344 + if (opt->wbr_copyup >= 0) {
23346 + opt->type = token;
23348 + pr_err("wrong value, %s\n", opt_str);
23351 + case Opt_fhsm_sec:
23352 + if (unlikely(match_int(&a->args[0], &n)
23354 + pr_err("bad integer in %s\n", opt_str);
23357 + if (sysaufs_brs) {
23358 + opt->fhsm_second = n;
23359 + opt->type = token;
23361 + pr_warn("ignored %s\n", opt_str);
23366 + pr_warn("ignored %s\n", opt_str);
23368 + case Opt_ignore_silent:
23373 + pr_err("unknown option %s\n", opt_str);
23377 + if (!err && !skipped) {
23378 + if (unlikely(++opt > opt_tail)) {
23381 + opt->type = Opt_tail;
23384 + opt->type = Opt_tail;
23390 + if (unlikely(err))
23391 + au_opts_free(opts);
23397 +static int au_opt_wbr_create(struct super_block *sb,
23398 + struct au_opt_wbr_create *create)
23401 + struct au_sbinfo *sbinfo;
23403 + SiMustWriteLock(sb);
23405 + err = 1; /* handled */
23406 + sbinfo = au_sbi(sb);
23407 + if (sbinfo->si_wbr_create_ops->fin) {
23408 + err = sbinfo->si_wbr_create_ops->fin(sb);
23413 + sbinfo->si_wbr_create = create->wbr_create;
23414 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23415 + switch (create->wbr_create) {
23416 + case AuWbrCreate_MFSRRV:
23417 + case AuWbrCreate_MFSRR:
23418 + case AuWbrCreate_PMFSRR:
23419 + case AuWbrCreate_PMFSRRV:
23420 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23422 + case AuWbrCreate_MFS:
23423 + case AuWbrCreate_MFSV:
23424 + case AuWbrCreate_PMFS:
23425 + case AuWbrCreate_PMFSV:
23426 + sbinfo->si_wbr_mfs.mfs_expire
23427 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23431 + if (sbinfo->si_wbr_create_ops->init)
23432 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23439 + * plus: processed without an error
23440 + * zero: unprocessed
23442 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23443 + struct au_opts *opts)
23446 + struct au_sbinfo *sbinfo;
23448 + SiMustWriteLock(sb);
23450 + err = 1; /* handled */
23451 + sbinfo = au_sbi(sb);
23452 + switch (opt->type) {
23454 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23455 + sbinfo->si_mntflags |= opt->udba;
23456 + opts->given_udba |= opt->udba;
23460 + au_opt_set(sbinfo->si_mntflags, PLINK);
23462 + case Opt_noplink:
23463 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23464 + au_plink_put(sb, /*verbose*/1);
23465 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23467 + case Opt_list_plink:
23468 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23469 + au_plink_list(sb);
23473 + au_opt_set(sbinfo->si_mntflags, DIO);
23474 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23477 + au_opt_clr(sbinfo->si_mntflags, DIO);
23478 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23481 + case Opt_fhsm_sec:
23482 + au_fhsm_set(sbinfo, opt->fhsm_second);
23485 + case Opt_diropq_a:
23486 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23488 + case Opt_diropq_w:
23489 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23492 + case Opt_warn_perm:
23493 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23495 + case Opt_nowarn_perm:
23496 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23500 + au_opt_set(sbinfo->si_mntflags, REFROF);
23502 + case Opt_norefrof:
23503 + au_opt_clr(sbinfo->si_mntflags, REFROF);
23506 + case Opt_verbose:
23507 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23509 + case Opt_noverbose:
23510 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23514 + au_opt_set(sbinfo->si_mntflags, SUM);
23517 + au_opt_clr(sbinfo->si_mntflags, SUM);
23518 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23520 + au_opt_clr(sbinfo->si_mntflags, SUM);
23521 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23524 + case Opt_wbr_create:
23525 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23527 + case Opt_wbr_copyup:
23528 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23529 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23533 + sbinfo->si_dirwh = opt->dirwh;
23536 + case Opt_rdcache:
23537 + sbinfo->si_rdcache
23538 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
23541 + sbinfo->si_rdblk = opt->rdblk;
23543 + case Opt_rdblk_def:
23544 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23547 + sbinfo->si_rdhash = opt->rdhash;
23549 + case Opt_rdhash_def:
23550 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23554 + au_opt_set(sbinfo->si_mntflags, SHWH);
23557 + au_opt_clr(sbinfo->si_mntflags, SHWH);
23560 + case Opt_dirperm1:
23561 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
23563 + case Opt_nodirperm1:
23564 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
23567 + case Opt_trunc_xino:
23568 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
23570 + case Opt_notrunc_xino:
23571 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
23574 + case Opt_trunc_xino_path:
23575 + case Opt_itrunc_xino:
23576 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
23581 + case Opt_trunc_xib:
23582 + au_fset_opts(opts->flags, TRUNC_XIB);
23584 + case Opt_notrunc_xib:
23585 + au_fclr_opts(opts->flags, TRUNC_XIB);
23589 + sb->s_flags |= MS_POSIXACL;
23592 + sb->s_flags &= ~MS_POSIXACL;
23604 + * returns tri-state.
23605 + * plus: processed without an error
23606 + * zero: unprocessed
23609 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
23610 + struct au_opts *opts)
23612 + int err, do_refresh;
23615 + switch (opt->type) {
23617 + opt->add.bindex = au_sbend(sb) + 1;
23618 + if (opt->add.bindex < 0)
23619 + opt->add.bindex = 0;
23621 + case Opt_prepend:
23622 + opt->add.bindex = 0;
23623 + add: /* indented label */
23625 + err = au_br_add(sb, &opt->add,
23626 + au_ftest_opts(opts->flags, REMOUNT));
23629 + au_fset_opts(opts->flags, REFRESH);
23635 + err = au_br_del(sb, &opt->del,
23636 + au_ftest_opts(opts->flags, REMOUNT));
23639 + au_fset_opts(opts->flags, TRUNC_XIB);
23640 + au_fset_opts(opts->flags, REFRESH);
23646 + err = au_br_mod(sb, &opt->mod,
23647 + au_ftest_opts(opts->flags, REMOUNT),
23652 + au_fset_opts(opts->flags, REFRESH);
23660 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
23661 + struct au_opt_xino **opt_xino,
23662 + struct au_opts *opts)
23665 + aufs_bindex_t bend, bindex;
23666 + struct dentry *root, *parent, *h_root;
23669 + switch (opt->type) {
23671 + err = au_xino_set(sb, &opt->xino,
23672 + !!au_ftest_opts(opts->flags, REMOUNT));
23673 + if (unlikely(err))
23676 + *opt_xino = &opt->xino;
23677 + au_xino_brid_set(sb, -1);
23679 + /* safe d_parent access */
23680 + parent = opt->xino.file->f_path.dentry->d_parent;
23681 + root = sb->s_root;
23682 + bend = au_sbend(sb);
23683 + for (bindex = 0; bindex <= bend; bindex++) {
23684 + h_root = au_h_dptr(root, bindex);
23685 + if (h_root == parent) {
23686 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
23694 + au_xino_brid_set(sb, -1);
23695 + *opt_xino = (void *)-1;
23702 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
23703 + unsigned int pending)
23706 + aufs_bindex_t bindex, bend;
23707 + unsigned char do_plink, skip, do_free;
23708 + struct au_branch *br;
23709 + struct au_wbr *wbr;
23710 + struct dentry *root;
23711 + struct inode *dir, *h_dir;
23712 + struct au_sbinfo *sbinfo;
23713 + struct au_hinode *hdir;
23715 + SiMustAnyLock(sb);
23717 + sbinfo = au_sbi(sb);
23718 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
23720 + if (!(sb_flags & MS_RDONLY)) {
23721 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
23722 + pr_warn("first branch should be rw\n");
23723 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
23724 + pr_warn("shwh should be used with ro\n");
23727 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
23728 + && !au_opt_test(sbinfo->si_mntflags, XINO))
23729 + pr_warn("udba=*notify requires xino\n");
23731 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
23732 + pr_warn("dirperm1 breaks the protection"
23733 + " by the permission bits on the lower branch\n");
23737 + root = sb->s_root;
23738 + dir = root->d_inode;
23739 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
23740 + bend = au_sbend(sb);
23741 + for (bindex = 0; !err && bindex <= bend; bindex++) {
23743 + h_dir = au_h_iptr(dir, bindex);
23744 + br = au_sbr(sb, bindex);
23746 + if ((br->br_perm & AuBrAttr_ICEX)
23747 + && !h_dir->i_op->listxattr)
23748 + br->br_perm &= ~AuBrAttr_ICEX;
23750 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
23751 + && (au_br_sb(br)->s_flags & MS_NOSEC))
23752 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
23756 + wbr = br->br_wbr;
23758 + wbr_wh_read_lock(wbr);
23760 + if (!au_br_writable(br->br_perm)) {
23763 + || (!wbr->wbr_whbase
23764 + && !wbr->wbr_plink
23765 + && !wbr->wbr_orph));
23766 + } else if (!au_br_wh_linkable(br->br_perm)) {
23767 + /* skip = (!br->br_whbase && !br->br_orph); */
23768 + skip = (!wbr || !wbr->wbr_whbase);
23769 + if (skip && wbr) {
23771 + skip = !!wbr->wbr_plink;
23773 + skip = !wbr->wbr_plink;
23776 + /* skip = (br->br_whbase && br->br_ohph); */
23777 + skip = (wbr && wbr->wbr_whbase);
23780 + skip = !!wbr->wbr_plink;
23782 + skip = !wbr->wbr_plink;
23786 + wbr_wh_read_unlock(wbr);
23788 + if (au_br_fhsm(br->br_perm)) {
23790 + AuDebugOn(!br->br_fhsm);
23796 + hdir = au_hi(dir, bindex);
23797 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
23799 + wbr_wh_write_lock(wbr);
23800 + err = au_wh_init(br, sb);
23802 + wbr_wh_write_unlock(wbr);
23803 + au_hn_imtx_unlock(hdir);
23805 + if (!err && do_free) {
23807 + br->br_wbr = NULL;
23812 + au_fset_si(sbinfo, FHSM);
23813 + for (bindex = bend; bindex >= 0; bindex--) {
23814 + br = au_sbr(sb, bindex);
23815 + if (au_br_fhsm(br->br_perm)) {
23816 + au_fhsm_set_bottom(sb, bindex);
23821 + au_fclr_si(sbinfo, FHSM);
23822 + au_fhsm_set_bottom(sb, -1);
23828 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
23831 + unsigned int tmp;
23832 + aufs_bindex_t bindex, bend;
23833 + struct au_opt *opt;
23834 + struct au_opt_xino *opt_xino, xino;
23835 + struct au_sbinfo *sbinfo;
23836 + struct au_branch *br;
23837 + struct inode *dir;
23839 + SiMustWriteLock(sb);
23844 + while (err >= 0 && opt->type != Opt_tail)
23845 + err = au_opt_simple(sb, opt++, opts);
23848 + else if (unlikely(err < 0))
23851 + /* disable xino and udba temporary */
23852 + sbinfo = au_sbi(sb);
23853 + tmp = sbinfo->si_mntflags;
23854 + au_opt_clr(sbinfo->si_mntflags, XINO);
23855 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
23858 + while (err >= 0 && opt->type != Opt_tail)
23859 + err = au_opt_br(sb, opt++, opts);
23862 + else if (unlikely(err < 0))
23865 + bend = au_sbend(sb);
23866 + if (unlikely(bend < 0)) {
23868 + pr_err("no branches\n");
23872 + if (au_opt_test(tmp, XINO))
23873 + au_opt_set(sbinfo->si_mntflags, XINO);
23875 + while (!err && opt->type != Opt_tail)
23876 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
23877 + if (unlikely(err))
23880 + err = au_opts_verify(sb, sb->s_flags, tmp);
23881 + if (unlikely(err))
23884 + /* restore xino */
23885 + if (au_opt_test(tmp, XINO) && !opt_xino) {
23886 + xino.file = au_xino_def(sb);
23887 + err = PTR_ERR(xino.file);
23888 + if (IS_ERR(xino.file))
23891 + err = au_xino_set(sb, &xino, /*remount*/0);
23893 + if (unlikely(err))
23897 + /* restore udba */
23898 + tmp &= AuOptMask_UDBA;
23899 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23900 + sbinfo->si_mntflags |= tmp;
23901 + bend = au_sbend(sb);
23902 + for (bindex = 0; bindex <= bend; bindex++) {
23903 + br = au_sbr(sb, bindex);
23904 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
23905 + if (unlikely(err))
23906 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
23908 + /* go on even if err */
23910 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
23911 + dir = sb->s_root->d_inode;
23912 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
23919 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
23922 + struct inode *dir;
23923 + struct au_opt_xino *opt_xino;
23924 + struct au_opt *opt;
23925 + struct au_sbinfo *sbinfo;
23927 + SiMustWriteLock(sb);
23929 + dir = sb->s_root->d_inode;
23930 + sbinfo = au_sbi(sb);
23934 + while (err >= 0 && opt->type != Opt_tail) {
23935 + err = au_opt_simple(sb, opt, opts);
23937 + err = au_opt_br(sb, opt, opts);
23939 + err = au_opt_xino(sb, opt, &opt_xino, opts);
23945 + /* go on even err */
23947 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
23948 + if (unlikely(rerr && !err))
23951 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
23952 + rerr = au_xib_trunc(sb);
23953 + if (unlikely(rerr && !err))
23957 + /* will be handled by the caller */
23958 + if (!au_ftest_opts(opts->flags, REFRESH)
23959 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
23960 + au_fset_opts(opts->flags, REFRESH);
23962 + AuDbg("status 0x%x\n", opts->flags);
23966 +/* ---------------------------------------------------------------------- */
23968 +unsigned int au_opt_udba(struct super_block *sb)
23970 + return au_mntflags(sb) & AuOptMask_UDBA;
23972 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
23973 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
23974 +++ linux/fs/aufs/opts.h 2015-04-13 15:10:20.786823613 +0200
23977 + * Copyright (C) 2005-2015 Junjiro R. Okajima
23979 + * This program, aufs is free software; you can redistribute it and/or modify
23980 + * it under the terms of the GNU General Public License as published by
23981 + * the Free Software Foundation; either version 2 of the License, or
23982 + * (at your option) any later version.
23984 + * This program is distributed in the hope that it will be useful,
23985 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23986 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23987 + * GNU General Public License for more details.
23989 + * You should have received a copy of the GNU General Public License
23990 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23994 + * mount options/flags
23997 +#ifndef __AUFS_OPTS_H__
23998 +#define __AUFS_OPTS_H__
24002 +#include <linux/path.h>
24005 +struct super_block;
24007 +/* ---------------------------------------------------------------------- */
24010 +#define AuOpt_XINO 1 /* external inode number bitmap
24011 + and translation table */
24012 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24013 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24014 +#define AuOpt_UDBA_REVAL (1 << 3)
24015 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24016 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24017 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24018 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24020 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
24021 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24022 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24023 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24024 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24025 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24026 +#define AuOpt_DIO (1 << 14) /* direct io */
24028 +#ifndef CONFIG_AUFS_HNOTIFY
24029 +#undef AuOpt_UDBA_HNOTIFY
24030 +#define AuOpt_UDBA_HNOTIFY 0
24032 +#ifndef CONFIG_AUFS_SHWH
24034 +#define AuOpt_SHWH 0
24037 +#define AuOpt_Def (AuOpt_XINO \
24038 + | AuOpt_UDBA_REVAL \
24040 + /* | AuOpt_DIRPERM1 */ \
24041 + | AuOpt_WARN_PERM)
24042 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24043 + | AuOpt_UDBA_REVAL \
24044 + | AuOpt_UDBA_HNOTIFY)
24046 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24047 +#define au_opt_set(flags, name) do { \
24048 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24049 + ((flags) |= AuOpt_##name); \
24051 +#define au_opt_set_udba(flags, name) do { \
24052 + (flags) &= ~AuOptMask_UDBA; \
24053 + ((flags) |= AuOpt_##name); \
24055 +#define au_opt_clr(flags, name) do { \
24056 + ((flags) &= ~AuOpt_##name); \
24059 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24061 +#ifdef CONFIG_PROC_FS
24064 + return mntflags & ~AuOpt_PLINK;
24068 +/* ---------------------------------------------------------------------- */
24070 +/* policies to select one among multiple writable branches */
24072 + AuWbrCreate_TDP, /* top down parent */
24073 + AuWbrCreate_RR, /* round robin */
24074 + AuWbrCreate_MFS, /* most free space */
24075 + AuWbrCreate_MFSV, /* mfs with seconds */
24076 + AuWbrCreate_MFSRR, /* mfs then rr */
24077 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24078 + AuWbrCreate_PMFS, /* parent and mfs */
24079 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24080 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24081 + AuWbrCreate_PMFSRRV, /* plus seconds */
24083 + AuWbrCreate_Def = AuWbrCreate_TDP
24087 + AuWbrCopyup_TDP, /* top down parent */
24088 + AuWbrCopyup_BUP, /* bottom up parent */
24089 + AuWbrCopyup_BU, /* bottom up */
24091 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24094 +/* ---------------------------------------------------------------------- */
24096 +struct au_opt_add {
24097 + aufs_bindex_t bindex;
24100 + struct path path;
24103 +struct au_opt_del {
24105 + struct path h_path;
24108 +struct au_opt_mod {
24111 + struct dentry *h_root;
24114 +struct au_opt_xino {
24116 + struct file *file;
24119 +struct au_opt_xino_itrunc {
24120 + aufs_bindex_t bindex;
24123 +struct au_opt_wbr_create {
24126 + unsigned long long mfsrr_watermark;
24132 + struct au_opt_xino xino;
24133 + struct au_opt_xino_itrunc xino_itrunc;
24134 + struct au_opt_add add;
24135 + struct au_opt_del del;
24136 + struct au_opt_mod mod;
24139 + unsigned int rdblk;
24140 + unsigned int rdhash;
24142 + struct au_opt_wbr_create wbr_create;
24144 + unsigned int fhsm_second;
24149 +#define AuOpts_REMOUNT 1
24150 +#define AuOpts_REFRESH (1 << 1)
24151 +#define AuOpts_TRUNC_XIB (1 << 2)
24152 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24153 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24154 +#define au_fset_opts(flags, name) \
24155 + do { (flags) |= AuOpts_##name; } while (0)
24156 +#define au_fclr_opts(flags, name) \
24157 + do { (flags) &= ~AuOpts_##name; } while (0)
24160 + struct au_opt *opt;
24163 + unsigned int given_udba;
24164 + unsigned int flags;
24165 + unsigned long sb_flags;
24168 +/* ---------------------------------------------------------------------- */
24171 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24172 +const char *au_optstr_udba(int udba);
24173 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24174 +const char *au_optstr_wbr_create(int wbr_create);
24176 +void au_opts_free(struct au_opts *opts);
24177 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24178 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24179 + unsigned int pending);
24180 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24181 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24183 +unsigned int au_opt_udba(struct super_block *sb);
24185 +#endif /* __KERNEL__ */
24186 +#endif /* __AUFS_OPTS_H__ */
24187 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24188 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24189 +++ linux/fs/aufs/plink.c 2015-04-13 15:10:20.790157026 +0200
24192 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24194 + * This program, aufs is free software; you can redistribute it and/or modify
24195 + * it under the terms of the GNU General Public License as published by
24196 + * the Free Software Foundation; either version 2 of the License, or
24197 + * (at your option) any later version.
24199 + * This program is distributed in the hope that it will be useful,
24200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24202 + * GNU General Public License for more details.
24204 + * You should have received a copy of the GNU General Public License
24205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24215 + * the pseudo-link maintenance mode.
24216 + * during a user process maintains the pseudo-links,
24217 + * prohibit adding a new plink and branch manipulation.
24221 + * For entry functions which will handle plink, and i_mutex is already held
24223 + * They cannot wait and should return an error at once.
24224 + * Callers has to check the error.
24226 + * For entry functions which will handle plink, but i_mutex is not held
24228 + * They can wait the plink maintenance mode to finish.
24230 + * They behave like F_SETLK and F_SETLKW.
24231 + * If the caller never handle plink, then both flags are unnecessary.
24234 +int au_plink_maint(struct super_block *sb, int flags)
24238 + struct au_sbinfo *sbi;
24240 + SiMustAnyLock(sb);
24243 + if (!au_opt_test(au_mntflags(sb), PLINK))
24246 + sbi = au_sbi(sb);
24247 + pid = sbi->si_plink_maint_pid;
24248 + if (!pid || pid == current->pid)
24251 + /* todo: it highly depends upon /sbin/mount.aufs */
24253 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24254 + rcu_read_unlock();
24258 + if (au_ftest_lock(flags, NOPLMW)) {
24259 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24260 + /* AuDebugOn(!lockdep_depth(current)); */
24261 + while (sbi->si_plink_maint_pid) {
24262 + si_read_unlock(sb);
24263 + /* gave up wake_up_bit() */
24264 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24266 + if (au_ftest_lock(flags, FLUSH))
24267 + au_nwt_flush(&sbi->si_nowait);
24268 + si_noflush_read_lock(sb);
24270 + } else if (au_ftest_lock(flags, NOPLM)) {
24271 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24279 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24281 + spin_lock(&sbinfo->si_plink_maint_lock);
24282 + sbinfo->si_plink_maint_pid = 0;
24283 + spin_unlock(&sbinfo->si_plink_maint_lock);
24284 + wake_up_all(&sbinfo->si_plink_wq);
24287 +int au_plink_maint_enter(struct super_block *sb)
24290 + struct au_sbinfo *sbinfo;
24293 + sbinfo = au_sbi(sb);
24294 + /* make sure i am the only one in this fs */
24295 + si_write_lock(sb, AuLock_FLUSH);
24296 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24297 + spin_lock(&sbinfo->si_plink_maint_lock);
24298 + if (!sbinfo->si_plink_maint_pid)
24299 + sbinfo->si_plink_maint_pid = current->pid;
24302 + spin_unlock(&sbinfo->si_plink_maint_lock);
24304 + si_write_unlock(sb);
24309 +/* ---------------------------------------------------------------------- */
24311 +#ifdef CONFIG_AUFS_DEBUG
24312 +void au_plink_list(struct super_block *sb)
24315 + struct au_sbinfo *sbinfo;
24316 + struct hlist_head *plink_hlist;
24317 + struct pseudo_link *plink;
24319 + SiMustAnyLock(sb);
24321 + sbinfo = au_sbi(sb);
24322 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24323 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24325 + for (i = 0; i < AuPlink_NHASH; i++) {
24326 + plink_hlist = &sbinfo->si_plink[i].head;
24328 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24329 + AuDbg("%lu\n", plink->inode->i_ino);
24330 + rcu_read_unlock();
24335 +/* is the inode pseudo-linked? */
24336 +int au_plink_test(struct inode *inode)
24339 + struct au_sbinfo *sbinfo;
24340 + struct hlist_head *plink_hlist;
24341 + struct pseudo_link *plink;
24343 + sbinfo = au_sbi(inode->i_sb);
24344 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24345 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24346 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24349 + i = au_plink_hash(inode->i_ino);
24350 + plink_hlist = &sbinfo->si_plink[i].head;
24352 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24353 + if (plink->inode == inode) {
24357 + rcu_read_unlock();
24361 +/* ---------------------------------------------------------------------- */
24364 + * generate a name for plink.
24365 + * the file will be stored under AUFS_WH_PLINKDIR.
24367 +/* 20 is max digits length of ulong 64 */
24368 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24370 +static int plink_name(char *name, int len, struct inode *inode,
24371 + aufs_bindex_t bindex)
24374 + struct inode *h_inode;
24376 + h_inode = au_h_iptr(inode, bindex);
24377 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24381 +struct au_do_plink_lkup_args {
24382 + struct dentry **errp;
24383 + struct qstr *tgtname;
24384 + struct dentry *h_parent;
24385 + struct au_branch *br;
24388 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24389 + struct dentry *h_parent,
24390 + struct au_branch *br)
24392 + struct dentry *h_dentry;
24393 + struct mutex *h_mtx;
24395 + h_mtx = &h_parent->d_inode->i_mutex;
24396 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24397 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24398 + mutex_unlock(h_mtx);
24402 +static void au_call_do_plink_lkup(void *args)
24404 + struct au_do_plink_lkup_args *a = args;
24405 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24408 +/* lookup the plink-ed @inode under the branch at @bindex */
24409 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24411 + struct dentry *h_dentry, *h_parent;
24412 + struct au_branch *br;
24413 + struct inode *h_dir;
24415 + char a[PLINK_NAME_LEN];
24416 + struct qstr tgtname = QSTR_INIT(a, 0);
24418 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24420 + br = au_sbr(inode->i_sb, bindex);
24421 + h_parent = br->br_wbr->wbr_plink;
24422 + h_dir = h_parent->d_inode;
24423 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24425 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24426 + struct au_do_plink_lkup_args args = {
24427 + .errp = &h_dentry,
24428 + .tgtname = &tgtname,
24429 + .h_parent = h_parent,
24433 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24434 + if (unlikely(wkq_err))
24435 + h_dentry = ERR_PTR(wkq_err);
24437 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24442 +/* create a pseudo-link */
24443 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24444 + struct dentry *h_dentry, struct au_branch *br)
24447 + struct path h_path = {
24448 + .mnt = au_br_mnt(br)
24450 + struct inode *h_dir, *delegated;
24452 + h_dir = h_parent->d_inode;
24453 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24455 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24456 + err = PTR_ERR(h_path.dentry);
24457 + if (IS_ERR(h_path.dentry))
24461 + /* wh.plink dir is not monitored */
24462 + /* todo: is it really safe? */
24463 + if (h_path.dentry->d_inode
24464 + && h_path.dentry->d_inode != h_dentry->d_inode) {
24465 + delegated = NULL;
24466 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24467 + if (unlikely(err == -EWOULDBLOCK)) {
24468 + pr_warn("cannot retry for NFSv4 delegation"
24469 + " for an internal unlink\n");
24472 + dput(h_path.dentry);
24473 + h_path.dentry = NULL;
24477 + if (!err && !h_path.dentry->d_inode) {
24478 + delegated = NULL;
24479 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24480 + if (unlikely(err == -EWOULDBLOCK)) {
24481 + pr_warn("cannot retry for NFSv4 delegation"
24482 + " for an internal link\n");
24486 + dput(h_path.dentry);
24489 + mutex_unlock(&h_dir->i_mutex);
24493 +struct do_whplink_args {
24495 + struct qstr *tgt;
24496 + struct dentry *h_parent;
24497 + struct dentry *h_dentry;
24498 + struct au_branch *br;
24501 +static void call_do_whplink(void *args)
24503 + struct do_whplink_args *a = args;
24504 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24507 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24508 + aufs_bindex_t bindex, struct au_branch *br)
24510 + int err, wkq_err;
24511 + struct au_wbr *wbr;
24512 + struct dentry *h_parent;
24513 + struct inode *h_dir;
24514 + char a[PLINK_NAME_LEN];
24515 + struct qstr tgtname = QSTR_INIT(a, 0);
24517 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24518 + h_parent = wbr->wbr_plink;
24519 + h_dir = h_parent->d_inode;
24520 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24522 + /* always superio. */
24523 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24524 + struct do_whplink_args args = {
24527 + .h_parent = h_parent,
24528 + .h_dentry = h_dentry,
24531 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24532 + if (unlikely(wkq_err))
24535 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
24540 +/* free a single plink */
24541 +static void do_put_plink(struct pseudo_link *plink, int do_del)
24544 + hlist_del(&plink->hlist);
24545 + iput(plink->inode);
24549 +static void do_put_plink_rcu(struct rcu_head *rcu)
24551 + struct pseudo_link *plink;
24553 + plink = container_of(rcu, struct pseudo_link, rcu);
24554 + iput(plink->inode);
24559 + * create a new pseudo-link for @h_dentry on @bindex.
24560 + * the linked inode is held in aufs @inode.
24562 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
24563 + struct dentry *h_dentry)
24565 + struct super_block *sb;
24566 + struct au_sbinfo *sbinfo;
24567 + struct hlist_head *plink_hlist;
24568 + struct pseudo_link *plink, *tmp;
24569 + struct au_sphlhead *sphl;
24570 + int found, err, cnt, i;
24572 + sb = inode->i_sb;
24573 + sbinfo = au_sbi(sb);
24574 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24575 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24577 + found = au_plink_test(inode);
24581 + i = au_plink_hash(inode->i_ino);
24582 + sphl = sbinfo->si_plink + i;
24583 + plink_hlist = &sphl->head;
24584 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
24586 + tmp->inode = au_igrab(inode);
24592 + spin_lock(&sphl->spin);
24593 + hlist_for_each_entry(plink, plink_hlist, hlist) {
24594 + if (plink->inode == inode) {
24600 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
24601 + spin_unlock(&sphl->spin);
24603 + cnt = au_sphl_count(sphl);
24604 +#define msg "unexpectedly unblanced or too many pseudo-links"
24605 + if (cnt > AUFS_PLINK_WARN)
24606 + AuWarn1(msg ", %d\n", cnt);
24608 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
24610 + do_put_plink(tmp, 0);
24615 + if (unlikely(err)) {
24616 + pr_warn("err %d, damaged pseudo link.\n", err);
24618 + au_sphl_del_rcu(&tmp->hlist, sphl);
24619 + call_rcu(&tmp->rcu, do_put_plink_rcu);
24624 +/* free all plinks */
24625 +void au_plink_put(struct super_block *sb, int verbose)
24628 + struct au_sbinfo *sbinfo;
24629 + struct hlist_head *plink_hlist;
24630 + struct hlist_node *tmp;
24631 + struct pseudo_link *plink;
24633 + SiMustWriteLock(sb);
24635 + sbinfo = au_sbi(sb);
24636 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24637 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24639 + /* no spin_lock since sbinfo is write-locked */
24641 + for (i = 0; i < AuPlink_NHASH; i++) {
24642 + plink_hlist = &sbinfo->si_plink[i].head;
24643 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
24644 + pr_warn("pseudo-link is not flushed");
24647 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
24648 + do_put_plink(plink, 0);
24649 + INIT_HLIST_HEAD(plink_hlist);
24653 +void au_plink_clean(struct super_block *sb, int verbose)
24655 + struct dentry *root;
24657 + root = sb->s_root;
24658 + aufs_write_lock(root);
24659 + if (au_opt_test(au_mntflags(sb), PLINK))
24660 + au_plink_put(sb, verbose);
24661 + aufs_write_unlock(root);
24664 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
24667 + aufs_bindex_t bstart, bend, bindex;
24670 + bstart = au_ibstart(inode);
24671 + bend = au_ibend(inode);
24672 + if (bstart >= 0) {
24673 + for (bindex = bstart; bindex <= bend; bindex++) {
24674 + if (!au_h_iptr(inode, bindex)
24675 + || au_ii_br_id(inode, bindex) != br_id)
24677 + au_set_h_iptr(inode, bindex, NULL, 0);
24682 + for (bindex = bstart; bindex <= bend; bindex++)
24683 + if (au_h_iptr(inode, bindex)) {
24693 +/* free the plinks on a branch specified by @br_id */
24694 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
24696 + struct au_sbinfo *sbinfo;
24697 + struct hlist_head *plink_hlist;
24698 + struct hlist_node *tmp;
24699 + struct pseudo_link *plink;
24700 + struct inode *inode;
24703 + SiMustWriteLock(sb);
24705 + sbinfo = au_sbi(sb);
24706 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24707 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24709 + /* no spin_lock since sbinfo is write-locked */
24710 + for (i = 0; i < AuPlink_NHASH; i++) {
24711 + plink_hlist = &sbinfo->si_plink[i].head;
24712 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
24713 + inode = au_igrab(plink->inode);
24714 + ii_write_lock_child(inode);
24715 + do_put = au_plink_do_half_refresh(inode, br_id);
24717 + do_put_plink(plink, 1);
24718 + ii_write_unlock(inode);
24723 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
24724 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
24725 +++ linux/fs/aufs/poll.c 2015-04-13 15:10:20.790157026 +0200
24728 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24730 + * This program, aufs is free software; you can redistribute it and/or modify
24731 + * it under the terms of the GNU General Public License as published by
24732 + * the Free Software Foundation; either version 2 of the License, or
24733 + * (at your option) any later version.
24735 + * This program is distributed in the hope that it will be useful,
24736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24738 + * GNU General Public License for more details.
24740 + * You should have received a copy of the GNU General Public License
24741 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24746 + * There is only one filesystem which implements ->poll operation, currently.
24751 +unsigned int aufs_poll(struct file *file, poll_table *wait)
24753 + unsigned int mask;
24755 + struct file *h_file;
24756 + struct dentry *dentry;
24757 + struct super_block *sb;
24759 + /* We should pretend an error happened. */
24760 + mask = POLLERR /* | POLLIN | POLLOUT */;
24761 + dentry = file->f_path.dentry;
24762 + sb = dentry->d_sb;
24763 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
24764 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
24765 + if (unlikely(err))
24768 + /* it is not an error if h_file has no operation */
24769 + mask = DEFAULT_POLLMASK;
24770 + h_file = au_hf_top(file);
24771 + if (h_file->f_op->poll)
24772 + mask = h_file->f_op->poll(h_file, wait);
24774 + di_read_unlock(dentry, AuLock_IR);
24775 + fi_read_unlock(file);
24778 + si_read_unlock(sb);
24779 + AuTraceErr((int)mask);
24782 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
24783 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
24784 +++ linux/fs/aufs/posix_acl.c 2015-04-13 15:10:20.790157026 +0200
24787 + * Copyright (C) 2014-2015 Junjiro R. Okajima
24789 + * This program, aufs is free software; you can redistribute it and/or modify
24790 + * it under the terms of the GNU General Public License as published by
24791 + * the Free Software Foundation; either version 2 of the License, or
24792 + * (at your option) any later version.
24794 + * This program is distributed in the hope that it will be useful,
24795 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24796 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24797 + * GNU General Public License for more details.
24799 + * You should have received a copy of the GNU General Public License
24800 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24804 + * posix acl operations
24807 +#include <linux/fs.h>
24808 +#include <linux/posix_acl.h>
24811 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
24813 + struct posix_acl *acl;
24815 + aufs_bindex_t bindex;
24816 + struct inode *h_inode;
24817 + struct super_block *sb;
24820 + sb = inode->i_sb;
24821 + si_read_lock(sb, AuLock_FLUSH);
24822 + ii_read_lock_child(inode);
24823 + if (!(sb->s_flags & MS_POSIXACL))
24826 + bindex = au_ibstart(inode);
24827 + h_inode = au_h_iptr(inode, bindex);
24828 + if (unlikely(!h_inode
24829 + || ((h_inode->i_mode & S_IFMT)
24830 + != (inode->i_mode & S_IFMT)))) {
24831 + err = au_busy_or_stale();
24832 + acl = ERR_PTR(err);
24836 + /* always topmost only */
24837 + acl = get_acl(h_inode, type);
24840 + ii_read_unlock(inode);
24841 + si_read_unlock(sb);
24843 + AuTraceErrPtr(acl);
24847 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
24851 + struct dentry *dentry;
24852 + struct au_srxattr arg = {
24853 + .type = AU_ACL_SET,
24860 + mutex_lock(&inode->i_mutex);
24861 + if (inode->i_ino == AUFS_ROOT_INO)
24862 + dentry = dget(inode->i_sb->s_root);
24864 + dentry = d_find_alias(inode);
24866 + dentry = d_find_any_alias(inode);
24868 + pr_warn("cannot handle this inode, "
24869 + "please report to aufs-users ML\n");
24875 + ssz = au_srxattr(dentry, &arg);
24882 + mutex_unlock(&inode->i_mutex);
24885 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
24886 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
24887 +++ linux/fs/aufs/procfs.c 2015-04-13 15:10:20.790157026 +0200
24890 + * Copyright (C) 2010-2015 Junjiro R. Okajima
24892 + * This program, aufs is free software; you can redistribute it and/or modify
24893 + * it under the terms of the GNU General Public License as published by
24894 + * the Free Software Foundation; either version 2 of the License, or
24895 + * (at your option) any later version.
24897 + * This program is distributed in the hope that it will be useful,
24898 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24899 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24900 + * GNU General Public License for more details.
24902 + * You should have received a copy of the GNU General Public License
24903 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24907 + * procfs interfaces
24910 +#include <linux/proc_fs.h>
24913 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
24915 + struct au_sbinfo *sbinfo;
24917 + sbinfo = file->private_data;
24919 + au_plink_maint_leave(sbinfo);
24920 + kobject_put(&sbinfo->si_kobj);
24926 +static void au_procfs_plm_write_clean(struct file *file)
24928 + struct au_sbinfo *sbinfo;
24930 + sbinfo = file->private_data;
24932 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
24935 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
24938 + struct super_block *sb;
24939 + struct au_sbinfo *sbinfo;
24942 + if (unlikely(file->private_data))
24946 + /* don't use au_sbilist_lock() here */
24947 + spin_lock(&au_sbilist.spin);
24948 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
24949 + if (id == sysaufs_si_id(sbinfo)) {
24950 + kobject_get(&sbinfo->si_kobj);
24951 + sb = sbinfo->si_sb;
24954 + spin_unlock(&au_sbilist.spin);
24957 + if (unlikely(!sb))
24960 + err = au_plink_maint_enter(sb);
24962 + /* keep kobject_get() */
24963 + file->private_data = sbinfo;
24965 + kobject_put(&sbinfo->si_kobj);
24971 + * Accept a valid "si=xxxx" only.
24972 + * Once it is accepted successfully, accept "clean" too.
24974 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
24975 + size_t count, loff_t *ppos)
24978 + unsigned long id;
24979 + /* last newline is allowed */
24980 + char buf[3 + sizeof(unsigned long) * 2 + 1];
24983 + if (unlikely(!capable(CAP_SYS_ADMIN)))
24987 + if (unlikely(count > sizeof(buf)))
24990 + err = copy_from_user(buf, ubuf, count);
24991 + if (unlikely(err)) {
24998 + if (!strcmp("clean", buf)) {
24999 + au_procfs_plm_write_clean(file);
25000 + goto out_success;
25001 + } else if (unlikely(strncmp("si=", buf, 3)))
25004 + err = kstrtoul(buf + 3, 16, &id);
25005 + if (unlikely(err))
25008 + err = au_procfs_plm_write_si(file, id);
25009 + if (unlikely(err))
25013 + err = count; /* success */
25018 +static const struct file_operations au_procfs_plm_fop = {
25019 + .write = au_procfs_plm_write,
25020 + .release = au_procfs_plm_release,
25021 + .owner = THIS_MODULE
25024 +/* ---------------------------------------------------------------------- */
25026 +static struct proc_dir_entry *au_procfs_dir;
25028 +void au_procfs_fin(void)
25030 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25031 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25034 +int __init au_procfs_init(void)
25037 + struct proc_dir_entry *entry;
25040 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25041 + if (unlikely(!au_procfs_dir))
25044 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25045 + au_procfs_dir, &au_procfs_plm_fop);
25046 + if (unlikely(!entry))
25050 + goto out; /* success */
25054 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25058 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25059 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25060 +++ linux/fs/aufs/rdu.c 2015-04-13 15:10:20.790157026 +0200
25063 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25065 + * This program, aufs is free software; you can redistribute it and/or modify
25066 + * it under the terms of the GNU General Public License as published by
25067 + * the Free Software Foundation; either version 2 of the License, or
25068 + * (at your option) any later version.
25070 + * This program is distributed in the hope that it will be useful,
25071 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25072 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25073 + * GNU General Public License for more details.
25075 + * You should have received a copy of the GNU General Public License
25076 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25080 + * readdir in userspace.
25083 +#include <linux/compat.h>
25084 +#include <linux/fs_stack.h>
25085 +#include <linux/security.h>
25088 +/* bits for struct aufs_rdu.flags */
25089 +#define AuRdu_CALLED 1
25090 +#define AuRdu_CONT (1 << 1)
25091 +#define AuRdu_FULL (1 << 2)
25092 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25093 +#define au_fset_rdu(flags, name) \
25094 + do { (flags) |= AuRdu_##name; } while (0)
25095 +#define au_fclr_rdu(flags, name) \
25096 + do { (flags) &= ~AuRdu_##name; } while (0)
25098 +struct au_rdu_arg {
25099 + struct dir_context ctx;
25100 + struct aufs_rdu *rdu;
25101 + union au_rdu_ent_ul ent;
25102 + unsigned long end;
25104 + struct super_block *sb;
25108 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25109 + loff_t offset, u64 h_ino, unsigned int d_type)
25112 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25113 + struct aufs_rdu *rdu = arg->rdu;
25114 + struct au_rdu_ent ent;
25118 + au_fset_rdu(rdu->cookie.flags, CALLED);
25119 + len = au_rdu_len(nlen);
25120 + if (arg->ent.ul + len < arg->end) {
25122 + ent.bindex = rdu->cookie.bindex;
25123 + ent.type = d_type;
25125 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25126 + ent.type = DT_UNKNOWN;
25128 + /* unnecessary to support mmap_sem since this is a dir */
25130 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25132 + if (copy_to_user(arg->ent.e->name, name, nlen))
25134 + /* the terminating NULL */
25135 + if (__put_user(0, arg->ent.e->name + nlen))
25138 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25139 + arg->ent.ul += len;
25143 + au_fset_rdu(rdu->cookie.flags, FULL);
25145 + rdu->tail = arg->ent;
25149 + /* AuTraceErr(err); */
25153 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25157 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25159 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25160 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25162 + if (unlikely(offset != cookie->h_pos))
25168 + au_fclr_rdu(cookie->flags, CALLED);
25170 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25174 + && au_ftest_rdu(cookie->flags, CALLED)
25175 + && !au_ftest_rdu(cookie->flags, FULL));
25176 + cookie->h_pos = h_file->f_pos;
25183 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25186 + aufs_bindex_t bend;
25187 + struct au_rdu_arg arg = {
25189 + .actor = au_rdu_fill
25192 + struct dentry *dentry;
25193 + struct inode *inode;
25194 + struct file *h_file;
25195 + struct au_rdu_cookie *cookie = &rdu->cookie;
25197 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25198 + if (unlikely(err)) {
25204 + rdu->tail = rdu->ent;
25207 + arg.ent = rdu->ent;
25208 + arg.end = arg.ent.ul;
25209 + arg.end += rdu->sz;
25212 + if (unlikely(!file->f_op->iterate))
25215 + err = security_file_permission(file, MAY_READ);
25217 + if (unlikely(err))
25220 + dentry = file->f_path.dentry;
25221 + inode = dentry->d_inode;
25223 + mutex_lock(&inode->i_mutex);
25225 + err = mutex_lock_killable(&inode->i_mutex);
25227 + if (unlikely(err))
25231 + arg.sb = inode->i_sb;
25232 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25233 + if (unlikely(err))
25235 + err = au_alive_dir(dentry);
25236 + if (unlikely(err))
25238 + /* todo: reval? */
25239 + fi_read_lock(file);
25242 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25243 + && cookie->generation != au_figen(file)))
25248 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25250 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25252 + bend = au_fbstart(file);
25253 + if (cookie->bindex < bend)
25254 + cookie->bindex = bend;
25255 + bend = au_fbend_dir(file);
25256 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25257 + for (; !err && cookie->bindex <= bend;
25258 + cookie->bindex++, cookie->h_pos = 0) {
25259 + h_file = au_hf_dir(file, cookie->bindex);
25263 + au_fclr_rdu(cookie->flags, FULL);
25264 + err = au_rdu_do(h_file, &arg);
25266 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25269 + AuDbg("rent %llu\n", rdu->rent);
25271 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25272 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25273 + au_fset_rdu(cookie->flags, CONT);
25274 + cookie->generation = au_figen(file);
25277 + ii_read_lock_child(inode);
25278 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25279 + ii_read_unlock(inode);
25282 + fi_read_unlock(file);
25284 + si_read_unlock(arg.sb);
25286 + mutex_unlock(&inode->i_mutex);
25292 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25296 + unsigned long long nent;
25297 + union au_rdu_ent_ul *u;
25298 + struct au_rdu_ent ent;
25299 + struct super_block *sb;
25302 + nent = rdu->nent;
25304 + sb = file->f_path.dentry->d_sb;
25305 + si_read_lock(sb, AuLock_FLUSH);
25306 + while (nent-- > 0) {
25307 + /* unnecessary to support mmap_sem since this is a dir */
25308 + err = copy_from_user(&ent, u->e, sizeof(ent));
25310 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25311 + if (unlikely(err)) {
25317 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25319 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25321 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25323 + if (unlikely(err)) {
25328 + err = __put_user(ino, &u->e->ino);
25329 + if (unlikely(err)) {
25334 + u->ul += au_rdu_len(ent.nlen);
25336 + si_read_unlock(sb);
25341 +/* ---------------------------------------------------------------------- */
25343 +static int au_rdu_verify(struct aufs_rdu *rdu)
25345 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25346 + "%llu, b%d, 0x%x, g%u}\n",
25347 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25349 + rdu->rent, rdu->shwh, rdu->full,
25350 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25351 + rdu->cookie.generation);
25353 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25357 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25361 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25364 + struct aufs_rdu rdu;
25365 + void __user *p = (void __user *)arg;
25367 + err = copy_from_user(&rdu, p, sizeof(rdu));
25368 + if (unlikely(err)) {
25373 + err = au_rdu_verify(&rdu);
25374 + if (unlikely(err))
25378 + case AUFS_CTL_RDU:
25379 + err = au_rdu(file, &rdu);
25380 + if (unlikely(err))
25383 + e = copy_to_user(p, &rdu, sizeof(rdu));
25384 + if (unlikely(e)) {
25389 + case AUFS_CTL_RDU_INO:
25390 + err = au_rdu_ino(file, &rdu);
25394 + /* err = -ENOTTY; */
25403 +#ifdef CONFIG_COMPAT
25404 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25407 + struct aufs_rdu rdu;
25408 + void __user *p = compat_ptr(arg);
25410 + /* todo: get_user()? */
25411 + err = copy_from_user(&rdu, p, sizeof(rdu));
25412 + if (unlikely(err)) {
25417 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25418 + err = au_rdu_verify(&rdu);
25419 + if (unlikely(err))
25423 + case AUFS_CTL_RDU:
25424 + err = au_rdu(file, &rdu);
25425 + if (unlikely(err))
25428 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25429 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25430 + e = copy_to_user(p, &rdu, sizeof(rdu));
25431 + if (unlikely(e)) {
25436 + case AUFS_CTL_RDU_INO:
25437 + err = au_rdu_ino(file, &rdu);
25441 + /* err = -ENOTTY; */
25450 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
25451 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25452 +++ linux/fs/aufs/rwsem.h 2015-04-13 15:10:20.790157026 +0200
25455 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25457 + * This program, aufs is free software; you can redistribute it and/or modify
25458 + * it under the terms of the GNU General Public License as published by
25459 + * the Free Software Foundation; either version 2 of the License, or
25460 + * (at your option) any later version.
25462 + * This program is distributed in the hope that it will be useful,
25463 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25464 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25465 + * GNU General Public License for more details.
25467 + * You should have received a copy of the GNU General Public License
25468 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25472 + * simple read-write semaphore wrappers
25475 +#ifndef __AUFS_RWSEM_H__
25476 +#define __AUFS_RWSEM_H__
25480 +#include "debug.h"
25483 + struct rw_semaphore rwsem;
25484 +#ifdef CONFIG_AUFS_DEBUG
25485 + /* just for debugging, not almighty counter */
25486 + atomic_t rcnt, wcnt;
25490 +#ifdef CONFIG_AUFS_DEBUG
25491 +#define AuDbgCntInit(rw) do { \
25492 + atomic_set(&(rw)->rcnt, 0); \
25493 + atomic_set(&(rw)->wcnt, 0); \
25494 + smp_mb(); /* atomic set */ \
25497 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25498 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25499 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25500 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25502 +#define AuDbgCntInit(rw) do {} while (0)
25503 +#define AuDbgRcntInc(rw) do {} while (0)
25504 +#define AuDbgRcntDec(rw) do {} while (0)
25505 +#define AuDbgWcntInc(rw) do {} while (0)
25506 +#define AuDbgWcntDec(rw) do {} while (0)
25507 +#endif /* CONFIG_AUFS_DEBUG */
25509 +/* to debug easier, do not make them inlined functions */
25510 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25511 +/* rwsem_is_locked() is unusable */
25512 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25513 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25514 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25515 + && atomic_read(&(rw)->wcnt) <= 0)
25516 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25517 + || atomic_read(&(rw)->wcnt))
25519 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25521 +static inline void au_rw_init(struct au_rwsem *rw)
25523 + AuDbgCntInit(rw);
25524 + init_rwsem(&rw->rwsem);
25527 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25530 + down_write(&rw->rwsem);
25531 + AuDbgWcntInc(rw);
25534 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25535 + unsigned int lsc)
25538 + down_write_nested(&rw->rwsem, lsc);
25539 + AuDbgWcntInc(rw);
25542 +static inline void au_rw_read_lock(struct au_rwsem *rw)
25544 + down_read(&rw->rwsem);
25545 + AuDbgRcntInc(rw);
25548 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
25550 + down_read_nested(&rw->rwsem, lsc);
25551 + AuDbgRcntInc(rw);
25554 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
25556 + AuRwMustReadLock(rw);
25557 + AuDbgRcntDec(rw);
25558 + up_read(&rw->rwsem);
25561 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
25563 + AuRwMustWriteLock(rw);
25564 + AuDbgRcntInc(rw);
25565 + AuDbgWcntDec(rw);
25566 + downgrade_write(&rw->rwsem);
25569 +static inline void au_rw_write_lock(struct au_rwsem *rw)
25571 + down_write(&rw->rwsem);
25572 + AuDbgWcntInc(rw);
25575 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
25576 + unsigned int lsc)
25578 + down_write_nested(&rw->rwsem, lsc);
25579 + AuDbgWcntInc(rw);
25582 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
25584 + AuRwMustWriteLock(rw);
25585 + AuDbgWcntDec(rw);
25586 + up_write(&rw->rwsem);
25589 +/* why is not _nested version defined */
25590 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
25594 + ret = down_read_trylock(&rw->rwsem);
25596 + AuDbgRcntInc(rw);
25600 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
25604 + ret = down_write_trylock(&rw->rwsem);
25606 + AuDbgWcntInc(rw);
25610 +#undef AuDbgCntInit
25611 +#undef AuDbgRcntInc
25612 +#undef AuDbgRcntDec
25613 +#undef AuDbgWcntInc
25614 +#undef AuDbgWcntDec
25616 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25617 +static inline void prefix##_read_lock(param) \
25618 +{ au_rw_read_lock(rwsem); } \
25619 +static inline void prefix##_write_lock(param) \
25620 +{ au_rw_write_lock(rwsem); } \
25621 +static inline int prefix##_read_trylock(param) \
25622 +{ return au_rw_read_trylock(rwsem); } \
25623 +static inline int prefix##_write_trylock(param) \
25624 +{ return au_rw_write_trylock(rwsem); }
25625 +/* why is not _nested version defined */
25626 +/* static inline void prefix##_read_trylock_nested(param, lsc)
25627 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
25628 +static inline void prefix##_write_trylock_nestd(param, lsc)
25629 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
25631 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
25632 +static inline void prefix##_read_unlock(param) \
25633 +{ au_rw_read_unlock(rwsem); } \
25634 +static inline void prefix##_write_unlock(param) \
25635 +{ au_rw_write_unlock(rwsem); } \
25636 +static inline void prefix##_downgrade_lock(param) \
25637 +{ au_rw_dgrade_lock(rwsem); }
25639 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
25640 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25641 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
25643 +#endif /* __KERNEL__ */
25644 +#endif /* __AUFS_RWSEM_H__ */
25645 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
25646 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
25647 +++ linux/fs/aufs/sbinfo.c 2015-04-13 15:10:20.790157026 +0200
25650 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25652 + * This program, aufs is free software; you can redistribute it and/or modify
25653 + * it under the terms of the GNU General Public License as published by
25654 + * the Free Software Foundation; either version 2 of the License, or
25655 + * (at your option) any later version.
25657 + * This program is distributed in the hope that it will be useful,
25658 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25659 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25660 + * GNU General Public License for more details.
25662 + * You should have received a copy of the GNU General Public License
25663 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25667 + * superblock private data
25673 + * they are necessary regardless sysfs is disabled.
25675 +void au_si_free(struct kobject *kobj)
25678 + struct au_sbinfo *sbinfo;
25679 + char *locked __maybe_unused; /* debug only */
25681 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
25682 + for (i = 0; i < AuPlink_NHASH; i++)
25683 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
25684 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
25686 + au_rw_write_lock(&sbinfo->si_rwsem);
25687 + au_br_free(sbinfo);
25688 + au_rw_write_unlock(&sbinfo->si_rwsem);
25690 + AuDebugOn(radix_tree_gang_lookup
25691 + (&sbinfo->au_si_pid.tree, (void **)&locked,
25692 + /*first_index*/PID_MAX_DEFAULT - 1,
25693 + /*max_items*/sizeof(locked)/sizeof(*locked)));
25695 + kfree(sbinfo->si_branch);
25696 + kfree(sbinfo->au_si_pid.bitmap);
25697 + mutex_destroy(&sbinfo->si_xib_mtx);
25698 + AuRwDestroy(&sbinfo->si_rwsem);
25703 +int au_si_alloc(struct super_block *sb)
25706 + struct au_sbinfo *sbinfo;
25707 + static struct lock_class_key aufs_si;
25710 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
25711 + if (unlikely(!sbinfo))
25714 + BUILD_BUG_ON(sizeof(unsigned long) !=
25715 + sizeof(*sbinfo->au_si_pid.bitmap));
25716 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
25717 + sizeof(*sbinfo->au_si_pid.bitmap),
25719 + if (unlikely(!sbinfo->au_si_pid.bitmap))
25722 + /* will be reallocated separately */
25723 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
25724 + if (unlikely(!sbinfo->si_branch))
25727 + err = sysaufs_si_init(sbinfo);
25728 + if (unlikely(err))
25731 + au_nwt_init(&sbinfo->si_nowait);
25732 + au_rw_init_wlock(&sbinfo->si_rwsem);
25733 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
25734 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
25735 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
25737 + atomic_long_set(&sbinfo->si_ninodes, 0);
25738 + atomic_long_set(&sbinfo->si_nfiles, 0);
25740 + sbinfo->si_bend = -1;
25741 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
25743 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
25744 + sbinfo->si_wbr_create = AuWbrCreate_Def;
25745 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
25746 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
25748 + au_fhsm_init(sbinfo);
25750 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
25752 + sbinfo->si_xino_jiffy = jiffies;
25753 + sbinfo->si_xino_expire
25754 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
25755 + mutex_init(&sbinfo->si_xib_mtx);
25756 + sbinfo->si_xino_brid = -1;
25757 + /* leave si_xib_last_pindex and si_xib_next_bit */
25759 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
25760 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
25761 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
25762 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
25764 + for (i = 0; i < AuPlink_NHASH; i++)
25765 + au_sphl_init(sbinfo->si_plink + i);
25766 + init_waitqueue_head(&sbinfo->si_plink_wq);
25767 + spin_lock_init(&sbinfo->si_plink_maint_lock);
25769 + au_sphl_init(&sbinfo->si_files);
25771 + /* leave other members for sysaufs and si_mnt. */
25772 + sbinfo->si_sb = sb;
25773 + sb->s_fs_info = sbinfo;
25775 + return 0; /* success */
25778 + kfree(sbinfo->si_branch);
25780 + kfree(sbinfo->au_si_pid.bitmap);
25787 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
25790 + struct au_branch **brp;
25792 + AuRwMustWriteLock(&sbinfo->si_rwsem);
25795 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
25796 + if (unlikely(!sz))
25797 + sz = sizeof(*brp);
25798 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
25800 + sbinfo->si_branch = brp;
25807 +/* ---------------------------------------------------------------------- */
25809 +unsigned int au_sigen_inc(struct super_block *sb)
25811 + unsigned int gen;
25813 + SiMustWriteLock(sb);
25815 + gen = ++au_sbi(sb)->si_generation;
25816 + au_update_digen(sb->s_root);
25817 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
25818 + sb->s_root->d_inode->i_version++;
25822 +aufs_bindex_t au_new_br_id(struct super_block *sb)
25824 + aufs_bindex_t br_id;
25826 + struct au_sbinfo *sbinfo;
25828 + SiMustWriteLock(sb);
25830 + sbinfo = au_sbi(sb);
25831 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
25832 + br_id = ++sbinfo->si_last_br_id;
25833 + AuDebugOn(br_id < 0);
25834 + if (br_id && au_br_index(sb, br_id) < 0)
25841 +/* ---------------------------------------------------------------------- */
25843 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
25844 +int si_read_lock(struct super_block *sb, int flags)
25849 + if (au_ftest_lock(flags, FLUSH))
25850 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25852 + si_noflush_read_lock(sb);
25853 + err = au_plink_maint(sb, flags);
25854 + if (unlikely(err))
25855 + si_read_unlock(sb);
25860 +int si_write_lock(struct super_block *sb, int flags)
25864 + if (au_ftest_lock(flags, FLUSH))
25865 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25867 + si_noflush_write_lock(sb);
25868 + err = au_plink_maint(sb, flags);
25869 + if (unlikely(err))
25870 + si_write_unlock(sb);
25875 +/* dentry and super_block lock. call at entry point */
25876 +int aufs_read_lock(struct dentry *dentry, int flags)
25879 + struct super_block *sb;
25881 + sb = dentry->d_sb;
25882 + err = si_read_lock(sb, flags);
25883 + if (unlikely(err))
25886 + if (au_ftest_lock(flags, DW))
25887 + di_write_lock_child(dentry);
25889 + di_read_lock_child(dentry, flags);
25891 + if (au_ftest_lock(flags, GEN)) {
25892 + err = au_digen_test(dentry, au_sigen(sb));
25893 + AuDebugOn(!err && au_dbrange_test(dentry));
25894 + if (unlikely(err))
25895 + aufs_read_unlock(dentry, flags);
25902 +void aufs_read_unlock(struct dentry *dentry, int flags)
25904 + if (au_ftest_lock(flags, DW))
25905 + di_write_unlock(dentry);
25907 + di_read_unlock(dentry, flags);
25908 + si_read_unlock(dentry->d_sb);
25911 +void aufs_write_lock(struct dentry *dentry)
25913 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
25914 + di_write_lock_child(dentry);
25917 +void aufs_write_unlock(struct dentry *dentry)
25919 + di_write_unlock(dentry);
25920 + si_write_unlock(dentry->d_sb);
25923 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
25926 + unsigned int sigen;
25927 + struct super_block *sb;
25930 + err = si_read_lock(sb, flags);
25931 + if (unlikely(err))
25934 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
25936 + if (au_ftest_lock(flags, GEN)) {
25937 + sigen = au_sigen(sb);
25938 + err = au_digen_test(d1, sigen);
25939 + AuDebugOn(!err && au_dbrange_test(d1));
25941 + err = au_digen_test(d2, sigen);
25942 + AuDebugOn(!err && au_dbrange_test(d2));
25944 + if (unlikely(err))
25945 + aufs_read_and_write_unlock2(d1, d2);
25952 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
25954 + di_write_unlock2(d1, d2);
25955 + si_read_unlock(d1->d_sb);
25958 +/* ---------------------------------------------------------------------- */
25960 +int si_pid_test_slow(struct super_block *sb)
25965 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
25966 + rcu_read_unlock();
25968 + return (long)!!p;
25971 +void si_pid_set_slow(struct super_block *sb)
25974 + struct au_sbinfo *sbinfo;
25976 + AuDebugOn(si_pid_test_slow(sb));
25978 + sbinfo = au_sbi(sb);
25979 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
25981 + spin_lock(&sbinfo->au_si_pid.tree_lock);
25982 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
25983 + /*any valid ptr*/sb);
25984 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
25986 + radix_tree_preload_end();
25989 +void si_pid_clr_slow(struct super_block *sb)
25992 + struct au_sbinfo *sbinfo;
25994 + AuDebugOn(!si_pid_test_slow(sb));
25996 + sbinfo = au_sbi(sb);
25997 + spin_lock(&sbinfo->au_si_pid.tree_lock);
25998 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
25999 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26001 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26002 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26003 +++ linux/fs/aufs/spl.h 2015-04-13 15:10:20.790157026 +0200
26006 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26008 + * This program, aufs is free software; you can redistribute it and/or modify
26009 + * it under the terms of the GNU General Public License as published by
26010 + * the Free Software Foundation; either version 2 of the License, or
26011 + * (at your option) any later version.
26013 + * This program is distributed in the hope that it will be useful,
26014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26016 + * GNU General Public License for more details.
26018 + * You should have received a copy of the GNU General Public License
26019 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26023 + * simple list protected by a spinlock
26026 +#ifndef __AUFS_SPL_H__
26027 +#define __AUFS_SPL_H__
26031 +struct au_splhead {
26033 + struct list_head head;
26036 +static inline void au_spl_init(struct au_splhead *spl)
26038 + spin_lock_init(&spl->spin);
26039 + INIT_LIST_HEAD(&spl->head);
26042 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26044 + spin_lock(&spl->spin);
26045 + list_add(list, &spl->head);
26046 + spin_unlock(&spl->spin);
26049 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26051 + spin_lock(&spl->spin);
26053 + spin_unlock(&spl->spin);
26056 +static inline void au_spl_del_rcu(struct list_head *list,
26057 + struct au_splhead *spl)
26059 + spin_lock(&spl->spin);
26060 + list_del_rcu(list);
26061 + spin_unlock(&spl->spin);
26064 +/* ---------------------------------------------------------------------- */
26066 +struct au_sphlhead {
26068 + struct hlist_head head;
26071 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26073 + spin_lock_init(&sphl->spin);
26074 + INIT_HLIST_HEAD(&sphl->head);
26077 +static inline void au_sphl_add(struct hlist_node *hlist,
26078 + struct au_sphlhead *sphl)
26080 + spin_lock(&sphl->spin);
26081 + hlist_add_head(hlist, &sphl->head);
26082 + spin_unlock(&sphl->spin);
26085 +static inline void au_sphl_del(struct hlist_node *hlist,
26086 + struct au_sphlhead *sphl)
26088 + spin_lock(&sphl->spin);
26089 + hlist_del(hlist);
26090 + spin_unlock(&sphl->spin);
26093 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26094 + struct au_sphlhead *sphl)
26096 + spin_lock(&sphl->spin);
26097 + hlist_del_rcu(hlist);
26098 + spin_unlock(&sphl->spin);
26101 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26103 + unsigned long cnt;
26104 + struct hlist_node *pos;
26107 + spin_lock(&sphl->spin);
26108 + hlist_for_each(pos, &sphl->head)
26110 + spin_unlock(&sphl->spin);
26114 +#endif /* __KERNEL__ */
26115 +#endif /* __AUFS_SPL_H__ */
26116 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26117 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26118 +++ linux/fs/aufs/super.c 2015-04-13 15:10:20.790157026 +0200
26121 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26123 + * This program, aufs is free software; you can redistribute it and/or modify
26124 + * it under the terms of the GNU General Public License as published by
26125 + * the Free Software Foundation; either version 2 of the License, or
26126 + * (at your option) any later version.
26128 + * This program is distributed in the hope that it will be useful,
26129 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26130 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26131 + * GNU General Public License for more details.
26133 + * You should have received a copy of the GNU General Public License
26134 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26138 + * mount and super_block operations
26141 +#include <linux/mm.h>
26142 +#include <linux/seq_file.h>
26143 +#include <linux/statfs.h>
26144 +#include <linux/vmalloc.h>
26148 + * super_operations
26150 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26152 + struct au_icntnr *c;
26154 + c = au_cache_alloc_icntnr();
26156 + au_icntnr_init(c);
26157 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26158 + c->iinfo.ii_hinode = NULL;
26159 + return &c->vfs_inode;
26164 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26166 + struct inode *inode = container_of(head, struct inode, i_rcu);
26168 + INIT_HLIST_HEAD(&inode->i_dentry);
26169 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26172 +static void aufs_destroy_inode(struct inode *inode)
26174 + au_iinfo_fin(inode);
26175 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26178 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26180 + struct inode *inode;
26183 + inode = iget_locked(sb, ino);
26184 + if (unlikely(!inode)) {
26185 + inode = ERR_PTR(-ENOMEM);
26188 + if (!(inode->i_state & I_NEW))
26191 + err = au_xigen_new(inode);
26193 + err = au_iinfo_init(inode);
26195 + inode->i_version++;
26197 + iget_failed(inode);
26198 + inode = ERR_PTR(err);
26202 + /* never return NULL */
26203 + AuDebugOn(!inode);
26204 + AuTraceErrPtr(inode);
26208 +/* lock free root dinfo */
26209 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26212 + aufs_bindex_t bindex, bend;
26213 + struct path path;
26214 + struct au_hdentry *hdp;
26215 + struct au_branch *br;
26216 + au_br_perm_str_t perm;
26219 + bend = au_sbend(sb);
26220 + hdp = au_di(sb->s_root)->di_hdentry;
26221 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26222 + br = au_sbr(sb, bindex);
26223 + path.mnt = au_br_mnt(br);
26224 + path.dentry = hdp[bindex].hd_dentry;
26225 + err = au_seq_path(seq, &path);
26227 + au_optstr_br_perm(&perm, br->br_perm);
26228 + err = seq_printf(seq, "=%s", perm.a);
26232 + if (!err && bindex != bend)
26233 + err = seq_putc(seq, ':');
26239 +static void au_show_wbr_create(struct seq_file *m, int v,
26240 + struct au_sbinfo *sbinfo)
26244 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26246 + seq_puts(m, ",create=");
26247 + pat = au_optstr_wbr_create(v);
26249 + case AuWbrCreate_TDP:
26250 + case AuWbrCreate_RR:
26251 + case AuWbrCreate_MFS:
26252 + case AuWbrCreate_PMFS:
26253 + seq_puts(m, pat);
26255 + case AuWbrCreate_MFSV:
26256 + seq_printf(m, /*pat*/"mfs:%lu",
26257 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26260 + case AuWbrCreate_PMFSV:
26261 + seq_printf(m, /*pat*/"pmfs:%lu",
26262 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26265 + case AuWbrCreate_MFSRR:
26266 + seq_printf(m, /*pat*/"mfsrr:%llu",
26267 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26269 + case AuWbrCreate_MFSRRV:
26270 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26271 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26272 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26275 + case AuWbrCreate_PMFSRR:
26276 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26277 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26279 + case AuWbrCreate_PMFSRRV:
26280 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26281 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26282 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26288 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26290 +#ifdef CONFIG_SYSFS
26294 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26295 + aufs_bindex_t bindex, brid;
26296 + struct qstr *name;
26298 + struct dentry *d, *h_root;
26299 + struct au_hdentry *hdp;
26301 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26304 + f = au_sbi(sb)->si_xib;
26308 + /* stop printing the default xino path on the first writable branch */
26310 + brid = au_xino_brid(sb);
26312 + bindex = au_br_index(sb, brid);
26313 + hdp = au_di(sb->s_root)->di_hdentry;
26314 + h_root = hdp[0 + bindex].hd_dentry;
26316 + d = f->f_path.dentry;
26317 + name = &d->d_name;
26318 + /* safe ->d_parent because the file is unlinked */
26319 + if (d->d_parent == h_root
26320 + && name->len == len
26321 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26324 + seq_puts(seq, ",xino=");
26325 + err = au_xino_path(seq, f);
26332 +/* seq_file will re-call me in case of too long string */
26333 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26336 + unsigned int mnt_flags, v;
26337 + struct super_block *sb;
26338 + struct au_sbinfo *sbinfo;
26340 +#define AuBool(name, str) do { \
26341 + v = au_opt_test(mnt_flags, name); \
26342 + if (v != au_opt_test(AuOpt_Def, name)) \
26343 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26346 +#define AuStr(name, str) do { \
26347 + v = mnt_flags & AuOptMask_##name; \
26348 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26349 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26352 +#define AuUInt(name, str, val) do { \
26353 + if (val != AUFS_##name##_DEF) \
26354 + seq_printf(m, "," #str "=%u", val); \
26357 + sb = dentry->d_sb;
26358 + if (sb->s_flags & MS_POSIXACL)
26359 + seq_puts(m, ",acl");
26361 + /* lock free root dinfo */
26362 + si_noflush_read_lock(sb);
26363 + sbinfo = au_sbi(sb);
26364 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26366 + mnt_flags = au_mntflags(sb);
26367 + if (au_opt_test(mnt_flags, XINO)) {
26368 + err = au_show_xino(m, sb);
26369 + if (unlikely(err))
26372 + seq_puts(m, ",noxino");
26374 + AuBool(TRUNC_XINO, trunc_xino);
26375 + AuStr(UDBA, udba);
26376 + AuBool(SHWH, shwh);
26377 + AuBool(PLINK, plink);
26378 + AuBool(DIO, dio);
26379 + AuBool(DIRPERM1, dirperm1);
26380 + /* AuBool(REFROF, refrof); */
26382 + v = sbinfo->si_wbr_create;
26383 + if (v != AuWbrCreate_Def)
26384 + au_show_wbr_create(m, v, sbinfo);
26386 + v = sbinfo->si_wbr_copyup;
26387 + if (v != AuWbrCopyup_Def)
26388 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26390 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26391 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26392 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26394 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26396 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26397 + AuUInt(RDCACHE, rdcache, v);
26399 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26400 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26402 + au_fhsm_show(m, sbinfo);
26404 + AuBool(SUM, sum);
26405 + /* AuBool(SUM_W, wsum); */
26406 + AuBool(WARN_PERM, warn_perm);
26407 + AuBool(VERBOSE, verbose);
26410 + /* be sure to print "br:" last */
26411 + if (!sysaufs_brs) {
26412 + seq_puts(m, ",br:");
26413 + au_show_brs(m, sb);
26415 + si_read_unlock(sb);
26423 +/* ---------------------------------------------------------------------- */
26425 +/* sum mode which returns the summation for statfs(2) */
26427 +static u64 au_add_till_max(u64 a, u64 b)
26435 + return ULLONG_MAX;
26438 +static u64 au_mul_till_max(u64 a, long mul)
26446 + return ULLONG_MAX;
26449 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26452 + long bsize, factor;
26453 + u64 blocks, bfree, bavail, files, ffree;
26454 + aufs_bindex_t bend, bindex, i;
26455 + unsigned char shared;
26456 + struct path h_path;
26457 + struct super_block *h_sb;
26460 + bsize = LONG_MAX;
26466 + bend = au_sbend(sb);
26467 + for (bindex = 0; bindex <= bend; bindex++) {
26468 + h_path.mnt = au_sbr_mnt(sb, bindex);
26469 + h_sb = h_path.mnt->mnt_sb;
26471 + for (i = 0; !shared && i < bindex; i++)
26472 + shared = (au_sbr_sb(sb, i) == h_sb);
26476 + /* sb->s_root for NFS is unreliable */
26477 + h_path.dentry = h_path.mnt->mnt_root;
26478 + err = vfs_statfs(&h_path, buf);
26479 + if (unlikely(err))
26482 + if (bsize > buf->f_bsize) {
26484 + * we will reduce bsize, so we have to expand blocks
26485 + * etc. to match them again
26487 + factor = (bsize / buf->f_bsize);
26488 + blocks = au_mul_till_max(blocks, factor);
26489 + bfree = au_mul_till_max(bfree, factor);
26490 + bavail = au_mul_till_max(bavail, factor);
26491 + bsize = buf->f_bsize;
26494 + factor = (buf->f_bsize / bsize);
26495 + blocks = au_add_till_max(blocks,
26496 + au_mul_till_max(buf->f_blocks, factor));
26497 + bfree = au_add_till_max(bfree,
26498 + au_mul_till_max(buf->f_bfree, factor));
26499 + bavail = au_add_till_max(bavail,
26500 + au_mul_till_max(buf->f_bavail, factor));
26501 + files = au_add_till_max(files, buf->f_files);
26502 + ffree = au_add_till_max(ffree, buf->f_ffree);
26505 + buf->f_bsize = bsize;
26506 + buf->f_blocks = blocks;
26507 + buf->f_bfree = bfree;
26508 + buf->f_bavail = bavail;
26509 + buf->f_files = files;
26510 + buf->f_ffree = ffree;
26511 + buf->f_frsize = 0;
26517 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26520 + struct path h_path;
26521 + struct super_block *sb;
26523 + /* lock free root dinfo */
26524 + sb = dentry->d_sb;
26525 + si_noflush_read_lock(sb);
26526 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26527 + /* sb->s_root for NFS is unreliable */
26528 + h_path.mnt = au_sbr_mnt(sb, 0);
26529 + h_path.dentry = h_path.mnt->mnt_root;
26530 + err = vfs_statfs(&h_path, buf);
26532 + err = au_statfs_sum(sb, buf);
26533 + si_read_unlock(sb);
26536 + buf->f_type = AUFS_SUPER_MAGIC;
26537 + buf->f_namelen = AUFS_MAX_NAMELEN;
26538 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
26540 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
26545 +/* ---------------------------------------------------------------------- */
26547 +static int aufs_sync_fs(struct super_block *sb, int wait)
26550 + aufs_bindex_t bend, bindex;
26551 + struct au_branch *br;
26552 + struct super_block *h_sb;
26555 + si_noflush_read_lock(sb);
26556 + bend = au_sbend(sb);
26557 + for (bindex = 0; bindex <= bend; bindex++) {
26558 + br = au_sbr(sb, bindex);
26559 + if (!au_br_writable(br->br_perm))
26562 + h_sb = au_sbr_sb(sb, bindex);
26563 + if (h_sb->s_op->sync_fs) {
26564 + e = h_sb->s_op->sync_fs(h_sb, wait);
26565 + if (unlikely(e && !err))
26567 + /* go on even if an error happens */
26570 + si_read_unlock(sb);
26575 +/* ---------------------------------------------------------------------- */
26577 +/* final actions when unmounting a file system */
26578 +static void aufs_put_super(struct super_block *sb)
26580 + struct au_sbinfo *sbinfo;
26582 + sbinfo = au_sbi(sb);
26586 + dbgaufs_si_fin(sbinfo);
26587 + kobject_put(&sbinfo->si_kobj);
26590 +/* ---------------------------------------------------------------------- */
26592 +void au_array_free(void *array)
26595 + if (!is_vmalloc_addr(array))
26602 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
26605 + unsigned long long n, sz;
26612 + if (*hint > ULLONG_MAX / sizeof(array)) {
26613 + array = ERR_PTR(-EMFILE);
26614 + pr_err("hint %llu\n", *hint);
26618 + sz = sizeof(array) * *hint;
26619 + array = kzalloc(sz, GFP_NOFS);
26620 + if (unlikely(!array))
26621 + array = vzalloc(sz);
26622 + if (unlikely(!array)) {
26623 + array = ERR_PTR(-ENOMEM);
26627 + n = cb(array, *hint, arg);
26628 + AuDebugOn(n > *hint);
26635 +static unsigned long long au_iarray_cb(void *a,
26636 + unsigned long long max __maybe_unused,
26639 + unsigned long long n;
26640 + struct inode **p, *inode;
26641 + struct list_head *head;
26646 + spin_lock(&inode_sb_list_lock);
26647 + list_for_each_entry(inode, head, i_sb_list) {
26648 + if (!is_bad_inode(inode)
26649 + && au_ii(inode)->ii_bstart >= 0) {
26650 + spin_lock(&inode->i_lock);
26651 + if (atomic_read(&inode->i_count)) {
26655 + AuDebugOn(n > max);
26657 + spin_unlock(&inode->i_lock);
26660 + spin_unlock(&inode_sb_list_lock);
26665 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
26667 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
26668 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
26671 +void au_iarray_free(struct inode **a, unsigned long long max)
26673 + unsigned long long ull;
26675 + for (ull = 0; ull < max; ull++)
26677 + au_array_free(a);
26680 +/* ---------------------------------------------------------------------- */
26683 + * refresh dentry and inode at remount time.
26685 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
26686 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
26687 + struct dentry *parent)
26691 + di_write_lock_child(dentry);
26692 + di_read_lock_parent(parent, AuLock_IR);
26693 + err = au_refresh_dentry(dentry, parent);
26694 + if (!err && dir_flags)
26695 + au_hn_reset(dentry->d_inode, dir_flags);
26696 + di_read_unlock(parent, AuLock_IR);
26697 + di_write_unlock(dentry);
26702 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
26703 + struct au_sbinfo *sbinfo,
26704 + const unsigned int dir_flags)
26707 + struct dentry *parent;
26708 + struct inode *inode;
26711 + parent = dget_parent(dentry);
26712 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
26713 + inode = dentry->d_inode;
26715 + if (!S_ISDIR(inode->i_mode))
26716 + err = au_do_refresh(dentry, /*dir_flags*/0,
26719 + err = au_do_refresh(dentry, dir_flags, parent);
26720 + if (unlikely(err))
26721 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
26724 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
26725 + AuDbgDentry(dentry);
26733 +static int au_refresh_d(struct super_block *sb)
26735 + int err, i, j, ndentry, e;
26736 + unsigned int sigen;
26737 + struct au_dcsub_pages dpages;
26738 + struct au_dpage *dpage;
26739 + struct dentry **dentries, *d;
26740 + struct au_sbinfo *sbinfo;
26741 + struct dentry *root = sb->s_root;
26742 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
26744 + err = au_dpages_init(&dpages, GFP_NOFS);
26745 + if (unlikely(err))
26747 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
26748 + if (unlikely(err))
26751 + sigen = au_sigen(sb);
26752 + sbinfo = au_sbi(sb);
26753 + for (i = 0; i < dpages.ndpage; i++) {
26754 + dpage = dpages.dpages + i;
26755 + dentries = dpage->dentries;
26756 + ndentry = dpage->ndentry;
26757 + for (j = 0; j < ndentry; j++) {
26759 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
26760 + if (unlikely(e && !err))
26762 + /* go on even err */
26767 + au_dpages_free(&dpages);
26772 +static int au_refresh_i(struct super_block *sb)
26775 + unsigned int sigen;
26776 + unsigned long long max, ull;
26777 + struct inode *inode, **array;
26779 + array = au_iarray_alloc(sb, &max);
26780 + err = PTR_ERR(array);
26781 + if (IS_ERR(array))
26785 + sigen = au_sigen(sb);
26786 + for (ull = 0; ull < max; ull++) {
26787 + inode = array[ull];
26788 + if (unlikely(!inode))
26790 + if (au_iigen(inode, NULL) != sigen) {
26791 + ii_write_lock_child(inode);
26792 + e = au_refresh_hinode_self(inode);
26793 + ii_write_unlock(inode);
26794 + if (unlikely(e)) {
26795 + pr_err("error %d, i%lu\n", e, inode->i_ino);
26798 + /* go on even if err */
26803 + au_iarray_free(array, max);
26809 +static void au_remount_refresh(struct super_block *sb)
26812 + unsigned int udba;
26813 + aufs_bindex_t bindex, bend;
26814 + struct dentry *root;
26815 + struct inode *inode;
26816 + struct au_branch *br;
26818 + au_sigen_inc(sb);
26819 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
26821 + root = sb->s_root;
26822 + DiMustNoWaiters(root);
26823 + inode = root->d_inode;
26824 + IiMustNoWaiters(inode);
26826 + udba = au_opt_udba(sb);
26827 + bend = au_sbend(sb);
26828 + for (bindex = 0; bindex <= bend; bindex++) {
26829 + br = au_sbr(sb, bindex);
26830 + err = au_hnotify_reset_br(udba, br, br->br_perm);
26831 + if (unlikely(err))
26832 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
26834 + /* go on even if err */
26836 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
26838 + di_write_unlock(root);
26839 + err = au_refresh_d(sb);
26840 + e = au_refresh_i(sb);
26841 + if (unlikely(e && !err))
26843 + /* aufs_write_lock() calls ..._child() */
26844 + di_write_lock_child(root);
26846 + au_cpup_attr_all(inode, /*force*/1);
26848 + if (unlikely(err))
26849 + AuIOErr("refresh failed, ignored, %d\n", err);
26852 +/* stop extra interpretation of errno in mount(8), and strange error messages */
26853 +static int cvt_err(int err)
26867 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
26870 + unsigned int mntflags;
26871 + struct au_opts opts;
26872 + struct dentry *root;
26873 + struct inode *inode;
26874 + struct au_sbinfo *sbinfo;
26877 + root = sb->s_root;
26878 + if (!data || !*data) {
26879 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
26881 + di_write_lock_child(root);
26882 + err = au_opts_verify(sb, *flags, /*pending*/0);
26883 + aufs_write_unlock(root);
26889 + memset(&opts, 0, sizeof(opts));
26890 + opts.opt = (void *)__get_free_page(GFP_NOFS);
26891 + if (unlikely(!opts.opt))
26893 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
26894 + opts.flags = AuOpts_REMOUNT;
26895 + opts.sb_flags = *flags;
26897 + /* parse it before aufs lock */
26898 + err = au_opts_parse(sb, data, &opts);
26899 + if (unlikely(err))
26902 + sbinfo = au_sbi(sb);
26903 + inode = root->d_inode;
26904 + mutex_lock(&inode->i_mutex);
26905 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
26906 + if (unlikely(err))
26908 + di_write_lock_child(root);
26910 + /* au_opts_remount() may return an error */
26911 + err = au_opts_remount(sb, &opts);
26912 + au_opts_free(&opts);
26914 + if (au_ftest_opts(opts.flags, REFRESH))
26915 + au_remount_refresh(sb);
26917 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
26918 + mntflags = au_mntflags(sb);
26919 + do_dx = !!au_opt_test(mntflags, DIO);
26920 + au_dy_arefresh(do_dx);
26923 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
26924 + aufs_write_unlock(root);
26927 + mutex_unlock(&inode->i_mutex);
26929 + free_page((unsigned long)opts.opt);
26931 + err = cvt_err(err);
26936 +static const struct super_operations aufs_sop = {
26937 + .alloc_inode = aufs_alloc_inode,
26938 + .destroy_inode = aufs_destroy_inode,
26939 + /* always deleting, no clearing */
26940 + .drop_inode = generic_delete_inode,
26941 + .show_options = aufs_show_options,
26942 + .statfs = aufs_statfs,
26943 + .put_super = aufs_put_super,
26944 + .sync_fs = aufs_sync_fs,
26945 + .remount_fs = aufs_remount_fs
26948 +/* ---------------------------------------------------------------------- */
26950 +static int alloc_root(struct super_block *sb)
26953 + struct inode *inode;
26954 + struct dentry *root;
26957 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
26958 + err = PTR_ERR(inode);
26959 + if (IS_ERR(inode))
26962 + inode->i_op = &aufs_dir_iop;
26963 + inode->i_fop = &aufs_dir_fop;
26964 + inode->i_mode = S_IFDIR;
26965 + set_nlink(inode, 2);
26966 + unlock_new_inode(inode);
26968 + root = d_make_root(inode);
26969 + if (unlikely(!root))
26971 + err = PTR_ERR(root);
26972 + if (IS_ERR(root))
26975 + err = au_di_init(root);
26977 + sb->s_root = root;
26978 + return 0; /* success */
26986 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
26987 + int silent __maybe_unused)
26990 + struct au_opts opts;
26991 + struct dentry *root;
26992 + struct inode *inode;
26993 + char *arg = raw_data;
26995 + if (unlikely(!arg || !*arg)) {
26997 + pr_err("no arg\n");
27002 + memset(&opts, 0, sizeof(opts));
27003 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27004 + if (unlikely(!opts.opt))
27006 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27007 + opts.sb_flags = sb->s_flags;
27009 + err = au_si_alloc(sb);
27010 + if (unlikely(err))
27013 + /* all timestamps always follow the ones on the branch */
27014 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27015 + sb->s_op = &aufs_sop;
27016 + sb->s_d_op = &aufs_dop;
27017 + sb->s_magic = AUFS_SUPER_MAGIC;
27018 + sb->s_maxbytes = 0;
27019 + sb->s_stack_depth = 1;
27020 + au_export_init(sb);
27021 + /* au_xattr_init(sb); */
27023 + err = alloc_root(sb);
27024 + if (unlikely(err)) {
27025 + si_write_unlock(sb);
27028 + root = sb->s_root;
27029 + inode = root->d_inode;
27032 + * actually we can parse options regardless aufs lock here.
27033 + * but at remount time, parsing must be done before aufs lock.
27034 + * so we follow the same rule.
27036 + ii_write_lock_parent(inode);
27037 + aufs_write_unlock(root);
27038 + err = au_opts_parse(sb, arg, &opts);
27039 + if (unlikely(err))
27042 + /* lock vfs_inode first, then aufs. */
27043 + mutex_lock(&inode->i_mutex);
27044 + aufs_write_lock(root);
27045 + err = au_opts_mount(sb, &opts);
27046 + au_opts_free(&opts);
27047 + aufs_write_unlock(root);
27048 + mutex_unlock(&inode->i_mutex);
27050 + goto out_opts; /* success */
27054 + sb->s_root = NULL;
27056 + dbgaufs_si_fin(au_sbi(sb));
27057 + kobject_put(&au_sbi(sb)->si_kobj);
27058 + sb->s_fs_info = NULL;
27060 + free_page((unsigned long)opts.opt);
27063 + err = cvt_err(err);
27068 +/* ---------------------------------------------------------------------- */
27070 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27071 + const char *dev_name __maybe_unused,
27074 + struct dentry *root;
27075 + struct super_block *sb;
27077 + /* all timestamps always follow the ones on the branch */
27078 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27079 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27080 + if (IS_ERR(root))
27084 + si_write_lock(sb, !AuLock_FLUSH);
27085 + sysaufs_brs_add(sb, 0);
27086 + si_write_unlock(sb);
27087 + au_sbilist_add(sb);
27093 +static void aufs_kill_sb(struct super_block *sb)
27095 + struct au_sbinfo *sbinfo;
27097 + sbinfo = au_sbi(sb);
27099 + au_sbilist_del(sb);
27100 + aufs_write_lock(sb->s_root);
27102 + if (sbinfo->si_wbr_create_ops->fin)
27103 + sbinfo->si_wbr_create_ops->fin(sb);
27104 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27105 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27106 + au_remount_refresh(sb);
27108 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27109 + au_plink_put(sb, /*verbose*/1);
27111 + sbinfo->si_sb = NULL;
27112 + aufs_write_unlock(sb->s_root);
27113 + au_nwt_flush(&sbinfo->si_nowait);
27115 + kill_anon_super(sb);
27118 +struct file_system_type aufs_fs_type = {
27119 + .name = AUFS_FSTYPE,
27120 + /* a race between rename and others */
27121 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27122 + .mount = aufs_mount,
27123 + .kill_sb = aufs_kill_sb,
27124 + /* no need to __module_get() and module_put(). */
27125 + .owner = THIS_MODULE,
27127 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27128 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27129 +++ linux/fs/aufs/super.h 2015-04-13 15:10:20.790157026 +0200
27132 + * Copyright (C) 2005-2015 Junjiro R. Okajima
27134 + * This program, aufs is free software; you can redistribute it and/or modify
27135 + * it under the terms of the GNU General Public License as published by
27136 + * the Free Software Foundation; either version 2 of the License, or
27137 + * (at your option) any later version.
27139 + * This program is distributed in the hope that it will be useful,
27140 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27141 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27142 + * GNU General Public License for more details.
27144 + * You should have received a copy of the GNU General Public License
27145 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27149 + * super_block operations
27152 +#ifndef __AUFS_SUPER_H__
27153 +#define __AUFS_SUPER_H__
27157 +#include <linux/fs.h>
27158 +#include "rwsem.h"
27162 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
27163 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
27166 +/* policies to select one among multiple writable branches */
27167 +struct au_wbr_copyup_operations {
27168 + int (*copyup)(struct dentry *dentry);
27171 +#define AuWbr_DIR 1 /* target is a dir */
27172 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27174 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27175 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27176 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27178 +struct au_wbr_create_operations {
27179 + int (*create)(struct dentry *dentry, unsigned int flags);
27180 + int (*init)(struct super_block *sb);
27181 + int (*fin)(struct super_block *sb);
27184 +struct au_wbr_mfs {
27185 + struct mutex mfs_lock; /* protect this structure */
27186 + unsigned long mfs_jiffy;
27187 + unsigned long mfs_expire;
27188 + aufs_bindex_t mfs_bindex;
27190 + unsigned long long mfsrr_bytes;
27191 + unsigned long long mfsrr_watermark;
27194 +struct pseudo_link {
27196 + struct hlist_node hlist;
27197 + struct rcu_head rcu;
27199 + struct inode *inode;
27202 +#define AuPlink_NHASH 100
27203 +static inline int au_plink_hash(ino_t ino)
27205 + return ino % AuPlink_NHASH;
27208 +/* File-based Hierarchical Storage Management */
27210 +#ifdef CONFIG_AUFS_FHSM
27211 + /* allow only one process who can receive the notification */
27212 + spinlock_t fhsm_spin;
27214 + wait_queue_head_t fhsm_wqh;
27215 + atomic_t fhsm_readable;
27217 + /* these are protected by si_rwsem */
27218 + unsigned long fhsm_expire;
27219 + aufs_bindex_t fhsm_bottom;
27224 +struct au_sbinfo {
27225 + /* nowait tasks in the system-wide workqueue */
27226 + struct au_nowait_tasks si_nowait;
27229 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27230 + * rwsem for au_sbinfo is necessary.
27232 + struct au_rwsem si_rwsem;
27234 + /* prevent recursive locking in deleting inode */
27236 + unsigned long *bitmap;
27237 + spinlock_t tree_lock;
27238 + struct radix_tree_root tree;
27242 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27245 + atomic_long_t si_ninodes, si_nfiles;
27247 + /* branch management */
27248 + unsigned int si_generation;
27250 + /* see AuSi_ flags */
27251 + unsigned char au_si_status;
27253 + aufs_bindex_t si_bend;
27255 + /* dirty trick to keep br_id plus */
27256 + unsigned int si_last_br_id :
27257 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27258 + struct au_branch **si_branch;
27260 + /* policy to select a writable branch */
27261 + unsigned char si_wbr_copyup;
27262 + unsigned char si_wbr_create;
27263 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27264 + struct au_wbr_create_operations *si_wbr_create_ops;
27266 + /* round robin */
27267 + atomic_t si_wbr_rr_next;
27269 + /* most free space */
27270 + struct au_wbr_mfs si_wbr_mfs;
27272 + /* File-based Hierarchical Storage Management */
27273 + struct au_fhsm si_fhsm;
27275 + /* mount flags */
27276 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27277 + unsigned int si_mntflags;
27279 + /* external inode number (bitmap and translation table) */
27280 + au_readf_t si_xread;
27281 + au_writef_t si_xwrite;
27282 + struct file *si_xib;
27283 + struct mutex si_xib_mtx; /* protect xib members */
27284 + unsigned long *si_xib_buf;
27285 + unsigned long si_xib_last_pindex;
27286 + int si_xib_next_bit;
27287 + aufs_bindex_t si_xino_brid;
27288 + unsigned long si_xino_jiffy;
27289 + unsigned long si_xino_expire;
27290 + /* reserved for future use */
27291 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27293 +#ifdef CONFIG_AUFS_EXPORT
27294 + /* i_generation */
27295 + struct file *si_xigen;
27296 + atomic_t si_xigen_next;
27299 + /* vdir parameters */
27300 + unsigned long si_rdcache; /* max cache time in jiffies */
27301 + unsigned int si_rdblk; /* deblk size */
27302 + unsigned int si_rdhash; /* hash size */
27305 + * If the number of whiteouts are larger than si_dirwh, leave all of
27306 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
27307 + * future fsck.aufs or kernel thread will remove them later.
27308 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27310 + unsigned int si_dirwh;
27312 + /* pseudo_link list */
27313 + struct au_sphlhead si_plink[AuPlink_NHASH];
27314 + wait_queue_head_t si_plink_wq;
27315 + spinlock_t si_plink_maint_lock;
27316 + pid_t si_plink_maint_pid;
27319 + struct au_sphlhead si_files;
27322 + * sysfs and lifetime management.
27323 + * this is not a small structure and it may be a waste of memory in case
27324 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27325 + * but using sysfs is majority.
27327 + struct kobject si_kobj;
27328 +#ifdef CONFIG_DEBUG_FS
27329 + struct dentry *si_dbgaufs;
27330 + struct dentry *si_dbgaufs_plink;
27331 + struct dentry *si_dbgaufs_xib;
27332 +#ifdef CONFIG_AUFS_EXPORT
27333 + struct dentry *si_dbgaufs_xigen;
27337 +#ifdef CONFIG_AUFS_SBILIST
27338 + struct list_head si_list;
27341 + /* dirty, necessary for unmounting, sysfs and sysrq */
27342 + struct super_block *si_sb;
27345 +/* sbinfo status flags */
27347 + * set true when refresh_dirs() failed at remount time.
27348 + * then try refreshing dirs at access time again.
27349 + * if it is false, refreshing dirs at access time is unnecesary
27351 +#define AuSi_FAILED_REFRESH_DIR 1
27353 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27355 +#ifndef CONFIG_AUFS_FHSM
27357 +#define AuSi_FHSM 0
27360 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27361 + unsigned int flag)
27363 + AuRwMustAnyLock(&sbi->si_rwsem);
27364 + return sbi->au_si_status & flag;
27366 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27367 +#define au_fset_si(sbinfo, name) do { \
27368 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27369 + (sbinfo)->au_si_status |= AuSi_##name; \
27371 +#define au_fclr_si(sbinfo, name) do { \
27372 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27373 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27376 +/* ---------------------------------------------------------------------- */
27378 +/* policy to select one among writable branches */
27379 +#define AuWbrCopyup(sbinfo, ...) \
27380 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27381 +#define AuWbrCreate(sbinfo, ...) \
27382 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27384 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27385 +#define AuLock_DW 1 /* write-lock dentry */
27386 +#define AuLock_IR (1 << 1) /* read-lock inode */
27387 +#define AuLock_IW (1 << 2) /* write-lock inode */
27388 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27389 +#define AuLock_DIR (1 << 4) /* target is a dir */
27390 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27391 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27392 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27393 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27394 +#define au_fset_lock(flags, name) \
27395 + do { (flags) |= AuLock_##name; } while (0)
27396 +#define au_fclr_lock(flags, name) \
27397 + do { (flags) &= ~AuLock_##name; } while (0)
27399 +/* ---------------------------------------------------------------------- */
27402 +extern struct file_system_type aufs_fs_type;
27403 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27404 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
27406 +void au_array_free(void *array);
27407 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
27408 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27409 +void au_iarray_free(struct inode **a, unsigned long long max);
27412 +void au_si_free(struct kobject *kobj);
27413 +int au_si_alloc(struct super_block *sb);
27414 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27416 +unsigned int au_sigen_inc(struct super_block *sb);
27417 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27419 +int si_read_lock(struct super_block *sb, int flags);
27420 +int si_write_lock(struct super_block *sb, int flags);
27421 +int aufs_read_lock(struct dentry *dentry, int flags);
27422 +void aufs_read_unlock(struct dentry *dentry, int flags);
27423 +void aufs_write_lock(struct dentry *dentry);
27424 +void aufs_write_unlock(struct dentry *dentry);
27425 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27426 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27428 +int si_pid_test_slow(struct super_block *sb);
27429 +void si_pid_set_slow(struct super_block *sb);
27430 +void si_pid_clr_slow(struct super_block *sb);
27432 +/* wbr_policy.c */
27433 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27434 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27435 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27436 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27437 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27440 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27442 +#ifdef CONFIG_AUFS_FHSM
27445 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27449 + spin_lock(&fhsm->fhsm_spin);
27450 + pid = fhsm->fhsm_pid;
27451 + spin_unlock(&fhsm->fhsm_spin);
27456 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27457 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27458 +int au_fhsm_fd(struct super_block *sb, int oflags);
27459 +int au_fhsm_br_alloc(struct au_branch *br);
27460 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
27461 +void au_fhsm_fin(struct super_block *sb);
27462 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27463 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27464 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27466 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27468 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27469 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27470 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
27471 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
27472 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
27473 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27474 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27475 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27476 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27479 +/* ---------------------------------------------------------------------- */
27481 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27483 + return sb->s_fs_info;
27486 +/* ---------------------------------------------------------------------- */
27488 +#ifdef CONFIG_AUFS_EXPORT
27489 +int au_test_nfsd(void);
27490 +void au_export_init(struct super_block *sb);
27491 +void au_xigen_inc(struct inode *inode);
27492 +int au_xigen_new(struct inode *inode);
27493 +int au_xigen_set(struct super_block *sb, struct file *base);
27494 +void au_xigen_clr(struct super_block *sb);
27496 +static inline int au_busy_or_stale(void)
27498 + if (!au_test_nfsd())
27503 +AuStubInt0(au_test_nfsd, void)
27504 +AuStubVoid(au_export_init, struct super_block *sb)
27505 +AuStubVoid(au_xigen_inc, struct inode *inode)
27506 +AuStubInt0(au_xigen_new, struct inode *inode)
27507 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27508 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27509 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
27510 +#endif /* CONFIG_AUFS_EXPORT */
27512 +/* ---------------------------------------------------------------------- */
27514 +#ifdef CONFIG_AUFS_SBILIST
27516 +extern struct au_splhead au_sbilist;
27518 +static inline void au_sbilist_init(void)
27520 + au_spl_init(&au_sbilist);
27523 +static inline void au_sbilist_add(struct super_block *sb)
27525 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27528 +static inline void au_sbilist_del(struct super_block *sb)
27530 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27533 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27534 +static inline void au_sbilist_lock(void)
27536 + spin_lock(&au_sbilist.spin);
27539 +static inline void au_sbilist_unlock(void)
27541 + spin_unlock(&au_sbilist.spin);
27543 +#define AuGFP_SBILIST GFP_ATOMIC
27545 +AuStubVoid(au_sbilist_lock, void)
27546 +AuStubVoid(au_sbilist_unlock, void)
27547 +#define AuGFP_SBILIST GFP_NOFS
27548 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
27550 +AuStubVoid(au_sbilist_init, void)
27551 +AuStubVoid(au_sbilist_add, struct super_block *sb)
27552 +AuStubVoid(au_sbilist_del, struct super_block *sb)
27553 +AuStubVoid(au_sbilist_lock, void)
27554 +AuStubVoid(au_sbilist_unlock, void)
27555 +#define AuGFP_SBILIST GFP_NOFS
27558 +/* ---------------------------------------------------------------------- */
27560 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
27563 + * This function is a dynamic '__init' function actually,
27564 + * so the tiny check for si_rwsem is unnecessary.
27566 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
27567 +#ifdef CONFIG_DEBUG_FS
27568 + sbinfo->si_dbgaufs = NULL;
27569 + sbinfo->si_dbgaufs_plink = NULL;
27570 + sbinfo->si_dbgaufs_xib = NULL;
27571 +#ifdef CONFIG_AUFS_EXPORT
27572 + sbinfo->si_dbgaufs_xigen = NULL;
27577 +/* ---------------------------------------------------------------------- */
27579 +static inline pid_t si_pid_bit(void)
27581 + /* the origin of pid is 1, but the bitmap's is 0 */
27582 + return current->pid - 1;
27585 +static inline int si_pid_test(struct super_block *sb)
27589 + bit = si_pid_bit();
27590 + if (bit < PID_MAX_DEFAULT)
27591 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27592 + return si_pid_test_slow(sb);
27595 +static inline void si_pid_set(struct super_block *sb)
27599 + bit = si_pid_bit();
27600 + if (bit < PID_MAX_DEFAULT) {
27601 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27602 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27605 + si_pid_set_slow(sb);
27608 +static inline void si_pid_clr(struct super_block *sb)
27612 + bit = si_pid_bit();
27613 + if (bit < PID_MAX_DEFAULT) {
27614 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27615 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27618 + si_pid_clr_slow(sb);
27621 +/* ---------------------------------------------------------------------- */
27623 +/* lock superblock. mainly for entry point functions */
27625 + * __si_read_lock, __si_write_lock,
27626 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
27628 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
27630 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
27631 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
27632 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
27634 +static inline void si_noflush_read_lock(struct super_block *sb)
27636 + __si_read_lock(sb);
27640 +static inline int si_noflush_read_trylock(struct super_block *sb)
27644 + locked = __si_read_trylock(sb);
27650 +static inline void si_noflush_write_lock(struct super_block *sb)
27652 + __si_write_lock(sb);
27656 +static inline int si_noflush_write_trylock(struct super_block *sb)
27660 + locked = __si_write_trylock(sb);
27666 +#if 0 /* reserved */
27667 +static inline int si_read_trylock(struct super_block *sb, int flags)
27669 + if (au_ftest_lock(flags, FLUSH))
27670 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27671 + return si_noflush_read_trylock(sb);
27675 +static inline void si_read_unlock(struct super_block *sb)
27678 + __si_read_unlock(sb);
27681 +#if 0 /* reserved */
27682 +static inline int si_write_trylock(struct super_block *sb, int flags)
27684 + if (au_ftest_lock(flags, FLUSH))
27685 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27686 + return si_noflush_write_trylock(sb);
27690 +static inline void si_write_unlock(struct super_block *sb)
27693 + __si_write_unlock(sb);
27696 +#if 0 /* reserved */
27697 +static inline void si_downgrade_lock(struct super_block *sb)
27699 + __si_downgrade_lock(sb);
27703 +/* ---------------------------------------------------------------------- */
27705 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
27707 + SiMustAnyLock(sb);
27708 + return au_sbi(sb)->si_bend;
27711 +static inline unsigned int au_mntflags(struct super_block *sb)
27713 + SiMustAnyLock(sb);
27714 + return au_sbi(sb)->si_mntflags;
27717 +static inline unsigned int au_sigen(struct super_block *sb)
27719 + SiMustAnyLock(sb);
27720 + return au_sbi(sb)->si_generation;
27723 +static inline void au_ninodes_inc(struct super_block *sb)
27725 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
27728 +static inline void au_ninodes_dec(struct super_block *sb)
27730 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
27731 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
27734 +static inline void au_nfiles_inc(struct super_block *sb)
27736 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
27739 +static inline void au_nfiles_dec(struct super_block *sb)
27741 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
27742 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
27745 +static inline struct au_branch *au_sbr(struct super_block *sb,
27746 + aufs_bindex_t bindex)
27748 + SiMustAnyLock(sb);
27749 + return au_sbi(sb)->si_branch[0 + bindex];
27752 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
27754 + SiMustWriteLock(sb);
27755 + au_sbi(sb)->si_xino_brid = brid;
27758 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
27760 + SiMustAnyLock(sb);
27761 + return au_sbi(sb)->si_xino_brid;
27764 +#endif /* __KERNEL__ */
27765 +#endif /* __AUFS_SUPER_H__ */
27766 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
27767 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
27768 +++ linux/fs/aufs/sysaufs.c 2015-04-13 15:10:20.790157026 +0200
27771 + * Copyright (C) 2005-2015 Junjiro R. Okajima
27773 + * This program, aufs is free software; you can redistribute it and/or modify
27774 + * it under the terms of the GNU General Public License as published by
27775 + * the Free Software Foundation; either version 2 of the License, or
27776 + * (at your option) any later version.
27778 + * This program is distributed in the hope that it will be useful,
27779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27781 + * GNU General Public License for more details.
27783 + * You should have received a copy of the GNU General Public License
27784 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27788 + * sysfs interface and lifetime management
27789 + * they are necessary regardless sysfs is disabled.
27792 +#include <linux/random.h>
27795 +unsigned long sysaufs_si_mask;
27796 +struct kset *sysaufs_kset;
27798 +#define AuSiAttr(_name) { \
27799 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
27800 + .show = sysaufs_si_##_name, \
27803 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
27804 +struct attribute *sysaufs_si_attrs[] = {
27805 + &sysaufs_si_attr_xi_path.attr,
27809 +static const struct sysfs_ops au_sbi_ops = {
27810 + .show = sysaufs_si_show
27813 +static struct kobj_type au_sbi_ktype = {
27814 + .release = au_si_free,
27815 + .sysfs_ops = &au_sbi_ops,
27816 + .default_attrs = sysaufs_si_attrs
27819 +/* ---------------------------------------------------------------------- */
27821 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
27825 + sbinfo->si_kobj.kset = sysaufs_kset;
27826 + /* cf. sysaufs_name() */
27827 + err = kobject_init_and_add
27828 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
27829 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
27831 + dbgaufs_si_null(sbinfo);
27833 + err = dbgaufs_si_init(sbinfo);
27834 + if (unlikely(err))
27835 + kobject_put(&sbinfo->si_kobj);
27840 +void sysaufs_fin(void)
27843 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
27844 + kset_unregister(sysaufs_kset);
27847 +int __init sysaufs_init(void)
27852 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
27853 + } while (!sysaufs_si_mask);
27856 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
27857 + if (unlikely(!sysaufs_kset))
27859 + err = PTR_ERR(sysaufs_kset);
27860 + if (IS_ERR(sysaufs_kset))
27862 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
27863 + if (unlikely(err)) {
27864 + kset_unregister(sysaufs_kset);
27868 + err = dbgaufs_init();
27869 + if (unlikely(err))
27874 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
27875 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
27876 +++ linux/fs/aufs/sysaufs.h 2015-04-13 15:10:20.790157026 +0200
27879 + * Copyright (C) 2005-2015 Junjiro R. Okajima
27881 + * This program, aufs is free software; you can redistribute it and/or modify
27882 + * it under the terms of the GNU General Public License as published by
27883 + * the Free Software Foundation; either version 2 of the License, or
27884 + * (at your option) any later version.
27886 + * This program is distributed in the hope that it will be useful,
27887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27889 + * GNU General Public License for more details.
27891 + * You should have received a copy of the GNU General Public License
27892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27896 + * sysfs interface and mount lifetime management
27899 +#ifndef __SYSAUFS_H__
27900 +#define __SYSAUFS_H__
27904 +#include <linux/sysfs.h>
27905 +#include "module.h"
27907 +struct super_block;
27910 +struct sysaufs_si_attr {
27911 + struct attribute attr;
27912 + int (*show)(struct seq_file *seq, struct super_block *sb);
27915 +/* ---------------------------------------------------------------------- */
27918 +extern unsigned long sysaufs_si_mask;
27919 +extern struct kset *sysaufs_kset;
27920 +extern struct attribute *sysaufs_si_attrs[];
27921 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
27922 +int __init sysaufs_init(void);
27923 +void sysaufs_fin(void);
27925 +/* ---------------------------------------------------------------------- */
27927 +/* some people doesn't like to show a pointer in kernel */
27928 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
27930 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
27933 +#define SysaufsSiNamePrefix "si_"
27934 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
27935 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
27937 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
27938 + sysaufs_si_id(sbinfo));
27942 +#ifdef CONFIG_SYSFS
27944 +extern struct attribute_group *sysaufs_attr_group;
27946 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
27947 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
27949 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
27950 +#ifdef CONFIG_COMPAT
27951 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
27954 +void sysaufs_br_init(struct au_branch *br);
27955 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
27956 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
27958 +#define sysaufs_brs_init() do {} while (0)
27961 +#define sysaufs_attr_group NULL
27963 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
27964 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
27965 + struct attribute *attr, char *buf)
27966 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
27967 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
27968 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
27970 +static inline void sysaufs_brs_init(void)
27975 +#endif /* CONFIG_SYSFS */
27977 +#endif /* __KERNEL__ */
27978 +#endif /* __SYSAUFS_H__ */
27979 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
27980 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
27981 +++ linux/fs/aufs/sysfs.c 2015-04-13 15:10:20.790157026 +0200
27984 + * Copyright (C) 2005-2015 Junjiro R. Okajima
27986 + * This program, aufs is free software; you can redistribute it and/or modify
27987 + * it under the terms of the GNU General Public License as published by
27988 + * the Free Software Foundation; either version 2 of the License, or
27989 + * (at your option) any later version.
27991 + * This program is distributed in the hope that it will be useful,
27992 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27993 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27994 + * GNU General Public License for more details.
27996 + * You should have received a copy of the GNU General Public License
27997 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28001 + * sysfs interface
28004 +#include <linux/compat.h>
28005 +#include <linux/seq_file.h>
28008 +#ifdef CONFIG_AUFS_FS_MODULE
28009 +/* this entry violates the "one line per file" policy of sysfs */
28010 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28014 + static char *conf =
28015 +/* this file is generated at compiling */
28016 +#include "conf.str"
28019 + err = snprintf(buf, PAGE_SIZE, conf);
28020 + if (unlikely(err >= PAGE_SIZE))
28025 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28028 +static struct attribute *au_attr[] = {
28029 +#ifdef CONFIG_AUFS_FS_MODULE
28030 + &au_config_attr.attr,
28032 + NULL, /* need to NULL terminate the list of attributes */
28035 +static struct attribute_group sysaufs_attr_group_body = {
28039 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28041 +/* ---------------------------------------------------------------------- */
28043 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28047 + SiMustAnyLock(sb);
28050 + if (au_opt_test(au_mntflags(sb), XINO)) {
28051 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28052 + seq_putc(seq, '\n');
28058 + * the lifetime of branch is independent from the entry under sysfs.
28059 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28062 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28063 + aufs_bindex_t bindex, int idx)
28066 + struct path path;
28067 + struct dentry *root;
28068 + struct au_branch *br;
28069 + au_br_perm_str_t perm;
28071 + AuDbg("b%d\n", bindex);
28074 + root = sb->s_root;
28075 + di_read_lock_parent(root, !AuLock_IR);
28076 + br = au_sbr(sb, bindex);
28079 + case AuBrSysfs_BR:
28080 + path.mnt = au_br_mnt(br);
28081 + path.dentry = au_h_dptr(root, bindex);
28082 + au_seq_path(seq, &path);
28083 + au_optstr_br_perm(&perm, br->br_perm);
28084 + err = seq_printf(seq, "=%s\n", perm.a);
28086 + case AuBrSysfs_BRID:
28087 + err = seq_printf(seq, "%d\n", br->br_id);
28090 + di_read_unlock(root, !AuLock_IR);
28097 +/* ---------------------------------------------------------------------- */
28099 +static struct seq_file *au_seq(char *p, ssize_t len)
28101 + struct seq_file *seq;
28103 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28105 + /* mutex_init(&seq.lock); */
28108 + return seq; /* success */
28111 + seq = ERR_PTR(-ENOMEM);
28115 +#define SysaufsBr_PREFIX "br"
28116 +#define SysaufsBrid_PREFIX "brid"
28118 +/* todo: file size may exceed PAGE_SIZE */
28119 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28125 + aufs_bindex_t bend;
28126 + struct au_sbinfo *sbinfo;
28127 + struct super_block *sb;
28128 + struct seq_file *seq;
28130 + struct attribute **cattr;
28132 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28133 + sb = sbinfo->si_sb;
28136 + * prevent a race condition between sysfs and aufs.
28137 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28138 + * prohibits maintaining the sysfs entries.
28139 + * hew we acquire read lock after sysfs_get_active_two().
28140 + * on the other hand, the remount process may maintain the sysfs/aufs
28141 + * entries after acquiring write lock.
28142 + * it can cause a deadlock.
28143 + * simply we gave up processing read here.
28146 + if (unlikely(!si_noflush_read_trylock(sb)))
28149 + seq = au_seq(buf, PAGE_SIZE);
28150 + err = PTR_ERR(seq);
28154 + name = (void *)attr->name;
28155 + cattr = sysaufs_si_attrs;
28157 + if (!strcmp(name, (*cattr)->name)) {
28158 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28165 + if (!strncmp(name, SysaufsBrid_PREFIX,
28166 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28167 + idx = AuBrSysfs_BRID;
28168 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28169 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28170 + sizeof(SysaufsBr_PREFIX) - 1)) {
28171 + idx = AuBrSysfs_BR;
28172 + name += sizeof(SysaufsBr_PREFIX) - 1;
28176 + err = kstrtol(name, 10, &l);
28178 + bend = au_sbend(sb);
28180 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28187 + err = seq->count;
28188 + /* sysfs limit */
28189 + if (unlikely(err == PAGE_SIZE))
28194 + si_read_unlock(sb);
28199 +/* ---------------------------------------------------------------------- */
28201 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28205 + aufs_bindex_t bindex, bend;
28208 + struct seq_file *seq;
28209 + struct au_branch *br;
28211 + si_read_lock(sb, AuLock_FLUSH);
28212 + bend = au_sbend(sb);
28218 + buf = (void *)__get_free_page(GFP_NOFS);
28219 + if (unlikely(!buf))
28222 + seq = au_seq(buf, PAGE_SIZE);
28223 + err = PTR_ERR(seq);
28227 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28228 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28229 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28230 + if (unlikely(err))
28233 + br = au_sbr(sb, bindex);
28234 + brid = br->br_id;
28235 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28236 + err = __put_user(brid, &arg->id);
28237 + if (unlikely(err))
28240 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28241 + err = __put_user(br->br_perm, &arg->perm);
28242 + if (unlikely(err))
28245 + au_seq_path(seq, &br->br_path);
28246 + err = seq_putc(seq, '\0');
28247 + if (!err && seq->count <= sz) {
28248 + err = copy_to_user(arg->path, seq->buf, seq->count);
28250 + if (unlikely(err))
28257 + if (unlikely(err))
28263 + free_page((unsigned long)buf);
28265 + si_read_unlock(sb);
28269 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28271 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
28274 +#ifdef CONFIG_COMPAT
28275 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28277 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
28281 +/* ---------------------------------------------------------------------- */
28283 +void sysaufs_br_init(struct au_branch *br)
28286 + struct au_brsysfs *br_sysfs;
28287 + struct attribute *attr;
28289 + br_sysfs = br->br_sysfs;
28290 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28291 + attr = &br_sysfs->attr;
28292 + sysfs_attr_init(attr);
28293 + attr->name = br_sysfs->name;
28294 + attr->mode = S_IRUGO;
28299 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28301 + struct au_branch *br;
28302 + struct kobject *kobj;
28303 + struct au_brsysfs *br_sysfs;
28305 + aufs_bindex_t bend;
28307 + dbgaufs_brs_del(sb, bindex);
28309 + if (!sysaufs_brs)
28312 + kobj = &au_sbi(sb)->si_kobj;
28313 + bend = au_sbend(sb);
28314 + for (; bindex <= bend; bindex++) {
28315 + br = au_sbr(sb, bindex);
28316 + br_sysfs = br->br_sysfs;
28317 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28318 + sysfs_remove_file(kobj, &br_sysfs->attr);
28324 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28327 + aufs_bindex_t bend;
28328 + struct kobject *kobj;
28329 + struct au_branch *br;
28330 + struct au_brsysfs *br_sysfs;
28332 + dbgaufs_brs_add(sb, bindex);
28334 + if (!sysaufs_brs)
28337 + kobj = &au_sbi(sb)->si_kobj;
28338 + bend = au_sbend(sb);
28339 + for (; bindex <= bend; bindex++) {
28340 + br = au_sbr(sb, bindex);
28341 + br_sysfs = br->br_sysfs;
28342 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28343 + SysaufsBr_PREFIX "%d", bindex);
28344 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28345 + SysaufsBrid_PREFIX "%d", bindex);
28346 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28347 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28348 + if (unlikely(err))
28349 + pr_warn("failed %s under sysfs(%d)\n",
28350 + br_sysfs->name, err);
28355 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
28356 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28357 +++ linux/fs/aufs/sysrq.c 2015-04-13 15:10:20.790157026 +0200
28360 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28362 + * This program, aufs is free software; you can redistribute it and/or modify
28363 + * it under the terms of the GNU General Public License as published by
28364 + * the Free Software Foundation; either version 2 of the License, or
28365 + * (at your option) any later version.
28367 + * This program is distributed in the hope that it will be useful,
28368 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28369 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28370 + * GNU General Public License for more details.
28372 + * You should have received a copy of the GNU General Public License
28373 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28377 + * magic sysrq hanlder
28380 +/* #include <linux/sysrq.h> */
28381 +#include <linux/writeback.h>
28384 +/* ---------------------------------------------------------------------- */
28386 +static void sysrq_sb(struct super_block *sb)
28389 + struct au_sbinfo *sbinfo;
28390 + struct file *file;
28391 + struct au_sphlhead *files;
28392 + struct au_finfo *finfo;
28394 + plevel = au_plevel;
28395 + au_plevel = KERN_WARNING;
28397 + /* since we define pr_fmt, call printk directly */
28398 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28400 + sbinfo = au_sbi(sb);
28401 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28402 + pr("superblock\n");
28406 + pr("root dentry\n");
28407 + au_dpri_dentry(sb->s_root);
28408 + pr("root inode\n");
28409 + au_dpri_inode(sb->s_root->d_inode);
28414 + int err, i, j, ndentry;
28415 + struct au_dcsub_pages dpages;
28416 + struct au_dpage *dpage;
28418 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28419 + if (unlikely(err))
28421 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28423 + for (i = 0; i < dpages.ndpage; i++) {
28424 + dpage = dpages.dpages + i;
28425 + ndentry = dpage->ndentry;
28426 + for (j = 0; j < ndentry; j++)
28427 + au_dpri_dentry(dpage->dentries[j]);
28429 + au_dpages_free(&dpages);
28437 + pr("isolated inode\n");
28438 + spin_lock(&inode_sb_list_lock);
28439 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28440 + spin_lock(&i->i_lock);
28441 + if (1 || hlist_empty(&i->i_dentry))
28442 + au_dpri_inode(i);
28443 + spin_unlock(&i->i_lock);
28445 + spin_unlock(&inode_sb_list_lock);
28449 + files = &au_sbi(sb)->si_files;
28450 + spin_lock(&files->spin);
28451 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28454 + file = finfo->fi_file;
28455 + mode = file_inode(file)->i_mode;
28456 + if (!special_file(mode))
28457 + au_dpri_file(file);
28459 + spin_unlock(&files->spin);
28463 + au_plevel = plevel;
28466 +/* ---------------------------------------------------------------------- */
28468 +/* module parameter */
28469 +static char *aufs_sysrq_key = "a";
28470 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28471 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28473 +static void au_sysrq(int key __maybe_unused)
28475 + struct au_sbinfo *sbinfo;
28478 + au_sbilist_lock();
28479 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28480 + sysrq_sb(sbinfo->si_sb);
28481 + au_sbilist_unlock();
28485 +static struct sysrq_key_op au_sysrq_op = {
28486 + .handler = au_sysrq,
28487 + .help_msg = "Aufs",
28488 + .action_msg = "Aufs",
28489 + .enable_mask = SYSRQ_ENABLE_DUMP
28492 +/* ---------------------------------------------------------------------- */
28494 +int __init au_sysrq_init(void)
28500 + key = *aufs_sysrq_key;
28501 + if ('a' <= key && key <= 'z')
28502 + err = register_sysrq_key(key, &au_sysrq_op);
28503 + if (unlikely(err))
28504 + pr_err("err %d, sysrq=%c\n", err, key);
28508 +void au_sysrq_fin(void)
28512 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28513 + if (unlikely(err))
28514 + pr_err("err %d (ignored)\n", err);
28516 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
28517 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28518 +++ linux/fs/aufs/vdir.c 2015-04-13 15:10:20.790157026 +0200
28521 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28523 + * This program, aufs is free software; you can redistribute it and/or modify
28524 + * it under the terms of the GNU General Public License as published by
28525 + * the Free Software Foundation; either version 2 of the License, or
28526 + * (at your option) any later version.
28528 + * This program is distributed in the hope that it will be useful,
28529 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28530 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28531 + * GNU General Public License for more details.
28533 + * You should have received a copy of the GNU General Public License
28534 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28538 + * virtual or vertical directory
28543 +static unsigned int calc_size(int nlen)
28545 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
28548 +static int set_deblk_end(union au_vdir_deblk_p *p,
28549 + union au_vdir_deblk_p *deblk_end)
28551 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
28552 + p->de->de_str.len = 0;
28556 + return -1; /* error */
28559 +/* returns true or false */
28560 +static int is_deblk_end(union au_vdir_deblk_p *p,
28561 + union au_vdir_deblk_p *deblk_end)
28563 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
28564 + return !p->de->de_str.len;
28568 +static unsigned char *last_deblk(struct au_vdir *vdir)
28570 + return vdir->vd_deblk[vdir->vd_nblk - 1];
28573 +/* ---------------------------------------------------------------------- */
28575 +/* estimate the apropriate size for name hash table */
28576 +unsigned int au_rdhash_est(loff_t sz)
28584 + if (sz < AUFS_RDHASH_DEF)
28585 + n = AUFS_RDHASH_DEF;
28586 + /* pr_info("n %u\n", n); */
28591 + * the allocated memory has to be freed by
28592 + * au_nhash_wh_free() or au_nhash_de_free().
28594 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
28596 + struct hlist_head *head;
28600 + sz = sizeof(*nhash->nh_head) * num_hash;
28601 + head = kmalloc(sz, gfp);
28603 + nhash->nh_num = num_hash;
28604 + nhash->nh_head = head;
28605 + for (u = 0; u < num_hash; u++)
28606 + INIT_HLIST_HEAD(head++);
28607 + return 0; /* success */
28613 +static void nhash_count(struct hlist_head *head)
28617 + struct hlist_node *pos;
28620 + hlist_for_each(pos, head)
28622 + pr_info("%lu\n", n);
28626 +static void au_nhash_wh_do_free(struct hlist_head *head)
28628 + struct au_vdir_wh *pos;
28629 + struct hlist_node *node;
28631 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
28635 +static void au_nhash_de_do_free(struct hlist_head *head)
28637 + struct au_vdir_dehstr *pos;
28638 + struct hlist_node *node;
28640 + hlist_for_each_entry_safe(pos, node, head, hash)
28641 + au_cache_free_vdir_dehstr(pos);
28644 +static void au_nhash_do_free(struct au_nhash *nhash,
28645 + void (*free)(struct hlist_head *head))
28648 + struct hlist_head *head;
28650 + n = nhash->nh_num;
28654 + head = nhash->nh_head;
28655 + while (n-- > 0) {
28656 + nhash_count(head);
28659 + kfree(nhash->nh_head);
28662 +void au_nhash_wh_free(struct au_nhash *whlist)
28664 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
28667 +static void au_nhash_de_free(struct au_nhash *delist)
28669 + au_nhash_do_free(delist, au_nhash_de_do_free);
28672 +/* ---------------------------------------------------------------------- */
28674 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
28678 + unsigned int u, n;
28679 + struct hlist_head *head;
28680 + struct au_vdir_wh *pos;
28683 + n = whlist->nh_num;
28684 + head = whlist->nh_head;
28685 + for (u = 0; u < n; u++, head++)
28686 + hlist_for_each_entry(pos, head, wh_hash)
28687 + if (pos->wh_bindex == btgt && ++num > limit)
28692 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
28693 + unsigned char *name,
28694 + unsigned int len)
28697 + /* const unsigned int magic_bit = 12; */
28699 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
28704 + /* v = hash_long(v, magic_bit); */
28705 + v %= nhash->nh_num;
28706 + return nhash->nh_head + v;
28709 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
28712 + return str->len == nlen && !memcmp(str->name, name, nlen);
28715 +/* returns found or not */
28716 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
28718 + struct hlist_head *head;
28719 + struct au_vdir_wh *pos;
28720 + struct au_vdir_destr *str;
28722 + head = au_name_hash(whlist, name, nlen);
28723 + hlist_for_each_entry(pos, head, wh_hash) {
28724 + str = &pos->wh_str;
28725 + AuDbg("%.*s\n", str->len, str->name);
28726 + if (au_nhash_test_name(str, name, nlen))
28732 +/* returns found(true) or not */
28733 +static int test_known(struct au_nhash *delist, char *name, int nlen)
28735 + struct hlist_head *head;
28736 + struct au_vdir_dehstr *pos;
28737 + struct au_vdir_destr *str;
28739 + head = au_name_hash(delist, name, nlen);
28740 + hlist_for_each_entry(pos, head, hash) {
28742 + AuDbg("%.*s\n", str->len, str->name);
28743 + if (au_nhash_test_name(str, name, nlen))
28749 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
28750 + unsigned char d_type)
28752 +#ifdef CONFIG_AUFS_SHWH
28753 + wh->wh_ino = ino;
28754 + wh->wh_type = d_type;
28758 +/* ---------------------------------------------------------------------- */
28760 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
28761 + unsigned int d_type, aufs_bindex_t bindex,
28762 + unsigned char shwh)
28765 + struct au_vdir_destr *str;
28766 + struct au_vdir_wh *wh;
28768 + AuDbg("%.*s\n", nlen, name);
28769 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
28772 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
28773 + if (unlikely(!wh))
28777 + wh->wh_bindex = bindex;
28779 + au_shwh_init_wh(wh, ino, d_type);
28780 + str = &wh->wh_str;
28782 + memcpy(str->name, name, nlen);
28783 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
28790 +static int append_deblk(struct au_vdir *vdir)
28793 + unsigned long ul;
28794 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
28795 + union au_vdir_deblk_p p, deblk_end;
28796 + unsigned char **o;
28799 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
28801 + if (unlikely(!o))
28804 + vdir->vd_deblk = o;
28805 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
28807 + ul = vdir->vd_nblk++;
28808 + vdir->vd_deblk[ul] = p.deblk;
28809 + vdir->vd_last.ul = ul;
28810 + vdir->vd_last.p.deblk = p.deblk;
28811 + deblk_end.deblk = p.deblk + deblk_sz;
28812 + err = set_deblk_end(&p, &deblk_end);
28819 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
28820 + unsigned int d_type, struct au_nhash *delist)
28824 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
28825 + union au_vdir_deblk_p p, *room, deblk_end;
28826 + struct au_vdir_dehstr *dehstr;
28828 + p.deblk = last_deblk(vdir);
28829 + deblk_end.deblk = p.deblk + deblk_sz;
28830 + room = &vdir->vd_last.p;
28831 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
28832 + || !is_deblk_end(room, &deblk_end));
28834 + sz = calc_size(nlen);
28835 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
28836 + err = append_deblk(vdir);
28837 + if (unlikely(err))
28840 + p.deblk = last_deblk(vdir);
28841 + deblk_end.deblk = p.deblk + deblk_sz;
28843 + AuDebugOn(room->deblk != p.deblk);
28847 + dehstr = au_cache_alloc_vdir_dehstr();
28848 + if (unlikely(!dehstr))
28851 + dehstr->str = &room->de->de_str;
28852 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
28853 + room->de->de_ino = ino;
28854 + room->de->de_type = d_type;
28855 + room->de->de_str.len = nlen;
28856 + memcpy(room->de->de_str.name, name, nlen);
28859 + room->deblk += sz;
28860 + if (unlikely(set_deblk_end(room, &deblk_end)))
28861 + err = append_deblk(vdir);
28868 +/* ---------------------------------------------------------------------- */
28870 +void au_vdir_free(struct au_vdir *vdir)
28872 + unsigned char **deblk;
28874 + deblk = vdir->vd_deblk;
28875 + while (vdir->vd_nblk--)
28877 + kfree(vdir->vd_deblk);
28878 + au_cache_free_vdir(vdir);
28881 +static struct au_vdir *alloc_vdir(struct file *file)
28883 + struct au_vdir *vdir;
28884 + struct super_block *sb;
28887 + sb = file->f_path.dentry->d_sb;
28888 + SiMustAnyLock(sb);
28891 + vdir = au_cache_alloc_vdir();
28892 + if (unlikely(!vdir))
28895 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
28896 + if (unlikely(!vdir->vd_deblk))
28899 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
28900 + if (!vdir->vd_deblk_sz) {
28901 + /* estimate the apropriate size for deblk */
28902 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
28903 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
28905 + vdir->vd_nblk = 0;
28906 + vdir->vd_version = 0;
28907 + vdir->vd_jiffy = 0;
28908 + err = append_deblk(vdir);
28910 + return vdir; /* success */
28912 + kfree(vdir->vd_deblk);
28915 + au_cache_free_vdir(vdir);
28917 + vdir = ERR_PTR(err);
28921 +static int reinit_vdir(struct au_vdir *vdir)
28924 + union au_vdir_deblk_p p, deblk_end;
28926 + while (vdir->vd_nblk > 1) {
28927 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
28928 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
28931 + p.deblk = vdir->vd_deblk[0];
28932 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
28933 + err = set_deblk_end(&p, &deblk_end);
28934 + /* keep vd_dblk_sz */
28935 + vdir->vd_last.ul = 0;
28936 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
28937 + vdir->vd_version = 0;
28938 + vdir->vd_jiffy = 0;
28943 +/* ---------------------------------------------------------------------- */
28945 +#define AuFillVdir_CALLED 1
28946 +#define AuFillVdir_WHABLE (1 << 1)
28947 +#define AuFillVdir_SHWH (1 << 2)
28948 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
28949 +#define au_fset_fillvdir(flags, name) \
28950 + do { (flags) |= AuFillVdir_##name; } while (0)
28951 +#define au_fclr_fillvdir(flags, name) \
28952 + do { (flags) &= ~AuFillVdir_##name; } while (0)
28954 +#ifndef CONFIG_AUFS_SHWH
28955 +#undef AuFillVdir_SHWH
28956 +#define AuFillVdir_SHWH 0
28959 +struct fillvdir_arg {
28960 + struct dir_context ctx;
28961 + struct file *file;
28962 + struct au_vdir *vdir;
28963 + struct au_nhash delist;
28964 + struct au_nhash whlist;
28965 + aufs_bindex_t bindex;
28966 + unsigned int flags;
28970 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
28971 + loff_t offset __maybe_unused, u64 h_ino,
28972 + unsigned int d_type)
28974 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
28975 + char *name = (void *)__name;
28976 + struct super_block *sb;
28978 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
28981 + sb = arg->file->f_path.dentry->d_sb;
28982 + au_fset_fillvdir(arg->flags, CALLED);
28984 + if (nlen <= AUFS_WH_PFX_LEN
28985 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
28986 + if (test_known(&arg->delist, name, nlen)
28987 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
28988 + goto out; /* already exists or whiteouted */
28990 + sb = arg->file->f_path.dentry->d_sb;
28991 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
28993 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28994 + d_type = DT_UNKNOWN;
28995 + arg->err = append_de(arg->vdir, name, nlen, ino,
28996 + d_type, &arg->delist);
28998 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
28999 + name += AUFS_WH_PFX_LEN;
29000 + nlen -= AUFS_WH_PFX_LEN;
29001 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29002 + goto out; /* already whiteouted */
29005 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29008 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29009 + d_type = DT_UNKNOWN;
29010 + arg->err = au_nhash_append_wh
29011 + (&arg->whlist, name, nlen, ino, d_type,
29012 + arg->bindex, shwh);
29018 + arg->vdir->vd_jiffy = jiffies;
29020 + AuTraceErr(arg->err);
29024 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29025 + struct au_nhash *whlist, struct au_nhash *delist)
29027 +#ifdef CONFIG_AUFS_SHWH
29029 + unsigned int nh, u;
29030 + struct hlist_head *head;
29031 + struct au_vdir_wh *pos;
29032 + struct hlist_node *n;
29034 + struct au_vdir_destr *destr;
29036 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29039 + o = p = (void *)__get_free_page(GFP_NOFS);
29040 + if (unlikely(!p))
29044 + nh = whlist->nh_num;
29045 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29046 + p += AUFS_WH_PFX_LEN;
29047 + for (u = 0; u < nh; u++) {
29048 + head = whlist->nh_head + u;
29049 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29050 + destr = &pos->wh_str;
29051 + memcpy(p, destr->name, destr->len);
29052 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29053 + pos->wh_ino, pos->wh_type, delist);
29054 + if (unlikely(err))
29059 + free_page((unsigned long)o);
29069 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29072 + unsigned int rdhash;
29074 + aufs_bindex_t bend, bindex, bstart;
29075 + unsigned char shwh;
29076 + struct file *hf, *file;
29077 + struct super_block *sb;
29079 + file = arg->file;
29080 + sb = file->f_path.dentry->d_sb;
29081 + SiMustAnyLock(sb);
29083 + rdhash = au_sbi(sb)->si_rdhash;
29085 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29086 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29087 + if (unlikely(err))
29089 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29090 + if (unlikely(err))
29096 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29098 + au_fset_fillvdir(arg->flags, SHWH);
29100 + bstart = au_fbstart(file);
29101 + bend = au_fbend_dir(file);
29102 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29103 + hf = au_hf_dir(file, bindex);
29107 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29109 + if (unlikely(offset))
29112 + arg->bindex = bindex;
29113 + au_fclr_fillvdir(arg->flags, WHABLE);
29115 + || (bindex != bend
29116 + && au_br_whable(au_sbr_perm(sb, bindex))))
29117 + au_fset_fillvdir(arg->flags, WHABLE);
29120 + au_fclr_fillvdir(arg->flags, CALLED);
29122 + err = vfsub_iterate_dir(hf, &arg->ctx);
29125 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29128 + * dir_relax() may be good for concurrency, but aufs should not
29129 + * use it since it will cause a lockdep problem.
29133 + if (!err && shwh)
29134 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29136 + au_nhash_wh_free(&arg->whlist);
29139 + au_nhash_de_free(&arg->delist);
29144 +static int read_vdir(struct file *file, int may_read)
29147 + unsigned long expire;
29148 + unsigned char do_read;
29149 + struct fillvdir_arg arg = {
29151 + .actor = fillvdir
29154 + struct inode *inode;
29155 + struct au_vdir *vdir, *allocated;
29158 + inode = file_inode(file);
29159 + IMustLock(inode);
29160 + SiMustAnyLock(inode->i_sb);
29162 + allocated = NULL;
29164 + expire = au_sbi(inode->i_sb)->si_rdcache;
29165 + vdir = au_ivdir(inode);
29168 + vdir = alloc_vdir(file);
29169 + err = PTR_ERR(vdir);
29170 + if (IS_ERR(vdir))
29173 + allocated = vdir;
29174 + } else if (may_read
29175 + && (inode->i_version != vdir->vd_version
29176 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29178 + err = reinit_vdir(vdir);
29179 + if (unlikely(err))
29184 + return 0; /* success */
29188 + err = au_do_read_vdir(&arg);
29190 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29191 + vdir->vd_version = inode->i_version;
29192 + vdir->vd_last.ul = 0;
29193 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29195 + au_set_ivdir(inode, allocated);
29196 + } else if (allocated)
29197 + au_vdir_free(allocated);
29203 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29206 + unsigned long ul, n;
29207 + const unsigned int deblk_sz = src->vd_deblk_sz;
29209 + AuDebugOn(tgt->vd_nblk != 1);
29212 + if (tgt->vd_nblk < src->vd_nblk) {
29213 + unsigned char **p;
29215 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29217 + if (unlikely(!p))
29219 + tgt->vd_deblk = p;
29222 + if (tgt->vd_deblk_sz != deblk_sz) {
29223 + unsigned char *p;
29225 + tgt->vd_deblk_sz = deblk_sz;
29226 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29227 + if (unlikely(!p))
29229 + tgt->vd_deblk[0] = p;
29231 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29232 + tgt->vd_version = src->vd_version;
29233 + tgt->vd_jiffy = src->vd_jiffy;
29235 + n = src->vd_nblk;
29236 + for (ul = 1; ul < n; ul++) {
29237 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29239 + if (unlikely(!tgt->vd_deblk[ul]))
29243 + tgt->vd_nblk = n;
29244 + tgt->vd_last.ul = tgt->vd_last.ul;
29245 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29246 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29247 + - src->vd_deblk[src->vd_last.ul];
29249 + return 0; /* success */
29252 + rerr = reinit_vdir(tgt);
29257 +int au_vdir_init(struct file *file)
29260 + struct inode *inode;
29261 + struct au_vdir *vdir_cache, *allocated;
29263 + /* test file->f_pos here instead of ctx->pos */
29264 + err = read_vdir(file, !file->f_pos);
29265 + if (unlikely(err))
29268 + allocated = NULL;
29269 + vdir_cache = au_fvdir_cache(file);
29270 + if (!vdir_cache) {
29271 + vdir_cache = alloc_vdir(file);
29272 + err = PTR_ERR(vdir_cache);
29273 + if (IS_ERR(vdir_cache))
29275 + allocated = vdir_cache;
29276 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29277 + /* test file->f_pos here instead of ctx->pos */
29278 + err = reinit_vdir(vdir_cache);
29279 + if (unlikely(err))
29282 + return 0; /* success */
29284 + inode = file_inode(file);
29285 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29287 + file->f_version = inode->i_version;
29289 + au_set_fvdir_cache(file, allocated);
29290 + } else if (allocated)
29291 + au_vdir_free(allocated);
29297 +static loff_t calc_offset(struct au_vdir *vdir)
29300 + union au_vdir_deblk_p p;
29302 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29303 + offset = vdir->vd_last.p.deblk - p.deblk;
29304 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29308 +/* returns true or false */
29309 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29312 + unsigned int deblk_sz;
29313 + unsigned long ul, n;
29315 + union au_vdir_deblk_p p, deblk_end;
29316 + struct au_vdir *vdir_cache;
29319 + vdir_cache = au_fvdir_cache(file);
29320 + offset = calc_offset(vdir_cache);
29321 + AuDbg("offset %lld\n", offset);
29322 + if (ctx->pos == offset)
29325 + vdir_cache->vd_last.ul = 0;
29326 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29331 + deblk_sz = vdir_cache->vd_deblk_sz;
29332 + ul = div64_u64(ctx->pos, deblk_sz);
29333 + AuDbg("ul %lu\n", ul);
29334 + if (ul >= vdir_cache->vd_nblk)
29337 + n = vdir_cache->vd_nblk;
29338 + for (; ul < n; ul++) {
29339 + p.deblk = vdir_cache->vd_deblk[ul];
29340 + deblk_end.deblk = p.deblk + deblk_sz;
29342 + offset *= deblk_sz;
29343 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29346 + l = calc_size(p.de->de_str.len);
29350 + if (!is_deblk_end(&p, &deblk_end)) {
29352 + vdir_cache->vd_last.ul = ul;
29353 + vdir_cache->vd_last.p = p;
29360 + AuTraceErr(!valid);
29364 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29366 + unsigned int l, deblk_sz;
29367 + union au_vdir_deblk_p deblk_end;
29368 + struct au_vdir *vdir_cache;
29369 + struct au_vdir_de *de;
29371 + vdir_cache = au_fvdir_cache(file);
29372 + if (!seek_vdir(file, ctx))
29375 + deblk_sz = vdir_cache->vd_deblk_sz;
29377 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29378 + deblk_end.deblk += deblk_sz;
29379 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29380 + de = vdir_cache->vd_last.p.de;
29381 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29382 + de->de_str.len, de->de_str.name, ctx->pos,
29383 + (unsigned long)de->de_ino, de->de_type);
29384 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29385 + de->de_str.len, de->de_ino,
29387 + /* todo: ignore the error caused by udba? */
29388 + /* return err; */
29392 + l = calc_size(de->de_str.len);
29393 + vdir_cache->vd_last.p.deblk += l;
29396 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29397 + vdir_cache->vd_last.ul++;
29398 + vdir_cache->vd_last.p.deblk
29399 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29400 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29409 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
29410 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29411 +++ linux/fs/aufs/vfsub.c 2015-04-13 15:10:20.790157026 +0200
29414 + * Copyright (C) 2005-2015 Junjiro R. Okajima
29416 + * This program, aufs is free software; you can redistribute it and/or modify
29417 + * it under the terms of the GNU General Public License as published by
29418 + * the Free Software Foundation; either version 2 of the License, or
29419 + * (at your option) any later version.
29421 + * This program is distributed in the hope that it will be useful,
29422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29424 + * GNU General Public License for more details.
29426 + * You should have received a copy of the GNU General Public License
29427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29431 + * sub-routines for VFS
29434 +#include <linux/namei.h>
29435 +#include <linux/security.h>
29436 +#include <linux/splice.h>
29439 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29443 + struct super_block *h_sb;
29445 + /* for remote fs, leave work for its getattr or d_revalidate */
29446 + /* for bad i_attr fs, handle them in aufs_getattr() */
29447 + /* still some fs may acquire i_mutex. we need to skip them */
29451 + h_sb = h_path->dentry->d_sb;
29452 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29454 + err = vfs_getattr(h_path, &st);
29459 +/* ---------------------------------------------------------------------- */
29461 +struct file *vfsub_dentry_open(struct path *path, int flags)
29463 + struct file *file;
29465 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29467 + if (!IS_ERR_OR_NULL(file)
29468 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29469 + i_readcount_inc(path->dentry->d_inode);
29474 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29476 + struct file *file;
29479 + file = filp_open(path,
29480 + oflags /* | __FMODE_NONOTIFY */,
29483 + if (IS_ERR(file))
29485 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29491 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
29495 + err = kern_path(name, flags, path);
29496 + if (!err && path->dentry->d_inode)
29497 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29501 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29504 + struct path path = {
29508 + /* VFS checks it too, but by WARN_ON_ONCE() */
29509 + IMustLock(parent->d_inode);
29511 + path.dentry = lookup_one_len(name, parent, len);
29512 + if (IS_ERR(path.dentry))
29514 + if (path.dentry->d_inode)
29515 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
29518 + AuTraceErrPtr(path.dentry);
29519 + return path.dentry;
29522 +void vfsub_call_lkup_one(void *args)
29524 + struct vfsub_lkup_one_args *a = args;
29525 + *a->errp = vfsub_lkup_one(a->name, a->parent);
29528 +/* ---------------------------------------------------------------------- */
29530 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
29531 + struct dentry *d2, struct au_hinode *hdir2)
29533 + struct dentry *d;
29536 + d = lock_rename(d1, d2);
29538 + au_hn_suspend(hdir1);
29539 + if (hdir1 != hdir2)
29540 + au_hn_suspend(hdir2);
29545 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
29546 + struct dentry *d2, struct au_hinode *hdir2)
29548 + au_hn_resume(hdir1);
29549 + if (hdir1 != hdir2)
29550 + au_hn_resume(hdir2);
29552 + unlock_rename(d1, d2);
29556 +/* ---------------------------------------------------------------------- */
29558 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
29561 + struct dentry *d;
29565 + d = path->dentry;
29566 + path->dentry = d->d_parent;
29567 + err = security_path_mknod(path, d, mode, 0);
29568 + path->dentry = d;
29569 + if (unlikely(err))
29573 + err = vfs_create(dir, path->dentry, mode, want_excl);
29576 + struct path tmp = *path;
29579 + vfsub_update_h_iattr(&tmp, &did);
29581 + tmp.dentry = path->dentry->d_parent;
29582 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29591 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
29594 + struct dentry *d;
29598 + d = path->dentry;
29599 + path->dentry = d->d_parent;
29600 + err = security_path_symlink(path, d, symname);
29601 + path->dentry = d;
29602 + if (unlikely(err))
29606 + err = vfs_symlink(dir, path->dentry, symname);
29609 + struct path tmp = *path;
29612 + vfsub_update_h_iattr(&tmp, &did);
29614 + tmp.dentry = path->dentry->d_parent;
29615 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29624 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
29627 + struct dentry *d;
29631 + d = path->dentry;
29632 + path->dentry = d->d_parent;
29633 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
29634 + path->dentry = d;
29635 + if (unlikely(err))
29639 + err = vfs_mknod(dir, path->dentry, mode, dev);
29642 + struct path tmp = *path;
29645 + vfsub_update_h_iattr(&tmp, &did);
29647 + tmp.dentry = path->dentry->d_parent;
29648 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29657 +static int au_test_nlink(struct inode *inode)
29659 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
29661 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
29662 + || inode->i_nlink < link_max)
29667 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
29668 + struct inode **delegated_inode)
29671 + struct dentry *d;
29675 + err = au_test_nlink(src_dentry->d_inode);
29676 + if (unlikely(err))
29679 + /* we don't call may_linkat() */
29680 + d = path->dentry;
29681 + path->dentry = d->d_parent;
29682 + err = security_path_link(src_dentry, path, d);
29683 + path->dentry = d;
29684 + if (unlikely(err))
29688 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
29691 + struct path tmp = *path;
29694 + /* fuse has different memory inode for the same inumber */
29695 + vfsub_update_h_iattr(&tmp, &did);
29697 + tmp.dentry = path->dentry->d_parent;
29698 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29699 + tmp.dentry = src_dentry;
29700 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29709 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
29710 + struct inode *dir, struct path *path,
29711 + struct inode **delegated_inode)
29714 + struct path tmp = {
29717 + struct dentry *d;
29720 + IMustLock(src_dir);
29722 + d = path->dentry;
29723 + path->dentry = d->d_parent;
29724 + tmp.dentry = src_dentry->d_parent;
29725 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
29726 + path->dentry = d;
29727 + if (unlikely(err))
29731 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
29732 + delegated_inode, /*flags*/0);
29737 + tmp.dentry = d->d_parent;
29738 + vfsub_update_h_iattr(&tmp, &did);
29740 + tmp.dentry = src_dentry;
29741 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29742 + tmp.dentry = src_dentry->d_parent;
29743 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29752 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
29755 + struct dentry *d;
29759 + d = path->dentry;
29760 + path->dentry = d->d_parent;
29761 + err = security_path_mkdir(path, d, mode);
29762 + path->dentry = d;
29763 + if (unlikely(err))
29767 + err = vfs_mkdir(dir, path->dentry, mode);
29770 + struct path tmp = *path;
29773 + vfsub_update_h_iattr(&tmp, &did);
29775 + tmp.dentry = path->dentry->d_parent;
29776 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29785 +int vfsub_rmdir(struct inode *dir, struct path *path)
29788 + struct dentry *d;
29792 + d = path->dentry;
29793 + path->dentry = d->d_parent;
29794 + err = security_path_rmdir(path, d);
29795 + path->dentry = d;
29796 + if (unlikely(err))
29800 + err = vfs_rmdir(dir, path->dentry);
29803 + struct path tmp = {
29804 + .dentry = path->dentry->d_parent,
29808 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
29815 +/* ---------------------------------------------------------------------- */
29817 +/* todo: support mmap_sem? */
29818 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
29824 + err = vfs_read(file, ubuf, count, ppos);
29827 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29831 +/* todo: kernel_read()? */
29832 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
29836 + mm_segment_t oldfs;
29843 + oldfs = get_fs();
29844 + set_fs(KERNEL_DS);
29845 + err = vfsub_read_u(file, buf.u, count, ppos);
29850 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
29856 + err = vfs_write(file, ubuf, count, ppos);
29859 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29863 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
29866 + mm_segment_t oldfs;
29869 + const char __user *u;
29873 + oldfs = get_fs();
29874 + set_fs(KERNEL_DS);
29875 + err = vfsub_write_u(file, buf.u, count, ppos);
29880 +int vfsub_flush(struct file *file, fl_owner_t id)
29885 + if (file->f_op->flush) {
29886 + if (!au_test_nfs(file->f_path.dentry->d_sb))
29887 + err = file->f_op->flush(file, id);
29890 + err = file->f_op->flush(file, id);
29894 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
29900 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
29904 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
29907 + err = iterate_dir(file, ctx);
29910 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29914 +long vfsub_splice_to(struct file *in, loff_t *ppos,
29915 + struct pipe_inode_info *pipe, size_t len,
29916 + unsigned int flags)
29921 + err = do_splice_to(in, ppos, pipe, len, flags);
29923 + file_accessed(in);
29925 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
29929 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
29930 + loff_t *ppos, size_t len, unsigned int flags)
29935 + err = do_splice_from(pipe, out, ppos, len, flags);
29938 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
29942 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
29946 + /* file can be NULL */
29948 + err = vfs_fsync(file, datasync);
29952 + AuDebugOn(!file);
29953 + path = &file->f_path;
29955 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29960 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
29961 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
29962 + struct file *h_file)
29965 + struct inode *h_inode;
29966 + struct super_block *h_sb;
29969 + err = vfsub_truncate(h_path, length);
29973 + h_inode = h_path->dentry->d_inode;
29974 + h_sb = h_inode->i_sb;
29976 + sb_start_write(h_sb);
29978 + err = locks_verify_truncate(h_inode, h_file, length);
29980 + err = security_path_truncate(h_path);
29983 + err = do_truncate(h_path->dentry, length, attr, h_file);
29987 + sb_end_write(h_sb);
29994 +/* ---------------------------------------------------------------------- */
29996 +struct au_vfsub_mkdir_args {
29998 + struct inode *dir;
29999 + struct path *path;
30003 +static void au_call_vfsub_mkdir(void *args)
30005 + struct au_vfsub_mkdir_args *a = args;
30006 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30009 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30011 + int err, do_sio, wkq_err;
30013 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30016 + err = vfsub_mkdir(dir, path, mode);
30019 + struct au_vfsub_mkdir_args args = {
30025 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30026 + if (unlikely(wkq_err))
30033 +struct au_vfsub_rmdir_args {
30035 + struct inode *dir;
30036 + struct path *path;
30039 +static void au_call_vfsub_rmdir(void *args)
30041 + struct au_vfsub_rmdir_args *a = args;
30042 + *a->errp = vfsub_rmdir(a->dir, a->path);
30045 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30047 + int err, do_sio, wkq_err;
30049 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30052 + err = vfsub_rmdir(dir, path);
30055 + struct au_vfsub_rmdir_args args = {
30060 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30061 + if (unlikely(wkq_err))
30068 +/* ---------------------------------------------------------------------- */
30070 +struct notify_change_args {
30072 + struct path *path;
30073 + struct iattr *ia;
30074 + struct inode **delegated_inode;
30077 +static void call_notify_change(void *args)
30079 + struct notify_change_args *a = args;
30080 + struct inode *h_inode;
30082 + h_inode = a->path->dentry->d_inode;
30083 + IMustLock(h_inode);
30085 + *a->errp = -EPERM;
30086 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30088 + *a->errp = notify_change(a->path->dentry, a->ia,
30089 + a->delegated_inode);
30092 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30094 + AuTraceErr(*a->errp);
30097 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30098 + struct inode **delegated_inode)
30101 + struct notify_change_args args = {
30105 + .delegated_inode = delegated_inode
30108 + call_notify_change(&args);
30113 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30114 + struct inode **delegated_inode)
30116 + int err, wkq_err;
30117 + struct notify_change_args args = {
30121 + .delegated_inode = delegated_inode
30124 + wkq_err = au_wkq_wait(call_notify_change, &args);
30125 + if (unlikely(wkq_err))
30131 +/* ---------------------------------------------------------------------- */
30133 +struct unlink_args {
30135 + struct inode *dir;
30136 + struct path *path;
30137 + struct inode **delegated_inode;
30140 +static void call_unlink(void *args)
30142 + struct unlink_args *a = args;
30143 + struct dentry *d = a->path->dentry;
30144 + struct inode *h_inode;
30145 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30146 + && au_dcount(d) == 1);
30148 + IMustLock(a->dir);
30150 + a->path->dentry = d->d_parent;
30151 + *a->errp = security_path_unlink(a->path, d);
30152 + a->path->dentry = d;
30153 + if (unlikely(*a->errp))
30156 + if (!stop_sillyrename)
30158 + h_inode = d->d_inode;
30163 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30166 + struct path tmp = {
30167 + .dentry = d->d_parent,
30168 + .mnt = a->path->mnt
30170 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30173 + if (!stop_sillyrename)
30178 + AuTraceErr(*a->errp);
30182 + * @dir: must be locked.
30183 + * @dentry: target dentry.
30185 +int vfsub_unlink(struct inode *dir, struct path *path,
30186 + struct inode **delegated_inode, int force)
30189 + struct unlink_args args = {
30193 + .delegated_inode = delegated_inode
30197 + call_unlink(&args);
30201 + wkq_err = au_wkq_wait(call_unlink, &args);
30202 + if (unlikely(wkq_err))
30208 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
30209 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30210 +++ linux/fs/aufs/vfsub.h 2015-04-13 15:10:20.790157026 +0200
30213 + * Copyright (C) 2005-2015 Junjiro R. Okajima
30215 + * This program, aufs is free software; you can redistribute it and/or modify
30216 + * it under the terms of the GNU General Public License as published by
30217 + * the Free Software Foundation; either version 2 of the License, or
30218 + * (at your option) any later version.
30220 + * This program is distributed in the hope that it will be useful,
30221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30223 + * GNU General Public License for more details.
30225 + * You should have received a copy of the GNU General Public License
30226 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30230 + * sub-routines for VFS
30233 +#ifndef __AUFS_VFSUB_H__
30234 +#define __AUFS_VFSUB_H__
30238 +#include <linux/fs.h>
30239 +#include <linux/mount.h>
30240 +#include <linux/xattr.h>
30241 +#include "debug.h"
30243 +/* copied from linux/fs/internal.h */
30244 +/* todo: BAD approach!! */
30245 +extern void __mnt_drop_write(struct vfsmount *);
30246 +extern spinlock_t inode_sb_list_lock;
30248 +/* ---------------------------------------------------------------------- */
30250 +/* lock subclass for lower inode */
30251 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
30252 +/* reduce? gave up. */
30254 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
30255 + AuLsc_I_PARENT, /* lower inode, parent first */
30256 + AuLsc_I_PARENT2, /* copyup dirs */
30257 + AuLsc_I_PARENT3, /* copyup wh */
30263 +/* to debug easier, do not make them inlined functions */
30264 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
30265 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
30267 +/* ---------------------------------------------------------------------- */
30269 +static inline void vfsub_drop_nlink(struct inode *inode)
30271 + AuDebugOn(!inode->i_nlink);
30272 + drop_nlink(inode);
30275 +static inline void vfsub_dead_dir(struct inode *inode)
30277 + AuDebugOn(!S_ISDIR(inode->i_mode));
30278 + inode->i_flags |= S_DEAD;
30279 + clear_nlink(inode);
30282 +static inline int vfsub_native_ro(struct inode *inode)
30284 + return (inode->i_sb->s_flags & MS_RDONLY)
30285 + || IS_RDONLY(inode)
30286 + /* || IS_APPEND(inode) */
30287 + || IS_IMMUTABLE(inode);
30290 +/* ---------------------------------------------------------------------- */
30292 +int vfsub_update_h_iattr(struct path *h_path, int *did);
30293 +struct file *vfsub_dentry_open(struct path *path, int flags);
30294 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
30295 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
30297 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30300 +struct vfsub_lkup_one_args {
30301 + struct dentry **errp;
30302 + struct qstr *name;
30303 + struct dentry *parent;
30306 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30307 + struct dentry *parent)
30309 + return vfsub_lookup_one_len(name->name, parent, name->len);
30312 +void vfsub_call_lkup_one(void *args);
30314 +/* ---------------------------------------------------------------------- */
30316 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30321 + err = mnt_want_write(mnt);
30326 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30329 + mnt_drop_write(mnt);
30333 +#if 0 /* reserved */
30334 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30337 + mnt_drop_write_file(file);
30342 +/* ---------------------------------------------------------------------- */
30345 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30346 + struct dentry *d2, struct au_hinode *hdir2);
30347 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30348 + struct dentry *d2, struct au_hinode *hdir2);
30350 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30352 +int vfsub_symlink(struct inode *dir, struct path *path,
30353 + const char *symname);
30354 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30355 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30356 + struct path *path, struct inode **delegated_inode);
30357 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30358 + struct inode *hdir, struct path *path,
30359 + struct inode **delegated_inode);
30360 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30361 +int vfsub_rmdir(struct inode *dir, struct path *path);
30363 +/* ---------------------------------------------------------------------- */
30365 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30367 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30369 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30371 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30373 +int vfsub_flush(struct file *file, fl_owner_t id);
30374 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30376 +static inline loff_t vfsub_f_size_read(struct file *file)
30378 + return i_size_read(file_inode(file));
30381 +static inline unsigned int vfsub_file_flags(struct file *file)
30383 + unsigned int flags;
30385 + spin_lock(&file->f_lock);
30386 + flags = file->f_flags;
30387 + spin_unlock(&file->f_lock);
30392 +#if 0 /* reserved */
30393 +static inline void vfsub_file_accessed(struct file *h_file)
30395 + file_accessed(h_file);
30396 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30400 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30401 + struct dentry *h_dentry)
30403 + struct path h_path = {
30404 + .dentry = h_dentry,
30407 + touch_atime(&h_path);
30408 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30411 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30414 + return generic_update_time(h_inode, ts, flags);
30415 + /* no vfsub_update_h_iattr() since we don't have struct path */
30418 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30419 + struct pipe_inode_info *pipe, size_t len,
30420 + unsigned int flags);
30421 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30422 + loff_t *ppos, size_t len, unsigned int flags);
30424 +static inline long vfsub_truncate(struct path *path, loff_t length)
30429 + err = vfs_truncate(path, length);
30434 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30435 + struct file *h_file);
30436 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30438 +/* ---------------------------------------------------------------------- */
30440 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30445 + err = vfs_llseek(file, offset, origin);
30450 +/* ---------------------------------------------------------------------- */
30452 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30453 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30454 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30455 + struct inode **delegated_inode);
30456 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30457 + struct inode **delegated_inode);
30458 +int vfsub_unlink(struct inode *dir, struct path *path,
30459 + struct inode **delegated_inode, int force);
30461 +/* ---------------------------------------------------------------------- */
30463 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
30464 + const void *value, size_t size, int flags)
30469 + err = vfs_setxattr(dentry, name, value, size, flags);
30475 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
30480 + err = vfs_removexattr(dentry, name);
30486 +#endif /* __KERNEL__ */
30487 +#endif /* __AUFS_VFSUB_H__ */
30488 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
30489 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
30490 +++ linux/fs/aufs/wbr_policy.c 2015-04-13 15:10:20.790157026 +0200
30493 + * Copyright (C) 2005-2015 Junjiro R. Okajima
30495 + * This program, aufs is free software; you can redistribute it and/or modify
30496 + * it under the terms of the GNU General Public License as published by
30497 + * the Free Software Foundation; either version 2 of the License, or
30498 + * (at your option) any later version.
30500 + * This program is distributed in the hope that it will be useful,
30501 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30502 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30503 + * GNU General Public License for more details.
30505 + * You should have received a copy of the GNU General Public License
30506 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30510 + * policies for selecting one among multiple writable branches
30513 +#include <linux/statfs.h>
30516 +/* subset of cpup_attr() */
30517 +static noinline_for_stack
30518 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
30522 + struct inode *h_isrc;
30524 + h_isrc = h_src->d_inode;
30525 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
30526 + ia.ia_mode = h_isrc->i_mode;
30527 + ia.ia_uid = h_isrc->i_uid;
30528 + ia.ia_gid = h_isrc->i_gid;
30529 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
30530 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
30531 + /* no delegation since it is just created */
30532 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30534 + /* is this nfs only? */
30535 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
30536 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
30537 + ia.ia_mode = h_isrc->i_mode;
30538 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30544 +#define AuCpdown_PARENT_OPQ 1
30545 +#define AuCpdown_WHED (1 << 1)
30546 +#define AuCpdown_MADE_DIR (1 << 2)
30547 +#define AuCpdown_DIROPQ (1 << 3)
30548 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
30549 +#define au_fset_cpdown(flags, name) \
30550 + do { (flags) |= AuCpdown_##name; } while (0)
30551 +#define au_fclr_cpdown(flags, name) \
30552 + do { (flags) &= ~AuCpdown_##name; } while (0)
30554 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
30555 + unsigned int *flags)
30558 + struct dentry *opq_dentry;
30560 + opq_dentry = au_diropq_create(dentry, bdst);
30561 + err = PTR_ERR(opq_dentry);
30562 + if (IS_ERR(opq_dentry))
30564 + dput(opq_dentry);
30565 + au_fset_cpdown(*flags, DIROPQ);
30571 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
30572 + struct inode *dir, aufs_bindex_t bdst)
30575 + struct path h_path;
30576 + struct au_branch *br;
30578 + br = au_sbr(dentry->d_sb, bdst);
30579 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
30580 + err = PTR_ERR(h_path.dentry);
30581 + if (IS_ERR(h_path.dentry))
30585 + if (h_path.dentry->d_inode) {
30586 + h_path.mnt = au_br_mnt(br);
30587 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
30590 + dput(h_path.dentry);
30596 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
30597 + struct au_pin *pin,
30598 + struct dentry *h_parent, void *arg)
30601 + aufs_bindex_t bopq, bstart;
30602 + struct path h_path;
30603 + struct dentry *parent;
30604 + struct inode *h_dir, *h_inode, *inode, *dir;
30605 + unsigned int *flags = arg;
30607 + bstart = au_dbstart(dentry);
30608 + /* dentry is di-locked */
30609 + parent = dget_parent(dentry);
30610 + dir = parent->d_inode;
30611 + h_dir = h_parent->d_inode;
30612 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
30613 + IMustLock(h_dir);
30615 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
30616 + if (unlikely(err < 0))
30618 + h_path.dentry = au_h_dptr(dentry, bdst);
30619 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
30620 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
30621 + S_IRWXU | S_IRUGO | S_IXUGO);
30622 + if (unlikely(err))
30624 + au_fset_cpdown(*flags, MADE_DIR);
30626 + bopq = au_dbdiropq(dentry);
30627 + au_fclr_cpdown(*flags, WHED);
30628 + au_fclr_cpdown(*flags, DIROPQ);
30629 + if (au_dbwh(dentry) == bdst)
30630 + au_fset_cpdown(*flags, WHED);
30631 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
30632 + au_fset_cpdown(*flags, PARENT_OPQ);
30633 + h_inode = h_path.dentry->d_inode;
30634 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30635 + if (au_ftest_cpdown(*flags, WHED)) {
30636 + err = au_cpdown_dir_opq(dentry, bdst, flags);
30637 + if (unlikely(err)) {
30638 + mutex_unlock(&h_inode->i_mutex);
30643 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
30644 + mutex_unlock(&h_inode->i_mutex);
30645 + if (unlikely(err))
30648 + if (au_ftest_cpdown(*flags, WHED)) {
30649 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
30650 + if (unlikely(err))
30654 + inode = dentry->d_inode;
30655 + if (au_ibend(inode) < bdst)
30656 + au_set_ibend(inode, bdst);
30657 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
30658 + au_hi_flags(inode, /*isdir*/1));
30659 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
30660 + goto out; /* success */
30664 + if (au_ftest_cpdown(*flags, DIROPQ)) {
30665 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30666 + rerr = au_diropq_remove(dentry, bdst);
30667 + mutex_unlock(&h_inode->i_mutex);
30668 + if (unlikely(rerr)) {
30669 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
30670 + dentry, bdst, rerr);
30676 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
30677 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
30678 + if (unlikely(rerr)) {
30679 + AuIOErr("failed removing %pd b%d (%d)\n",
30680 + dentry, bdst, rerr);
30685 + au_set_h_dptr(dentry, bdst, NULL);
30686 + if (au_dbend(dentry) == bdst)
30687 + au_update_dbend(dentry);
30693 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
30696 + unsigned int flags;
30699 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
30704 +/* ---------------------------------------------------------------------- */
30706 +/* policies for create */
30708 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
30710 + int err, i, j, ndentry;
30711 + aufs_bindex_t bopq;
30712 + struct au_dcsub_pages dpages;
30713 + struct au_dpage *dpage;
30714 + struct dentry **dentries, *parent, *d;
30716 + err = au_dpages_init(&dpages, GFP_NOFS);
30717 + if (unlikely(err))
30719 + parent = dget_parent(dentry);
30720 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
30721 + if (unlikely(err))
30725 + for (i = 0; i < dpages.ndpage; i++) {
30726 + dpage = dpages.dpages + i;
30727 + dentries = dpage->dentries;
30728 + ndentry = dpage->ndentry;
30729 + for (j = 0; j < ndentry; j++) {
30731 + di_read_lock_parent2(d, !AuLock_IR);
30732 + bopq = au_dbdiropq(d);
30733 + di_read_unlock(d, !AuLock_IR);
30734 + if (bopq >= 0 && bopq < err)
30741 + au_dpages_free(&dpages);
30746 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
30748 + for (; bindex >= 0; bindex--)
30749 + if (!au_br_rdonly(au_sbr(sb, bindex)))
30754 +/* top down parent */
30755 +static int au_wbr_create_tdp(struct dentry *dentry,
30756 + unsigned int flags __maybe_unused)
30759 + aufs_bindex_t bstart, bindex;
30760 + struct super_block *sb;
30761 + struct dentry *parent, *h_parent;
30763 + sb = dentry->d_sb;
30764 + bstart = au_dbstart(dentry);
30766 + if (!au_br_rdonly(au_sbr(sb, bstart)))
30770 + parent = dget_parent(dentry);
30771 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
30772 + h_parent = au_h_dptr(parent, bindex);
30773 + if (!h_parent || !h_parent->d_inode)
30776 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
30783 + /* bottom up here */
30784 + if (unlikely(err < 0)) {
30785 + err = au_wbr_bu(sb, bstart - 1);
30787 + err = au_wbr_nonopq(dentry, err);
30791 + AuDbg("b%d\n", err);
30795 +/* ---------------------------------------------------------------------- */
30797 +/* an exception for the policy other than tdp */
30798 +static int au_wbr_create_exp(struct dentry *dentry)
30801 + aufs_bindex_t bwh, bdiropq;
30802 + struct dentry *parent;
30805 + bwh = au_dbwh(dentry);
30806 + parent = dget_parent(dentry);
30807 + bdiropq = au_dbdiropq(parent);
30809 + if (bdiropq >= 0)
30810 + err = min(bdiropq, bwh);
30813 + AuDbg("%d\n", err);
30814 + } else if (bdiropq >= 0) {
30816 + AuDbg("%d\n", err);
30821 + err = au_wbr_nonopq(dentry, err);
30823 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
30826 + AuDbg("%d\n", err);
30830 +/* ---------------------------------------------------------------------- */
30833 +static int au_wbr_create_init_rr(struct super_block *sb)
30837 + err = au_wbr_bu(sb, au_sbend(sb));
30838 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
30841 + AuDbg("b%d\n", err);
30845 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
30849 + aufs_bindex_t bindex, bend;
30850 + struct super_block *sb;
30853 + err = au_wbr_create_exp(dentry);
30857 + sb = dentry->d_sb;
30858 + next = &au_sbi(sb)->si_wbr_rr_next;
30859 + bend = au_sbend(sb);
30861 + for (bindex = 0; bindex <= bend; bindex++) {
30862 + if (!au_ftest_wbr(flags, DIR)) {
30863 + err = atomic_dec_return(next) + 1;
30864 + /* modulo for 0 is meaningless */
30865 + if (unlikely(!err))
30866 + err = atomic_dec_return(next) + 1;
30868 + err = atomic_read(next);
30869 + AuDbg("%d\n", err);
30872 + AuDbg("%d\n", err);
30873 + if (!au_br_rdonly(au_sbr(sb, err)))
30879 + err = au_wbr_nonopq(dentry, err);
30882 + AuDbg("%d\n", err);
30886 +/* ---------------------------------------------------------------------- */
30888 +/* most free space */
30889 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
30891 + struct super_block *sb;
30892 + struct au_branch *br;
30893 + struct au_wbr_mfs *mfs;
30894 + struct dentry *h_parent;
30895 + aufs_bindex_t bindex, bend;
30897 + unsigned long long b, bavail;
30898 + struct path h_path;
30899 + /* reduce the stack usage */
30900 + struct kstatfs *st;
30902 + st = kmalloc(sizeof(*st), GFP_NOFS);
30903 + if (unlikely(!st)) {
30904 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
30909 + sb = dentry->d_sb;
30910 + mfs = &au_sbi(sb)->si_wbr_mfs;
30911 + MtxMustLock(&mfs->mfs_lock);
30912 + mfs->mfs_bindex = -EROFS;
30913 + mfs->mfsrr_bytes = 0;
30916 + bend = au_sbend(sb);
30918 + bindex = au_dbstart(parent);
30919 + bend = au_dbtaildir(parent);
30922 + for (; bindex <= bend; bindex++) {
30924 + h_parent = au_h_dptr(parent, bindex);
30925 + if (!h_parent || !h_parent->d_inode)
30928 + br = au_sbr(sb, bindex);
30929 + if (au_br_rdonly(br))
30932 + /* sb->s_root for NFS is unreliable */
30933 + h_path.mnt = au_br_mnt(br);
30934 + h_path.dentry = h_path.mnt->mnt_root;
30935 + err = vfs_statfs(&h_path, st);
30936 + if (unlikely(err)) {
30937 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
30941 + /* when the available size is equal, select the lower one */
30942 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
30943 + || sizeof(b) < sizeof(st->f_bsize));
30944 + b = st->f_bavail * st->f_bsize;
30945 + br->br_wbr->wbr_bytes = b;
30946 + if (b >= bavail) {
30948 + mfs->mfs_bindex = bindex;
30949 + mfs->mfs_jiffy = jiffies;
30953 + mfs->mfsrr_bytes = bavail;
30954 + AuDbg("b%d\n", mfs->mfs_bindex);
30958 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
30961 + struct dentry *parent;
30962 + struct super_block *sb;
30963 + struct au_wbr_mfs *mfs;
30965 + err = au_wbr_create_exp(dentry);
30969 + sb = dentry->d_sb;
30971 + if (au_ftest_wbr(flags, PARENT))
30972 + parent = dget_parent(dentry);
30973 + mfs = &au_sbi(sb)->si_wbr_mfs;
30974 + mutex_lock(&mfs->mfs_lock);
30975 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
30976 + || mfs->mfs_bindex < 0
30977 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
30978 + au_mfs(dentry, parent);
30979 + mutex_unlock(&mfs->mfs_lock);
30980 + err = mfs->mfs_bindex;
30984 + err = au_wbr_nonopq(dentry, err);
30987 + AuDbg("b%d\n", err);
30991 +static int au_wbr_create_init_mfs(struct super_block *sb)
30993 + struct au_wbr_mfs *mfs;
30995 + mfs = &au_sbi(sb)->si_wbr_mfs;
30996 + mutex_init(&mfs->mfs_lock);
30997 + mfs->mfs_jiffy = 0;
30998 + mfs->mfs_bindex = -EROFS;
31003 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31005 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31009 +/* ---------------------------------------------------------------------- */
31011 +/* most free space and then round robin */
31012 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31015 + struct au_wbr_mfs *mfs;
31017 + err = au_wbr_create_mfs(dentry, flags);
31019 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31020 + mutex_lock(&mfs->mfs_lock);
31021 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31022 + err = au_wbr_create_rr(dentry, flags);
31023 + mutex_unlock(&mfs->mfs_lock);
31026 + AuDbg("b%d\n", err);
31030 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31034 + au_wbr_create_init_mfs(sb); /* ignore */
31035 + err = au_wbr_create_init_rr(sb);
31040 +/* ---------------------------------------------------------------------- */
31042 +/* top down parent and most free space */
31043 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31046 + unsigned long long b;
31047 + aufs_bindex_t bindex, bstart, bend;
31048 + struct super_block *sb;
31049 + struct dentry *parent, *h_parent;
31050 + struct au_branch *br;
31052 + err = au_wbr_create_tdp(dentry, flags);
31053 + if (unlikely(err < 0))
31055 + parent = dget_parent(dentry);
31056 + bstart = au_dbstart(parent);
31057 + bend = au_dbtaildir(parent);
31058 + if (bstart == bend)
31059 + goto out_parent; /* success */
31061 + e2 = au_wbr_create_mfs(dentry, flags);
31063 + goto out_parent; /* success */
31065 + /* when the available size is equal, select upper one */
31066 + sb = dentry->d_sb;
31067 + br = au_sbr(sb, err);
31068 + b = br->br_wbr->wbr_bytes;
31069 + AuDbg("b%d, %llu\n", err, b);
31071 + for (bindex = bstart; bindex <= bend; bindex++) {
31072 + h_parent = au_h_dptr(parent, bindex);
31073 + if (!h_parent || !h_parent->d_inode)
31076 + br = au_sbr(sb, bindex);
31077 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31078 + b = br->br_wbr->wbr_bytes;
31080 + AuDbg("b%d, %llu\n", err, b);
31085 + err = au_wbr_nonopq(dentry, err);
31090 + AuDbg("b%d\n", err);
31094 +/* ---------------------------------------------------------------------- */
31097 + * - top down parent
31098 + * - most free space with parent
31099 + * - most free space round-robin regardless parent
31101 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31104 + unsigned long long watermark;
31105 + struct super_block *sb;
31106 + struct au_branch *br;
31107 + struct au_wbr_mfs *mfs;
31109 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31110 + if (unlikely(err < 0))
31113 + sb = dentry->d_sb;
31114 + br = au_sbr(sb, err);
31115 + mfs = &au_sbi(sb)->si_wbr_mfs;
31116 + mutex_lock(&mfs->mfs_lock);
31117 + watermark = mfs->mfsrr_watermark;
31118 + mutex_unlock(&mfs->mfs_lock);
31119 + if (br->br_wbr->wbr_bytes < watermark)
31120 + /* regardless the parent dir */
31121 + err = au_wbr_create_mfsrr(dentry, flags);
31124 + AuDbg("b%d\n", err);
31128 +/* ---------------------------------------------------------------------- */
31130 +/* policies for copyup */
31132 +/* top down parent */
31133 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31135 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31138 +/* bottom up parent */
31139 +static int au_wbr_copyup_bup(struct dentry *dentry)
31142 + aufs_bindex_t bindex, bstart;
31143 + struct dentry *parent, *h_parent;
31144 + struct super_block *sb;
31147 + sb = dentry->d_sb;
31148 + parent = dget_parent(dentry);
31149 + bstart = au_dbstart(parent);
31150 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31151 + h_parent = au_h_dptr(parent, bindex);
31152 + if (!h_parent || !h_parent->d_inode)
31155 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31162 + /* bottom up here */
31163 + if (unlikely(err < 0))
31164 + err = au_wbr_bu(sb, bstart - 1);
31166 + AuDbg("b%d\n", err);
31171 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31175 + err = au_wbr_bu(dentry->d_sb, bstart);
31176 + AuDbg("b%d\n", err);
31177 + if (err > bstart)
31178 + err = au_wbr_nonopq(dentry, err);
31180 + AuDbg("b%d\n", err);
31184 +static int au_wbr_copyup_bu(struct dentry *dentry)
31187 + aufs_bindex_t bstart;
31189 + bstart = au_dbstart(dentry);
31190 + err = au_wbr_do_copyup_bu(dentry, bstart);
31194 +/* ---------------------------------------------------------------------- */
31196 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
31197 + [AuWbrCopyup_TDP] = {
31198 + .copyup = au_wbr_copyup_tdp
31200 + [AuWbrCopyup_BUP] = {
31201 + .copyup = au_wbr_copyup_bup
31203 + [AuWbrCopyup_BU] = {
31204 + .copyup = au_wbr_copyup_bu
31208 +struct au_wbr_create_operations au_wbr_create_ops[] = {
31209 + [AuWbrCreate_TDP] = {
31210 + .create = au_wbr_create_tdp
31212 + [AuWbrCreate_RR] = {
31213 + .create = au_wbr_create_rr,
31214 + .init = au_wbr_create_init_rr
31216 + [AuWbrCreate_MFS] = {
31217 + .create = au_wbr_create_mfs,
31218 + .init = au_wbr_create_init_mfs,
31219 + .fin = au_wbr_create_fin_mfs
31221 + [AuWbrCreate_MFSV] = {
31222 + .create = au_wbr_create_mfs,
31223 + .init = au_wbr_create_init_mfs,
31224 + .fin = au_wbr_create_fin_mfs
31226 + [AuWbrCreate_MFSRR] = {
31227 + .create = au_wbr_create_mfsrr,
31228 + .init = au_wbr_create_init_mfsrr,
31229 + .fin = au_wbr_create_fin_mfs
31231 + [AuWbrCreate_MFSRRV] = {
31232 + .create = au_wbr_create_mfsrr,
31233 + .init = au_wbr_create_init_mfsrr,
31234 + .fin = au_wbr_create_fin_mfs
31236 + [AuWbrCreate_PMFS] = {
31237 + .create = au_wbr_create_pmfs,
31238 + .init = au_wbr_create_init_mfs,
31239 + .fin = au_wbr_create_fin_mfs
31241 + [AuWbrCreate_PMFSV] = {
31242 + .create = au_wbr_create_pmfs,
31243 + .init = au_wbr_create_init_mfs,
31244 + .fin = au_wbr_create_fin_mfs
31246 + [AuWbrCreate_PMFSRR] = {
31247 + .create = au_wbr_create_pmfsrr,
31248 + .init = au_wbr_create_init_mfsrr,
31249 + .fin = au_wbr_create_fin_mfs
31251 + [AuWbrCreate_PMFSRRV] = {
31252 + .create = au_wbr_create_pmfsrr,
31253 + .init = au_wbr_create_init_mfsrr,
31254 + .fin = au_wbr_create_fin_mfs
31257 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
31258 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
31259 +++ linux/fs/aufs/whout.c 2015-04-13 15:10:20.790157026 +0200
31262 + * Copyright (C) 2005-2015 Junjiro R. Okajima
31264 + * This program, aufs is free software; you can redistribute it and/or modify
31265 + * it under the terms of the GNU General Public License as published by
31266 + * the Free Software Foundation; either version 2 of the License, or
31267 + * (at your option) any later version.
31269 + * This program is distributed in the hope that it will be useful,
31270 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31271 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31272 + * GNU General Public License for more details.
31274 + * You should have received a copy of the GNU General Public License
31275 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31279 + * whiteout for logical deletion and opaque directory
31284 +#define WH_MASK S_IRUGO
31287 + * If a directory contains this file, then it is opaque. We start with the
31288 + * .wh. flag so that it is blocked by lookup.
31290 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
31291 + sizeof(AUFS_WH_DIROPQ) - 1);
31294 + * generate whiteout name, which is NOT terminated by NULL.
31295 + * @name: original d_name.name
31296 + * @len: original d_name.len
31297 + * @wh: whiteout qstr
31298 + * returns zero when succeeds, otherwise error.
31299 + * succeeded value as wh->name should be freed by kfree().
31301 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31305 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31306 + return -ENAMETOOLONG;
31308 + wh->len = name->len + AUFS_WH_PFX_LEN;
31309 + p = kmalloc(wh->len, GFP_NOFS);
31312 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31313 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31320 +/* ---------------------------------------------------------------------- */
31323 + * test if the @wh_name exists under @h_parent.
31324 + * @try_sio specifies the necessary of super-io.
31326 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31329 + struct dentry *wh_dentry;
31332 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31334 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31335 + err = PTR_ERR(wh_dentry);
31336 + if (IS_ERR(wh_dentry)) {
31337 + if (err == -ENAMETOOLONG)
31343 + if (!wh_dentry->d_inode)
31344 + goto out_wh; /* success */
31347 + if (d_is_reg(wh_dentry))
31348 + goto out_wh; /* success */
31351 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31352 + wh_dentry, wh_dentry->d_inode->i_mode);
31361 + * test if the @h_dentry sets opaque or not.
31363 +int au_diropq_test(struct dentry *h_dentry)
31366 + struct inode *h_dir;
31368 + h_dir = h_dentry->d_inode;
31369 + err = au_wh_test(h_dentry, &diropq_name,
31370 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31375 + * returns a negative dentry whose name is unique and temporary.
31377 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31378 + struct qstr *prefix)
31380 + struct dentry *dentry;
31382 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31384 + /* strict atomic_t is unnecessary here */
31385 + static unsigned short cnt;
31388 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31391 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31392 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31393 + dentry = ERR_PTR(-ENAMETOOLONG);
31394 + if (unlikely(qs.len > NAME_MAX))
31396 + dentry = ERR_PTR(-ENOMEM);
31397 + name = kmalloc(qs.len + 1, GFP_NOFS);
31398 + if (unlikely(!name))
31402 + /* doubly whiteout-ed */
31403 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31404 + p = name + AUFS_WH_PFX_LEN * 2;
31405 + memcpy(p, prefix->name, prefix->len);
31406 + p += prefix->len;
31408 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31411 + for (i = 0; i < 3; i++) {
31412 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31413 + dentry = au_sio_lkup_one(&qs, h_parent);
31414 + if (IS_ERR(dentry) || !dentry->d_inode)
31418 + /* pr_warn("could not get random name\n"); */
31419 + dentry = ERR_PTR(-EEXIST);
31420 + AuDbg("%.*s\n", AuLNPair(&qs));
31424 + if (name != defname)
31427 + AuTraceErrPtr(dentry);
31432 + * rename the @h_dentry on @br to the whiteouted temporary name.
31434 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31437 + struct path h_path = {
31438 + .mnt = au_br_mnt(br)
31440 + struct inode *h_dir, *delegated;
31441 + struct dentry *h_parent;
31443 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31444 + h_dir = h_parent->d_inode;
31445 + IMustLock(h_dir);
31447 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31448 + err = PTR_ERR(h_path.dentry);
31449 + if (IS_ERR(h_path.dentry))
31452 + /* under the same dir, no need to lock_rename() */
31453 + delegated = NULL;
31454 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31456 + if (unlikely(err == -EWOULDBLOCK)) {
31457 + pr_warn("cannot retry for NFSv4 delegation"
31458 + " for an internal rename\n");
31461 + dput(h_path.dentry);
31468 +/* ---------------------------------------------------------------------- */
31470 + * functions for removing a whiteout
31473 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
31476 + struct inode *delegated;
31479 + * forces superio when the dir has a sticky bit.
31480 + * this may be a violation of unix fs semantics.
31482 + force = (h_dir->i_mode & S_ISVTX)
31483 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
31484 + delegated = NULL;
31485 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
31486 + if (unlikely(err == -EWOULDBLOCK)) {
31487 + pr_warn("cannot retry for NFSv4 delegation"
31488 + " for an internal unlink\n");
31494 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
31495 + struct dentry *dentry)
31499 + err = do_unlink_wh(h_dir, h_path);
31500 + if (!err && dentry)
31501 + au_set_dbwh(dentry, -1);
31506 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
31507 + struct au_branch *br)
31510 + struct path h_path = {
31511 + .mnt = au_br_mnt(br)
31515 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
31516 + if (IS_ERR(h_path.dentry))
31517 + err = PTR_ERR(h_path.dentry);
31519 + if (h_path.dentry->d_inode
31520 + && d_is_reg(h_path.dentry))
31521 + err = do_unlink_wh(h_parent->d_inode, &h_path);
31522 + dput(h_path.dentry);
31528 +/* ---------------------------------------------------------------------- */
31530 + * initialize/clean whiteout for a branch
31533 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
31537 + struct inode *delegated;
31539 + if (!whpath->dentry->d_inode)
31543 + err = vfsub_rmdir(h_dir, whpath);
31545 + delegated = NULL;
31546 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
31547 + if (unlikely(err == -EWOULDBLOCK)) {
31548 + pr_warn("cannot retry for NFSv4 delegation"
31549 + " for an internal unlink\n");
31553 + if (unlikely(err))
31554 + pr_warn("failed removing %pd (%d), ignored.\n",
31555 + whpath->dentry, err);
31558 +static int test_linkable(struct dentry *h_root)
31560 + struct inode *h_dir = h_root->d_inode;
31562 + if (h_dir->i_op->link)
31565 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
31566 + h_root, au_sbtype(h_root->d_sb));
31570 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
31571 +static int au_whdir(struct inode *h_dir, struct path *path)
31576 + if (!path->dentry->d_inode) {
31577 + int mode = S_IRWXU;
31579 + if (au_test_nfs(path->dentry->d_sb))
31581 + err = vfsub_mkdir(h_dir, path, mode);
31582 + } else if (d_is_dir(path->dentry))
31585 + pr_err("unknown %pd exists\n", path->dentry);
31590 +struct au_wh_base {
31591 + const struct qstr *name;
31592 + struct dentry *dentry;
31595 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
31596 + struct path *h_path)
31598 + h_path->dentry = base[AuBrWh_BASE].dentry;
31599 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31600 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31601 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31602 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31603 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31607 + * returns tri-state,
31608 + * minus: error, caller should print the message
31610 + * plus: error, caller should NOT print the message
31612 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
31613 + int do_plink, struct au_wh_base base[],
31614 + struct path *h_path)
31617 + struct inode *h_dir;
31619 + h_dir = h_root->d_inode;
31620 + h_path->dentry = base[AuBrWh_BASE].dentry;
31621 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31622 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31624 + err = test_linkable(h_root);
31625 + if (unlikely(err)) {
31630 + err = au_whdir(h_dir, h_path);
31631 + if (unlikely(err))
31633 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31635 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31636 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31637 + err = au_whdir(h_dir, h_path);
31638 + if (unlikely(err))
31640 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31647 + * for the moment, aufs supports the branch filesystem which does not support
31648 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
31649 + * copyup failed. finally, such filesystem will not be used as the writable
31652 + * returns tri-state, see above.
31654 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
31655 + int do_plink, struct au_wh_base base[],
31656 + struct path *h_path)
31659 + struct inode *h_dir;
31661 + WbrWhMustWriteLock(wbr);
31663 + err = test_linkable(h_root);
31664 + if (unlikely(err)) {
31670 + * todo: should this create be done in /sbin/mount.aufs helper?
31673 + h_dir = h_root->d_inode;
31674 + if (!base[AuBrWh_BASE].dentry->d_inode) {
31675 + h_path->dentry = base[AuBrWh_BASE].dentry;
31676 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
31677 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
31680 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
31681 + if (unlikely(err))
31684 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31686 + err = au_whdir(h_dir, h_path);
31687 + if (unlikely(err))
31689 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31691 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31692 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
31694 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31695 + err = au_whdir(h_dir, h_path);
31696 + if (unlikely(err))
31698 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31705 + * initialize the whiteout base file/dir for @br.
31707 +int au_wh_init(struct au_branch *br, struct super_block *sb)
31710 + const unsigned char do_plink
31711 + = !!au_opt_test(au_mntflags(sb), PLINK);
31712 + struct inode *h_dir;
31713 + struct path path = br->br_path;
31714 + struct dentry *h_root = path.dentry;
31715 + struct au_wbr *wbr = br->br_wbr;
31716 + static const struct qstr base_name[] = {
31717 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
31718 + sizeof(AUFS_BASE_NAME) - 1),
31719 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
31720 + sizeof(AUFS_PLINKDIR_NAME) - 1),
31721 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
31722 + sizeof(AUFS_ORPHDIR_NAME) - 1)
31724 + struct au_wh_base base[] = {
31725 + [AuBrWh_BASE] = {
31726 + .name = base_name + AuBrWh_BASE,
31729 + [AuBrWh_PLINK] = {
31730 + .name = base_name + AuBrWh_PLINK,
31733 + [AuBrWh_ORPH] = {
31734 + .name = base_name + AuBrWh_ORPH,
31740 + WbrWhMustWriteLock(wbr);
31742 + for (i = 0; i < AuBrWh_Last; i++) {
31743 + /* doubly whiteouted */
31744 + struct dentry *d;
31746 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
31747 + err = PTR_ERR(d);
31751 + base[i].dentry = d;
31753 + && wbr->wbr_wh[i]
31754 + && wbr->wbr_wh[i] != base[i].dentry);
31758 + for (i = 0; i < AuBrWh_Last; i++) {
31759 + dput(wbr->wbr_wh[i]);
31760 + wbr->wbr_wh[i] = NULL;
31764 + if (!au_br_writable(br->br_perm)) {
31765 + h_dir = h_root->d_inode;
31766 + au_wh_init_ro(h_dir, base, &path);
31767 + } else if (!au_br_wh_linkable(br->br_perm)) {
31768 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
31774 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
31780 + goto out; /* success */
31783 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
31784 + err, h_root, au_sbtype(h_root->d_sb));
31786 + for (i = 0; i < AuBrWh_Last; i++)
31787 + dput(base[i].dentry);
31791 +/* ---------------------------------------------------------------------- */
31793 + * whiteouts are all hard-linked usually.
31794 + * when its link count reaches a ceiling, we create a new whiteout base
31795 + * asynchronously.
31798 +struct reinit_br_wh {
31799 + struct super_block *sb;
31800 + struct au_branch *br;
31803 +static void reinit_br_wh(void *arg)
31806 + aufs_bindex_t bindex;
31807 + struct path h_path;
31808 + struct reinit_br_wh *a = arg;
31809 + struct au_wbr *wbr;
31810 + struct inode *dir, *delegated;
31811 + struct dentry *h_root;
31812 + struct au_hinode *hdir;
31815 + wbr = a->br->br_wbr;
31816 + /* big aufs lock */
31817 + si_noflush_write_lock(a->sb);
31818 + if (!au_br_writable(a->br->br_perm))
31820 + bindex = au_br_index(a->sb, a->br->br_id);
31821 + if (unlikely(bindex < 0))
31824 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
31825 + dir = a->sb->s_root->d_inode;
31826 + hdir = au_hi(dir, bindex);
31827 + h_root = au_h_dptr(a->sb->s_root, bindex);
31828 + AuDebugOn(h_root != au_br_dentry(a->br));
31830 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
31831 + wbr_wh_write_lock(wbr);
31832 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
31835 + h_path.dentry = wbr->wbr_whbase;
31836 + h_path.mnt = au_br_mnt(a->br);
31837 + delegated = NULL;
31838 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
31840 + if (unlikely(err == -EWOULDBLOCK)) {
31841 + pr_warn("cannot retry for NFSv4 delegation"
31842 + " for an internal unlink\n");
31846 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
31849 + dput(wbr->wbr_whbase);
31850 + wbr->wbr_whbase = NULL;
31852 + err = au_wh_init(a->br, a->sb);
31853 + wbr_wh_write_unlock(wbr);
31854 + au_hn_imtx_unlock(hdir);
31855 + di_read_unlock(a->sb->s_root, AuLock_IR);
31857 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
31861 + atomic_dec(&wbr->wbr_wh_running);
31862 + atomic_dec(&a->br->br_count);
31863 + si_write_unlock(a->sb);
31864 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
31866 + if (unlikely(err))
31867 + AuIOErr("err %d\n", err);
31870 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
31872 + int do_dec, wkq_err;
31873 + struct reinit_br_wh *arg;
31876 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
31879 + /* ignore ENOMEM */
31880 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
31883 + * dec(wh_running), kfree(arg) and dec(br_count)
31884 + * in reinit function
31888 + atomic_inc(&br->br_count);
31889 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
31890 + if (unlikely(wkq_err)) {
31891 + atomic_dec(&br->br_wbr->wbr_wh_running);
31892 + atomic_dec(&br->br_count);
31900 + atomic_dec(&br->br_wbr->wbr_wh_running);
31903 +/* ---------------------------------------------------------------------- */
31906 + * create the whiteout @wh.
31908 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
31909 + struct dentry *wh)
31912 + struct path h_path = {
31915 + struct au_branch *br;
31916 + struct au_wbr *wbr;
31917 + struct dentry *h_parent;
31918 + struct inode *h_dir, *delegated;
31920 + h_parent = wh->d_parent; /* dir inode is locked */
31921 + h_dir = h_parent->d_inode;
31922 + IMustLock(h_dir);
31924 + br = au_sbr(sb, bindex);
31925 + h_path.mnt = au_br_mnt(br);
31926 + wbr = br->br_wbr;
31927 + wbr_wh_read_lock(wbr);
31928 + if (wbr->wbr_whbase) {
31929 + delegated = NULL;
31930 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
31931 + if (unlikely(err == -EWOULDBLOCK)) {
31932 + pr_warn("cannot retry for NFSv4 delegation"
31933 + " for an internal link\n");
31936 + if (!err || err != -EMLINK)
31939 + /* link count full. re-initialize br_whbase. */
31940 + kick_reinit_br_wh(sb, br);
31943 + /* return this error in this context */
31944 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
31946 + au_fhsm_wrote(sb, bindex, /*force*/0);
31949 + wbr_wh_read_unlock(wbr);
31953 +/* ---------------------------------------------------------------------- */
31956 + * create or remove the diropq.
31958 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
31959 + unsigned int flags)
31961 + struct dentry *opq_dentry, *h_dentry;
31962 + struct super_block *sb;
31963 + struct au_branch *br;
31966 + sb = dentry->d_sb;
31967 + br = au_sbr(sb, bindex);
31968 + h_dentry = au_h_dptr(dentry, bindex);
31969 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
31970 + if (IS_ERR(opq_dentry))
31973 + if (au_ftest_diropq(flags, CREATE)) {
31974 + err = link_or_create_wh(sb, bindex, opq_dentry);
31976 + au_set_dbdiropq(dentry, bindex);
31977 + goto out; /* success */
31980 + struct path tmp = {
31981 + .dentry = opq_dentry,
31982 + .mnt = au_br_mnt(br)
31984 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
31986 + au_set_dbdiropq(dentry, -1);
31988 + dput(opq_dentry);
31989 + opq_dentry = ERR_PTR(err);
31992 + return opq_dentry;
31995 +struct do_diropq_args {
31996 + struct dentry **errp;
31997 + struct dentry *dentry;
31998 + aufs_bindex_t bindex;
31999 + unsigned int flags;
32002 +static void call_do_diropq(void *args)
32004 + struct do_diropq_args *a = args;
32005 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32008 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32009 + unsigned int flags)
32011 + struct dentry *diropq, *h_dentry;
32013 + h_dentry = au_h_dptr(dentry, bindex);
32014 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
32015 + diropq = do_diropq(dentry, bindex, flags);
32018 + struct do_diropq_args args = {
32020 + .dentry = dentry,
32021 + .bindex = bindex,
32025 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32026 + if (unlikely(wkq_err))
32027 + diropq = ERR_PTR(wkq_err);
32033 +/* ---------------------------------------------------------------------- */
32036 + * lookup whiteout dentry.
32037 + * @h_parent: lower parent dentry which must exist and be locked
32038 + * @base_name: name of dentry which will be whiteouted
32039 + * returns dentry for whiteout.
32041 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32042 + struct au_branch *br)
32045 + struct qstr wh_name;
32046 + struct dentry *wh_dentry;
32048 + err = au_wh_name_alloc(&wh_name, base_name);
32049 + wh_dentry = ERR_PTR(err);
32051 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32052 + kfree(wh_name.name);
32054 + return wh_dentry;
32058 + * link/create a whiteout for @dentry on @bindex.
32060 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32061 + struct dentry *h_parent)
32063 + struct dentry *wh_dentry;
32064 + struct super_block *sb;
32067 + sb = dentry->d_sb;
32068 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32069 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
32070 + err = link_or_create_wh(sb, bindex, wh_dentry);
32072 + au_set_dbwh(dentry, bindex);
32073 + au_fhsm_wrote(sb, bindex, /*force*/0);
32076 + wh_dentry = ERR_PTR(err);
32080 + return wh_dentry;
32083 +/* ---------------------------------------------------------------------- */
32085 +/* Delete all whiteouts in this directory on branch bindex. */
32086 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32087 + aufs_bindex_t bindex, struct au_branch *br)
32090 + unsigned long ul, n;
32091 + struct qstr wh_name;
32093 + struct hlist_head *head;
32094 + struct au_vdir_wh *pos;
32095 + struct au_vdir_destr *str;
32098 + p = (void *)__get_free_page(GFP_NOFS);
32099 + wh_name.name = p;
32100 + if (unlikely(!wh_name.name))
32104 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32105 + p += AUFS_WH_PFX_LEN;
32106 + n = whlist->nh_num;
32107 + head = whlist->nh_head;
32108 + for (ul = 0; !err && ul < n; ul++, head++) {
32109 + hlist_for_each_entry(pos, head, wh_hash) {
32110 + if (pos->wh_bindex != bindex)
32113 + str = &pos->wh_str;
32114 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32115 + memcpy(p, str->name, str->len);
32116 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32117 + err = unlink_wh_name(h_dentry, &wh_name, br);
32122 + AuIOErr("whiteout name too long %.*s\n",
32123 + str->len, str->name);
32128 + free_page((unsigned long)wh_name.name);
32134 +struct del_wh_children_args {
32136 + struct dentry *h_dentry;
32137 + struct au_nhash *whlist;
32138 + aufs_bindex_t bindex;
32139 + struct au_branch *br;
32142 +static void call_del_wh_children(void *args)
32144 + struct del_wh_children_args *a = args;
32145 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32148 +/* ---------------------------------------------------------------------- */
32150 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32152 + struct au_whtmp_rmdir *whtmp;
32154 + unsigned int rdhash;
32156 + SiMustAnyLock(sb);
32158 + whtmp = kmalloc(sizeof(*whtmp), gfp);
32159 + if (unlikely(!whtmp)) {
32160 + whtmp = ERR_PTR(-ENOMEM);
32164 + whtmp->dir = NULL;
32165 + whtmp->br = NULL;
32166 + whtmp->wh_dentry = NULL;
32167 + /* no estimation for dir size */
32168 + rdhash = au_sbi(sb)->si_rdhash;
32170 + rdhash = AUFS_RDHASH_DEF;
32171 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32172 + if (unlikely(err)) {
32174 + whtmp = ERR_PTR(err);
32181 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32184 + atomic_dec(&whtmp->br->br_count);
32185 + dput(whtmp->wh_dentry);
32186 + iput(whtmp->dir);
32187 + au_nhash_wh_free(&whtmp->whlist);
32192 + * rmdir the whiteouted temporary named dir @h_dentry.
32193 + * @whlist: whiteouted children.
32195 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32196 + struct dentry *wh_dentry, struct au_nhash *whlist)
32199 + unsigned int h_nlink;
32200 + struct path h_tmp;
32201 + struct inode *wh_inode, *h_dir;
32202 + struct au_branch *br;
32204 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
32205 + IMustLock(h_dir);
32207 + br = au_sbr(dir->i_sb, bindex);
32208 + wh_inode = wh_dentry->d_inode;
32209 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
32212 + * someone else might change some whiteouts while we were sleeping.
32213 + * it means this whlist may have an obsoleted entry.
32215 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
32216 + err = del_wh_children(wh_dentry, whlist, bindex, br);
32219 + struct del_wh_children_args args = {
32221 + .h_dentry = wh_dentry,
32222 + .whlist = whlist,
32223 + .bindex = bindex,
32227 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
32228 + if (unlikely(wkq_err))
32231 + mutex_unlock(&wh_inode->i_mutex);
32234 + h_tmp.dentry = wh_dentry;
32235 + h_tmp.mnt = au_br_mnt(br);
32236 + h_nlink = h_dir->i_nlink;
32237 + err = vfsub_rmdir(h_dir, &h_tmp);
32238 + /* some fs doesn't change the parent nlink in some cases */
32239 + h_nlink -= h_dir->i_nlink;
32243 + if (au_ibstart(dir) == bindex) {
32244 + /* todo: dir->i_mutex is necessary */
32245 + au_cpup_attr_timesizes(dir);
32247 + vfsub_drop_nlink(dir);
32249 + return 0; /* success */
32252 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
32256 +static void call_rmdir_whtmp(void *args)
32259 + aufs_bindex_t bindex;
32260 + struct au_whtmp_rmdir *a = args;
32261 + struct super_block *sb;
32262 + struct dentry *h_parent;
32263 + struct inode *h_dir;
32264 + struct au_hinode *hdir;
32266 + /* rmdir by nfsd may cause deadlock with this i_mutex */
32267 + /* mutex_lock(&a->dir->i_mutex); */
32269 + sb = a->dir->i_sb;
32270 + si_read_lock(sb, !AuLock_FLUSH);
32271 + if (!au_br_writable(a->br->br_perm))
32273 + bindex = au_br_index(sb, a->br->br_id);
32274 + if (unlikely(bindex < 0))
32278 + ii_write_lock_parent(a->dir);
32279 + h_parent = dget_parent(a->wh_dentry);
32280 + h_dir = h_parent->d_inode;
32281 + hdir = au_hi(a->dir, bindex);
32282 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
32283 + if (unlikely(err))
32285 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32286 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
32289 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
32290 + au_hn_imtx_unlock(hdir);
32291 + vfsub_mnt_drop_write(au_br_mnt(a->br));
32295 + ii_write_unlock(a->dir);
32297 + /* mutex_unlock(&a->dir->i_mutex); */
32298 + au_whtmp_rmdir_free(a);
32299 + si_read_unlock(sb);
32300 + au_nwt_done(&au_sbi(sb)->si_nowait);
32301 + if (unlikely(err))
32302 + AuIOErr("err %d\n", err);
32305 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32306 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32309 + struct super_block *sb;
32313 + /* all post-process will be done in do_rmdir_whtmp(). */
32315 + args->dir = au_igrab(dir);
32316 + args->br = au_sbr(sb, bindex);
32317 + atomic_inc(&args->br->br_count);
32318 + args->wh_dentry = dget(wh_dentry);
32319 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32320 + if (unlikely(wkq_err)) {
32321 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32322 + au_whtmp_rmdir_free(args);
32325 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
32326 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32327 +++ linux/fs/aufs/whout.h 2015-04-13 15:10:20.790157026 +0200
32330 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32332 + * This program, aufs is free software; you can redistribute it and/or modify
32333 + * it under the terms of the GNU General Public License as published by
32334 + * the Free Software Foundation; either version 2 of the License, or
32335 + * (at your option) any later version.
32337 + * This program is distributed in the hope that it will be useful,
32338 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32339 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32340 + * GNU General Public License for more details.
32342 + * You should have received a copy of the GNU General Public License
32343 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32347 + * whiteout for logical deletion and opaque directory
32350 +#ifndef __AUFS_WHOUT_H__
32351 +#define __AUFS_WHOUT_H__
32358 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32359 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32360 +int au_diropq_test(struct dentry *h_dentry);
32362 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32363 + struct qstr *prefix);
32364 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32365 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32366 + struct dentry *dentry);
32367 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32369 +/* diropq flags */
32370 +#define AuDiropq_CREATE 1
32371 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32372 +#define au_fset_diropq(flags, name) \
32373 + do { (flags) |= AuDiropq_##name; } while (0)
32374 +#define au_fclr_diropq(flags, name) \
32375 + do { (flags) &= ~AuDiropq_##name; } while (0)
32377 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32378 + unsigned int flags);
32379 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32380 + struct au_branch *br);
32381 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32382 + struct dentry *h_parent);
32384 +/* real rmdir for the whiteout-ed dir */
32385 +struct au_whtmp_rmdir {
32386 + struct inode *dir;
32387 + struct au_branch *br;
32388 + struct dentry *wh_dentry;
32389 + struct au_nhash whlist;
32392 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32393 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32394 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32395 + struct dentry *wh_dentry, struct au_nhash *whlist);
32396 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32397 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32399 +/* ---------------------------------------------------------------------- */
32401 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32402 + aufs_bindex_t bindex)
32404 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32407 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32409 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32412 +#endif /* __KERNEL__ */
32413 +#endif /* __AUFS_WHOUT_H__ */
32414 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
32415 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32416 +++ linux/fs/aufs/wkq.c 2015-04-13 15:10:20.790157026 +0200
32419 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32421 + * This program, aufs is free software; you can redistribute it and/or modify
32422 + * it under the terms of the GNU General Public License as published by
32423 + * the Free Software Foundation; either version 2 of the License, or
32424 + * (at your option) any later version.
32426 + * This program is distributed in the hope that it will be useful,
32427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32429 + * GNU General Public License for more details.
32431 + * You should have received a copy of the GNU General Public License
32432 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32436 + * workqueue for asynchronous/super-io operations
32437 + * todo: try new dredential scheme
32440 +#include <linux/module.h>
32443 +/* internal workqueue named AUFS_WKQ_NAME */
32445 +static struct workqueue_struct *au_wkq;
32447 +struct au_wkinfo {
32448 + struct work_struct wk;
32449 + struct kobject *kobj;
32451 + unsigned int flags; /* see wkq.h */
32453 + au_wkq_func_t func;
32456 + struct completion *comp;
32459 +/* ---------------------------------------------------------------------- */
32461 +static void wkq_func(struct work_struct *wk)
32463 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32465 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32466 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32468 + wkinfo->func(wkinfo->args);
32469 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32470 + complete(wkinfo->comp);
32472 + kobject_put(wkinfo->kobj);
32473 + module_put(THIS_MODULE); /* todo: ?? */
32479 + * Since struct completion is large, try allocating it dynamically.
32481 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
32482 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
32484 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32486 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
32488 + init_completion(*comp);
32489 + wkinfo->comp = *comp;
32495 +static void au_wkq_comp_free(struct completion *comp)
32503 +#define AuWkqCompDeclare(name) \
32504 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
32505 + struct completion *comp = &_ ## name
32507 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32509 + wkinfo->comp = *comp;
32513 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
32517 +#endif /* 4KSTACKS */
32519 +static void au_wkq_run(struct au_wkinfo *wkinfo)
32521 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
32522 + if (au_wkq_test()) {
32523 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
32524 + " due to a dead dir by UDBA?\n");
32525 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
32528 + au_dbg_verify_kthread();
32530 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
32531 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
32532 + queue_work(au_wkq, &wkinfo->wk);
32534 + INIT_WORK(&wkinfo->wk, wkq_func);
32535 + schedule_work(&wkinfo->wk);
32540 + * Be careful. It is easy to make deadlock happen.
32541 + * processA: lock, wkq and wait
32542 + * processB: wkq and wait, lock in wkq
32545 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
32548 + AuWkqCompDeclare(comp);
32549 + struct au_wkinfo wkinfo = {
32555 + err = au_wkq_comp_alloc(&wkinfo, &comp);
32557 + au_wkq_run(&wkinfo);
32558 + /* no timeout, no interrupt */
32559 + wait_for_completion(wkinfo.comp);
32560 + au_wkq_comp_free(comp);
32561 + destroy_work_on_stack(&wkinfo.wk);
32569 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
32570 + * problem in a concurrent umounting.
32572 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32573 + unsigned int flags)
32576 + struct au_wkinfo *wkinfo;
32578 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
32581 + * wkq_func() must free this wkinfo.
32582 + * it highly depends upon the implementation of workqueue.
32585 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
32587 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
32588 + wkinfo->flags = flags & ~AuWkq_WAIT;
32589 + wkinfo->func = func;
32590 + wkinfo->args = args;
32591 + wkinfo->comp = NULL;
32592 + kobject_get(wkinfo->kobj);
32593 + __module_get(THIS_MODULE); /* todo: ?? */
32595 + au_wkq_run(wkinfo);
32598 + au_nwt_done(&au_sbi(sb)->si_nowait);
32604 +/* ---------------------------------------------------------------------- */
32606 +void au_nwt_init(struct au_nowait_tasks *nwt)
32608 + atomic_set(&nwt->nw_len, 0);
32609 + /* smp_mb(); */ /* atomic_set */
32610 + init_waitqueue_head(&nwt->nw_wq);
32613 +void au_wkq_fin(void)
32615 + destroy_workqueue(au_wkq);
32618 +int __init au_wkq_init(void)
32623 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
32624 + if (IS_ERR(au_wkq))
32625 + err = PTR_ERR(au_wkq);
32626 + else if (!au_wkq)
32631 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
32632 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
32633 +++ linux/fs/aufs/wkq.h 2015-04-13 15:10:20.790157026 +0200
32636 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32638 + * This program, aufs is free software; you can redistribute it and/or modify
32639 + * it under the terms of the GNU General Public License as published by
32640 + * the Free Software Foundation; either version 2 of the License, or
32641 + * (at your option) any later version.
32643 + * This program is distributed in the hope that it will be useful,
32644 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32645 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32646 + * GNU General Public License for more details.
32648 + * You should have received a copy of the GNU General Public License
32649 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32653 + * workqueue for asynchronous/super-io operations
32654 + * todo: try new credentials management scheme
32657 +#ifndef __AUFS_WKQ_H__
32658 +#define __AUFS_WKQ_H__
32662 +struct super_block;
32664 +/* ---------------------------------------------------------------------- */
32667 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
32669 +struct au_nowait_tasks {
32671 + wait_queue_head_t nw_wq;
32674 +/* ---------------------------------------------------------------------- */
32676 +typedef void (*au_wkq_func_t)(void *args);
32679 +#define AuWkq_WAIT 1
32680 +#define AuWkq_NEST (1 << 1)
32681 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
32682 +#define au_fset_wkq(flags, name) \
32683 + do { (flags) |= AuWkq_##name; } while (0)
32684 +#define au_fclr_wkq(flags, name) \
32685 + do { (flags) &= ~AuWkq_##name; } while (0)
32687 +#ifndef CONFIG_AUFS_HNOTIFY
32689 +#define AuWkq_NEST 0
32693 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
32694 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32695 + unsigned int flags);
32696 +void au_nwt_init(struct au_nowait_tasks *nwt);
32697 +int __init au_wkq_init(void);
32698 +void au_wkq_fin(void);
32700 +/* ---------------------------------------------------------------------- */
32702 +static inline int au_wkq_test(void)
32704 + return current->flags & PF_WQ_WORKER;
32707 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
32709 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
32712 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
32714 + if (atomic_dec_and_test(&nwt->nw_len))
32715 + wake_up_all(&nwt->nw_wq);
32718 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
32720 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
32724 +#endif /* __KERNEL__ */
32725 +#endif /* __AUFS_WKQ_H__ */
32726 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
32727 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
32728 +++ linux/fs/aufs/xattr.c 2015-04-13 15:10:20.790157026 +0200
32731 + * Copyright (C) 2014-2015 Junjiro R. Okajima
32733 + * This program, aufs is free software; you can redistribute it and/or modify
32734 + * it under the terms of the GNU General Public License as published by
32735 + * the Free Software Foundation; either version 2 of the License, or
32736 + * (at your option) any later version.
32738 + * This program is distributed in the hope that it will be useful,
32739 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32740 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32741 + * GNU General Public License for more details.
32743 + * You should have received a copy of the GNU General Public License
32744 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32748 + * handling xattr functions
32751 +#include <linux/xattr.h>
32754 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
32756 + if (!ignore_flags)
32764 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
32769 +#define cmp(brattr, prefix) do { \
32770 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
32771 + XATTR_##prefix##_PREFIX_LEN)) { \
32772 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
32778 + cmp(SEC, SECURITY);
32779 + cmp(SYS, SYSTEM);
32780 + cmp(TR, TRUSTED);
32784 + if (ignore_flags & AuBrAttr_ICEX_OTH)
32791 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
32793 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
32794 + char *name, char **buf, unsigned int ignore_flags,
32795 + unsigned int verbose)
32799 + struct inode *h_idst;
32801 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
32803 + if (unlikely(err <= 0)) {
32805 + if (err == -ENODATA
32806 + || (err == -EOPNOTSUPP
32807 + && (ignore_flags & au_xattr_out_of_list)))
32812 + /* unlock it temporary */
32813 + h_idst = h_dst->d_inode;
32814 + mutex_unlock(&h_idst->i_mutex);
32815 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
32816 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
32817 + if (unlikely(err)) {
32818 + if (verbose || au_debug_test())
32819 + pr_err("%s, err %d\n", name, err);
32820 + err = au_xattr_ignore(err, name, ignore_flags);
32827 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
32828 + unsigned int verbose)
32830 + int err, unlocked, acl_access, acl_default;
32832 + struct inode *h_isrc, *h_idst;
32833 + char *value, *p, *o, *e;
32835 + /* try stopping to update the source inode while we are referencing */
32836 + /* there should not be the parent-child relationship between them */
32837 + h_isrc = h_src->d_inode;
32838 + h_idst = h_dst->d_inode;
32839 + mutex_unlock(&h_idst->i_mutex);
32840 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
32841 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
32844 + /* some filesystems don't list POSIX ACL, for example tmpfs */
32845 + ssz = vfs_listxattr(h_src, NULL, 0);
32847 + if (unlikely(err < 0)) {
32849 + if (err == -ENODATA
32850 + || err == -EOPNOTSUPP)
32851 + err = 0; /* ignore */
32860 + p = kmalloc(ssz, GFP_NOFS);
32862 + if (unlikely(!p))
32864 + err = vfs_listxattr(h_src, p, ssz);
32866 + mutex_unlock(&h_isrc->i_mutex);
32868 + AuDbg("err %d, ssz %zd\n", err, ssz);
32869 + if (unlikely(err < 0))
32877 + while (!err && p < e) {
32878 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
32879 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
32880 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
32881 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
32883 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
32885 + p += strlen(p) + 1;
32888 + ignore_flags |= au_xattr_out_of_list;
32889 + if (!err && !acl_access) {
32890 + err = au_do_cpup_xattr(h_dst, h_src,
32891 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
32892 + ignore_flags, verbose);
32895 + if (!err && !acl_default) {
32896 + err = au_do_cpup_xattr(h_dst, h_src,
32897 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
32898 + ignore_flags, verbose);
32908 + mutex_unlock(&h_isrc->i_mutex);
32913 +/* ---------------------------------------------------------------------- */
32920 +struct au_lgxattr {
32928 + const char *name;
32935 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
32938 + struct path h_path;
32939 + struct super_block *sb;
32941 + sb = dentry->d_sb;
32942 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
32943 + if (unlikely(err))
32945 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
32946 + if (unlikely(err))
32948 + if (unlikely(!h_path.dentry))
32949 + /* illegally overlapped or something */
32950 + goto out_di; /* pretending success */
32952 + /* always topmost entry only */
32953 + switch (arg->type) {
32954 + case AU_XATTR_LIST:
32955 + err = vfs_listxattr(h_path.dentry,
32956 + arg->u.list.list, arg->u.list.size);
32958 + case AU_XATTR_GET:
32959 + err = vfs_getxattr(h_path.dentry,
32960 + arg->u.get.name, arg->u.get.value,
32961 + arg->u.get.size);
32966 + di_read_unlock(dentry, AuLock_IR);
32968 + si_read_unlock(sb);
32974 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
32976 + struct au_lgxattr arg = {
32977 + .type = AU_XATTR_LIST,
32984 + return au_lgxattr(dentry, &arg);
32987 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
32990 + struct au_lgxattr arg = {
32991 + .type = AU_XATTR_GET,
32999 + return au_lgxattr(dentry, &arg);
33002 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33003 + size_t size, int flags)
33005 + struct au_srxattr arg = {
33006 + .type = AU_XATTR_SET,
33015 + return au_srxattr(dentry, &arg);
33018 +int aufs_removexattr(struct dentry *dentry, const char *name)
33020 + struct au_srxattr arg = {
33021 + .type = AU_XATTR_REMOVE,
33027 + return au_srxattr(dentry, &arg);
33030 +/* ---------------------------------------------------------------------- */
33033 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33034 + const char *name, size_t name_len, int type)
33036 + return aufs_listxattr(dentry, list, list_size);
33039 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33040 + size_t size, int type)
33042 + return aufs_getxattr(dentry, name, buffer, size);
33045 +static int au_xattr_set(struct dentry *dentry, const char *name,
33046 + const void *value, size_t size, int flags, int type)
33048 + return aufs_setxattr(dentry, name, value, size, flags);
33051 +static const struct xattr_handler au_xattr_handler = {
33052 + /* no prefix, no flags */
33053 + .list = au_xattr_list,
33054 + .get = au_xattr_get,
33055 + .set = au_xattr_set
33056 + /* why no remove? */
33059 +static const struct xattr_handler *au_xattr_handlers[] = {
33060 + &au_xattr_handler
33063 +void au_xattr_init(struct super_block *sb)
33065 + /* sb->s_xattr = au_xattr_handlers; */
33068 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33069 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33070 +++ linux/fs/aufs/xino.c 2015-04-13 15:10:20.790157026 +0200
33073 + * Copyright (C) 2005-2015 Junjiro R. Okajima
33075 + * This program, aufs is free software; you can redistribute it and/or modify
33076 + * it under the terms of the GNU General Public License as published by
33077 + * the Free Software Foundation; either version 2 of the License, or
33078 + * (at your option) any later version.
33080 + * This program is distributed in the hope that it will be useful,
33081 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33082 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33083 + * GNU General Public License for more details.
33085 + * You should have received a copy of the GNU General Public License
33086 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33090 + * external inode number translation table and bitmap
33093 +#include <linux/seq_file.h>
33094 +#include <linux/statfs.h>
33097 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33098 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
33102 + mm_segment_t oldfs;
33109 + oldfs = get_fs();
33110 + set_fs(KERNEL_DS);
33112 + /* todo: signal_pending? */
33113 + err = func(file, buf.u, size, pos);
33114 + } while (err == -EAGAIN || err == -EINTR);
33117 +#if 0 /* reserved for future use */
33119 + fsnotify_access(file->f_path.dentry);
33125 +/* ---------------------------------------------------------------------- */
33127 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
33128 + size_t size, loff_t *pos)
33131 + mm_segment_t oldfs;
33134 + const char __user *u;
33138 + oldfs = get_fs();
33139 + set_fs(KERNEL_DS);
33141 + /* todo: signal_pending? */
33142 + err = func(file, buf.u, size, pos);
33143 + } while (err == -EAGAIN || err == -EINTR);
33146 +#if 0 /* reserved for future use */
33148 + fsnotify_modify(file->f_path.dentry);
33154 +struct do_xino_fwrite_args {
33156 + au_writef_t func;
33157 + struct file *file;
33163 +static void call_do_xino_fwrite(void *args)
33165 + struct do_xino_fwrite_args *a = args;
33166 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
33169 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
33174 + /* todo: signal block and no wkq? */
33175 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
33177 + err = do_xino_fwrite(func, file, buf, size, pos);
33181 + * it breaks RLIMIT_FSIZE and normal user's limit,
33182 + * users should care about quota and real 'filesystem full.'
33185 + struct do_xino_fwrite_args args = {
33194 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
33195 + if (unlikely(wkq_err))
33202 +/* ---------------------------------------------------------------------- */
33205 + * create a new xinofile at the same place/path as @base_file.
33207 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
33209 + struct file *file;
33210 + struct dentry *base, *parent;
33211 + struct inode *dir, *delegated;
33212 + struct qstr *name;
33213 + struct path path;
33216 + base = base_file->f_path.dentry;
33217 + parent = base->d_parent; /* dir inode is locked */
33218 + dir = parent->d_inode;
33221 + file = ERR_PTR(-EINVAL);
33222 + name = &base->d_name;
33223 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
33224 + if (IS_ERR(path.dentry)) {
33225 + file = (void *)path.dentry;
33226 + pr_err("%pd lookup err %ld\n",
33227 + base, PTR_ERR(path.dentry));
33231 + /* no need to mnt_want_write() since we call dentry_open() later */
33232 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
33233 + if (unlikely(err)) {
33234 + file = ERR_PTR(err);
33235 + pr_err("%pd create err %d\n", base, err);
33239 + path.mnt = base_file->f_path.mnt;
33240 + file = vfsub_dentry_open(&path,
33241 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33242 + /* | __FMODE_NONOTIFY */);
33243 + if (IS_ERR(file)) {
33244 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
33248 + delegated = NULL;
33249 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
33250 + if (unlikely(err == -EWOULDBLOCK)) {
33251 + pr_warn("cannot retry for NFSv4 delegation"
33252 + " for an internal unlink\n");
33255 + if (unlikely(err)) {
33256 + pr_err("%pd unlink err %d\n", base, err);
33261 + /* no one can touch copy_src xino */
33262 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
33263 + if (unlikely(err)) {
33264 + pr_err("%pd copy err %d\n", base, err);
33268 + goto out_dput; /* success */
33272 + file = ERR_PTR(err);
33274 + dput(path.dentry);
33279 +struct au_xino_lock_dir {
33280 + struct au_hinode *hdir;
33281 + struct dentry *parent;
33282 + struct mutex *mtx;
33285 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
33286 + struct au_xino_lock_dir *ldir)
33288 + aufs_bindex_t brid, bindex;
33290 + ldir->hdir = NULL;
33292 + brid = au_xino_brid(sb);
33294 + bindex = au_br_index(sb, brid);
33295 + if (bindex >= 0) {
33296 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
33297 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
33299 + ldir->parent = dget_parent(xino->f_path.dentry);
33300 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
33301 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
33305 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
33308 + au_hn_imtx_unlock(ldir->hdir);
33310 + mutex_unlock(ldir->mtx);
33311 + dput(ldir->parent);
33315 +/* ---------------------------------------------------------------------- */
33317 +/* trucate xino files asynchronously */
33319 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
33322 + unsigned long jiffy;
33324 + aufs_bindex_t bi, bend;
33325 + struct kstatfs *st;
33326 + struct au_branch *br;
33327 + struct file *new_xino, *file;
33328 + struct super_block *h_sb;
33329 + struct au_xino_lock_dir ldir;
33332 + st = kzalloc(sizeof(*st), GFP_NOFS);
33333 + if (unlikely(!st))
33337 + bend = au_sbend(sb);
33338 + if (unlikely(bindex < 0 || bend < bindex))
33340 + br = au_sbr(sb, bindex);
33341 + file = br->br_xino.xi_file;
33345 + err = vfs_statfs(&file->f_path, st);
33346 + if (unlikely(err))
33347 + AuErr1("statfs err %d, ignored\n", err);
33349 + blocks = file_inode(file)->i_blocks;
33350 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33351 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
33353 + au_xino_lock_dir(sb, file, &ldir);
33354 + /* mnt_want_write() is unnecessary here */
33355 + new_xino = au_xino_create2(file, file);
33356 + au_xino_unlock_dir(&ldir);
33357 + err = PTR_ERR(new_xino);
33358 + if (IS_ERR(new_xino)) {
33359 + pr_err("err %d, ignored\n", err);
33364 + br->br_xino.xi_file = new_xino;
33366 + h_sb = au_br_sb(br);
33367 + for (bi = 0; bi <= bend; bi++) {
33368 + if (unlikely(bi == bindex))
33370 + br = au_sbr(sb, bi);
33371 + if (au_br_sb(br) != h_sb)
33374 + fput(br->br_xino.xi_file);
33375 + br->br_xino.xi_file = new_xino;
33376 + get_file(new_xino);
33379 + err = vfs_statfs(&new_xino->f_path, st);
33381 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33382 + bindex, (u64)file_inode(new_xino)->i_blocks,
33383 + st->f_bfree, st->f_blocks);
33384 + if (file_inode(new_xino)->i_blocks < blocks)
33385 + au_sbi(sb)->si_xino_jiffy = jiffy;
33387 + AuErr1("statfs err %d, ignored\n", err);
33395 +struct xino_do_trunc_args {
33396 + struct super_block *sb;
33397 + struct au_branch *br;
33400 +static void xino_do_trunc(void *_args)
33402 + struct xino_do_trunc_args *args = _args;
33403 + struct super_block *sb;
33404 + struct au_branch *br;
33405 + struct inode *dir;
33407 + aufs_bindex_t bindex;
33411 + dir = sb->s_root->d_inode;
33414 + si_noflush_write_lock(sb);
33415 + ii_read_lock_parent(dir);
33416 + bindex = au_br_index(sb, br->br_id);
33417 + err = au_xino_trunc(sb, bindex);
33418 + ii_read_unlock(dir);
33419 + if (unlikely(err))
33420 + pr_warn("err b%d, (%d)\n", bindex, err);
33421 + atomic_dec(&br->br_xino_running);
33422 + atomic_dec(&br->br_count);
33423 + si_write_unlock(sb);
33424 + au_nwt_done(&au_sbi(sb)->si_nowait);
33428 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
33431 + struct kstatfs st;
33432 + struct au_sbinfo *sbinfo;
33434 + /* todo: si_xino_expire and the ratio should be customizable */
33435 + sbinfo = au_sbi(sb);
33436 + if (time_before(jiffies,
33437 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
33440 + /* truncation border */
33441 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
33442 + if (unlikely(err)) {
33443 + AuErr1("statfs err %d, ignored\n", err);
33446 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
33452 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
33454 + struct xino_do_trunc_args *args;
33457 + if (!xino_trunc_test(sb, br))
33460 + if (atomic_inc_return(&br->br_xino_running) > 1)
33463 + /* lock and kfree() will be called in trunc_xino() */
33464 + args = kmalloc(sizeof(*args), GFP_NOFS);
33465 + if (unlikely(!args)) {
33466 + AuErr1("no memory\n");
33470 + atomic_inc(&br->br_count);
33473 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
33475 + return; /* success */
33477 + pr_err("wkq %d\n", wkq_err);
33478 + atomic_dec(&br->br_count);
33483 + atomic_dec(&br->br_xino_running);
33486 +/* ---------------------------------------------------------------------- */
33488 +static int au_xino_do_write(au_writef_t write, struct file *file,
33489 + ino_t h_ino, ino_t ino)
33495 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
33496 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
33499 + pos *= sizeof(ino);
33500 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
33501 + if (sz == sizeof(ino))
33502 + return 0; /* success */
33504 + AuIOErr("write failed (%zd)\n", sz);
33509 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
33510 + * at the position of @h_ino.
33511 + * even if @ino is zero, it is written to the xinofile and means no entry.
33512 + * if the size of the xino file on a specific filesystem exceeds the watermark,
33513 + * try truncating it.
33515 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
33519 + unsigned int mnt_flags;
33520 + struct au_branch *br;
33522 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
33523 + || ((loff_t)-1) > 0);
33524 + SiMustAnyLock(sb);
33526 + mnt_flags = au_mntflags(sb);
33527 + if (!au_opt_test(mnt_flags, XINO))
33530 + br = au_sbr(sb, bindex);
33531 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
33534 + if (au_opt_test(mnt_flags, TRUNC_XINO)
33535 + && au_test_fs_trunc_xino(au_br_sb(br)))
33536 + xino_try_trunc(sb, br);
33537 + return 0; /* success */
33540 + AuIOErr("write failed (%d)\n", err);
33544 +/* ---------------------------------------------------------------------- */
33546 +/* aufs inode number bitmap */
33548 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
33549 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
33553 + AuDebugOn(bit < 0 || page_bits <= bit);
33554 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
33558 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
33560 + AuDebugOn(ino < AUFS_FIRST_INO);
33561 + ino -= AUFS_FIRST_INO;
33562 + *pindex = ino / page_bits;
33563 + *bit = ino % page_bits;
33566 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
33571 + struct au_sbinfo *sbinfo;
33572 + struct file *xib;
33573 + unsigned long *p;
33575 + sbinfo = au_sbi(sb);
33576 + MtxMustLock(&sbinfo->si_xib_mtx);
33577 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
33578 + || !au_opt_test(sbinfo->si_mntflags, XINO));
33580 + if (pindex == sbinfo->si_xib_last_pindex)
33583 + xib = sbinfo->si_xib;
33584 + p = sbinfo->si_xib_buf;
33585 + pos = sbinfo->si_xib_last_pindex;
33586 + pos *= PAGE_SIZE;
33587 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33588 + if (unlikely(sz != PAGE_SIZE))
33592 + pos *= PAGE_SIZE;
33593 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
33594 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
33596 + memset(p, 0, PAGE_SIZE);
33597 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33599 + if (sz == PAGE_SIZE) {
33600 + sbinfo->si_xib_last_pindex = pindex;
33601 + return 0; /* success */
33605 + AuIOErr1("write failed (%zd)\n", sz);
33612 +/* ---------------------------------------------------------------------- */
33614 +static void au_xib_clear_bit(struct inode *inode)
33617 + unsigned long pindex;
33618 + struct super_block *sb;
33619 + struct au_sbinfo *sbinfo;
33621 + AuDebugOn(inode->i_nlink);
33623 + sb = inode->i_sb;
33624 + xib_calc_bit(inode->i_ino, &pindex, &bit);
33625 + AuDebugOn(page_bits <= bit);
33626 + sbinfo = au_sbi(sb);
33627 + mutex_lock(&sbinfo->si_xib_mtx);
33628 + err = xib_pindex(sb, pindex);
33630 + clear_bit(bit, sbinfo->si_xib_buf);
33631 + sbinfo->si_xib_next_bit = bit;
33633 + mutex_unlock(&sbinfo->si_xib_mtx);
33636 +/* for s_op->delete_inode() */
33637 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
33640 + unsigned int mnt_flags;
33641 + aufs_bindex_t bindex, bend, bi;
33642 + unsigned char try_trunc;
33643 + struct au_iinfo *iinfo;
33644 + struct super_block *sb;
33645 + struct au_hinode *hi;
33646 + struct inode *h_inode;
33647 + struct au_branch *br;
33648 + au_writef_t xwrite;
33650 + sb = inode->i_sb;
33651 + mnt_flags = au_mntflags(sb);
33652 + if (!au_opt_test(mnt_flags, XINO)
33653 + || inode->i_ino == AUFS_ROOT_INO)
33657 + au_xigen_inc(inode);
33658 + au_xib_clear_bit(inode);
33661 + iinfo = au_ii(inode);
33665 + bindex = iinfo->ii_bstart;
33669 + xwrite = au_sbi(sb)->si_xwrite;
33670 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
33671 + hi = iinfo->ii_hinode + bindex;
33672 + bend = iinfo->ii_bend;
33673 + for (; bindex <= bend; bindex++, hi++) {
33674 + h_inode = hi->hi_inode;
33676 + || (!unlinked && h_inode->i_nlink))
33679 + /* inode may not be revalidated */
33680 + bi = au_br_index(sb, hi->hi_id);
33684 + br = au_sbr(sb, bi);
33685 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
33686 + h_inode->i_ino, /*ino*/0);
33687 + if (!err && try_trunc
33688 + && au_test_fs_trunc_xino(au_br_sb(br)))
33689 + xino_try_trunc(sb, br);
33693 +/* get an unused inode number from bitmap */
33694 +ino_t au_xino_new_ino(struct super_block *sb)
33697 + unsigned long *p, pindex, ul, pend;
33698 + struct au_sbinfo *sbinfo;
33699 + struct file *file;
33700 + int free_bit, err;
33702 + if (!au_opt_test(au_mntflags(sb), XINO))
33703 + return iunique(sb, AUFS_FIRST_INO);
33705 + sbinfo = au_sbi(sb);
33706 + mutex_lock(&sbinfo->si_xib_mtx);
33707 + p = sbinfo->si_xib_buf;
33708 + free_bit = sbinfo->si_xib_next_bit;
33709 + if (free_bit < page_bits && !test_bit(free_bit, p))
33710 + goto out; /* success */
33711 + free_bit = find_first_zero_bit(p, page_bits);
33712 + if (free_bit < page_bits)
33713 + goto out; /* success */
33715 + pindex = sbinfo->si_xib_last_pindex;
33716 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
33717 + err = xib_pindex(sb, ul);
33718 + if (unlikely(err))
33720 + free_bit = find_first_zero_bit(p, page_bits);
33721 + if (free_bit < page_bits)
33722 + goto out; /* success */
33725 + file = sbinfo->si_xib;
33726 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
33727 + for (ul = pindex + 1; ul <= pend; ul++) {
33728 + err = xib_pindex(sb, ul);
33729 + if (unlikely(err))
33731 + free_bit = find_first_zero_bit(p, page_bits);
33732 + if (free_bit < page_bits)
33733 + goto out; /* success */
33738 + set_bit(free_bit, p);
33739 + sbinfo->si_xib_next_bit = free_bit + 1;
33740 + pindex = sbinfo->si_xib_last_pindex;
33741 + mutex_unlock(&sbinfo->si_xib_mtx);
33742 + ino = xib_calc_ino(pindex, free_bit);
33743 + AuDbg("i%lu\n", (unsigned long)ino);
33746 + mutex_unlock(&sbinfo->si_xib_mtx);
33752 + * read @ino from xinofile for the specified branch{@sb, @bindex}
33753 + * at the position of @h_ino.
33754 + * if @ino does not exist and @do_new is true, get new one.
33756 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
33762 + struct file *file;
33763 + struct au_sbinfo *sbinfo;
33766 + if (!au_opt_test(au_mntflags(sb), XINO))
33767 + return 0; /* no xino */
33770 + sbinfo = au_sbi(sb);
33772 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
33773 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
33776 + pos *= sizeof(*ino);
33778 + file = au_sbr(sb, bindex)->br_xino.xi_file;
33779 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
33780 + return 0; /* no ino */
33782 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
33783 + if (sz == sizeof(*ino))
33784 + return 0; /* success */
33787 + if (unlikely(sz >= 0)) {
33789 + AuIOErr("xino read error (%zd)\n", sz);
33795 +/* ---------------------------------------------------------------------- */
33797 +/* create and set a new xino file */
33799 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
33801 + struct file *file;
33802 + struct dentry *h_parent, *d;
33803 + struct inode *h_dir;
33807 + * at mount-time, and the xino file is the default path,
33808 + * hnotify is disabled so we have no notify events to ignore.
33809 + * when a user specified the xino, we cannot get au_hdir to be ignored.
33811 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33812 + /* | __FMODE_NONOTIFY */,
33813 + S_IRUGO | S_IWUGO);
33814 + if (IS_ERR(file)) {
33816 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
33820 + /* keep file count */
33821 + h_parent = dget_parent(file->f_path.dentry);
33822 + h_dir = h_parent->d_inode;
33823 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
33824 + /* mnt_want_write() is unnecessary here */
33825 + /* no delegation since it is just created */
33826 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
33827 + mutex_unlock(&h_dir->i_mutex);
33829 + if (unlikely(err)) {
33831 + pr_err("unlink %s(%d)\n", fname, err);
33836 + d = file->f_path.dentry;
33837 + if (unlikely(sb == d->d_sb)) {
33839 + pr_err("%s must be outside\n", fname);
33842 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
33844 + pr_err("xino doesn't support %s(%s)\n",
33845 + fname, au_sbtype(d->d_sb));
33848 + return file; /* success */
33852 + file = ERR_PTR(err);
33857 + * find another branch who is on the same filesystem of the specified
33858 + * branch{@btgt}. search until @bend.
33860 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
33861 + aufs_bindex_t bend)
33863 + aufs_bindex_t bindex;
33864 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
33866 + for (bindex = 0; bindex < btgt; bindex++)
33867 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
33869 + for (bindex++; bindex <= bend; bindex++)
33870 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
33875 +/* ---------------------------------------------------------------------- */
33878 + * initialize the xinofile for the specified branch @br
33879 + * at the place/path where @base_file indicates.
33880 + * test whether another branch is on the same filesystem or not,
33881 + * if @do_test is true.
33883 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
33884 + struct file *base_file, int do_test)
33888 + aufs_bindex_t bend, bindex;
33889 + struct au_branch *shared_br, *b;
33890 + struct file *file;
33891 + struct super_block *tgt_sb;
33893 + shared_br = NULL;
33894 + bend = au_sbend(sb);
33896 + tgt_sb = au_br_sb(br);
33897 + for (bindex = 0; bindex <= bend; bindex++) {
33898 + b = au_sbr(sb, bindex);
33899 + if (tgt_sb == au_br_sb(b)) {
33906 + if (!shared_br || !shared_br->br_xino.xi_file) {
33907 + struct au_xino_lock_dir ldir;
33909 + au_xino_lock_dir(sb, base_file, &ldir);
33910 + /* mnt_want_write() is unnecessary here */
33911 + file = au_xino_create2(base_file, NULL);
33912 + au_xino_unlock_dir(&ldir);
33913 + err = PTR_ERR(file);
33914 + if (IS_ERR(file))
33916 + br->br_xino.xi_file = file;
33918 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
33919 + get_file(br->br_xino.xi_file);
33922 + ino = AUFS_ROOT_INO;
33923 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
33925 + if (unlikely(err)) {
33926 + fput(br->br_xino.xi_file);
33927 + br->br_xino.xi_file = NULL;
33934 +/* ---------------------------------------------------------------------- */
33936 +/* trucate a xino bitmap file */
33939 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
33943 + unsigned long pindex;
33944 + loff_t pos, pend;
33945 + struct au_sbinfo *sbinfo;
33948 + unsigned long *p;
33951 + sbinfo = au_sbi(sb);
33952 + MtxMustLock(&sbinfo->si_xib_mtx);
33953 + p = sbinfo->si_xib_buf;
33954 + func = sbinfo->si_xread;
33955 + pend = vfsub_f_size_read(file);
33957 + while (pos < pend) {
33958 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
33960 + if (unlikely(sz <= 0))
33964 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
33965 + if (unlikely(*ino < AUFS_FIRST_INO))
33968 + xib_calc_bit(*ino, &pindex, &bit);
33969 + AuDebugOn(page_bits <= bit);
33970 + err = xib_pindex(sb, pindex);
33982 +static int xib_restore(struct super_block *sb)
33985 + aufs_bindex_t bindex, bend;
33989 + page = (void *)__get_free_page(GFP_NOFS);
33990 + if (unlikely(!page))
33994 + bend = au_sbend(sb);
33995 + for (bindex = 0; !err && bindex <= bend; bindex++)
33996 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
33997 + err = do_xib_restore
33998 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34000 + AuDbg("b%d\n", bindex);
34001 + free_page((unsigned long)page);
34007 +int au_xib_trunc(struct super_block *sb)
34012 + struct au_xino_lock_dir ldir;
34013 + struct au_sbinfo *sbinfo;
34014 + unsigned long *p;
34015 + struct file *file;
34017 + SiMustWriteLock(sb);
34020 + sbinfo = au_sbi(sb);
34021 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34024 + file = sbinfo->si_xib;
34025 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34028 + au_xino_lock_dir(sb, file, &ldir);
34029 + /* mnt_want_write() is unnecessary here */
34030 + file = au_xino_create2(sbinfo->si_xib, NULL);
34031 + au_xino_unlock_dir(&ldir);
34032 + err = PTR_ERR(file);
34033 + if (IS_ERR(file))
34035 + fput(sbinfo->si_xib);
34036 + sbinfo->si_xib = file;
34038 + p = sbinfo->si_xib_buf;
34039 + memset(p, 0, PAGE_SIZE);
34041 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34042 + if (unlikely(sz != PAGE_SIZE)) {
34044 + AuIOErr("err %d\n", err);
34050 + mutex_lock(&sbinfo->si_xib_mtx);
34051 + /* mnt_want_write() is unnecessary here */
34052 + err = xib_restore(sb);
34053 + mutex_unlock(&sbinfo->si_xib_mtx);
34059 +/* ---------------------------------------------------------------------- */
34062 + * xino mount option handlers
34064 +static au_readf_t find_readf(struct file *h_file)
34066 + const struct file_operations *fop = h_file->f_op;
34069 + return fop->read;
34070 + if (fop->aio_read)
34071 + return do_sync_read;
34072 + if (fop->read_iter)
34073 + return new_sync_read;
34074 + return ERR_PTR(-ENOSYS);
34077 +static au_writef_t find_writef(struct file *h_file)
34079 + const struct file_operations *fop = h_file->f_op;
34082 + return fop->write;
34083 + if (fop->aio_write)
34084 + return do_sync_write;
34085 + if (fop->write_iter)
34086 + return new_sync_write;
34087 + return ERR_PTR(-ENOSYS);
34091 +static void xino_clear_xib(struct super_block *sb)
34093 + struct au_sbinfo *sbinfo;
34095 + SiMustWriteLock(sb);
34097 + sbinfo = au_sbi(sb);
34098 + sbinfo->si_xread = NULL;
34099 + sbinfo->si_xwrite = NULL;
34100 + if (sbinfo->si_xib)
34101 + fput(sbinfo->si_xib);
34102 + sbinfo->si_xib = NULL;
34103 + free_page((unsigned long)sbinfo->si_xib_buf);
34104 + sbinfo->si_xib_buf = NULL;
34107 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34111 + struct au_sbinfo *sbinfo;
34112 + struct file *file;
34114 + SiMustWriteLock(sb);
34116 + sbinfo = au_sbi(sb);
34117 + file = au_xino_create2(base, sbinfo->si_xib);
34118 + err = PTR_ERR(file);
34119 + if (IS_ERR(file))
34121 + if (sbinfo->si_xib)
34122 + fput(sbinfo->si_xib);
34123 + sbinfo->si_xib = file;
34124 + sbinfo->si_xread = find_readf(file);
34125 + sbinfo->si_xwrite = find_writef(file);
34128 + if (!sbinfo->si_xib_buf)
34129 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34130 + if (unlikely(!sbinfo->si_xib_buf))
34133 + sbinfo->si_xib_last_pindex = 0;
34134 + sbinfo->si_xib_next_bit = 0;
34135 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34137 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34138 + PAGE_SIZE, &pos);
34139 + if (unlikely(err != PAGE_SIZE))
34143 + goto out; /* success */
34146 + free_page((unsigned long)sbinfo->si_xib_buf);
34147 + sbinfo->si_xib_buf = NULL;
34151 + fput(sbinfo->si_xib);
34152 + sbinfo->si_xib = NULL;
34153 + sbinfo->si_xread = NULL;
34154 + sbinfo->si_xwrite = NULL;
34159 +/* xino for each branch */
34160 +static void xino_clear_br(struct super_block *sb)
34162 + aufs_bindex_t bindex, bend;
34163 + struct au_branch *br;
34165 + bend = au_sbend(sb);
34166 + for (bindex = 0; bindex <= bend; bindex++) {
34167 + br = au_sbr(sb, bindex);
34168 + if (!br || !br->br_xino.xi_file)
34171 + fput(br->br_xino.xi_file);
34172 + br->br_xino.xi_file = NULL;
34176 +static int au_xino_set_br(struct super_block *sb, struct file *base)
34180 + aufs_bindex_t bindex, bend, bshared;
34182 + struct file *old, *new;
34184 + struct au_branch *br;
34185 + struct inode *inode;
34186 + au_writef_t writef;
34188 + SiMustWriteLock(sb);
34191 + bend = au_sbend(sb);
34192 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
34193 + if (unlikely(!fpair))
34196 + inode = sb->s_root->d_inode;
34197 + ino = AUFS_ROOT_INO;
34198 + writef = au_sbi(sb)->si_xwrite;
34199 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34200 + br = au_sbr(sb, bindex);
34201 + bshared = is_sb_shared(sb, bindex, bindex - 1);
34202 + if (bshared >= 0) {
34203 + /* shared xino */
34204 + *p = fpair[bshared];
34205 + get_file(p->new);
34210 + p->old = br->br_xino.xi_file;
34211 + p->new = au_xino_create2(base, br->br_xino.xi_file);
34212 + err = PTR_ERR(p->new);
34213 + if (IS_ERR(p->new)) {
34219 + err = au_xino_do_write(writef, p->new,
34220 + au_h_iptr(inode, bindex)->i_ino, ino);
34221 + if (unlikely(err))
34225 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34226 + br = au_sbr(sb, bindex);
34227 + if (br->br_xino.xi_file)
34228 + fput(br->br_xino.xi_file);
34229 + get_file(p->new);
34230 + br->br_xino.xi_file = p->new;
34234 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
34244 +void au_xino_clr(struct super_block *sb)
34246 + struct au_sbinfo *sbinfo;
34248 + au_xigen_clr(sb);
34249 + xino_clear_xib(sb);
34250 + xino_clear_br(sb);
34251 + sbinfo = au_sbi(sb);
34252 + /* lvalue, do not call au_mntflags() */
34253 + au_opt_clr(sbinfo->si_mntflags, XINO);
34256 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
34259 + struct dentry *parent, *cur_parent;
34260 + struct qstr *dname, *cur_name;
34261 + struct file *cur_xino;
34262 + struct inode *dir;
34263 + struct au_sbinfo *sbinfo;
34265 + SiMustWriteLock(sb);
34268 + sbinfo = au_sbi(sb);
34269 + parent = dget_parent(xino->file->f_path.dentry);
34272 + dname = &xino->file->f_path.dentry->d_name;
34273 + cur_xino = sbinfo->si_xib;
34275 + cur_parent = dget_parent(cur_xino->f_path.dentry);
34276 + cur_name = &cur_xino->f_path.dentry->d_name;
34277 + skip = (cur_parent == parent
34278 + && au_qstreq(dname, cur_name));
34279 + dput(cur_parent);
34285 + au_opt_set(sbinfo->si_mntflags, XINO);
34286 + dir = parent->d_inode;
34287 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
34288 + /* mnt_want_write() is unnecessary here */
34289 + err = au_xino_set_xib(sb, xino->file);
34291 + err = au_xigen_set(sb, xino->file);
34293 + err = au_xino_set_br(sb, xino->file);
34294 + mutex_unlock(&dir->i_mutex);
34296 + goto out; /* success */
34299 + AuIOErr("failed creating xino(%d).\n", err);
34300 + au_xigen_clr(sb);
34301 + xino_clear_xib(sb);
34308 +/* ---------------------------------------------------------------------- */
34311 + * create a xinofile at the default place/path.
34313 +struct file *au_xino_def(struct super_block *sb)
34315 + struct file *file;
34317 + struct au_branch *br;
34318 + struct super_block *h_sb;
34319 + struct path path;
34320 + aufs_bindex_t bend, bindex, bwr;
34323 + bend = au_sbend(sb);
34325 + for (bindex = 0; bindex <= bend; bindex++) {
34326 + br = au_sbr(sb, bindex);
34327 + if (au_br_writable(br->br_perm)
34328 + && !au_test_fs_bad_xino(au_br_sb(br))) {
34335 + file = ERR_PTR(-ENOMEM);
34336 + page = (void *)__get_free_page(GFP_NOFS);
34337 + if (unlikely(!page))
34339 + path.mnt = au_br_mnt(br);
34340 + path.dentry = au_h_dptr(sb->s_root, bwr);
34341 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
34342 + file = (void *)p;
34343 + if (!IS_ERR(p)) {
34344 + strcat(p, "/" AUFS_XINO_FNAME);
34345 + AuDbg("%s\n", p);
34346 + file = au_xino_create(sb, p, /*silent*/0);
34347 + if (!IS_ERR(file))
34348 + au_xino_brid_set(sb, br->br_id);
34350 + free_page((unsigned long)page);
34352 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
34353 + if (IS_ERR(file))
34355 + h_sb = file->f_path.dentry->d_sb;
34356 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
34357 + pr_err("xino doesn't support %s(%s)\n",
34358 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
34360 + file = ERR_PTR(-EINVAL);
34362 + if (!IS_ERR(file))
34363 + au_xino_brid_set(sb, -1);
34370 +/* ---------------------------------------------------------------------- */
34372 +int au_xino_path(struct seq_file *seq, struct file *file)
34376 + err = au_seq_path(seq, &file->f_path);
34377 + if (unlikely(err < 0))
34381 +#define Deleted "\\040(deleted)"
34382 + seq->count -= sizeof(Deleted) - 1;
34383 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
34384 + sizeof(Deleted) - 1));
34390 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
34391 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
34392 +++ linux/include/uapi/linux/aufs_type.h 2015-04-13 15:10:20.790157026 +0200
34395 + * Copyright (C) 2005-2015 Junjiro R. Okajima
34397 + * This program, aufs is free software; you can redistribute it and/or modify
34398 + * it under the terms of the GNU General Public License as published by
34399 + * the Free Software Foundation; either version 2 of the License, or
34400 + * (at your option) any later version.
34402 + * This program is distributed in the hope that it will be useful,
34403 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34404 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34405 + * GNU General Public License for more details.
34407 + * You should have received a copy of the GNU General Public License
34408 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34411 +#ifndef __AUFS_TYPE_H__
34412 +#define __AUFS_TYPE_H__
34414 +#define AUFS_NAME "aufs"
34418 + * define it before including all other headers.
34419 + * sched.h may use pr_* macros before defining "current", so define the
34420 + * no-current version first, and re-define later.
34422 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
34423 +#include <linux/sched.h>
34425 +#define pr_fmt(fmt) \
34426 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
34427 + (int)sizeof(current->comm), current->comm, current->pid
34429 +#include <stdint.h>
34430 +#include <sys/types.h>
34431 +#endif /* __KERNEL__ */
34433 +#include <linux/limits.h>
34435 +#define AUFS_VERSION "3.x-rcN-20150406"
34437 +/* todo? move this to linux-2.6.19/include/magic.h */
34438 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
34440 +/* ---------------------------------------------------------------------- */
34442 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
34443 +typedef int8_t aufs_bindex_t;
34444 +#define AUFS_BRANCH_MAX 127
34446 +typedef int16_t aufs_bindex_t;
34447 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
34448 +#define AUFS_BRANCH_MAX 511
34449 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
34450 +#define AUFS_BRANCH_MAX 1023
34451 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
34452 +#define AUFS_BRANCH_MAX 32767
34457 +#ifndef AUFS_BRANCH_MAX
34458 +#error unknown CONFIG_AUFS_BRANCH_MAX value
34460 +#endif /* __KERNEL__ */
34462 +/* ---------------------------------------------------------------------- */
34464 +#define AUFS_FSTYPE AUFS_NAME
34466 +#define AUFS_ROOT_INO 2
34467 +#define AUFS_FIRST_INO 11
34469 +#define AUFS_WH_PFX ".wh."
34470 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
34471 +#define AUFS_WH_TMP_LEN 4
34472 +/* a limit for rmdir/rename a dir and copyup */
34473 +#define AUFS_MAX_NAMELEN (NAME_MAX \
34474 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
34476 + - AUFS_WH_TMP_LEN) /* hex */
34477 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
34478 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
34479 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
34480 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
34481 +#define AUFS_DIRWH_DEF 3
34482 +#define AUFS_RDCACHE_DEF 10 /* seconds */
34483 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
34484 +#define AUFS_RDBLK_DEF 512 /* bytes */
34485 +#define AUFS_RDHASH_DEF 32
34486 +#define AUFS_WKQ_NAME AUFS_NAME "d"
34487 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
34488 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
34489 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
34490 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
34492 +/* pseudo-link maintenace under /proc */
34493 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
34494 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
34495 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
34497 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
34498 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
34500 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
34501 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
34502 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
34504 +/* doubly whiteouted */
34505 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
34506 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
34507 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
34509 +/* branch permissions and attributes */
34510 +#define AUFS_BRPERM_RW "rw"
34511 +#define AUFS_BRPERM_RO "ro"
34512 +#define AUFS_BRPERM_RR "rr"
34513 +#define AUFS_BRATTR_COO_REG "coo_reg"
34514 +#define AUFS_BRATTR_COO_ALL "coo_all"
34515 +#define AUFS_BRATTR_FHSM "fhsm"
34516 +#define AUFS_BRATTR_UNPIN "unpin"
34517 +#define AUFS_BRATTR_ICEX "icex"
34518 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
34519 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
34520 +#define AUFS_BRATTR_ICEX_TR "icextr"
34521 +#define AUFS_BRATTR_ICEX_USR "icexusr"
34522 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
34523 +#define AUFS_BRRATTR_WH "wh"
34524 +#define AUFS_BRWATTR_NLWH "nolwh"
34525 +#define AUFS_BRWATTR_MOO "moo"
34527 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
34528 +#define AuBrPerm_RO (1 << 1) /* readonly */
34529 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
34530 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
34532 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
34533 +#define AuBrAttr_COO_ALL (1 << 4)
34534 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
34536 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
34537 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
34538 + branch. meaningless since
34539 + linux-3.18-rc1 */
34541 +/* ignore error in copying XATTR */
34542 +#define AuBrAttr_ICEX_SEC (1 << 7)
34543 +#define AuBrAttr_ICEX_SYS (1 << 8)
34544 +#define AuBrAttr_ICEX_TR (1 << 9)
34545 +#define AuBrAttr_ICEX_USR (1 << 10)
34546 +#define AuBrAttr_ICEX_OTH (1 << 11)
34547 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
34548 + | AuBrAttr_ICEX_SYS \
34549 + | AuBrAttr_ICEX_TR \
34550 + | AuBrAttr_ICEX_USR \
34551 + | AuBrAttr_ICEX_OTH)
34553 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
34554 +#define AuBrRAttr_Mask AuBrRAttr_WH
34556 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
34557 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
34558 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
34560 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
34562 +/* #warning test userspace */
34564 +#ifndef CONFIG_AUFS_FHSM
34565 +#undef AuBrAttr_FHSM
34566 +#define AuBrAttr_FHSM 0
34568 +#ifndef CONFIG_AUFS_XATTR
34569 +#undef AuBrAttr_ICEX
34570 +#define AuBrAttr_ICEX 0
34571 +#undef AuBrAttr_ICEX_SEC
34572 +#define AuBrAttr_ICEX_SEC 0
34573 +#undef AuBrAttr_ICEX_SYS
34574 +#define AuBrAttr_ICEX_SYS 0
34575 +#undef AuBrAttr_ICEX_TR
34576 +#define AuBrAttr_ICEX_TR 0
34577 +#undef AuBrAttr_ICEX_USR
34578 +#define AuBrAttr_ICEX_USR 0
34579 +#undef AuBrAttr_ICEX_OTH
34580 +#define AuBrAttr_ICEX_OTH 0
34584 +/* the longest combination */
34585 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
34586 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
34587 + "+" AUFS_BRATTR_COO_REG \
34588 + "+" AUFS_BRATTR_FHSM \
34589 + "+" AUFS_BRATTR_UNPIN \
34590 + "+" AUFS_BRATTR_ICEX_SEC \
34591 + "+" AUFS_BRATTR_ICEX_SYS \
34592 + "+" AUFS_BRATTR_ICEX_USR \
34593 + "+" AUFS_BRATTR_ICEX_OTH \
34594 + "+" AUFS_BRWATTR_NLWH)
34597 + char a[AuBrPermStrSz];
34598 +} au_br_perm_str_t;
34600 +static inline int au_br_writable(int brperm)
34602 + return brperm & AuBrPerm_RW;
34605 +static inline int au_br_whable(int brperm)
34607 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
34610 +static inline int au_br_wh_linkable(int brperm)
34612 + return !(brperm & AuBrWAttr_NoLinkWH);
34615 +static inline int au_br_cmoo(int brperm)
34617 + return brperm & AuBrAttr_CMOO_Mask;
34620 +static inline int au_br_fhsm(int brperm)
34622 + return brperm & AuBrAttr_FHSM;
34625 +/* ---------------------------------------------------------------------- */
34629 + /* readdir in userspace */
34633 + AuCtl_WBR_FD, /* pathconf wrapper */
34634 + AuCtl_IBUSY, /* busy inode */
34635 + AuCtl_MVDOWN, /* move-down */
34636 + AuCtl_BR, /* info about branches */
34637 + AuCtl_FHSM_FD /* connection for fhsm */
34640 +/* borrowed from linux/include/linux/kernel.h */
34642 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
34643 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
34646 +/* borrowed from linux/include/linux/compiler-gcc3.h */
34648 +#define __aligned(x) __attribute__((aligned(x)))
34653 +#define __packed __attribute__((packed))
34657 +struct au_rdu_cookie {
34662 + uint32_t generation;
34665 +struct au_rdu_ent {
34674 +static inline int au_rdu_len(int nlen)
34676 + /* include the terminating NULL */
34677 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
34678 + sizeof(uint64_t));
34681 +union au_rdu_ent_ul {
34682 + struct au_rdu_ent __user *e;
34694 + uint64_t sz; /* AuCtl_RDU */
34695 + uint64_t nent; /* AuCtl_RDU_INO */
34697 + union au_rdu_ent_ul ent;
34698 + uint16_t verify[AufsCtlRduV_End];
34700 + /* input/output */
34704 + union au_rdu_ent_ul tail;
34705 + /* number of entries which were added in a single call */
34710 + struct au_rdu_cookie cookie;
34713 +/* ---------------------------------------------------------------------- */
34715 +struct aufs_wbr_fd {
34720 +/* ---------------------------------------------------------------------- */
34722 +struct aufs_ibusy {
34723 + uint64_t ino, h_ino;
34727 +/* ---------------------------------------------------------------------- */
34729 +/* error code for move-down */
34730 +/* the actual message strings are implemented in aufs-util.git */
34732 + EAU_MVDOWN_OPAQUE = 1,
34733 + EAU_MVDOWN_WHITEOUT,
34734 + EAU_MVDOWN_UPPER,
34735 + EAU_MVDOWN_BOTTOM,
34736 + EAU_MVDOWN_NOUPPER,
34737 + EAU_MVDOWN_NOLOWERBR,
34741 +/* flags for move-down */
34742 +#define AUFS_MVDOWN_DMSG 1
34743 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
34744 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
34745 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
34746 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
34747 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
34748 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
34749 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
34750 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
34751 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
34752 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
34753 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
34754 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
34756 +/* index for move-down */
34758 + AUFS_MVDOWN_UPPER,
34759 + AUFS_MVDOWN_LOWER,
34760 + AUFS_MVDOWN_NARRAY
34764 + * additional info of move-down
34765 + * number of free blocks and inodes.
34766 + * subset of struct kstatfs, but smaller and always 64bit.
34768 +struct aufs_stfs {
34769 + uint64_t f_blocks;
34770 + uint64_t f_bavail;
34771 + uint64_t f_files;
34772 + uint64_t f_ffree;
34775 +struct aufs_stbr {
34776 + int16_t brid; /* optional input */
34777 + int16_t bindex; /* output */
34778 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
34781 +struct aufs_mvdown {
34782 + uint32_t flags; /* input/output */
34783 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
34784 + int8_t au_errno; /* output */
34787 +/* ---------------------------------------------------------------------- */
34789 +union aufs_brinfo {
34790 + /* PATH_MAX may differ between kernel-space and user-space */
34791 + char _spacer[4096];
34799 +/* ---------------------------------------------------------------------- */
34801 +#define AuCtlType 'A'
34802 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
34803 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
34804 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
34805 + struct aufs_wbr_fd)
34806 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
34807 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
34808 + struct aufs_mvdown)
34809 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
34810 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
34812 +#endif /* __AUFS_TYPE_H__ */
34813 aufs3.x-rcN loopback patch
34815 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
34816 index a0da519..ffef6c0 100644
34817 --- a/drivers/block/loop.c
34818 +++ b/drivers/block/loop.c
34819 @@ -471,7 +471,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
34822 struct switch_request {
34823 - struct file *file;
34824 + struct file *file, *virt_file;
34825 struct completion wait;
34828 @@ -491,6 +491,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
34829 mapping = file->f_mapping;
34830 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
34831 lo->lo_backing_file = file;
34832 + lo->lo_backing_virt_file = p->virt_file;
34833 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
34834 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
34835 lo->old_gfp_mask = mapping_gfp_mask(mapping);
34836 @@ -502,11 +503,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
34837 * First it needs to flush existing IO, it does this by sending a magic
34838 * BIO down the pipe. The completion of this BIO does the actual switch.
34840 -static int loop_switch(struct loop_device *lo, struct file *file)
34841 +static int loop_switch(struct loop_device *lo, struct file *file,
34842 + struct file *virt_file)
34844 struct switch_request w;
34847 + w.virt_file = virt_file;
34849 /* freeze queue and wait for completion of scheduled requests */
34850 blk_mq_freeze_queue(lo->lo_queue);
34851 @@ -525,7 +528,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
34853 static int loop_flush(struct loop_device *lo)
34855 - return loop_switch(lo, NULL);
34856 + return loop_switch(lo, NULL, NULL);
34859 +static struct file *loop_real_file(struct file *file)
34861 + struct file *f = NULL;
34863 + if (file->f_path.dentry->d_sb->s_op->real_loop)
34864 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
34869 @@ -540,6 +552,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
34872 struct file *file, *old_file;
34873 + struct file *f, *virt_file = NULL, *old_virt_file;
34874 struct inode *inode;
34877 @@ -556,9 +569,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
34881 + f = loop_real_file(file);
34883 + virt_file = file;
34888 inode = file->f_mapping->host;
34889 old_file = lo->lo_backing_file;
34890 + old_virt_file = lo->lo_backing_virt_file;
34894 @@ -570,17 +590,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
34897 /* and ... switch */
34898 - error = loop_switch(lo, file);
34899 + error = loop_switch(lo, file, virt_file);
34904 + if (old_virt_file)
34905 + fput(old_virt_file);
34906 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
34907 ioctl_by_bdev(bdev, BLKRRPART, 0);
34917 @@ -741,7 +765,7 @@ static void loop_config_discard(struct loop_device *lo)
34918 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
34919 struct block_device *bdev, unsigned int arg)
34921 - struct file *file, *f;
34922 + struct file *file, *f, *virt_file = NULL;
34923 struct inode *inode;
34924 struct address_space *mapping;
34925 unsigned lo_blocksize;
34926 @@ -756,6 +780,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
34930 + f = loop_real_file(file);
34932 + virt_file = file;
34938 if (lo->lo_state != Lo_unbound)
34939 @@ -804,6 +834,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
34940 lo->lo_device = bdev;
34941 lo->lo_flags = lo_flags;
34942 lo->lo_backing_file = file;
34943 + lo->lo_backing_virt_file = virt_file;
34944 lo->transfer = transfer_none;
34946 lo->lo_sizelimit = 0;
34947 @@ -835,6 +866,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
34954 /* This is safe: open() is still holding a reference. */
34955 module_put(THIS_MODULE);
34956 @@ -881,6 +914,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
34957 static int loop_clr_fd(struct loop_device *lo)
34959 struct file *filp = lo->lo_backing_file;
34960 + struct file *virt_filp = lo->lo_backing_virt_file;
34961 gfp_t gfp = lo->old_gfp_mask;
34962 struct block_device *bdev = lo->lo_device;
34964 @@ -909,6 +943,7 @@ static int loop_clr_fd(struct loop_device *lo)
34965 spin_lock_irq(&lo->lo_lock);
34966 lo->lo_state = Lo_rundown;
34967 lo->lo_backing_file = NULL;
34968 + lo->lo_backing_virt_file = NULL;
34969 spin_unlock_irq(&lo->lo_lock);
34971 loop_release_xfer(lo);
34972 @@ -950,6 +985,8 @@ static int loop_clr_fd(struct loop_device *lo)
34973 * bd_mutex which is usually taken before lo_ctl_mutex.
34981 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
34982 index 301c27f..df84aa0 100644
34983 --- a/drivers/block/loop.h
34984 +++ b/drivers/block/loop.h
34985 @@ -46,7 +46,7 @@ struct loop_device {
34986 int (*ioctl)(struct loop_device *, int cmd,
34987 unsigned long arg);
34989 - struct file * lo_backing_file;
34990 + struct file * lo_backing_file, *lo_backing_virt_file;
34991 struct block_device *lo_device;
34992 unsigned lo_blocksize;
34994 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
34995 index 41c4c4a..6a68365 100644
34996 --- a/fs/aufs/f_op.c
34997 +++ b/fs/aufs/f_op.c
34998 @@ -368,7 +368,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
35000 h_file = au_hf_top(file);
35002 - if (au_test_loopback_kthread()) {
35003 + if (0 && au_test_loopback_kthread()) {
35004 au_warn_loopback(h_file->f_path.dentry->d_sb);
35005 if (file->f_mapping != h_file->f_mapping) {
35006 file->f_mapping = h_file->f_mapping;
35007 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35008 index 69f7e96..7941063 100644
35009 --- a/fs/aufs/loop.c
35010 +++ b/fs/aufs/loop.c
35011 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
35012 symbol_put(loop_backing_file);
35013 kfree(au_warn_loopback_array);
35016 +/* ---------------------------------------------------------------------- */
35018 +/* support the loopback block device insude aufs */
35020 +struct file *aufs_real_loop(struct file *file)
35024 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
35025 + fi_read_lock(file);
35026 + f = au_hf_top(file);
35027 + fi_read_unlock(file);
35031 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35032 index 6d9864d..3322557 100644
35033 --- a/fs/aufs/loop.h
35034 +++ b/fs/aufs/loop.h
35035 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35037 int au_loopback_init(void);
35038 void au_loopback_fin(void);
35040 +struct file *aufs_real_loop(struct file *file);
35042 +AuStub(struct file *, loop_backing_file, return NULL)
35044 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35045 struct dentry *h_adding)
35046 AuStubInt0(au_test_loopback_kthread, void)
35047 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35049 AuStubInt0(au_loopback_init, void)
35050 AuStubVoid(au_loopback_fin, void)
35052 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35053 #endif /* BLK_DEV_LOOP */
35055 #endif /* __KERNEL__ */
35056 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35057 index 98dc945..5da1392 100644
35058 --- a/fs/aufs/super.c
35059 +++ b/fs/aufs/super.c
35060 @@ -810,7 +810,10 @@ static const struct super_operations aufs_sop = {
35061 .statfs = aufs_statfs,
35062 .put_super = aufs_put_super,
35063 .sync_fs = aufs_sync_fs,
35064 - .remount_fs = aufs_remount_fs
35065 + .remount_fs = aufs_remount_fs,
35066 +#ifdef CONFIG_AUFS_BDEV_LOOP
35067 + .real_loop = aufs_real_loop
35071 /* ---------------------------------------------------------------------- */
35072 diff --git a/include/linux/fs.h b/include/linux/fs.h
35073 index b4d71b5..328c21d 100644
35074 --- a/include/linux/fs.h
35075 +++ b/include/linux/fs.h
35076 @@ -1655,6 +1655,10 @@ struct super_operations {
35077 struct shrink_control *);
35078 long (*free_cached_objects)(struct super_block *,
35079 struct shrink_control *);
35080 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35082 + struct file *(*real_loop)(struct file *);