]> git.pld-linux.org Git - packages/kernel.git/blobdiff - kernel-aufs3.patch
- partial update to 4.1.0 (aufs, imq need fixes)
[packages/kernel.git] / kernel-aufs3.patch
index e01d1dbea58ddbd546b2773bf367828e52dcfb00..53816565ec3236e8b12f862535097122b30f099d 100644 (file)
@@ -1,10 +1,10 @@
-aufs3.8 kbuild patch
+aufs3.x-rcN kbuild patch
 
 diff --git a/fs/Kconfig b/fs/Kconfig
-index 780725a..d460c05 100644
+index ec35851..a059d62 100644
 --- a/fs/Kconfig
 +++ b/fs/Kconfig
-@@ -211,6 +211,7 @@ source "fs/sysv/Kconfig"
+@@ -218,6 +218,7 @@ source "fs/sysv/Kconfig"
  source "fs/ufs/Kconfig"
  source "fs/exofs/Kconfig"
  source "fs/f2fs/Kconfig"
@@ -13,47 +13,100 @@ index 780725a..d460c05 100644
  endif # MISC_FILESYSTEMS
  
 diff --git a/fs/Makefile b/fs/Makefile
-index 9d53192..e70f08f 100644
+index a88ac48..162500e 100644
 --- a/fs/Makefile
 +++ b/fs/Makefile
-@@ -127,3 +127,4 @@ obj-$(CONFIG_F2FS_FS)              += f2fs/
- obj-y                         += exofs/ # Multiple modules
+@@ -126,3 +126,4 @@ obj-y                              += exofs/ # Multiple modules
  obj-$(CONFIG_CEPH_FS)         += ceph/
  obj-$(CONFIG_PSTORE)          += pstore/
+ obj-$(CONFIG_EFIVAR_FS)               += efivarfs/
 +obj-$(CONFIG_AUFS_FS)           += aufs/
-aufs3.8 base patch
+diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
+index 68ceb97..0352fa4 100644
+--- a/include/uapi/linux/Kbuild
++++ b/include/uapi/linux/Kbuild
+@@ -58,6 +58,7 @@ header-y += atmsvc.h
+ header-y += atm_tcp.h
+ header-y += atm_zatm.h
+ header-y += audit.h
++header-y += aufs_type.h
+ header-y += auto_fs4.h
+ header-y += auto_fs.h
+ header-y += auxvec.h
+aufs3.x-rcN base patch
 
-diff --git a/fs/file_table.c b/fs/file_table.c
-index de9e965..e73287a 100644
---- a/fs/file_table.c
-+++ b/fs/file_table.c
-@@ -36,7 +36,7 @@ struct files_stat_struct files_stat = {
-       .max_files = NR_FILE
- };
+diff --git a/MAINTAINERS b/MAINTAINERS
+index efbcb50..30a1654 100644
+--- a/MAINTAINERS
++++ b/MAINTAINERS
+@@ -1864,6 +1864,20 @@ F:      include/linux/audit.h
+ F:    include/uapi/linux/audit.h
+ F:    kernel/audit*
  
--DEFINE_STATIC_LGLOCK(files_lglock);
-+DEFINE_LGLOCK(files_lglock);
++AUFS (advanced multi layered unification filesystem) FILESYSTEM
++M:    "J. R. Okajima" <hooanon05g@gmail.com>
++L:    linux-unionfs@vger.kernel.org
++L:    aufs-users@lists.sourceforge.net (members only)
++W:    http://aufs.sourceforge.net
++T:    git://git.code.sf.net/p/aufs/aufs3-linux
++T:    git://github.com/sfjro/aufs3-linux.git
++S:    Supported
++F:    Documentation/filesystems/aufs/
++F:    Documentation/ABI/testing/debugfs-aufs
++F:    Documentation/ABI/testing/sysfs-aufs
++F:    fs/aufs/
++F:    include/uapi/linux/aufs_type.h
++
+ AUXILIARY DISPLAY DRIVERS
+ M:    Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
+ W:    http://miguelojeda.es/auxdisplay.htm
+diff --git a/drivers/block/loop.c b/drivers/block/loop.c
+index d1f168b..a0da519 100644
+--- a/drivers/block/loop.c
++++ b/drivers/block/loop.c
+@@ -592,6 +592,24 @@ static inline int is_loop_device(struct file *file)
+       return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
+ }
  
- /* SLAB cache for file structures */
- static struct kmem_cache *filp_cachep __read_mostly;
-diff --git a/fs/inode.c b/fs/inode.c
-index 14084b7..ece87ed 100644
---- a/fs/inode.c
-+++ b/fs/inode.c
-@@ -1503,7 +1503,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
-  * This does the actual work of updating an inodes time or version.  Must have
-  * had called mnt_want_write() before calling this.
++/*
++ * for AUFS
++ * no get/put for file.
++ */
++struct file *loop_backing_file(struct super_block *sb)
++{
++      struct file *ret;
++      struct loop_device *l;
++
++      ret = NULL;
++      if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
++              l = sb->s_bdev->bd_disk->private_data;
++              ret = l->lo_backing_file;
++      }
++      return ret;
++}
++EXPORT_SYMBOL(loop_backing_file);
++
+ /* loop sysfs attributes */
+ static ssize_t loop_attr_show(struct device *dev, char *page,
+diff --git a/fs/dcache.c b/fs/dcache.c
+index c71e373..b93a9f2 100644
+--- a/fs/dcache.c
++++ b/fs/dcache.c
+@@ -1130,7 +1130,7 @@ enum d_walk_ret {
+  *
+  * The @enter() and @finish() callbacks are called with d_lock held.
   */
--static int update_time(struct inode *inode, struct timespec *time, int flags)
-+int update_time(struct inode *inode, struct timespec *time, int flags)
+-static void d_walk(struct dentry *parent, void *data,
++void d_walk(struct dentry *parent, void *data,
+                  enum d_walk_ret (*enter)(void *, struct dentry *),
+                  void (*finish)(void *))
  {
-       if (inode->i_op->update_time)
-               return inode->i_op->update_time(inode, time, flags);
 diff --git a/fs/splice.c b/fs/splice.c
-index 6909d89..020c7bc 100644
+index 7968da9..beb9993 100644
 --- a/fs/splice.c
 +++ b/fs/splice.c
-@@ -1092,8 +1092,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
+@@ -1099,8 +1099,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
  /*
   * Attempt to initiate a splice from pipe to file.
   */
@@ -64,7 +117,7 @@ index 6909d89..020c7bc 100644
  {
        ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
                                loff_t *, size_t, unsigned int);
-@@ -1120,9 +1120,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
+@@ -1116,9 +1116,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
  /*
   * Attempt to initiate a splice from a file to a pipe.
   */
@@ -77,23 +130,23 @@ index 6909d89..020c7bc 100644
  {
        ssize_t (*splice_read)(struct file *, loff_t *,
                               struct pipe_inode_info *, size_t, unsigned int);
-diff --git a/include/linux/fs.h b/include/linux/fs.h
-index 7617ee0..1a39c33 100644
---- a/include/linux/fs.h
-+++ b/include/linux/fs.h
-@@ -2551,6 +2551,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
- extern int inode_newsize_ok(const struct inode *, loff_t offset);
- extern void setattr_copy(struct inode *inode, const struct iattr *attr);
-+extern int update_time(struct inode *, struct timespec *, int);
- extern int file_update_time(struct file *file);
+diff --git a/include/linux/file.h b/include/linux/file.h
+index f87d308..9a290b3 100644
+--- a/include/linux/file.h
++++ b/include/linux/file.h
+@@ -19,6 +19,7 @@ struct dentry;
+ struct path;
+ extern struct file *alloc_file(struct path *, fmode_t mode,
+       const struct file_operations *fop);
++extern struct file *get_empty_filp(void);
  
- extern int generic_show_options(struct seq_file *m, struct dentry *root);
+ static inline void fput_light(struct file *file, int fput_needed)
+ {
 diff --git a/include/linux/splice.h b/include/linux/splice.h
-index 09a545a..1ac5727 100644
+index da2751d..2e0fca6 100644
 --- a/include/linux/splice.h
 +++ b/include/linux/splice.h
-@@ -91,4 +91,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
+@@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
  extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
  
  extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
@@ -104,34 +157,487 @@ index 09a545a..1ac5727 100644
 +                       struct pipe_inode_info *pipe, size_t len,
 +                       unsigned int flags);
  #endif
-aufs3.8 standalone patch
+aufs3.x-rcN mmap patch
 
-diff --git a/fs/file_table.c b/fs/file_table.c
-index e73287a..b33aebe 100644
---- a/fs/file_table.c
-+++ b/fs/file_table.c
-@@ -37,6 +37,7 @@ struct files_stat_struct files_stat = {
- };
+diff --git a/fs/buffer.c b/fs/buffer.c
+index 20805db..363569f 100644
+--- a/fs/buffer.c
++++ b/fs/buffer.c
+@@ -2450,7 +2450,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
+        * Update file times before taking page lock. We may end up failing the
+        * fault so this update may be superfluous but who really cares...
+        */
+-      file_update_time(vma->vm_file);
++      vma_file_update_time(vma);
  
- DEFINE_LGLOCK(files_lglock);
-+EXPORT_SYMBOL(files_lglock);
+       ret = __block_page_mkwrite(vma, vmf, get_block);
+       sb_end_pagefault(sb);
+diff --git a/fs/proc/base.c b/fs/proc/base.c
+index 3f3d7ae..426bcc7 100644
+--- a/fs/proc/base.c
++++ b/fs/proc/base.c
+@@ -1735,7 +1735,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
+       down_read(&mm->mmap_sem);
+       vma = find_exact_vma(mm, vm_start, vm_end);
+       if (vma && vma->vm_file) {
+-              *path = vma->vm_file->f_path;
++              *path = vma_pr_or_file(vma)->f_path;
+               path_get(path);
+               rc = 0;
+       }
+diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
+index d4a3574..1397181 100644
+--- a/fs/proc/nommu.c
++++ b/fs/proc/nommu.c
+@@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
+       file = region->vm_file;
  
- /* SLAB cache for file structures */
- static struct kmem_cache *filp_cachep __read_mostly;
-@@ -403,6 +404,8 @@ void file_sb_list_del(struct file *file)
+       if (file) {
+-              struct inode *inode = file_inode(region->vm_file);
++              struct inode *inode;
++
++              file = vmr_pr_or_file(region);
++              inode = file_inode(file);
+               dev = inode->i_sb->s_dev;
+               ino = inode->i_ino;
        }
+diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
+index 6dee68d..9afa35d 100644
+--- a/fs/proc/task_mmu.c
++++ b/fs/proc/task_mmu.c
+@@ -279,7 +279,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
+       const char *name = NULL;
+       if (file) {
+-              struct inode *inode = file_inode(vma->vm_file);
++              struct inode *inode;
++
++              file = vma_pr_or_file(vma);
++              inode = file_inode(file);
+               dev = inode->i_sb->s_dev;
+               ino = inode->i_ino;
+               pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
+@@ -1479,7 +1482,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
+       struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
+       struct vm_area_struct *vma = v;
+       struct numa_maps *md = &numa_priv->md;
+-      struct file *file = vma->vm_file;
++      struct file *file = vma_pr_or_file(vma);
+       struct mm_struct *mm = vma->vm_mm;
+       struct mm_walk walk = {
+               .hugetlb_entry = gather_hugetlb_stats,
+diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
+index 599ec2e..1740207 100644
+--- a/fs/proc/task_nommu.c
++++ b/fs/proc/task_nommu.c
+@@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
+       file = vma->vm_file;
+       if (file) {
+-              struct inode *inode = file_inode(vma->vm_file);
++              struct inode *inode;
++
++              file = vma_pr_or_file(vma);
++              inode = file_inode(file);
+               dev = inode->i_sb->s_dev;
+               ino = inode->i_ino;
+               pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
+diff --git a/include/linux/mm.h b/include/linux/mm.h
+index 47a9392..c8f8b46 100644
+--- a/include/linux/mm.h
++++ b/include/linux/mm.h
+@@ -1254,6 +1254,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
+ }
+ #endif
++extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
++extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
++                                    int);
++extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
++extern void vma_do_fput(struct vm_area_struct *, const char[], int);
++
++#define vma_file_update_time(vma)     vma_do_file_update_time(vma, __func__, \
++                                                              __LINE__)
++#define vma_pr_or_file(vma)           vma_do_pr_or_file(vma, __func__, \
++                                                        __LINE__)
++#define vma_get_file(vma)             vma_do_get_file(vma, __func__, __LINE__)
++#define vma_fput(vma)                 vma_do_fput(vma, __func__, __LINE__)
++
++#ifndef CONFIG_MMU
++extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
++extern void vmr_do_fput(struct vm_region *, const char[], int);
++
++#define vmr_pr_or_file(region)                vmr_do_pr_or_file(region, __func__, \
++                                                        __LINE__)
++#define vmr_fput(region)              vmr_do_fput(region, __func__, __LINE__)
++#endif /* !CONFIG_MMU */
++
+ extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
+ extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
+               void *buf, int len, int write);
+diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
+index 199a03a..ed38ea3 100644
+--- a/include/linux/mm_types.h
++++ b/include/linux/mm_types.h
+@@ -241,6 +241,7 @@ struct vm_region {
+       unsigned long   vm_top;         /* region allocated to here */
+       unsigned long   vm_pgoff;       /* the offset in vm_file corresponding to vm_start */
+       struct file     *vm_file;       /* the backing file or NULL */
++      struct file     *vm_prfile;     /* the virtual backing file or NULL */
+       int             vm_usage;       /* region usage count (access under nommu_region_sem) */
+       bool            vm_icache_flushed : 1; /* true if the icache has been flushed for
+@@ -305,6 +306,7 @@ struct vm_area_struct {
+       unsigned long vm_pgoff;         /* Offset (within vm_file) in PAGE_SIZE
+                                          units, *not* PAGE_CACHE_SIZE */
+       struct file * vm_file;          /* File we map to (can be NULL). */
++      struct file *vm_prfile;         /* shadow of vm_file */
+       void * vm_private_data;         /* was vm_pte (shared mem) */
+ #ifndef CONFIG_MMU
+diff --git a/kernel/fork.c b/kernel/fork.c
+index cf65139..f28a048 100644
+--- a/kernel/fork.c
++++ b/kernel/fork.c
+@@ -430,7 +430,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
+                       struct inode *inode = file_inode(file);
+                       struct address_space *mapping = file->f_mapping;
+-                      get_file(file);
++                      vma_get_file(tmp);
+                       if (tmp->vm_flags & VM_DENYWRITE)
+                               atomic_dec(&inode->i_writecount);
+                       i_mmap_lock_write(mapping);
+diff --git a/mm/Makefile b/mm/Makefile
+index 15dbe99..88e25b5 100644
+--- a/mm/Makefile
++++ b/mm/Makefile
+@@ -21,7 +21,7 @@ obj-y                        := filemap.o mempool.o oom_kill.o \
+                          mm_init.o mmu_context.o percpu.o slab_common.o \
+                          compaction.o vmacache.o \
+                          interval_tree.o list_lru.o workingset.o \
+-                         debug.o $(mmu-y)
++                         prfile.o debug.o $(mmu-y)
+ obj-y += init-mm.o
+diff --git a/mm/filemap.c b/mm/filemap.c
+index ad72420..8885258 100644
+--- a/mm/filemap.c
++++ b/mm/filemap.c
+@@ -2064,7 +2064,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
+       int ret = VM_FAULT_LOCKED;
+       sb_start_pagefault(inode->i_sb);
+-      file_update_time(vma->vm_file);
++      vma_file_update_time(vma);
+       lock_page(page);
+       if (page->mapping != inode->i_mapping) {
+               unlock_page(page);
+diff --git a/mm/madvise.c b/mm/madvise.c
+index d551475..1ebf71b 100644
+--- a/mm/madvise.c
++++ b/mm/madvise.c
+@@ -320,12 +320,12 @@ static long madvise_remove(struct vm_area_struct *vma,
+        * vma's reference to the file) can go away as soon as we drop
+        * mmap_sem.
+        */
+-      get_file(f);
++      vma_get_file(vma);
+       up_read(&current->mm->mmap_sem);
+       error = vfs_fallocate(f,
+                               FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+                               offset, end - start);
+-      fput(f);
++      vma_fput(vma);
+       down_read(&current->mm->mmap_sem);
+       return error;
  }
+diff --git a/mm/memory.c b/mm/memory.c
+index 97839f5..5e5d491 100644
+--- a/mm/memory.c
++++ b/mm/memory.c
+@@ -2034,7 +2034,7 @@ static inline int wp_page_reuse(struct m
+               }
+               if (!page_mkwrite)
+-                      file_update_time(vma->vm_file);
++                      vma_file_update_time(vma);
+       }
+       return VM_FAULT_WRITE;
+diff --git a/mm/mmap.c b/mm/mmap.c
+index 9ec50a3..4a6a641 100644
+--- a/mm/mmap.c
++++ b/mm/mmap.c
+@@ -274,7 +274,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
+       if (vma->vm_ops && vma->vm_ops->close)
+               vma->vm_ops->close(vma);
+       if (vma->vm_file)
+-              fput(vma->vm_file);
++              vma_fput(vma);
+       mpol_put(vma_policy(vma));
+       kmem_cache_free(vm_area_cachep, vma);
+       return next;
+@@ -886,7 +886,7 @@ again:                     remove_next = 1 + (end > next->vm_end);
+       if (remove_next) {
+               if (file) {
+                       uprobe_munmap(next, next->vm_start, next->vm_end);
+-                      fput(file);
++                      vma_fput(vma);
+               }
+               if (next->anon_vma)
+                       anon_vma_merge(vma, next);
+@@ -1671,8 +1671,8 @@ out:
+       return addr;
+ unmap_and_free_vma:
++      vma_fput(vma);
+       vma->vm_file = NULL;
+-      fput(file);
+       /* Undo any partial mapping done by a device driver. */
+       unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
+@@ -2473,7 +2473,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
+               goto out_free_mpol;
+       if (new->vm_file)
+-              get_file(new->vm_file);
++              vma_get_file(new);
  
-+EXPORT_SYMBOL(file_sb_list_del);
+       if (new->vm_ops && new->vm_ops->open)
+               new->vm_ops->open(new);
+@@ -2492,7 +2492,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
+       if (new->vm_ops && new->vm_ops->close)
+               new->vm_ops->close(new);
+       if (new->vm_file)
+-              fput(new->vm_file);
++              vma_fput(new);
+       unlink_anon_vmas(new);
+  out_free_mpol:
+       mpol_put(vma_policy(new));
+@@ -2635,7 +2635,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
+       struct vm_area_struct *vma;
+       unsigned long populate = 0;
+       unsigned long ret = -EINVAL;
+-      struct file *file;
+       pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
+                       "See Documentation/vm/remap_file_pages.txt.\n",
+@@ -2679,10 +2678,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
+               munlock_vma_pages_range(vma, start, start + size);
+       }
+-      file = get_file(vma->vm_file);
++      vma_get_file(vma);
+       ret = do_mmap_pgoff(vma->vm_file, start, size,
+                       prot, flags, pgoff, &populate);
+-      fput(file);
++      vma_fput(vma);
+ out:
+       up_write(&mm->mmap_sem);
+       if (populate)
+@@ -2950,7 +2949,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
+                       if (anon_vma_clone(new_vma, vma))
+                               goto out_free_mempol;
+                       if (new_vma->vm_file)
+-                              get_file(new_vma->vm_file);
++                              vma_get_file(new_vma);
+                       if (new_vma->vm_ops && new_vma->vm_ops->open)
+                               new_vma->vm_ops->open(new_vma);
+                       vma_link(mm, new_vma, prev, rb_link, rb_parent);
+diff --git a/mm/msync.c b/mm/msync.c
+index bb04d53..5c24c54 100644
+--- a/mm/msync.c
++++ b/mm/msync.c
+@@ -84,10 +84,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
+               start = vma->vm_end;
+               if ((flags & MS_SYNC) && file &&
+                               (vma->vm_flags & VM_SHARED)) {
+-                      get_file(file);
++                      vma_get_file(vma);
+                       up_read(&mm->mmap_sem);
+                       error = vfs_fsync_range(file, fstart, fend, 1);
+-                      fput(file);
++                      vma_fput(vma);
+                       if (error || start >= end)
+                               goto out;
+                       down_read(&mm->mmap_sem);
+diff --git a/mm/nommu.c b/mm/nommu.c
+index 3fba2dc..870ce96 100644
+--- a/mm/nommu.c
++++ b/mm/nommu.c
+@@ -693,7 +693,7 @@ static void __put_nommu_region(struct vm_region *region)
+               up_write(&nommu_region_sem);
+               if (region->vm_file)
+-                      fput(region->vm_file);
++                      vmr_fput(region);
+               /* IO memory and memory shared directly out of the pagecache
+                * from ramfs/tmpfs mustn't be released here */
+@@ -858,7 +858,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
+       if (vma->vm_ops && vma->vm_ops->close)
+               vma->vm_ops->close(vma);
+       if (vma->vm_file)
+-              fput(vma->vm_file);
++              vma_fput(vma);
+       put_nommu_region(vma->vm_region);
+       kmem_cache_free(vm_area_cachep, vma);
+ }
+@@ -1398,7 +1398,7 @@ unsigned long do_mmap_pgoff(struct file *file,
+                                       goto error_just_free;
+                               }
+                       }
+-                      fput(region->vm_file);
++                      vmr_fput(region);
+                       kmem_cache_free(vm_region_jar, region);
+                       region = pregion;
+                       result = start;
+@@ -1474,10 +1474,10 @@ error_just_free:
+       up_write(&nommu_region_sem);
+ error:
+       if (region->vm_file)
+-              fput(region->vm_file);
++              vmr_fput(region);
+       kmem_cache_free(vm_region_jar, region);
+       if (vma->vm_file)
+-              fput(vma->vm_file);
++              vma_fput(vma);
+       kmem_cache_free(vm_area_cachep, vma);
+       kleave(" = %d", ret);
+       return ret;
+diff --git a/mm/prfile.c b/mm/prfile.c
+new file mode 100644
+index 0000000..6aa5ab5
+--- /dev/null
++++ b/mm/prfile.c
+@@ -0,0 +1,86 @@
++/*
++ * Mainly for aufs which mmap(2) diffrent file and wants to print different path
++ * in /proc/PID/maps.
++ * Call these functions via macros defined in linux/mm.h.
++ *
++ * See Documentation/filesystems/aufs/design/06mmap.txt
++ *
++ * Copyright (c) 2014 Junjro R. Okajima
++ * Copyright (c) 2014 Ian Campbell
++ */
++
++#include <linux/mm.h>
++#include <linux/file.h>
++#include <linux/fs.h>
++
++/* #define PRFILE_TRACE */
++static inline void prfile_trace(struct file *f, struct file *pr,
++                            const char func[], int line, const char func2[])
++{
++#ifdef PRFILE_TRACE
++      if (pr)
++              pr_info("%s:%d: %s, %p\n", func, line, func2,
++                      f ? (char *)f->f_path.dentry->d_name.name : "(null)");
++#endif
++}
++
++void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
++                           int line)
++{
++      struct file *f = vma->vm_file, *pr = vma->vm_prfile;
++
++      prfile_trace(f, pr, func, line, __func__);
++      file_update_time(f);
++      if (f && pr)
++              file_update_time(pr);
++}
++
++struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
++                             int line)
++{
++      struct file *f = vma->vm_file, *pr = vma->vm_prfile;
++
++      prfile_trace(f, pr, func, line, __func__);
++      return (f && pr) ? pr : f;
++}
++
++void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
++{
++      struct file *f = vma->vm_file, *pr = vma->vm_prfile;
++
++      prfile_trace(f, pr, func, line, __func__);
++      get_file(f);
++      if (f && pr)
++              get_file(pr);
++}
++
++void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
++{
++      struct file *f = vma->vm_file, *pr = vma->vm_prfile;
++
++      prfile_trace(f, pr, func, line, __func__);
++      fput(f);
++      if (f && pr)
++              fput(pr);
++}
++
++#ifndef CONFIG_MMU
++struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
++                             int line)
++{
++      struct file *f = region->vm_file, *pr = region->vm_prfile;
++
++      prfile_trace(f, pr, func, line, __func__);
++      return (f && pr) ? pr : f;
++}
++
++void vmr_do_fput(struct vm_region *region, const char func[], int line)
++{
++      struct file *f = region->vm_file, *pr = region->vm_prfile;
 +
- #ifdef CONFIG_SMP
++      prfile_trace(f, pr, func, line, __func__);
++      fput(f);
++      if (f && pr)
++              fput(pr);
++}
++#endif /* !CONFIG_MMU */
+aufs3.x-rcN standalone patch
+
+diff --git a/fs/dcache.c b/fs/dcache.c
+index b93a9f2..5a010ee 100644
+--- a/fs/dcache.c
++++ b/fs/dcache.c
+@@ -1235,6 +1235,7 @@ rename_retry:
+       seq = 1;
+       goto again;
+ }
++EXPORT_SYMBOL(d_walk);
  
  /*
+  * Search for at least 1 mount point in the dentry's subdirs.
+diff --git a/fs/file_table.c b/fs/file_table.c
+index 3f85411..00e9dcf 100644
+--- a/fs/file_table.c
++++ b/fs/file_table.c
+@@ -147,6 +147,7 @@ over:
+       }
+       return ERR_PTR(-ENFILE);
+ }
++EXPORT_SYMBOL(get_empty_filp);
+ /**
+  * alloc_file - allocate and initialize a 'struct file'
+@@ -308,6 +309,7 @@ void put_filp(struct file *file)
+               file_free(file);
+       }
+ }
++EXPORT_SYMBOL(put_filp);
+ void __init files_init(unsigned long mempages)
+ { 
 diff --git a/fs/inode.c b/fs/inode.c
-index ece87ed..38f7bc8 100644
+index f00b16f..eb7b8b5 100644
 --- a/fs/inode.c
 +++ b/fs/inode.c
-@@ -56,6 +56,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
+@@ -58,6 +58,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
  static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
  
  __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
@@ -139,27 +645,19 @@ index ece87ed..38f7bc8 100644
  
  /*
   * Empty aops. Can be used for the cases where the user does not
-@@ -1519,6 +1520,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
-       mark_inode_dirty_sync(inode);
-       return 0;
- }
-+EXPORT_SYMBOL(update_time);
- /**
-  *    touch_atime     -       update the access time
 diff --git a/fs/namespace.c b/fs/namespace.c
-index 55605c5..aed7607 100644
+index 82ef140..a3aa4b9 100644
 --- a/fs/namespace.c
 +++ b/fs/namespace.c
-@@ -52,6 +52,7 @@ EXPORT_SYMBOL_GPL(fs_kobj);
-  * tree or hash is modified or when a vfsmount structure is modified.
-  */
- DEFINE_BRLOCK(vfsmount_lock);
-+EXPORT_SYMBOL(vfsmount_lock);
+@@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
+       mnt_dec_writers(real_mount(mnt));
+       preempt_enable();
+ }
++EXPORT_SYMBOL_GPL(__mnt_drop_write);
  
- static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
- {
-@@ -1424,6 +1425,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
+ /**
+  * mnt_drop_write - give up write access to a mount
+@@ -1718,6 +1719,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
        }
        return 0;
  }
@@ -168,7 +666,7 @@ index 55605c5..aed7607 100644
  static void cleanup_group_ids(struct mount *mnt, struct mount *end)
  {
 diff --git a/fs/notify/group.c b/fs/notify/group.c
-index bd2625b..2ff2a0f 100644
+index d16b62c..06ca6bc 100644
 --- a/fs/notify/group.c
 +++ b/fs/notify/group.c
 @@ -22,6 +22,7 @@
@@ -179,7 +677,7 @@ index bd2625b..2ff2a0f 100644
  
  #include <linux/fsnotify_backend.h>
  #include "fsnotify.h"
-@@ -65,6 +66,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
+@@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
  {
        atomic_inc(&group->refcnt);
  }
@@ -187,7 +685,7 @@ index bd2625b..2ff2a0f 100644
  
  /*
   * Drop a reference to a group.  Free it if it's through.
-@@ -74,6 +76,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
+@@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
        if (atomic_dec_and_test(&group->refcnt))
                fsnotify_final_destroy_group(group);
  }
@@ -195,7 +693,7 @@ index bd2625b..2ff2a0f 100644
  
  /*
   * Create a new fsnotify_group and hold a reference for the group returned.
-@@ -102,6 +105,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
+@@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
  
        return group;
  }
@@ -204,26 +702,26 @@ index bd2625b..2ff2a0f 100644
  int fsnotify_fasync(int fd, struct file *file, int on)
  {
 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
-index fc6b49b..a6bb87d 100644
+index 92e48c7..d2c4b68 100644
 --- a/fs/notify/mark.c
 +++ b/fs/notify/mark.c
-@@ -115,6 +115,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
+@@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
                mark->free_mark(mark);
        }
  }
 +EXPORT_SYMBOL(fsnotify_put_mark);
  
- /*
-  * Any time a mark is getting freed we end up here.
-@@ -197,6 +198,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
+ /* Calculate mask of events for a list of marks */
+ u32 fsnotify_recalc_mask(struct hlist_head *head)
+@@ -202,6 +203,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
        fsnotify_destroy_mark_locked(mark, group);
        mutex_unlock(&group->mark_mutex);
  }
 +EXPORT_SYMBOL(fsnotify_destroy_mark);
  
- void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
- {
-@@ -281,6 +283,7 @@ err:
+ /*
+  * Destroy all marks in the given list. The marks must be already detached from
+@@ -376,6 +378,7 @@ err:
  
        return ret;
  }
@@ -231,7 +729,7 @@ index fc6b49b..a6bb87d 100644
  
  int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
                      struct inode *inode, struct vfsmount *mnt, int allow_dups)
-@@ -342,6 +345,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
+@@ -455,6 +458,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
        atomic_set(&mark->refcnt, 1);
        mark->free_mark = free_mark;
  }
@@ -240,10 +738,10 @@ index fc6b49b..a6bb87d 100644
  static int fsnotify_mark_destroy(void *ignored)
  {
 diff --git a/fs/open.c b/fs/open.c
-index 9b33c0c..e3365035 100644
+index 33f9cbf..fcc7eb4 100644
 --- a/fs/open.c
 +++ b/fs/open.c
-@@ -60,6 +60,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
+@@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
        mutex_unlock(&dentry->d_inode->i_mutex);
        return ret;
  }
@@ -251,11 +749,19 @@ index 9b33c0c..e3365035 100644
  
  long vfs_truncate(struct path *path, loff_t length)
  {
+@@ -672,6 +673,7 @@ int open_check_o_direct(struct file *f)
+       }
+       return 0;
+ }
++EXPORT_SYMBOL(open_check_o_direct);
+ static int do_dentry_open(struct file *f,
+                         int (*open)(struct inode *, struct file *),
 diff --git a/fs/splice.c b/fs/splice.c
-index 020c7bc..a622ade 100644
+index beb9993..813275a 100644
 --- a/fs/splice.c
 +++ b/fs/splice.c
-@@ -1116,6 +1116,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
+@@ -1112,6 +1112,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
  
        return splice_write(pipe, out, ppos, len, flags);
  }
@@ -263,7 +769,7 @@ index 020c7bc..a622ade 100644
  
  /*
   * Attempt to initiate a splice from a file to a pipe.
-@@ -1142,6 +1143,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
+@@ -1138,6 +1139,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
  
        return splice_read(in, ppos, pipe, len, flags);
  }
@@ -271,11 +777,23 @@ index 020c7bc..a622ade 100644
  
  /**
   * splice_direct_to_actor - splices data directly between two non-pipes
+diff --git a/fs/xattr.c b/fs/xattr.c
+index 4ef6985..6bb6303 100644
+--- a/fs/xattr.c
++++ b/fs/xattr.c
+@@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
+       *xattr_value = value;
+       return error;
+ }
++EXPORT_SYMBOL(vfs_getxattr_alloc);
+ /* Compare an extended attribute value with the given value */
+ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
 diff --git a/security/commoncap.c b/security/commoncap.c
-index 7ee08c7..176edf1 100644
+index f66713b..fd4c4b8 100644
 --- a/security/commoncap.c
 +++ b/security/commoncap.c
-@@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
+@@ -975,9 +975,11 @@ int cap_mmap_addr(unsigned long addr)
        }
        return ret;
  }
@@ -288,7 +806,7 @@ index 7ee08c7..176edf1 100644
  }
 +EXPORT_SYMBOL(cap_mmap_file);
 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
-index d794abc..a20f167 100644
+index 188c1d2..426d9af 100644
 --- a/security/device_cgroup.c
 +++ b/security/device_cgroup.c
 @@ -7,6 +7,7 @@
@@ -299,7 +817,7 @@ index d794abc..a20f167 100644
  #include <linux/list.h>
  #include <linux/uaccess.h>
  #include <linux/seq_file.h>
-@@ -631,6 +632,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
+@@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
        return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
                        access);
  }
@@ -308,10 +826,10 @@ index d794abc..a20f167 100644
  int devcgroup_inode_mknod(int mode, dev_t dev)
  {
 diff --git a/security/security.c b/security/security.c
-index 7b88c6a..5d00a30 100644
+index e81d5bb..0b7b840 100644
 --- a/security/security.c
 +++ b/security/security.c
-@@ -396,6 +396,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
+@@ -430,6 +430,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
                return 0;
        return security_ops->path_rmdir(dir, dentry);
  }
@@ -319,7 +837,7 @@ index 7b88c6a..5d00a30 100644
  
  int security_path_unlink(struct path *dir, struct dentry *dentry)
  {
-@@ -412,6 +413,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
+@@ -446,6 +447,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
                return 0;
        return security_ops->path_symlink(dir, dentry, old_name);
  }
@@ -327,15 +845,15 @@ index 7b88c6a..5d00a30 100644
  
  int security_path_link(struct dentry *old_dentry, struct path *new_dir,
                       struct dentry *new_dentry)
-@@ -420,6 +422,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
+@@ -454,6 +456,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
                return 0;
        return security_ops->path_link(old_dentry, new_dir, new_dentry);
  }
 +EXPORT_SYMBOL(security_path_link);
  
  int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
-                        struct path *new_dir, struct dentry *new_dentry)
-@@ -438,6 +441,7 @@ int security_path_truncate(struct path *path)
+                        struct path *new_dir, struct dentry *new_dentry,
+@@ -481,6 +484,7 @@ int security_path_truncate(struct path *path)
                return 0;
        return security_ops->path_truncate(path);
  }
@@ -343,7 +861,7 @@ index 7b88c6a..5d00a30 100644
  
  int security_path_chmod(struct path *path, umode_t mode)
  {
-@@ -445,6 +449,7 @@ int security_path_chmod(struct path *path, umode_t mode)
+@@ -488,6 +492,7 @@ int security_path_chmod(struct path *path, umode_t mode)
                return 0;
        return security_ops->path_chmod(path, mode);
  }
@@ -351,7 +869,7 @@ index 7b88c6a..5d00a30 100644
  
  int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
  {
-@@ -452,6 +457,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
+@@ -495,6 +500,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
                return 0;
        return security_ops->path_chown(path, uid, gid);
  }
@@ -359,7 +877,7 @@ index 7b88c6a..5d00a30 100644
  
  int security_path_chroot(struct path *path)
  {
-@@ -528,6 +534,7 @@ int security_inode_readlink(struct dentry *dentry)
+@@ -580,6 +586,7 @@ int security_inode_readlink(struct dentry *dentry)
                return 0;
        return security_ops->inode_readlink(dentry);
  }
@@ -367,7 +885,7 @@ index 7b88c6a..5d00a30 100644
  
  int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
  {
-@@ -542,6 +549,7 @@ int security_inode_permission(struct inode *inode, int mask)
+@@ -594,6 +601,7 @@ int security_inode_permission(struct inode *inode, int mask)
                return 0;
        return security_ops->inode_permission(inode, mask);
  }
@@ -375,7 +893,7 @@ index 7b88c6a..5d00a30 100644
  
  int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
  {
-@@ -663,6 +671,7 @@ int security_file_permission(struct file *file, int mask)
+@@ -716,6 +724,7 @@ int security_file_permission(struct file *file, int mask)
  
        return fsnotify_perm(file, mask);
  }
@@ -383,7 +901,7 @@ index 7b88c6a..5d00a30 100644
  
  int security_file_alloc(struct file *file)
  {
-@@ -723,6 +732,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
+@@ -775,6 +784,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
                return ret;
        return ima_file_mmap(file, prot);
  }
@@ -393,19 +911,32 @@ index 7b88c6a..5d00a30 100644
  {
 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs    1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/ABI/testing/debugfs-aufs       2012-08-26 08:39:00.753841216 +0200
-@@ -0,0 +1,37 @@
++++ linux/Documentation/ABI/testing/debugfs-aufs       2014-01-30 21:10:02.794146538 +0100
+@@ -0,0 +1,50 @@
 +What:         /debug/aufs/si_<id>/
 +Date:         March 2009
-+Contact:      J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
 +Description:
 +              Under /debug/aufs, a directory named si_<id> is created
 +              per aufs mount, where <id> is a unique id generated
 +              internally.
 +
++What:         /debug/aufs/si_<id>/plink
++Date:         Apr 2013
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
++Description:
++              It has three lines and shows the information about the
++              pseudo-link. The first line is a single number
++              representing a number of buckets. The second line is a
++              number of pseudo-links per buckets (separated by a
++              blank). The last line is a single number representing a
++              total number of psedo-links.
++              When the aufs mount option 'noplink' is specified, it
++              will show "1\n0\n0\n".
++
 +What:         /debug/aufs/si_<id>/xib
 +Date:         March 2009
-+Contact:      J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
 +Description:
 +              It shows the consumed blocks by xib (External Inode Number
 +              Bitmap), its block size and file size.
@@ -414,7 +945,7 @@ diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Document
 +
 +What:         /debug/aufs/si_<id>/xino0, xino1 ... xinoN
 +Date:         March 2009
-+Contact:      J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
 +Description:
 +              It shows the consumed blocks by xino (External Inode Number
 +              Translation Table), its link count, block size and file
@@ -424,7 +955,7 @@ diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Document
 +
 +What:         /debug/aufs/si_<id>/xigen
 +Date:         March 2009
-+Contact:      J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
 +Description:
 +              It shows the consumed blocks by xigen (External Inode
 +              Generation Table), its block size and file size.
@@ -434,11 +965,11 @@ diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Document
 +              will be empty. About XINO files, see the aufs manual.
 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs      1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/ABI/testing/sysfs-aufs 2012-08-26 08:39:00.753841216 +0200
-@@ -0,0 +1,24 @@
++++ linux/Documentation/ABI/testing/sysfs-aufs 2014-01-30 21:10:02.794146538 +0100
+@@ -0,0 +1,31 @@
 +What:         /sys/fs/aufs/si_<id>/
 +Date:         March 2009
-+Contact:      J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
 +Description:
 +              Under /sys/fs/aufs, a directory named si_<id> is created
 +              per aufs mount, where <id> is a unique id generated
@@ -446,14 +977,21 @@ diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentat
 +
 +What:         /sys/fs/aufs/si_<id>/br0, br1 ... brN
 +Date:         March 2009
-+Contact:      J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
 +Description:
 +              It shows the abolute path of a member directory (which
 +              is called branch) in aufs, and its permission.
 +
++What:         /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
++Date:         July 2013
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
++Description:
++              It shows the id of a member directory (which is called
++              branch) in aufs.
++
 +What:         /sys/fs/aufs/si_<id>/xi_path
 +Date:         March 2009
-+Contact:      J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact:      J. R. Okajima <hooanon05g@gmail.com>
 +Description:
 +              It shows the abolute path of XINO (External Inode Number
 +              Bitmap, Translation Table and Generation Table) file
@@ -462,10 +1000,10 @@ diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentat
 +              will be empty. About XINO files, see the aufs manual.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/01intro.txt    2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,162 @@
++++ linux/Documentation/filesystems/aufs/design/01intro.txt    2015-06-22 08:27:37.867501461 +0200
+@@ -0,0 +1,170 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -478,8 +1016,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt lin
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Introduction
 +----------------------------------------
@@ -495,7 +1032,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt lin
 +- multi layered stackable unification filesystem, the member directory
 +  is called as a branch.
 +- branch permission and attribute, 'readonly', 'real-readonly',
-+  'readwrite', 'whiteout-able', 'link-able whiteout' and their
++  'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
 +  combination.
 +- internal "file copy-on-write".
 +- logical deletion, whiteout.
@@ -546,11 +1083,16 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt lin
 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
 +  open(O_RDWR).
 +
-+Unionfs has a longer history. When I started implementing a stacking filesystem
-+(Aug 2005), it already existed. It has virtual super_block, inode,
-+dentry and file objects and they have an array pointing lower same kind
-+objects. After contributing many patches for Unionfs, I re-started my
-+project AUFS (Jun 2006).
++In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
++merged into mainline. This is another implementation of UnionMount as a
++separated filesystem. All the limitations and known problems which
++UnionMount are equally inherited to "overlay" filesystem.
++
++Unionfs has a longer history. When I started implementing a stackable
++filesystem (Aug 2005), it already existed. It has virtual super_block,
++inode, dentry and file objects and they have an array pointing lower
++same kind objects. After contributing many patches for Unionfs, I
++re-started my project AUFS (Jun 2006).
 +
 +In AUFS, the structure of filesystem resembles to Unionfs, but I
 +implemented my own ideas, approaches and enhancements and it became
@@ -572,11 +1114,14 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt lin
 +- DM snapshot-merge may help a lot when users try merging. in the
 +  fs-layer union, users will use rsync(1).
 +
++You may want to read my old paper "Filesystems in LiveCD"
++(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
++
 +
-+Several characters/aspects of aufs
++Several characters/aspects/persona of aufs
 +----------------------------------------------------------------------
 +
-+Aufs has several characters or aspects.
++Aufs has several characters, aspects or persona.
 +1. a filesystem, callee of VFS helper
 +2. sub-VFS, caller of VFS helper for branches
 +3. a virtual filesystem which maintains persistent inode number
@@ -607,10 +1152,11 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt lin
 +numbers. This is particularly important to support exporting a
 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
 +backend block device for its own. But some storage is necessary to
-+maintain inode number. It may be a large space and may not suit to keep
-+in memory. Aufs rents some space from its first writable branch
-+filesystem (by default) and creates file(s) on it. These files are
-+created by aufs internally and removed soon (currently) keeping opened.
++keep and maintain the inode numbers. It may be a large space and may not
++suit to keep in memory. Aufs rents some space from its first writable
++branch filesystem (by default) and creates file(s) on it. These files
++are created by aufs internally and removed soon (currently) keeping
++opened.
 +Note: Because these files are removed, they are totally gone after
 +      unmounting aufs. It means the inode numbers are not persistent
 +      across unmount or reboot. I have a plan to make them really
@@ -628,10 +1174,10 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt lin
 +about it. But currently I have implemented it in kernel space.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt        1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/02struct.txt   2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,226 @@
++++ linux/Documentation/filesystems/aufs/design/02struct.txt   2015-06-22 08:27:37.867501461 +0200
+@@ -0,0 +1,258 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -644,8 +1190,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Basic Aufs Internal Structure
 +
@@ -662,18 +1207,18 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +
 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
-+- [0] = NULL
++- [0] = NULL (because /rw/fileA doesn't exist)
 +- [1] = /ro/fileA
 +
 +This style of an array is essentially same to the aufs
 +superblock/inode/dentry/file objects.
 +
 +Because aufs supports manipulating branches, ie. add/delete/change
-+dynamically, these objects has its own generation. When branches are
-+changed, the generation in aufs superblock is incremented. And a
-+generation in other object are compared when it is accessed.
-+When a generation in other objects are obsoleted, aufs refreshes the
-+internal array.
++branches dynamically, these objects has its own generation. When
++branches are changed, the generation in aufs superblock is
++incremented. And a generation in other object are compared when it is
++accessed. When a generation in other objects are obsoleted, aufs
++refreshes the internal array.
 +
 +
 +Superblock
@@ -681,8 +1226,8 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +Additionally aufs superblock has some data for policies to select one
 +among multiple writable branches, XIB files, pseudo-links and kobject.
 +See below in detail.
-+About the policies which supports copy-down a directory, see policy.txt
-+too.
++About the policies which supports copy-down a directory, see
++wbr_policy.txt too.
 +
 +
 +Branch and XINO(External Inode Number Translation Table)
@@ -702,13 +1247,20 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +might appear. If your branch filesystem consumes disk space for such
 +holes, then you should specify 'xino=' option at mounting aufs.
 +
++Aufs has a mount option to free the disk blocks for such holes in XINO
++files on tmpfs or ramdisk. But it is not so effective actually. If you
++meet a problem of disk shortage due to XINO files, then you should try
++"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
++The patch localizes the assignment inumbers per tmpfs-mount and avoid
++the holes in XINO files.
++
 +Also a writable branch has three kinds of "whiteout bases". All these
-+are existed when the branch is joined to aufs and the names are
++are existed when the branch is joined to aufs, and their names are
 +whiteout-ed doubly, so that users will never see their names in aufs
 +hierarchy.
-+1. a regular file which will be linked to all whiteouts.
++1. a regular file which will be hardlinked to all whiteouts.
 +2. a directory to store a pseudo-link.
-+3. a directory to store an "orphan-ed" file temporary.
++3. a directory to store an "orphan"-ed file temporary.
 +
 +1. Whiteout Base
 +   When you remove a file on a readonly branch, aufs handles it as a
@@ -725,8 +1277,8 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +   creating a file under this dir, the file is unlinked.
 +
 +Because aufs supports manipulating branches, ie. add/delete/change
-+dynamically, a branch has its own id. When the branch order changes, aufs
-+finds the new index by searching the branch id.
++dynamically, a branch has its own id. When the branch order changes,
++aufs finds the new index by searching the branch id.
 +
 +
 +Pseudo-link
@@ -739,7 +1291,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +simple list. If fileB is read after unlinking fileA, aufs returns
 +filedata from the pseudo-link instead of the lower readonly
 +branch. Because the pseudo-link is based upon the inode, to keep the
-+inode number by xino (see above) is important.
++inode number by xino (see above) is essentially necessary.
 +
 +All the hardlinks under the Pseudo-link Directory of the writable branch
 +should be restored in a proper location later. Aufs provides a utility
@@ -757,12 +1309,13 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +XIB(external inode number bitmap)
 +----------------------------------------------------------------------
 +Addition to the xino file per a branch, aufs has an external inode number
-+bitmap in a superblock object. It is also a file such like a xino file.
++bitmap in a superblock object. It is also an internal file such like a
++xino file.
 +It is a simple bitmap to mark whether the aufs inode number is in-use or
 +not.
 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
 +
-+Aufs implements a feature to truncate/refresh both of xino and xib to
++As well as XINO files, aufs has a feature to truncate/refresh XIB to
 +reduce the number of consumed disk blocks for these files.
 +
 +
@@ -774,7 +1327,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +with eliminating the whiteout-ed ones, and sets it to file (dir)
 +object. So the file object has its entry list until it is closed. The
 +entry list will be updated when the file position is zero and becomes
-+old. This decision is made in aufs automatically.
++obsoleted. This decision is made in aufs automatically.
 +
 +The dynamically allocated memory block for the name of entries has a
 +unit of 512 bytes (by default) and stores the names contiguously (no
@@ -813,9 +1366,8 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +its completion. This approach solves a problem of a signal handler
 +simply.
 +If aufs didn't adopt the workqueue and changed the privilege of the
-+process, and if the mkdir/write call arises SIGXFSZ or other signal,
-+then the user process might gain a privilege or the generated core file
-+was owned by a superuser.
++process, then the process may receive the unexpected SIGXFSZ or other
++signals.
 +
 +Also aufs uses the system global workqueue ("events" kernel thread) too
 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
@@ -833,7 +1385,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +
 +Basically the whiteout represents "logical deletion" which stops aufs to
 +lookup further, but also it represents "dir is opaque" which also stop
-+lookup.
++further lookup.
 +
 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
 +In order to make several functions in a single systemcall to be
@@ -841,7 +1393,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +unique whiteouted name.
 +For example, in rename(2) dir where the target dir already existed, aufs
 +renames the target dir to a temporary unique whiteouted name before the
-+actual rename on a branch and then handles other actions (make it opaque,
++actual rename on a branch, and then handles other actions (make it opaque,
 +update the attributes, etc). If an error happens in these actions, aufs
 +simply renames the whiteouted name back and returns an error. If all are
 +succeeded, aufs registers a function to remove the whiteouted unique
@@ -856,12 +1408,127 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +internally and makes change to the new file on the upper writable branch.
 +When the trigger systemcall does not update the timestamps of the parent
 +dir, aufs reverts it after copy-up.
++
++
++Move-down (aufs3.9 and later)
++----------------------------------------------------------------------
++"Copy-up" is one of the essential feature in aufs. It copies a file from
++the lower readonly branch to the upper writable branch when a user
++changes something about the file.
++"Move-down" is an opposite action of copy-up. Basically this action is
++ran manually instead of automatically and internally.
++For desgin and implementation, aufs has to consider these issues.
++- whiteout for the file may exist on the lower branch.
++- ancestor directories may not exist on the lower branch.
++- diropq for the ancestor directories may exist on the upper branch.
++- free space on the lower branch will reduce.
++- another access to the file may happen during moving-down, including
++  UDBA (see "Revalidate Dentry and UDBA").
++- the file should not be hard-linked nor pseudo-linked. they should be
++  handled by auplink utility later.
++
++Sometimes users want to move-down a file from the upper writable branch
++to the lower readonly or writable branch. For instance,
++- the free space of the upper writable branch is going to run out.
++- create a new intermediate branch between the upper and lower branch.
++- etc.
++
++For this purpose, use "aumvdown" command in aufs-util.git.
+diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
+--- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt   1970-01-01 01:00:00.000000000 +0100
++++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt      2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,85 @@
++
++# Copyright (C) 2015 Junjiro R. Okajima
++# 
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 2 of the License, or
++# (at your option) any later version.
++# 
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++# 
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++Support for a branch who has its ->atomic_open()
++----------------------------------------------------------------------
++The filesystems who implement its ->atomic_open() are not majority. For
++example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
++particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
++->atomic_open(), NFSv4 returns an error for this open(2). While I am not
++sure whether all filesystems who have ->atomic_open() behave like this,
++but NFSv4 surely returns the error.
++
++In order to support ->atomic_open() for aufs, there are a few
++approaches.
++
++A. Introduce aufs_atomic_open()
++   - calls one of VFS:do_last(), lookup_open() or atomic_open() for
++     branch fs.
++B. Introduce aufs_atomic_open() calling create, open and chmod. this is
++   an aufs user Pip Cet's approach
++   - calls aufs_create(), VFS finish_open() and notify_change().
++   - pass fake-mode to finish_open(), and then correct the mode by
++     notify_change().
++C. Extend aufs_open() to call branch fs's ->atomic_open()
++   - no aufs_atomic_open().
++   - aufs_lookup() registers the TID to an aufs internal object.
++   - aufs_create() does nothing when the matching TID is registered, but
++     registers the mode.
++   - aufs_open() calls branch fs's ->atomic_open() when the matching
++     TID is registered.
++D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
++   credential
++   - no aufs_atomic_open().
++   - aufs_create() registers the TID to an internal object. this info
++     represents "this process created this file just now."
++   - when aufs gets EACCES from branch fs's ->open(), then confirm the
++     registered TID and re-try open() with superuser's credential.
++
++Pros and cons for each approach.
++
++A.
++   - straightforward but highly depends upon VFS internal.
++   - the atomic behavaiour is kept.
++   - some of parameters such as nameidata are hard to reproduce for
++     branch fs.
++   - large overhead.
++B.
++   - easy to implement.
++   - the atomic behavaiour is lost.
++C.
++   - the atomic behavaiour is kept.
++   - dirty and tricky.
++   - VFS checks whether the file is created correctly after calling
++     ->create(), which means this approach doesn't work.
++D.
++   - easy to implement.
++   - the atomic behavaiour is lost.
++   - to open a file with superuser's credential and give it to a user
++     process is a bad idea, since the file object keeps the credential
++     in it. It may affect LSM or something. This approach doesn't work
++     either.
++
++The approach A is ideal, but it hard to implement. So here is a
++variation of A, which is to be implemented.
++
++A-1. Introduce aufs_atomic_open()
++     - calls branch fs ->atomic_open() if exists. otherwise calls
++       vfs_create() and finish_open().
++     - the demerit is that the several checks after branch fs
++       ->atomic_open() are lost. in the ordinary case, the checks are
++       done by VFS:do_last(), lookup_open() and atomic_open(). some can
++       be implemented in aufs, but not all I am afraid.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt        1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/03lookup.txt   2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,106 @@
++++ linux/Documentation/filesystems/aufs/design/03lookup.txt   2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,113 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -874,44 +1541,51 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt li
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Lookup in a Branch
 +----------------------------------------------------------------------
 +Since aufs has a character of sub-VFS (see Introduction), it operates
-+lookup for branches as VFS does. It may be a heavy work. Generally
-+speaking struct nameidata is a bigger structure and includes many
-+information. But almost all lookup operation in aufs is the simplest
-+case, ie. lookup only an entry directly connected to its parent. Digging
-+down the directory hierarchy is unnecessary.
-+
-+VFS has a function lookup_one_len() for that use, but it is not usable
-+for a branch filesystem which requires struct nameidata. So aufs
-+implements a simple lookup wrapper function. When a branch filesystem
-+allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
-+a simplest nameidata and calls lookup_hash().
-+Here aufs applies "a principle in NFSD", ie. if the filesystem supports
-+NFS-export, then it has to support NULL as a nameidata parameter for
-+->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
-+aufs tests if ->s_export_op in the branch is NULL or not.
-+
-+When a branch is a remote filesystem, aufs basically trusts its
++lookup for branches as VFS does. It may be a heavy work. But almost all
++lookup operation in aufs is the simplest case, ie. lookup only an entry
++directly connected to its parent. Digging down the directory hierarchy
++is unnecessary. VFS has a function lookup_one_len() for that use, and
++aufs calls it.
++
++When a branch is a remote filesystem, aufs basically relies upon its
 +->d_revalidate(), also aufs forces the hardest revalidate tests for
 +them.
 +For d_revalidate, aufs implements three levels of revalidate tests. See
 +"Revalidate Dentry and UDBA" in detail.
 +
 +
-+Loopback Mount
++Test Only the Highest One for the Directory Permission (dirperm1 option)
 +----------------------------------------------------------------------
-+Basically aufs supports any type of filesystem and block device for a
-+branch (actually there are some exceptions). But it is prohibited to add
-+a loopback mounted one whose backend file exists in a filesystem which is
-+already added to aufs. The reason is to protect aufs from a recursive
-+lookup. If it was allowed, the aufs lookup operation might re-enter a
-+lookup for the loopback mounted branch in the same context, and will
-+cause a deadlock.
++Let's try case study.
++- aufs has two branches, upper readwrite and lower readonly.
++  /au = /rw + /ro
++- "dirA" exists under /ro, but /rw. and its mode is 0700.
++- user invoked "chmod a+rx /au/dirA"
++- the internal copy-up is activated and "/rw/dirA" is created and its
++  permission bits are set to world readable.
++- then "/au/dirA" becomes world readable?
++
++In this case, /ro/dirA is still 0700 since it exists in readonly branch,
++or it may be a natively readonly filesystem. If aufs respects the lower
++branch, it should not respond readdir request from other users. But user
++allowed it by chmod. Should really aufs rejects showing the entries
++under /ro/dirA?
++
++To be honest, I don't have a good solution for this case. So aufs
++implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
++users.
++When dirperm1 is specified, aufs checks only the highest one for the
++directory permission, and shows the entries. Otherwise, as usual, checks
++every dir existing on all branches and rejects the request.
++
++As a side effect, dirperm1 option improves the performance of aufs
++because the number of permission check is reduced when the number of
++branch is many.
 +
 +
 +Revalidate Dentry and UDBA (User's Direct Branch Access)
@@ -963,15 +1637,15 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt li
 +   itself.
 +3. No Extra Validation
 +   This is the simplest test and doesn't add any additional revalidation
-+   test, and skip therevalidatin in step 4. It is useful and improves
++   test, and skip the revalidation in step 4. It is useful and improves
 +   aufs performance when system surely hide the aufs branches from user,
 +   by over-mounting something (or another method).
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt        1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/04branch.txt   2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,76 @@
++++ linux/Documentation/filesystems/aufs/design/04branch.txt   2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,74 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -984,8 +1658,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt li
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Branch Manipulation
 +
@@ -996,8 +1669,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt li
 +Add a Branch
 +----------------------------------------------------------------------
 +o Confirm the adding dir exists outside of aufs, including loopback
-+  mount.
-+- and other various attributes...
++  mount, and its various attributes.
 +o Initialize the xino file and whiteout bases if necessary.
 +  See struct.txt.
 +
@@ -1012,7 +1684,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt li
 +  writable branch, and the writable branch is world-writable, then a
 +  malicious guy may create /etc/passwd on the writable branch directly
 +  and the infected file will be valid in aufs.
-+  I am afraid it can be a security issue, but nothing to do except
++  I am afraid it can be a security issue, but aufs can do nothing except
 +  producing a warning.
 +
 +
@@ -1048,10 +1720,10 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt li
 +    same named entry on the upper branch.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt    1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt       2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,65 @@
++++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt       2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,64 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -1064,8 +1736,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.tx
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Policies to Select One among Multiple Writable Branches
 +----------------------------------------------------------------------
@@ -1074,9 +1745,9 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.tx
 +writable branch which has the parent (or ancestor) dir of the target
 +file is chosen (top-down-parent policy).
 +By user's request, aufs implements some other policies to select the
-+writable branch, for file creation two policies, round-robin and
-+most-free-space policies. For copy-up three policies, top-down-parent,
-+bottom-up-parent and bottom-up policies.
++writable branch, for file creation several policies, round-robin,
++most-free-space, and other policies. For copy-up, top-down-parent,
++bottom-up-parent, bottom-up and others.
 +
 +As expected, the round-robin policy selects the branch in circular. When
 +you have two writable branches and creates 10 new files, 5 files will be
@@ -1115,12 +1786,12 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.tx
 +  where the source and the target exists and selects the higher
 +  one. If the selected branch is readonly, then aufs follows the
 +  copyup policy.
-diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
---- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt  1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/06mmap.txt     2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,47 @@
+diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
+--- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt  1970-01-01 01:00:00.000000000 +0100
++++ linux/Documentation/filesystems/aufs/design/06fhsm.txt     2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,120 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2011-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -1136,13 +1807,136 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linu
 +# along with this program; if not, write to the Free Software
 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 +
++
++File-based Hierarchical Storage Management (FHSM)
++----------------------------------------------------------------------
++Hierarchical Storage Management (or HSM) is a well-known feature in the
++storage world. Aufs provides this feature as file-based with multiple
++writable branches, based upon the principle of "Colder, the Lower".
++Here the word "colder" means that the less used files, and "lower" means
++that the position in the order of the stacked branches vertically.
++These multiple writable branches are prioritized, ie. the topmost one
++should be the fastest drive and be used heavily.
++
++o Characters in aufs FHSM story
++- aufs itself and a new branch attribute.
++- a new ioctl interface to move-down and to establish a connection with
++  the daemon ("move-down" is a converse of "copy-up").
++- userspace tool and daemon.
++
++The userspace daemon establishes a connection with aufs and waits for
++the notification. The notified information is very similar to struct
++statfs containing the number of consumed blocks and inodes.
++When the consumed blocks/inodes of a branch exceeds the user-specified
++upper watermark, the daemon activates its move-down process until the
++consumed blocks/inodes reaches the user-specified lower watermark.
++
++The actual move-down is done by aufs based upon the request from
++user-space since we need to maintain the inode number and the internal
++pointer arrays in aufs.
++
++Currently aufs FHSM handles the regular files only. Additionally they
++must not be hard-linked nor pseudo-linked.
++
++
++o Cowork of aufs and the user-space daemon
++  During the userspace daemon established the connection, aufs sends a
++  small notification to it whenever aufs writes something into the
++  writable branch. But it may cost high since aufs issues statfs(2)
++  internally. So user can specify a new option to cache the
++  info. Actually the notification is controlled by these factors.
++  + the specified cache time.
++  + classified as "force" by aufs internally.
++  Until the specified time expires, aufs doesn't send the info
++  except the forced cases. When aufs decide forcing, the info is always
++  notified to userspace.
++  For example, the number of free inodes is generally large enough and
++  the shortage of it happens rarely. So aufs doesn't force the
++  notification when creating a new file, directory and others. This is
++  the typical case which aufs doesn't force.
++  When aufs writes the actual filedata and the files consumes any of new
++  blocks, the aufs forces notifying.
++
++
++o Interfaces in aufs
++- New branch attribute.
++  + fhsm
++    Specifies that the branch is managed by FHSM feature. In other word,
++    participant in the FHSM.
++    When nofhsm is set to the branch, it will not be the source/target
++    branch of the move-down operation. This attribute is set
++    independently from coo and moo attributes, and if you want full
++    FHSM, you should specify them as well.
++- New mount option.
++  + fhsm_sec
++    Specifies a second to suppress many less important info to be
++    notified.
++- New ioctl.
++  + AUFS_CTL_FHSM_FD
++    create a new file descriptor which userspace can read the notification
++    (a subset of struct statfs) from aufs.
++- Module parameter 'brs'
++  It has to be set to 1. Otherwise the new mount option 'fhsm' will not
++  be set.
++- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
++  When there are two or more branches with fhsm attributes,
++  /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
++  terminates it. As a result of remounting and branch-manipulation, the
++  number of branches with fhsm attribute can be one. In this case,
++  /sbin/mount.aufs will terminate the user-space daemon.
++
++
++Finally the operation is done as these steps in kernel-space.
++- make sure that,
++  + no one else is using the file.
++  + the file is not hard-linked.
++  + the file is not pseudo-linked.
++  + the file is a regular file.
++  + the parent dir is not opaqued.
++- find the target writable branch.
++- make sure the file is not whiteout-ed by the upper (than the target)
++  branch.
++- make the parent dir on the target branch.
++- mutex lock the inode on the branch.
++- unlink the whiteout on the target branch (if exists).
++- lookup and create the whiteout-ed temporary name on the target branch.
++- copy the file as the whiteout-ed temporary name on the target branch.
++- rename the whiteout-ed temporary name to the original name.
++- unlink the file on the source branch.
++- maintain the internal pointer array and the external inode number
++  table (XINO).
++- maintain the timestamps and other attributes of the parent dir and the
++  file.
++
++And of course, in every step, an error may happen. So the operation
++should restore the original file state after an error happens.
+diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
+--- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt  1970-01-01 01:00:00.000000000 +0100
++++ linux/Documentation/filesystems/aufs/design/06mmap.txt     2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,72 @@
++
++# Copyright (C) 2005-2015 Junjiro R. Okajima
++# 
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 2 of the License, or
++# (at your option) any later version.
++# 
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++# 
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
 +mmap(2) -- File Memory Mapping
 +----------------------------------------------------------------------
 +In aufs, the file-mapped pages are handled by a branch fs directly, no
 +interaction with aufs. It means aufs_mmap() calls the branch fs's
 +->mmap().
 +This approach is simple and good, but there is one problem.
-+Under /proc, several entries show the mmap-ped files by its path (with
++Under /proc, several entries show the mmapped files by its path (with
 +device and inode number), and the printed path will be the path on the
 +branch fs's instead of virtual aufs's.
 +This is not a problem in most cases, but some utilities lsof(1) (and its
@@ -1159,19 +1953,145 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linu
 +  incremented.
 +- merging vma maintains the ref count too.
 +
-+This is not a good approach. It just faking the printed path. But it
++This is not a good approach. It just fakes the printed path. But it
 +leaves all behaviour around f_mapping unchanged. This is surely an
 +advantage.
 +Actually aufs had adopted another complicated approach which calls
 +generic_file_mmap() and handles struct vm_operations_struct. In this
 +approach, aufs met a hard problem and I could not solve it without
 +switching the approach.
++
++There may be one more another approach which is
++- bind-mount the branch-root onto the aufs-root internally
++- grab the new vfsmount (ie. struct mount)
++- lazy-umount the branch-root internally
++- in open(2) the aufs-file, open the branch-file with the hidden
++  vfsmount (instead of the original branch's vfsmount)
++- ideally this "bind-mount and lazy-umount" should be done atomically,
++  but it may be possible from userspace by the mount helper.
++
++Adding the internal hidden vfsmount and using it in opening a file, the
++file path under /proc will be printed correctly. This approach looks
++smarter, but is not possible I am afraid.
++- aufs-root may be bind-mount later. when it happens, another hidden
++  vfsmount will be required.
++- it is hard to get the chance to bind-mount and lazy-umount
++  + in kernel-space, FS can have vfsmount in open(2) via
++    file->f_path, and aufs can know its vfsmount. But several locks are
++    already acquired, and if aufs tries to bind-mount and lazy-umount
++    here, then it may cause a deadlock.
++  + in user-space, bind-mount doesn't invoke the mount helper.
++- since /proc shows dev and ino, aufs has to give vma these info. it
++  means a new member vm_prinode will be necessary. this is essentially
++  equivalent to vm_prfile described above.
++
++I have to give up this "looks-smater" approach.
+diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
+--- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
++++ linux/Documentation/filesystems/aufs/design/06xattr.txt    2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,96 @@
++
++# Copyright (C) 2014-2015 Junjiro R. Okajima
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 2 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++
++
++Listing XATTR/EA and getting the value
++----------------------------------------------------------------------
++For the inode standard attributes (owner, group, timestamps, etc.), aufs
++shows the values from the topmost existing file. This behaviour is good
++for the non-dir entries since the bahaviour exactly matches the shown
++information. But for the directories, aufs considers all the same named
++entries on the lower branches. Which means, if one of the lower entry
++rejects readdir call, then aufs returns an error even if the topmost
++entry allows it. This behaviour is necessary to respect the branch fs's
++security, but can make users confused since the user-visible standard
++attributes don't match the behaviour.
++To address this issue, aufs has a mount option called dirperm1 which
++checks the permission for the topmost entry only, and ignores the lower
++entry's permission.
++
++A similar issue can happen around XATTR.
++getxattr(2) and listxattr(2) families behave as if dirperm1 option is
++always set. Otherwise these very unpleasant situation would happen.
++- listxattr(2) may return the duplicated entries.
++- users may not be able to remove or reset the XATTR forever,
++
++
++XATTR/EA support in the internal (copy,move)-(up,down)
++----------------------------------------------------------------------
++Generally the extended attributes of inode are categorized as these.
++- "security" for LSM and capability.
++- "system" for posix ACL, 'acl' mount option is required for the branch
++  fs generally.
++- "trusted" for userspace, CAP_SYS_ADMIN is required.
++- "user" for userspace, 'user_xattr' mount option is required for the
++  branch fs generally.
++
++Moreover there are some other categories. Aufs handles these rather
++unpopular categories as the ordinary ones, ie. there is no special
++condition nor exception.
++
++In copy-up, the support for XATTR on the dst branch may differ from the
++src branch. In this case, the copy-up operation will get an error and
++the original user operation which triggered the copy-up will fail. It
++can happen that even all copy-up will fail.
++When both of src and dst branches support XATTR and if an error occurs
++during copying XATTR, then the copy-up should fail obviously. That is a
++good reason and aufs should return an error to userspace. But when only
++the src branch support that XATTR, aufs should not return an error.
++For example, the src branch supports ACL but the dst branch doesn't
++because the dst branch may natively un-support it or temporary
++un-support it due to "noacl" mount option. Of course, the dst branch fs
++may NOT return an error even if the XATTR is not supported. It is
++totally up to the branch fs.
++
++Anyway when the aufs internal copy-up gets an error from the dst branch
++fs, then aufs tries removing the just copied entry and returns the error
++to the userspace. The worst case of this situation will be all copy-up
++will fail.
++
++For the copy-up operation, there two basic approaches.
++- copy the specified XATTR only (by category above), and return the
++  error unconditionally if it happens.
++- copy all XATTR, and ignore the error on the specified category only.
++
++In order to support XATTR and to implement the correct behaviour, aufs
++chooses the latter approach and introduces some new branch attributes,
++"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
++They correspond to the XATTR namespaces (see above). Additionally, to be
++convenient, "icex" is also provided which means all "icex*" attributes
++are set (here the word "icex" stands for "ignore copy-error on XATTR").
++
++The meaning of these attributes is to ignore the error from setting
++XATTR on that branch.
++Note that aufs tries copying all XATTR unconditionally, and ignores the
++error from the dst branch according to the specified attributes.
++
++Some XATTR may have its default value. The default value may come from
++the parent dir or the environment. If the default value is set at the
++file creating-time, it will be overwritten by copy-up.
++Some contradiction may happen I am afraid.
++Do we need another attribute to stop copying XATTR? I am unsure. For
++now, aufs implements the branch attributes to ignore the error.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt        1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/07export.txt   2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,59 @@
++++ linux/Documentation/filesystems/aufs/design/07export.txt   2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,58 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -1184,8 +2104,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt li
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Export Aufs via NFS
 +----------------------------------------------------------------------
@@ -1211,10 +2130,10 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt li
 +  + find the index of a branch from its id in handle, and check it is
 +    still exist in aufs.
 +  + 1st level: get the inode number from handle and search it in cache.
-+  + 2nd level: if not found, get the parent inode number from handle and
-+    search it in cache. and then open the parent dir, find the matching
-+    inode number by vfs_readdir() and get its name, and call
-+    lookup_one_len() for the target dentry.
++  + 2nd level: if not found in cache, get the parent inode number from
++    the handle and search it in cache. and then open the found parent
++    dir, find the matching inode number by vfs_readdir() and get its
++    name, and call lookup_one_len() for the target dentry.
 +  + 3rd level: if the parent dir is not cached, call
 +    exportfs_decode_fh() for a branch and get the parent on a branch,
 +    build a pathname of it, convert it a pathname in aufs, call
@@ -1231,10 +2150,10 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt li
 +  lookup_one_len(), vfs_getattr(), encode_fh() and others.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt  1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/08shwh.txt     2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,53 @@
++++ linux/Documentation/filesystems/aufs/design/08shwh.txt     2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,52 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -1247,8 +2166,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linu
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Show Whiteout Mode (shwh)
 +----------------------------------------------------------------------
@@ -1288,10 +2206,10 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linu
 +initramfs will use it to replace the old one at the next boot.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/10dynop.txt    2013-02-19 08:40:03.943559493 +0100
++++ linux/Documentation/filesystems/aufs/design/10dynop.txt    2015-06-22 08:27:37.870834875 +0200
 @@ -0,0 +1,47 @@
 +
-+# Copyright (C) 2010-2013 Junjiro R. Okajima
++# Copyright (C) 2010-2015 Junjiro R. Okajima
 +#
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -1304,8 +2222,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt lin
 +# GNU General Public License for more details.
 +#
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Dynamically customizable FS operations
 +----------------------------------------------------------------------
@@ -1315,34 +2232,35 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt lin
 +operation. Some FS have multiple sets of them. For instance, ext2 has
 +three sets, one for XIP, for NOBH, and for normal.
 +Since aufs overrides and redirects these operations, sometimes aufs has
-+to change its behaviour according to the branch FS type. More imporantly
++to change its behaviour according to the branch FS type. More importantly
 +VFS acts differently if a function (member in the struct) is set or
 +not. It means aufs should have several sets of operations and select one
 +among them according to the branch FS definition.
 +
-+In order to solve this problem and not to affect the behavour of VFS,
++In order to solve this problem and not to affect the behaviour of VFS,
 +aufs defines these operations dynamically. For instance, aufs defines
-+aio_read function for struct file_operations, but it may not be set to
-+the file_operations. When the branch FS doesn't have it, aufs doesn't
-+set it to its file_operations while the function definition itself is
-+still alive. So the behaviour of io_submit(2) will not change, and it
-+will return an error when aio_read is not defined.
++dummy direct_IO function for struct address_space_operations, but it may
++not be set to the address_space_operations actually. When the branch FS
++doesn't have it, aufs doesn't set it to its address_space_operations
++while the function definition itself is still alive. So the behaviour
++itself will not change, and it will return an error when direct_IO is
++not set.
 +
 +The lifetime of these dynamically generated operation object is
 +maintained by aufs branch object. When the branch is removed from aufs,
 +the reference counter of the object is decremented. When it reaches
 +zero, the dynamically generated operation object will be freed.
 +
-+This approach is designed to support AIO (io_submit), Direcit I/O and
-+XIP mainly.
-+Currently this approach is applied to file_operations and
-+vm_operations_struct for regular files only.
++This approach is designed to support AIO (io_submit), Direct I/O and
++XIP (DAX) mainly.
++Currently this approach is applied to address_space_operations for
++regular files only.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt  1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/99plan.txt     2013-02-19 08:40:03.943559493 +0100
-@@ -0,0 +1,96 @@
++++ linux/Documentation/filesystems/aufs/design/99plan.txt     2015-06-22 08:27:37.870834875 +0200
+@@ -0,0 +1,57 @@
 +
-+# Copyright (C) 2005-2013 Junjiro R. Okajima
++# Copyright (C) 2005-2015 Junjiro R. Okajima
 +# 
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -1355,8 +2273,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linu
 +# GNU General Public License for more details.
 +# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +Plan
 +
@@ -1365,53 +2282,16 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linu
 +easier to be reviewed.
 +
 +
-+Test Only the Highest One for the Directory Permission (dirperm1 option)
-+----------------------------------------------------------------------
-+Let's try case study.
-+- aufs has two branches, upper readwrite and lower readonly.
-+  /au = /rw + /ro
-+- "dirA" exists under /ro, but /rw. and its mode is 0700.
-+- user invoked "chmod a+rx /au/dirA"
-+- then "dirA" becomes world readable?
-+
-+In this case, /ro/dirA is still 0700 since it exists in readonly branch,
-+or it may be a natively readonly filesystem. If aufs respects the lower
-+branch, it should not respond readdir request from other users. But user
-+allowed it by chmod. Should really aufs rejects showing the entries
-+under /ro/dirA?
-+
-+To be honest, I don't have a best solution for this case. So I
-+implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
-+users.
-+When dirperm1 is specified, aufs checks only the highest one for the
-+directory permission, and shows the entries. Otherwise, as usual, checks
-+every dir existing on all branches and rejects the request.
-+
-+As a side effect, dirperm1 option improves the performance of aufs
-+because the number of permission check is reduced.
-+
-+
 +Being Another Aufs's Readonly Branch (robr)
 +----------------------------------------------------------------------
 +Aufs1 allows aufs to be another aufs's readonly branch.
 +This feature was developed by a user's request. But it may not be used
-+currecnly.
++currently.
 +
 +
-+Copy-up on Open (coo=)
++Refresh the Opened File (refrof)
 +----------------------------------------------------------------------
-+By default the internal copy-up is executed when it is really necessary.
-+It is not done when a file is opened for writing, but when write(2) is
-+done. Users who have many (over 100) branches want to know and analyse
-+when and what file is copied-up. To insert a new upper branch which
-+contains such files only may improve the performance of aufs.
-+
-+Aufs1 implemented "coo=none | leaf | all" option.
-+
-+
-+Refresh the Opened File (refrof)
-+----------------------------------------------------------------------
-+This option is implemented in aufs1 but incomplete.
++This option is implemented in aufs1 but incomplete.
 +
 +When user reads from a file, he expects to get its latest filedata
 +generally. If the file is removed and a new same named file is created,
@@ -1424,7 +2304,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linu
 +- user opened "/au/fileA".
 +- he or someone else inserts a branch (/new) between /rw and /ro.
 +  /au = /rw + /new + /ro
-+- the new branch has "fileA".
++- the new branch contains "fileA".
 +- user reads from the opened "fileA"
 +- which filedata should aufs return, from /ro or /new?
 +
@@ -1435,12 +2315,11 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linu
 +Here again I don't have a best and final answer. I got an idea to
 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
 +Opened File) is specified (by default), aufs returns the filedata from
-+/new.
-+Otherwise from /new.
++/new. Otherwise from /ro.
 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
 --- /usr/share/empty/Documentation/filesystems/aufs/README     1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/README        2013-03-14 20:07:40.574775374 +0100
-@@ -0,0 +1,333 @@
++++ linux/Documentation/filesystems/aufs/README        2015-06-22 08:27:37.867501461 +0200
+@@ -0,0 +1,384 @@
 +
 +Aufs3 -- advanced multi layered unification filesystem version 3.x
 +http://aufs.sf.net
@@ -1450,7 +2329,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +0. Introduction
 +----------------------------------------
 +In the early days, aufs was entirely re-designed and re-implemented
-+Unionfs Version 1.x series. After many original ideas, approaches,
++Unionfs Version 1.x series. Adding many original ideas, approaches,
 +improvements and implementations, it becomes totally different from
 +Unionfs while keeping the basic features.
 +Recently, Unionfs Version 2.x series begin taking some of the same
@@ -1463,10 +2342,16 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
 +
 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
-+According to Christoph Hellwig, linux rejects all union-type filesystems
-+but UnionMount.
++      According to Christoph Hellwig, linux rejects all union-type
++      filesystems but UnionMount.
 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
 +
++PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
++    UnionMount, and he pointed out an issue around a directory mutex
++    lock and aufs addressed it. But it is still unsure whether aufs will
++    be merged (or any other union solution).
++<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
++
 +
 +1. Features
 +----------------------------------------
@@ -1479,7 +2364,12 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +- dynamic branch manipulation, add, del.
 +- etc...
 +
-+Also there are many enhancements in aufs1, such as:
++Also there are many enhancements in aufs, such as:
++- test only the highest one for the directory permission (dirperm1)
++- copyup on open (coo=)
++- 'move' policy for copy-up between two writable branches, after
++  checking free space.
++- xattr, acl
 +- readdir(3) in userspace.
 +- keep inode number by external inode number table
 +- keep the timestamps of file/dir in internal copyup operation
@@ -1511,28 +2401,18 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +
 +Currently these features are dropped temporary from aufs3.
 +See design/08plan.txt in detail.
-+- test only the highest one for the directory permission (dirperm1)
-+- copyup on open (coo=)
 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
 +  (robr)
 +- statistics of aufs thread (/sys/fs/aufs/stat)
-+- delegation mode (dlgt)
-+  a delegation of the internal branch access to support task I/O
-+  accounting, which also supports Linux Security Modules (LSM) mainly
-+  for Suse AppArmor.
-+- intent.open/create (file open in a single lookup)
 +
 +Features or just an idea in the future (see also design/*.txt),
 +- reorder the branch index without del/re-add.
 +- permanent xino files for NFSD
 +- an option for refreshing the opened files after add/del branches
-+- 'move' policy for copy-up between two writable branches, after
-+  checking free space.
 +- light version, without branch manipulation. (unnecessary?)
 +- copyup in userspace
 +- inotify in userspace
 +- readv/writev
-+- xattr, acl
 +
 +
 +2. Download
@@ -1547,9 +2427,13 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +git://git.kernel.org/.../torvalds/linux.git.
 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
 +build aufs3 as an external kernel module.
++Several extra patches are not included in this tree. Only
++aufs3-standalong tree contains them. They are describe in the later
++section "Configuration and Compilation."
 +
 +On the other hand, the aufs3-standalone tree has only aufs source files
 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
++But you need to apply all aufs patches manually.
 +
 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
 +represents the linux kernel version, "linux-3.x". For instance,
@@ -1558,20 +2442,34 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +
 +o aufs3-linux tree
 +$ git clone --reference /your/linux/git/tree \
-+      git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-linux.git \
-+      aufs3-linux.git
++      git://git.code.sf.net/p/aufs/aufs3-linux aufs3-linux.git
 +- if you don't have linux GIT tree, then remove "--reference ..."
 +$ cd aufs3-linux.git
 +$ git checkout origin/aufs3.0
 +
++Or You may want to directly git-pull aufs into your linux GIT tree, and
++leave the patch-work to GIT.
++$ cd /your/linux/git/tree
++$ git remote add aufs3 https://github.com/sfjro/aufs3-linux.git
++- aufs3-linux.git tree also exists on github.
++$ git fetch aufs3
++$ git checkout -b my3.14 v3.14
++$ (add your change...)
++$ git pull aufs3 aufs3.14
++- now you have v3.14 + your_changes + aufs3.14 in you my3.14 branch.
++- you may need to solve some conflicts between your_changes and
++  aufs3.14. in this case, git-rerere is recommended so that you can
++  solve the similar confilicts automatically when you upgrade to 3.15 or
++  later in the future.
++
 +o aufs3-standalone tree
-+$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git \
++$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
 +      aufs3-standalone.git
 +$ cd aufs3-standalone.git
 +$ git checkout origin/aufs3.0
 +
 +o aufs-util tree
-+$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git \
++$ git clone git://git.code.sf.net/p/aufs/aufs-util \
 +      aufs-util.git
 +$ cd aufs-util.git
 +$ git checkout origin/aufs3.0
@@ -1602,7 +2500,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +Make sure you have git-checkout'ed the correct branch.
 +
 +For aufs3-linux tree,
-+- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS.
++- enable CONFIG_AUFS_FS.
 +- set other aufs configurations if necessary.
 +
 +For aufs3-standalone tree,
@@ -1611,17 +2509,18 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +1.
 +- apply ./aufs3-kbuild.patch to your kernel source files.
 +- apply ./aufs3-base.patch too.
-+- apply ./aufs3-proc_map.patch too, if you want to make /proc/PID/maps (and
-+  others including lsof(1)) show the file path on aufs instead of the
-+  path on the branch fs.
++- apply ./aufs3-mmap.patch too.
 +- apply ./aufs3-standalone.patch too, if you have a plan to set
 +  CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
 +  kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
-+- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS, you can select either
++- enable CONFIG_AUFS_FS, you can select either
 +  =m or =y.
 +- and build your kernel as usual.
 +- install the built kernel.
++  Note: Since linux-3.9, every filesystem module requires an alias
++  "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
++  modules.aliases file if you set CONFIG_AUFS_FS=m.
 +- install the header files too by "make headers_install" to the
 +  directory where you specify. By default, it is $PWD/usr.
 +  "make help" shows a brief note for headers_install.
@@ -1630,15 +2529,16 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +2.
 +- module only (CONFIG_AUFS_FS=m).
 +- apply ./aufs3-base.patch to your kernel source files.
-+- apply ./aufs3-proc_map.patch too to your kernel source files,
-+  if you want to make /proc/PID/maps (and others including lsof(1)) show
-+  the file path on aufs instead of the path on the branch fs.
++- apply ./aufs3-mmap.patch too.
 +- apply ./aufs3-standalone.patch too.
 +- build your kernel, don't forget "make headers_install", and reboot.
 +- edit ./config.mk and set other aufs configurations if necessary.
 +  Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
 +  every aufs configurations.
 +- build the module by simple "make".
++  Note: Since linux-3.9, every filesystem module requires an alias
++  "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
++  modules.aliases file.
 +- you can specify ${KDIR} make variable which points to your kernel
 +  source tree.
 +- install the files
@@ -1669,6 +2569,23 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +  then run "make install_ulib" too. And refer to the aufs manual in
 +  detail.
 +
++There several other patches in aufs3-standalone.git. They are all
++optional. When you meet some problems, they will help you.
++- aufs3-loopback.patch
++  Supports a nested loopback mount in a branch-fs. This patch is
++  unnecessary until aufs produces a message like "you may want to try
++  another patch for loopback file".
++- vfs-ino.patch
++  Modifies a system global kernel internal function get_next_ino() in
++  order to stop assigning 0 for an inode-number. Not directly related to
++  aufs, but recommended generally.
++- tmpfs-idr.patch
++  Keeps the tmpfs inode number as the lowest value. Effective to reduce
++  the size of aufs XINO files for tmpfs branch. Also it prevents the
++  duplication of inode number, which is important for backup tools and
++  other utilities. When you find aufs XINO files for tmpfs branch
++  growing too much, try this patch.
++
 +
 +4. Usage
 +----------------------------------------
@@ -1757,6 +2674,19 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
 +11).
 +Sam Liddicott made a donation (2011/9).
++Era Scarecrow made a donation (2013/4).
++Bor Ratajc made a donation (2013/4).
++Alessandro Gorreta made a donation (2013/4).
++POIRETTE Marc made a donation (2013/4).
++Alessandro Gorreta made a donation (2013/4).
++lauri kasvandik made a donation (2013/5).
++"pemasu from Finland" made a donation (2013/7).
++The Parted Magic Project made a donation (2013/9 and 11).
++Pavel Barta made a donation (2013/10).
++Nikolay Pertsev made a donation (2014/5).
++James B made a donation (2014/7).
++Stefano Di Biase made a donation (2014/8).
++Daniel Epellei made a donation (2015/1).
 +
 +Thank you very much.
 +Donations are always, including future donations, very important and
@@ -1776,10 +2706,10 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +# End: ;
 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
 --- /usr/share/empty/fs/aufs/aufs.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/aufs.h       2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,60 @@
++++ linux/fs/aufs/aufs.h       2015-06-22 08:27:37.874168290 +0200
+@@ -0,0 +1,59 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -1792,8 +2722,7 @@ diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -1840,10 +2769,10 @@ diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
 +#endif /* __AUFS_H__ */
 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 --- /usr/share/empty/fs/aufs/branch.c  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/branch.c     2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,1172 @@
++++ linux/fs/aufs/branch.c     2015-06-22 08:29:23.703424266 +0200
+@@ -0,0 +1,1406 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -1856,8 +2785,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -1893,6 +2821,11 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              AuRwDestroy(&wbr->wbr_wh_rwsem);
 +      }
 +
++      if (br->br_fhsm) {
++              au_br_fhsm_fin(br->br_fhsm);
++              kfree(br->br_fhsm);
++      }
++
 +      key = br->br_dykey;
 +      for (i = 0; i < AuBrDynOp; i++, key++)
 +              if (*key)
@@ -1902,7 +2835,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +
 +      /* recursive lock, s_umount of branch's */
 +      lockdep_off();
-+      mntput(br->br_mnt);
++      path_put(&br->br_path);
 +      lockdep_on();
 +      kfree(wbr);
 +      kfree(br);
@@ -1986,6 +2919,13 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +                      goto out_hnotify;
 +      }
 +
++      add_branch->br_fhsm = NULL;
++      if (au_br_fhsm(perm)) {
++              err = au_fhsm_br_alloc(add_branch);
++              if (unlikely(err))
++                      goto out_wbr;
++      }
++
 +      err = au_sbr_realloc(au_sbi(sb), new_nbranch);
 +      if (!err)
 +              err = au_di_realloc(au_di(root), new_nbranch);
@@ -1994,8 +2934,8 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      if (!err)
 +              return add_branch; /* success */
 +
++out_wbr:
 +      kfree(add_branch->br_wbr);
-+
 +out_hnotify:
 +      au_hnotify_fin_br(add_branch);
 +out_br:
@@ -2079,6 +3019,12 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              goto out;
 +      }
 +
++      if (unlikely(inode->i_sb->s_stack_depth)) {
++              pr_err("already stacked, %s (%s)\n",
++                     add->pathname, au_sbtype(inode->i_sb));
++              goto out;
++      }
++
 +      err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
 +      if (unlikely(err))
 +              goto out;
@@ -2116,7 +3062,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 + * initialize or clean the whiteouts for an adding branch
 + */
 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
-+                       int new_perm, struct dentry *h_root)
++                       int new_perm)
 +{
 +      int err, old_perm;
 +      aufs_bindex_t bindex;
@@ -2124,6 +3070,10 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      struct au_wbr *wbr;
 +      struct au_hinode *hdir;
 +
++      err = vfsub_mnt_want_write(au_br_mnt(br));
++      if (unlikely(err))
++              goto out;
++
 +      wbr = br->br_wbr;
 +      old_perm = br->br_perm;
 +      br->br_perm = new_perm;
@@ -2134,20 +3084,21 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              hdir = au_hi(sb->s_root->d_inode, bindex);
 +              au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
 +      } else {
-+              h_mtx = &h_root->d_inode->i_mutex;
++              h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
 +              mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
 +      }
 +      if (!wbr)
-+              err = au_wh_init(h_root, br, sb);
++              err = au_wh_init(br, sb);
 +      else {
 +              wbr_wh_write_lock(wbr);
-+              err = au_wh_init(h_root, br, sb);
++              err = au_wh_init(br, sb);
 +              wbr_wh_write_unlock(wbr);
 +      }
 +      if (hdir)
 +              au_hn_imtx_unlock(hdir);
 +      else
 +              mutex_unlock(h_mtx);
++      vfsub_mnt_drop_write(au_br_mnt(br));
 +      br->br_perm = old_perm;
 +
 +      if (!err && wbr && !au_br_writable(new_perm)) {
@@ -2155,16 +3106,16 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              br->br_wbr = NULL;
 +      }
 +
++out:
 +      return err;
 +}
 +
 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
-+                     int perm, struct path *path)
++                     int perm)
 +{
 +      int err;
 +      struct kstatfs kst;
 +      struct au_wbr *wbr;
-+      struct dentry *h_dentry;
 +
 +      wbr = br->br_wbr;
 +      au_rw_init(&wbr->wbr_wh_rwsem);
@@ -2174,25 +3125,24 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +
 +      /*
 +       * a limit for rmdir/rename a dir
-+       * cf. AUFS_MAX_NAMELEN in include/linux/aufs_type.h
++       * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
 +       */
-+      err = vfs_statfs(path, &kst);
++      err = vfs_statfs(&br->br_path, &kst);
 +      if (unlikely(err))
 +              goto out;
 +      err = -EINVAL;
-+      h_dentry = path->dentry;
 +      if (kst.f_namelen >= NAME_MAX)
-+              err = au_br_init_wh(sb, br, perm, h_dentry);
++              err = au_br_init_wh(sb, br, perm);
 +      else
-+              pr_err("%.*s(%s), unsupported namelen %ld\n",
-+                     AuDLNPair(h_dentry), au_sbtype(h_dentry->d_sb),
-+                     kst.f_namelen);
++              pr_err("%pd(%s), unsupported namelen %ld\n",
++                     au_br_dentry(br),
++                     au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
 +
 +out:
 +      return err;
 +}
 +
-+/* intialize a new branch */
++/* initialize a new branch */
 +static int au_br_init(struct au_branch *br, struct super_block *sb,
 +                    struct au_opt_add *add)
 +{
@@ -2202,17 +3152,16 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      memset(&br->br_xino, 0, sizeof(br->br_xino));
 +      mutex_init(&br->br_xino.xi_nondir_mtx);
 +      br->br_perm = add->perm;
-+      br->br_mnt = add->path.mnt; /* set first, mntget() later */
++      br->br_path = add->path; /* set first, path_get() later */
 +      spin_lock_init(&br->br_dykey_lock);
 +      memset(br->br_dykey, 0, sizeof(br->br_dykey));
 +      atomic_set(&br->br_count, 0);
-+      br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
 +      atomic_set(&br->br_xino_running, 0);
 +      br->br_id = au_new_br_id(sb);
 +      AuDebugOn(br->br_id < 0);
 +
 +      if (au_br_writable(add->perm)) {
-+              err = au_wbr_init(br, sb, add->perm, &add->path);
++              err = au_wbr_init(br, sb, add->perm);
 +              if (unlikely(err))
 +                      goto out_err;
 +      }
@@ -2227,11 +3176,11 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      }
 +
 +      sysaufs_br_init(br);
-+      mntget(add->path.mnt);
++      path_get(&br->br_path);
 +      goto out; /* success */
 +
 +out_err:
-+      br->br_mnt = NULL;
++      memset(&br->br_path, 0, sizeof(br->br_path));
 +out:
 +      return err;
 +}
@@ -2283,10 +3232,10 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              iinfo->ii_bstart = 0;
 +}
 +
-+static void au_br_do_add(struct super_block *sb, struct dentry *h_dentry,
-+                       struct au_branch *br, aufs_bindex_t bindex)
++static void au_br_do_add(struct super_block *sb, struct au_branch *br,
++                       aufs_bindex_t bindex)
 +{
-+      struct dentry *root;
++      struct dentry *root, *h_dentry;
 +      struct inode *root_inode;
 +      aufs_bindex_t bend, amount;
 +
@@ -2294,6 +3243,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      root_inode = root->d_inode;
 +      bend = au_sbend(sb);
 +      amount = bend + 1 - bindex;
++      h_dentry = au_br_dentry(br);
 +      au_sbilist_lock();
 +      au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
 +      au_br_do_add_hdp(au_di(root), bindex, bend, amount);
@@ -2336,15 +3286,15 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      }
 +
 +      add_bindex = add->bindex;
-+      h_dentry = add->path.dentry;
 +      if (!remount)
-+              au_br_do_add(sb, h_dentry, add_branch, add_bindex);
++              au_br_do_add(sb, add_branch, add_bindex);
 +      else {
 +              sysaufs_brs_del(sb, add_bindex);
-+              au_br_do_add(sb, h_dentry, add_branch, add_bindex);
++              au_br_do_add(sb, add_branch, add_bindex);
 +              sysaufs_brs_add(sb, add_bindex);
 +      }
 +
++      h_dentry = add->path.dentry;
 +      if (!add_bindex) {
 +              au_cpup_attr_all(root_inode, /*force*/1);
 +              sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
@@ -2360,7 +3310,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +          && au_br_writable(add_branch->br_perm)
 +          && !au_test_fs_bad_xino(h_dentry->d_sb)
 +          && add_branch->br_xino.xi_file
-+          && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
++          && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
 +              au_xino_brid_set(sb, add_branch->br_id);
 +
 +out:
@@ -2369,6 +3319,54 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +
 +/* ---------------------------------------------------------------------- */
 +
++static unsigned long long au_farray_cb(void *a,
++                                     unsigned long long max __maybe_unused,
++                                     void *arg)
++{
++      unsigned long long n;
++      struct file **p, *f;
++      struct au_sphlhead *files;
++      struct au_finfo *finfo;
++      struct super_block *sb = arg;
++
++      n = 0;
++      p = a;
++      files = &au_sbi(sb)->si_files;
++      spin_lock(&files->spin);
++      hlist_for_each_entry(finfo, &files->head, fi_hlist) {
++              f = finfo->fi_file;
++              if (file_count(f)
++                  && !special_file(file_inode(f)->i_mode)) {
++                      get_file(f);
++                      *p++ = f;
++                      n++;
++                      AuDebugOn(n > max);
++              }
++      }
++      spin_unlock(&files->spin);
++
++      return n;
++}
++
++static struct file **au_farray_alloc(struct super_block *sb,
++                                   unsigned long long *max)
++{
++      *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
++      return au_array_alloc(max, au_farray_cb, sb);
++}
++
++static void au_farray_free(struct file **a, unsigned long long max)
++{
++      unsigned long long ull;
++
++      for (ull = 0; ull < max; ull++)
++              if (a[ull])
++                      fput(a[ull]);
++      au_array_free(a);
++}
++
++/* ---------------------------------------------------------------------- */
++
 +/*
 + * delete a branch
 + */
@@ -2415,7 +3413,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              ndentry = dpage->ndentry;
 +              for (j = 0; !err && j < ndentry; j++) {
 +                      d = dpage->dentries[j];
-+                      AuDebugOn(!d->d_count);
++                      AuDebugOn(au_dcount(d) <= 0);
 +                      if (!au_digen_test(d, sigen)) {
 +                              di_read_lock_child(d, AuLock_IR);
 +                              if (unlikely(au_dbrange_test(d))) {
@@ -2445,7 +3443,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +                          && au_h_dptr(d, bindex)
 +                          && au_test_dbusy(d, bstart, bend)) {
 +                              err = -EBUSY;
-+                              AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
++                              AuVerbose(verbose, "busy %pd\n", d);
 +                              AuDbgDentry(d);
 +                      }
 +                      di_read_unlock(d, AuLock_IR);
@@ -2475,6 +3473,8 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      AuDbg("b%d\n", bindex);
 +      for (ull = 0; !err && ull < max; ull++) {
 +              i = array[ull];
++              if (unlikely(!i))
++                      break;
 +              if (i->i_ino == AUFS_ROOT_INO)
 +                      continue;
 +
@@ -2529,6 +3529,135 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      return err;
 +}
 +
++static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
++                       struct file **to_free, int *idx)
++{
++      int err;
++      unsigned char matched, root;
++      aufs_bindex_t bindex, bend;
++      struct au_fidir *fidir;
++      struct au_hfile *hfile;
++
++      err = 0;
++      root = IS_ROOT(file->f_path.dentry);
++      if (root) {
++              get_file(file);
++              to_free[*idx] = file;
++              (*idx)++;
++              goto out;
++      }
++
++      matched = 0;
++      fidir = au_fi(file)->fi_hdir;
++      AuDebugOn(!fidir);
++      bend = au_fbend_dir(file);
++      for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
++              hfile = fidir->fd_hfile + bindex;
++              if (!hfile->hf_file)
++                      continue;
++
++              if (hfile->hf_br->br_id == br_id) {
++                      matched = 1;
++                      break;
++              }
++      }
++      if (matched)
++              err = -EBUSY;
++
++out:
++      return err;
++}
++
++static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
++                        struct file **to_free, int opened)
++{
++      int err, idx;
++      unsigned long long ull, max;
++      aufs_bindex_t bstart;
++      struct file *file, **array;
++      struct dentry *root;
++      struct au_hfile *hfile;
++
++      array = au_farray_alloc(sb, &max);
++      err = PTR_ERR(array);
++      if (IS_ERR(array))
++              goto out;
++
++      err = 0;
++      idx = 0;
++      root = sb->s_root;
++      di_write_unlock(root);
++      for (ull = 0; ull < max; ull++) {
++              file = array[ull];
++              if (unlikely(!file))
++                      break;
++
++              /* AuDbg("%pD\n", file); */
++              fi_read_lock(file);
++              bstart = au_fbstart(file);
++              if (!d_is_dir(file->f_path.dentry)) {
++                      hfile = &au_fi(file)->fi_htop;
++                      if (hfile->hf_br->br_id == br_id)
++                              err = -EBUSY;
++              } else
++                      err = test_dir_busy(file, br_id, to_free, &idx);
++              fi_read_unlock(file);
++              if (unlikely(err))
++                      break;
++      }
++      di_write_lock_child(root);
++      au_farray_free(array, max);
++      AuDebugOn(idx > opened);
++
++out:
++      return err;
++}
++
++static void br_del_file(struct file **to_free, unsigned long long opened,
++                        aufs_bindex_t br_id)
++{
++      unsigned long long ull;
++      aufs_bindex_t bindex, bstart, bend, bfound;
++      struct file *file;
++      struct au_fidir *fidir;
++      struct au_hfile *hfile;
++
++      for (ull = 0; ull < opened; ull++) {
++              file = to_free[ull];
++              if (unlikely(!file))
++                      break;
++
++              /* AuDbg("%pD\n", file); */
++              AuDebugOn(!d_is_dir(file->f_path.dentry));
++              bfound = -1;
++              fidir = au_fi(file)->fi_hdir;
++              AuDebugOn(!fidir);
++              fi_write_lock(file);
++              bstart = au_fbstart(file);
++              bend = au_fbend_dir(file);
++              for (bindex = bstart; bindex <= bend; bindex++) {
++                      hfile = fidir->fd_hfile + bindex;
++                      if (!hfile->hf_file)
++                              continue;
++
++                      if (hfile->hf_br->br_id == br_id) {
++                              bfound = bindex;
++                              break;
++                      }
++              }
++              AuDebugOn(bfound < 0);
++              au_set_h_fptr(file, bfound, NULL);
++              if (bfound == bstart) {
++                      for (bstart++; bstart <= bend; bstart++)
++                              if (au_hf_dir(file, bstart)) {
++                                      au_set_fbstart(file, bstart);
++                                      break;
++                              }
++              }
++              fi_write_unlock(file);
++      }
++}
++
 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
 +                           const aufs_bindex_t bindex,
 +                           const aufs_bindex_t bend)
@@ -2621,17 +3750,29 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      au_br_do_free(br);
 +}
 +
++static unsigned long long empty_cb(void *array, unsigned long long max,
++                                 void *arg)
++{
++      return max;
++}
++
 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
 +{
 +      int err, rerr, i;
++      unsigned long long opened;
 +      unsigned int mnt_flags;
 +      aufs_bindex_t bindex, bend, br_id;
 +      unsigned char do_wh, verbose;
 +      struct au_branch *br;
 +      struct au_wbr *wbr;
++      struct dentry *root;
++      struct file **to_free;
 +
 +      err = 0;
-+      bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
++      opened = 0;
++      to_free = NULL;
++      root = sb->s_root;
++      bindex = au_find_dbindex(root, del->h_path.dentry);
 +      if (bindex < 0) {
 +              if (remount)
 +                      goto out; /* success */
@@ -2650,10 +3791,21 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              goto out;
 +      }
 +      br = au_sbr(sb, bindex);
-+      i = atomic_read(&br->br_count);
-+      if (unlikely(i)) {
-+              AuVerbose(verbose, "%d file(s) opened\n", i);
-+              goto out;
++      AuDebugOn(!path_equal(&br->br_path, &del->h_path));
++
++      br_id = br->br_id;
++      opened = atomic_read(&br->br_count);
++      if (unlikely(opened)) {
++              to_free = au_array_alloc(&opened, empty_cb, NULL);
++              err = PTR_ERR(to_free);
++              if (IS_ERR(to_free))
++                      goto out;
++
++              err = test_file_busy(sb, br_id, to_free, opened);
++              if (unlikely(err)) {
++                      AuVerbose(verbose, "%llu file(s) opened\n", opened);
++                      goto out;
++              }
 +      }
 +
 +      wbr = br->br_wbr;
@@ -2667,7 +3819,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              }
 +      }
 +
-+      err = test_children_busy(sb->s_root, bindex, verbose);
++      err = test_children_busy(root, bindex, verbose);
 +      if (unlikely(err)) {
 +              if (do_wh)
 +                      goto out_wh;
@@ -2675,7 +3827,16 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      }
 +
 +      err = 0;
-+      br_id = br->br_id;
++      if (to_free) {
++              /*
++               * now we confirmed the branch is deletable.
++               * let's free the remaining opened dirs on the branch.
++               */
++              di_write_unlock(root);
++              br_del_file(to_free, opened, br_id);
++              di_write_lock_child(root);
++      }
++
 +      if (!remount)
 +              au_br_do_del(sb, bindex, br);
 +      else {
@@ -2685,10 +3846,10 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      }
 +
 +      if (!bindex) {
-+              au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
++              au_cpup_attr_all(root->d_inode, /*force*/1);
 +              sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
 +      } else
-+              au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
++              au_sub_nlink(root->d_inode, del->h_path.dentry->d_inode);
 +      if (au_opt_test(mnt_flags, PLINK))
 +              au_plink_half_refresh(sb, br_id);
 +
@@ -2698,11 +3859,13 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +
 +out_wh:
 +      /* revert */
-+      rerr = au_br_init_wh(sb, br, br->br_perm, del->h_path.dentry);
++      rerr = au_br_init_wh(sb, br, br->br_perm);
 +      if (rerr)
 +              pr_warn("failed re-creating base whiteout, %s. (%d)\n",
 +                      del->pathname, rerr);
 +out:
++      if (to_free)
++              au_farray_free(to_free, opened);
 +      return err;
 +}
 +
@@ -2767,13 +3930,13 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +
 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
 +{
-+      return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
++      return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
 +}
 +
 +#ifdef CONFIG_COMPAT
 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
 +{
-+      return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
++      return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
 +}
 +#endif
 +
@@ -2802,58 +3965,14 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              || do_need_sigen_inc(new, old);
 +}
 +
-+static unsigned long long au_farray_cb(void *a,
-+                                     unsigned long long max __maybe_unused,
-+                                     void *arg)
-+{
-+      unsigned long long n;
-+      struct file **p, *f;
-+      struct super_block *sb = arg;
-+
-+      n = 0;
-+      p = a;
-+      lg_global_lock(&files_lglock);
-+      do_file_list_for_each_entry(sb, f) {
-+              if (au_fi(f)
-+                  && file_count(f)
-+                  && !special_file(f->f_dentry->d_inode->i_mode)) {
-+                      get_file(f);
-+                      *p++ = f;
-+                      n++;
-+                      AuDebugOn(n > max);
-+              }
-+      } while_file_list_for_each_entry;
-+      lg_global_unlock(&files_lglock);
-+
-+      return n;
-+}
-+
-+static struct file **au_farray_alloc(struct super_block *sb,
-+                                   unsigned long long *max)
-+{
-+      *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
-+      return au_array_alloc(max, au_farray_cb, sb);
-+}
-+
-+static void au_farray_free(struct file **a, unsigned long long max)
-+{
-+      unsigned long long ull;
-+
-+      for (ull = 0; ull < max; ull++)
-+              if (a[ull])
-+                      fput(a[ull]);
-+      au_array_free(a);
-+}
-+
 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
 +{
 +      int err, do_warn;
 +      unsigned int mnt_flags;
 +      unsigned long long ull, max;
 +      aufs_bindex_t br_id;
-+      unsigned char verbose;
++      unsigned char verbose, writer;
 +      struct file *file, *hf, **array;
-+      struct inode *inode;
 +      struct au_hfile *hfile;
 +
 +      mnt_flags = au_mntflags(sb);
@@ -2868,23 +3987,23 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +      br_id = au_sbr_id(sb, bindex);
 +      for (ull = 0; ull < max; ull++) {
 +              file = array[ull];
++              if (unlikely(!file))
++                      break;
 +
-+              /* AuDbg("%.*s\n", AuDLNPair(file->f_dentry)); */
++              /* AuDbg("%pD\n", file); */
 +              fi_read_lock(file);
 +              if (unlikely(au_test_mmapped(file))) {
 +                      err = -EBUSY;
-+                      AuVerbose(verbose, "mmapped %.*s\n",
-+                                AuDLNPair(file->f_dentry));
++                      AuVerbose(verbose, "mmapped %pD\n", file);
 +                      AuDbgFile(file);
 +                      FiMustNoWaiters(file);
 +                      fi_read_unlock(file);
 +                      goto out_array;
 +              }
 +
-+              inode = file->f_dentry->d_inode;
 +              hfile = &au_fi(file)->fi_htop;
 +              hf = hfile->hf_file;
-+              if (!S_ISREG(inode->i_mode)
++              if (!d_is_reg(file->f_path.dentry)
 +                  || !(file->f_mode & FMODE_WRITE)
 +                  || hfile->hf_br->br_id != br_id
 +                  || !(hf->f_mode & FMODE_WRITE))
@@ -2909,17 +4028,24 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +                      continue;
 +
 +              /* todo: already flushed? */
-+              /* cf. fs/super.c:mark_files_ro() */
++              /*
++               * fs/super.c:mark_files_ro() is gone, but aufs keeps its
++               * approach which resets f_mode and calls mnt_drop_write() and
++               * file_release_write() for each file, because the branch
++               * attribute in aufs world is totally different from the native
++               * fs rw/ro mode.
++              */
 +              /* fi_read_lock(file); */
 +              hfile = &au_fi(file)->fi_htop;
 +              hf = hfile->hf_file;
 +              /* fi_read_unlock(file); */
 +              spin_lock(&hf->f_lock);
-+              hf->f_mode &= ~FMODE_WRITE;
++              writer = !!(hf->f_mode & FMODE_WRITER);
++              hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
 +              spin_unlock(&hf->f_lock);
-+              if (!file_check_writeable(hf)) {
-+                      file_release_write(hf);
-+                      vfsub_mnt_drop_write(hf->f_vfsmnt);
++              if (writer) {
++                      put_write_access(file_inode(hf));
++                      __mnt_drop_write(hf->f_path.mnt);
 +              }
 +      }
 +
@@ -2935,9 +4061,9 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +{
 +      int err, rerr;
 +      aufs_bindex_t bindex;
-+      struct path path;
 +      struct dentry *root;
 +      struct au_branch *br;
++      struct au_br_fhsm *bf;
 +
 +      root = sb->s_root;
 +      bindex = au_find_dbindex(root, mod->h_root);
@@ -2955,14 +4081,25 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              goto out;
 +
 +      br = au_sbr(sb, bindex);
++      AuDebugOn(mod->h_root != au_br_dentry(br));
 +      if (br->br_perm == mod->perm)
 +              return 0; /* success */
 +
++      /* pre-allocate for non-fhsm --> fhsm */
++      bf = NULL;
++      if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
++              err = au_fhsm_br_alloc(br);
++              if (unlikely(err))
++                      goto out;
++              bf = br->br_fhsm;
++              br->br_fhsm = NULL;
++      }
++
 +      if (au_br_writable(br->br_perm)) {
 +              /* remove whiteout base */
-+              err = au_br_init_wh(sb, br, mod->perm, mod->h_root);
++              err = au_br_init_wh(sb, br, mod->perm);
 +              if (unlikely(err))
-+                      goto out;
++                      goto out_bf;
 +
 +              if (!au_br_writable(mod->perm)) {
 +                      /* rw --> ro, file might be mmapped */
@@ -2977,12 +4114,8 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +                              rerr = -ENOMEM;
 +                              br->br_wbr = kmalloc(sizeof(*br->br_wbr),
 +                                                   GFP_NOFS);
-+                              if (br->br_wbr) {
-+                                      path.mnt = br->br_mnt;
-+                                      path.dentry = mod->h_root;
-+                                      rerr = au_wbr_init(br, sb, br->br_perm,
-+                                                         &path);
-+                              }
++                              if (br->br_wbr)
++                                      rerr = au_wbr_init(br, sb, br->br_perm);
 +                              if (unlikely(rerr)) {
 +                                      AuIOErr("nested error %d (%d)\n",
 +                                              rerr, err);
@@ -2995,31 +4128,61 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +              err = -ENOMEM;
 +              br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
 +              if (br->br_wbr) {
-+                      path.mnt = br->br_mnt;
-+                      path.dentry = mod->h_root;
-+                      err = au_wbr_init(br, sb, mod->perm, &path);
++                      err = au_wbr_init(br, sb, mod->perm);
 +                      if (unlikely(err)) {
 +                              kfree(br->br_wbr);
 +                              br->br_wbr = NULL;
 +                      }
 +              }
 +      }
++      if (unlikely(err))
++              goto out_bf;
++
++      if (au_br_fhsm(br->br_perm)) {
++              if (!au_br_fhsm(mod->perm)) {
++                      /* fhsm --> non-fhsm */
++                      au_br_fhsm_fin(br->br_fhsm);
++                      kfree(br->br_fhsm);
++                      br->br_fhsm = NULL;
++              }
++      } else if (au_br_fhsm(mod->perm))
++              /* non-fhsm --> fhsm */
++              br->br_fhsm = bf;
 +
-+      if (!err) {
-+              *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
-+              br->br_perm = mod->perm;
-+      }
++      *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
++      br->br_perm = mod->perm;
++      goto out; /* success */
 +
++out_bf:
++      kfree(bf);
 +out:
 +      AuTraceErr(err);
 +      return err;
 +}
++
++/* ---------------------------------------------------------------------- */
++
++int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
++{
++      int err;
++      struct kstatfs kstfs;
++
++      err = vfs_statfs(&br->br_path, &kstfs);
++      if (!err) {
++              stfs->f_blocks = kstfs.f_blocks;
++              stfs->f_bavail = kstfs.f_bavail;
++              stfs->f_files = kstfs.f_files;
++              stfs->f_ffree = kstfs.f_ffree;
++      }
++
++      return err;
++}
 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 --- /usr/share/empty/fs/aufs/branch.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/branch.h     2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,236 @@
++++ linux/fs/aufs/branch.h     2015-06-22 08:29:23.703424266 +0200
+@@ -0,0 +1,279 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -3032,8 +4195,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -3064,6 +4226,16 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +#endif
 +};
 +
++/* File-based Hierarchical Storage Management */
++struct au_br_fhsm {
++#ifdef CONFIG_AUFS_FHSM
++      struct mutex            bf_lock;
++      unsigned long           bf_jiffy;
++      struct aufs_stfs        bf_stfs;
++      int                     bf_readable;
++#endif
++};
++
 +/* members for writable branch only */
 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
 +struct au_wbr {
@@ -3088,6 +4260,18 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +};
 +#endif
 +
++/* sysfs entries */
++struct au_brsysfs {
++      char                    name[16];
++      struct attribute        attr;
++};
++
++enum {
++      AuBrSysfs_BR,
++      AuBrSysfs_BRID,
++      AuBrSysfs_Last
++};
++
 +/* protected by superblock rwsem */
 +struct au_branch {
 +      struct au_xino_file     br_xino;
@@ -3095,15 +4279,15 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +      aufs_bindex_t           br_id;
 +
 +      int                     br_perm;
-+      struct vfsmount         *br_mnt;
++      struct path             br_path;
 +      spinlock_t              br_dykey_lock;
 +      struct au_dykey         *br_dykey[AuBrDynOp];
 +      atomic_t                br_count;
 +
 +      struct au_wbr           *br_wbr;
++      struct au_br_fhsm       *br_fhsm;
 +
 +      /* xino truncation */
-+      blkcnt_t                br_xino_upper;  /* watermark in blocks */
 +      atomic_t                br_xino_running;
 +
 +#ifdef CONFIG_AUFS_HFSNOTIFY
@@ -3111,42 +4295,31 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +#endif
 +
 +#ifdef CONFIG_SYSFS
-+      /* an entry under sysfs per mount-point */
-+      char                    br_name[8];
-+      struct attribute        br_attr;
++      /* entries under sysfs per mount-point */
++      struct au_brsysfs       br_sysfs[AuBrSysfs_Last];
 +#endif
 +};
 +
 +/* ---------------------------------------------------------------------- */
 +
-+/* branch permissions and attributes */
-+#define AuBrPerm_RW           1               /* writable, hardlinkable wh */
-+#define AuBrPerm_RO           (1 << 1)        /* readonly */
-+#define AuBrPerm_RR           (1 << 2)        /* natively readonly */
-+#define AuBrPerm_Mask         (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
-+
-+#define AuBrRAttr_WH          (1 << 3)        /* whiteout-able */
-+
-+#define AuBrWAttr_NoLinkWH    (1 << 4)        /* un-hardlinkable whiteouts */
-+
-+static inline int au_br_writable(int brperm)
++static inline struct vfsmount *au_br_mnt(struct au_branch *br)
 +{
-+      return brperm & AuBrPerm_RW;
++      return br->br_path.mnt;
 +}
 +
-+static inline int au_br_whable(int brperm)
++static inline struct dentry *au_br_dentry(struct au_branch *br)
 +{
-+      return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
++      return br->br_path.dentry;
 +}
 +
-+static inline int au_br_wh_linkable(int brperm)
++static inline struct super_block *au_br_sb(struct au_branch *br)
 +{
-+      return !(brperm & AuBrWAttr_NoLinkWH);
++      return au_br_mnt(br)->mnt_sb;
 +}
 +
 +static inline int au_br_rdonly(struct au_branch *br)
 +{
-+      return ((br->br_mnt->mnt_sb->s_flags & MS_RDONLY)
++      return ((au_br_sb(br)->s_flags & MS_RDONLY)
 +              || !au_br_writable(br->br_perm))
 +              ? -EROFS : 0;
 +}
@@ -3160,6 +4333,18 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +#endif
 +}
 +
++static inline int au_br_test_oflag(int oflag, struct au_branch *br)
++{
++      int err, exec_flag;
++
++      err = 0;
++      exec_flag = oflag & __FMODE_EXEC;
++      if (unlikely(exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC)))
++              err = -EACCES;
++
++      return err;
++}
++
 +/* ---------------------------------------------------------------------- */
 +
 +/* branch.c */
@@ -3177,6 +4362,8 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +struct au_opt_mod;
 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
 +            int *do_refresh);
++struct aufs_stfs;
++int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
 +
 +/* xino.c */
 +static const loff_t au_loff_max = LLONG_MAX;
@@ -3216,13 +4403,13 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +static inline
 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
 +{
-+      return au_sbr(sb, bindex)->br_mnt;
++      return au_br_mnt(au_sbr(sb, bindex));
 +}
 +
 +static inline
 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
 +{
-+      return au_sbr_mnt(sb, bindex)->mnt_sb;
++      return au_br_sb(au_sbr(sb, bindex));
 +}
 +
 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
@@ -3252,11 +4439,30 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
 +#define WbrWhMustWriteLock(wbr)       AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
 +
++/* ---------------------------------------------------------------------- */
++
++#ifdef CONFIG_AUFS_FHSM
++static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
++{
++      mutex_init(&brfhsm->bf_lock);
++      brfhsm->bf_jiffy = 0;
++      brfhsm->bf_readable = 0;
++}
++
++static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
++{
++      mutex_destroy(&brfhsm->bf_lock);
++}
++#else
++AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
++AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
++#endif
++
 +#endif /* __KERNEL__ */
 +#endif /* __AUFS_BRANCH_H__ */
 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
 --- /usr/share/empty/fs/aufs/conf.mk   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/conf.mk      2012-08-26 08:39:00.757174634 +0200
++++ linux/fs/aufs/conf.mk      2015-06-22 08:27:37.874168290 +0200
 @@ -0,0 +1,38 @@
 +
 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
@@ -3271,9 +4477,9 @@ diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
 +      SBILIST \
 +      HNOTIFY HFSNOTIFY \
 +      EXPORT INO_T_64 \
++      XATTR \
++      FHSM \
 +      RDU \
-+      PROC_MAP \
-+      SP_IATTR \
 +      SHWH \
 +      BR_RAMFS \
 +      BR_FUSE POLL \
@@ -3298,10 +4504,10 @@ diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
 +-include ${srctree}/${src}/conf_priv.mk
 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 --- /usr/share/empty/fs/aufs/cpup.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/cpup.c       2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,1085 @@
++++ linux/fs/aufs/cpup.c       2015-06-22 08:29:23.703424266 +0200
+@@ -0,0 +1,1308 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -3314,8 +4520,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -3326,12 +4531,14 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +#include <linux/mm.h>
 +#include "aufs.h"
 +
-+void au_cpup_attr_flags(struct inode *dst, struct inode *src)
++void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
 +{
 +      const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
-+              | S_NOATIME | S_NOCMTIME;
++              | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
++
++      BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
 +
-+      dst->i_flags |= src->i_flags & ~mask;
++      dst->i_flags |= iflags & ~mask;
 +      if (au_test_fs_notime(dst->i_sb))
 +              dst->i_flags |= S_NOATIME | S_NOCMTIME;
 +}
@@ -3362,8 +4569,11 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +
 +      /*
 +       * 0 can happen in revalidating.
-+       * h_inode->i_mutex is not held, but it is harmless since once i_nlink
-+       * reaches 0, it will never become positive.
++       * h_inode->i_mutex may not be held here, but it is harmless since once
++       * i_nlink reaches 0, it will never become positive except O_TMPFILE
++       * case.
++       * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
++       *       the incorrect link count.
 +       */
 +      set_nlink(inode, h_inode->i_nlink);
 +
@@ -3390,7 +4600,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      inode->i_uid = h_inode->i_uid;
 +      inode->i_gid = h_inode->i_gid;
 +      au_cpup_attr_timesizes(inode);
-+      au_cpup_attr_flags(inode, h_inode);
++      au_cpup_attr_flags(inode, h_inode->i_flags);
 +}
 +
 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
@@ -3444,46 +4654,83 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
 +              | ATTR_ATIME | ATTR_ATIME_SET;
 +
-+      err = vfsub_notify_change(&dt->dt_h_path, &attr);
++      /* no delegation since this is a directory */
++      err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
 +      if (unlikely(err))
 +              pr_warn("restoring timestamps failed(%d). ignored\n", err);
 +}
 +
 +/* ---------------------------------------------------------------------- */
 +
++/* internal use only */
++struct au_cpup_reg_attr {
++      int             valid;
++      struct kstat    st;
++      unsigned int    iflags; /* inode->i_flags */
++};
++
 +static noinline_for_stack
-+int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src)
++int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
++             struct au_cpup_reg_attr *h_src_attr)
 +{
-+      int err, sbits;
++      int err, sbits, icex;
++      unsigned int mnt_flags;
++      unsigned char verbose;
 +      struct iattr ia;
 +      struct path h_path;
 +      struct inode *h_isrc, *h_idst;
++      struct kstat *h_st;
++      struct au_branch *br;
 +
 +      h_path.dentry = au_h_dptr(dst, bindex);
 +      h_idst = h_path.dentry->d_inode;
-+      h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
++      br = au_sbr(dst->d_sb, bindex);
++      h_path.mnt = au_br_mnt(br);
 +      h_isrc = h_src->d_inode;
 +      ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
 +              | ATTR_ATIME | ATTR_MTIME
 +              | ATTR_ATIME_SET | ATTR_MTIME_SET;
-+      ia.ia_uid = h_isrc->i_uid;
-+      ia.ia_gid = h_isrc->i_gid;
-+      ia.ia_atime = h_isrc->i_atime;
-+      ia.ia_mtime = h_isrc->i_mtime;
-+      if (h_idst->i_mode != h_isrc->i_mode
-+          && !S_ISLNK(h_idst->i_mode)) {
-+              ia.ia_valid |= ATTR_MODE;
-+              ia.ia_mode = h_isrc->i_mode;
++      if (h_src_attr && h_src_attr->valid) {
++              h_st = &h_src_attr->st;
++              ia.ia_uid = h_st->uid;
++              ia.ia_gid = h_st->gid;
++              ia.ia_atime = h_st->atime;
++              ia.ia_mtime = h_st->mtime;
++              if (h_idst->i_mode != h_st->mode
++                  && !S_ISLNK(h_idst->i_mode)) {
++                      ia.ia_valid |= ATTR_MODE;
++                      ia.ia_mode = h_st->mode;
++              }
++              sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
++              au_cpup_attr_flags(h_idst, h_src_attr->iflags);
++      } else {
++              ia.ia_uid = h_isrc->i_uid;
++              ia.ia_gid = h_isrc->i_gid;
++              ia.ia_atime = h_isrc->i_atime;
++              ia.ia_mtime = h_isrc->i_mtime;
++              if (h_idst->i_mode != h_isrc->i_mode
++                  && !S_ISLNK(h_idst->i_mode)) {
++                      ia.ia_valid |= ATTR_MODE;
++                      ia.ia_mode = h_isrc->i_mode;
++              }
++              sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
++              au_cpup_attr_flags(h_idst, h_isrc->i_flags);
 +      }
-+      sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
-+      au_cpup_attr_flags(h_idst, h_isrc);
-+      err = vfsub_notify_change(&h_path, &ia);
++      /* no delegation since it is just created */
++      err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
 +
 +      /* is this nfs only? */
 +      if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
 +              ia.ia_valid = ATTR_FORCE | ATTR_MODE;
 +              ia.ia_mode = h_isrc->i_mode;
-+              err = vfsub_notify_change(&h_path, &ia);
++              err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
++      }
++
++      icex = br->br_perm & AuBrAttr_ICEX;
++      if (!err) {
++              mnt_flags = au_mntflags(dst->d_sb);
++              verbose = !!au_opt_test(mnt_flags, VERBOSE);
++              err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
 +      }
 +
 +      return err;
@@ -3542,6 +4789,8 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +                              wbytes -= b;
 +                              p += b;
 +                      }
++                      if (unlikely(err < 0))
++                              break;
 +              } else {
 +                      loff_t res;
 +
@@ -3560,7 +4809,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +              AuLabel(last hole);
 +
 +              err = 1;
-+              if (au_test_nfs(dst->f_dentry->d_sb)) {
++              if (au_test_nfs(dst->f_path.dentry->d_sb)) {
 +                      /* nfs requires this step to make last hole */
 +                      /* is this only nfs? */
 +                      do {
@@ -3576,9 +4825,11 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +                      ia->ia_size = dst->f_pos;
 +                      ia->ia_valid = ATTR_SIZE | ATTR_FILE;
 +                      ia->ia_file = dst;
-+                      h_mtx = &dst->f_dentry->d_inode->i_mutex;
++                      h_mtx = &file_inode(dst)->i_mutex;
 +                      mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
-+                      err = vfsub_notify_change(&dst->f_path, ia);
++                      /* no delegation since it is just created */
++                      err = vfsub_notify_change(&dst->f_path, ia,
++                                                /*delegated*/NULL);
 +                      mutex_unlock(h_mtx);
 +              }
 +      }
@@ -3594,7 +4845,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      char *buf;
 +
 +      err = -ENOMEM;
-+      blksize = dst->f_dentry->d_sb->s_blocksize;
++      blksize = dst->f_path.dentry->d_sb->s_blocksize;
 +      if (!blksize || PAGE_SIZE < blksize)
 +              blksize = PAGE_SIZE;
 +      AuDbg("blksize %lu\n", blksize);
@@ -3625,8 +4876,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 + * to support a sparse file which is opened with O_APPEND,
 + * we need to close the file.
 + */
-+static int au_cp_regular(struct dentry *dentry, aufs_bindex_t bdst,
-+                       aufs_bindex_t bsrc, loff_t len)
++static int au_cp_regular(struct au_cp_generic *cpg)
 +{
 +      int err, i;
 +      enum { SRC, DST };
@@ -3634,47 +4884,43 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +              aufs_bindex_t bindex;
 +              unsigned int flags;
 +              struct dentry *dentry;
++              int force_wr;
 +              struct file *file;
-+              void *label, *label_file;
++              void *label;
 +      } *f, file[] = {
 +              {
-+                      .bindex = bsrc,
++                      .bindex = cpg->bsrc,
 +                      .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
-+                      .file = NULL,
-+                      .label = &&out,
-+                      .label_file = &&out_src
++                      .label = &&out
 +              },
 +              {
-+                      .bindex = bdst,
++                      .bindex = cpg->bdst,
 +                      .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
-+                      .file = NULL,
-+                      .label = &&out_src,
-+                      .label_file = &&out_dst
++                      .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
++                      .label = &&out_src
 +              }
 +      };
 +      struct super_block *sb;
 +
 +      /* bsrc branch can be ro/rw. */
-+      sb = dentry->d_sb;
++      sb = cpg->dentry->d_sb;
 +      f = file;
 +      for (i = 0; i < 2; i++, f++) {
-+              f->dentry = au_h_dptr(dentry, f->bindex);
-+              f->file = au_h_open(dentry, f->bindex, f->flags, /*file*/NULL);
++              f->dentry = au_h_dptr(cpg->dentry, f->bindex);
++              f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
++                                  /*file*/NULL, f->force_wr);
 +              err = PTR_ERR(f->file);
 +              if (IS_ERR(f->file))
 +                      goto *f->label;
-+              err = -EINVAL;
-+              if (unlikely(!f->file->f_op))
-+                      goto *f->label_file;
 +      }
 +
 +      /* try stopping to update while we copyup */
 +      IMustLock(file[SRC].dentry->d_inode);
-+      err = au_copy_file(file[DST].file, file[SRC].file, len);
++      err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
 +
-+out_dst:
 +      fput(file[DST].file);
 +      au_sbr_put(sb, file[DST].bindex);
++
 +out_src:
 +      fput(file[SRC].file);
 +      au_sbr_put(sb, file[SRC].bindex);
@@ -3682,27 +4928,45 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      return err;
 +}
 +
-+static int au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
-+                            aufs_bindex_t bsrc, loff_t len,
-+                            struct inode *h_dir, struct path *h_path)
++static int au_do_cpup_regular(struct au_cp_generic *cpg,
++                            struct au_cpup_reg_attr *h_src_attr)
 +{
 +      int err, rerr;
 +      loff_t l;
++      struct path h_path;
++      struct inode *h_src_inode, *h_dst_inode;
 +
 +      err = 0;
-+      l = i_size_read(au_h_iptr(dentry->d_inode, bsrc));
-+      if (len == -1 || l < len)
-+              len = l;
-+      if (len)
-+              err = au_cp_regular(dentry, bdst, bsrc, len);
-+      if (!err)
-+              goto out; /* success */
++      h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
++      l = i_size_read(h_src_inode);
++      if (cpg->len == -1 || l < cpg->len)
++              cpg->len = l;
++      if (cpg->len) {
++              /* try stopping to update while we are referencing */
++              mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
++              au_pin_hdir_unlock(cpg->pin);
 +
-+      rerr = vfsub_unlink(h_dir, h_path, /*force*/0);
-+      if (rerr) {
-+              AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
-+                      AuDLNPair(h_path->dentry), err, rerr);
-+              err = -EIO;
++              h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
++              h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
++              h_src_attr->iflags = h_src_inode->i_flags;
++              err = vfs_getattr(&h_path, &h_src_attr->st);
++              if (unlikely(err)) {
++                      mutex_unlock(&h_src_inode->i_mutex);
++                      goto out;
++              }
++              h_src_attr->valid = 1;
++              err = au_cp_regular(cpg);
++              mutex_unlock(&h_src_inode->i_mutex);
++              rerr = au_pin_hdir_relock(cpg->pin);
++              if (!err && rerr)
++                      err = rerr;
++      }
++      if (!err && (h_src_inode->i_state & I_LINKABLE)) {
++              h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
++              h_dst_inode = h_path.dentry->d_inode;
++              spin_lock(&h_dst_inode->i_lock);
++              h_dst_inode->i_state |= I_LINKABLE;
++              spin_unlock(&h_dst_inode->i_lock);
 +      }
 +
 +out:
@@ -3745,17 +5009,15 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      return err;
 +}
 +
-+/* return with the lower dst inode is locked */
 +static noinline_for_stack
-+int cpup_entry(struct dentry *dentry, aufs_bindex_t bdst,
-+             aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+             struct dentry *dst_parent)
++int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
++             struct au_cpup_reg_attr *h_src_attr)
 +{
 +      int err;
 +      umode_t mode;
 +      unsigned int mnt_flags;
-+      unsigned char isdir;
-+      const unsigned char do_dt = !!au_ftest_cpup(flags, DTIME);
++      unsigned char isdir, isreg, force;
++      const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
 +      struct au_dtime dt;
 +      struct path h_path;
 +      struct dentry *h_src, *h_dst, *h_parent;
@@ -3763,37 +5025,38 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      struct super_block *sb;
 +
 +      /* bsrc branch can be ro/rw. */
-+      h_src = au_h_dptr(dentry, bsrc);
++      h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
 +      h_inode = h_src->d_inode;
-+      AuDebugOn(h_inode != au_h_iptr(dentry->d_inode, bsrc));
++      AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
 +
 +      /* try stopping to be referenced while we are creating */
-+      h_dst = au_h_dptr(dentry, bdst);
++      h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
++      if (au_ftest_cpup(cpg->flags, RENAME))
++              AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
++                                AUFS_WH_PFX_LEN));
 +      h_parent = h_dst->d_parent; /* dir inode is locked */
 +      h_dir = h_parent->d_inode;
 +      IMustLock(h_dir);
 +      AuDebugOn(h_parent != h_dst->d_parent);
 +
-+      sb = dentry->d_sb;
-+      h_path.mnt = au_sbr_mnt(sb, bdst);
++      sb = cpg->dentry->d_sb;
++      h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
 +      if (do_dt) {
 +              h_path.dentry = h_parent;
 +              au_dtime_store(&dt, dst_parent, &h_path);
 +      }
 +      h_path.dentry = h_dst;
 +
++      isreg = 0;
 +      isdir = 0;
 +      mode = h_inode->i_mode;
 +      switch (mode & S_IFMT) {
 +      case S_IFREG:
-+              /* try stopping to update while we are referencing */
-+              IMustLock(h_inode);
++              isreg = 1;
 +              err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
 +                                 /*want_excl*/true);
 +              if (!err)
-+                      err = au_do_cpup_regular
-+                              (dentry, bdst, bsrc, len,
-+                               au_h_iptr(dst_parent->d_inode, bdst), &h_path);
++                      err = au_do_cpup_regular(cpg, h_src_attr);
 +              break;
 +      case S_IFDIR:
 +              isdir = 1;
@@ -3803,10 +5066,10 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +                       * strange behaviour from the users view,
 +                       * particularry setattr case
 +                       */
-+                      if (au_ibstart(dst_parent->d_inode) == bdst)
++                      if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
 +                              au_cpup_attr_nlink(dst_parent->d_inode,
 +                                                 /*force*/1);
-+                      au_cpup_attr_nlink(dentry->d_inode, /*force*/1);
++                      au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
 +              }
 +              break;
 +      case S_IFLNK:
@@ -3829,173 +5092,277 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      if (!au_opt_test(mnt_flags, UDBA_NONE)
 +          && !isdir
 +          && au_opt_test(mnt_flags, XINO)
-+          && h_inode->i_nlink == 1
++          && (h_inode->i_nlink == 1
++              || (h_inode->i_state & I_LINKABLE))
 +          /* todo: unnecessary? */
-+          /* && dentry->d_inode->i_nlink == 1 */
-+          && bdst < bsrc
-+          && !au_ftest_cpup(flags, KEEPLINO))
-+              au_xino_write(sb, bsrc, h_inode->i_ino, /*ino*/0);
++          /* && cpg->dentry->d_inode->i_nlink == 1 */
++          && cpg->bdst < cpg->bsrc
++          && !au_ftest_cpup(cpg->flags, KEEPLINO))
++              au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
 +              /* ignore this error */
 +
++      if (!err) {
++              force = 0;
++              if (isreg) {
++                      force = !!cpg->len;
++                      if (cpg->len == -1)
++                              force = !!i_size_read(h_inode);
++              }
++              au_fhsm_wrote(sb, cpg->bdst, force);
++      }
++
 +      if (do_dt)
 +              au_dtime_revert(&dt);
 +      return err;
 +}
 +
++static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
++{
++      int err;
++      struct dentry *dentry, *h_dentry, *h_parent, *parent;
++      struct inode *h_dir;
++      aufs_bindex_t bdst;
++
++      dentry = cpg->dentry;
++      bdst = cpg->bdst;
++      h_dentry = au_h_dptr(dentry, bdst);
++      if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
++              dget(h_dentry);
++              au_set_h_dptr(dentry, bdst, NULL);
++              err = au_lkup_neg(dentry, bdst, /*wh*/0);
++              if (!err)
++                      h_path->dentry = dget(au_h_dptr(dentry, bdst));
++              au_set_h_dptr(dentry, bdst, h_dentry);
++      } else {
++              err = 0;
++              parent = dget_parent(dentry);
++              h_parent = au_h_dptr(parent, bdst);
++              dput(parent);
++              h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
++              if (IS_ERR(h_path->dentry))
++                      err = PTR_ERR(h_path->dentry);
++      }
++      if (unlikely(err))
++              goto out;
++
++      h_parent = h_dentry->d_parent; /* dir inode is locked */
++      h_dir = h_parent->d_inode;
++      IMustLock(h_dir);
++      AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
++      /* no delegation since it is just created */
++      err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
++      dput(h_path->dentry);
++
++out:
++      return err;
++}
++
 +/*
 + * copyup the @dentry from @bsrc to @bdst.
 + * the caller must set the both of lower dentries.
 + * @len is for truncating when it is -1 copyup the entire file.
 + * in link/rename cases, @dst_parent may be different from the real one.
++ * basic->bsrc can be larger than basic->bdst.
 + */
-+static int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
-+                        aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+                        struct dentry *dst_parent)
++static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
 +{
 +      int err, rerr;
 +      aufs_bindex_t old_ibstart;
 +      unsigned char isdir, plink;
-+      struct au_dtime dt;
-+      struct path h_path;
 +      struct dentry *h_src, *h_dst, *h_parent;
-+      struct inode *dst_inode, *h_dir, *inode;
++      struct inode *dst_inode, *h_dir, *inode, *delegated;
 +      struct super_block *sb;
++      struct au_branch *br;
++      /* to reuduce stack size */
++      struct {
++              struct au_dtime dt;
++              struct path h_path;
++              struct au_cpup_reg_attr h_src_attr;
++      } *a;
 +
-+      AuDebugOn(bsrc <= bdst);
++      err = -ENOMEM;
++      a = kmalloc(sizeof(*a), GFP_NOFS);
++      if (unlikely(!a))
++              goto out;
++      a->h_src_attr.valid = 0;
 +
-+      sb = dentry->d_sb;
-+      h_path.mnt = au_sbr_mnt(sb, bdst);
-+      h_dst = au_h_dptr(dentry, bdst);
++      sb = cpg->dentry->d_sb;
++      br = au_sbr(sb, cpg->bdst);
++      a->h_path.mnt = au_br_mnt(br);
++      h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
 +      h_parent = h_dst->d_parent; /* dir inode is locked */
 +      h_dir = h_parent->d_inode;
 +      IMustLock(h_dir);
 +
-+      h_src = au_h_dptr(dentry, bsrc);
-+      inode = dentry->d_inode;
++      h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
++      inode = cpg->dentry->d_inode;
 +
 +      if (!dst_parent)
-+              dst_parent = dget_parent(dentry);
++              dst_parent = dget_parent(cpg->dentry);
 +      else
 +              dget(dst_parent);
 +
 +      plink = !!au_opt_test(au_mntflags(sb), PLINK);
-+      dst_inode = au_h_iptr(inode, bdst);
++      dst_inode = au_h_iptr(inode, cpg->bdst);
 +      if (dst_inode) {
 +              if (unlikely(!plink)) {
 +                      err = -EIO;
 +                      AuIOErr("hi%lu(i%lu) exists on b%d "
 +                              "but plink is disabled\n",
-+                              dst_inode->i_ino, inode->i_ino, bdst);
-+                      goto out;
++                              dst_inode->i_ino, inode->i_ino, cpg->bdst);
++                      goto out_parent;
 +              }
 +
 +              if (dst_inode->i_nlink) {
-+                      const int do_dt = au_ftest_cpup(flags, DTIME);
++                      const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
 +
-+                      h_src = au_plink_lkup(inode, bdst);
++                      h_src = au_plink_lkup(inode, cpg->bdst);
 +                      err = PTR_ERR(h_src);
 +                      if (IS_ERR(h_src))
-+                              goto out;
++                              goto out_parent;
 +                      if (unlikely(!h_src->d_inode)) {
 +                              err = -EIO;
 +                              AuIOErr("i%lu exists on a upper branch "
 +                                      "but not pseudo-linked\n",
 +                                      inode->i_ino);
 +                              dput(h_src);
-+                              goto out;
++                              goto out_parent;
 +                      }
 +
 +                      if (do_dt) {
-+                              h_path.dentry = h_parent;
-+                              au_dtime_store(&dt, dst_parent, &h_path);
++                              a->h_path.dentry = h_parent;
++                              au_dtime_store(&a->dt, dst_parent, &a->h_path);
 +                      }
-+                      h_path.dentry = h_dst;
-+                      err = vfsub_link(h_src, h_dir, &h_path);
++
++                      a->h_path.dentry = h_dst;
++                      delegated = NULL;
++                      err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
++                      if (!err && au_ftest_cpup(cpg->flags, RENAME))
++                              err = au_do_ren_after_cpup(cpg, &a->h_path);
 +                      if (do_dt)
-+                              au_dtime_revert(&dt);
++                              au_dtime_revert(&a->dt);
++                      if (unlikely(err == -EWOULDBLOCK)) {
++                              pr_warn("cannot retry for NFSv4 delegation"
++                                      " for an internal link\n");
++                              iput(delegated);
++                      }
 +                      dput(h_src);
-+                      goto out;
++                      goto out_parent;
 +              } else
 +                      /* todo: cpup_wh_file? */
 +                      /* udba work */
 +                      au_update_ibrange(inode, /*do_put_zero*/1);
 +      }
 +
++      isdir = S_ISDIR(inode->i_mode);
 +      old_ibstart = au_ibstart(inode);
-+      err = cpup_entry(dentry, bdst, bsrc, len, flags, dst_parent);
++      err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
 +      if (unlikely(err))
-+              goto out;
++              goto out_rev;
 +      dst_inode = h_dst->d_inode;
 +      mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
++      /* todo: necessary? */
++      /* au_pin_hdir_unlock(cpg->pin); */
 +
-+      err = cpup_iattr(dentry, bdst, h_src);
-+      isdir = S_ISDIR(dst_inode->i_mode);
-+      if (!err) {
-+              if (bdst < old_ibstart) {
-+                      if (S_ISREG(inode->i_mode)) {
-+                              err = au_dy_iaop(inode, bdst, dst_inode);
-+                              if (unlikely(err))
-+                                      goto out_rev;
++      err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
++      if (unlikely(err)) {
++              /* todo: necessary? */
++              /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
++              mutex_unlock(&dst_inode->i_mutex);
++              goto out_rev;
++      }
++
++      if (cpg->bdst < old_ibstart) {
++              if (S_ISREG(inode->i_mode)) {
++                      err = au_dy_iaop(inode, cpg->bdst, dst_inode);
++                      if (unlikely(err)) {
++                              /* ignore an error */
++                              /* au_pin_hdir_relock(cpg->pin); */
++                              mutex_unlock(&dst_inode->i_mutex);
++                              goto out_rev;
 +                      }
-+                      au_set_ibstart(inode, bdst);
 +              }
-+              au_set_h_iptr(inode, bdst, au_igrab(dst_inode),
-+                            au_hi_flags(inode, isdir));
-+              mutex_unlock(&dst_inode->i_mutex);
-+              if (!isdir
-+                  && h_src->d_inode->i_nlink > 1
-+                  && plink)
-+                      au_plink_append(inode, bdst, h_dst);
-+              goto out; /* success */
++              au_set_ibstart(inode, cpg->bdst);
++      } else
++              au_set_ibend(inode, cpg->bdst);
++      au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
++                    au_hi_flags(inode, isdir));
++
++      /* todo: necessary? */
++      /* err = au_pin_hdir_relock(cpg->pin); */
++      mutex_unlock(&dst_inode->i_mutex);
++      if (unlikely(err))
++              goto out_rev;
++
++      if (!isdir
++          && (h_src->d_inode->i_nlink > 1
++              || h_src->d_inode->i_state & I_LINKABLE)
++          && plink)
++              au_plink_append(inode, cpg->bdst, h_dst);
++
++      if (au_ftest_cpup(cpg->flags, RENAME)) {
++              a->h_path.dentry = h_dst;
++              err = au_do_ren_after_cpup(cpg, &a->h_path);
 +      }
++      if (!err)
++              goto out_parent; /* success */
 +
 +      /* revert */
 +out_rev:
-+      h_path.dentry = h_parent;
-+      mutex_unlock(&dst_inode->i_mutex);
-+      au_dtime_store(&dt, dst_parent, &h_path);
-+      h_path.dentry = h_dst;
-+      if (!isdir)
-+              rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
-+      else
-+              rerr = vfsub_rmdir(h_dir, &h_path);
-+      au_dtime_revert(&dt);
++      a->h_path.dentry = h_parent;
++      au_dtime_store(&a->dt, dst_parent, &a->h_path);
++      a->h_path.dentry = h_dst;
++      rerr = 0;
++      if (h_dst->d_inode) {
++              if (!isdir) {
++                      /* no delegation since it is just created */
++                      rerr = vfsub_unlink(h_dir, &a->h_path,
++                                          /*delegated*/NULL, /*force*/0);
++              } else
++                      rerr = vfsub_rmdir(h_dir, &a->h_path);
++      }
++      au_dtime_revert(&a->dt);
 +      if (rerr) {
 +              AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
 +              err = -EIO;
 +      }
-+
-+out:
++out_parent:
 +      dput(dst_parent);
++      kfree(a);
++out:
 +      return err;
 +}
 +
++#if 0 /* reserved */
 +struct au_cpup_single_args {
 +      int *errp;
-+      struct dentry *dentry;
-+      aufs_bindex_t bdst, bsrc;
-+      loff_t len;
-+      unsigned int flags;
++      struct au_cp_generic *cpg;
 +      struct dentry *dst_parent;
 +};
 +
 +static void au_call_cpup_single(void *args)
 +{
 +      struct au_cpup_single_args *a = args;
-+      *a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
-+                                a->flags, a->dst_parent);
++
++      au_pin_hdir_acquire_nest(a->cpg->pin);
++      *a->errp = au_cpup_single(a->cpg, a->dst_parent);
++      au_pin_hdir_release(a->cpg->pin);
 +}
++#endif
 +
 +/*
 + * prevent SIGXFSZ in copy-up.
 + * testing CAP_MKNOD is for generic fs,
 + * but CAP_FSETID is for xfs only, currently.
 + */
-+static int au_cpup_sio_test(struct super_block *sb, umode_t mode)
++static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
 +{
 +      int do_sio;
++      struct super_block *sb;
++      struct inode *h_dir;
 +
 +      do_sio = 0;
++      sb = au_pinned_parent(pin)->d_sb;
 +      if (!au_wkq_test()
 +          && (!au_sbi(sb)->si_plink_maint_pid
 +              || au_plink_maint(sb, AuLock_NOPLM))) {
@@ -4012,30 +5379,29 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +              if (!do_sio)
 +                      do_sio = ((mode & (S_ISUID | S_ISGID))
 +                                && !capable(CAP_FSETID));
++              /* this workaround may be removed in the future */
++              if (!do_sio) {
++                      h_dir = au_pinned_h_dir(pin);
++                      do_sio = h_dir->i_mode & S_ISVTX;
++              }
 +      }
 +
 +      return do_sio;
 +}
 +
-+int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
-+                     aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+                     struct dentry *dst_parent)
++#if 0 /* reserved */
++int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
 +{
 +      int err, wkq_err;
 +      struct dentry *h_dentry;
 +
-+      h_dentry = au_h_dptr(dentry, bsrc);
-+      if (!au_cpup_sio_test(dentry->d_sb, h_dentry->d_inode->i_mode))
-+              err = au_cpup_single(dentry, bdst, bsrc, len, flags,
-+                                   dst_parent);
++      h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
++      if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
++              err = au_cpup_single(cpg, dst_parent);
 +      else {
 +              struct au_cpup_single_args args = {
 +                      .errp           = &err,
-+                      .dentry         = dentry,
-+                      .bdst           = bdst,
-+                      .bsrc           = bsrc,
-+                      .len            = len,
-+                      .flags          = flags,
++                      .cpg            = cpg,
 +                      .dst_parent     = dst_parent
 +              };
 +              wkq_err = au_wkq_wait(au_call_cpup_single, &args);
@@ -4045,31 +5411,35 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +
 +      return err;
 +}
++#endif
 +
 +/*
 + * copyup the @dentry from the first active lower branch to @bdst,
 + * using au_cpup_single().
 + */
-+static int au_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+                        unsigned int flags)
++static int au_cpup_simple(struct au_cp_generic *cpg)
 +{
 +      int err;
-+      aufs_bindex_t bsrc, bend;
++      unsigned int flags_orig;
++      struct dentry *dentry;
 +
-+      bend = au_dbend(dentry);
-+      for (bsrc = bdst + 1; bsrc <= bend; bsrc++)
-+              if (au_h_dptr(dentry, bsrc))
-+                      break;
++      AuDebugOn(cpg->bsrc < 0);
++
++      dentry = cpg->dentry;
++      DiMustWriteLock(dentry);
 +
-+      err = au_lkup_neg(dentry, bdst);
++      err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
 +      if (!err) {
-+              err = au_cpup_single(dentry, bdst, bsrc, len, flags, NULL);
++              flags_orig = cpg->flags;
++              au_fset_cpup(cpg->flags, RENAME);
++              err = au_cpup_single(cpg, NULL);
++              cpg->flags = flags_orig;
 +              if (!err)
 +                      return 0; /* success */
 +
 +              /* revert */
-+              au_set_h_dptr(dentry, bdst, NULL);
-+              au_set_dbstart(dentry, bsrc);
++              au_set_h_dptr(dentry, cpg->bdst, NULL);
++              au_set_dbstart(dentry, cpg->bsrc);
 +      }
 +
 +      return err;
@@ -4077,37 +5447,44 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +
 +struct au_cpup_simple_args {
 +      int *errp;
-+      struct dentry *dentry;
-+      aufs_bindex_t bdst;
-+      loff_t len;
-+      unsigned int flags;
++      struct au_cp_generic *cpg;
 +};
 +
 +static void au_call_cpup_simple(void *args)
 +{
 +      struct au_cpup_simple_args *a = args;
-+      *a->errp = au_cpup_simple(a->dentry, a->bdst, a->len, a->flags);
++
++      au_pin_hdir_acquire_nest(a->cpg->pin);
++      *a->errp = au_cpup_simple(a->cpg);
++      au_pin_hdir_release(a->cpg->pin);
 +}
 +
-+int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+                     unsigned int flags)
++static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
 +{
 +      int err, wkq_err;
-+      struct dentry *parent;
++      struct dentry *dentry, *parent;
++      struct file *h_file;
 +      struct inode *h_dir;
 +
++      dentry = cpg->dentry;
++      h_file = NULL;
++      if (au_ftest_cpup(cpg->flags, HOPEN)) {
++              AuDebugOn(cpg->bsrc < 0);
++              h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
++              err = PTR_ERR(h_file);
++              if (IS_ERR(h_file))
++                      goto out;
++      }
++
 +      parent = dget_parent(dentry);
-+      h_dir = au_h_iptr(parent->d_inode, bdst);
++      h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
 +      if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
-+          && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
-+              err = au_cpup_simple(dentry, bdst, len, flags);
++          && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
++              err = au_cpup_simple(cpg);
 +      else {
 +              struct au_cpup_simple_args args = {
 +                      .errp           = &err,
-+                      .dentry         = dentry,
-+                      .bdst           = bdst,
-+                      .len            = len,
-+                      .flags          = flags
++                      .cpg            = cpg
 +              };
 +              wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
 +              if (unlikely(wkq_err))
@@ -4115,58 +5492,97 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +      }
 +
 +      dput(parent);
++      if (h_file)
++              au_h_open_post(dentry, cpg->bsrc, h_file);
++
++out:
 +      return err;
 +}
 +
++int au_sio_cpup_simple(struct au_cp_generic *cpg)
++{
++      aufs_bindex_t bsrc, bend;
++      struct dentry *dentry, *h_dentry;
++
++      if (cpg->bsrc < 0) {
++              dentry = cpg->dentry;
++              bend = au_dbend(dentry);
++              for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
++                      h_dentry = au_h_dptr(dentry, bsrc);
++                      if (h_dentry) {
++                              AuDebugOn(!h_dentry->d_inode);
++                              break;
++                      }
++              }
++              AuDebugOn(bsrc > bend);
++              cpg->bsrc = bsrc;
++      }
++      AuDebugOn(cpg->bsrc <= cpg->bdst);
++      return au_do_sio_cpup_simple(cpg);
++}
++
++int au_sio_cpdown_simple(struct au_cp_generic *cpg)
++{
++      AuDebugOn(cpg->bdst <= cpg->bsrc);
++      return au_do_sio_cpup_simple(cpg);
++}
++
 +/* ---------------------------------------------------------------------- */
 +
 +/*
 + * copyup the deleted file for writing.
 + */
-+static int au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
-+                       struct dentry *wh_dentry, struct file *file,
-+                       loff_t len)
++static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
++                       struct file *file)
 +{
 +      int err;
-+      aufs_bindex_t bstart;
-+      struct au_dinfo *dinfo;
++      unsigned int flags_orig;
++      aufs_bindex_t bsrc_orig;
 +      struct dentry *h_d_dst, *h_d_start;
++      struct au_dinfo *dinfo;
 +      struct au_hdentry *hdp;
 +
-+      dinfo = au_di(dentry);
++      dinfo = au_di(cpg->dentry);
 +      AuRwMustWriteLock(&dinfo->di_rwsem);
 +
-+      bstart = dinfo->di_bstart;
++      bsrc_orig = cpg->bsrc;
++      cpg->bsrc = dinfo->di_bstart;
 +      hdp = dinfo->di_hdentry;
-+      h_d_dst = hdp[0 + bdst].hd_dentry;
-+      dinfo->di_bstart = bdst;
-+      hdp[0 + bdst].hd_dentry = wh_dentry;
++      h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
++      dinfo->di_bstart = cpg->bdst;
++      hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
++      h_d_start = NULL;
 +      if (file) {
-+              h_d_start = hdp[0 + bstart].hd_dentry;
-+              hdp[0 + bstart].hd_dentry = au_hf_top(file)->f_dentry;
++              h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
++              hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
 +      }
-+      err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME,
-+                           /*h_parent*/NULL);
++      flags_orig = cpg->flags;
++      cpg->flags = !AuCpup_DTIME;
++      err = au_cpup_single(cpg, /*h_parent*/NULL);
++      cpg->flags = flags_orig;
 +      if (file) {
 +              if (!err)
 +                      err = au_reopen_nondir(file);
-+              hdp[0 + bstart].hd_dentry = h_d_start;
++              hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
 +      }
-+      hdp[0 + bdst].hd_dentry = h_d_dst;
-+      dinfo->di_bstart = bstart;
++      hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
++      dinfo->di_bstart = cpg->bsrc;
++      cpg->bsrc = bsrc_orig;
 +
 +      return err;
 +}
 +
-+static int au_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+                    struct file *file)
++static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
 +{
 +      int err;
++      aufs_bindex_t bdst;
 +      struct au_dtime dt;
-+      struct dentry *parent, *h_parent, *wh_dentry;
++      struct dentry *dentry, *parent, *h_parent, *wh_dentry;
 +      struct au_branch *br;
 +      struct path h_path;
 +
++      dentry = cpg->dentry;
++      bdst = cpg->bdst;
 +      br = au_sbr(dentry->d_sb, bdst);
 +      parent = dget_parent(dentry);
 +      h_parent = au_h_dptr(parent, bdst);
@@ -4176,21 +5592,23 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +              goto out;
 +
 +      h_path.dentry = h_parent;
-+      h_path.mnt = br->br_mnt;
++      h_path.mnt = au_br_mnt(br);
 +      au_dtime_store(&dt, parent, &h_path);
-+      err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len);
++      err = au_do_cpup_wh(cpg, wh_dentry, file);
 +      if (unlikely(err))
 +              goto out_wh;
 +
 +      dget(wh_dentry);
 +      h_path.dentry = wh_dentry;
-+      if (!S_ISDIR(wh_dentry->d_inode->i_mode))
-+              err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
-+      else
++      if (!d_is_dir(wh_dentry)) {
++              /* no delegation since it is just created */
++              err = vfsub_unlink(h_parent->d_inode, &h_path,
++                                 /*delegated*/NULL, /*force*/0);
++      } else
 +              err = vfsub_rmdir(h_parent->d_inode, &h_path);
 +      if (unlikely(err)) {
-+              AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
-+                      AuDLNPair(wh_dentry), err);
++              AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
++                      wh_dentry, err);
 +              err = -EIO;
 +      }
 +      au_dtime_revert(&dt);
@@ -4205,32 +5623,37 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +
 +struct au_cpup_wh_args {
 +      int *errp;
-+      struct dentry *dentry;
-+      aufs_bindex_t bdst;
-+      loff_t len;
++      struct au_cp_generic *cpg;
 +      struct file *file;
 +};
 +
 +static void au_call_cpup_wh(void *args)
 +{
 +      struct au_cpup_wh_args *a = args;
-+      *a->errp = au_cpup_wh(a->dentry, a->bdst, a->len, a->file);
++
++      au_pin_hdir_acquire_nest(a->cpg->pin);
++      *a->errp = au_cpup_wh(a->cpg, a->file);
++      au_pin_hdir_release(a->cpg->pin);
 +}
 +
-+int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+                 struct file *file)
++int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
 +{
 +      int err, wkq_err;
-+      struct dentry *parent, *h_orph, *h_parent, *h_dentry;
-+      struct inode *dir, *h_dir, *h_tmpdir, *h_inode;
++      aufs_bindex_t bdst;
++      struct dentry *dentry, *parent, *h_orph, *h_parent;
++      struct inode *dir, *h_dir, *h_tmpdir;
 +      struct au_wbr *wbr;
++      struct au_pin wh_pin, *pin_orig;
 +
++      dentry = cpg->dentry;
++      bdst = cpg->bdst;
 +      parent = dget_parent(dentry);
 +      dir = parent->d_inode;
 +      h_orph = NULL;
 +      h_parent = NULL;
 +      h_dir = au_igrab(au_h_iptr(dir, bdst));
 +      h_tmpdir = h_dir;
++      pin_orig = NULL;
 +      if (!h_dir->i_nlink) {
 +              wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
 +              h_orph = wbr->wbr_orph;
@@ -4240,28 +5663,22 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +              h_tmpdir = h_orph->d_inode;
 +              au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
 +
-+              /* this temporary unlock is safe */
-+              if (file)
-+                      h_dentry = au_hf_top(file)->f_dentry;
-+              else
-+                      h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
-+              h_inode = h_dentry->d_inode;
-+              IMustLock(h_inode);
-+              mutex_unlock(&h_inode->i_mutex);
 +              mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
-+              mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
 +              /* todo: au_h_open_pre()? */
++
++              pin_orig = cpg->pin;
++              au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
++                          AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
++              cpg->pin = &wh_pin;
 +      }
 +
 +      if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
-+          && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
-+              err = au_cpup_wh(dentry, bdst, len, file);
++          && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
++              err = au_cpup_wh(cpg, file);
 +      else {
 +              struct au_cpup_wh_args args = {
 +                      .errp   = &err,
-+                      .dentry = dentry,
-+                      .bdst   = bdst,
-+                      .len    = len,
++                      .cpg    = cpg,
 +                      .file   = file
 +              };
 +              wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
@@ -4274,6 +5691,8 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +              /* todo: au_h_open_post()? */
 +              au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
 +              au_set_h_dptr(parent, bdst, h_parent);
++              AuDebugOn(!pin_orig);
++              cpg->pin = pin_orig;
 +      }
 +      iput(h_dir);
 +      dput(parent);
@@ -4289,6 +5708,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +/* cf. revalidate function in file.c */
 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
 +             int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
++                       struct au_pin *pin,
 +                       struct dentry *h_parent, void *arg),
 +             void *arg)
 +{
@@ -4334,7 +5754,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +                      au_pin_set_dentry(&pin, d);
 +                      err = au_do_pin(&pin);
 +                      if (!err) {
-+                              err = cp(d, bdst, h_parent, arg);
++                              err = cp(d, bdst, &pin, h_parent, arg);
 +                              au_unpin(&pin);
 +                      }
 +              }
@@ -4351,10 +5771,19 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +}
 +
 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
-+                     struct dentry *h_parent __maybe_unused ,
++                     struct au_pin *pin,
++                     struct dentry *h_parent __maybe_unused,
 +                     void *arg __maybe_unused)
 +{
-+      return au_sio_cpup_simple(dentry, bdst, -1, AuCpup_DTIME);
++      struct au_cp_generic cpg = {
++              .dentry = dentry,
++              .bdst   = bdst,
++              .bsrc   = -1,
++              .len    = 0,
++              .pin    = pin,
++              .flags  = AuCpup_DTIME
++      };
++      return au_sio_cpup_simple(&cpg);
 +}
 +
 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
@@ -4387,10 +5816,10 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +}
 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
 --- /usr/share/empty/fs/aufs/cpup.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/cpup.h       2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,81 @@
++++ linux/fs/aufs/cpup.h       2015-06-22 08:27:37.874168290 +0200
+@@ -0,0 +1,94 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -4403,8 +5832,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -4420,8 +5848,9 @@ diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
 +
 +struct inode;
 +struct file;
++struct au_pin;
 +
-+void au_cpup_attr_flags(struct inode *dst, struct inode *src);
++void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
 +void au_cpup_attr_timesizes(struct inode *inode);
 +void au_cpup_attr_nlink(struct inode *inode, int force);
 +void au_cpup_attr_changeable(struct inode *inode);
@@ -4430,10 +5859,26 @@ diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
 +
 +/* ---------------------------------------------------------------------- */
 +
++struct au_cp_generic {
++      struct dentry   *dentry;
++      aufs_bindex_t   bdst, bsrc;
++      loff_t          len;
++      struct au_pin   *pin;
++      unsigned int    flags;
++};
++
 +/* cpup flags */
-+#define AuCpup_DTIME  1               /* do dtime_store/revert */
-+#define AuCpup_KEEPLINO       (1 << 1)        /* do not clear the lower xino,
-+                                         for link(2) */
++#define AuCpup_DTIME          1               /* do dtime_store/revert */
++#define AuCpup_KEEPLINO               (1 << 1)        /* do not clear the lower xino,
++                                                 for link(2) */
++#define AuCpup_RENAME         (1 << 2)        /* rename after cpup */
++#define AuCpup_HOPEN          (1 << 3)        /* call h_open_pre/post() in
++                                                 cpup */
++#define AuCpup_OVERWRITE      (1 << 4)        /* allow overwriting the
++                                                 existing entry */
++#define AuCpup_RWDST          (1 << 5)        /* force write target even if
++                                                 the branch is marked as RO */
++
 +#define au_ftest_cpup(flags, name)    ((flags) & AuCpup_##name)
 +#define au_fset_cpup(flags, name) \
 +      do { (flags) |= AuCpup_##name; } while (0)
@@ -4441,16 +5886,13 @@ diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
 +      do { (flags) &= ~AuCpup_##name; } while (0)
 +
 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
-+int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
-+                     aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+                     struct dentry *dst_parent);
-+int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+                     unsigned int flags);
-+int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+                 struct file *file);
++int au_sio_cpup_simple(struct au_cp_generic *cpg);
++int au_sio_cpdown_simple(struct au_cp_generic *cpg);
++int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
 +
 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
 +             int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
++                       struct au_pin *pin,
 +                       struct dentry *h_parent, void *arg),
 +             void *arg);
 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
@@ -4472,10 +5914,10 @@ diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
 +#endif /* __AUFS_CPUP_H__ */
 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dbgaufs.c    2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,334 @@
++++ linux/fs/aufs/dbgaufs.c    2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,432 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -4488,8 +5930,7 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -4539,7 +5980,7 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +      if (!xf)
 +              goto out;
 +
-+      err = vfs_getattr(xf->f_vfsmnt, xf->f_dentry, &st);
++      err = vfs_getattr(&xf->f_path, &st);
 +      if (!err) {
 +              if (do_fcnt)
 +                      p->n = snprintf
@@ -4572,22 +6013,117 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +
 +/* ---------------------------------------------------------------------- */
 +
-+static int dbgaufs_xib_open(struct inode *inode, struct file *file)
++struct dbgaufs_plink_arg {
++      int n;
++      char a[];
++};
++
++static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
++                               struct file *file)
 +{
-+      int err;
++      free_page((unsigned long)file->private_data);
++      return 0;
++}
++
++static int dbgaufs_plink_open(struct inode *inode, struct file *file)
++{
++      int err, i, limit;
++      unsigned long n, sum;
++      struct dbgaufs_plink_arg *p;
 +      struct au_sbinfo *sbinfo;
 +      struct super_block *sb;
++      struct au_sphlhead *sphl;
++
++      err = -ENOMEM;
++      p = (void *)get_zeroed_page(GFP_NOFS);
++      if (unlikely(!p))
++              goto out;
 +
++      err = -EFBIG;
 +      sbinfo = inode->i_private;
 +      sb = sbinfo->si_sb;
 +      si_noflush_read_lock(sb);
-+      err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
-+      si_read_unlock(sb);
-+      return err;
-+}
++      if (au_opt_test(au_mntflags(sb), PLINK)) {
++              limit = PAGE_SIZE - sizeof(p->n);
++
++              /* the number of buckets */
++              n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
++              p->n += n;
++              limit -= n;
++
++              sum = 0;
++              for (i = 0, sphl = sbinfo->si_plink;
++                   i < AuPlink_NHASH;
++                   i++, sphl++) {
++                      n = au_sphl_count(sphl);
++                      sum += n;
++
++                      n = snprintf(p->a + p->n, limit, "%lu ", n);
++                      p->n += n;
++                      limit -= n;
++                      if (unlikely(limit <= 0))
++                              goto out_free;
++              }
++              p->a[p->n - 1] = '\n';
 +
-+static const struct file_operations dbgaufs_xib_fop = {
-+      .owner          = THIS_MODULE,
++              /* the sum of plinks */
++              n = snprintf(p->a + p->n, limit, "%lu\n", sum);
++              p->n += n;
++              limit -= n;
++              if (unlikely(limit <= 0))
++                      goto out_free;
++      } else {
++#define str "1\n0\n0\n"
++              p->n = sizeof(str) - 1;
++              strcpy(p->a, str);
++#undef str
++      }
++      si_read_unlock(sb);
++
++      err = 0;
++      file->private_data = p;
++      goto out; /* success */
++
++out_free:
++      free_page((unsigned long)p);
++out:
++      return err;
++}
++
++static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
++                                size_t count, loff_t *ppos)
++{
++      struct dbgaufs_plink_arg *p;
++
++      p = file->private_data;
++      return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
++}
++
++static const struct file_operations dbgaufs_plink_fop = {
++      .owner          = THIS_MODULE,
++      .open           = dbgaufs_plink_open,
++      .release        = dbgaufs_plink_release,
++      .read           = dbgaufs_plink_read
++};
++
++/* ---------------------------------------------------------------------- */
++
++static int dbgaufs_xib_open(struct inode *inode, struct file *file)
++{
++      int err;
++      struct au_sbinfo *sbinfo;
++      struct super_block *sb;
++
++      sbinfo = inode->i_private;
++      sb = sbinfo->si_sb;
++      si_noflush_read_lock(sb);
++      err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
++      si_read_unlock(sb);
++      return err;
++}
++
++static const struct file_operations dbgaufs_xib_fop = {
++      .owner          = THIS_MODULE,
 +      .open           = dbgaufs_xib_open,
 +      .release        = dbgaufs_xi_release,
 +      .read           = dbgaufs_xi_read
@@ -4608,7 +6144,7 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +
 +      err = -ENOENT;
 +      xf = NULL;
-+      name = &file->f_dentry->d_name;
++      name = &file->f_path.dentry->d_name;
 +      if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
 +                   || memcmp(name->name, DbgaufsXi_PREFIX,
 +                             sizeof(DbgaufsXi_PREFIX) - 1)))
@@ -4651,10 +6187,8 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +      for (; bindex <= bend; bindex++) {
 +              br = au_sbr(sb, bindex);
 +              xi = &br->br_xino;
-+              if (xi->xi_dbgaufs) {
-+                      debugfs_remove(xi->xi_dbgaufs);
-+                      xi->xi_dbgaufs = NULL;
-+              }
++              debugfs_remove(xi->xi_dbgaufs);
++              xi->xi_dbgaufs = NULL;
 +      }
 +}
 +
@@ -4715,7 +6249,7 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +      int err;
 +
 +      /*
-+       * This function is a dynamic '__init' fucntion actually,
++       * This function is a dynamic '__init' function actually,
 +       * so the tiny check for si_rwsem is unnecessary.
 +       */
 +      /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
@@ -4741,7 +6275,7 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
 +{
 +      /*
-+       * This function is a dynamic '__init' fucntion actually,
++       * This function is a dynamic '__fin' function actually,
 +       * so the tiny check for si_rwsem is unnecessary.
 +       */
 +      /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
@@ -4757,7 +6291,7 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +      char name[SysaufsSiNameLen];
 +
 +      /*
-+       * This function is a dynamic '__init' fucntion actually,
++       * This function is a dynamic '__init' function actually,
 +       * so the tiny check for si_rwsem is unnecessary.
 +       */
 +      /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
@@ -4781,6 +6315,12 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +      if (unlikely(!sbinfo->si_dbgaufs_xib))
 +              goto out_dir;
 +
++      sbinfo->si_dbgaufs_plink = debugfs_create_file
++              ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
++               &dbgaufs_plink_fop);
++      if (unlikely(!sbinfo->si_dbgaufs_plink))
++              goto out_dir;
++
 +      err = dbgaufs_xigen_init(sbinfo);
 +      if (!err)
 +              goto out; /* success */
@@ -4810,10 +6350,10 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
 +}
 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dbgaufs.h    2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,49 @@
++++ linux/fs/aufs/dbgaufs.h    2015-06-22 08:27:37.874168290 +0200
+@@ -0,0 +1,48 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -4826,8 +6366,7 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -4863,10 +6402,10 @@ diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
 +#endif /* __DBGAUFS_H__ */
 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
 --- /usr/share/empty/fs/aufs/dcsub.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dcsub.c      2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,243 @@
++++ linux/fs/aufs/dcsub.c      2015-06-22 08:27:37.877501704 +0200
+@@ -0,0 +1,224 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -4879,8 +6418,7 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -4965,7 +6503,7 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
 +              dpages->ndpage++;
 +      }
 +
-+      AuDebugOn(!dentry->d_count);
++      AuDebugOn(au_dcount(dentry) <= 0);
 +      dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
 +      return 0; /* success */
 +
@@ -4973,78 +6511,60 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
 +      return err;
 +}
 +
-+int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
-+                 au_dpages_test test, void *arg)
-+{
++/* todo: BAD approach */
++/* copied from linux/fs/dcache.c */
++enum d_walk_ret {
++      D_WALK_CONTINUE,
++      D_WALK_QUIT,
++      D_WALK_NORETRY,
++      D_WALK_SKIP,
++};
++
++extern void d_walk(struct dentry *parent, void *data,
++                 enum d_walk_ret (*enter)(void *, struct dentry *),
++                 void (*finish)(void *));
++
++struct ac_dpages_arg {
 +      int err;
-+      struct dentry *this_parent;
-+      struct list_head *next;
-+      struct super_block *sb = root->d_sb;
++      struct au_dcsub_pages *dpages;
++      struct super_block *sb;
++      au_dpages_test test;
++      void *arg;
++};
 +
-+      err = 0;
-+      write_seqlock(&rename_lock);
-+      this_parent = root;
-+      spin_lock(&this_parent->d_lock);
-+repeat:
-+      next = this_parent->d_subdirs.next;
-+resume:
-+      if (this_parent->d_sb == sb
-+          && !IS_ROOT(this_parent)
-+          && au_di(this_parent)
-+          && this_parent->d_count
-+          && (!test || test(this_parent, arg))) {
-+              err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
-+              if (unlikely(err))
-+                      goto out;
-+      }
++static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
++{
++      enum d_walk_ret ret;
++      struct ac_dpages_arg *arg = _arg;
 +
-+      while (next != &this_parent->d_subdirs) {
-+              struct list_head *tmp = next;
-+              struct dentry *dentry = list_entry(tmp, struct dentry,
-+                                                 d_u.d_child);
-+
-+              next = tmp->next;
-+              spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
-+              if (dentry->d_count) {
-+                      if (!list_empty(&dentry->d_subdirs)) {
-+                              spin_unlock(&this_parent->d_lock);
-+                              spin_release(&dentry->d_lock.dep_map, 1,
-+                                           _RET_IP_);
-+                              this_parent = dentry;
-+                              spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
-+                                           _RET_IP_);
-+                              goto repeat;
-+                      }
-+                      if (dentry->d_sb == sb
-+                          && au_di(dentry)
-+                          && (!test || test(dentry, arg)))
-+                              err = au_dpages_append(dpages, dentry,
-+                                                     GFP_ATOMIC);
-+              }
-+              spin_unlock(&dentry->d_lock);
-+              if (unlikely(err))
-+                      goto out;
++      ret = D_WALK_CONTINUE;
++      if (dentry->d_sb == arg->sb
++          && !IS_ROOT(dentry)
++          && au_dcount(dentry) > 0
++          && au_di(dentry)
++          && (!arg->test || arg->test(dentry, arg->arg))) {
++              arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
++              if (unlikely(arg->err))
++                      ret = D_WALK_QUIT;
 +      }
 +
-+      if (this_parent != root) {
-+              struct dentry *tmp;
-+              struct dentry *child;
++      return ret;
++}
 +
-+              tmp = this_parent->d_parent;
-+              rcu_read_lock();
-+              spin_unlock(&this_parent->d_lock);
-+              child = this_parent;
-+              this_parent = tmp;
-+              spin_lock(&this_parent->d_lock);
-+              rcu_read_unlock();
-+              next = child->d_u.d_child.next;
-+              goto resume;
-+      }
++int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
++                 au_dpages_test test, void *arg)
++{
++      struct ac_dpages_arg args = {
++              .err    = 0,
++              .dpages = dpages,
++              .sb     = root->d_sb,
++              .test   = test,
++              .arg    = arg
++      };
 +
-+out:
-+      spin_unlock(&this_parent->d_lock);
-+      write_sequnlock(&rename_lock);
-+      return err;
++      d_walk(root, &args, au_call_dpages_append, NULL);
++
++      return args.err;
 +}
 +
 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
@@ -5056,7 +6576,7 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
 +      write_seqlock(&rename_lock);
 +      spin_lock(&dentry->d_lock);
 +      if (do_include
-+          && dentry->d_count
++          && au_dcount(dentry) > 0
 +          && (!test || test(dentry, arg)))
 +              err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
 +      spin_unlock(&dentry->d_lock);
@@ -5064,13 +6584,13 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
 +              goto out;
 +
 +      /*
-+       * vfsmount_lock is unnecessary since this is a traverse in a single
++       * RCU for vfsmount is unnecessary since this is a traverse in a single
 +       * mount
 +       */
 +      while (!IS_ROOT(dentry)) {
 +              dentry = dentry->d_parent; /* rename_lock is locked */
 +              spin_lock(&dentry->d_lock);
-+              if (dentry->d_count
++              if (au_dcount(dentry) > 0
 +                  && (!test || test(dentry, arg)))
 +                      err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
 +              spin_unlock(&dentry->d_lock);
@@ -5110,10 +6630,10 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
 +}
 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 --- /usr/share/empty/fs/aufs/dcsub.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dcsub.h      2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,94 @@
++++ linux/fs/aufs/dcsub.h      2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,132 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -5126,8 +6646,7 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -5142,8 +6661,6 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 +#include <linux/dcache.h>
 +#include <linux/fs.h>
 +
-+struct dentry;
-+
 +struct au_dpage {
 +      int ndentry;
 +      struct dentry **dentries;
@@ -5170,20 +6687,40 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 +
 +/* ---------------------------------------------------------------------- */
 +
++/*
++ * todo: in linux-3.13, several similar (but faster) helpers are added to
++ * include/linux/dcache.h. Try them (in the future).
++ */
++
 +static inline int au_d_hashed_positive(struct dentry *d)
 +{
 +      int err;
 +      struct inode *inode = d->d_inode;
++
 +      err = 0;
 +      if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
 +              err = -ENOENT;
 +      return err;
 +}
 +
++static inline int au_d_linkable(struct dentry *d)
++{
++      int err;
++      struct inode *inode = d->d_inode;
++
++      err = au_d_hashed_positive(d);
++      if (err
++          && inode
++          && (inode->i_state & I_LINKABLE))
++              err = 0;
++      return err;
++}
++
 +static inline int au_d_alive(struct dentry *d)
 +{
 +      int err;
 +      struct inode *inode;
++
 +      err = 0;
 +      if (!IS_ROOT(d))
 +              err = au_d_hashed_positive(d);
@@ -5198,20 +6735,41 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 +static inline int au_alive_dir(struct dentry *d)
 +{
 +      int err;
++
 +      err = au_d_alive(d);
 +      if (unlikely(err || IS_DEADDIR(d->d_inode)))
 +              err = -ENOENT;
 +      return err;
 +}
 +
++static inline int au_qstreq(struct qstr *a, struct qstr *b)
++{
++      return a->len == b->len
++              && !memcmp(a->name, b->name, a->len);
++}
++
++/*
++ * by the commit
++ * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
++ *                    taking d_lock
++ * the type of d_lockref.count became int, but the inlined function d_count()
++ * still returns unsigned int.
++ * I don't know why. Maybe it is for every d_count() users?
++ * Anyway au_dcount() lives on.
++ */
++static inline int au_dcount(struct dentry *d)
++{
++      return (int)d_count(d);
++}
++
 +#endif /* __KERNEL__ */
 +#endif /* __AUFS_DCSUB_H__ */
 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 --- /usr/share/empty/fs/aufs/debug.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/debug.c      2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,490 @@
++++ linux/fs/aufs/debug.c      2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,438 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -5224,21 +6782,50 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
 + * debug print functions
 + */
 +
-+#include <linux/vt_kern.h>
 +#include "aufs.h"
 +
-+int aufs_debug;
++/* Returns 0, or -errno.  arg is in kp->arg. */
++static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
++{
++      int err, n;
++
++      err = kstrtoint(val, 0, &n);
++      if (!err) {
++              if (n > 0)
++                      au_debug_on();
++              else
++                      au_debug_off();
++      }
++      return err;
++}
++
++/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
++static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
++{
++      atomic_t *a;
++
++      a = kp->arg;
++      return sprintf(buffer, "%d", atomic_read(a));
++}
++
++static struct kernel_param_ops param_ops_atomic_t = {
++      .set = param_atomic_t_set,
++      .get = param_atomic_t_get
++      /* void (*free)(void *arg) */
++};
++
++atomic_t aufs_debug = ATOMIC_INIT(0);
 +MODULE_PARM_DESC(debug, "debug print");
-+module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
++module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
 +
++DEFINE_MUTEX(au_dbg_mtx);     /* just to serialize the dbg msgs */
 +char *au_plevel = KERN_DEBUG;
 +#define dpri(fmt, ...) do {                                   \
 +      if ((au_plevel                                          \
@@ -5253,17 +6840,16 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +{
 +      unsigned long ul, n;
 +      struct hlist_head *head;
-+      struct au_vdir_wh *tpos;
-+      struct hlist_node *pos;
++      struct au_vdir_wh *pos;
 +
 +      n = whlist->nh_num;
 +      head = whlist->nh_head;
 +      for (ul = 0; ul < n; ul++) {
-+              hlist_for_each_entry(tpos, pos, head, wh_hash)
++              hlist_for_each_entry(pos, head, wh_hash)
 +                      dpri("b%d, %.*s, %d\n",
-+                           tpos->wh_bindex,
-+                           tpos->wh_str.len, tpos->wh_str.name,
-+                           tpos->wh_str.len);
++                           pos->wh_bindex,
++                           pos->wh_str.len, pos->wh_str.name,
++                           pos->wh_str.len);
 +              head++;
 +      }
 +}
@@ -5300,7 +6886,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +              return -1;
 +      }
 +
-+      /* the type of i_blocks depends upon CONFIG_LSF */
++      /* the type of i_blocks depends upon CONFIG_LBDAF */
 +      BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
 +                   && sizeof(inode->i_blocks) != sizeof(u64));
 +      if (wh) {
@@ -5350,10 +6936,9 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +void au_dpri_dalias(struct inode *inode)
 +{
 +      struct dentry *d;
-+      struct hlist_node *p;
 +
 +      spin_lock(&inode->i_lock);
-+      hlist_for_each_entry(d, p, &inode->i_dentry, d_alias)
++      hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
 +              au_dpri_dentry(d);
 +      spin_unlock(&inode->i_lock);
 +}
@@ -5362,6 +6947,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +{
 +      struct dentry *wh = NULL;
 +      int hn;
++      struct au_iinfo *iinfo;
 +
 +      if (!dentry || IS_ERR(dentry)) {
 +              dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
@@ -5369,14 +6955,14 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +      }
 +      /* do not call dget_parent() here */
 +      /* note: access d_xxx without d_lock */
-+      dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
-+           bindex,
-+           AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
++      dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
++           bindex, dentry, dentry,
 +           dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
-+           dentry->d_count, dentry->d_flags);
++           au_dcount(dentry), dentry->d_flags,
++           d_unhashed(dentry) ? "un" : "");
 +      hn = -1;
 +      if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
-+              struct au_iinfo *iinfo = au_ii(dentry->d_inode);
++              iinfo = au_ii(dentry->d_inode);
 +              if (iinfo) {
 +                      hn = !!au_hn(iinfo->ii_hinode + bindex);
 +                      wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
@@ -5400,9 +6986,10 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +      dinfo = au_di(dentry);
 +      if (!dinfo)
 +              return;
-+      dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
++      dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
 +           dinfo->di_bstart, dinfo->di_bend,
-+           dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
++           dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
++           dinfo->di_tmpfile);
 +      if (dinfo->di_bstart < 0)
 +              return;
 +      hdp = dinfo->di_hdentry;
@@ -5420,16 +7007,16 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +      }
 +      a[0] = 0;
 +      if (bindex < 0
-+          && file->f_dentry
-+          && au_test_aufs(file->f_dentry->d_sb)
++          && !IS_ERR_OR_NULL(file->f_path.dentry)
++          && au_test_aufs(file->f_path.dentry->d_sb)
 +          && au_fi(file))
 +              snprintf(a, sizeof(a), ", gen %d, mmapped %d",
 +                       au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
 +      dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
 +           bindex, file->f_mode, file->f_flags, (long)file_count(file),
 +           file->f_version, file->f_pos, a);
-+      if (file->f_dentry)
-+              do_pri_dentry(bindex, file->f_dentry);
++      if (!IS_ERR_OR_NULL(file->f_path.dentry))
++              do_pri_dentry(bindex, file->f_path.dentry);
 +      return 0;
 +}
 +
@@ -5442,7 +7029,9 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +      int err;
 +
 +      err = do_pri_file(-1, file);
-+      if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
++      if (err
++          || IS_ERR_OR_NULL(file->f_path.dentry)
++          || !au_test_aufs(file->f_path.dentry->d_sb))
 +              return;
 +
 +      finfo = au_fi(file);
@@ -5469,7 +7058,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +
 +      if (!br || IS_ERR(br))
 +              goto out;
-+      mnt = br->br_mnt;
++      mnt = au_br_mnt(br);
 +      if (!mnt || IS_ERR(mnt))
 +              goto out;
 +      sb = mnt->mnt_sb;
@@ -5510,7 +7099,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +
 +      a->mnt.mnt_sb = sb;
 +      a->fake.br_perm = 0;
-+      a->fake.br_mnt = &a->mnt;
++      a->fake.br_path.mnt = &a->mnt;
 +      a->fake.br_xino.xi_file = NULL;
 +      atomic_set(&a->fake.br_count, 0);
 +      smp_mb(); /* atomic_set */
@@ -5532,39 +7121,6 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +
 +/* ---------------------------------------------------------------------- */
 +
-+void au_dbg_sleep_jiffy(int jiffy)
-+{
-+      while (jiffy)
-+              jiffy = schedule_timeout_uninterruptible(jiffy);
-+}
-+
-+void au_dbg_iattr(struct iattr *ia)
-+{
-+#define AuBit(name)   if (ia->ia_valid & ATTR_ ## name) \
-+                              dpri(#name "\n")
-+      AuBit(MODE);
-+      AuBit(UID);
-+      AuBit(GID);
-+      AuBit(SIZE);
-+      AuBit(ATIME);
-+      AuBit(MTIME);
-+      AuBit(CTIME);
-+      AuBit(ATIME_SET);
-+      AuBit(MTIME_SET);
-+      AuBit(FORCE);
-+      AuBit(ATTR_FLAG);
-+      AuBit(KILL_SUID);
-+      AuBit(KILL_SGID);
-+      AuBit(FILE);
-+      AuBit(KILL_PRIV);
-+      AuBit(OPEN);
-+      AuBit(TIMES_SET);
-+#undef        AuBit
-+      dpri("ia_file %p\n", ia->ia_file);
-+}
-+
-+/* ---------------------------------------------------------------------- */
-+
 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
 +{
 +      struct inode *h_inode, *inode = dentry->d_inode;
@@ -5589,42 +7145,16 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +                      continue;
 +              h_inode = au_h_iptr(inode, bindex);
 +              if (unlikely(h_inode != h_dentry->d_inode)) {
-+                      int old = au_debug_test();
-+                      if (!old)
-+                              au_debug(1);
++                      au_debug_on();
 +                      AuDbg("b%d, %s:%d\n", bindex, func, line);
 +                      AuDbgDentry(dentry);
 +                      AuDbgInode(inode);
-+                      if (!old)
-+                              au_debug(0);
++                      au_debug_off();
 +                      BUG();
 +              }
 +      }
 +}
 +
-+void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
-+{
-+      struct dentry *parent;
-+
-+      parent = dget_parent(dentry);
-+      AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
-+      AuDebugOn(IS_ROOT(dentry));
-+      AuDebugOn(au_digen_test(parent, sigen));
-+      dput(parent);
-+}
-+
-+void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
-+{
-+      struct dentry *parent;
-+      struct inode *inode;
-+
-+      parent = dget_parent(dentry);
-+      inode = dentry->d_inode;
-+      AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
-+      AuDebugOn(au_digen_test(parent, sigen));
-+      dput(parent);
-+}
-+
 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
 +{
 +      int err, i, j;
@@ -5659,26 +7189,6 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +
 +/* ---------------------------------------------------------------------- */
 +
-+void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
-+{
-+#ifdef AuForceNoPlink
-+      au_opt_clr(sbinfo->si_mntflags, PLINK);
-+#endif
-+#ifdef AuForceNoXino
-+      au_opt_clr(sbinfo->si_mntflags, XINO);
-+#endif
-+#ifdef AuForceNoRefrof
-+      au_opt_clr(sbinfo->si_mntflags, REFROF);
-+#endif
-+#ifdef AuForceHnotify
-+      au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
-+#endif
-+#ifdef AuForceRd0
-+      sbinfo->si_rdblk = 0;
-+      sbinfo->si_rdhash = 0;
-+#endif
-+}
-+
 +int __init au_debug_init(void)
 +{
 +      aufs_bindex_t bindex;
@@ -5694,18 +7204,14 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +      pr_warn("CONFIG_4KSTACKS is defined.\n");
 +#endif
 +
-+#ifdef AuForceNoBrs
-+      sysaufs_brs = 0;
-+#endif
-+
 +      return 0;
 +}
 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 --- /usr/share/empty/fs/aufs/debug.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/debug.h      2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,242 @@
++++ linux/fs/aufs/debug.h      2015-06-22 08:27:37.877501704 +0200
+@@ -0,0 +1,228 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -5718,8 +7224,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -5731,6 +7236,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +
 +#ifdef __KERNEL__
 +
++#include <linux/atomic.h>
 +#include <linux/module.h>
 +#include <linux/kallsyms.h>
 +#include <linux/sysrq.h>
@@ -5739,23 +7245,29 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +#define AuDebugOn(a)          BUG_ON(a)
 +
 +/* module parameter */
-+extern int aufs_debug;
-+static inline void au_debug(int n)
++extern atomic_t aufs_debug;
++static inline void au_debug_on(void)
++{
++      atomic_inc(&aufs_debug);
++}
++static inline void au_debug_off(void)
 +{
-+      aufs_debug = n;
-+      smp_mb();
++      atomic_dec_if_positive(&aufs_debug);
 +}
 +
 +static inline int au_debug_test(void)
 +{
-+      return aufs_debug;
++      return atomic_read(&aufs_debug) > 0;
 +}
 +#else
 +#define AuDebugOn(a)          do {} while (0)
-+AuStubVoid(au_debug, int n)
++AuStubVoid(au_debug_on, void)
++AuStubVoid(au_debug_off, void)
 +AuStubInt0(au_debug_test, void)
 +#endif /* CONFIG_AUFS_DEBUG */
 +
++#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
++
 +/* ---------------------------------------------------------------------- */
 +
 +/* debug print */
@@ -5803,14 +7315,12 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +
 +/* dirty macros for debug print, use with "%.*s" and caution */
 +#define AuLNPair(qstr)                (qstr)->len, (qstr)->name
-+#define AuDLNPair(d)          AuLNPair(&(d)->d_name)
 +
 +/* ---------------------------------------------------------------------- */
 +
-+struct au_sbinfo;
-+struct au_finfo;
 +struct dentry;
 +#ifdef CONFIG_AUFS_DEBUG
++extern struct mutex au_dbg_mtx;
 +extern char *au_plevel;
 +struct au_nhash;
 +void au_dpri_whlist(struct au_nhash *whlist);
@@ -5825,67 +7335,60 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +struct super_block;
 +void au_dpri_sb(struct super_block *sb);
 +
-+void au_dbg_sleep_jiffy(int jiffy);
-+struct iattr;
-+void au_dbg_iattr(struct iattr *ia);
-+
 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
-+void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
-+void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
 +void au_dbg_verify_kthread(void);
 +
 +int __init au_debug_init(void);
-+void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
++
 +#define AuDbgWhlist(w) do { \
++      mutex_lock(&au_dbg_mtx); \
 +      AuDbg(#w "\n"); \
 +      au_dpri_whlist(w); \
++      mutex_unlock(&au_dbg_mtx); \
 +} while (0)
 +
 +#define AuDbgVdir(v) do { \
++      mutex_lock(&au_dbg_mtx); \
 +      AuDbg(#v "\n"); \
 +      au_dpri_vdir(v); \
++      mutex_unlock(&au_dbg_mtx); \
 +} while (0)
 +
 +#define AuDbgInode(i) do { \
++      mutex_lock(&au_dbg_mtx); \
 +      AuDbg(#i "\n"); \
 +      au_dpri_inode(i); \
++      mutex_unlock(&au_dbg_mtx); \
 +} while (0)
 +
 +#define AuDbgDAlias(i) do { \
++      mutex_lock(&au_dbg_mtx); \
 +      AuDbg(#i "\n"); \
 +      au_dpri_dalias(i); \
++      mutex_unlock(&au_dbg_mtx); \
 +} while (0)
 +
 +#define AuDbgDentry(d) do { \
++      mutex_lock(&au_dbg_mtx); \
 +      AuDbg(#d "\n"); \
 +      au_dpri_dentry(d); \
++      mutex_unlock(&au_dbg_mtx); \
 +} while (0)
 +
 +#define AuDbgFile(f) do { \
++      mutex_lock(&au_dbg_mtx); \
 +      AuDbg(#f "\n"); \
 +      au_dpri_file(f); \
++      mutex_unlock(&au_dbg_mtx); \
 +} while (0)
 +
 +#define AuDbgSb(sb) do { \
++      mutex_lock(&au_dbg_mtx); \
 +      AuDbg(#sb "\n"); \
 +      au_dpri_sb(sb); \
-+} while (0)
-+
-+#define AuDbgSleep(sec) do { \
-+      AuDbg("sleep %d sec\n", sec); \
-+      ssleep(sec); \
-+} while (0)
-+
-+#define AuDbgSleepJiffy(jiffy) do { \
-+      AuDbg("sleep %d jiffies\n", jiffy); \
-+      au_dbg_sleep_jiffy(jiffy); \
-+} while (0)
-+
-+#define AuDbgIAttr(ia) do { \
-+      AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
-+      au_dbg_iattr(ia); \
++      mutex_unlock(&au_dbg_mtx); \
 +} while (0)
 +
 +#define AuDbgSym(addr) do {                           \
@@ -5893,12 +7396,6 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +      sprint_symbol(sym, (unsigned long)addr);        \
 +      AuDbg("%s\n", sym);                             \
 +} while (0)
-+
-+#define AuInfoSym(addr) do {                          \
-+      char sym[KSYM_SYMBOL_LEN];                      \
-+      sprint_symbol(sym, (unsigned long)addr);        \
-+      AuInfo("%s\n", sym);                            \
-+} while (0)
 +#else
 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
@@ -5907,7 +7404,6 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
 +AuStubVoid(au_dbg_verify_kthread, void)
 +AuStubInt0(__init au_debug_init, void)
-+AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
 +
 +#define AuDbgWhlist(w)                do {} while (0)
 +#define AuDbgVdir(v)          do {} while (0)
@@ -5916,11 +7412,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +#define AuDbgDentry(d)                do {} while (0)
 +#define AuDbgFile(f)          do {} while (0)
 +#define AuDbgSb(sb)           do {} while (0)
-+#define AuDbgSleep(sec)               do {} while (0)
-+#define AuDbgSleepJiffy(jiffy)        do {} while (0)
-+#define AuDbgIAttr(ia)                do {} while (0)
 +#define AuDbgSym(addr)                do {} while (0)
-+#define AuInfoSym(addr)               do {} while (0)
 +#endif /* CONFIG_AUFS_DEBUG */
 +
 +/* ---------------------------------------------------------------------- */
@@ -5948,10 +7440,10 @@ diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
 +#endif /* __AUFS_DEBUG_H__ */
 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 --- /usr/share/empty/fs/aufs/dentry.c  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dentry.c     2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,1060 @@
++++ linux/fs/aufs/dentry.c     2015-06-22 08:27:37.877501704 +0200
+@@ -0,0 +1,1097 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -5964,8 +7456,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -5976,6 +7467,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +#include "aufs.h"
 +
 +#define AuLkup_ALLOW_NEG      1
++#define AuLkup_IGNORE_PERM    (1 << 1)
 +#define au_ftest_lkup(flags, name)    ((flags) & AuLkup_##name)
 +#define au_fset_lkup(flags, name) \
 +      do { (flags) |= AuLkup_##name; } while (0)
@@ -5997,17 +7489,19 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +           struct au_do_lookup_args *args)
 +{
 +      struct dentry *h_dentry;
-+      struct inode *h_inode, *inode;
++      struct inode *h_inode;
 +      struct au_branch *br;
 +      int wh_found, opq;
 +      unsigned char wh_able;
 +      const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
++      const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
++                                                        IGNORE_PERM);
 +
 +      wh_found = 0;
 +      br = au_sbr(dentry->d_sb, bindex);
 +      wh_able = !!au_br_whable(br->br_perm);
 +      if (wh_able)
-+              wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
++              wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
 +      h_dentry = ERR_PTR(wh_found);
 +      if (!wh_found)
 +              goto real_lookup;
@@ -6021,9 +7515,16 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              return NULL; /* success */
 +
 +real_lookup:
-+      h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
-+      if (IS_ERR(h_dentry))
++      if (!ignore_perm)
++              h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
++      else
++              h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
++      if (IS_ERR(h_dentry)) {
++              if (PTR_ERR(h_dentry) == -ENAMETOOLONG
++                  && !allow_neg)
++                      h_dentry = NULL;
 +              goto out;
++      }
 +
 +      h_inode = h_dentry->d_inode;
 +      if (!h_inode) {
@@ -6039,13 +7540,13 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              au_set_dbstart(dentry, bindex);
 +      au_set_h_dptr(dentry, bindex, h_dentry);
 +
-+      inode = dentry->d_inode;
-+      if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
-+          || (inode && !S_ISDIR(inode->i_mode)))
++      if (!d_is_dir(h_dentry)
++          || !wh_able
++          || (d_is_positive(dentry) && !d_is_dir(dentry)))
 +              goto out; /* success */
 +
 +      mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+      opq = au_diropq_test(h_dentry, br);
++      opq = au_diropq_test(h_dentry);
 +      mutex_unlock(&h_inode->i_mutex);
 +      if (opq > 0)
 +              au_set_dbdiropq(dentry, bindex);
@@ -6079,7 +7580,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +{
 +      int npositive, err;
 +      aufs_bindex_t bindex, btail, bdiropq;
-+      unsigned char isdir;
++      unsigned char isdir, dirperm1;
 +      struct qstr whname;
 +      struct au_do_lookup_args args = {
 +              .flags          = 0,
@@ -6088,8 +7589,10 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      const struct qstr *name = &dentry->d_name;
 +      struct dentry *parent;
 +      struct inode *inode;
++      struct super_block *sb;
 +
-+      err = au_test_shwh(dentry->d_sb, name);
++      sb = dentry->d_sb;
++      err = au_test_shwh(sb, name);
 +      if (unlikely(err))
 +              goto out;
 +
@@ -6098,9 +7601,10 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              goto out;
 +
 +      inode = dentry->d_inode;
-+      isdir = !!(inode && S_ISDIR(inode->i_mode));
++      isdir = !!d_is_dir(dentry);
 +      if (!type)
 +              au_fset_lkup(args.flags, ALLOW_NEG);
++      dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
 +
 +      npositive = 0;
 +      parent = dget_parent(dentry);
@@ -6118,12 +7622,10 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +                      continue;
 +              }
 +              h_parent = au_h_dptr(parent, bindex);
-+              if (!h_parent)
-+                      continue;
-+              h_dir = h_parent->d_inode;
-+              if (!h_dir || !S_ISDIR(h_dir->i_mode))
++              if (!h_parent || !d_is_dir(h_parent))
 +                      continue;
 +
++              h_dir = h_parent->d_inode;
 +              mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
 +              h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
 +                                      &args);
@@ -6131,7 +7633,10 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              err = PTR_ERR(h_dentry);
 +              if (IS_ERR(h_dentry))
 +                      goto out_parent;
-+              au_fclr_lkup(args.flags, ALLOW_NEG);
++              if (h_dentry)
++                      au_fclr_lkup(args.flags, ALLOW_NEG);
++              if (dirperm1)
++                      au_fset_lkup(args.flags, IGNORE_PERM);
 +
 +              if (au_dbwh(dentry) >= 0)
 +                      break;
@@ -6158,11 +7663,11 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              au_update_dbstart(dentry);
 +      }
 +      err = npositive;
-+      if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
++      if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
 +                   && au_dbstart(dentry) < 0)) {
 +              err = -EIO;
-+              AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
-+                      AuDLNPair(dentry), err);
++              AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
++                      dentry, err);
 +      }
 +
 +out_parent:
@@ -6172,8 +7677,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      return err;
 +}
 +
-+struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
-+                             struct au_branch *br)
++struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
 +{
 +      struct dentry *dentry;
 +      int wkq_err;
@@ -6198,22 +7702,25 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +/*
 + * lookup @dentry on @bindex which should be negative.
 + */
-+int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
++int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
 +{
 +      int err;
 +      struct dentry *parent, *h_parent, *h_dentry;
++      struct au_branch *br;
 +
 +      parent = dget_parent(dentry);
 +      h_parent = au_h_dptr(parent, bindex);
-+      h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent,
-+                                 au_sbr(dentry->d_sb, bindex));
++      br = au_sbr(dentry->d_sb, bindex);
++      if (wh)
++              h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
++      else
++              h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
 +      err = PTR_ERR(h_dentry);
 +      if (IS_ERR(h_dentry))
 +              goto out;
 +      if (unlikely(h_dentry->d_inode)) {
 +              err = -EIO;
-+              AuIOErr("%.*s should be negative on b%d.\n",
-+                      AuDLNPair(h_dentry), bindex);
++              AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
 +              dput(h_dentry);
 +              goto out;
 +      }
@@ -6462,16 +7969,14 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +static void au_hide(struct dentry *dentry)
 +{
 +      int err;
-+      struct inode *inode;
 +
 +      AuDbgDentry(dentry);
-+      inode = dentry->d_inode;
-+      if (inode && S_ISDIR(inode->i_mode)) {
++      if (d_is_dir(dentry)) {
 +              /* shrink_dcache_parent(dentry); */
 +              err = au_hide_children(dentry);
 +              if (unlikely(err))
-+                      AuIOErr("%.*s, failed hiding children, ignored %d\n",
-+                              AuDLNPair(dentry), err);
++                      AuIOErr("%pd, failed hiding children, ignored %d\n",
++                              dentry, err);
 +      }
 +      au_do_hide(dentry);
 +}
@@ -6659,7 +8164,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      if (!ebrange)
 +              ebrange = au_do_refresh_hdentry(dentry, parent);
 +
-+      if (d_unhashed(dentry) || ebrange) {
++      if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
 +              AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
 +              if (inode)
 +                      err = au_refresh_hinode_self(inode);
@@ -6702,8 +8207,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      au_update_digen(dentry);
 +out:
 +      if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
-+              AuIOErr("failed refreshing %.*s, %d\n",
-+                      AuDLNPair(dentry), err);
++              AuIOErr("failed refreshing %pd, %d\n", dentry, err);
 +              AuDbgDentry(dentry);
 +      }
 +      AuTraceErr(err);
@@ -6746,7 +8250,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      int err;
 +      umode_t mode, h_mode;
 +      aufs_bindex_t bindex, btail, bstart, ibs, ibe;
-+      unsigned char plus, unhashed, is_root, h_plus;
++      unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
 +      struct inode *h_inode, *h_cached_inode;
 +      struct dentry *h_dentry;
 +      struct qstr *name, *h_name;
@@ -6759,13 +8263,13 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      unhashed = !!d_unhashed(dentry);
 +      is_root = !!IS_ROOT(dentry);
 +      name = &dentry->d_name;
++      tmpfile = au_di(dentry)->di_tmpfile;
 +
 +      /*
 +       * Theoretically, REVAL test should be unnecessary in case of
 +       * {FS,I}NOTIFY.
 +       * But {fs,i}notify doesn't fire some necessary events,
 +       *      IN_ATTRIB for atime/nlink/pageio
-+       *      IN_DELETE for NFS dentry
 +       * Let's do REVAL test too.
 +       */
 +      if (do_udba && inode) {
@@ -6784,19 +8288,28 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              if (!h_dentry)
 +                      continue;
 +
-+              AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
++              AuDbg("b%d, %pd\n", bindex, h_dentry);
++              h_nfs = !!au_test_nfs(h_dentry->d_sb);
 +              spin_lock(&h_dentry->d_lock);
 +              h_name = &h_dentry->d_name;
 +              if (unlikely(do_udba
 +                           && !is_root
-+                           && (unhashed != !!d_unhashed(h_dentry)
-+                               || name->len != h_name->len
-+                               || memcmp(name->name, h_name->name, name->len))
++                           && ((!h_nfs
++                                && (unhashed != !!d_unhashed(h_dentry)
++                                    || (!tmpfile
++                                        && !au_qstreq(name, h_name))
++                                        ))
++                               || (h_nfs
++                                   && !(flags & LOOKUP_OPEN)
++                                   && (h_dentry->d_flags
++                                       & DCACHE_NFSFS_RENAMED)))
 +                          )) {
-+                      AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
-+                                unhashed, d_unhashed(h_dentry),
-+                                AuDLNPair(dentry), AuDLNPair(h_dentry));
++                      int h_unhashed;
++
++                      h_unhashed = d_unhashed(h_dentry);
 +                      spin_unlock(&h_dentry->d_lock);
++                      AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
++                            unhashed, h_unhashed, dentry, h_dentry);
 +                      goto err;
 +              }
 +              spin_unlock(&h_dentry->d_lock);
@@ -6825,17 +8338,27 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              if (inode && ibs <= bindex && bindex <= ibe)
 +                      h_cached_inode = au_h_iptr(inode, bindex);
 +
-+              if (unlikely(plus != h_plus
-+                           || mode != h_mode
++              if (!h_nfs) {
++                      if (unlikely(plus != h_plus && !tmpfile))
++                              goto err;
++              } else {
++                      if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
++                                   && !is_root
++                                   && !IS_ROOT(h_dentry)
++                                   && unhashed != d_unhashed(h_dentry)))
++                              goto err;
++              }
++              if (unlikely(mode != h_mode
 +                           || h_cached_inode != h_inode))
 +                      goto err;
 +              continue;
 +
-+      err:
++err:
 +              err = -EINVAL;
 +              break;
 +      }
 +
++      AuTraceErr(err);
 +      return err;
 +}
 +
@@ -6926,10 +8449,6 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      if (unlikely(!au_di(dentry)))
 +              goto out;
 +
-+      inode = dentry->d_inode;
-+      if (inode && is_bad_inode(inode))
-+              goto out;
-+
 +      valid = 1;
 +      sb = dentry->d_sb;
 +      /*
@@ -6943,6 +8462,12 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +              AuTraceErr(err);
 +              goto out;
 +      }
++      inode = dentry->d_inode;
++      if (unlikely(inode && is_bad_inode(inode))) {
++              err = -EINVAL;
++              AuTraceErr(err);
++              goto out_dgrade;
++      }
 +      if (unlikely(au_dbrange_test(dentry))) {
 +              err = -EINVAL;
 +              AuTraceErr(err);
@@ -6961,7 +8486,10 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      di_downgrade_lock(dentry, AuLock_IR);
 +
 +      err = -EINVAL;
-+      if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
++      if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
++          && inode
++          && !(inode->i_state && I_LINKABLE)
++          && (IS_DEADDIR(inode) || !inode->i_nlink))
 +              goto out_inval;
 +
 +      do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
@@ -6979,8 +8507,8 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      err = h_d_revalidate(dentry, inode, flags, do_udba);
 +      if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
 +              err = -EIO;
-+              AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
-+                    AuDLNPair(dentry), err);
++              AuDbg("both of real entry and whiteout found, %p, err %d\n",
++                    dentry, err);
 +      }
 +      goto out_inval;
 +
@@ -6992,7 +8520,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +      valid = !err;
 +out:
 +      if (!valid) {
-+              AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
++              AuDbg("%pd invalid, %d\n", dentry, valid);
 +              d_drop(dentry);
 +      }
 +      return valid;
@@ -7007,15 +8535,16 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +}
 +
 +const struct dentry_operations aufs_dop = {
-+      .d_revalidate   = aufs_d_revalidate,
-+      .d_release      = aufs_d_release
++      .d_revalidate           = aufs_d_revalidate,
++      .d_weak_revalidate      = aufs_d_revalidate,
++      .d_release              = aufs_d_release
 +};
 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
 --- /usr/share/empty/fs/aufs/dentry.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dentry.h     2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,234 @@
++++ linux/fs/aufs/dentry.h     2015-06-22 08:27:37.877501704 +0200
+@@ -0,0 +1,233 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -7028,8 +8557,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -7054,6 +8582,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
 +
 +      struct au_rwsem         di_rwsem;
 +      aufs_bindex_t           di_bstart, di_bend, di_bwh, di_bdiropq;
++      unsigned char           di_tmpfile; /* to allow the different name */
 +      struct au_hdentry       *di_hdentry;
 +} ____cacheline_aligned_in_smp;
 +
@@ -7062,13 +8591,12 @@ diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
 +/* dentry.c */
 +extern const struct dentry_operations aufs_dop;
 +struct au_branch;
-+struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
-+                             struct au_branch *br);
++struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
 +              struct dentry *h_parent, struct au_branch *br);
 +
 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
-+int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex);
++int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
 +
@@ -7250,10 +8778,10 @@ diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
 +#endif /* __AUFS_DENTRY_H__ */
 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
 --- /usr/share/empty/fs/aufs/dinfo.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dinfo.c      2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,543 @@
++++ linux/fs/aufs/dinfo.c      2015-06-22 08:27:37.877501704 +0200
+@@ -0,0 +1,544 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -7266,8 +8794,7 @@ diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -7304,6 +8831,7 @@ diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
 +              dinfo->di_bend = -1;
 +              dinfo->di_bwh = -1;
 +              dinfo->di_bdiropq = -1;
++              dinfo->di_tmpfile = 0;
 +              for (i = 0; i < nbr; i++)
 +                      dinfo->di_hdentry[i].hd_id = -1;
 +              goto out;
@@ -7572,13 +9100,14 @@ diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
 +              return NULL;
 +      AuDebugOn(bindex < 0);
 +      d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
-+      AuDebugOn(d && d->d_count <= 0);
++      AuDebugOn(d && au_dcount(d) <= 0);
 +      return d;
 +}
 +
 +/*
 + * extended version of au_h_dptr().
-+ * returns a hashed and positive h_dentry in bindex, NULL, or error.
++ * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
++ * error.
 + */
 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
 +{
@@ -7592,7 +9121,7 @@ diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
 +      if (au_dbstart(dentry) <= bindex
 +          && bindex <= au_dbend(dentry))
 +              h_dentry = au_h_dptr(dentry, bindex);
-+      if (h_dentry && !au_d_hashed_positive(h_dentry)) {
++      if (h_dentry && !au_d_linkable(h_dentry)) {
 +              dget(h_dentry);
 +              goto out; /* success */
 +      }
@@ -7603,7 +9132,7 @@ diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
 +      h_dentry = d_find_alias(h_inode);
 +      if (h_dentry) {
 +              if (!IS_ERR(h_dentry)) {
-+                      if (!au_d_hashed_positive(h_dentry))
++                      if (!au_d_linkable(h_dentry))
 +                              goto out; /* success */
 +                      dput(h_dentry);
 +              } else
@@ -7797,10 +9326,10 @@ diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
 +}
 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 --- /usr/share/empty/fs/aufs/dir.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dir.c        2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,633 @@
++++ linux/fs/aufs/dir.c        2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,751 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -7813,8 +9342,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -7834,6 +9362,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      nlink += h_dir->i_nlink - 2;
 +      if (h_dir->i_nlink < 2)
 +              nlink += 2;
++      smp_mb(); /* for i_nlink */
 +      /* 0 can happen in revaliding */
 +      set_nlink(dir, nlink);
 +}
@@ -7848,6 +9377,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      nlink -= h_dir->i_nlink - 2;
 +      if (h_dir->i_nlink < 2)
 +              nlink -= 2;
++      smp_mb(); /* for i_nlink */
 +      /* nlink == 0 means the branch-fs is broken */
 +      set_nlink(dir, nlink);
 +}
@@ -7861,24 +9391,19 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +
 +      sz = 0;
 +      if (file) {
-+              AuDebugOn(!file->f_dentry);
-+              AuDebugOn(!file->f_dentry->d_inode);
-+              AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode));
++              AuDebugOn(!d_is_dir(file->f_path.dentry));
 +
 +              bend = au_fbend_dir(file);
 +              for (bindex = au_fbstart(file);
 +                   bindex <= bend && sz < KMALLOC_MAX_SIZE;
 +                   bindex++) {
 +                      h_file = au_hf_dir(file, bindex);
-+                      if (h_file
-+                          && h_file->f_dentry
-+                          && h_file->f_dentry->d_inode)
-+                              sz += i_size_read(h_file->f_dentry->d_inode);
++                      if (h_file && file_inode(h_file))
++                              sz += vfsub_f_size_read(h_file);
 +              }
 +      } else {
 +              AuDebugOn(!dentry);
-+              AuDebugOn(!dentry->d_inode);
-+              AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
++              AuDebugOn(!d_is_dir(dentry));
 +
 +              bend = au_dbtaildir(dentry);
 +              for (bindex = au_dbstart(dentry);
@@ -7900,38 +9425,142 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      return sz;
 +}
 +
-+/* ---------------------------------------------------------------------- */
++struct au_dir_ts_arg {
++      struct dentry *dentry;
++      aufs_bindex_t brid;
++};
 +
-+static int reopen_dir(struct file *file)
++static void au_do_dir_ts(void *arg)
 +{
++      struct au_dir_ts_arg *a = arg;
++      struct au_dtime dt;
++      struct path h_path;
++      struct inode *dir, *h_dir;
++      struct super_block *sb;
++      struct au_branch *br;
++      struct au_hinode *hdir;
 +      int err;
-+      unsigned int flags;
-+      aufs_bindex_t bindex, btail, bstart;
-+      struct dentry *dentry, *h_dentry;
-+      struct file *h_file;
-+
-+      /* open all lower dirs */
-+      dentry = file->f_dentry;
-+      bstart = au_dbstart(dentry);
-+      for (bindex = au_fbstart(file); bindex < bstart; bindex++)
-+              au_set_h_fptr(file, bindex, NULL);
-+      au_set_fbstart(file, bstart);
++      aufs_bindex_t bstart, bindex;
 +
-+      btail = au_dbtaildir(dentry);
-+      for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
-+              au_set_h_fptr(file, bindex, NULL);
-+      au_set_fbend_dir(file, btail);
++      sb = a->dentry->d_sb;
++      dir = a->dentry->d_inode;
++      if (!dir)
++              goto out;
++      /* no dir->i_mutex lock */
++      aufs_read_lock(a->dentry, AuLock_DW | AuLock_DIR); /* noflush */
 +
-+      flags = vfsub_file_flags(file);
-+      for (bindex = bstart; bindex <= btail; bindex++) {
-+              h_dentry = au_h_dptr(dentry, bindex);
-+              if (!h_dentry)
-+                      continue;
-+              h_file = au_hf_dir(file, bindex);
-+              if (h_file)
-+                      continue;
++      bstart = au_ibstart(dir);
++      bindex = au_br_index(sb, a->brid);
++      if (bindex < bstart)
++              goto out_unlock;
 +
-+              h_file = au_h_open(dentry, bindex, flags, file);
++      br = au_sbr(sb, bindex);
++      h_path.dentry = au_h_dptr(a->dentry, bindex);
++      if (!h_path.dentry)
++              goto out_unlock;
++      h_path.mnt = au_br_mnt(br);
++      au_dtime_store(&dt, a->dentry, &h_path);
++
++      br = au_sbr(sb, bstart);
++      if (!au_br_writable(br->br_perm))
++              goto out_unlock;
++      h_path.dentry = au_h_dptr(a->dentry, bstart);
++      h_path.mnt = au_br_mnt(br);
++      err = vfsub_mnt_want_write(h_path.mnt);
++      if (err)
++              goto out_unlock;
++      hdir = au_hi(dir, bstart);
++      au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
++      h_dir = au_h_iptr(dir, bstart);
++      if (h_dir->i_nlink
++          && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
++              dt.dt_h_path = h_path;
++              au_dtime_revert(&dt);
++      }
++      au_hn_imtx_unlock(hdir);
++      vfsub_mnt_drop_write(h_path.mnt);
++      au_cpup_attr_timesizes(dir);
++
++out_unlock:
++      aufs_read_unlock(a->dentry, AuLock_DW);
++out:
++      dput(a->dentry);
++      au_nwt_done(&au_sbi(sb)->si_nowait);
++      kfree(arg);
++}
++
++void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
++{
++      int perm, wkq_err;
++      aufs_bindex_t bstart;
++      struct au_dir_ts_arg *arg;
++      struct dentry *dentry;
++      struct super_block *sb;
++
++      IMustLock(dir);
++
++      dentry = d_find_any_alias(dir);
++      AuDebugOn(!dentry);
++      sb = dentry->d_sb;
++      bstart = au_ibstart(dir);
++      if (bstart == bindex) {
++              au_cpup_attr_timesizes(dir);
++              goto out;
++      }
++
++      perm = au_sbr_perm(sb, bstart);
++      if (!au_br_writable(perm))
++              goto out;
++
++      arg = kmalloc(sizeof(*arg), GFP_NOFS);
++      if (!arg)
++              goto out;
++
++      arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
++      arg->brid = au_sbr_id(sb, bindex);
++      wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
++      if (unlikely(wkq_err)) {
++              pr_err("wkq %d\n", wkq_err);
++              dput(dentry);
++              kfree(arg);
++      }
++
++out:
++      dput(dentry);
++}
++
++/* ---------------------------------------------------------------------- */
++
++static int reopen_dir(struct file *file)
++{
++      int err;
++      unsigned int flags;
++      aufs_bindex_t bindex, btail, bstart;
++      struct dentry *dentry, *h_dentry;
++      struct file *h_file;
++
++      /* open all lower dirs */
++      dentry = file->f_path.dentry;
++      bstart = au_dbstart(dentry);
++      for (bindex = au_fbstart(file); bindex < bstart; bindex++)
++              au_set_h_fptr(file, bindex, NULL);
++      au_set_fbstart(file, bstart);
++
++      btail = au_dbtaildir(dentry);
++      for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
++              au_set_h_fptr(file, bindex, NULL);
++      au_set_fbend_dir(file, btail);
++
++      flags = vfsub_file_flags(file);
++      for (bindex = bstart; bindex <= btail; bindex++) {
++              h_dentry = au_h_dptr(dentry, bindex);
++              if (!h_dentry)
++                      continue;
++              h_file = au_hf_dir(file, bindex);
++              if (h_file)
++                      continue;
++
++              h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
 +              err = PTR_ERR(h_file);
 +              if (IS_ERR(h_file))
 +                      goto out; /* close all? */
@@ -7946,20 +9575,17 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      return err;
 +}
 +
-+static int do_open_dir(struct file *file, int flags)
++static int do_open_dir(struct file *file, int flags, struct file *h_file)
 +{
 +      int err;
 +      aufs_bindex_t bindex, btail;
 +      struct dentry *dentry, *h_dentry;
-+      struct file *h_file;
 +
 +      FiMustWriteLock(file);
++      AuDebugOn(h_file);
 +
-+      dentry = file->f_dentry;
-+      err = au_alive_dir(dentry);
-+      if (unlikely(err))
-+              goto out;
-+
++      err = 0;
++      dentry = file->f_path.dentry;
 +      file->f_version = dentry->d_inode->i_version;
 +      bindex = au_dbstart(dentry);
 +      au_set_fbstart(file, bindex);
@@ -7970,7 +9596,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +              if (!h_dentry)
 +                      continue;
 +
-+              h_file = au_h_open(dentry, bindex, flags, file);
++              h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
 +              if (IS_ERR(h_file)) {
 +                      err = PTR_ERR(h_file);
 +                      break;
@@ -7989,7 +9615,6 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      au_set_fbstart(file, -1);
 +      au_set_fbend_dir(file, -1);
 +
-+out:
 +      return err;
 +}
 +
@@ -8001,11 +9626,15 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      struct au_fidir *fidir;
 +
 +      err = -ENOMEM;
-+      sb = file->f_dentry->d_sb;
++      sb = file->f_path.dentry->d_sb;
 +      si_read_lock(sb, AuLock_FLUSH);
 +      fidir = au_fidir_alloc(sb);
 +      if (fidir) {
-+              err = au_do_open(file, do_open_dir, fidir);
++              struct au_do_open_args args = {
++                      .open   = do_open_dir,
++                      .fidir  = fidir
++              };
++              err = au_do_open(file, &args);
 +              if (unlikely(err))
 +                      kfree(fidir);
 +      }
@@ -8024,6 +9653,8 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      finfo = au_fi(file);
 +      fidir = finfo->fi_hdir;
 +      if (fidir) {
++              au_sphl_del(&finfo->fi_hlist,
++                          &au_sbi(file->f_path.dentry->d_sb)->si_files);
 +              vdir_cache = fidir->fd_vdir_cache; /* lock-free */
 +              if (vdir_cache)
 +                      au_vdir_free(vdir_cache);
@@ -8110,8 +9741,8 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      if (unlikely(err))
 +              goto out;
 +
-+      sb = file->f_dentry->d_sb;
-+      inode = file->f_dentry->d_inode;
++      inode = file_inode(file);
++      sb = inode->i_sb;
 +      bend = au_fbend_dir(file);
 +      for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
 +              h_file = au_hf_dir(file, bindex);
@@ -8137,7 +9768,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      struct mutex *mtx;
 +
 +      err = 0;
-+      dentry = file->f_dentry;
++      dentry = file->f_path.dentry;
 +      mtx = &dentry->d_inode->i_mutex;
 +      mutex_lock(mtx);
 +      sb = dentry->d_sb;
@@ -8160,14 +9791,16 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +
 +/* ---------------------------------------------------------------------- */
 +
-+static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
++static int aufs_iterate(struct file *file, struct dir_context *ctx)
 +{
 +      int err;
 +      struct dentry *dentry;
 +      struct inode *inode, *h_inode;
 +      struct super_block *sb;
 +
-+      dentry = file->f_dentry;
++      AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
++
++      dentry = file->f_path.dentry;
 +      inode = dentry->d_inode;
 +      IMustLock(inode);
 +
@@ -8185,7 +9818,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +
 +      h_inode = au_h_iptr(inode, au_ibstart(inode));
 +      if (!au_test_nfsd()) {
-+              err = au_vdir_fill_de(file, dirent, filldir);
++              err = au_vdir_fill_de(file, ctx);
 +              fsstack_copy_attr_atime(inode, h_inode);
 +      } else {
 +              /*
@@ -8195,7 +9828,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +              atomic_inc(&h_inode->i_count);
 +              di_read_unlock(dentry, AuLock_IR);
 +              si_read_unlock(sb);
-+              err = au_vdir_fill_de(file, dirent, filldir);
++              err = au_vdir_fill_de(file, ctx);
 +              fsstack_copy_attr_atime(inode, h_inode);
 +              fi_write_unlock(file);
 +              iput(h_inode);
@@ -8229,17 +9862,19 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +#endif
 +
 +struct test_empty_arg {
++      struct dir_context ctx;
 +      struct au_nhash *whlist;
 +      unsigned int flags;
 +      int err;
 +      aufs_bindex_t bindex;
 +};
 +
-+static int test_empty_cb(void *__arg, const char *__name, int namelen,
-+                       loff_t offset __maybe_unused, u64 ino,
++static int test_empty_cb(struct dir_context *ctx, const char *__name,
++                       int namelen, loff_t offset __maybe_unused, u64 ino,
 +                       unsigned int d_type)
 +{
-+      struct test_empty_arg *arg = __arg;
++      struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
++                                                ctx);
 +      char *name = (void *)__name;
 +
 +      arg->err = 0;
@@ -8277,21 +9912,21 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +
 +      h_file = au_h_open(dentry, arg->bindex,
 +                         O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
-+                         /*file*/NULL);
++                         /*file*/NULL, /*force_wr*/0);
 +      err = PTR_ERR(h_file);
 +      if (IS_ERR(h_file))
 +              goto out;
 +
 +      err = 0;
 +      if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
-+          && !h_file->f_dentry->d_inode->i_nlink)
++          && !file_inode(h_file)->i_nlink)
 +              goto out_put;
 +
 +      do {
 +              arg->err = 0;
 +              au_fclr_testempty(arg->flags, CALLED);
 +              /* smp_mb(); */
-+              err = vfsub_readdir(h_file, test_empty_cb, arg);
++              err = vfsub_iterate_dir(h_file, &arg->ctx);
 +              if (err >= 0)
 +                      err = arg->err;
 +      } while (!err && au_ftest_testempty(arg->flags, CALLED));
@@ -8352,7 +9987,12 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      unsigned int rdhash;
 +      aufs_bindex_t bindex, bstart, btail;
 +      struct au_nhash whlist;
-+      struct test_empty_arg arg;
++      struct test_empty_arg arg = {
++              .ctx = {
++                      .actor = test_empty_cb
++              }
++      };
++      int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
 +
 +      SiMustAnyLock(dentry->d_sb);
 +
@@ -8368,8 +10008,11 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      bstart = au_dbstart(dentry);
 +      if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
 +              au_fset_testempty(arg.flags, SHWH);
++      test_empty = do_test_empty;
++      if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
++              test_empty = sio_test_empty;
 +      arg.bindex = bstart;
-+      err = do_test_empty(dentry, &arg);
++      err = test_empty(dentry, &arg);
 +      if (unlikely(err))
 +              goto out_whlist;
 +
@@ -8381,7 +10024,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +              h_dentry = au_h_dptr(dentry, bindex);
 +              if (h_dentry && h_dentry->d_inode) {
 +                      arg.bindex = bindex;
-+                      err = do_test_empty(dentry, &arg);
++                      err = test_empty(dentry, &arg);
 +              }
 +      }
 +
@@ -8394,7 +10037,11 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
 +{
 +      int err;
-+      struct test_empty_arg arg;
++      struct test_empty_arg arg = {
++              .ctx = {
++                      .actor = test_empty_cb
++              }
++      };
 +      aufs_bindex_t bindex, btail;
 +
 +      err = 0;
@@ -8422,7 +10069,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +      .owner          = THIS_MODULE,
 +      .llseek         = default_llseek,
 +      .read           = generic_read_dir,
-+      .readdir        = aufs_readdir,
++      .iterate        = aufs_iterate,
 +      .unlocked_ioctl = aufs_ioctl_dir,
 +#ifdef CONFIG_COMPAT
 +      .compat_ioctl   = aufs_compat_ioctl_dir,
@@ -8434,10 +10081,10 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +};
 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
 --- /usr/share/empty/fs/aufs/dir.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dir.h        2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,137 @@
++++ linux/fs/aufs/dir.h        2015-06-22 08:27:37.877501704 +0200
+@@ -0,0 +1,131 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -8450,8 +10097,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -8529,6 +10175,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
++void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
 +int au_test_empty_lower(struct dentry *dentry);
 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
 +
@@ -8544,7 +10191,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
 +                     unsigned char shwh);
 +void au_vdir_free(struct au_vdir *vdir);
 +int au_vdir_init(struct file *file);
-+int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
++int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
 +
 +/* ioctl.c */
 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
@@ -8557,17 +10204,11 @@ diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
 +                       unsigned long arg);
 +#endif
 +#else
-+static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
-+                              unsigned long arg)
-+{
-+      return -EINVAL;
-+}
++AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
++       unsigned int cmd, unsigned long arg)
 +#ifdef CONFIG_COMPAT
-+static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
-+                                     unsigned long arg)
-+{
-+      return -EINVAL;
-+}
++AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
++       unsigned int cmd, unsigned long arg)
 +#endif
 +#endif
 +
@@ -8575,10 +10216,10 @@ diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
 +#endif /* __AUFS_DIR_H__ */
 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
 --- /usr/share/empty/fs/aufs/dynop.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dynop.c      2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,379 @@
++++ linux/fs/aufs/dynop.c      2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,369 @@
 +/*
-+ * Copyright (C) 2010-2013 Junjiro R. Okajima
++ * Copyright (C) 2010-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -8591,8 +10232,7 @@ diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -8766,18 +10406,17 @@ diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
 +      DySetAop(invalidatepage);
 +      DySetAop(releasepage);
 +      DySetAop(freepage);
-+      /* these two will be changed according to an aufs mount option */
++      /* this one will be changed according to an aufs mount option */
 +      DySetAop(direct_IO);
-+      DySetAop(get_xip_mem);
 +      DySetAop(migratepage);
 +      DySetAop(launder_page);
 +      DySetAop(is_partially_uptodate);
++      DySetAop(is_dirty_writeback);
 +      DySetAop(error_remove_page);
 +      DySetAop(swap_activate);
 +      DySetAop(swap_deactivate);
 +
 +      DyDbgSize(cnt, *h_aop);
-+      dyaop->da_get_xip_mem = h_aop->get_xip_mem;
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -8818,7 +10457,7 @@ diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
 +
 +      key->dk_op.dy_hop = op->dy_hop;
 +      kref_init(&key->dk_kref);
-+      p->set(key, op->dy_hop, br->br_mnt->mnt_sb);
++      p->set(key, op->dy_hop, au_br_sb(br));
 +      old = dy_gadd(spl, key);
 +      if (old) {
 +              kfree(key);
@@ -8837,25 +10476,17 @@ diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
 +/* ---------------------------------------------------------------------- */
 +/*
 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
-+ * This behaviour is neccessary to return an error from open(O_DIRECT) instead
++ * This behaviour is necessary to return an error from open(O_DIRECT) instead
 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
 + * See the aufs manual in detail.
-+ *
-+ * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
-+ * performance of fadvise() and madvise() may be affected.
 + */
 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
 +{
-+      if (!do_dx) {
++      if (!do_dx)
 +              dyaop->da_op.direct_IO = NULL;
-+              dyaop->da_op.get_xip_mem = NULL;
-+      } else {
++      else
 +              dyaop->da_op.direct_IO = aufs_aop.direct_IO;
-+              dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
-+              if (!dyaop->da_get_xip_mem)
-+                      dyaop->da_op.get_xip_mem = NULL;
-+      }
 +}
 +
 +static struct au_dyaop *dy_aget(struct au_branch *br,
@@ -8958,10 +10589,10 @@ diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
 +}
 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
 --- /usr/share/empty/fs/aufs/dynop.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dynop.h      2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,76 @@
++++ linux/fs/aufs/dynop.h      2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,74 @@
 +/*
-+ * Copyright (C) 2010-2013 Junjiro R. Okajima
++ * Copyright (C) 2010-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -8974,8 +10605,7 @@ diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -8987,7 +10617,8 @@ diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
 +
 +#ifdef __KERNEL__
 +
-+#include "inode.h"
++#include <linux/fs.h>
++#include <linux/kref.h>
 +
 +enum {AuDy_AOP, AuDyLast};
 +
@@ -9017,8 +10648,6 @@ diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
 +struct au_dyaop {
 +      struct au_dykey                 da_key;
 +      struct address_space_operations da_op; /* not const */
-+      int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
-+                            void **, unsigned long *);
 +};
 +
 +/* ---------------------------------------------------------------------- */
@@ -9038,10 +10667,10 @@ diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
 +#endif /* __AUFS_DYNOP_H__ */
 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 --- /usr/share/empty/fs/aufs/export.c  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/export.c     2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,827 @@
++++ linux/fs/aufs/export.c     2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,831 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -9054,8 +10683,7 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -9204,7 +10832,7 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      file = sbinfo->si_xigen;
 +      BUG_ON(!file);
 +
-+      if (i_size_read(file->f_dentry->d_inode)
++      if (vfsub_f_size_read(file)
 +          < pos + sizeof(inode->i_generation)) {
 +              inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
 +              sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
@@ -9268,7 +10896,6 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      struct dentry *dentry, *d;
 +      struct inode *inode;
 +      unsigned int sigen;
-+      struct hlist_node *p;
 +
 +      dentry = NULL;
 +      inode = ilookup(sb, ino);
@@ -9287,7 +10914,7 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +              dentry = d_find_alias(inode);
 +      else {
 +              spin_lock(&inode->i_lock);
-+              hlist_for_each_entry(d, p, &inode->i_dentry, d_alias) {
++              hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
 +                      spin_lock(&d->d_lock);
 +                      if (!au_test_anon(d)
 +                          && d->d_parent->d_inode->i_ino == dir_ino) {
@@ -9344,9 +10971,9 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      };
 +
 +      get_fs_root(current->fs, &root);
-+      br_read_lock(&vfsmount_lock);
++      rcu_read_lock();
 +      err = iterate_mounts(au_compare_mnt, &args, root.mnt);
-+      br_read_unlock(&vfsmount_lock);
++      rcu_read_unlock();
 +      path_put(&root);
 +      AuDebugOn(!err);
 +      AuDebugOn(!args.mnt);
@@ -9384,6 +11011,7 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +}
 +
 +struct find_name_by_ino {
++      struct dir_context ctx;
 +      int called, found;
 +      ino_t ino;
 +      char *name;
@@ -9391,10 +11019,11 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +};
 +
 +static int
-+find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
-+               u64 ino, unsigned int d_type)
++find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
++               loff_t offset, u64 ino, unsigned int d_type)
 +{
-+      struct find_name_by_ino *a = arg;
++      struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
++                                                ctx);
 +
 +      a->called++;
 +      if (a->ino != ino)
@@ -9412,7 +11041,11 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      struct dentry *dentry, *parent;
 +      struct file *file;
 +      struct inode *dir;
-+      struct find_name_by_ino arg;
++      struct find_name_by_ino arg = {
++              .ctx = {
++                      .actor = find_name_by_ino
++              }
++      };
 +      int err;
 +
 +      parent = path->dentry;
@@ -9432,7 +11065,7 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      do {
 +              arg.called = 0;
 +              /* smp_mb(); */
-+              err = vfsub_readdir(file, find_name_by_ino, &arg);
++              err = vfsub_iterate_dir(file, &arg.ctx);
 +      } while (!err && !arg.found && arg.called);
 +      dentry = ERR_PTR(err);
 +      if (unlikely(err))
@@ -9550,7 +11183,7 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      struct path path;
 +
 +      br = au_sbr(sb, nsi_lock->bindex);
-+      h_mnt = br->br_mnt;
++      h_mnt = au_br_mnt(br);
 +      h_sb = h_mnt->mnt_sb;
 +      /* todo: call lower fh_to_dentry()? fh_to_parent()? */
 +      h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
@@ -9752,7 +11385,7 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      ii_read_lock_child(inode);
 +      bindex = au_ibstart(inode);
 +      if (!dir) {
-+              dentry = d_find_alias(inode);
++              dentry = d_find_any_alias(inode);
 +              if (unlikely(!dentry))
 +                      goto out_unlock;
 +              AuDebugOn(au_test_anon(dentry));
@@ -9768,13 +11401,13 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      ii_read_unlock(dir);
 +      if (unlikely(!h_dir))
 +              goto out_parent;
-+      h_parent = d_find_alias(h_dir);
++      h_parent = d_find_any_alias(h_dir);
 +      if (unlikely(!h_parent))
 +              goto out_hparent;
 +
 +      err = -EPERM;
 +      br = au_sbr(sb, bindex);
-+      h_sb = br->br_mnt->mnt_sb;
++      h_sb = au_br_sb(br);
 +      if (unlikely(!h_sb->s_export_op)) {
 +              AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
 +              goto out_hparent;
@@ -9867,12 +11500,12 @@ diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
 +      BUILD_BUG_ON(sizeof(u) != sizeof(int));
 +      atomic_set(&sbinfo->si_xigen_next, u);
 +}
-diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
---- /usr/share/empty/fs/aufs/file.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/file.c       2013-03-14 20:07:41.041453062 +0100
-@@ -0,0 +1,683 @@
+diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
+--- /usr/share/empty/fs/aufs/fhsm.c    1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/fhsm.c       2015-06-22 08:27:37.880835119 +0200
+@@ -0,0 +1,426 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2011-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -9890,440 +11523,1041 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 + */
 +
 +/*
-+ * handling file/dir, and address_space operation
++ * File-based Hierarchy Storage Management
 + */
 +
-+#ifdef CONFIG_AUFS_DEBUG
-+#include <linux/migrate.h>
-+#endif
-+#include <linux/pagemap.h>
++#include <linux/anon_inodes.h>
++#include <linux/poll.h>
++#include <linux/seq_file.h>
++#include <linux/statfs.h>
 +#include "aufs.h"
 +
-+/* drop flags for writing */
-+unsigned int au_file_roflags(unsigned int flags)
++static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
 +{
-+      flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
-+      flags |= O_RDONLY | O_NOATIME;
-+      return flags;
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
++
++      SiMustAnyLock(sb);
++
++      sbinfo = au_sbi(sb);
++      fhsm = &sbinfo->si_fhsm;
++      AuDebugOn(!fhsm);
++      return fhsm->fhsm_bottom;
 +}
 +
-+/* common functions to regular file and dir */
-+struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
-+                     struct file *file)
++void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
 +{
-+      struct file *h_file;
-+      struct dentry *h_dentry;
-+      struct inode *h_inode;
-+      struct super_block *sb;
-+      struct au_branch *br;
-+      struct path h_path;
-+      int err, exec_flag;
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
 +
-+      /* a race condition can happen between open and unlink/rmdir */
-+      h_file = ERR_PTR(-ENOENT);
-+      h_dentry = au_h_dptr(dentry, bindex);
-+      if (au_test_nfsd() && !h_dentry)
-+              goto out;
-+      h_inode = h_dentry->d_inode;
-+      if (au_test_nfsd() && !h_inode)
-+              goto out;
-+      spin_lock(&h_dentry->d_lock);
-+      err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
-+              || !h_inode
-+              /* || !dentry->d_inode->i_nlink */
-+              ;
-+      spin_unlock(&h_dentry->d_lock);
-+      if (unlikely(err))
-+              goto out;
++      SiMustWriteLock(sb);
 +
-+      sb = dentry->d_sb;
-+      br = au_sbr(sb, bindex);
-+      h_file = ERR_PTR(-EACCES);
-+      exec_flag = flags & __FMODE_EXEC;
-+      if (exec_flag && (br->br_mnt->mnt_flags & MNT_NOEXEC))
-+              goto out;
++      sbinfo = au_sbi(sb);
++      fhsm = &sbinfo->si_fhsm;
++      AuDebugOn(!fhsm);
++      fhsm->fhsm_bottom = bindex;
++}
 +
-+      /* drop flags for writing */
-+      if (au_test_ro(sb, bindex, dentry->d_inode))
-+              flags = au_file_roflags(flags);
-+      flags &= ~O_CREAT;
-+      atomic_inc(&br->br_count);
-+      h_path.dentry = h_dentry;
-+      h_path.mnt = br->br_mnt;
-+      if (!au_special_file(h_inode->i_mode))
-+              h_file = vfsub_dentry_open(&h_path, flags);
-+      else {
-+              /* this block depends upon the configuration */
-+              di_read_unlock(dentry, AuLock_IR);
-+              fi_write_unlock(file);
-+              si_read_unlock(sb);
-+              h_file = vfsub_dentry_open(&h_path, flags);
-+              si_noflush_read_lock(sb);
-+              fi_write_lock(file);
-+              di_read_lock_child(dentry, AuLock_IR);
-+      }
-+      if (IS_ERR(h_file))
-+              goto out_br;
++/* ---------------------------------------------------------------------- */
 +
-+      if (exec_flag) {
-+              err = deny_write_access(h_file);
-+              if (unlikely(err)) {
-+                      fput(h_file);
-+                      h_file = ERR_PTR(err);
-+                      goto out_br;
-+              }
-+      }
-+      fsnotify_open(h_file);
-+      goto out; /* success */
++static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
++{
++      struct au_br_fhsm *bf;
 +
-+out_br:
-+      atomic_dec(&br->br_count);
-+out:
-+      return h_file;
++      bf = br->br_fhsm;
++      MtxMustLock(&bf->bf_lock);
++
++      return !bf->bf_readable
++              || time_after(jiffies,
++                            bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
++}
++
++/* ---------------------------------------------------------------------- */
++
++static void au_fhsm_notify(struct super_block *sb, int val)
++{
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
++
++      SiMustAnyLock(sb);
++
++      sbinfo = au_sbi(sb);
++      fhsm = &sbinfo->si_fhsm;
++      if (au_fhsm_pid(fhsm)
++          && atomic_read(&fhsm->fhsm_readable) != -1) {
++              atomic_set(&fhsm->fhsm_readable, val);
++              if (val)
++                      wake_up(&fhsm->fhsm_wqh);
++      }
 +}
 +
-+int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
-+             struct au_fidir *fidir)
++static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
++                      struct aufs_stfs *rstfs, int do_lock, int do_notify)
 +{
 +      int err;
-+      struct dentry *dentry;
++      struct au_branch *br;
++      struct au_br_fhsm *bf;
 +
-+      err = au_finfo_init(file, fidir);
-+      if (unlikely(err))
-+              goto out;
++      br = au_sbr(sb, bindex);
++      AuDebugOn(au_br_rdonly(br));
++      bf = br->br_fhsm;
++      AuDebugOn(!bf);
 +
-+      dentry = file->f_dentry;
-+      di_read_lock_child(dentry, AuLock_IR);
-+      err = open(file, vfsub_file_flags(file));
-+      di_read_unlock(dentry, AuLock_IR);
++      if (do_lock)
++              mutex_lock(&bf->bf_lock);
++      else
++              MtxMustLock(&bf->bf_lock);
 +
-+      fi_write_unlock(file);
++      /* sb->s_root for NFS is unreliable */
++      err = au_br_stfs(br, &bf->bf_stfs);
 +      if (unlikely(err)) {
-+              au_fi(file)->fi_hdir = NULL;
-+              au_finfo_fin(file);
++              AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
++              goto out;
 +      }
 +
++      bf->bf_jiffy = jiffies;
++      bf->bf_readable = 1;
++      if (do_notify)
++              au_fhsm_notify(sb, /*val*/1);
++      if (rstfs)
++              *rstfs = bf->bf_stfs;
++
 +out:
++      if (do_lock)
++              mutex_unlock(&bf->bf_lock);
++      au_fhsm_notify(sb, /*val*/1);
++
 +      return err;
 +}
 +
-+int au_reopen_nondir(struct file *file)
++void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
 +{
 +      int err;
-+      aufs_bindex_t bstart;
-+      struct dentry *dentry;
-+      struct file *h_file, *h_file_tmp;
-+
-+      dentry = file->f_dentry;
-+      AuDebugOn(au_special_file(dentry->d_inode->i_mode));
-+      bstart = au_dbstart(dentry);
-+      h_file_tmp = NULL;
-+      if (au_fbstart(file) == bstart) {
-+              h_file = au_hf_top(file);
-+              if (file->f_mode == h_file->f_mode)
-+                      return 0; /* success */
-+              h_file_tmp = h_file;
-+              get_file(h_file_tmp);
-+              au_set_h_fptr(file, bstart, NULL);
-+      }
-+      AuDebugOn(au_fi(file)->fi_hdir);
-+      AuDebugOn(au_fbstart(file) < bstart);
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
++      struct au_branch *br;
++      struct au_br_fhsm *bf;
 +
-+      h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
-+                         file);
-+      err = PTR_ERR(h_file);
-+      if (IS_ERR(h_file))
-+              goto out; /* todo: close all? */
++      AuDbg("b%d, force %d\n", bindex, force);
++      SiMustAnyLock(sb);
 +
-+      err = 0;
-+      au_set_fbstart(file, bstart);
-+      au_set_h_fptr(file, bstart, h_file);
-+      au_update_figen(file);
-+      /* todo: necessary? */
-+      /* file->f_ra = h_file->f_ra; */
++      sbinfo = au_sbi(sb);
++      fhsm = &sbinfo->si_fhsm;
++      if (!au_ftest_si(sbinfo, FHSM)
++          || fhsm->fhsm_bottom == bindex)
++              return;
 +
-+out:
-+      if (h_file_tmp)
-+              fput(h_file_tmp);
-+      return err;
++      br = au_sbr(sb, bindex);
++      bf = br->br_fhsm;
++      AuDebugOn(!bf);
++      mutex_lock(&bf->bf_lock);
++      if (force
++          || au_fhsm_pid(fhsm)
++          || au_fhsm_test_jiffy(sbinfo, br))
++              err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
++                                /*do_notify*/1);
++      mutex_unlock(&bf->bf_lock);
 +}
 +
-+/* ---------------------------------------------------------------------- */
-+
-+static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
-+                      struct dentry *hi_wh)
++void au_fhsm_wrote_all(struct super_block *sb, int force)
 +{
-+      int err;
-+      aufs_bindex_t bstart;
-+      struct au_dinfo *dinfo;
-+      struct dentry *h_dentry;
-+      struct au_hdentry *hdp;
++      aufs_bindex_t bindex, bend;
++      struct au_branch *br;
 +
-+      dinfo = au_di(file->f_dentry);
-+      AuRwMustWriteLock(&dinfo->di_rwsem);
++      /* exclude the bottom */
++      bend = au_fhsm_bottom(sb);
++      for (bindex = 0; bindex < bend; bindex++) {
++              br = au_sbr(sb, bindex);
++              if (au_br_fhsm(br->br_perm))
++                      au_fhsm_wrote(sb, bindex, force);
++      }
++}
 +
-+      bstart = dinfo->di_bstart;
-+      dinfo->di_bstart = btgt;
-+      hdp = dinfo->di_hdentry;
-+      h_dentry = hdp[0 + btgt].hd_dentry;
-+      hdp[0 + btgt].hd_dentry = hi_wh;
-+      err = au_reopen_nondir(file);
-+      hdp[0 + btgt].hd_dentry = h_dentry;
-+      dinfo->di_bstart = bstart;
++/* ---------------------------------------------------------------------- */
 +
-+      return err;
++static unsigned int au_fhsm_poll(struct file *file,
++                               struct poll_table_struct *wait)
++{
++      unsigned int mask;
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
++
++      mask = 0;
++      sbinfo = file->private_data;
++      fhsm = &sbinfo->si_fhsm;
++      poll_wait(file, &fhsm->fhsm_wqh, wait);
++      if (atomic_read(&fhsm->fhsm_readable))
++              mask = POLLIN /* | POLLRDNORM */;
++
++      AuTraceErr((int)mask);
++      return mask;
 +}
 +
-+static int au_ready_to_write_wh(struct file *file, loff_t len,
-+                              aufs_bindex_t bcpup)
++static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
++                            struct aufs_stfs *stfs, __s16 brid)
 +{
 +      int err;
-+      struct inode *inode, *h_inode;
-+      struct dentry *dentry, *h_dentry, *hi_wh;
-+
-+      dentry = file->f_dentry;
-+      au_update_dbstart(dentry);
-+      inode = dentry->d_inode;
-+      h_inode = NULL;
-+      if (au_dbstart(dentry) <= bcpup && au_dbend(dentry) >= bcpup) {
-+              h_dentry = au_h_dptr(dentry, bcpup);
-+              if (h_dentry)
-+                      h_inode = h_dentry->d_inode;
-+      }
-+      hi_wh = au_hi_wh(inode, bcpup);
-+      if (!hi_wh && !h_inode)
-+              err = au_sio_cpup_wh(dentry, bcpup, len, file);
-+      else
-+              /* already copied-up after unlink */
-+              err = au_reopen_wh(file, bcpup, hi_wh);
 +
-+      if (!err
-+          && inode->i_nlink > 1
-+          && au_opt_test(au_mntflags(dentry->d_sb), PLINK))
-+              au_plink_append(inode, bcpup, au_h_dptr(dentry, bcpup));
++      err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
++      if (!err)
++              err = __put_user(brid, &stbr->brid);
++      if (unlikely(err))
++              err = -EFAULT;
 +
 +      return err;
 +}
 +
-+/*
-+ * prepare the @file for writing.
-+ */
-+int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
++static ssize_t au_fhsm_do_read(struct super_block *sb,
++                             struct aufs_stbr __user *stbr, size_t count)
 +{
-+      int err;
-+      aufs_bindex_t bstart, bcpup, dbstart;
-+      struct dentry *dentry, *parent, *h_dentry;
-+      struct inode *h_inode, *inode;
-+      struct super_block *sb;
-+      struct file *h_file;
-+
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      inode = dentry->d_inode;
-+      AuDebugOn(au_special_file(inode->i_mode));
-+      bstart = au_fbstart(file);
-+      err = au_test_ro(sb, bstart, inode);
-+      if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
-+              err = au_pin(pin, dentry, bstart, AuOpt_UDBA_NONE, /*flags*/0);
-+              goto out;
-+      }
++      ssize_t err;
++      int nstbr;
++      aufs_bindex_t bindex, bend;
++      struct au_branch *br;
++      struct au_br_fhsm *bf;
 +
-+      /* need to cpup or reopen */
-+      parent = dget_parent(dentry);
-+      di_write_lock_parent(parent);
-+      err = AuWbrCopyup(au_sbi(sb), dentry);
-+      bcpup = err;
-+      if (unlikely(err < 0))
-+              goto out_dgrade;
++      /* except the bottom branch */
 +      err = 0;
++      nstbr = 0;
++      bend = au_fhsm_bottom(sb);
++      for (bindex = 0; !err && bindex < bend; bindex++) {
++              br = au_sbr(sb, bindex);
++              if (!au_br_fhsm(br->br_perm))
++                      continue;
 +
-+      if (!d_unhashed(dentry) && !au_h_dptr(parent, bcpup)) {
-+              err = au_cpup_dirs(dentry, bcpup);
-+              if (unlikely(err))
-+                      goto out_dgrade;
++              bf = br->br_fhsm;
++              mutex_lock(&bf->bf_lock);
++              if (bf->bf_readable) {
++                      err = -EFAULT;
++                      if (count >= sizeof(*stbr))
++                              err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
++                                                        br->br_id);
++                      if (!err) {
++                              bf->bf_readable = 0;
++                              count -= sizeof(*stbr);
++                              nstbr++;
++                      }
++              }
++              mutex_unlock(&bf->bf_lock);
 +      }
++      if (!err)
++              err = sizeof(*stbr) * nstbr;
 +
-+      err = au_pin(pin, dentry, bcpup, AuOpt_UDBA_NONE,
-+                   AuPin_DI_LOCKED | AuPin_MNT_WRITE);
-+      if (unlikely(err))
-+              goto out_dgrade;
++      return err;
++}
 +
-+      h_dentry = au_hf_top(file)->f_dentry;
-+      h_inode = h_dentry->d_inode;
-+      dbstart = au_dbstart(dentry);
-+      if (dbstart <= bcpup) {
-+              h_dentry = au_h_dptr(dentry, bcpup);
-+              AuDebugOn(!h_dentry);
-+              h_inode = h_dentry->d_inode;
-+              AuDebugOn(!h_inode);
-+              bstart = bcpup;
-+      }
++static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
++                         loff_t *pos)
++{
++      ssize_t err;
++      int readable;
++      aufs_bindex_t nfhsm, bindex, bend;
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
++      struct au_branch *br;
++      struct super_block *sb;
 +
-+      if (dbstart <= bcpup            /* just reopen */
-+          || !d_unhashed(dentry)      /* copyup and reopen */
-+              ) {
-+              mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+              h_file = au_h_open_pre(dentry, bstart);
-+              if (IS_ERR(h_file)) {
-+                      err = PTR_ERR(h_file);
-+                      h_file = NULL;
-+              } else {
-+                      di_downgrade_lock(parent, AuLock_IR);
-+                      if (dbstart > bcpup)
-+                              err = au_sio_cpup_simple(dentry, bcpup, len,
-+                                                       AuCpup_DTIME);
-+                      if (!err)
-+                              err = au_reopen_nondir(file);
-+              }
-+              mutex_unlock(&h_inode->i_mutex);
-+              au_h_open_post(dentry, bstart, h_file);
-+      } else {                        /* copyup as wh and reopen */
-+              /*
-+               * since writable hfsplus branch is not supported,
-+               * h_open_pre/post() are unnecessary.
-+               */
-+              mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+              err = au_ready_to_write_wh(file, len, bcpup);
-+              di_downgrade_lock(parent, AuLock_IR);
-+              mutex_unlock(&h_inode->i_mutex);
++      err = 0;
++      sbinfo = file->private_data;
++      fhsm = &sbinfo->si_fhsm;
++need_data:
++      spin_lock_irq(&fhsm->fhsm_wqh.lock);
++      if (!atomic_read(&fhsm->fhsm_readable)) {
++              if (vfsub_file_flags(file) & O_NONBLOCK)
++                      err = -EAGAIN;
++              else
++                      err = wait_event_interruptible_locked_irq
++                              (fhsm->fhsm_wqh,
++                               atomic_read(&fhsm->fhsm_readable));
 +      }
++      spin_unlock_irq(&fhsm->fhsm_wqh.lock);
++      if (unlikely(err))
++              goto out;
 +
-+      if (!err) {
-+              au_pin_set_parent_lflag(pin, /*lflag*/0);
-+              goto out_dput; /* success */
++      /* sb may already be dead */
++      au_rw_read_lock(&sbinfo->si_rwsem);
++      readable = atomic_read(&fhsm->fhsm_readable);
++      if (readable > 0) {
++              sb = sbinfo->si_sb;
++              AuDebugOn(!sb);
++              /* exclude the bottom branch */
++              nfhsm = 0;
++              bend = au_fhsm_bottom(sb);
++              for (bindex = 0; bindex < bend; bindex++) {
++                      br = au_sbr(sb, bindex);
++                      if (au_br_fhsm(br->br_perm))
++                              nfhsm++;
++              }
++              err = -EMSGSIZE;
++              if (nfhsm * sizeof(struct aufs_stbr) <= count) {
++                      atomic_set(&fhsm->fhsm_readable, 0);
++                      err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
++                                           count);
++              }
 +      }
-+      au_unpin(pin);
-+      goto out_unlock;
++      au_rw_read_unlock(&sbinfo->si_rwsem);
++      if (!readable)
++              goto need_data;
 +
-+out_dgrade:
-+      di_downgrade_lock(parent, AuLock_IR);
-+out_unlock:
-+      di_read_unlock(parent, AuLock_IR);
-+out_dput:
-+      dput(parent);
 +out:
 +      return err;
 +}
 +
-+/* ---------------------------------------------------------------------- */
++static int au_fhsm_release(struct inode *inode, struct file *file)
++{
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
 +
-+int au_do_flush(struct file *file, fl_owner_t id,
-+              int (*flush)(struct file *file, fl_owner_t id))
++      /* sb may already be dead */
++      sbinfo = file->private_data;
++      fhsm = &sbinfo->si_fhsm;
++      spin_lock(&fhsm->fhsm_spin);
++      fhsm->fhsm_pid = 0;
++      spin_unlock(&fhsm->fhsm_spin);
++      kobject_put(&sbinfo->si_kobj);
++
++      return 0;
++}
++
++static const struct file_operations au_fhsm_fops = {
++      .owner          = THIS_MODULE,
++      .llseek         = noop_llseek,
++      .read           = au_fhsm_read,
++      .poll           = au_fhsm_poll,
++      .release        = au_fhsm_release
++};
++
++int au_fhsm_fd(struct super_block *sb, int oflags)
 +{
-+      int err;
-+      struct dentry *dentry;
-+      struct super_block *sb;
-+      struct inode *inode;
++      int err, fd;
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
 +
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      inode = dentry->d_inode;
-+      si_noflush_read_lock(sb);
-+      fi_read_lock(file);
-+      ii_read_lock_child(inode);
++      err = -EPERM;
++      if (unlikely(!capable(CAP_SYS_ADMIN)))
++              goto out;
 +
-+      err = flush(file, id);
-+      au_cpup_attr_timesizes(inode);
++      err = -EINVAL;
++      if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
++              goto out;
 +
-+      ii_read_unlock(inode);
-+      fi_read_unlock(file);
++      err = 0;
++      sbinfo = au_sbi(sb);
++      fhsm = &sbinfo->si_fhsm;
++      spin_lock(&fhsm->fhsm_spin);
++      if (!fhsm->fhsm_pid)
++              fhsm->fhsm_pid = current->pid;
++      else
++              err = -EBUSY;
++      spin_unlock(&fhsm->fhsm_spin);
++      if (unlikely(err))
++              goto out;
++
++      oflags |= O_RDONLY;
++      /* oflags |= FMODE_NONOTIFY; */
++      fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
++      err = fd;
++      if (unlikely(fd < 0))
++              goto out_pid;
++
++      /* succeed reglardless 'fhsm' status */
++      kobject_get(&sbinfo->si_kobj);
++      si_noflush_read_lock(sb);
++      if (au_ftest_si(sbinfo, FHSM))
++              au_fhsm_wrote_all(sb, /*force*/0);
 +      si_read_unlock(sb);
++      goto out; /* success */
++
++out_pid:
++      spin_lock(&fhsm->fhsm_spin);
++      fhsm->fhsm_pid = 0;
++      spin_unlock(&fhsm->fhsm_spin);
++out:
++      AuTraceErr(err);
 +      return err;
 +}
 +
 +/* ---------------------------------------------------------------------- */
 +
-+static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
++int au_fhsm_br_alloc(struct au_branch *br)
 +{
 +      int err;
-+      aufs_bindex_t bstart;
-+      struct au_pin pin;
-+      struct au_finfo *finfo;
-+      struct dentry *dentry, *parent, *hi_wh;
-+      struct inode *inode;
-+      struct super_block *sb;
-+
-+      FiMustWriteLock(file);
 +
 +      err = 0;
-+      finfo = au_fi(file);
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      inode = dentry->d_inode;
-+      bstart = au_ibstart(inode);
-+      if (bstart == finfo->fi_btop || IS_ROOT(dentry))
-+              goto out;
-+
-+      parent = dget_parent(dentry);
-+      if (au_test_ro(sb, bstart, inode)) {
-+              di_read_lock_parent(parent, !AuLock_IR);
-+              err = AuWbrCopyup(au_sbi(sb), dentry);
-+              bstart = err;
-+              di_read_unlock(parent, !AuLock_IR);
-+              if (unlikely(err < 0))
-+                      goto out_parent;
-+              err = 0;
-+      }
++      br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
++      if (br->br_fhsm)
++              au_br_fhsm_init(br->br_fhsm);
++      else
++              err = -ENOMEM;
 +
-+      di_read_lock_parent(parent, AuLock_IR);
-+      hi_wh = au_hi_wh(inode, bstart);
-+      if (!S_ISDIR(inode->i_mode)
-+          && au_opt_test(au_mntflags(sb), PLINK)
-+          && au_plink_test(inode)
-+          && !d_unhashed(dentry)) {
-+              err = au_test_and_cpup_dirs(dentry, bstart);
-+              if (unlikely(err))
-+                      goto out_unlock;
++      return err;
++}
 +
-+              /* always superio. */
-+              err = au_pin(&pin, dentry, bstart, AuOpt_UDBA_NONE,
-+                           AuPin_DI_LOCKED | AuPin_MNT_WRITE);
-+              if (!err)
-+                      err = au_sio_cpup_simple(dentry, bstart, -1,
-+                                               AuCpup_DTIME);
-+              au_unpin(&pin);
-+      } else if (hi_wh) {
-+              /* already copied-up after unlink */
-+              err = au_reopen_wh(file, bstart, hi_wh);
-+              *need_reopen = 0;
-+      }
++/* ---------------------------------------------------------------------- */
 +
-+out_unlock:
-+      di_read_unlock(parent, AuLock_IR);
-+out_parent:
-+      dput(parent);
-+out:
-+      return err;
++void au_fhsm_fin(struct super_block *sb)
++{
++      au_fhsm_notify(sb, /*val*/-1);
 +}
 +
-+static void au_do_refresh_dir(struct file *file)
++void au_fhsm_init(struct au_sbinfo *sbinfo)
 +{
-+      aufs_bindex_t bindex, bend, new_bindex, brid;
-+      struct au_hfile *p, tmp, *q;
-+      struct au_finfo *finfo;
-+      struct super_block *sb;
-+      struct au_fidir *fidir;
++      struct au_fhsm *fhsm;
 +
-+      FiMustWriteLock(file);
++      fhsm = &sbinfo->si_fhsm;
++      spin_lock_init(&fhsm->fhsm_spin);
++      init_waitqueue_head(&fhsm->fhsm_wqh);
++      atomic_set(&fhsm->fhsm_readable, 0);
++      fhsm->fhsm_expire
++              = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
++      fhsm->fhsm_bottom = -1;
++}
 +
-+      sb = file->f_dentry->d_sb;
-+      finfo = au_fi(file);
-+      fidir = finfo->fi_hdir;
-+      AuDebugOn(!fidir);
-+      p = fidir->fd_hfile + finfo->fi_btop;
-+      brid = p->hf_br->br_id;
-+      bend = fidir->fd_bbot;
-+      for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
-+              if (!p->hf_file)
-+                      continue;
++void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
++{
++      sbinfo->si_fhsm.fhsm_expire
++              = msecs_to_jiffies(sec * MSEC_PER_SEC);
++}
 +
-+              new_bindex = au_br_index(sb, p->hf_br->br_id);
-+              if (new_bindex == bindex)
-+                      continue;
-+              if (new_bindex < 0) {
-+                      au_set_h_fptr(file, bindex, NULL);
-+                      continue;
-+              }
++void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
++{
++      unsigned int u;
++
++      if (!au_ftest_si(sbinfo, FHSM))
++              return;
++
++      u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
++      if (u != AUFS_FHSM_CACHE_DEF_SEC)
++              seq_printf(seq, ",fhsm_sec=%u", u);
++}
+diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
+--- /usr/share/empty/fs/aufs/file.c    1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/file.c       2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,844 @@
++/*
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
++ *
++ * This program, aufs is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * handling file/dir, and address_space operation
++ */
++
++#ifdef CONFIG_AUFS_DEBUG
++#include <linux/migrate.h>
++#endif
++#include <linux/pagemap.h>
++#include "aufs.h"
++
++/* drop flags for writing */
++unsigned int au_file_roflags(unsigned int flags)
++{
++      flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
++      flags |= O_RDONLY | O_NOATIME;
++      return flags;
++}
++
++/* common functions to regular file and dir */
++struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
++                     struct file *file, int force_wr)
++{
++      struct file *h_file;
++      struct dentry *h_dentry;
++      struct inode *h_inode;
++      struct super_block *sb;
++      struct au_branch *br;
++      struct path h_path;
++      int err;
++
++      /* a race condition can happen between open and unlink/rmdir */
++      h_file = ERR_PTR(-ENOENT);
++      h_dentry = au_h_dptr(dentry, bindex);
++      if (au_test_nfsd() && !h_dentry)
++              goto out;
++      h_inode = h_dentry->d_inode;
++      if (au_test_nfsd() && !h_inode)
++              goto out;
++      spin_lock(&h_dentry->d_lock);
++      err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
++              || !h_inode
++              /* || !dentry->d_inode->i_nlink */
++              ;
++      spin_unlock(&h_dentry->d_lock);
++      if (unlikely(err))
++              goto out;
++
++      sb = dentry->d_sb;
++      br = au_sbr(sb, bindex);
++      err = au_br_test_oflag(flags, br);
++      h_file = ERR_PTR(err);
++      if (unlikely(err))
++              goto out;
++
++      /* drop flags for writing */
++      if (au_test_ro(sb, bindex, dentry->d_inode)) {
++              if (force_wr && !(flags & O_WRONLY))
++                      force_wr = 0;
++              flags = au_file_roflags(flags);
++              if (force_wr) {
++                      h_file = ERR_PTR(-EROFS);
++                      flags = au_file_roflags(flags);
++                      if (unlikely(vfsub_native_ro(h_inode)
++                                   || IS_APPEND(h_inode)))
++                              goto out;
++                      flags &= ~O_ACCMODE;
++                      flags |= O_WRONLY;
++              }
++      }
++      flags &= ~O_CREAT;
++      atomic_inc(&br->br_count);
++      h_path.dentry = h_dentry;
++      h_path.mnt = au_br_mnt(br);
++      h_file = vfsub_dentry_open(&h_path, flags);
++      if (IS_ERR(h_file))
++              goto out_br;
++
++      if (flags & __FMODE_EXEC) {
++              err = deny_write_access(h_file);
++              if (unlikely(err)) {
++                      fput(h_file);
++                      h_file = ERR_PTR(err);
++                      goto out_br;
++              }
++      }
++      fsnotify_open(h_file);
++      goto out; /* success */
++
++out_br:
++      atomic_dec(&br->br_count);
++out:
++      return h_file;
++}
++
++static int au_cmoo(struct dentry *dentry)
++{
++      int err, cmoo;
++      unsigned int udba;
++      struct path h_path;
++      struct au_pin pin;
++      struct au_cp_generic cpg = {
++              .dentry = dentry,
++              .bdst   = -1,
++              .bsrc   = -1,
++              .len    = -1,
++              .pin    = &pin,
++              .flags  = AuCpup_DTIME | AuCpup_HOPEN
++      };
++      struct inode *delegated;
++      struct super_block *sb;
++      struct au_sbinfo *sbinfo;
++      struct au_fhsm *fhsm;
++      pid_t pid;
++      struct au_branch *br;
++      struct dentry *parent;
++      struct au_hinode *hdir;
++
++      DiMustWriteLock(dentry);
++      IiMustWriteLock(dentry->d_inode);
++
++      err = 0;
++      if (IS_ROOT(dentry))
++              goto out;
++      cpg.bsrc = au_dbstart(dentry);
++      if (!cpg.bsrc)
++              goto out;
++
++      sb = dentry->d_sb;
++      sbinfo = au_sbi(sb);
++      fhsm = &sbinfo->si_fhsm;
++      pid = au_fhsm_pid(fhsm);
++      if (pid
++          && (current->pid == pid
++              || current->real_parent->pid == pid))
++              goto out;
++
++      br = au_sbr(sb, cpg.bsrc);
++      cmoo = au_br_cmoo(br->br_perm);
++      if (!cmoo)
++              goto out;
++      if (!d_is_reg(dentry))
++              cmoo &= AuBrAttr_COO_ALL;
++      if (!cmoo)
++              goto out;
++
++      parent = dget_parent(dentry);
++      di_write_lock_parent(parent);
++      err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
++      cpg.bdst = err;
++      if (unlikely(err < 0)) {
++              err = 0;        /* there is no upper writable branch */
++              goto out_dgrade;
++      }
++      AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
++
++      /* do not respect the coo attrib for the target branch */
++      err = au_cpup_dirs(dentry, cpg.bdst);
++      if (unlikely(err))
++              goto out_dgrade;
++
++      di_downgrade_lock(parent, AuLock_IR);
++      udba = au_opt_udba(sb);
++      err = au_pin(&pin, dentry, cpg.bdst, udba,
++                   AuPin_DI_LOCKED | AuPin_MNT_WRITE);
++      if (unlikely(err))
++              goto out_parent;
++
++      err = au_sio_cpup_simple(&cpg);
++      au_unpin(&pin);
++      if (unlikely(err))
++              goto out_parent;
++      if (!(cmoo & AuBrWAttr_MOO))
++              goto out_parent; /* success */
++
++      err = au_pin(&pin, dentry, cpg.bsrc, udba,
++                   AuPin_DI_LOCKED | AuPin_MNT_WRITE);
++      if (unlikely(err))
++              goto out_parent;
++
++      h_path.mnt = au_br_mnt(br);
++      h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
++      hdir = au_hi(parent->d_inode, cpg.bsrc);
++      delegated = NULL;
++      err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
++      au_unpin(&pin);
++      /* todo: keep h_dentry or not? */
++      if (unlikely(err == -EWOULDBLOCK)) {
++              pr_warn("cannot retry for NFSv4 delegation"
++                      " for an internal unlink\n");
++              iput(delegated);
++      }
++      if (unlikely(err)) {
++              pr_err("unlink %pd after coo failed (%d), ignored\n",
++                     dentry, err);
++              err = 0;
++      }
++      goto out_parent; /* success */
++
++out_dgrade:
++      di_downgrade_lock(parent, AuLock_IR);
++out_parent:
++      di_read_unlock(parent, AuLock_IR);
++      dput(parent);
++out:
++      AuTraceErr(err);
++      return err;
++}
++
++int au_do_open(struct file *file, struct au_do_open_args *args)
++{
++      int err, no_lock = args->no_lock;
++      struct dentry *dentry;
++      struct au_finfo *finfo;
++
++      if (!no_lock)
++              err = au_finfo_init(file, args->fidir);
++      else {
++              lockdep_off();
++              err = au_finfo_init(file, args->fidir);
++              lockdep_on();
++      }
++      if (unlikely(err))
++              goto out;
++
++      dentry = file->f_path.dentry;
++      AuDebugOn(IS_ERR_OR_NULL(dentry));
++      if (!no_lock) {
++              di_write_lock_child(dentry);
++              err = au_cmoo(dentry);
++              di_downgrade_lock(dentry, AuLock_IR);
++              if (!err)
++                      err = args->open(file, vfsub_file_flags(file), NULL);
++              di_read_unlock(dentry, AuLock_IR);
++      } else {
++              err = au_cmoo(dentry);
++              if (!err)
++                      err = args->open(file, vfsub_file_flags(file),
++                                       args->h_file);
++              if (!err && au_fbstart(file) != au_dbstart(dentry))
++                      /*
++                       * cmoo happens after h_file was opened.
++                       * need to refresh file later.
++                       */
++                      atomic_dec(&au_fi(file)->fi_generation);
++      }
++
++      finfo = au_fi(file);
++      if (!err) {
++              finfo->fi_file = file;
++              au_sphl_add(&finfo->fi_hlist,
++                          &au_sbi(file->f_path.dentry->d_sb)->si_files);
++      }
++      if (!no_lock)
++              fi_write_unlock(file);
++      else {
++              lockdep_off();
++              fi_write_unlock(file);
++              lockdep_on();
++      }
++      if (unlikely(err)) {
++              finfo->fi_hdir = NULL;
++              au_finfo_fin(file);
++      }
++
++out:
++      return err;
++}
++
++int au_reopen_nondir(struct file *file)
++{
++      int err;
++      aufs_bindex_t bstart;
++      struct dentry *dentry;
++      struct file *h_file, *h_file_tmp;
++
++      dentry = file->f_path.dentry;
++      bstart = au_dbstart(dentry);
++      h_file_tmp = NULL;
++      if (au_fbstart(file) == bstart) {
++              h_file = au_hf_top(file);
++              if (file->f_mode == h_file->f_mode)
++                      return 0; /* success */
++              h_file_tmp = h_file;
++              get_file(h_file_tmp);
++              au_set_h_fptr(file, bstart, NULL);
++      }
++      AuDebugOn(au_fi(file)->fi_hdir);
++      /*
++       * it can happen
++       * file exists on both of rw and ro
++       * open --> dbstart and fbstart are both 0
++       * prepend a branch as rw, "rw" become ro
++       * remove rw/file
++       * delete the top branch, "rw" becomes rw again
++       *      --> dbstart is 1, fbstart is still 0
++       * write --> fbstart is 0 but dbstart is 1
++       */
++      /* AuDebugOn(au_fbstart(file) < bstart); */
++
++      h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
++                         file, /*force_wr*/0);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file)) {
++              if (h_file_tmp) {
++                      atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
++                      au_set_h_fptr(file, bstart, h_file_tmp);
++                      h_file_tmp = NULL;
++              }
++              goto out; /* todo: close all? */
++      }
++
++      err = 0;
++      au_set_fbstart(file, bstart);
++      au_set_h_fptr(file, bstart, h_file);
++      au_update_figen(file);
++      /* todo: necessary? */
++      /* file->f_ra = h_file->f_ra; */
++
++out:
++      if (h_file_tmp)
++              fput(h_file_tmp);
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
++                      struct dentry *hi_wh)
++{
++      int err;
++      aufs_bindex_t bstart;
++      struct au_dinfo *dinfo;
++      struct dentry *h_dentry;
++      struct au_hdentry *hdp;
++
++      dinfo = au_di(file->f_path.dentry);
++      AuRwMustWriteLock(&dinfo->di_rwsem);
++
++      bstart = dinfo->di_bstart;
++      dinfo->di_bstart = btgt;
++      hdp = dinfo->di_hdentry;
++      h_dentry = hdp[0 + btgt].hd_dentry;
++      hdp[0 + btgt].hd_dentry = hi_wh;
++      err = au_reopen_nondir(file);
++      hdp[0 + btgt].hd_dentry = h_dentry;
++      dinfo->di_bstart = bstart;
++
++      return err;
++}
++
++static int au_ready_to_write_wh(struct file *file, loff_t len,
++                              aufs_bindex_t bcpup, struct au_pin *pin)
++{
++      int err;
++      struct inode *inode, *h_inode;
++      struct dentry *h_dentry, *hi_wh;
++      struct au_cp_generic cpg = {
++              .dentry = file->f_path.dentry,
++              .bdst   = bcpup,
++              .bsrc   = -1,
++              .len    = len,
++              .pin    = pin
++      };
++
++      au_update_dbstart(cpg.dentry);
++      inode = cpg.dentry->d_inode;
++      h_inode = NULL;
++      if (au_dbstart(cpg.dentry) <= bcpup
++          && au_dbend(cpg.dentry) >= bcpup) {
++              h_dentry = au_h_dptr(cpg.dentry, bcpup);
++              if (h_dentry)
++                      h_inode = h_dentry->d_inode;
++      }
++      hi_wh = au_hi_wh(inode, bcpup);
++      if (!hi_wh && !h_inode)
++              err = au_sio_cpup_wh(&cpg, file);
++      else
++              /* already copied-up after unlink */
++              err = au_reopen_wh(file, bcpup, hi_wh);
++
++      if (!err
++          && (inode->i_nlink > 1
++              || (inode->i_state & I_LINKABLE))
++          && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
++              au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
++
++      return err;
++}
++
++/*
++ * prepare the @file for writing.
++ */
++int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
++{
++      int err;
++      aufs_bindex_t dbstart;
++      struct dentry *parent;
++      struct inode *inode;
++      struct super_block *sb;
++      struct file *h_file;
++      struct au_cp_generic cpg = {
++              .dentry = file->f_path.dentry,
++              .bdst   = -1,
++              .bsrc   = -1,
++              .len    = len,
++              .pin    = pin,
++              .flags  = AuCpup_DTIME
++      };
++
++      sb = cpg.dentry->d_sb;
++      inode = cpg.dentry->d_inode;
++      cpg.bsrc = au_fbstart(file);
++      err = au_test_ro(sb, cpg.bsrc, inode);
++      if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
++              err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
++                           /*flags*/0);
++              goto out;
++      }
++
++      /* need to cpup or reopen */
++      parent = dget_parent(cpg.dentry);
++      di_write_lock_parent(parent);
++      err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
++      cpg.bdst = err;
++      if (unlikely(err < 0))
++              goto out_dgrade;
++      err = 0;
++
++      if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
++              err = au_cpup_dirs(cpg.dentry, cpg.bdst);
++              if (unlikely(err))
++                      goto out_dgrade;
++      }
++
++      err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
++                   AuPin_DI_LOCKED | AuPin_MNT_WRITE);
++      if (unlikely(err))
++              goto out_dgrade;
++
++      dbstart = au_dbstart(cpg.dentry);
++      if (dbstart <= cpg.bdst)
++              cpg.bsrc = cpg.bdst;
++
++      if (dbstart <= cpg.bdst         /* just reopen */
++          || !d_unhashed(cpg.dentry)  /* copyup and reopen */
++              ) {
++              h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
++              if (IS_ERR(h_file))
++                      err = PTR_ERR(h_file);
++              else {
++                      di_downgrade_lock(parent, AuLock_IR);
++                      if (dbstart > cpg.bdst)
++                              err = au_sio_cpup_simple(&cpg);
++                      if (!err)
++                              err = au_reopen_nondir(file);
++                      au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
++              }
++      } else {                        /* copyup as wh and reopen */
++              /*
++               * since writable hfsplus branch is not supported,
++               * h_open_pre/post() are unnecessary.
++               */
++              err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
++              di_downgrade_lock(parent, AuLock_IR);
++      }
++
++      if (!err) {
++              au_pin_set_parent_lflag(pin, /*lflag*/0);
++              goto out_dput; /* success */
++      }
++      au_unpin(pin);
++      goto out_unlock;
++
++out_dgrade:
++      di_downgrade_lock(parent, AuLock_IR);
++out_unlock:
++      di_read_unlock(parent, AuLock_IR);
++out_dput:
++      dput(parent);
++out:
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++int au_do_flush(struct file *file, fl_owner_t id,
++              int (*flush)(struct file *file, fl_owner_t id))
++{
++      int err;
++      struct super_block *sb;
++      struct inode *inode;
++
++      inode = file_inode(file);
++      sb = inode->i_sb;
++      si_noflush_read_lock(sb);
++      fi_read_lock(file);
++      ii_read_lock_child(inode);
++
++      err = flush(file, id);
++      au_cpup_attr_timesizes(inode);
++
++      ii_read_unlock(inode);
++      fi_read_unlock(file);
++      si_read_unlock(sb);
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
++{
++      int err;
++      struct au_pin pin;
++      struct au_finfo *finfo;
++      struct dentry *parent, *hi_wh;
++      struct inode *inode;
++      struct super_block *sb;
++      struct au_cp_generic cpg = {
++              .dentry = file->f_path.dentry,
++              .bdst   = -1,
++              .bsrc   = -1,
++              .len    = -1,
++              .pin    = &pin,
++              .flags  = AuCpup_DTIME
++      };
++
++      FiMustWriteLock(file);
++
++      err = 0;
++      finfo = au_fi(file);
++      sb = cpg.dentry->d_sb;
++      inode = cpg.dentry->d_inode;
++      cpg.bdst = au_ibstart(inode);
++      if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
++              goto out;
++
++      parent = dget_parent(cpg.dentry);
++      if (au_test_ro(sb, cpg.bdst, inode)) {
++              di_read_lock_parent(parent, !AuLock_IR);
++              err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
++              cpg.bdst = err;
++              di_read_unlock(parent, !AuLock_IR);
++              if (unlikely(err < 0))
++                      goto out_parent;
++              err = 0;
++      }
++
++      di_read_lock_parent(parent, AuLock_IR);
++      hi_wh = au_hi_wh(inode, cpg.bdst);
++      if (!S_ISDIR(inode->i_mode)
++          && au_opt_test(au_mntflags(sb), PLINK)
++          && au_plink_test(inode)
++          && !d_unhashed(cpg.dentry)
++          && cpg.bdst < au_dbstart(cpg.dentry)) {
++              err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
++              if (unlikely(err))
++                      goto out_unlock;
++
++              /* always superio. */
++              err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
++                           AuPin_DI_LOCKED | AuPin_MNT_WRITE);
++              if (!err) {
++                      err = au_sio_cpup_simple(&cpg);
++                      au_unpin(&pin);
++              }
++      } else if (hi_wh) {
++              /* already copied-up after unlink */
++              err = au_reopen_wh(file, cpg.bdst, hi_wh);
++              *need_reopen = 0;
++      }
++
++out_unlock:
++      di_read_unlock(parent, AuLock_IR);
++out_parent:
++      dput(parent);
++out:
++      return err;
++}
++
++static void au_do_refresh_dir(struct file *file)
++{
++      aufs_bindex_t bindex, bend, new_bindex, brid;
++      struct au_hfile *p, tmp, *q;
++      struct au_finfo *finfo;
++      struct super_block *sb;
++      struct au_fidir *fidir;
++
++      FiMustWriteLock(file);
++
++      sb = file->f_path.dentry->d_sb;
++      finfo = au_fi(file);
++      fidir = finfo->fi_hdir;
++      AuDebugOn(!fidir);
++      p = fidir->fd_hfile + finfo->fi_btop;
++      brid = p->hf_br->br_id;
++      bend = fidir->fd_bbot;
++      for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
++              if (!p->hf_file)
++                      continue;
++
++              new_bindex = au_br_index(sb, p->hf_br->br_id);
++              if (new_bindex == bindex)
++                      continue;
++              if (new_bindex < 0) {
++                      au_set_h_fptr(file, bindex, NULL);
++                      continue;
++              }
 +
 +              /* swap two lower inode, and loop again */
 +              q = fidir->fd_hfile + new_bindex;
@@ -10337,16 +12571,14 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +      }
 +
 +      p = fidir->fd_hfile;
-+      if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
++      if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
 +              bend = au_sbend(sb);
 +              for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
 +                   finfo->fi_btop++, p++)
 +                      if (p->hf_file) {
-+                              if (p->hf_file->f_dentry
-+                                  && p->hf_file->f_dentry->d_inode)
++                              if (file_inode(p->hf_file))
 +                                      break;
-+                              else
-+                                      au_hfput(p, file);
++                              au_hfput(p, file);
 +                      }
 +      } else {
 +              bend = au_br_index(sb, brid);
@@ -10361,11 +12593,9 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +      for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
 +           fidir->fd_bbot--, p--)
 +              if (p->hf_file) {
-+                      if (p->hf_file->f_dentry
-+                          && p->hf_file->f_dentry->d_inode)
++                      if (file_inode(p->hf_file))
 +                              break;
-+                      else
-+                              au_hfput(p, file);
++                      au_hfput(p, file);
 +              }
 +      AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
 +}
@@ -10381,7 +12611,7 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +      struct au_finfo *finfo;
 +      struct au_hfile *hfile;
 +
-+      dentry = file->f_dentry;
++      dentry = file->f_path.dentry;
 +      finfo = au_fi(file);
 +      if (!finfo->fi_hdir) {
 +              hfile = &finfo->fi_htop;
@@ -10431,9 +12661,8 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +      struct inode *inode;
 +
 +      err = 0;
-+      dentry = file->f_dentry;
++      dentry = file->f_path.dentry;
 +      inode = dentry->d_inode;
-+      AuDebugOn(au_special_file(inode->i_mode));
 +      sigen = au_sigen(dentry->d_sb);
 +      fi_write_lock(file);
 +      figen = au_figen(file);
@@ -10482,16 +12711,7 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +
 +/* it will never be called, but necessary to support O_DIRECT */
 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
-+                            const struct iovec *iov, loff_t offset,
-+                            unsigned long nr_segs)
-+{ BUG(); return 0; }
-+
-+/*
-+ * it will never be called, but madvise and fadvise behaves differently
-+ * when get_xip_mem is defined
-+ */
-+static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
-+                          int create, void **kmem, unsigned long *pfn)
++                            struct iov_iter *iter, loff_t offset)
 +{ BUG(); return 0; }
 +
 +/* they will never be called. */
@@ -10509,7 +12729,8 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +
 +static int aufs_set_page_dirty(struct page *page)
 +{ AuUnsupport(); return 0; }
-+static void aufs_invalidatepage(struct page *page, unsigned long offset)
++static void aufs_invalidatepage(struct page *page, unsigned int offset,
++                              unsigned int length)
 +{ AuUnsupport(); }
 +static int aufs_releasepage(struct page *page, gfp_t gfp)
 +{ AuUnsupport(); return 0; }
@@ -10519,9 +12740,12 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +static int aufs_launder_page(struct page *page)
 +{ AuUnsupport(); return 0; }
 +static int aufs_is_partially_uptodate(struct page *page,
-+                                    read_descriptor_t *desc,
-+                                    unsigned long from)
++                                    unsigned long from,
++                                    unsigned long count)
 +{ AuUnsupport(); return 0; }
++static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
++                                  bool *writeback)
++{ AuUnsupport(); }
 +static int aufs_error_remove_page(struct address_space *mapping,
 +                                struct page *page)
 +{ AuUnsupport(); return 0; }
@@ -10535,7 +12759,6 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +const struct address_space_operations aufs_aop = {
 +      .readpage               = aufs_readpage,
 +      .direct_IO              = aufs_direct_IO,
-+      .get_xip_mem            = aufs_get_xip_mem,
 +#ifdef CONFIG_AUFS_DEBUG
 +      .writepage              = aufs_writepage,
 +      /* no writepages, because of writepage */
@@ -10549,6 +12772,7 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +      .migratepage            = aufs_migratepage,
 +      .launder_page           = aufs_launder_page,
 +      .is_partially_uptodate  = aufs_is_partially_uptodate,
++      .is_dirty_writeback     = aufs_is_dirty_writeback,
 +      .error_remove_page      = aufs_error_remove_page,
 +      .swap_activate          = aufs_swap_activate,
 +      .swap_deactivate        = aufs_swap_deactivate
@@ -10556,10 +12780,10 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +};
 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 --- /usr/share/empty/fs/aufs/file.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/file.h       2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,298 @@
++++ linux/fs/aufs/file.h       2015-06-22 08:27:37.880835119 +0200
+@@ -0,0 +1,291 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -10572,8 +12796,7 @@ diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -10622,6 +12845,9 @@ diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 +              atomic_t                        fi_mmapped;
 +      };
 +      struct au_fidir         *fi_hdir;       /* for dir only */
++
++      struct hlist_node       fi_hlist;
++      struct file             *fi_file;       /* very ugly */
 +} ____cacheline_aligned_in_smp;
 +
 +/* ---------------------------------------------------------------------- */
@@ -10630,9 +12856,15 @@ diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 +extern const struct address_space_operations aufs_aop;
 +unsigned int au_file_roflags(unsigned int flags);
 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
-+                     struct file *file);
-+int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
-+             struct au_fidir *fidir);
++                     struct file *file, int force_wr);
++struct au_do_open_args {
++      int             no_lock;
++      int             (*open)(struct file *file, int flags,
++                              struct file *h_file);
++      struct au_fidir *fidir;
++      struct file     *h_file;
++};
++int au_do_open(struct file *file, struct au_do_open_args *args);
 +int au_reopen_nondir(struct file *file);
 +struct au_pin;
 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
@@ -10648,37 +12880,22 @@ diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 +
 +#ifdef CONFIG_AUFS_BR_HFSPLUS
 +/* hfsplus.c */
-+struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex);
++struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
++                         int force_wr);
 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
 +                  struct file *h_file);
 +#else
-+static inline
-+struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
-+{
-+      return NULL;
-+}
-+
++AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
++       aufs_bindex_t bindex, int force_wr)
 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
 +         struct file *h_file);
 +#endif
 +
 +/* f_op.c */
 +extern const struct file_operations aufs_file_fop;
-+int au_do_open_nondir(struct file *file, int flags);
++int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
-+
-+#ifdef CONFIG_AUFS_SP_IATTR
-+/* f_op_sp.c */
-+int au_special_file(umode_t mode);
-+void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
-+#else
-+AuStubInt0(au_special_file, umode_t mode)
-+static inline void au_init_special_fop(struct inode *inode, umode_t mode,
-+                                     dev_t rdev)
-+{
-+      init_special_inode(inode, mode, rdev);
-+}
-+#endif
++struct file *au_read_pre(struct file *file, int keep_fi);
 +
 +/* finfo.c */
 +void au_hfput(struct au_hfile *hf, struct file *file);
@@ -10698,6 +12915,8 @@ diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 +#ifdef CONFIG_COMPAT
 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
 +                         unsigned long arg);
++long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
++                            unsigned long arg);
 +#endif
 +
 +/* ---------------------------------------------------------------------- */
@@ -10844,24 +13063,22 @@ diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
 +                                  struct file *file)
 +{
-+#ifdef CONFIG_AUFS_PROC_MAP
 +      get_file(file);
 +      vma->vm_prfile = file;
 +#ifndef CONFIG_MMU
 +      get_file(file);
 +      vma->vm_region->vm_prfile = file;
 +#endif
-+#endif
 +}
 +
 +#endif /* __KERNEL__ */
 +#endif /* __AUFS_FILE_H__ */
 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
 --- /usr/share/empty/fs/aufs/finfo.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/finfo.c      2013-02-19 08:40:03.946892891 +0100
++++ linux/fs/aufs/finfo.c      2015-06-22 08:29:23.706757681 +0200
 @@ -0,0 +1,157 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -10874,8 +13091,7 @@ diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -10912,14 +13128,15 @@ diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
 +              au_hfput(hf, file);
 +      if (val) {
 +              FiMustWriteLock(file);
++              AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
 +              hf->hf_file = val;
-+              hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
++              hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
 +      }
 +}
 +
 +void au_update_figen(struct file *file)
 +{
-+      atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
++      atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
 +      /* smp_mb(); */ /* atomic_set */
 +}
 +
@@ -10970,7 +13187,7 @@ diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
 +{
 +      struct au_finfo *finfo;
 +
-+      au_nfiles_dec(file->f_dentry->d_sb);
++      au_nfiles_dec(file->f_path.dentry->d_sb);
 +
 +      finfo = au_fi(file);
 +      AuDebugOn(finfo->fi_hdir);
@@ -10994,7 +13211,7 @@ diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
 +      struct dentry *dentry;
 +
 +      err = -ENOMEM;
-+      dentry = file->f_dentry;
++      dentry = file->f_path.dentry;
 +      finfo = au_cache_alloc_finfo();
 +      if (unlikely(!finfo))
 +              goto out;
@@ -11019,10 +13236,10 @@ diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
 +}
 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 --- /usr/share/empty/fs/aufs/f_op.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/f_op.c       2013-03-14 20:07:41.041453062 +0100
-@@ -0,0 +1,723 @@
++++ linux/fs/aufs/f_op.c       2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,748 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -11035,42 +13252,50 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
 + * file and vm operations
 + */
 +
++#include <linux/aio.h>
 +#include <linux/fs_stack.h>
 +#include <linux/mman.h>
 +#include <linux/security.h>
 +#include "aufs.h"
 +
-+int au_do_open_nondir(struct file *file, int flags)
++int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
 +{
 +      int err;
 +      aufs_bindex_t bindex;
-+      struct file *h_file;
 +      struct dentry *dentry;
 +      struct au_finfo *finfo;
++      struct inode *h_inode;
 +
 +      FiMustWriteLock(file);
 +
-+      dentry = file->f_dentry;
-+      err = au_d_alive(dentry);
-+      if (unlikely(err))
-+              goto out;
-+
++      err = 0;
++      dentry = file->f_path.dentry;
++      AuDebugOn(IS_ERR_OR_NULL(dentry));
 +      finfo = au_fi(file);
 +      memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
 +      atomic_set(&finfo->fi_mmapped, 0);
 +      bindex = au_dbstart(dentry);
-+      h_file = au_h_open(dentry, bindex, flags, file);
++      if (!h_file)
++              h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
++      else
++              get_file(h_file);
 +      if (IS_ERR(h_file))
 +              err = PTR_ERR(h_file);
 +      else {
++              if ((flags & __O_TMPFILE)
++                  && !(flags & O_EXCL)) {
++                      h_inode = file_inode(h_file);
++                      spin_lock(&h_inode->i_lock);
++                      h_inode->i_state |= I_LINKABLE;
++                      spin_unlock(&h_inode->i_lock);
++              }
 +              au_set_fbstart(file, bindex);
 +              au_set_h_fptr(file, bindex, h_file);
 +              au_update_figen(file);
@@ -11078,7 +13303,6 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +              /* file->f_ra = h_file->f_ra; */
 +      }
 +
-+out:
 +      return err;
 +}
 +
@@ -11087,14 +13311,16 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +{
 +      int err;
 +      struct super_block *sb;
++      struct au_do_open_args args = {
++              .open   = au_do_open_nondir
++      };
 +
-+      AuDbg("%.*s, f_flags 0x%x, f_mode 0x%x\n",
-+            AuDLNPair(file->f_dentry), vfsub_file_flags(file),
-+            file->f_mode);
++      AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
++            file, vfsub_file_flags(file), file->f_mode);
 +
-+      sb = file->f_dentry->d_sb;
++      sb = file->f_path.dentry->d_sb;
 +      si_read_lock(sb, AuLock_FLUSH);
-+      err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
++      err = au_do_open(file, &args);
 +      si_read_unlock(sb);
 +      return err;
 +}
@@ -11105,6 +13331,8 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +      aufs_bindex_t bindex;
 +
 +      finfo = au_fi(file);
++      au_sphl_del(&finfo->fi_hlist,
++                  &au_sbi(file->f_path.dentry->d_sb)->si_files);
 +      bindex = finfo->fi_btop;
 +      if (bindex >= 0)
 +              au_set_h_fptr(file, bindex, NULL);
@@ -11141,914 +13369,629 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 + * read functions after [fdi]_rwsem are released, but it should be harmless.
 + */
 +
-+static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
-+                       loff_t *ppos)
++/* Callers should call au_read_post() or fput() in the end */
++struct file *au_read_pre(struct file *file, int keep_fi)
 +{
-+      ssize_t err;
-+      struct dentry *dentry;
 +      struct file *h_file;
-+      struct super_block *sb;
++      int err;
 +
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
 +      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
-+      if (unlikely(err))
-+              goto out;
++      if (!err) {
++              di_read_unlock(file->f_path.dentry, AuLock_IR);
++              h_file = au_hf_top(file);
++              get_file(h_file);
++              if (!keep_fi)
++                      fi_read_unlock(file);
++      } else
++              h_file = ERR_PTR(err);
 +
-+      h_file = au_hf_top(file);
-+      get_file(h_file);
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_read_unlock(file);
++      return h_file;
++}
 +
-+      /* filedata may be obsoleted by concurrent copyup, but no problem */
-+      err = vfsub_read_u(h_file, buf, count, ppos);
-+      /* todo: necessary? */
-+      /* file->f_ra = h_file->f_ra; */
++static void au_read_post(struct inode *inode, struct file *h_file)
++{
 +      /* update without lock, I don't think it a problem */
-+      fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
++      fsstack_copy_attr_atime(inode, file_inode(h_file));
 +      fput(h_file);
-+
-+out:
-+      si_read_unlock(sb);
-+      return err;
 +}
 +
++struct au_write_pre {
++      blkcnt_t blks;
++      aufs_bindex_t bstart;
++};
++
 +/*
-+ * todo: very ugly
-+ * it locks both of i_mutex and si_rwsem for read in safe.
-+ * if the plink maintenance mode continues forever (that is the problem),
-+ * may loop forever.
++ * return with iinfo is write-locked
++ * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
++ * end
 + */
-+static void au_mtx_and_read_lock(struct inode *inode)
-+{
-+      int err;
-+      struct super_block *sb = inode->i_sb;
-+
-+      while (1) {
-+              mutex_lock(&inode->i_mutex);
-+              err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
-+              if (!err)
-+                      break;
-+              mutex_unlock(&inode->i_mutex);
-+              si_read_lock(sb, AuLock_NOPLMW);
-+              si_read_unlock(sb);
-+      }
-+}
-+
-+static ssize_t aufs_write(struct file *file, const char __user *ubuf,
-+                        size_t count, loff_t *ppos)
++static struct file *au_write_pre(struct file *file, int do_ready,
++                               struct au_write_pre *wpre)
 +{
-+      ssize_t err;
-+      struct au_pin pin;
-+      struct dentry *dentry;
-+      struct super_block *sb;
-+      struct inode *inode;
 +      struct file *h_file;
-+      char __user *buf = (char __user *)ubuf;
-+
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      inode = dentry->d_inode;
-+      au_mtx_and_read_lock(inode);
-+
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
-+      if (unlikely(err))
-+              goto out;
-+
-+      err = au_ready_to_write(file, -1, &pin);
-+      di_downgrade_lock(dentry, AuLock_IR);
-+      if (unlikely(err)) {
-+              di_read_unlock(dentry, AuLock_IR);
-+              fi_write_unlock(file);
-+              goto out;
-+      }
-+
-+      h_file = au_hf_top(file);
-+      get_file(h_file);
-+      au_unpin(&pin);
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_write_unlock(file);
-+
-+      err = vfsub_write_u(h_file, buf, count, ppos);
-+      ii_write_lock_child(inode);
-+      au_cpup_attr_timesizes(inode);
-+      inode->i_mode = h_file->f_dentry->d_inode->i_mode;
-+      ii_write_unlock(inode);
-+      fput(h_file);
-+
-+out:
-+      si_read_unlock(sb);
-+      mutex_unlock(&inode->i_mutex);
-+      return err;
-+}
-+
-+static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
-+                       const struct iovec *iov, unsigned long nv, loff_t pos)
-+{
-+      ssize_t err;
-+      struct file *file;
-+      ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
-+                      loff_t);
-+
-+      err = security_file_permission(h_file, rw);
-+      if (unlikely(err))
-+              goto out;
-+
-+      err = -ENOSYS;
-+      func = NULL;
-+      if (rw == MAY_READ)
-+              func = h_file->f_op->aio_read;
-+      else if (rw == MAY_WRITE)
-+              func = h_file->f_op->aio_write;
-+      if (func) {
-+              file = kio->ki_filp;
-+              kio->ki_filp = h_file;
-+              lockdep_off();
-+              err = func(kio, iov, nv, pos);
-+              lockdep_on();
-+              kio->ki_filp = file;
-+      } else
-+              /* currently there is no such fs */
-+              WARN_ON_ONCE(1);
-+
-+out:
-+      return err;
-+}
-+
-+static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
-+                           unsigned long nv, loff_t pos)
-+{
-+      ssize_t err;
-+      struct file *file, *h_file;
 +      struct dentry *dentry;
-+      struct super_block *sb;
-+
-+      file = kio->ki_filp;
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
-+      if (unlikely(err))
-+              goto out;
-+
-+      h_file = au_hf_top(file);
-+      get_file(h_file);
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_read_unlock(file);
-+
-+      err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
-+      /* todo: necessary? */
-+      /* file->f_ra = h_file->f_ra; */
-+      /* update without lock, I don't think it a problem */
-+      fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
-+      fput(h_file);
-+
-+out:
-+      si_read_unlock(sb);
-+      return err;
-+}
-+
-+static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
-+                            unsigned long nv, loff_t pos)
-+{
-+      ssize_t err;
++      int err;
 +      struct au_pin pin;
-+      struct dentry *dentry;
-+      struct inode *inode;
-+      struct file *file, *h_file;
-+      struct super_block *sb;
-+
-+      file = kio->ki_filp;
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      inode = dentry->d_inode;
-+      au_mtx_and_read_lock(inode);
 +
 +      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
-+      if (unlikely(err))
-+              goto out;
-+
-+      err = au_ready_to_write(file, -1, &pin);
-+      di_downgrade_lock(dentry, AuLock_IR);
-+      if (unlikely(err)) {
-+              di_read_unlock(dentry, AuLock_IR);
-+              fi_write_unlock(file);
++      h_file = ERR_PTR(err);
++      if (unlikely(err))
 +              goto out;
++
++      dentry = file->f_path.dentry;
++      if (do_ready) {
++              err = au_ready_to_write(file, -1, &pin);
++              if (unlikely(err)) {
++                      h_file = ERR_PTR(err);
++                      di_write_unlock(dentry);
++                      goto out_fi;
++              }
 +      }
 +
++      di_downgrade_lock(dentry, /*flags*/0);
++      if (wpre)
++              wpre->bstart = au_fbstart(file);
 +      h_file = au_hf_top(file);
 +      get_file(h_file);
-+      au_unpin(&pin);
-+      di_read_unlock(dentry, AuLock_IR);
++      if (wpre)
++              wpre->blks = file_inode(h_file)->i_blocks;
++      if (do_ready)
++              au_unpin(&pin);
++      di_read_unlock(dentry, /*flags*/0);
++
++out_fi:
 +      fi_write_unlock(file);
++out:
++      return h_file;
++}
++
++static void au_write_post(struct inode *inode, struct file *h_file,
++                        struct au_write_pre *wpre, ssize_t written)
++{
++      struct inode *h_inode;
 +
-+      err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
-+      ii_write_lock_child(inode);
 +      au_cpup_attr_timesizes(inode);
-+      inode->i_mode = h_file->f_dentry->d_inode->i_mode;
++      AuDebugOn(au_ibstart(inode) != wpre->bstart);
++      h_inode = file_inode(h_file);
++      inode->i_mode = h_inode->i_mode;
 +      ii_write_unlock(inode);
 +      fput(h_file);
 +
-+out:
-+      si_read_unlock(sb);
-+      mutex_unlock(&inode->i_mutex);
-+      return err;
++      /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
++      if (written > 0)
++              au_fhsm_wrote(inode->i_sb, wpre->bstart,
++                            /*force*/h_inode->i_blocks > wpre->blks);
 +}
 +
-+static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
-+                              struct pipe_inode_info *pipe, size_t len,
-+                              unsigned int flags)
++static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
++                       loff_t *ppos)
 +{
 +      ssize_t err;
++      struct inode *inode;
 +      struct file *h_file;
-+      struct dentry *dentry;
 +      struct super_block *sb;
 +
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
++      inode = file_inode(file);
++      sb = inode->i_sb;
 +      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
-+      if (unlikely(err))
-+              goto out;
 +
-+      err = -EINVAL;
-+      h_file = au_hf_top(file);
-+      get_file(h_file);
-+      if (au_test_loopback_kthread()) {
-+              au_warn_loopback(h_file->f_dentry->d_sb);
-+              if (file->f_mapping != h_file->f_mapping) {
-+                      file->f_mapping = h_file->f_mapping;
-+                      smp_mb(); /* unnecessary? */
-+              }
-+      }
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_read_unlock(file);
++      h_file = au_read_pre(file, /*keep_fi*/0);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out;
 +
-+      err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
-+      /* todo: necessasry? */
++      /* filedata may be obsoleted by concurrent copyup, but no problem */
++      err = vfsub_read_u(h_file, buf, count, ppos);
++      /* todo: necessary? */
 +      /* file->f_ra = h_file->f_ra; */
-+      /* update without lock, I don't think it a problem */
-+      fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
-+      fput(h_file);
++      au_read_post(inode, h_file);
 +
 +out:
 +      si_read_unlock(sb);
 +      return err;
 +}
 +
-+static ssize_t
-+aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
-+                size_t len, unsigned int flags)
++/*
++ * todo: very ugly
++ * it locks both of i_mutex and si_rwsem for read in safe.
++ * if the plink maintenance mode continues forever (that is the problem),
++ * may loop forever.
++ */
++static void au_mtx_and_read_lock(struct inode *inode)
++{
++      int err;
++      struct super_block *sb = inode->i_sb;
++
++      while (1) {
++              mutex_lock(&inode->i_mutex);
++              err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
++              if (!err)
++                      break;
++              mutex_unlock(&inode->i_mutex);
++              si_read_lock(sb, AuLock_NOPLMW);
++              si_read_unlock(sb);
++      }
++}
++
++static ssize_t aufs_write(struct file *file, const char __user *ubuf,
++                        size_t count, loff_t *ppos)
 +{
 +      ssize_t err;
-+      struct au_pin pin;
-+      struct dentry *dentry;
++      struct au_write_pre wpre;
 +      struct inode *inode;
 +      struct file *h_file;
-+      struct super_block *sb;
++      char __user *buf = (char __user *)ubuf;
 +
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      inode = dentry->d_inode;
++      inode = file_inode(file);
 +      au_mtx_and_read_lock(inode);
 +
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
-+      if (unlikely(err))
-+              goto out;
-+
-+      err = au_ready_to_write(file, -1, &pin);
-+      di_downgrade_lock(dentry, AuLock_IR);
-+      if (unlikely(err)) {
-+              di_read_unlock(dentry, AuLock_IR);
-+              fi_write_unlock(file);
++      h_file = au_write_pre(file, /*do_ready*/1, &wpre);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
 +              goto out;
-+      }
-+
-+      h_file = au_hf_top(file);
-+      get_file(h_file);
-+      au_unpin(&pin);
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_write_unlock(file);
 +
-+      err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
-+      ii_write_lock_child(inode);
-+      au_cpup_attr_timesizes(inode);
-+      inode->i_mode = h_file->f_dentry->d_inode->i_mode;
-+      ii_write_unlock(inode);
-+      fput(h_file);
++      err = vfsub_write_u(h_file, buf, count, ppos);
++      au_write_post(inode, h_file, &wpre, err);
 +
 +out:
-+      si_read_unlock(sb);
++      si_read_unlock(inode->i_sb);
 +      mutex_unlock(&inode->i_mutex);
 +      return err;
 +}
 +
-+/* ---------------------------------------------------------------------- */
-+
-+/*
-+ * The locking order around current->mmap_sem.
-+ * - in most and regular cases
-+ *   file I/O syscall -- aufs_read() or something
-+ *    -- si_rwsem for read -- mmap_sem
-+ *    (Note that [fdi]i_rwsem are released before mmap_sem).
-+ * - in mmap case
-+ *   mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
-+ * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
-+ * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
-+ * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
-+ * It means that when aufs acquires si_rwsem for write, the process should never
-+ * acquire mmap_sem.
-+ *
-+ * Actually aufs_readdir() holds [fdi]i_rwsem before mmap_sem, but this is not a
-+ * problem either since any directory is not able to be mmap-ed.
-+ * The similar scenario is applied to aufs_readlink() too.
-+ */
-+
-+/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
-+#define AuConv_VM_PROT(f, b)  _calc_vm_trans(f, VM_##b, PROT_##b)
-+
-+static unsigned long au_arch_prot_conv(unsigned long flags)
-+{
-+      /* currently ppc64 only */
-+#ifdef CONFIG_PPC64
-+      /* cf. linux/arch/powerpc/include/asm/mman.h */
-+      AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
-+      return AuConv_VM_PROT(flags, SAO);
-+#else
-+      AuDebugOn(arch_calc_vm_prot_bits(-1));
-+      return 0;
-+#endif
-+}
-+
-+static unsigned long au_prot_conv(unsigned long flags)
-+{
-+      return AuConv_VM_PROT(flags, READ)
-+              | AuConv_VM_PROT(flags, WRITE)
-+              | AuConv_VM_PROT(flags, EXEC)
-+              | au_arch_prot_conv(flags);
-+}
-+
-+/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
-+#define AuConv_VM_MAP(f, b)   _calc_vm_trans(f, VM_##b, MAP_##b)
-+
-+static unsigned long au_flag_conv(unsigned long flags)
-+{
-+      return AuConv_VM_MAP(flags, GROWSDOWN)
-+              | AuConv_VM_MAP(flags, DENYWRITE)
-+              | AuConv_VM_MAP(flags, LOCKED);
-+}
-+
-+static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
++static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
++                        struct iov_iter *iov_iter)
 +{
-+      int err;
-+      aufs_bindex_t bstart;
-+      const unsigned char wlock
-+              = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
-+      struct dentry *dentry;
-+      struct super_block *sb;
-+      struct file *h_file;
-+      struct au_branch *br;
-+      struct au_pin pin;
-+
-+      AuDbgVmRegion(file, vma);
++      ssize_t err;
++      struct file *file;
++      ssize_t (*iter)(struct kiocb *, struct iov_iter *);
++      ssize_t (*aio)(struct kiocb *, const struct iovec *, unsigned long,
++                     loff_t);
 +
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      lockdep_off();
-+      si_read_lock(sb, AuLock_NOPLMW);
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
++      err = security_file_permission(h_file, rw);
 +      if (unlikely(err))
 +              goto out;
 +
-+      if (wlock) {
-+              err = au_ready_to_write(file, -1, &pin);
-+              di_write_unlock(dentry);
-+              if (unlikely(err)) {
-+                      fi_write_unlock(file);
-+                      goto out;
-+              }
-+              au_unpin(&pin);
-+      } else
-+              di_write_unlock(dentry);
-+
-+      bstart = au_fbstart(file);
-+      br = au_sbr(sb, bstart);
-+      h_file = au_hf_top(file);
-+      get_file(h_file);
-+      au_set_mmapped(file);
-+      fi_write_unlock(file);
-+      lockdep_on();
-+
-+      au_vm_file_reset(vma, h_file);
-+      err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
-+                               au_flag_conv(vma->vm_flags));
-+      if (!err)
-+              err = h_file->f_op->mmap(h_file, vma);
-+      if (unlikely(err))
-+              goto out_reset;
++      err = -ENOSYS;
++      iter = NULL;
++      aio = NULL;
++      if (rw == MAY_READ) {
++              iter = h_file->f_op->read_iter;
++              aio = h_file->f_op->aio_read;
++      } else if (rw == MAY_WRITE) {
++              iter = h_file->f_op->write_iter;
++              aio = h_file->f_op->aio_write;
++      }
 +
-+      au_vm_prfile_set(vma, file);
-+      /* update without lock, I don't think it a problem */
-+      fsstack_copy_attr_atime(file->f_dentry->d_inode,
-+                              h_file->f_dentry->d_inode);
-+      goto out_fput; /* success */
++      file = kio->ki_filp;
++      kio->ki_filp = h_file;
++      if (iter) {
++              lockdep_off();
++              err = iter(kio, iov_iter);
++              lockdep_on();
++      } else if (aio) {
++              lockdep_off();
++              err = aio(kio, iov_iter->iov, iov_iter->nr_segs, kio->ki_pos);
++              lockdep_on();
++      } else
++              /* currently there is no such fs */
++              WARN_ON_ONCE(1);
++      kio->ki_filp = file;
 +
-+out_reset:
-+      au_unset_mmapped(file);
-+      au_vm_file_reset(vma, file);
-+out_fput:
-+      fput(h_file);
-+      lockdep_off();
 +out:
-+      si_read_unlock(sb);
-+      lockdep_on();
-+      AuTraceErr(err);
 +      return err;
 +}
 +
-+/* ---------------------------------------------------------------------- */
-+
-+static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
-+                           int datasync)
++static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
 +{
-+      int err;
-+      struct au_pin pin;
-+      struct dentry *dentry;
++      ssize_t err;
++      struct file *file, *h_file;
 +      struct inode *inode;
-+      struct file *h_file;
 +      struct super_block *sb;
 +
-+      dentry = file->f_dentry;
-+      inode = dentry->d_inode;
-+      sb = dentry->d_sb;
-+      mutex_lock(&inode->i_mutex);
-+      err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
-+      if (unlikely(err))
-+              goto out;
-+
-+      err = 0; /* -EBADF; */ /* posix? */
-+      if (unlikely(!(file->f_mode & FMODE_WRITE)))
-+              goto out_si;
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
-+      if (unlikely(err))
-+              goto out_si;
++      file = kio->ki_filp;
++      inode = file_inode(file);
++      sb = inode->i_sb;
++      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
 +
-+      err = au_ready_to_write(file, -1, &pin);
-+      di_downgrade_lock(dentry, AuLock_IR);
-+      if (unlikely(err))
-+              goto out_unlock;
-+      au_unpin(&pin);
++      h_file = au_read_pre(file, /*keep_fi*/0);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out;
 +
-+      err = -EINVAL;
-+      h_file = au_hf_top(file);
-+      err = vfsub_fsync(h_file, &h_file->f_path, datasync);
-+      au_cpup_attr_timesizes(inode);
++      err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
++      /* todo: necessary? */
++      /* file->f_ra = h_file->f_ra; */
++      au_read_post(inode, h_file);
 +
-+out_unlock:
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_write_unlock(file);
-+out_si:
-+      si_read_unlock(sb);
 +out:
-+      mutex_unlock(&inode->i_mutex);
++      si_read_unlock(sb);
 +      return err;
 +}
 +
-+/* no one supports this operation, currently */
-+#if 0
-+static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
++static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
 +{
-+      int err;
-+      struct au_pin pin;
-+      struct dentry *dentry;
++      ssize_t err;
++      struct au_write_pre wpre;
 +      struct inode *inode;
 +      struct file *file, *h_file;
 +
 +      file = kio->ki_filp;
-+      dentry = file->f_dentry;
-+      inode = dentry->d_inode;
++      inode = file_inode(file);
 +      au_mtx_and_read_lock(inode);
 +
-+      err = 0; /* -EBADF; */ /* posix? */
-+      if (unlikely(!(file->f_mode & FMODE_WRITE)))
-+              goto out;
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
-+      if (unlikely(err))
++      h_file = au_write_pre(file, /*do_ready*/1, &wpre);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
 +              goto out;
 +
-+      err = au_ready_to_write(file, -1, &pin);
-+      di_downgrade_lock(dentry, AuLock_IR);
-+      if (unlikely(err))
-+              goto out_unlock;
-+      au_unpin(&pin);
-+
-+      err = -ENOSYS;
-+      h_file = au_hf_top(file);
-+      if (h_file->f_op && h_file->f_op->aio_fsync) {
-+              struct dentry *h_d;
-+              struct mutex *h_mtx;
-+
-+              h_d = h_file->f_dentry;
-+              h_mtx = &h_d->d_inode->i_mutex;
-+              if (!is_sync_kiocb(kio)) {
-+                      get_file(h_file);
-+                      fput(file);
-+              }
-+              kio->ki_filp = h_file;
-+              err = h_file->f_op->aio_fsync(kio, datasync);
-+              mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
-+              if (!err)
-+                      vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
-+              /*ignore*/
-+              au_cpup_attr_timesizes(inode);
-+              mutex_unlock(h_mtx);
-+      }
++      err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
++      au_write_post(inode, h_file, &wpre, err);
 +
-+out_unlock:
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_write_unlock(file);
 +out:
-+      si_read_unlock(inode->sb);
++      si_read_unlock(inode->i_sb);
 +      mutex_unlock(&inode->i_mutex);
 +      return err;
 +}
-+#endif
 +
-+static int aufs_fasync(int fd, struct file *file, int flag)
++static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
++                              struct pipe_inode_info *pipe, size_t len,
++                              unsigned int flags)
 +{
-+      int err;
++      ssize_t err;
 +      struct file *h_file;
-+      struct dentry *dentry;
++      struct inode *inode;
 +      struct super_block *sb;
 +
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
++      inode = file_inode(file);
++      sb = inode->i_sb;
 +      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
-+      if (unlikely(err))
-+              goto out;
 +
-+      h_file = au_hf_top(file);
-+      if (h_file->f_op && h_file->f_op->fasync)
-+              err = h_file->f_op->fasync(fd, h_file, flag);
++      h_file = au_read_pre(file, /*keep_fi*/1);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out;
 +
-+      di_read_unlock(dentry, AuLock_IR);
++      if (au_test_loopback_kthread()) {
++              au_warn_loopback(h_file->f_path.dentry->d_sb);
++              if (file->f_mapping != h_file->f_mapping) {
++                      file->f_mapping = h_file->f_mapping;
++                      smp_mb(); /* unnecessary? */
++              }
++      }
 +      fi_read_unlock(file);
 +
++      err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
++      /* todo: necessasry? */
++      /* file->f_ra = h_file->f_ra; */
++      au_read_post(inode, h_file);
++
 +out:
 +      si_read_unlock(sb);
 +      return err;
 +}
 +
-+/* ---------------------------------------------------------------------- */
-+
-+/* no one supports this operation, currently */
-+#if 0
-+static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
-+                           size_t len, loff_t *pos , int more)
++static ssize_t
++aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
++                size_t len, unsigned int flags)
 +{
++      ssize_t err;
++      struct au_write_pre wpre;
++      struct inode *inode;
++      struct file *h_file;
++
++      inode = file_inode(file);
++      au_mtx_and_read_lock(inode);
++
++      h_file = au_write_pre(file, /*do_ready*/1, &wpre);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out;
++
++      err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
++      au_write_post(inode, h_file, &wpre, err);
++
++out:
++      si_read_unlock(inode->i_sb);
++      mutex_unlock(&inode->i_mutex);
++      return err;
 +}
-+#endif
 +
-+/* ---------------------------------------------------------------------- */
++static long aufs_fallocate(struct file *file, int mode, loff_t offset,
++                         loff_t len)
++{
++      long err;
++      struct au_write_pre wpre;
++      struct inode *inode;
++      struct file *h_file;
 +
-+const struct file_operations aufs_file_fop = {
-+      .owner          = THIS_MODULE,
++      inode = file_inode(file);
++      au_mtx_and_read_lock(inode);
 +
-+      .llseek         = default_llseek,
++      h_file = au_write_pre(file, /*do_ready*/1, &wpre);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out;
 +
-+      .read           = aufs_read,
-+      .write          = aufs_write,
-+      .aio_read       = aufs_aio_read,
-+      .aio_write      = aufs_aio_write,
-+#ifdef CONFIG_AUFS_POLL
-+      .poll           = aufs_poll,
-+#endif
-+      .unlocked_ioctl = aufs_ioctl_nondir,
-+#ifdef CONFIG_COMPAT
-+      .compat_ioctl   = aufs_ioctl_nondir, /* same */
-+#endif
-+      .mmap           = aufs_mmap,
-+      .open           = aufs_open_nondir,
-+      .flush          = aufs_flush_nondir,
-+      .release        = aufs_release_nondir,
-+      .fsync          = aufs_fsync_nondir,
-+      /* .aio_fsync   = aufs_aio_fsync_nondir, */
-+      .fasync         = aufs_fasync,
-+      /* .sendpage    = aufs_sendpage, */
-+      .splice_write   = aufs_splice_write,
-+      .splice_read    = aufs_splice_read,
-+#if 0
-+      .aio_splice_write = aufs_aio_splice_write,
-+      .aio_splice_read  = aufs_aio_splice_read
-+#endif
-+};
-diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
---- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/f_op_sp.c    2013-03-14 20:07:41.041453062 +0100
-@@ -0,0 +1,295 @@
-+/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
-+ *
-+ * This program, aufs is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-+ */
++      lockdep_off();
++      err = vfs_fallocate(h_file, mode, offset, len);
++      lockdep_on();
++      au_write_post(inode, h_file, &wpre, /*written*/1);
++
++out:
++      si_read_unlock(inode->i_sb);
++      mutex_unlock(&inode->i_mutex);
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
 +
 +/*
-+ * file operations for special files.
-+ * while they exist in aufs virtually,
-+ * their file I/O is handled out of aufs.
++ * The locking order around current->mmap_sem.
++ * - in most and regular cases
++ *   file I/O syscall -- aufs_read() or something
++ *    -- si_rwsem for read -- mmap_sem
++ *    (Note that [fdi]i_rwsem are released before mmap_sem).
++ * - in mmap case
++ *   mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
++ * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
++ * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
++ * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
++ * It means that when aufs acquires si_rwsem for write, the process should never
++ * acquire mmap_sem.
++ *
++ * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
++ * problem either since any directory is not able to be mmap-ed.
++ * The similar scenario is applied to aufs_readlink() too.
 + */
 +
-+#include "aufs.h"
++#if 0 /* stop calling security_file_mmap() */
++/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
++#define AuConv_VM_PROT(f, b)  _calc_vm_trans(f, VM_##b, PROT_##b)
 +
-+static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
-+                              unsigned long nv, loff_t pos)
++static unsigned long au_arch_prot_conv(unsigned long flags)
 +{
-+      ssize_t err;
-+      aufs_bindex_t bstart;
-+      unsigned char wbr;
-+      struct file *file, *h_file;
-+      struct super_block *sb;
++      /* currently ppc64 only */
++#ifdef CONFIG_PPC64
++      /* cf. linux/arch/powerpc/include/asm/mman.h */
++      AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
++      return AuConv_VM_PROT(flags, SAO);
++#else
++      AuDebugOn(arch_calc_vm_prot_bits(-1));
++      return 0;
++#endif
++}
 +
-+      file = kio->ki_filp;
-+      sb = file->f_dentry->d_sb;
-+      si_read_lock(sb, AuLock_FLUSH);
-+      fi_read_lock(file);
-+      bstart = au_fbstart(file);
-+      h_file = au_hf_top(file);
-+      fi_read_unlock(file);
-+      wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
-+      si_read_unlock(sb);
++static unsigned long au_prot_conv(unsigned long flags)
++{
++      return AuConv_VM_PROT(flags, READ)
++              | AuConv_VM_PROT(flags, WRITE)
++              | AuConv_VM_PROT(flags, EXEC)
++              | au_arch_prot_conv(flags);
++}
 +
-+      /* do not change the file in kio */
-+      AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
-+      err = h_file->f_op->aio_read(kio, iov, nv, pos);
-+      if (err > 0 && wbr)
-+              file_accessed(h_file);
++/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
++#define AuConv_VM_MAP(f, b)   _calc_vm_trans(f, VM_##b, MAP_##b)
 +
-+      return err;
++static unsigned long au_flag_conv(unsigned long flags)
++{
++      return AuConv_VM_MAP(flags, GROWSDOWN)
++              | AuConv_VM_MAP(flags, DENYWRITE)
++              | AuConv_VM_MAP(flags, LOCKED);
 +}
++#endif
 +
-+static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
-+                               unsigned long nv, loff_t pos)
++static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
 +{
-+      ssize_t err;
-+      aufs_bindex_t bstart;
-+      unsigned char wbr;
++      int err;
++      const unsigned char wlock
++              = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
 +      struct super_block *sb;
-+      struct file *file, *h_file;
++      struct file *h_file;
++      struct inode *inode;
++
++      AuDbgVmRegion(file, vma);
++
++      inode = file_inode(file);
++      sb = inode->i_sb;
++      lockdep_off();
++      si_read_lock(sb, AuLock_NOPLMW);
++
++      h_file = au_write_pre(file, wlock, /*wpre*/NULL);
++      lockdep_on();
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out;
++
++      err = 0;
++      au_set_mmapped(file);
++      au_vm_file_reset(vma, h_file);
++      /*
++       * we cannot call security_mmap_file() here since it may acquire
++       * mmap_sem or i_mutex.
++       *
++       * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
++       *                       au_flag_conv(vma->vm_flags));
++       */
++      if (!err)
++              err = h_file->f_op->mmap(h_file, vma);
++      if (!err) {
++              au_vm_prfile_set(vma, file);
++              fsstack_copy_attr_atime(inode, file_inode(h_file));
++              goto out_fput; /* success */
++      }
++      au_unset_mmapped(file);
++      au_vm_file_reset(vma, file);
 +
-+      file = kio->ki_filp;
-+      sb = file->f_dentry->d_sb;
-+      si_read_lock(sb, AuLock_FLUSH);
-+      fi_read_lock(file);
-+      bstart = au_fbstart(file);
-+      h_file = au_hf_top(file);
-+      fi_read_unlock(file);
-+      wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
++out_fput:
++      lockdep_off();
++      ii_write_unlock(inode);
++      lockdep_on();
++      fput(h_file);
++out:
++      lockdep_off();
 +      si_read_unlock(sb);
-+
-+      /* do not change the file in kio */
-+      AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
-+      err = h_file->f_op->aio_write(kio, iov, nv, pos);
++      lockdep_on();
++      AuTraceErr(err);
 +      return err;
 +}
 +
 +/* ---------------------------------------------------------------------- */
 +
-+static int aufs_release_sp(struct inode *inode, struct file *file)
++static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
++                           int datasync)
 +{
 +      int err;
++      struct au_write_pre wpre;
++      struct inode *inode;
 +      struct file *h_file;
 +
-+      fi_read_lock(file);
-+      h_file = au_hf_top(file);
-+      fi_read_unlock(file);
-+      /* close this fifo in aufs */
-+      err = h_file->f_op->release(inode, file); /* ignore */
-+      aufs_release_nondir(inode, file); /* ignore */
-+      return err;
-+}
-+
-+/* ---------------------------------------------------------------------- */
-+
-+/* currently, support only FIFO */
-+enum {
-+      AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
-+      /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
-+      AuSp_Last
-+};
-+static int aufs_open_sp(struct inode *inode, struct file *file);
-+static struct au_sp_fop {
-+      int                     done;
-+      struct file_operations  fop;    /* not 'const' */
-+      spinlock_t              spin;
-+} au_sp_fop[AuSp_Last] = {
-+      [AuSp_FIFO] = {
-+              .fop    = {
-+                      .owner  = THIS_MODULE,
-+                      .open   = aufs_open_sp
-+              }
-+      }
-+};
-+
-+static void au_init_fop_sp(struct file *file)
-+{
-+      struct au_sp_fop *p;
-+      int i;
-+      struct file *h_file;
++      err = 0; /* -EBADF; */ /* posix? */
++      if (unlikely(!(file->f_mode & FMODE_WRITE)))
++              goto out;
 +
-+      p = au_sp_fop;
-+      if (unlikely(!p->done)) {
-+              /* initialize first time only */
-+              static DEFINE_SPINLOCK(spin);
++      inode = file_inode(file);
++      au_mtx_and_read_lock(inode);
 +
-+              spin_lock(&spin);
-+              if (!p->done) {
-+                      BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
-+                                   != AuSp_Last);
-+                      for (i = 0; i < AuSp_Last; i++)
-+                              spin_lock_init(&p[i].spin);
-+                      p->done = 1;
-+              }
-+              spin_unlock(&spin);
-+      }
++      h_file = au_write_pre(file, /*do_ready*/1, &wpre);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out_unlock;
 +
-+      switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
-+      case FMODE_READ:
-+              i = AuSp_FIFO_R;
-+              break;
-+      case FMODE_WRITE:
-+              i = AuSp_FIFO_W;
-+              break;
-+      case FMODE_READ | FMODE_WRITE:
-+              i = AuSp_FIFO_RW;
-+              break;
-+      default:
-+              BUG();
-+      }
++      err = vfsub_fsync(h_file, &h_file->f_path, datasync);
++      au_write_post(inode, h_file, &wpre, /*written*/0);
 +
-+      p += i;
-+      if (unlikely(!p->done)) {
-+              /* initialize first time only */
-+              h_file = au_hf_top(file);
-+              spin_lock(&p->spin);
-+              if (!p->done) {
-+                      p->fop = *h_file->f_op;
-+                      p->fop.owner = THIS_MODULE;
-+                      if (p->fop.aio_read)
-+                              p->fop.aio_read = aufs_aio_read_sp;
-+                      if (p->fop.aio_write)
-+                              p->fop.aio_write = aufs_aio_write_sp;
-+                      p->fop.release = aufs_release_sp;
-+                      p->done = 1;
-+              }
-+              spin_unlock(&p->spin);
-+      }
-+      file->f_op = &p->fop;
++out_unlock:
++      si_read_unlock(inode->i_sb);
++      mutex_unlock(&inode->i_mutex);
++out:
++      return err;
 +}
 +
-+static int au_cpup_sp(struct dentry *dentry)
++/* no one supports this operation, currently */
++#if 0
++static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
 +{
 +      int err;
-+      aufs_bindex_t bcpup;
-+      struct au_pin pin;
-+      struct au_wr_dir_args wr_dir_args = {
-+              .force_btgt     = -1,
-+              .flags          = 0
-+      };
-+
-+      AuDbg("%.*s\n", AuDLNPair(dentry));
++      struct au_write_pre wpre;
++      struct inode *inode;
++      struct file *file, *h_file;
 +
-+      di_read_unlock(dentry, AuLock_IR);
-+      di_write_lock_child(dentry);
-+      err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
-+      if (unlikely(err < 0))
++      err = 0; /* -EBADF; */ /* posix? */
++      if (unlikely(!(file->f_mode & FMODE_WRITE)))
 +              goto out;
-+      bcpup = err;
-+      err = 0;
-+      if (bcpup == au_dbstart(dentry))
-+              goto out; /* success */
 +
-+      err = au_pin(&pin, dentry, bcpup, au_opt_udba(dentry->d_sb),
-+                   AuPin_MNT_WRITE);
-+      if (!err) {
-+              err = au_sio_cpup_simple(dentry, bcpup, -1, AuCpup_DTIME);
-+              au_unpin(&pin);
++      file = kio->ki_filp;
++      inode = file_inode(file);
++      au_mtx_and_read_lock(inode);
++
++      h_file = au_write_pre(file, /*do_ready*/1, &wpre);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out_unlock;
++
++      err = -ENOSYS;
++      h_file = au_hf_top(file);
++      if (h_file->f_op->aio_fsync) {
++              struct mutex *h_mtx;
++
++              h_mtx = &file_inode(h_file)->i_mutex;
++              if (!is_sync_kiocb(kio)) {
++                      get_file(h_file);
++                      fput(file);
++              }
++              kio->ki_filp = h_file;
++              err = h_file->f_op->aio_fsync(kio, datasync);
++              mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
++              if (!err)
++                      vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
++              /*ignore*/
++              mutex_unlock(h_mtx);
 +      }
++      au_write_post(inode, h_file, &wpre, /*written*/0);
 +
++out_unlock:
++      si_read_unlock(inode->sb);
++      mutex_unlock(&inode->i_mutex);
 +out:
-+      di_downgrade_lock(dentry, AuLock_IR);
 +      return err;
 +}
++#endif
 +
-+static int au_do_open_sp(struct file *file, int flags)
++static int aufs_fasync(int fd, struct file *file, int flag)
 +{
 +      int err;
-+      struct dentry *dentry;
-+      struct super_block *sb;
 +      struct file *h_file;
-+      struct inode *h_inode;
-+
-+      dentry = file->f_dentry;
-+      AuDbg("%.*s\n", AuDLNPair(dentry));
++      struct super_block *sb;
 +
-+      /*
-+       * try copying-up.
-+       * operate on the ro branch is not an error.
-+       */
-+      au_cpup_sp(dentry); /* ignore */
++      sb = file->f_path.dentry->d_sb;
++      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
 +
-+      /* prepare h_file */
-+      err = au_do_open_nondir(file, vfsub_file_flags(file));
-+      if (unlikely(err))
++      h_file = au_read_pre(file, /*keep_fi*/0);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
 +              goto out;
 +
-+      sb = dentry->d_sb;
-+      h_file = au_hf_top(file);
-+      h_inode = h_file->f_dentry->d_inode;
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_write_unlock(file);
-+      si_read_unlock(sb);
-+      /* open this fifo in aufs */
-+      err = h_inode->i_fop->open(file->f_dentry->d_inode, file);
-+      si_noflush_read_lock(sb);
-+      fi_write_lock(file);
-+      di_read_lock_child(dentry, AuLock_IR);
-+      if (!err)
-+              au_init_fop_sp(file);
++      if (h_file->f_op->fasync)
++              err = h_file->f_op->fasync(fd, h_file, flag);
++      fput(h_file); /* instead of au_read_post() */
 +
 +out:
++      si_read_unlock(sb);
 +      return err;
 +}
 +
-+static int aufs_open_sp(struct inode *inode, struct file *file)
-+{
-+      int err;
-+      struct super_block *sb;
++/* ---------------------------------------------------------------------- */
 +
-+      sb = file->f_dentry->d_sb;
-+      si_read_lock(sb, AuLock_FLUSH);
-+      err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
-+      si_read_unlock(sb);
-+      return err;
++/* no one supports this operation, currently */
++#if 0
++static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
++                           size_t len, loff_t *pos, int more)
++{
 +}
++#endif
 +
 +/* ---------------------------------------------------------------------- */
 +
-+void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
-+{
-+      init_special_inode(inode, mode, rdev);
++const struct file_operations aufs_file_fop = {
++      .owner          = THIS_MODULE,
 +
-+      switch (mode & S_IFMT) {
-+      case S_IFIFO:
-+              inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
-+              /*FALLTHROUGH*/
-+      case S_IFCHR:
-+      case S_IFBLK:
-+      case S_IFSOCK:
-+              break;
-+      default:
-+              AuDebugOn(1);
-+      }
-+}
++      .llseek         = default_llseek,
 +
-+int au_special_file(umode_t mode)
-+{
-+      int ret;
++      .read           = aufs_read,
++      .write          = aufs_write,
++      .read_iter      = aufs_read_iter,
++      .write_iter     = aufs_write_iter,
 +
-+      ret = 0;
-+      switch (mode & S_IFMT) {
-+      case S_IFIFO:
++#ifdef CONFIG_AUFS_POLL
++      .poll           = aufs_poll,
++#endif
++      .unlocked_ioctl = aufs_ioctl_nondir,
++#ifdef CONFIG_COMPAT
++      .compat_ioctl   = aufs_compat_ioctl_nondir,
++#endif
++      .mmap           = aufs_mmap,
++      .open           = aufs_open_nondir,
++      .flush          = aufs_flush_nondir,
++      .release        = aufs_release_nondir,
++      .fsync          = aufs_fsync_nondir,
++      /* .aio_fsync   = aufs_aio_fsync_nondir, */
++      .fasync         = aufs_fasync,
++      /* .sendpage    = aufs_sendpage, */
++      .splice_write   = aufs_splice_write,
++      .splice_read    = aufs_splice_read,
 +#if 0
-+      case S_IFCHR:
-+      case S_IFBLK:
-+      case S_IFSOCK:
++      .aio_splice_write = aufs_aio_splice_write,
++      .aio_splice_read  = aufs_aio_splice_read,
 +#endif
-+              ret = 1;
-+      }
-+
-+      return ret;
-+}
++      .fallocate      = aufs_fallocate
++};
 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 --- /usr/share/empty/fs/aufs/fstype.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/fstype.h     2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,481 @@
++++ linux/fs/aufs/fstype.h     2015-06-22 08:27:37.880835119 +0200
+@@ -0,0 +1,400 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -12061,8 +14004,7 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -12077,6 +14019,7 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +#include <linux/fs.h>
 +#include <linux/magic.h>
 +#include <linux/romfs_fs.h>
++#include <linux/nfs_fs.h>
 +
 +static inline int au_test_aufs(struct super_block *sb)
 +{
@@ -12090,8 +14033,8 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +
 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
 +{
-+#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
-+      return sb->s_magic == ROMFS_MAGIC;
++#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
++      return sb->s_magic == ISOFS_SUPER_MAGIC;
 +#else
 +      return 0;
 +#endif
@@ -12099,8 +14042,8 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +
 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
 +{
-+#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
-+      return sb->s_magic == ISOFS_SUPER_MAGIC;
++#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
++      return sb->s_magic == ROMFS_MAGIC;
 +#else
 +      return 0;
 +#endif
@@ -12132,91 +14075,28 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +#endif
 +}
 +
-+static inline int au_test_xfs(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
-+      return sb->s_magic == XFS_SB_MAGIC;
-+#else
-+      return 0;
-+#endif
-+}
-+
-+static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
-+{
-+#ifdef CONFIG_TMPFS
-+      return sb->s_magic == TMPFS_MAGIC;
-+#else
-+      return 0;
-+#endif
-+}
-+
-+static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
-+      return !strcmp(au_sbtype(sb), "ecryptfs");
-+#else
-+      return 0;
-+#endif
-+}
-+
-+static inline int au_test_smbfs(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_SMB_FS) || defined(CONFIG_SMB_FS_MODULE)
-+      return sb->s_magic == SMB_SUPER_MAGIC;
-+#else
-+      return 0;
-+#endif
-+}
-+
-+static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
-+      return sb->s_magic == OCFS2_SUPER_MAGIC;
-+#else
-+      return 0;
-+#endif
-+}
-+
-+static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
-+      return sb->s_magic == DLMFS_MAGIC;
-+#else
-+      return 0;
-+#endif
-+}
-+
-+static inline int au_test_coda(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
-+      return sb->s_magic == CODA_SUPER_MAGIC;
-+#else
-+      return 0;
-+#endif
-+}
-+
-+static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
++static inline int au_test_xfs(struct super_block *sb __maybe_unused)
 +{
-+#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
-+      return sb->s_magic == V9FS_MAGIC;
++#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
++      return sb->s_magic == XFS_SB_MAGIC;
 +#else
 +      return 0;
 +#endif
 +}
 +
-+static inline int au_test_ext4(struct super_block *sb __maybe_unused)
++static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
 +{
-+#if defined(CONFIG_EXT4DEV_FS) || defined(CONFIG_EXT4DEV_FS_MODULE)
-+      return sb->s_magic == EXT4_SUPER_MAGIC;
++#ifdef CONFIG_TMPFS
++      return sb->s_magic == TMPFS_MAGIC;
 +#else
 +      return 0;
 +#endif
 +}
 +
-+static inline int au_test_sysv(struct super_block *sb __maybe_unused)
++static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
 +{
-+#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
-+      return !strcmp(au_sbtype(sb), "sysv");
++#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
++      return !strcmp(au_sbtype(sb), "ecryptfs");
 +#else
 +      return 0;
 +#endif
@@ -12276,15 +14156,6 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +#endif
 +}
 +
-+static inline int au_test_cifs(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
-+      return sb->s_magic == CIFS_MAGIC_NUMBER;
-+#else
-+      return 0;
-+#endif
-+}
-+
 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
 +{
 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
@@ -12414,11 +14285,7 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +{
 +      return au_test_nfs(sb)
 +              || au_test_fuse(sb)
-+              /* || au_test_smbfs(sb) */      /* untested */
-+              /* || au_test_ocfs2(sb) */      /* untested */
 +              /* || au_test_btrfs(sb) */      /* untested */
-+              /* || au_test_coda(sb) */       /* untested */
-+              /* || au_test_v9fs(sb) */       /* untested */
 +              ;
 +}
 +
@@ -12431,10 +14298,6 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +              || au_test_btrfs(sb)
 +              || au_test_ubifs(sb)
 +              || au_test_hfsplus(sb)  /* maintained, but incorrect */
-+              /* || au_test_ext4(sb) */       /* untested */
-+              /* || au_test_ocfs2(sb) */      /* untested */
-+              /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
-+              /* || au_test_sysv(sb) */       /* untested */
 +              /* || au_test_minix(sb) */      /* untested */
 +              ;
 +}
@@ -12446,7 +14309,6 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
 +{
 +      return au_test_fs_bad_iattr_size(sb)
-+              /* || au_test_cifs(sb) */       /* untested */
 +              || au_test_fat(sb)
 +              || au_test_msdos(sb)
 +              || au_test_vfat(sb);
@@ -12460,7 +14322,6 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +              || au_test_ramfs(sb)
 +#endif
 +              || au_test_ubifs(sb)
-+              || au_test_btrfs(sb)
 +              || au_test_hfsplus(sb);
 +}
 +
@@ -12472,19 +14333,9 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +      return au_test_nfs(sb)
 +              || au_test_fuse(sb)
 +              || au_test_ubifs(sb)
-+              /* || au_test_cifs(sb) */       /* untested */
 +              ;
 +}
 +
-+/*
-+ * filesystems which requires replacing i_mapping.
-+ */
-+static inline int au_test_fs_bad_mapping(struct super_block *sb)
-+{
-+      return au_test_fuse(sb)
-+              || au_test_ubifs(sb);
-+}
-+
 +/* temporary support for i#1 in cramfs */
 +static inline int au_test_fs_unique_ino(struct inode *inode)
 +{
@@ -12526,14 +14377,25 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +              || au_test_romfs(sb);
 +}
 +
++/*
++ * test if the @inode is nfs with 'noacl' option
++ * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
++ */
++static inline int au_test_nfs_noacl(struct inode *inode)
++{
++      return au_test_nfs(inode->i_sb)
++              /* && IS_POSIXACL(inode) */
++              && !nfs_server_capable(inode, NFS_CAP_ACLS);
++}
++
 +#endif /* __KERNEL__ */
 +#endif /* __AUFS_FSTYPE_H__ */
 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 --- /usr/share/empty/fs/aufs/hfsnotify.c       1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/hfsnotify.c  2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,293 @@
++++ linux/fs/aufs/hfsnotify.c  2015-06-22 08:27:37.880835119 +0200
+@@ -0,0 +1,288 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -12546,8 +14408,7 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -12568,7 +14429,7 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +                                           hn_mark);
 +      AuDbg("here\n");
 +      au_cache_free_hnotify(hn);
-+      smp_mb__before_atomic_dec();
++      smp_mb__before_atomic();
 +      if (atomic64_dec_and_test(&au_hfsn_ifree))
 +              wake_up(&au_hfsn_wq);
 +}
@@ -12595,10 +14456,12 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +       * by udba rename or rmdir, aufs assign a new inode to the known
 +       * h_inode, so specify 1 to allow dups.
 +       */
++      lockdep_off();
 +      err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
 +                               /*mnt*/NULL, /*allow_dups*/1);
 +      /* even if err */
 +      fsnotify_put_mark(mark);
++      lockdep_on();
 +
 +      return err;
 +}
@@ -12617,8 +14480,10 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +      group = mark->group;
 +      fsnotify_get_group(group);
 +      spin_unlock(&mark->lock);
++      lockdep_off();
 +      fsnotify_destroy_mark(mark, group);
 +      fsnotify_put_group(group);
++      lockdep_on();
 +
 +      /* free hn by myself */
 +      return 0;
@@ -12650,8 +14515,11 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +static char *au_hfsn_name(u32 mask)
 +{
 +#ifdef CONFIG_AUFS_DEBUG
-+#define test_ret(flag)        if (mask & flag) \
-+                              return #flag;
++#define test_ret(flag)                                \
++      do {                                    \
++              if (mask & flag)                \
++                      return #flag;           \
++      } while (0)
 +      test_ret(FS_ACCESS);
 +      test_ret(FS_MODIFY);
 +      test_ret(FS_ATTRIB);
@@ -12667,7 +14535,7 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +      test_ret(FS_UNMOUNT);
 +      test_ret(FS_Q_OVERFLOW);
 +      test_ret(FS_IN_IGNORED);
-+      test_ret(FS_IN_ISDIR);
++      test_ret(FS_ISDIR);
 +      test_ret(FS_IN_ONESHOT);
 +      test_ret(FS_EVENT_ON_CHILD);
 +      return "";
@@ -12689,29 +14557,29 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +}
 +
 +static int au_hfsn_handle_event(struct fsnotify_group *group,
++                              struct inode *inode,
 +                              struct fsnotify_mark *inode_mark,
 +                              struct fsnotify_mark *vfsmount_mark,
-+                              struct fsnotify_event *event)
++                              u32 mask, void *data, int data_type,
++                              const unsigned char *file_name, u32 cookie)
 +{
 +      int err;
 +      struct au_hnotify *hnotify;
 +      struct inode *h_dir, *h_inode;
-+      __u32 mask;
-+      struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
++      struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
 +
-+      AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
++      AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
 +
 +      err = 0;
 +      /* if FS_UNMOUNT happens, there must be another bug */
-+      mask = event->mask;
 +      AuDebugOn(mask & FS_UNMOUNT);
 +      if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
 +              goto out;
 +
-+      h_dir = event->to_tell;
-+      h_inode = event->inode;
++      h_dir = inode;
++      h_inode = NULL;
 +#ifdef AuDbgHnotify
-+      au_debug(1);
++      au_debug_on();
 +      if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
 +          || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
 +              AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
@@ -12719,7 +14587,7 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +                    AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
 +              /* WARN_ON(1); */
 +      }
-+      au_debug(0);
++      au_debug_off();
 +#endif
 +
 +      AuDebugOn(!inode_mark);
@@ -12730,21 +14598,7 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +      return err;
 +}
 +
-+/* isn't it waste to ask every registered 'group'? */
-+/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
-+/* it should be exported to modules */
-+static bool au_hfsn_should_send_event(struct fsnotify_group *group,
-+                                    struct inode *h_inode,
-+                                    struct fsnotify_mark *inode_mark,
-+                                    struct fsnotify_mark *vfsmount_mark,
-+                                    __u32 mask, void *data, int data_type)
-+{
-+      mask = (mask & ~FS_EVENT_ON_CHILD);
-+      return inode_mark->mask & mask;
-+}
-+
 +static struct fsnotify_ops au_hfsn_ops = {
-+      .should_send_event      = au_hfsn_should_send_event,
 +      .handle_event           = au_hfsn_handle_event,
 +      .free_group_priv        = au_hfsn_free_group
 +};
@@ -12756,8 +14610,11 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +      struct au_br_hfsnotify *hfsn;
 +
 +      hfsn = br->br_hfsn;
-+      if (hfsn)
++      if (hfsn) {
++              lockdep_off();
 +              fsnotify_put_group(hfsn->hfsn_group);
++              lockdep_on();
++      }
 +}
 +
 +static int au_hfsn_init_br(struct au_branch *br, int perm)
@@ -12827,10 +14684,10 @@ diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
 +};
 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/hfsplus.c    2013-02-19 08:40:03.946892891 +0100
-@@ -0,0 +1,57 @@
++++ linux/fs/aufs/hfsplus.c    2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,56 @@
 +/*
-+ * Copyright (C) 2010-2013 Junjiro R. Okajima
++ * Copyright (C) 2010-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -12843,8 +14700,7 @@ diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -12859,7 +14715,8 @@ diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
 +
 +#include "aufs.h"
 +
-+struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
++struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
++                         int force_wr)
 +{
 +      struct file *h_file;
 +      struct dentry *h_dentry;
@@ -12867,14 +14724,13 @@ diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
 +      h_dentry = au_h_dptr(dentry, bindex);
 +      AuDebugOn(!h_dentry);
 +      AuDebugOn(!h_dentry->d_inode);
-+      IMustLock(h_dentry->d_inode);
 +
 +      h_file = NULL;
 +      if (au_test_hfsplus(h_dentry->d_sb)
-+          && S_ISREG(h_dentry->d_inode->i_mode))
++          && d_is_reg(h_dentry))
 +              h_file = au_h_open(dentry, bindex,
 +                                 O_RDONLY | O_NOATIME | O_LARGEFILE,
-+                                 /*file*/NULL);
++                                 /*file*/NULL, force_wr);
 +      return h_file;
 +}
 +
@@ -12888,10 +14744,10 @@ diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
 +}
 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/hnotify.c    2013-03-14 20:07:41.041453062 +0100
-@@ -0,0 +1,713 @@
++++ linux/fs/aufs/hnotify.c    2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,714 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -12904,8 +14760,7 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -13092,7 +14947,6 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +      int err;
 +      struct dentry *d;
 +      struct qstr *dname;
-+      struct hlist_node *p;
 +
 +      err = 1;
 +      if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
@@ -13105,7 +14959,7 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +              AuDebugOn(!name);
 +              au_iigen_dec(inode);
 +              spin_lock(&inode->i_lock);
-+              hlist_for_each_entry(d, p, &inode->i_dentry, d_alias) {
++              hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
 +                      spin_lock(&d->d_lock);
 +                      dname = &d->d_name;
 +                      if (dname->len != nlen
@@ -13121,7 +14975,7 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +              spin_unlock(&inode->i_lock);
 +      } else {
 +              au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
-+              d = d_find_alias(inode);
++              d = d_find_any_alias(inode);
 +              if (!d) {
 +                      au_iigen_dec(inode);
 +                      goto out;
@@ -13211,6 +15065,7 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +static int hn_job(struct hn_job_args *a)
 +{
 +      const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
++      int e;
 +
 +      /* reset xino */
 +      if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
@@ -13220,18 +15075,19 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +          && a->inode
 +          && a->h_inode) {
 +              mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
-+              if (!a->h_inode->i_nlink)
++              if (!a->h_inode->i_nlink
++                  && !(a->h_inode->i_state & I_LINKABLE))
 +                      hn_xino(a->inode, a->h_inode); /* ignore this error */
 +              mutex_unlock(&a->h_inode->i_mutex);
 +      }
 +
 +      /* make the generation obsolete */
 +      if (au_ftest_hnjob(a->flags, GEN)) {
-+              int err = -1;
++              e = -1;
 +              if (a->inode)
-+                      err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
++                      e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
 +                                            isdir);
-+              if (err && a->dentry)
++              if (e && a->dentry)
 +                      hn_gen_by_name(a->dentry, isdir);
 +              /* ignore this error */
 +      }
@@ -13251,8 +15107,7 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +      if (au_ftest_hnjob(a->flags, MNTPNT)
 +          && a->dentry
 +          && d_mountpoint(a->dentry))
-+              pr_warn("mount-point %.*s is removed or renamed\n",
-+                      AuDLNPair(a->dentry));
++              pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
 +
 +      return 0;
 +}
@@ -13265,14 +15120,14 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +      struct dentry *dentry, *d, *parent;
 +      struct qstr *dname;
 +
-+      parent = d_find_alias(dir);
++      parent = d_find_any_alias(dir);
 +      if (!parent)
 +              return NULL;
 +
 +      dentry = NULL;
 +      spin_lock(&parent->d_lock);
-+      list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
-+              /* AuDbg("%.*s\n", AuDLNPair(d)); */
++      list_for_each_entry(d, &parent->d_subdirs, d_child) {
++              /* AuDbg("%pd\n", d); */
 +              spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
 +              dname = &d->d_name;
 +              if (dname->len != nlen || memcmp(dname->name, name, nlen))
@@ -13281,13 +15136,13 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +                      au_digen_dec(d);
 +              else
 +                      goto cont_unlock;
-+              if (d->d_count) {
++              if (au_dcount(d) > 0) {
 +                      dentry = dget_dlock(d);
 +                      spin_unlock(&d->d_lock);
 +                      break;
 +              }
 +
-+      cont_unlock:
++cont_unlock:
 +              spin_unlock(&d->d_lock);
 +      }
 +      spin_unlock(&parent->d_lock);
@@ -13479,7 +15334,7 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +              au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
 +              /*FALLTHROUGH*/
 +      case FS_CREATE:
-+              AuDebugOn(!h_child_name || !h_child_inode);
++              AuDebugOn(!h_child_name);
 +              break;
 +
 +      case FS_DELETE:
@@ -13524,8 +15379,10 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +              p[len] = 0;
 +      }
 +
++      /* NFS fires the event for silly-renamed one from kworker */
 +      f = 0;
-+      if (!dir->i_nlink)
++      if (!dir->i_nlink
++          || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
 +              f = AuWkq_NEST;
 +      err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
 +      if (unlikely(err)) {
@@ -13605,10 +15462,10 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +}
 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
 --- /usr/share/empty/fs/aufs/iinfo.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/iinfo.c      2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,276 @@
++++ linux/fs/aufs/iinfo.c      2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,277 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -13621,8 +15478,7 @@ diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -13755,7 +15611,9 @@ diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
 +                      struct inode *h_i;
 +
 +                      h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
-+                      if (h_i && !h_i->i_nlink)
++                      if (h_i
++                          && !h_i->i_nlink
++                          && !(h_i->i_state & I_LINKABLE))
 +                              au_set_h_iptr(inode, bindex, NULL, 0);
 +              }
 +      }
@@ -13885,10 +15743,10 @@ diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
 +}
 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 --- /usr/share/empty/fs/aufs/inode.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/inode.c      2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,492 @@
++++ linux/fs/aufs/inode.c      2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,495 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -13901,8 +15759,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -14103,7 +15960,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +      case S_IFSOCK:
 +              btail = au_dbtail(dentry);
 +              inode->i_op = &aufs_iop;
-+              au_init_special_fop(inode, mode, h_inode->i_rdev);
++              init_special_inode(inode, mode, h_inode->i_rdev);
 +              break;
 +      default:
 +              AuIOErr("Unknown file type 0%o\n", mode);
@@ -14128,6 +15985,10 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +                                    au_igrab(h_dentry->d_inode), flags);
 +      }
 +      au_cpup_attr_all(inode, /*force*/1);
++      /*
++       * to force calling aufs_get_acl() every time,
++       * do not call cache_no_acl() for aufs inode.
++       */
 +
 +out:
 +      return err;
@@ -14220,7 +16081,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +/* todo: return with unlocked? */
 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
 +{
-+      struct inode *inode, *h_inode;
++      struct inode *inode;
 +      struct dentry *h_dentry;
 +      struct super_block *sb;
 +      struct mutex *mtx;
@@ -14231,15 +16092,14 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +      sb = dentry->d_sb;
 +      bstart = au_dbstart(dentry);
 +      h_dentry = au_h_dptr(dentry, bstart);
-+      h_inode = h_dentry->d_inode;
-+      h_ino = h_inode->i_ino;
++      h_ino = h_dentry->d_inode->i_ino;
 +
 +      /*
 +       * stop 'race'-ing between hardlinks under different
 +       * parents.
 +       */
 +      mtx = NULL;
-+      if (!S_ISDIR(h_inode->i_mode))
++      if (!d_is_dir(h_dentry))
 +              mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
 +
 +new_ino:
@@ -14267,10 +16127,10 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +      AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
 +      if (inode->i_state & I_NEW) {
 +              /* verbose coding for lock class name */
-+              if (unlikely(S_ISLNK(h_inode->i_mode)))
++              if (unlikely(d_is_symlink(h_dentry)))
 +                      au_rw_class(&au_ii(inode)->ii_rwsem,
 +                                  au_lc_key + AuLcSymlink_IIINFO);
-+              else if (unlikely(S_ISDIR(h_inode->i_mode)))
++              else if (unlikely(d_is_dir(h_dentry)))
 +                      au_rw_class(&au_ii(inode)->ii_rwsem,
 +                                  au_lc_key + AuLcDir_IIINFO);
 +              else /* likely */
@@ -14317,8 +16177,8 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +
 +      if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
 +              AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
-+                      " b%d, %s, %.*s, hi%lu, i%lu.\n",
-+                      bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
++                      " b%d, %s, %pd, hi%lu, i%lu.\n",
++                      bstart, au_sbtype(h_dentry->d_sb), dentry,
 +                      (unsigned long)h_ino, (unsigned long)ino);
 +      ino = 0;
 +      err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
@@ -14344,6 +16204,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +             struct inode *inode)
 +{
 +      int err;
++      struct inode *hi;
 +
 +      err = au_br_rdonly(au_sbr(sb, bindex));
 +
@@ -14356,7 +16217,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +               * permission check is unnecessary since vfsub routine
 +               * will be called later
 +               */
-+              struct inode *hi = au_h_iptr(inode, bindex);
++              hi = au_h_iptr(inode, bindex);
 +              if (hi)
 +                      err = IS_IMMUTABLE(hi) ? -EROFS : 0;
 +      }
@@ -14381,10 +16242,10 @@ diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
 +}
 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 --- /usr/share/empty/fs/aufs/inode.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/inode.h      2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,588 @@
++++ linux/fs/aufs/inode.h      2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,673 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -14397,8 +16258,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -14486,8 +16346,20 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +      struct dentry *parent;
 +      struct au_hinode *hdir;
 +      struct vfsmount *h_mnt;
++
++      /* temporary unlock/relock for copyup */
++      struct dentry *h_dentry, *h_parent;
++      struct au_branch *br;
++      struct task_struct *task;
 +};
 +
++void au_pin_hdir_unlock(struct au_pin *p);
++int au_pin_hdir_lock(struct au_pin *p);
++int au_pin_hdir_relock(struct au_pin *p);
++void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
++void au_pin_hdir_acquire_nest(struct au_pin *p);
++void au_pin_hdir_release(struct au_pin *p);
++
 +/* ---------------------------------------------------------------------- */
 +
 +static inline struct au_iinfo *au_ii(struct inode *inode)
@@ -14530,6 +16402,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +/* au_wr_dir flags */
 +#define AuWrDir_ADD_ENTRY     1
 +#define AuWrDir_ISDIR         (1 << 1)
++#define AuWrDir_TMPFILE               (1 << 2)
 +#define au_ftest_wrdir(flags, name)   ((flags) & AuWrDir_##name)
 +#define au_fset_wrdir(flags, name) \
 +      do { (flags) |= AuWrDir_##name; } while (0)
@@ -14551,6 +16424,29 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +         unsigned int udba, unsigned char flags) __must_check;
 +int au_do_pin(struct au_pin *pin) __must_check;
 +void au_unpin(struct au_pin *pin);
++int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
++
++#define AuIcpup_DID_CPUP      1
++#define au_ftest_icpup(flags, name)   ((flags) & AuIcpup_##name)
++#define au_fset_icpup(flags, name) \
++      do { (flags) |= AuIcpup_##name; } while (0)
++#define au_fclr_icpup(flags, name) \
++      do { (flags) &= ~AuIcpup_##name; } while (0)
++
++struct au_icpup_args {
++      unsigned char flags;
++      unsigned char pin_flags;
++      aufs_bindex_t btgt;
++      unsigned int udba;
++      struct au_pin pin;
++      struct path h_path;
++      struct inode *h_inode;
++};
++
++int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
++                   struct au_icpup_args *a);
++
++int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
 +
 +/* i_op_add.c */
 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
@@ -14560,6 +16456,10 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
 +              bool want_excl);
++struct vfsub_aopen_args;
++int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
++                     struct vfsub_aopen_args *args);
++int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
 +            struct dentry *dentry);
 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
@@ -14611,6 +16511,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +#ifdef CONFIG_PROC_FS
 +/* plink.c */
 +int au_plink_maint(struct super_block *sb, int flags);
++struct au_sbinfo;
 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
 +int au_plink_maint_enter(struct super_block *sb);
 +#ifdef CONFIG_AUFS_DEBUG
@@ -14640,6 +16541,57 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
 +#endif /* CONFIG_PROC_FS */
 +
++#ifdef CONFIG_AUFS_XATTR
++/* xattr.c */
++int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
++                unsigned int verbose);
++ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
++ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
++                    size_t size);
++int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
++                size_t size, int flags);
++int aufs_removexattr(struct dentry *dentry, const char *name);
++
++/* void au_xattr_init(struct super_block *sb); */
++#else
++AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
++         int ignore_flags, unsigned int verbose);
++/* AuStubVoid(au_xattr_init, struct super_block *sb); */
++#endif
++
++#ifdef CONFIG_FS_POSIX_ACL
++struct posix_acl *aufs_get_acl(struct inode *inode, int type);
++int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
++#endif
++
++#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
++enum {
++      AU_XATTR_SET,
++      AU_XATTR_REMOVE,
++      AU_ACL_SET
++};
++
++struct au_srxattr {
++      int type;
++      union {
++              struct {
++                      const char      *name;
++                      const void      *value;
++                      size_t          size;
++                      int             flags;
++              } set;
++              struct {
++                      const char      *name;
++              } remove;
++              struct {
++                      struct posix_acl *acl;
++                      int             type;
++              } acl_set;
++      } u;
++};
++ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
++#endif
++
 +/* ---------------------------------------------------------------------- */
 +
 +/* lock subclass for iinfo */
@@ -14853,6 +16805,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +      }
 +}
 +
++#if 0 /* reserved */
 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
 +{
 +      if (pin) {
@@ -14860,6 +16813,7 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +              pin->parent = dget(parent);
 +      }
 +}
++#endif
 +
 +/* ---------------------------------------------------------------------- */
 +
@@ -14912,18 +16866,10 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +}
 +
 +#else
-+static inline
-+int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
-+              struct inode *inode __maybe_unused)
-+{
-+      return -EOPNOTSUPP;
-+}
-+
-+static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
-+{
-+      return NULL;
-+}
-+
++AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
++       struct au_hinode *hinode __maybe_unused,
++       struct inode *inode __maybe_unused)
++AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
 +         int do_set __maybe_unused)
@@ -14973,10 +16919,10 @@ diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
 +#endif /* __AUFS_INODE_H__ */
 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 --- /usr/share/empty/fs/aufs/ioctl.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/ioctl.c      2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,196 @@
++++ linux/fs/aufs/ioctl.c      2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,219 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -14989,16 +16935,19 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
 + * ioctl
 + * plink-management and readdir in userspace.
 + * assist the pathconf(3) wrapper library.
++ * move-down
++ * File-based Hierarchical Storage Management.
 + */
 +
++#include <linux/compat.h>
++#include <linux/file.h>
 +#include "aufs.h"
 +
 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
@@ -15033,7 +16982,7 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +                      goto out;
 +      }
 +
-+      fd = get_unused_fd();
++      fd = get_unused_fd_flags(0);
 +      err = fd;
 +      if (unlikely(fd < 0))
 +              goto out;
@@ -15070,7 +17019,8 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +      }
 +      AuDbg("wbi %d\n", wbi);
 +      if (wbi >= 0)
-+              h_file = au_h_open(root, wbi, wbrfd.oflags, NULL);
++              h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
++                                 /*force_wr*/0);
 +
 +out_unlock:
 +      aufs_read_unlock(root, AuLock_IR);
@@ -15095,6 +17045,7 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
 +{
 +      long err;
++      struct dentry *dentry;
 +
 +      switch (cmd) {
 +      case AUFS_CTL_RDU:
@@ -15110,6 +17061,18 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +              err = au_ibusy_ioctl(file, arg);
 +              break;
 +
++      case AUFS_CTL_BRINFO:
++              err = au_brinfo_ioctl(file, arg);
++              break;
++
++      case AUFS_CTL_FHSM_FD:
++              dentry = file->f_path.dentry;
++              if (IS_ROOT(dentry))
++                      err = au_fhsm_fd(dentry->d_sb, arg);
++              else
++                      err = -ENOTTY;
++              break;
++
 +      default:
 +              /* do not call the lower */
 +              AuDbg("0x%x\n", cmd);
@@ -15125,6 +17088,10 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +      long err;
 +
 +      switch (cmd) {
++      case AUFS_CTL_MVDOWN:
++              err = au_mvdown(file->f_path.dentry, (void __user *)arg);
++              break;
++
 +      case AUFS_CTL_WBR_FD:
 +              err = au_wbr_fd(&file->f_path, (void __user *)arg);
 +              break;
@@ -15155,6 +17122,10 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +              err = au_ibusy_compat_ioctl(file, arg);
 +              break;
 +
++      case AUFS_CTL_BRINFO:
++              err = au_brinfo_compat_ioctl(file, arg);
++              break;
++
 +      default:
 +              err = aufs_ioctl_dir(file, cmd, arg);
 +      }
@@ -15163,20 +17134,18 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +      return err;
 +}
 +
-+#if 0 /* unused yet */
 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
 +                            unsigned long arg)
 +{
 +      return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
 +}
 +#endif
-+#endif
 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 --- /usr/share/empty/fs/aufs/i_op_add.c        1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/i_op_add.c   2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,713 @@
++++ linux/fs/aufs/i_op_add.c   2015-06-22 08:27:37.880835119 +0200
+@@ -0,0 +1,930 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -15189,8 +17158,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -15211,17 +17179,19 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      int err, rerr;
 +      aufs_bindex_t bwh;
 +      struct path h_path;
++      struct super_block *sb;
 +      struct inode *inode, *h_dir;
 +      struct dentry *wh;
 +
 +      bwh = -1;
++      sb = dir->i_sb;
 +      if (wh_dentry) {
 +              h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
 +              IMustLock(h_dir);
 +              AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
 +              bwh = au_dbwh(dentry);
 +              h_path.dentry = wh_dentry;
-+              h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
++              h_path.mnt = au_sbr_mnt(sb, bindex);
 +              err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
 +                                        dentry);
 +              if (unlikely(err))
@@ -15233,9 +17203,9 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +              d_instantiate(dentry, inode);
 +              dir = dentry->d_parent->d_inode; /* dir inode is locked */
 +              IMustLock(dir);
-+              if (au_ibstart(dir) == au_dbstart(dentry))
-+                      au_cpup_attr_timesizes(dir);
++              au_dir_ts(dir, bindex);
 +              dir->i_version++;
++              au_fhsm_wrote(sb, bindex, /*force*/0);
 +              return 0; /* success */
 +      }
 +
@@ -15248,8 +17218,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
 +      rerr = PTR_ERR(wh);
 +      if (IS_ERR(wh)) {
-+              AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
-+                      AuDLNPair(dentry), err, rerr);
++              AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
++                      dentry, err, rerr);
 +              err = -EIO;
 +      } else
 +              dput(wh);
@@ -15336,7 +17306,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      unsigned int udba;
 +      aufs_bindex_t bcpup;
 +
-+      AuDbg("%.*s\n", AuDLNPair(dentry));
++      AuDbg("%pd\n", dentry);
 +
 +      err = au_wr_dir(dentry, src_dentry, wr_dir_args);
 +      bcpup = err;
@@ -15367,7 +17337,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      if (dt) {
 +              struct path tmp = {
 +                      .dentry = h_parent,
-+                      .mnt    = br->br_mnt
++                      .mnt    = au_br_mnt(br)
 +              };
 +              au_dtime_store(dt, au_pinned_parent(pin), &tmp);
 +      }
@@ -15376,6 +17346,11 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      if (bcpup != au_dbwh(dentry))
 +              goto out; /* success */
 +
++      /*
++       * ENAMETOOLONG here means that if we allowed create such name, then it
++       * would not be able to removed in the future. So we don't allow such
++       * name here and we don't handle ENAMETOOLONG differently here.
++       */
 +      wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
 +
 +out_unpin:
@@ -15392,8 +17367,10 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      int type;
 +      union {
 +              struct {
-+                      umode_t mode;
-+                      bool want_excl;
++                      umode_t                 mode;
++                      bool                    want_excl;
++                      bool                    try_aopen;
++                      struct vfsub_aopen_args *aopen;
 +              } c;
 +              struct {
 +                      const char *symname;
@@ -15408,50 +17385,72 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +static int add_simple(struct inode *dir, struct dentry *dentry,
 +                    struct simple_arg *arg)
 +{
-+      int err;
++      int err, rerr;
 +      aufs_bindex_t bstart;
 +      unsigned char created;
-+      struct au_dtime dt;
-+      struct au_pin pin;
-+      struct path h_path;
++      const unsigned char try_aopen
++              = (arg->type == Creat && arg->u.c.try_aopen);
 +      struct dentry *wh_dentry, *parent;
 +      struct inode *h_dir;
-+      struct au_wr_dir_args wr_dir_args = {
-+              .force_btgt     = -1,
-+              .flags          = AuWrDir_ADD_ENTRY
-+      };
++      struct super_block *sb;
++      struct au_branch *br;
++      /* to reuduce stack size */
++      struct {
++              struct au_dtime dt;
++              struct au_pin pin;
++              struct path h_path;
++              struct au_wr_dir_args wr_dir_args;
++      } *a;
 +
-+      AuDbg("%.*s\n", AuDLNPair(dentry));
++      AuDbg("%pd\n", dentry);
 +      IMustLock(dir);
 +
-+      parent = dentry->d_parent; /* dir inode is locked */
-+      err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
-+      if (unlikely(err))
++      err = -ENOMEM;
++      a = kmalloc(sizeof(*a), GFP_NOFS);
++      if (unlikely(!a))
 +              goto out;
++      a->wr_dir_args.force_btgt = -1;
++      a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
++
++      parent = dentry->d_parent; /* dir inode is locked */
++      if (!try_aopen) {
++              err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
++              if (unlikely(err))
++                      goto out_free;
++      }
 +      err = au_d_may_add(dentry);
 +      if (unlikely(err))
 +              goto out_unlock;
-+      di_write_lock_parent(parent);
-+      wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
-+                                    &wr_dir_args);
++      if (!try_aopen)
++              di_write_lock_parent(parent);
++      wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
++                                    &a->pin, &a->wr_dir_args);
 +      err = PTR_ERR(wh_dentry);
 +      if (IS_ERR(wh_dentry))
 +              goto out_parent;
 +
 +      bstart = au_dbstart(dentry);
-+      h_path.dentry = au_h_dptr(dentry, bstart);
-+      h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
-+      h_dir = au_pinned_h_dir(&pin);
++      sb = dentry->d_sb;
++      br = au_sbr(sb, bstart);
++      a->h_path.dentry = au_h_dptr(dentry, bstart);
++      a->h_path.mnt = au_br_mnt(br);
++      h_dir = au_pinned_h_dir(&a->pin);
 +      switch (arg->type) {
 +      case Creat:
-+              err = vfsub_create(h_dir, &h_path, arg->u.c.mode,
-+                                 arg->u.c.want_excl);
++              err = 0;
++              if (!try_aopen || !h_dir->i_op->atomic_open)
++                      err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
++                                         arg->u.c.want_excl);
++              else
++                      err = vfsub_atomic_open(h_dir, a->h_path.dentry,
++                                              arg->u.c.aopen, br);
 +              break;
 +      case Symlink:
-+              err = vfsub_symlink(h_dir, &h_path, arg->u.s.symname);
++              err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
 +              break;
 +      case Mknod:
-+              err = vfsub_mknod(h_dir, &h_path, arg->u.m.mode, arg->u.m.dev);
++              err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
++                                arg->u.m.dev);
 +              break;
 +      default:
 +              BUG();
@@ -15461,28 +17460,36 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +              err = epilog(dir, bstart, wh_dentry, dentry);
 +
 +      /* revert */
-+      if (unlikely(created && err && h_path.dentry->d_inode)) {
-+              int rerr;
-+              rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
++      if (unlikely(created && err && a->h_path.dentry->d_inode)) {
++              /* no delegation since it is just created */
++              rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
++                                  /*force*/0);
 +              if (rerr) {
-+                      AuIOErr("%.*s revert failure(%d, %d)\n",
-+                              AuDLNPair(dentry), err, rerr);
++                      AuIOErr("%pd revert failure(%d, %d)\n",
++                              dentry, err, rerr);
 +                      err = -EIO;
 +              }
-+              au_dtime_revert(&dt);
++              au_dtime_revert(&a->dt);
 +      }
 +
-+      au_unpin(&pin);
++      if (!err && try_aopen && !h_dir->i_op->atomic_open)
++              *arg->u.c.aopen->opened |= FILE_CREATED;
++
++      au_unpin(&a->pin);
 +      dput(wh_dentry);
 +
 +out_parent:
-+      di_write_unlock(parent);
++      if (!try_aopen)
++              di_write_unlock(parent);
 +out_unlock:
 +      if (unlikely(err)) {
 +              au_update_dbstart(dentry);
 +              d_drop(dentry);
 +      }
-+      aufs_read_unlock(dentry, AuLock_DW);
++      if (!try_aopen)
++              aufs_read_unlock(dentry, AuLock_DW);
++out_free:
++      kfree(a);
 +out:
 +      return err;
 +}
@@ -15522,6 +17529,136 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      return add_simple(dir, dentry, &arg);
 +}
 +
++int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
++                     struct vfsub_aopen_args *aopen_args)
++{
++      struct simple_arg arg = {
++              .type = Creat,
++              .u.c = {
++                      .mode           = aopen_args->create_mode,
++                      .want_excl      = aopen_args->open_flag & O_EXCL,
++                      .try_aopen      = true,
++                      .aopen          = aopen_args
++              }
++      };
++      return add_simple(dir, dentry, &arg);
++}
++
++int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
++{
++      int err;
++      aufs_bindex_t bindex;
++      struct super_block *sb;
++      struct dentry *parent, *h_parent, *h_dentry;
++      struct inode *h_dir, *inode;
++      struct vfsmount *h_mnt;
++      struct au_wr_dir_args wr_dir_args = {
++              .force_btgt     = -1,
++              .flags          = AuWrDir_TMPFILE
++      };
++
++      /* copy-up may happen */
++      mutex_lock(&dir->i_mutex);
++
++      sb = dir->i_sb;
++      err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
++      if (unlikely(err))
++              goto out;
++
++      err = au_di_init(dentry);
++      if (unlikely(err))
++              goto out_si;
++
++      err = -EBUSY;
++      parent = d_find_any_alias(dir);
++      AuDebugOn(!parent);
++      di_write_lock_parent(parent);
++      if (unlikely(parent->d_inode != dir))
++              goto out_parent;
++
++      err = au_digen_test(parent, au_sigen(sb));
++      if (unlikely(err))
++              goto out_parent;
++
++      bindex = au_dbstart(parent);
++      au_set_dbstart(dentry, bindex);
++      au_set_dbend(dentry, bindex);
++      err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
++      bindex = err;
++      if (unlikely(err < 0))
++              goto out_parent;
++
++      err = -EOPNOTSUPP;
++      h_dir = au_h_iptr(dir, bindex);
++      if (unlikely(!h_dir->i_op->tmpfile))
++              goto out_parent;
++
++      h_mnt = au_sbr_mnt(sb, bindex);
++      err = vfsub_mnt_want_write(h_mnt);
++      if (unlikely(err))
++              goto out_parent;
++
++      h_parent = au_h_dptr(parent, bindex);
++      err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
++      if (unlikely(err))
++              goto out_mnt;
++
++      err = -ENOMEM;
++      h_dentry = d_alloc(h_parent, &dentry->d_name);
++      if (unlikely(!h_dentry))
++              goto out_mnt;
++
++      err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
++      if (unlikely(err))
++              goto out_dentry;
++
++      au_set_dbstart(dentry, bindex);
++      au_set_dbend(dentry, bindex);
++      au_set_h_dptr(dentry, bindex, dget(h_dentry));
++      inode = au_new_inode(dentry, /*must_new*/1);
++      if (IS_ERR(inode)) {
++              err = PTR_ERR(inode);
++              au_set_h_dptr(dentry, bindex, NULL);
++              au_set_dbstart(dentry, -1);
++              au_set_dbend(dentry, -1);
++      } else {
++              if (!inode->i_nlink)
++                      set_nlink(inode, 1);
++              d_tmpfile(dentry, inode);
++              au_di(dentry)->di_tmpfile = 1;
++
++              /* update without i_mutex */
++              if (au_ibstart(dir) == au_dbstart(dentry))
++                      au_cpup_attr_timesizes(dir);
++      }
++
++out_dentry:
++      dput(h_dentry);
++out_mnt:
++      vfsub_mnt_drop_write(h_mnt);
++out_parent:
++      di_write_unlock(parent);
++      dput(parent);
++      di_write_unlock(dentry);
++      if (!err)
++#if 0
++              /* verbose coding for lock class name */
++              au_rw_class(&au_di(dentry)->di_rwsem,
++                          au_lc_key + AuLcNonDir_DIINFO);
++#else
++              ;
++#endif
++      else {
++              au_di_fin(dentry);
++              dentry->d_fsdata = NULL;
++      }
++out_si:
++      si_read_unlock(sb);
++out:
++      mutex_unlock(&dir->i_mutex);
++      return err;
++}
++
 +/* ---------------------------------------------------------------------- */
 +
 +struct au_link_args {
@@ -15536,8 +17673,14 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +{
 +      int err;
 +      struct dentry *h_src_dentry;
-+      struct mutex *h_mtx;
-+      struct file *h_file;
++      struct au_cp_generic cpg = {
++              .dentry = src_dentry,
++              .bdst   = a->bdst,
++              .bsrc   = a->bsrc,
++              .len    = -1,
++              .pin    = &a->pin,
++              .flags  = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
++      };
 +
 +      di_read_lock_parent(a->src_parent, AuLock_IR);
 +      err = au_test_and_cpup_dirs(src_dentry, a->bdst);
@@ -15545,22 +17688,13 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +              goto out;
 +
 +      h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
-+      h_mtx = &h_src_dentry->d_inode->i_mutex;
 +      err = au_pin(&a->pin, src_dentry, a->bdst,
 +                   au_opt_udba(src_dentry->d_sb),
 +                   AuPin_DI_LOCKED | AuPin_MNT_WRITE);
 +      if (unlikely(err))
 +              goto out;
-+      mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
-+      h_file = au_h_open_pre(src_dentry, a->bsrc);
-+      if (IS_ERR(h_file)) {
-+              err = PTR_ERR(h_file);
-+              h_file = NULL;
-+      } else
-+              err = au_sio_cpup_simple(src_dentry, a->bdst, -1,
-+                                       AuCpup_DTIME /* | AuCpup_KEEPLINO */);
-+      mutex_unlock(h_mtx);
-+      au_h_open_post(src_dentry, a->bsrc, h_file);
++
++      err = au_sio_cpup_simple(&cpg);
 +      au_unpin(&a->pin);
 +
 +out:
@@ -15568,12 +17702,14 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      return err;
 +}
 +
-+static int au_cpup_or_link(struct dentry *src_dentry, struct au_link_args *a)
++static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
++                         struct au_link_args *a)
 +{
 +      int err;
 +      unsigned char plink;
-+      struct inode *h_inode, *inode;
++      aufs_bindex_t bend;
 +      struct dentry *h_src_dentry;
++      struct inode *h_inode, *inode, *delegated;
 +      struct super_block *sb;
 +      struct file *h_file;
 +
@@ -15585,22 +17721,44 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +              h_inode = au_h_iptr(inode, a->bdst);
 +      if (!h_inode || !h_inode->i_nlink) {
 +              /* copyup src_dentry as the name of dentry. */
-+              au_set_dbstart(src_dentry, a->bdst);
-+              au_set_h_dptr(src_dentry, a->bdst, dget(a->h_path.dentry));
-+              h_inode = au_h_dptr(src_dentry, a->bsrc)->d_inode;
-+              mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+              h_file = au_h_open_pre(src_dentry, a->bsrc);
-+              if (IS_ERR(h_file)) {
++              bend = au_dbend(dentry);
++              if (bend < a->bsrc)
++                      au_set_dbend(dentry, a->bsrc);
++              au_set_h_dptr(dentry, a->bsrc,
++                            dget(au_h_dptr(src_dentry, a->bsrc)));
++              dget(a->h_path.dentry);
++              au_set_h_dptr(dentry, a->bdst, NULL);
++              AuDbg("temporary d_inode...\n");
++              spin_lock(&dentry->d_lock);
++              dentry->d_inode = src_dentry->d_inode; /* tmp */
++              spin_unlock(&dentry->d_lock);
++              h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
++              if (IS_ERR(h_file))
 +                      err = PTR_ERR(h_file);
-+                      h_file = NULL;
-+              } else
-+                      err = au_sio_cpup_single(src_dentry, a->bdst, a->bsrc,
-+                                               -1, AuCpup_KEEPLINO,
-+                                               a->parent);
-+              mutex_unlock(&h_inode->i_mutex);
-+              au_h_open_post(src_dentry, a->bsrc, h_file);
-+              au_set_h_dptr(src_dentry, a->bdst, NULL);
-+              au_set_dbstart(src_dentry, a->bsrc);
++              else {
++                      struct au_cp_generic cpg = {
++                              .dentry = dentry,
++                              .bdst   = a->bdst,
++                              .bsrc   = -1,
++                              .len    = -1,
++                              .pin    = &a->pin,
++                              .flags  = AuCpup_KEEPLINO
++                      };
++                      err = au_sio_cpup_simple(&cpg);
++                      au_h_open_post(dentry, a->bsrc, h_file);
++                      if (!err) {
++                              dput(a->h_path.dentry);
++                              a->h_path.dentry = au_h_dptr(dentry, a->bdst);
++                      } else
++                              au_set_h_dptr(dentry, a->bdst,
++                                            a->h_path.dentry);
++              }
++              spin_lock(&dentry->d_lock);
++              dentry->d_inode = NULL; /* restore */
++              spin_unlock(&dentry->d_lock);
++              AuDbg("temporary d_inode...done\n");
++              au_set_h_dptr(dentry, a->bsrc, NULL);
++              au_set_dbend(dentry, bend);
 +      } else {
 +              /* the inode of src_dentry already exists on a.bdst branch */
 +              h_src_dentry = d_find_alias(h_inode);
@@ -15618,8 +17776,14 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +
 +              }
 +              if (h_src_dentry) {
++                      delegated = NULL;
 +                      err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
-+                                       &a->h_path);
++                                       &a->h_path, &delegated);
++                      if (unlikely(err == -EWOULDBLOCK)) {
++                              pr_warn("cannot retry for NFSv4 delegation"
++                                      " for an internal link\n");
++                              iput(delegated);
++                      }
 +                      dput(h_src_dentry);
 +              } else {
 +                      AuIOErr("no dentry found for hi%lu on b%d\n",
@@ -15643,7 +17807,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      struct au_dtime dt;
 +      struct au_link_args *a;
 +      struct dentry *wh_dentry, *h_src_dentry;
-+      struct inode *inode;
++      struct inode *inode, *delegated;
 +      struct super_block *sb;
 +      struct au_wr_dir_args wr_dir_args = {
 +              /* .force_btgt  = -1, */
@@ -15664,7 +17828,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +                                      AuLock_NOPLM | AuLock_GEN);
 +      if (unlikely(err))
 +              goto out_kfree;
-+      err = au_d_hashed_positive(src_dentry);
++      err = au_d_linkable(src_dentry);
 +      if (unlikely(err))
 +              goto out_unlock;
 +      err = au_d_may_add(dentry);
@@ -15689,20 +17853,31 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
 +      a->bsrc = au_ibstart(inode);
 +      h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
++      if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
++              h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
 +      if (!h_src_dentry) {
 +              a->bsrc = au_dbstart(src_dentry);
 +              h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
 +              AuDebugOn(!h_src_dentry);
-+      } else if (IS_ERR(h_src_dentry))
++      } else if (IS_ERR(h_src_dentry)) {
++              err = PTR_ERR(h_src_dentry);
 +              goto out_parent;
++      }
 +
 +      if (au_opt_test(au_mntflags(sb), PLINK)) {
 +              if (a->bdst < a->bsrc
 +                  /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
-+                      err = au_cpup_or_link(src_dentry, a);
-+              else
++                      err = au_cpup_or_link(src_dentry, dentry, a);
++              else {
++                      delegated = NULL;
 +                      err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
-+                                       &a->h_path);
++                                       &a->h_path, &delegated);
++                      if (unlikely(err == -EWOULDBLOCK)) {
++                              pr_warn("cannot retry for NFSv4 delegation"
++                                      " for an internal link\n");
++                              iput(delegated);
++                      }
++              }
 +              dput(h_src_dentry);
 +      } else {
 +              /*
@@ -15726,10 +17901,18 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +              if (!err) {
 +                      h_src_dentry = au_h_dptr(src_dentry, a->bdst);
 +                      err = -ENOENT;
-+                      if (h_src_dentry && h_src_dentry->d_inode)
++                      if (h_src_dentry && h_src_dentry->d_inode) {
++                              delegated = NULL;
 +                              err = vfsub_link(h_src_dentry,
 +                                               au_pinned_h_dir(&a->pin),
-+                                               &a->h_path);
++                                               &a->h_path, &delegated);
++                              if (unlikely(err == -EWOULDBLOCK)) {
++                                      pr_warn("cannot retry"
++                                              " for NFSv4 delegation"
++                                              " for an internal link\n");
++                                      iput(delegated);
++                              }
++                      }
 +              }
 +      }
 +      if (unlikely(err))
@@ -15743,22 +17926,24 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +                      goto out_revert;
 +      }
 +
++      au_dir_ts(dir, a->bdst);
 +      dir->i_version++;
-+      if (au_ibstart(dir) == au_dbstart(dentry))
-+              au_cpup_attr_timesizes(dir);
 +      inc_nlink(inode);
 +      inode->i_ctime = dir->i_ctime;
 +      d_instantiate(dentry, au_igrab(inode));
 +      if (d_unhashed(a->h_path.dentry))
 +              /* some filesystem calls d_drop() */
 +              d_drop(dentry);
++      /* some filesystems consume an inode even hardlink */
++      au_fhsm_wrote(sb, a->bdst, /*force*/0);
 +      goto out_unpin; /* success */
 +
 +out_revert:
-+      rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
++      /* no delegation since it is just created */
++      rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
++                          /*delegated*/NULL, /*force*/0);
 +      if (unlikely(rerr)) {
-+              AuIOErr("%.*s reverting failed(%d, %d)\n",
-+                      AuDLNPair(dentry), err, rerr);
++              AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
 +              err = -EIO;
 +      }
 +      au_dtime_revert(&dt);
@@ -15778,6 +17963,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +out_kfree:
 +      kfree(a);
 +out:
++      AuTraceErr(err);
 +      return err;
 +}
 +
@@ -15857,8 +18043,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +              rerr = au_diropq_remove(dentry, bindex);
 +              mutex_unlock(h_mtx);
 +              if (rerr) {
-+                      AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
-+                              AuDLNPair(dentry), err, rerr);
++                      AuIOErr("%pd reverting diropq failed(%d, %d)\n",
++                              dentry, err, rerr);
 +                      err = -EIO;
 +              }
 +      }
@@ -15867,8 +18053,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +      AuLabel(revert dir);
 +      rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
 +      if (rerr) {
-+              AuIOErr("%.*s reverting dir failed(%d, %d)\n",
-+                      AuDLNPair(dentry), err, rerr);
++              AuIOErr("%pd reverting dir failed(%d, %d)\n",
++                      dentry, err, rerr);
 +              err = -EIO;
 +      }
 +      au_dtime_revert(&a->dt);
@@ -15890,10 +18076,10 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +}
 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 --- /usr/share/empty/fs/aufs/i_op.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/i_op.c       2013-03-14 20:07:41.041453062 +0100
-@@ -0,0 +1,1030 @@
++++ linux/fs/aufs/i_op.c       2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,1445 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -15906,8 +18092,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -15939,13 +18124,19 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +       * - skip the lower fs test in the case of write to ro branch.
 +       * - nfs dir permission write check is optimized, but a policy for
 +       *   link/rename requires a real check.
++       * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
++       *   in this case, generic_permission() returns -EOPNOTSUPP.
 +       */
 +      if ((write_mask && !au_br_writable(brperm))
 +          || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
 +              && write_mask && !(mask & MAY_READ))
 +          || !h_inode->i_op->permission) {
 +              /* AuLabel(generic_permission); */
++              /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
 +              err = generic_permission(h_inode, mask);
++              if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
++                      err = h_inode->i_op->permission(h_inode, mask);
++              AuTraceErr(err);
 +      } else {
 +              /* AuLabel(h_inode->permission); */
 +              err = h_inode->i_op->permission(h_inode, mask);
@@ -15997,7 +18188,9 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              goto out;
 +#endif
 +
-+      if (!isdir || write_mask) {
++      if (!isdir
++          || write_mask
++          || au_opt_test(au_mntflags(sb), DIRPERM1)) {
 +              err = au_busy_or_stale();
 +              h_inode = au_h_iptr(inode, au_ibstart(inode));
 +              if (unlikely(!h_inode
@@ -16008,7 +18201,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              err = 0;
 +              bindex = au_ibstart(inode);
 +              br = au_sbr(sb, bindex);
-+              err = h_permission(h_inode, mask, br->br_mnt, br->br_perm);
++              err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
 +              if (write_mask
 +                  && !err
 +                  && !special_file(h_inode->i_mode)) {
@@ -16034,7 +18227,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +                              break;
 +
 +                      br = au_sbr(sb, bindex);
-+                      err = h_permission(h_inode, mask, br->br_mnt,
++                      err = h_permission(h_inode, mask, au_br_mnt(br),
 +                                         br->br_perm);
 +              }
 +      }
@@ -16096,13 +18289,15 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +      if (npositive) {
 +              inode = au_new_inode(dentry, /*must_new*/0);
-+              ret = (void *)inode;
-+      }
-+      if (IS_ERR(inode)) {
-+              inode = NULL;
-+              goto out_unlock;
++              if (IS_ERR(inode)) {
++                      ret = (void *)inode;
++                      inode = NULL;
++                      goto out_unlock;
++              }
 +      }
 +
++      if (inode)
++              atomic_inc(&inode->i_count);
 +      ret = d_splice_alias(inode, dentry);
 +#if 0
 +      if (unlikely(d_need_lookup(dentry))) {
@@ -16111,10 +18306,16 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              spin_unlock(&dentry->d_lock);
 +      } else
 +#endif
-+      if (unlikely(IS_ERR(ret) && inode)) {
-+              ii_write_unlock(inode);
-+              iput(inode);
-+              inode = NULL;
++      if (inode) {
++              if (!IS_ERR(ret)) {
++                      iput(inode);
++                      if (ret && ret != dentry)
++                              ii_write_unlock(inode);
++              } else {
++                      ii_write_unlock(inode);
++                      iput(inode);
++                      inode = NULL;
++              }
 +      }
 +
 +out_unlock:
@@ -16139,6 +18340,149 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +/* ---------------------------------------------------------------------- */
 +
++struct aopen_node {
++      struct hlist_node hlist;
++      struct file *file, *h_file;
++};
++
++static int au_do_aopen(struct inode *inode, struct file *file)
++{
++      struct au_sphlhead *aopen;
++      struct aopen_node *node;
++      struct au_do_open_args args = {
++              .no_lock        = 1,
++              .open           = au_do_open_nondir
++      };
++
++      aopen = &au_sbi(inode->i_sb)->si_aopen;
++      spin_lock(&aopen->spin);
++      hlist_for_each_entry(node, &aopen->head, hlist)
++              if (node->file == file) {
++                      args.h_file = node->h_file;
++                      break;
++              }
++      spin_unlock(&aopen->spin);
++      /* AuDebugOn(!args.h_file); */
++
++      return au_do_open(file, &args);
++}
++
++static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
++                          struct file *file, unsigned int open_flag,
++                          umode_t create_mode, int *opened)
++{
++      int err, h_opened = *opened;
++      struct dentry *parent;
++      struct dentry *d;
++      struct au_sphlhead *aopen;
++      struct vfsub_aopen_args args = {
++              .open_flag      = open_flag,
++              .create_mode    = create_mode,
++              .opened         = &h_opened
++      };
++      struct aopen_node aopen_node = {
++              .file   = file
++      };
++
++      IMustLock(dir);
++      AuDbg("open_flag 0x%x\n", open_flag);
++      AuDbgDentry(dentry);
++
++      err = 0;
++      if (!au_di(dentry)) {
++              d = aufs_lookup(dir, dentry, /*flags*/0);
++              if (IS_ERR(d)) {
++                      err = PTR_ERR(d);
++                      goto out;
++              } else if (d) {
++                      /*
++                       * obsoleted dentry found.
++                       * another error will be returned later.
++                       */
++                      d_drop(d);
++                      dput(d);
++                      AuDbgDentry(d);
++              }
++              AuDbgDentry(dentry);
++      }
++
++      if (d_is_positive(dentry)
++          || d_unhashed(dentry)
++          || d_unlinked(dentry)
++          || !(open_flag & O_CREAT))
++              goto out_no_open;
++
++      err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
++      if (unlikely(err))
++              goto out;
++
++      parent = dentry->d_parent;      /* dir is locked */
++      di_write_lock_parent(parent);
++      err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
++      if (unlikely(err))
++              goto out_unlock;
++
++      AuDbgDentry(dentry);
++      if (d_is_positive(dentry))
++              goto out_unlock;
++
++      args.file = get_empty_filp();
++      err = PTR_ERR(args.file);
++      if (IS_ERR(args.file))
++              goto out_unlock;
++
++      args.file->f_flags = file->f_flags;
++      err = au_aopen_or_create(dir, dentry, &args);
++      AuTraceErr(err);
++      AuDbgFile(args.file);
++      if (unlikely(err < 0)) {
++              if (h_opened & FILE_OPENED)
++                      fput(args.file);
++              else
++                      put_filp(args.file);
++              goto out_unlock;
++      }
++
++      /* some filesystems don't set FILE_CREATED while succeeded? */
++      *opened |= FILE_CREATED;
++      if (h_opened & FILE_OPENED)
++              aopen_node.h_file = args.file;
++      else {
++              put_filp(args.file);
++              args.file = NULL;
++      }
++      aopen = &au_sbi(dir->i_sb)->si_aopen;
++      au_sphl_add(&aopen_node.hlist, aopen);
++      err = finish_open(file, dentry, au_do_aopen, opened);
++      au_sphl_del(&aopen_node.hlist, aopen);
++      AuTraceErr(err);
++      AuDbgFile(file);
++      if (aopen_node.h_file)
++              fput(aopen_node.h_file);
++
++out_unlock:
++      di_write_unlock(parent);
++      aufs_read_unlock(dentry, AuLock_DW);
++      AuDbgDentry(dentry);
++      if (unlikely(err))
++              goto out;
++out_no_open:
++      if (!err && !(*opened & FILE_CREATED)) {
++              AuLabel(out_no_open);
++              dget(dentry);
++              err = finish_no_open(file, dentry);
++      }
++out:
++      AuDbg("%pd%s%s\n", dentry,
++            (*opened & FILE_CREATED) ? " created" : "",
++            (*opened & FILE_OPENED) ? " opened" : "");
++      AuTraceErr(err);
++      return err;
++}
++
++
++/* ---------------------------------------------------------------------- */
++
 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
 +                        const unsigned char add_entry, aufs_bindex_t bcpup,
 +                        aufs_bindex_t bstart)
@@ -16154,16 +18498,18 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +      err = 0;
 +      if (!au_h_dptr(parent, bcpup)) {
-+              if (bstart < bcpup)
++              if (bstart > bcpup)
++                      err = au_cpup_dirs(dentry, bcpup);
++              else if (bstart < bcpup)
 +                      err = au_cpdown_dirs(dentry, bcpup);
 +              else
-+                      err = au_cpup_dirs(dentry, bcpup);
++                      BUG();
 +      }
-+      if (!err && add_entry) {
++      if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
 +              h_parent = au_h_dptr(parent, bcpup);
 +              h_dir = h_parent->d_inode;
 +              mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
-+              err = au_lkup_neg(dentry, bcpup);
++              err = au_lkup_neg(dentry, bcpup, /*wh*/0);
 +              /* todo: no unlock here */
 +              mutex_unlock(&h_dir->i_mutex);
 +
@@ -16193,9 +18539,11 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +            struct au_wr_dir_args *args)
 +{
 +      int err;
++      unsigned int flags;
 +      aufs_bindex_t bcpup, bstart, src_bstart;
-+      const unsigned char add_entry = !!au_ftest_wrdir(args->flags,
-+                                                       ADD_ENTRY);
++      const unsigned char add_entry
++              = au_ftest_wrdir(args->flags, ADD_ENTRY)
++              | au_ftest_wrdir(args->flags, TMPFILE);
 +      struct super_block *sb;
 +      struct dentry *parent;
 +      struct au_sbinfo *sbinfo;
@@ -16211,8 +18559,10 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +                      if (src_bstart < bstart)
 +                              bcpup = src_bstart;
 +              } else if (add_entry) {
-+                      err = AuWbrCreate(sbinfo, dentry,
-+                                        au_ftest_wrdir(args->flags, ISDIR));
++                      flags = 0;
++                      if (au_ftest_wrdir(args->flags, ISDIR))
++                              au_fset_wbr(flags, DIR);
++                      err = AuWbrCreate(sbinfo, dentry, flags);
 +                      bcpup = err;
 +              }
 +
@@ -16249,7 +18599,9 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +                      au_set_dbstart(dentry, bcpup);
 +                      au_set_dbend(dentry, bcpup);
 +              }
-+              AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
++              AuDebugOn(add_entry
++                        && !au_ftest_wrdir(args->flags, TMPFILE)
++                        && !au_h_dptr(dentry, bcpup));
 +      }
 +
 +out:
@@ -16259,6 +18611,85 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +/* ---------------------------------------------------------------------- */
 +
++void au_pin_hdir_unlock(struct au_pin *p)
++{
++      if (p->hdir)
++              au_hn_imtx_unlock(p->hdir);
++}
++
++int au_pin_hdir_lock(struct au_pin *p)
++{
++      int err;
++
++      err = 0;
++      if (!p->hdir)
++              goto out;
++
++      /* even if an error happens later, keep this lock */
++      au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
++
++      err = -EBUSY;
++      if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
++              goto out;
++
++      err = 0;
++      if (p->h_dentry)
++              err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
++                                p->h_parent, p->br);
++
++out:
++      return err;
++}
++
++int au_pin_hdir_relock(struct au_pin *p)
++{
++      int err, i;
++      struct inode *h_i;
++      struct dentry *h_d[] = {
++              p->h_dentry,
++              p->h_parent
++      };
++
++      err = au_pin_hdir_lock(p);
++      if (unlikely(err))
++              goto out;
++
++      for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
++              if (!h_d[i])
++                      continue;
++              h_i = h_d[i]->d_inode;
++              if (h_i)
++                      err = !h_i->i_nlink;
++      }
++
++out:
++      return err;
++}
++
++void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
++{
++#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
++      p->hdir->hi_inode->i_mutex.owner = task;
++#endif
++}
++
++void au_pin_hdir_acquire_nest(struct au_pin *p)
++{
++      if (p->hdir) {
++              mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
++                                 p->lsc_hi, 0, NULL, _RET_IP_);
++              au_pin_hdir_set_owner(p, current);
++      }
++}
++
++void au_pin_hdir_release(struct au_pin *p)
++{
++      if (p->hdir) {
++              au_pin_hdir_set_owner(p, p->task);
++              mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
++      }
++}
++
 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
 +{
 +      if (pin && pin->parent)
@@ -16268,12 +18699,13 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +void au_unpin(struct au_pin *p)
 +{
++      if (p->hdir)
++              au_pin_hdir_unlock(p);
 +      if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
 +              vfsub_mnt_drop_write(p->h_mnt);
 +      if (!p->hdir)
 +              return;
 +
-+      au_hn_imtx_unlock(p->hdir);
 +      if (!au_ftest_pin(p->flags, DI_LOCKED))
 +              di_read_unlock(p->parent, AuLock_IR);
 +      iput(p->hdir->hi_inode);
@@ -16281,22 +18713,21 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +      p->parent = NULL;
 +      p->hdir = NULL;
 +      p->h_mnt = NULL;
++      /* do not clear p->task */
 +}
 +
 +int au_do_pin(struct au_pin *p)
 +{
 +      int err;
 +      struct super_block *sb;
-+      struct dentry *h_dentry, *h_parent;
-+      struct au_branch *br;
 +      struct inode *h_dir;
 +
 +      err = 0;
 +      sb = p->dentry->d_sb;
-+      br = au_sbr(sb, p->bindex);
++      p->br = au_sbr(sb, p->bindex);
 +      if (IS_ROOT(p->dentry)) {
 +              if (au_ftest_pin(p->flags, MNT_WRITE)) {
-+                      p->h_mnt = br->br_mnt;
++                      p->h_mnt = au_br_mnt(p->br);
 +                      err = vfsub_mnt_want_write(p->h_mnt);
 +                      if (unlikely(err)) {
 +                              au_fclr_pin(p->flags, MNT_WRITE);
@@ -16306,16 +18737,16 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              goto out;
 +      }
 +
-+      h_dentry = NULL;
++      p->h_dentry = NULL;
 +      if (p->bindex <= au_dbend(p->dentry))
-+              h_dentry = au_h_dptr(p->dentry, p->bindex);
++              p->h_dentry = au_h_dptr(p->dentry, p->bindex);
 +
 +      p->parent = dget_parent(p->dentry);
 +      if (!au_ftest_pin(p->flags, DI_LOCKED))
 +              di_read_lock(p->parent, AuLock_IR, p->lsc_di);
 +
 +      h_dir = NULL;
-+      h_parent = au_h_dptr(p->parent, p->bindex);
++      p->h_parent = au_h_dptr(p->parent, p->bindex);
 +      p->hdir = au_hi(p->parent->d_inode, p->bindex);
 +      if (p->hdir)
 +              h_dir = p->hdir->hi_inode;
@@ -16325,7 +18756,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +       * if DI_LOCKED is not set, then p->parent may be different
 +       * and h_parent can be NULL.
 +       */
-+      if (unlikely(!p->hdir || !h_dir || !h_parent)) {
++      if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
 +              err = -EBUSY;
 +              if (!au_ftest_pin(p->flags, DI_LOCKED))
 +                      di_read_unlock(p->parent, AuLock_IR);
@@ -16334,33 +18765,26 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              goto out_err;
 +      }
 +
-+      au_igrab(h_dir);
-+      au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
-+
-+      if (unlikely(p->hdir->hi_inode != h_parent->d_inode)) {
-+              err = -EBUSY;
-+              goto out_unpin;
-+      }
-+      if (h_dentry) {
-+              err = au_h_verify(h_dentry, p->udba, h_dir, h_parent, br);
-+              if (unlikely(err)) {
-+                      au_fclr_pin(p->flags, MNT_WRITE);
-+                      goto out_unpin;
-+              }
-+      }
-+
 +      if (au_ftest_pin(p->flags, MNT_WRITE)) {
-+              p->h_mnt = br->br_mnt;
++              p->h_mnt = au_br_mnt(p->br);
 +              err = vfsub_mnt_want_write(p->h_mnt);
 +              if (unlikely(err)) {
 +                      au_fclr_pin(p->flags, MNT_WRITE);
-+                      goto out_unpin;
++                      if (!au_ftest_pin(p->flags, DI_LOCKED))
++                              di_read_unlock(p->parent, AuLock_IR);
++                      dput(p->parent);
++                      p->parent = NULL;
++                      goto out_err;
 +              }
 +      }
-+      goto out; /* success */
 +
-+out_unpin:
++      au_igrab(h_dir);
++      err = au_pin_hdir_lock(p);
++      if (!err)
++              goto out; /* success */
++
 +      au_unpin(p);
++
 +out_err:
 +      pr_err("err %d\n", err);
 +      err = au_busy_or_stale();
@@ -16382,6 +18806,11 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +      p->parent = NULL;
 +      p->hdir = NULL;
 +      p->h_mnt = NULL;
++
++      p->h_dentry = NULL;
++      p->h_parent = NULL;
++      p->br = NULL;
++      p->task = current;
 +}
 +
 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
@@ -16402,7 +18831,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
 + */
 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
-+static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
++int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
 +{
 +      int err;
 +      struct inode *inode;
@@ -16422,42 +18851,24 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +      return err;
 +}
 +
-+#define AuIcpup_DID_CPUP      1
-+#define au_ftest_icpup(flags, name)   ((flags) & AuIcpup_##name)
-+#define au_fset_icpup(flags, name) \
-+      do { (flags) |= AuIcpup_##name; } while (0)
-+#define au_fclr_icpup(flags, name) \
-+      do { (flags) &= ~AuIcpup_##name; } while (0)
-+
-+struct au_icpup_args {
-+      unsigned char flags;
-+      unsigned char pin_flags;
-+      aufs_bindex_t btgt;
-+      unsigned int udba;
-+      struct au_pin pin;
-+      struct path h_path;
-+      struct inode *h_inode;
-+};
-+
-+static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
-+                          struct au_icpup_args *a)
++int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
++                   struct au_icpup_args *a)
 +{
 +      int err;
 +      loff_t sz;
 +      aufs_bindex_t bstart, ibstart;
 +      struct dentry *hi_wh, *parent;
 +      struct inode *inode;
-+      struct file *h_file;
 +      struct au_wr_dir_args wr_dir_args = {
 +              .force_btgt     = -1,
 +              .flags          = 0
 +      };
 +
-+      bstart = au_dbstart(dentry);
-+      inode = dentry->d_inode;
-+      if (S_ISDIR(inode->i_mode))
++      if (d_is_dir(dentry))
 +              au_fset_wrdir(wr_dir_args.flags, ISDIR);
 +      /* plink or hi_wh() case */
++      bstart = au_dbstart(dentry);
++      inode = dentry->d_inode;
 +      ibstart = au_ibstart(inode);
 +      if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
 +              wr_dir_args.force_btgt = ibstart;
@@ -16483,17 +18894,26 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +      a->h_path.dentry = au_h_dptr(dentry, bstart);
 +      a->h_inode = a->h_path.dentry->d_inode;
-+      mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
 +      sz = -1;
-+      if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
-+              sz = ia->ia_size;
++      if (ia && (ia->ia_valid & ATTR_SIZE)) {
++              mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
++              if (ia->ia_size < i_size_read(a->h_inode))
++                      sz = ia->ia_size;
++              mutex_unlock(&a->h_inode->i_mutex);
++      }
 +
-+      h_file = NULL;
 +      hi_wh = NULL;
 +      if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
 +              hi_wh = au_hi_wh(inode, a->btgt);
 +              if (!hi_wh) {
-+                      err = au_sio_cpup_wh(dentry, a->btgt, sz, /*file*/NULL);
++                      struct au_cp_generic cpg = {
++                              .dentry = dentry,
++                              .bdst   = a->btgt,
++                              .bsrc   = -1,
++                              .len    = sz,
++                              .pin    = &a->pin
++                      };
++                      err = au_sio_cpup_wh(&cpg, /*file*/NULL);
 +                      if (unlikely(err))
 +                              goto out_unlock;
 +                      hi_wh = au_hi_wh(inode, a->btgt);
@@ -16511,13 +18931,15 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              goto out; /* success */
 +
 +      if (!d_unhashed(dentry)) {
-+              h_file = au_h_open_pre(dentry, bstart);
-+              if (IS_ERR(h_file)) {
-+                      err = PTR_ERR(h_file);
-+                      h_file = NULL;
-+              } else
-+                      err = au_sio_cpup_simple(dentry, a->btgt, sz,
-+                                               AuCpup_DTIME);
++              struct au_cp_generic cpg = {
++                      .dentry = dentry,
++                      .bdst   = a->btgt,
++                      .bsrc   = bstart,
++                      .len    = sz,
++                      .pin    = &a->pin,
++                      .flags  = AuCpup_DTIME | AuCpup_HOPEN
++              };
++              err = au_sio_cpup_simple(&cpg);
 +              if (!err)
 +                      a->h_path.dentry = au_h_dptr(dentry, a->btgt);
 +      } else if (!hi_wh)
@@ -16526,14 +18948,9 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              a->h_path.dentry = hi_wh; /* do not dget here */
 +
 +out_unlock:
-+      mutex_unlock(&a->h_inode->i_mutex);
-+      au_h_open_post(dentry, bstart, h_file);
 +      a->h_inode = a->h_path.dentry->d_inode;
-+      if (!err) {
-+              mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
++      if (!err)
 +              goto out; /* success */
-+      }
-+
 +      au_unpin(&a->pin);
 +out_parent:
 +      if (parent) {
@@ -16541,13 +18958,15 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              dput(parent);
 +      }
 +out:
++      if (!err)
++              mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
 +      return err;
 +}
 +
 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
 +{
 +      int err;
-+      struct inode *inode;
++      struct inode *inode, *delegated;
 +      struct super_block *sb;
 +      struct file *file;
 +      struct au_icpup_args *a;
@@ -16571,7 +18990,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +      if (ia->ia_valid & ATTR_FILE) {
 +              /* currently ftruncate(2) only */
-+              AuDebugOn(!S_ISREG(inode->i_mode));
++              AuDebugOn(!d_is_reg(dentry));
 +              file = ia->ia_file;
 +              err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
 +              if (unlikely(err))
@@ -16609,8 +19028,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +                      goto out_unlock;
 +      } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
 +                 && (ia->ia_valid & ATTR_CTIME)) {
-+              err = security_path_chown(&a->h_path, vfsub_ia_uid(ia),
-+                                        vfsub_ia_gid(ia));
++              err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
 +              if (unlikely(err))
 +                      goto out_unlock;
 +      }
@@ -16628,8 +19046,18 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              mutex_unlock(&a->h_inode->i_mutex);
 +              err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
 +              mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
-+      } else
-+              err = vfsub_notify_change(&a->h_path, ia);
++      } else {
++              delegated = NULL;
++              while (1) {
++                      err = vfsub_notify_change(&a->h_path, ia, &delegated);
++                      if (delegated) {
++                              err = break_deleg_wait(&delegated);
++                              if (!err)
++                                      continue;
++                      }
++                      break;
++              }
++      }
 +      if (!err)
 +              au_cpup_attr_changeable(inode);
 +
@@ -16654,14 +19082,108 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +      return err;
 +}
 +
++#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
++static int au_h_path_to_set_attr(struct dentry *dentry,
++                               struct au_icpup_args *a, struct path *h_path)
++{
++      int err;
++      struct super_block *sb;
++
++      sb = dentry->d_sb;
++      a->udba = au_opt_udba(sb);
++      /* no d_unlinked(), to set UDBA_NONE for root */
++      if (d_unhashed(dentry))
++              a->udba = AuOpt_UDBA_NONE;
++      if (a->udba != AuOpt_UDBA_NONE) {
++              AuDebugOn(IS_ROOT(dentry));
++              err = au_reval_for_attr(dentry, au_sigen(sb));
++              if (unlikely(err))
++                      goto out;
++      }
++      err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
++      if (unlikely(err < 0))
++              goto out;
++
++      h_path->dentry = a->h_path.dentry;
++      h_path->mnt = au_sbr_mnt(sb, a->btgt);
++
++out:
++      return err;
++}
++
++ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
++{
++      int err;
++      struct path h_path;
++      struct super_block *sb;
++      struct au_icpup_args *a;
++      struct inode *inode, *h_inode;
++
++      inode = dentry->d_inode;
++      IMustLock(inode);
++
++      err = -ENOMEM;
++      a = kzalloc(sizeof(*a), GFP_NOFS);
++      if (unlikely(!a))
++              goto out;
++
++      sb = dentry->d_sb;
++      err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
++      if (unlikely(err))
++              goto out_kfree;
++
++      h_path.dentry = NULL;   /* silence gcc */
++      di_write_lock_child(dentry);
++      err = au_h_path_to_set_attr(dentry, a, &h_path);
++      if (unlikely(err))
++              goto out_di;
++
++      mutex_unlock(&a->h_inode->i_mutex);
++      switch (arg->type) {
++      case AU_XATTR_SET:
++              err = vfsub_setxattr(h_path.dentry,
++                                   arg->u.set.name, arg->u.set.value,
++                                   arg->u.set.size, arg->u.set.flags);
++              break;
++      case AU_XATTR_REMOVE:
++              err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
++              break;
++      case AU_ACL_SET:
++              err = -EOPNOTSUPP;
++              h_inode = h_path.dentry->d_inode;
++              if (h_inode->i_op->set_acl)
++                      err = h_inode->i_op->set_acl(h_inode,
++                                                   arg->u.acl_set.acl,
++                                                   arg->u.acl_set.type);
++              break;
++      }
++      if (!err)
++              au_cpup_attr_timesizes(inode);
++
++      au_unpin(&a->pin);
++      if (unlikely(err))
++              au_update_dbstart(dentry);
++
++out_di:
++      di_write_unlock(dentry);
++      si_read_unlock(sb);
++out_kfree:
++      kfree(a);
++out:
++      AuTraceErr(err);
++      return err;
++}
++#endif
++
 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
 +                           unsigned int nlink)
 +{
 +      unsigned int n;
 +
 +      inode->i_mode = st->mode;
-+      i_uid_write(inode, st->uid);
-+      i_gid_write(inode, st->gid);
++      /* don't i_[ug]id_write() here */
++      inode->i_uid = st->uid;
++      inode->i_gid = st->gid;
 +      inode->i_atime = st->atime;
 +      inode->i_mtime = st->mtime;
 +      inode->i_ctime = st->ctime;
@@ -16671,6 +19193,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +              n = inode->i_nlink;
 +              n -= nlink;
 +              n += st->nlink;
++              smp_mb(); /* for i_nlink */
 +              /* 0 can happen */
 +              set_nlink(inode, n);
 +      }
@@ -16681,82 +19204,117 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +      spin_unlock(&inode->i_lock);
 +}
 +
-+static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
-+                      struct dentry *dentry, struct kstat *st)
++/*
++ * common routine for aufs_getattr() and aufs_getxattr().
++ * returns zero or negative (an error).
++ * @dentry will be read-locked in success.
++ */
++int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
 +{
 +      int err;
-+      unsigned int mnt_flags;
++      unsigned int mnt_flags, sigen;
++      unsigned char udba_none;
 +      aufs_bindex_t bindex;
-+      unsigned char udba_none, positive;
 +      struct super_block *sb, *h_sb;
 +      struct inode *inode;
-+      struct vfsmount *h_mnt;
-+      struct dentry *h_dentry;
 +
++      h_path->mnt = NULL;
++      h_path->dentry = NULL;
++
++      err = 0;
 +      sb = dentry->d_sb;
-+      inode = dentry->d_inode;
-+      err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
-+      if (unlikely(err))
-+              goto out;
 +      mnt_flags = au_mntflags(sb);
 +      udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
 +
 +      /* support fstat(2) */
 +      if (!d_unlinked(dentry) && !udba_none) {
-+              unsigned int sigen = au_sigen(sb);
++              sigen = au_sigen(sb);
 +              err = au_digen_test(dentry, sigen);
 +              if (!err) {
 +                      di_read_lock_child(dentry, AuLock_IR);
 +                      err = au_dbrange_test(dentry);
-+                      if (unlikely(err))
-+                              goto out_unlock;
++                      if (unlikely(err)) {
++                              di_read_unlock(dentry, AuLock_IR);
++                              goto out;
++                      }
 +              } else {
 +                      AuDebugOn(IS_ROOT(dentry));
 +                      di_write_lock_child(dentry);
 +                      err = au_dbrange_test(dentry);
 +                      if (!err)
 +                              err = au_reval_for_attr(dentry, sigen);
-+                      di_downgrade_lock(dentry, AuLock_IR);
-+                      if (unlikely(err))
-+                              goto out_unlock;
++                      if (!err)
++                              di_downgrade_lock(dentry, AuLock_IR);
++                      else {
++                              di_write_unlock(dentry);
++                              goto out;
++                      }
 +              }
 +      } else
 +              di_read_lock_child(dentry, AuLock_IR);
 +
++      inode = dentry->d_inode;
 +      bindex = au_ibstart(inode);
-+      h_mnt = au_sbr_mnt(sb, bindex);
-+      h_sb = h_mnt->mnt_sb;
-+      if (!au_test_fs_bad_iattr(h_sb) && udba_none)
-+              goto out_fill; /* success */
++      h_path->mnt = au_sbr_mnt(sb, bindex);
++      h_sb = h_path->mnt->mnt_sb;
++      if (!force
++          && !au_test_fs_bad_iattr(h_sb)
++          && udba_none)
++              goto out; /* success */
 +
-+      h_dentry = NULL;
 +      if (au_dbstart(dentry) == bindex)
-+              h_dentry = dget(au_h_dptr(dentry, bindex));
++              h_path->dentry = au_h_dptr(dentry, bindex);
 +      else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
-+              h_dentry = au_plink_lkup(inode, bindex);
-+              if (IS_ERR(h_dentry))
-+                      goto out_fill; /* pretending success */
++              h_path->dentry = au_plink_lkup(inode, bindex);
++              if (IS_ERR(h_path->dentry))
++                      /* pretending success */
++                      h_path->dentry = NULL;
++              else
++                      dput(h_path->dentry);
 +      }
-+      /* illegally overlapped or something */
-+      if (unlikely(!h_dentry))
++
++out:
++      return err;
++}
++
++static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
++                      struct dentry *dentry, struct kstat *st)
++{
++      int err;
++      unsigned char positive;
++      struct path h_path;
++      struct inode *inode;
++      struct super_block *sb;
++
++      inode = dentry->d_inode;
++      sb = dentry->d_sb;
++      err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
++      if (unlikely(err))
++              goto out;
++      err = au_h_path_getattr(dentry, /*force*/0, &h_path);
++      if (unlikely(err))
++              goto out_si;
++      if (unlikely(!h_path.dentry))
++              /* illegally overlapped or something */
 +              goto out_fill; /* pretending success */
 +
-+      positive = !!h_dentry->d_inode;
++      positive = !!h_path.dentry->d_inode;
 +      if (positive)
-+              err = vfs_getattr(h_mnt, h_dentry, st);
-+      dput(h_dentry);
++              err = vfs_getattr(&h_path, st);
 +      if (!err) {
 +              if (positive)
-+                      au_refresh_iattr(inode, st, h_dentry->d_inode->i_nlink);
++                      au_refresh_iattr(inode, st,
++                                       h_path.dentry->d_inode->i_nlink);
 +              goto out_fill; /* success */
 +      }
 +      AuTraceErr(err);
-+      goto out_unlock;
++      goto out_di;
 +
 +out_fill:
 +      generic_fillattr(inode, st);
-+out_unlock:
++out_di:
 +      di_read_unlock(dentry, AuLock_IR);
++out_si:
 +      si_read_unlock(sb);
 +out:
 +      AuTraceErr(err);
@@ -16876,9 +19434,15 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +      h_inode = au_h_iptr(inode, au_ibstart(inode));
 +      err = vfsub_update_time(h_inode, ts, flags);
 +      lockdep_off();
++      if (!err)
++              au_cpup_attr_timesizes(inode);
 +      ii_write_unlock(inode);
 +      si_read_unlock(sb);
 +      lockdep_on();
++
++      if (!err && (flags & S_VERSION))
++              inode_inc_iversion(inode);
++
 +      return err;
 +}
 +
@@ -16886,9 +19450,21 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +struct inode_operations aufs_symlink_iop = {
 +      .permission     = aufs_permission,
++#ifdef CONFIG_FS_POSIX_ACL
++      .get_acl        = aufs_get_acl,
++      .set_acl        = aufs_set_acl, /* unsupport for symlink? */
++#endif
++
 +      .setattr        = aufs_setattr,
 +      .getattr        = aufs_getattr,
 +
++#ifdef CONFIG_AUFS_XATTR
++      .setxattr       = aufs_setxattr,
++      .getxattr       = aufs_getxattr,
++      .listxattr      = aufs_listxattr,
++      .removexattr    = aufs_removexattr,
++#endif
++
 +      .readlink       = aufs_readlink,
 +      .follow_link    = aufs_follow_link,
 +      .put_link       = aufs_put_link,
@@ -16908,26 +19484,51 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +      .rename         = aufs_rename,
 +
 +      .permission     = aufs_permission,
++#ifdef CONFIG_FS_POSIX_ACL
++      .get_acl        = aufs_get_acl,
++      .set_acl        = aufs_set_acl,
++#endif
++
 +      .setattr        = aufs_setattr,
 +      .getattr        = aufs_getattr,
 +
-+      .update_time    = aufs_update_time
-+      /* no support for atomic_open() */
++#ifdef CONFIG_AUFS_XATTR
++      .setxattr       = aufs_setxattr,
++      .getxattr       = aufs_getxattr,
++      .listxattr      = aufs_listxattr,
++      .removexattr    = aufs_removexattr,
++#endif
++
++      .update_time    = aufs_update_time,
++      .atomic_open    = aufs_atomic_open,
++      .tmpfile        = aufs_tmpfile
 +};
 +
 +struct inode_operations aufs_iop = {
 +      .permission     = aufs_permission,
++#ifdef CONFIG_FS_POSIX_ACL
++      .get_acl        = aufs_get_acl,
++      .set_acl        = aufs_set_acl,
++#endif
++
 +      .setattr        = aufs_setattr,
 +      .getattr        = aufs_getattr,
 +
++#ifdef CONFIG_AUFS_XATTR
++      .setxattr       = aufs_setxattr,
++      .getxattr       = aufs_getxattr,
++      .listxattr      = aufs_listxattr,
++      .removexattr    = aufs_removexattr,
++#endif
++
 +      .update_time    = aufs_update_time
 +};
 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 --- /usr/share/empty/fs/aufs/i_op_del.c        1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/i_op_del.c   2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,477 @@
++++ linux/fs/aufs/i_op_del.c   2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,506 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -16940,8 +19541,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -17055,11 +19655,12 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +       * let's try heavy test.
 +       */
 +      err = -EACCES;
-+      if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
++      if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
++                   && au_test_h_perm(h_parent->d_inode,
++                                     MAY_EXEC | MAY_WRITE)))
 +              goto out;
 +
-+      h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
-+                                 au_sbr(dentry->d_sb, bindex));
++      h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
 +      err = -EIO;
 +      if (IS_ERR(h_latest))
 +              goto out;
@@ -17168,8 +19769,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +
 +      err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
 +      if (unlikely(err)) {
-+              AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
-+                      AuDLNPair(h_dentry), bindex, err);
++              AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
++                      h_dentry, bindex, err);
 +              err = 0;
 +      }
 +
@@ -17191,8 +19792,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +      d_drop(dentry);
 +      inode->i_ctime = dir->i_ctime;
 +
-+      if (au_ibstart(dir) == bindex)
-+              au_cpup_attr_timesizes(dir);
++      au_dir_ts(dir, bindex);
 +      dir->i_version++;
 +}
 +
@@ -17216,8 +19816,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +              return 0;
 +      }
 +
-+      AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
-+              AuDLNPair(dentry), err, rerr);
++      AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
 +      return -EIO;
 +}
 +
@@ -17227,24 +19826,32 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +{
 +      int err;
 +      aufs_bindex_t bwh, bindex, bstart;
-+      struct au_dtime dt;
-+      struct au_pin pin;
-+      struct path h_path;
-+      struct inode *inode, *h_dir;
++      struct inode *inode, *h_dir, *delegated;
 +      struct dentry *parent, *wh_dentry;
++      /* to reuduce stack size */
++      struct {
++              struct au_dtime dt;
++              struct au_pin pin;
++              struct path h_path;
++      } *a;
 +
 +      IMustLock(dir);
 +
++      err = -ENOMEM;
++      a = kmalloc(sizeof(*a), GFP_NOFS);
++      if (unlikely(!a))
++              goto out;
++
 +      err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
 +      if (unlikely(err))
-+              goto out;
++              goto out_free;
 +      err = au_d_hashed_positive(dentry);
 +      if (unlikely(err))
 +              goto out_unlock;
 +      inode = dentry->d_inode;
 +      IMustLock(inode);
 +      err = -EISDIR;
-+      if (unlikely(S_ISDIR(inode->i_mode)))
++      if (unlikely(d_is_dir(dentry)))
 +              goto out_unlock; /* possible? */
 +
 +      bstart = au_dbstart(dentry);
@@ -17252,17 +19859,24 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +      bindex = -1;
 +      parent = dentry->d_parent; /* dir inode is locked */
 +      di_write_lock_parent(parent);
-+      wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &dt, &pin);
++      wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
++                                      &a->pin);
 +      err = PTR_ERR(wh_dentry);
 +      if (IS_ERR(wh_dentry))
 +              goto out_parent;
 +
-+      h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
-+      h_path.dentry = au_h_dptr(dentry, bstart);
-+      dget(h_path.dentry);
++      a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
++      a->h_path.dentry = au_h_dptr(dentry, bstart);
++      dget(a->h_path.dentry);
 +      if (bindex == bstart) {
-+              h_dir = au_pinned_h_dir(&pin);
-+              err = vfsub_unlink(h_dir, &h_path, /*force*/0);
++              h_dir = au_pinned_h_dir(&a->pin);
++              delegated = NULL;
++              err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal unlink\n");
++                      iput(delegated);
++              }
 +      } else {
 +              /* dir inode is locked */
 +              h_dir = wh_dentry->d_parent->d_inode;
@@ -17276,8 +19890,9 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +
 +              /* update target timestamps */
 +              if (bindex == bstart) {
-+                      vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
-+                      inode->i_ctime = h_path.dentry->d_inode->i_ctime;
++                      vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
++                      /*ignore*/
++                      inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
 +              } else
 +                      /* todo: this timestamp may be reverted later */
 +                      inode->i_ctime = h_dir->i_ctime;
@@ -17288,19 +19903,22 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +      if (wh_dentry) {
 +              int rerr;
 +
-+              rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
++              rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
++                               &a->dt);
 +              if (rerr)
 +                      err = rerr;
 +      }
 +
 +out_unpin:
-+      au_unpin(&pin);
++      au_unpin(&a->pin);
 +      dput(wh_dentry);
-+      dput(h_path.dentry);
++      dput(a->h_path.dentry);
 +out_parent:
 +      di_write_unlock(parent);
 +out_unlock:
 +      aufs_read_unlock(dentry, AuLock_DW);
++out_free:
++      kfree(a);
 +out:
 +      return err;
 +}
@@ -17309,24 +19927,32 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +{
 +      int err, rmdir_later;
 +      aufs_bindex_t bwh, bindex, bstart;
-+      struct au_dtime dt;
-+      struct au_pin pin;
 +      struct inode *inode;
 +      struct dentry *parent, *wh_dentry, *h_dentry;
 +      struct au_whtmp_rmdir *args;
++      /* to reuduce stack size */
++      struct {
++              struct au_dtime dt;
++              struct au_pin pin;
++      } *a;
 +
 +      IMustLock(dir);
 +
++      err = -ENOMEM;
++      a = kmalloc(sizeof(*a), GFP_NOFS);
++      if (unlikely(!a))
++              goto out;
++
 +      err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
 +      if (unlikely(err))
-+              goto out;
++              goto out_free;
 +      err = au_alive_dir(dentry);
 +      if (unlikely(err))
 +              goto out_unlock;
 +      inode = dentry->d_inode;
 +      IMustLock(inode);
 +      err = -ENOTDIR;
-+      if (unlikely(!S_ISDIR(inode->i_mode)))
++      if (unlikely(!d_is_dir(dentry)))
 +              goto out_unlock; /* possible? */
 +
 +      err = -ENOMEM;
@@ -17343,7 +19969,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +      bstart = au_dbstart(dentry);
 +      bwh = au_dbwh(dentry);
 +      bindex = -1;
-+      wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &dt, &pin);
++      wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
++                                      &a->pin);
 +      err = PTR_ERR(wh_dentry);
 +      if (IS_ERR(wh_dentry))
 +              goto out_parent;
@@ -17384,13 +20011,14 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +      if (wh_dentry) {
 +              int rerr;
 +
-+              rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
++              rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
++                               &a->dt);
 +              if (rerr)
 +                      err = rerr;
 +      }
 +
 +out_unpin:
-+      au_unpin(&pin);
++      au_unpin(&a->pin);
 +      dput(wh_dentry);
 +      dput(h_dentry);
 +out_parent:
@@ -17399,16 +20027,18 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +              au_whtmp_rmdir_free(args);
 +out_unlock:
 +      aufs_read_unlock(dentry, AuLock_DW);
++out_free:
++      kfree(a);
 +out:
 +      AuTraceErr(err);
 +      return err;
 +}
 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 --- /usr/share/empty/fs/aufs/i_op_ren.c        1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/i_op_ren.c   2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,1026 @@
++++ linux/fs/aufs/i_op_ren.c   2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,1015 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -17421,8 +20051,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -17442,7 +20071,6 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +#define AuRen_MNT_WRITE       (1 << 4)
 +#define AuRen_DT_DSTDIR       (1 << 5)
 +#define AuRen_DIROPQ  (1 << 6)
-+#define AuRen_CPUP    (1 << 7)
 +#define au_ftest_ren(flags, name)     ((flags) & AuRen_##name)
 +#define au_fset_ren(flags, name) \
 +      do { (flags) |= AuRen_##name; } while (0)
@@ -17521,52 +20149,48 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      au_hn_imtx_unlock(a->src_hinode);
 +      au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
 +      if (rerr)
-+              RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
++              RevertFailure("remove diropq %pd", a->src_dentry);
 +}
 +
 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
 +{
 +      int rerr;
++      struct inode *delegated;
 +
 +      a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
 +                                        a->src_h_parent);
 +      rerr = PTR_ERR(a->h_path.dentry);
 +      if (IS_ERR(a->h_path.dentry)) {
-+              RevertFailure("lkup one %.*s", AuDLNPair(a->src_dentry));
++              RevertFailure("lkup one %pd", a->src_dentry);
 +              return;
 +      }
 +
++      delegated = NULL;
 +      rerr = vfsub_rename(a->dst_h_dir,
 +                          au_h_dptr(a->src_dentry, a->btgt),
-+                          a->src_h_dir, &a->h_path);
++                          a->src_h_dir, &a->h_path, &delegated);
++      if (unlikely(rerr == -EWOULDBLOCK)) {
++              pr_warn("cannot retry for NFSv4 delegation"
++                      " for an internal rename\n");
++              iput(delegated);
++      }
 +      d_drop(a->h_path.dentry);
 +      dput(a->h_path.dentry);
 +      /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
 +      if (rerr)
-+              RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
-+}
-+
-+static void au_ren_rev_cpup(int err, struct au_ren_args *a)
-+{
-+      int rerr;
-+
-+      a->h_path.dentry = a->dst_h_dentry;
-+      rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
-+      au_set_h_dptr(a->src_dentry, a->btgt, NULL);
-+      au_set_dbstart(a->src_dentry, a->src_bstart);
-+      if (rerr)
-+              RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
++              RevertFailure("rename %pd", a->src_dentry);
 +}
 +
 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
 +{
 +      int rerr;
++      struct inode *delegated;
 +
 +      a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
 +                                        a->dst_h_parent);
 +      rerr = PTR_ERR(a->h_path.dentry);
 +      if (IS_ERR(a->h_path.dentry)) {
-+              RevertFailure("lkup one %.*s", AuDLNPair(a->dst_dentry));
++              RevertFailure("lkup one %pd", a->dst_dentry);
 +              return;
 +      }
 +      if (a->h_path.dentry->d_inode) {
@@ -17575,13 +20199,20 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +              return;
 +      }
 +
-+      rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
++      delegated = NULL;
++      rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
++                          &delegated);
++      if (unlikely(rerr == -EWOULDBLOCK)) {
++              pr_warn("cannot retry for NFSv4 delegation"
++                      " for an internal rename\n");
++              iput(delegated);
++      }
 +      d_drop(a->h_path.dentry);
 +      dput(a->h_path.dentry);
 +      if (!rerr)
 +              au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
 +      else
-+              RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
++              RevertFailure("rename %pd", a->h_dst);
 +}
 +
 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
@@ -17592,7 +20223,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
 +      au_set_dbwh(a->src_dentry, a->src_bwh);
 +      if (rerr)
-+              RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
++              RevertFailure("unlink %pd", a->src_wh_dentry);
 +}
 +#undef RevertFailure
 +
@@ -17607,6 +20238,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +{
 +      int err;
 +      struct dentry *d;
++      struct inode *delegated;
 +
 +      d = a->src_dentry;
 +      if (au_dbstart(d) == a->btgt) {
@@ -17615,34 +20247,17 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +                  && au_dbdiropq(d) == a->btgt)
 +                      au_fclr_ren(a->flags, DIROPQ);
 +              AuDebugOn(au_dbstart(d) != a->btgt);
++              delegated = NULL;
 +              err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
-+                                 a->dst_h_dir, &a->h_path);
-+      } else {
-+              struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
-+              struct file *h_file;
-+
-+              au_fset_ren(a->flags, CPUP);
-+              mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
-+              au_set_dbstart(d, a->btgt);
-+              au_set_h_dptr(d, a->btgt, dget(a->dst_h_dentry));
-+              h_file = au_h_open_pre(d, a->src_bstart);
-+              if (IS_ERR(h_file)) {
-+                      err = PTR_ERR(h_file);
-+                      h_file = NULL;
-+              } else
-+                      err = au_sio_cpup_single(d, a->btgt, a->src_bstart, -1,
-+                                               !AuCpup_DTIME, a->dst_parent);
-+              mutex_unlock(h_mtx);
-+              au_h_open_post(d, a->src_bstart, h_file);
-+              if (!err) {
-+                      d = a->dst_dentry;
-+                      au_set_h_dptr(d, a->btgt, NULL);
-+                      au_update_dbstart(d);
-+              } else {
-+                      au_set_h_dptr(d, a->btgt, NULL);
-+                      au_set_dbstart(d, a->src_bstart);
++                                 a->dst_h_dir, &a->h_path, &delegated);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal rename\n");
++                      iput(delegated);
 +              }
-+      }
++      } else
++              BUG();
++
 +      if (!err && a->h_dst)
 +              /* it will be set to dinfo later */
 +              dget(a->h_dst);
@@ -17663,8 +20278,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +          || au_test_fs_remote(a->h_dst->d_sb)) {
 +              err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
 +              if (unlikely(err))
-+                      pr_warn("failed removing whtmp dir %.*s (%d), "
-+                              "ignored.\n", AuDLNPair(a->h_dst), err);
++                      pr_warn("failed removing whtmp dir %pd (%d), "
++                              "ignored.\n", a->h_dst, err);
 +      } else {
 +              au_nhash_wh_free(&a->thargs->whlist);
 +              a->thargs->whlist = a->whlist;
@@ -17691,7 +20306,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      au_hn_imtx_unlock(a->src_hinode);
 +      if (IS_ERR(diropq))
 +              err = PTR_ERR(diropq);
-+      dput(diropq);
++      else
++              dput(diropq);
 +
 +      return err;
 +}
@@ -17743,31 +20359,13 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +
 +              d = a->dst_dentry;
 +              au_set_h_dptr(d, a->btgt, NULL);
-+              err = au_lkup_neg(d, a->btgt);
++              err = au_lkup_neg(d, a->btgt, /*wh*/0);
 +              if (unlikely(err))
 +                      goto out_whtmp;
 +              a->dst_h_dentry = au_h_dptr(d, a->btgt);
 +      }
 +
-+      /* cpup src */
-+      if (a->dst_h_dentry->d_inode && a->src_bstart != a->btgt) {
-+              struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
-+              struct file *h_file;
-+
-+              mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
-+              AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
-+              h_file = au_h_open_pre(a->src_dentry, a->src_bstart);
-+              if (IS_ERR(h_file)) {
-+                      err = PTR_ERR(h_file);
-+                      h_file = NULL;
-+              } else
-+                      err = au_sio_cpup_simple(a->src_dentry, a->btgt, -1,
-+                                               !AuCpup_DTIME);
-+              mutex_unlock(h_mtx);
-+              au_h_open_post(a->src_dentry, a->src_bstart, h_file);
-+              if (unlikely(err))
-+                      goto out_whtmp;
-+      }
++      BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
 +
 +      /* rename by vfs_rename or cpup */
 +      d = a->dst_dentry;
@@ -17809,6 +20407,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      if (a->thargs)
 +              au_ren_del_whtmp(a); /* ignore this error */
 +
++      au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
 +      err = 0;
 +      goto out_success;
 +
@@ -17816,10 +20415,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      if (au_ftest_ren(a->flags, DIROPQ))
 +              au_ren_rev_diropq(err, a);
 +out_rename:
-+      if (!au_ftest_ren(a->flags, CPUP))
-+              au_ren_rev_rename(err, a);
-+      else
-+              au_ren_rev_cpup(err, a);
++      au_ren_rev_rename(err, a);
 +      dput(a->h_dst);
 +out_whtmp:
 +      if (a->thargs)
@@ -18019,13 +20615,10 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 + */
 +static void au_ren_unlock(struct au_ren_args *a)
 +{
-+      struct super_block *sb;
-+
-+      sb = a->dst_dentry->d_sb;
-+      if (au_ftest_ren(a->flags, MNT_WRITE))
-+              vfsub_mnt_drop_write(a->br->br_mnt);
 +      vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
 +                          a->dst_h_parent, a->dst_hdir);
++      if (au_ftest_ren(a->flags, MNT_WRITE))
++              vfsub_mnt_drop_write(au_br_mnt(a->br));
 +}
 +
 +static int au_ren_lock(struct au_ren_args *a)
@@ -18038,6 +20631,11 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      a->src_hdir = au_hi(a->src_dir, a->btgt);
 +      a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
 +      a->dst_hdir = au_hi(a->dst_dir, a->btgt);
++
++      err = vfsub_mnt_want_write(au_br_mnt(a->br));
++      if (unlikely(err))
++              goto out;
++      au_fset_ren(a->flags, MNT_WRITE);
 +      a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
 +                                    a->dst_h_parent, a->dst_hdir);
 +      udba = au_opt_udba(a->src_dentry->d_sb);
@@ -18052,18 +20650,12 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +              err = au_h_verify(a->dst_h_dentry, udba,
 +                                a->dst_h_parent->d_inode, a->dst_h_parent,
 +                                a->br);
-+      if (!err) {
-+              err = vfsub_mnt_want_write(a->br->br_mnt);
-+              if (unlikely(err))
-+                      goto out_unlock;
-+              au_fset_ren(a->flags, MNT_WRITE);
++      if (!err)
 +              goto out; /* success */
-+      }
 +
 +      err = au_busy_or_stale();
-+
-+out_unlock:
 +      au_ren_unlock(a);
++
 +out:
 +      return err;
 +}
@@ -18082,8 +20674,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +              au_cpup_attr_nlink(dir, /*force*/1);
 +      }
 +
-+      if (au_ibstart(dir) == a->btgt)
-+              au_cpup_attr_timesizes(dir);
++      au_dir_ts(dir, a->btgt);
 +
 +      if (au_ftest_ren(a->flags, ISSAMEDIR))
 +              return;
@@ -18092,8 +20683,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      dir->i_version++;
 +      if (au_ftest_ren(a->flags, ISDIR))
 +              au_cpup_attr_nlink(dir, /*force*/1);
-+      if (au_ibstart(dir) == a->btgt)
-+              au_cpup_attr_timesizes(dir);
++      au_dir_ts(dir, a->btgt);
 +}
 +
 +static void au_ren_refresh(struct au_ren_args *a)
@@ -18259,7 +20849,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      /* reduce stack space */
 +      struct au_ren_args *a;
 +
-+      AuDbg("%.*s, %.*s\n", AuDLNPair(_src_dentry), AuDLNPair(_dst_dentry));
++      AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
 +      IMustLock(_src_dir);
 +      IMustLock(_dst_dir);
 +
@@ -18284,9 +20874,10 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +
 +      err = -ENOTDIR;
 +      flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
-+      if (S_ISDIR(a->src_inode->i_mode)) {
++      if (d_is_dir(a->src_dentry)) {
 +              au_fset_ren(a->flags, ISDIR);
-+              if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
++              if (unlikely(d_is_positive(a->dst_dentry)
++                           && !d_is_dir(a->dst_dentry)))
 +                      goto out_free;
 +              err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
 +                                              AuLock_DIR | flags);
@@ -18333,7 +20924,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      if (unlikely(err < 0))
 +              goto out_parent;
 +      a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
-+      a->h_path.mnt = a->br->br_mnt;
++      a->h_path.mnt = au_br_mnt(a->br);
 +
 +      /* are they available to be renamed */
 +      err = au_ren_may_dir(a);
@@ -18371,9 +20962,37 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +      if (err)
 +              au_fset_ren(a->flags, WHSRC);
 +
++      /* cpup src */
++      if (a->src_bstart != a->btgt) {
++              struct au_pin pin;
++
++              err = au_pin(&pin, a->src_dentry, a->btgt,
++                           au_opt_udba(a->src_dentry->d_sb),
++                           AuPin_DI_LOCKED | AuPin_MNT_WRITE);
++              if (!err) {
++                      struct au_cp_generic cpg = {
++                              .dentry = a->src_dentry,
++                              .bdst   = a->btgt,
++                              .bsrc   = a->src_bstart,
++                              .len    = -1,
++                              .pin    = &pin,
++                              .flags  = AuCpup_DTIME | AuCpup_HOPEN
++                      };
++                      AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
++                      err = au_sio_cpup_simple(&cpg);
++                      au_unpin(&pin);
++              }
++              if (unlikely(err))
++                      goto out_children;
++              a->src_bstart = a->btgt;
++              a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
++              au_fset_ren(a->flags, WHSRC);
++      }
++
 +      /* lock them all */
 +      err = au_ren_lock(a);
 +      if (unlikely(err))
++              /* leave the copied-up one */
 +              goto out_children;
 +
 +      if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
@@ -18435,11 +21054,10 @@ diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
 +}
 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
 --- /usr/share/empty/fs/aufs/Kconfig   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/Kconfig      2013-03-14 20:07:41.038119650 +0100
-@@ -0,0 +1,203 @@
++++ linux/fs/aufs/Kconfig      2015-06-22 08:27:37.874168290 +0200
+@@ -0,0 +1,185 @@
 +config AUFS_FS
 +      tristate "Aufs (Advanced multi layered unification filesystem) support"
-+      depends on EXPERIMENTAL
 +      help
 +      Aufs is a stackable unification filesystem such as Unionfs,
 +      which unifies several directories and provides a merged single
@@ -18527,125 +21145,395 @@ diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
 +      /* typedef unsigned long/int __kernel_ino_t */
 +      /* alpha and s390x are int */
 +
-+config AUFS_RDU
-+      bool "Readdir in userspace"
-+      help
-+      Aufs has two methods to provide a merged view for a directory,
-+      by a user-space library and by kernel-space natively. The latter
-+      is always enabled but sometimes large and slow.
-+      If you enable this option, install the library in aufs2-util
-+      package, and set some environment variables for your readdir(3),
-+      then the work will be handled in user-space which generally
-+      shows better performance in most cases.
-+      See detail in aufs.5.
++config AUFS_XATTR
++      bool "support for XATTR/EA (including Security Labels)"
++      help
++      If your branch fs supports XATTR/EA and you want to make them
++      available in aufs too, then enable this opsion and specify the
++      branch attributes for EA.
++      See detail in aufs.5.
++
++config AUFS_FHSM
++      bool "File-based Hierarchical Storage Management"
++      help
++      Hierarchical Storage Management (or HSM) is a well-known feature
++      in the storage world. Aufs provides this feature as file-based.
++      with multiple branches.
++      These multiple branches are prioritized, ie. the topmost one
++      should be the fastest drive and be used heavily.
++
++config AUFS_RDU
++      bool "Readdir in userspace"
++      help
++      Aufs has two methods to provide a merged view for a directory,
++      by a user-space library and by kernel-space natively. The latter
++      is always enabled but sometimes large and slow.
++      If you enable this option, install the library in aufs2-util
++      package, and set some environment variables for your readdir(3),
++      then the work will be handled in user-space which generally
++      shows better performance in most cases.
++      See detail in aufs.5.
++
++config AUFS_SHWH
++      bool "Show whiteouts"
++      help
++      If you want to make the whiteouts in aufs visible, then enable
++      this option and specify 'shwh' mount option. Although it may
++      sounds like philosophy or something, but in technically it
++      simply shows the name of whiteout with keeping its behaviour.
++
++config AUFS_BR_RAMFS
++      bool "Ramfs (initramfs/rootfs) as an aufs branch"
++      help
++      If you want to use ramfs as an aufs branch fs, then enable this
++      option. Generally tmpfs is recommended.
++      Aufs prohibited them to be a branch fs by default, because
++      initramfs becomes unusable after switch_root or something
++      generally. If you sets initramfs as an aufs branch and boot your
++      system by switch_root, you will meet a problem easily since the
++      files in initramfs may be inaccessible.
++      Unless you are going to use ramfs as an aufs branch fs without
++      switch_root or something, leave it N.
++
++config AUFS_BR_FUSE
++      bool "Fuse fs as an aufs branch"
++      depends on FUSE_FS
++      select AUFS_POLL
++      help
++      If you want to use fuse-based userspace filesystem as an aufs
++      branch fs, then enable this option.
++      It implements the internal poll(2) operation which is
++      implemented by fuse only (curretnly).
++
++config AUFS_POLL
++      bool
++      help
++      Automatic configuration for internal use.
++
++config AUFS_BR_HFSPLUS
++      bool "Hfsplus as an aufs branch"
++      depends on HFSPLUS_FS
++      default y
++      help
++      If you want to use hfsplus fs as an aufs branch fs, then enable
++      this option. This option introduces a small overhead at
++      copying-up a file on hfsplus.
++
++config AUFS_BDEV_LOOP
++      bool
++      depends on BLK_DEV_LOOP
++      default y
++      help
++      Automatic configuration for internal use.
++      Convert =[ym] into =y.
++
++config AUFS_DEBUG
++      bool "Debug aufs"
++      help
++      Enable this to compile aufs internal debug code.
++      It will have a negative impact to the performance.
++
++config AUFS_MAGIC_SYSRQ
++      bool
++      depends on AUFS_DEBUG && MAGIC_SYSRQ
++      default y
++      help
++      Automatic configuration for internal use.
++      When aufs supports Magic SysRq, enabled automatically.
++endif
+diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
+--- /usr/share/empty/fs/aufs/loop.c    1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/loop.c       2015-06-22 08:29:23.706757681 +0200
+@@ -0,0 +1,145 @@
++/*
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
++ *
++ * This program, aufs is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * support for loopback block device as a branch
++ */
++
++#include "aufs.h"
++
++/* added into drivers/block/loop.c */
++static struct file *(*backing_file_func)(struct super_block *sb);
++
++/*
++ * test if two lower dentries have overlapping branches.
++ */
++int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
++{
++      struct super_block *h_sb;
++      struct file *backing_file;
++
++      if (unlikely(!backing_file_func)) {
++              /* don't load "loop" module here */
++              backing_file_func = symbol_get(loop_backing_file);
++              if (unlikely(!backing_file_func))
++                      /* "loop" module is not loaded */
++                      return 0;
++      }
++
++      h_sb = h_adding->d_sb;
++      backing_file = backing_file_func(h_sb);
++      if (!backing_file)
++              return 0;
++
++      h_adding = backing_file->f_path.dentry;
++      /*
++       * h_adding can be local NFS.
++       * in this case aufs cannot detect the loop.
++       */
++      if (unlikely(h_adding->d_sb == sb))
++              return 1;
++      return !!au_test_subdir(h_adding, sb->s_root);
++}
++
++/* true if a kernel thread named 'loop[0-9].*' accesses a file */
++int au_test_loopback_kthread(void)
++{
++      int ret;
++      struct task_struct *tsk = current;
++      char c, comm[sizeof(tsk->comm)];
++
++      ret = 0;
++      if (tsk->flags & PF_KTHREAD) {
++              get_task_comm(comm, tsk);
++              c = comm[4];
++              ret = ('0' <= c && c <= '9'
++                     && !strncmp(comm, "loop", 4));
++      }
++
++      return ret;
++}
++
++/* ---------------------------------------------------------------------- */
++
++#define au_warn_loopback_step 16
++static int au_warn_loopback_nelem = au_warn_loopback_step;
++static unsigned long *au_warn_loopback_array;
++
++void au_warn_loopback(struct super_block *h_sb)
++{
++      int i, new_nelem;
++      unsigned long *a, magic;
++      static DEFINE_SPINLOCK(spin);
++
++      magic = h_sb->s_magic;
++      spin_lock(&spin);
++      a = au_warn_loopback_array;
++      for (i = 0; i < au_warn_loopback_nelem && *a; i++)
++              if (a[i] == magic) {
++                      spin_unlock(&spin);
++                      return;
++              }
++
++      /* h_sb is new to us, print it */
++      if (i < au_warn_loopback_nelem) {
++              a[i] = magic;
++              goto pr;
++      }
++
++      /* expand the array */
++      new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
++      a = au_kzrealloc(au_warn_loopback_array,
++                       au_warn_loopback_nelem * sizeof(unsigned long),
++                       new_nelem * sizeof(unsigned long), GFP_ATOMIC);
++      if (a) {
++              au_warn_loopback_nelem = new_nelem;
++              au_warn_loopback_array = a;
++              a[i] = magic;
++              goto pr;
++      }
++
++      spin_unlock(&spin);
++      AuWarn1("realloc failed, ignored\n");
++      return;
++
++pr:
++      spin_unlock(&spin);
++      pr_warn("you may want to try another patch for loopback file "
++              "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
++}
++
++int au_loopback_init(void)
++{
++      int err;
++      struct super_block *sb __maybe_unused;
++
++      AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
++
++      err = 0;
++      au_warn_loopback_array = kcalloc(au_warn_loopback_step,
++                                       sizeof(unsigned long), GFP_NOFS);
++      if (unlikely(!au_warn_loopback_array))
++              err = -ENOMEM;
++
++      return err;
++}
++
++void au_loopback_fin(void)
++{
++      symbol_put(loop_backing_file);
++      kfree(au_warn_loopback_array);
++}
+diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
+--- /usr/share/empty/fs/aufs/loop.h    1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/loop.h       2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,52 @@
++/*
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
++ *
++ * This program, aufs is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * support for loopback mount as a branch
++ */
++
++#ifndef __AUFS_LOOP_H__
++#define __AUFS_LOOP_H__
++
++#ifdef __KERNEL__
++
++struct dentry;
++struct super_block;
++
++#ifdef CONFIG_AUFS_BDEV_LOOP
++/* drivers/block/loop.c */
++struct file *loop_backing_file(struct super_block *sb);
++
++/* loop.c */
++int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
++int au_test_loopback_kthread(void);
++void au_warn_loopback(struct super_block *h_sb);
++
++int au_loopback_init(void);
++void au_loopback_fin(void);
++#else
++AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
++         struct dentry *h_adding)
++AuStubInt0(au_test_loopback_kthread, void)
++AuStubVoid(au_warn_loopback, struct super_block *h_sb)
 +
-+config AUFS_PROC_MAP
-+      bool "support for /proc/maps and lsof(1)"
-+      depends on PROC_FS
-+      help
-+      When you issue mmap(2) in aufs, it is actually a direct mmap(2)
-+      call to the file on the branch fs since the file in aufs is
-+      purely virtual. And the file path printed in /proc/maps (and
-+      others) will be the path on the branch fs. In most cases, it
-+      does no harm. But some utilities like lsof(1) may confuse since
-+      the utility or user may expect the file path in aufs to be
-+      printed.
-+      To address this issue, aufs provides a patch which introduces a
-+      new member called vm_prfile into struct vm_are_struct. The patch
-+      is meaningless without enabling this configuration since nobody
-+      sets the new vm_prfile member.
-+      If you don't apply the patch, then enabling this configuration
-+      will cause a compile error.
-+      This approach is fragile since if someone else make some changes
-+      around vm_file, then vm_prfile may not work anymore. As a
-+      workaround such case, aufs provides this configuration. If you
-+      disable it, then lsof(1) may produce incorrect result but the
-+      problem will be gone even if the aufs patch is applied (I hope).
-+
-+config AUFS_SP_IATTR
-+      bool "Respect the attributes (mtime/ctime mainly) of special files"
-+      help
-+      When you write something to a special file, some attributes of it
-+      (mtime/ctime mainly) may be updated. Generally such updates are
-+      less important (actually some device drivers and NFS ignore
-+      it). But some applications (such like test program) requires
-+      such updates. If you need these updates, then enable this
-+      configuration which introduces some overhead.
-+      Currently this configuration handles FIFO only.
++AuStubInt0(au_loopback_init, void)
++AuStubVoid(au_loopback_fin, void)
++#endif /* BLK_DEV_LOOP */
 +
-+config AUFS_SHWH
-+      bool "Show whiteouts"
-+      help
-+      If you want to make the whiteouts in aufs visible, then enable
-+      this option and specify 'shwh' mount option. Although it may
-+      sounds like philosophy or something, but in technically it
-+      simply shows the name of whiteout with keeping its behaviour.
++#endif /* __KERNEL__ */
++#endif /* __AUFS_LOOP_H__ */
+diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
+--- /usr/share/empty/fs/aufs/magic.mk  1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/magic.mk     2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,30 @@
 +
-+config AUFS_BR_RAMFS
-+      bool "Ramfs (initramfs/rootfs) as an aufs branch"
-+      help
-+      If you want to use ramfs as an aufs branch fs, then enable this
-+      option. Generally tmpfs is recommended.
-+      Aufs prohibited them to be a branch fs by default, because
-+      initramfs becomes unusable after switch_root or something
-+      generally. If you sets initramfs as an aufs branch and boot your
-+      system by switch_root, you will meet a problem easily since the
-+      files in initramfs may be inaccessible.
-+      Unless you are going to use ramfs as an aufs branch fs without
-+      switch_root or something, leave it N.
++# defined in ${srctree}/fs/fuse/inode.c
++# tristate
++ifdef CONFIG_FUSE_FS
++ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
++endif
 +
-+config AUFS_BR_FUSE
-+      bool "Fuse fs as an aufs branch"
-+      depends on FUSE_FS
-+      select AUFS_POLL
-+      help
-+      If you want to use fuse-based userspace filesystem as an aufs
-+      branch fs, then enable this option.
-+      It implements the internal poll(2) operation which is
-+      implemented by fuse only (curretnly).
++# defined in ${srctree}/fs/xfs/xfs_sb.h
++# tristate
++ifdef CONFIG_XFS_FS
++ccflags-y += -DXFS_SB_MAGIC=0x58465342
++endif
 +
-+config AUFS_POLL
-+      bool
-+      help
-+      Automatic configuration for internal use.
++# defined in ${srctree}/fs/configfs/mount.c
++# tristate
++ifdef CONFIG_CONFIGFS_FS
++ccflags-y += -DCONFIGFS_MAGIC=0x62656570
++endif
 +
-+config AUFS_BR_HFSPLUS
-+      bool "Hfsplus as an aufs branch"
-+      depends on HFSPLUS_FS
-+      default y
-+      help
-+      If you want to use hfsplus fs as an aufs branch fs, then enable
-+      this option. This option introduces a small overhead at
-+      copying-up a file on hfsplus.
++# defined in ${srctree}/fs/ubifs/ubifs.h
++# tristate
++ifdef CONFIG_UBIFS_FS
++ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
++endif
 +
-+config AUFS_BDEV_LOOP
-+      bool
-+      depends on BLK_DEV_LOOP
-+      default y
-+      help
-+      Automatic configuration for internal use.
-+      Convert =[ym] into =y.
++# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
++# tristate
++ifdef CONFIG_HFSPLUS_FS
++ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
++endif
+diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
+--- /usr/share/empty/fs/aufs/Makefile  1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/Makefile     2015-06-22 08:27:37.874168290 +0200
+@@ -0,0 +1,44 @@
 +
-+config AUFS_DEBUG
-+      bool "Debug aufs"
-+      help
-+      Enable this to compile aufs internal debug code.
-+      It will have a negative impact to the performance.
++include ${src}/magic.mk
++ifeq (${CONFIG_AUFS_FS},m)
++include ${src}/conf.mk
++endif
++-include ${src}/priv_def.mk
 +
-+config AUFS_MAGIC_SYSRQ
-+      bool
-+      depends on AUFS_DEBUG && MAGIC_SYSRQ
-+      default y
-+      help
-+      Automatic configuration for internal use.
-+      When aufs supports Magic SysRq, enabled automatically.
++# cf. include/linux/kernel.h
++# enable pr_debug
++ccflags-y += -DDEBUG
++# sparse requires the full pathname
++ifdef M
++ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
++else
++ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
 +endif
-diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
---- /usr/share/empty/fs/aufs/loop.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/loop.c       2013-03-14 20:07:18.764260309 +0100
-@@ -0,0 +1,135 @@
++
++obj-$(CONFIG_AUFS_FS) += aufs.o
++aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
++      wkq.o vfsub.o dcsub.o \
++      cpup.o whout.o wbr_policy.o \
++      dinfo.o dentry.o \
++      dynop.o \
++      finfo.o file.o f_op.o \
++      dir.o vdir.o \
++      iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
++      mvdown.o ioctl.o
++
++# all are boolean
++aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
++aufs-$(CONFIG_SYSFS) += sysfs.o
++aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
++aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
++aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
++aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
++aufs-$(CONFIG_AUFS_EXPORT) += export.o
++aufs-$(CONFIG_AUFS_XATTR) += xattr.o
++aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
++aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
++aufs-$(CONFIG_AUFS_POLL) += poll.o
++aufs-$(CONFIG_AUFS_RDU) += rdu.o
++aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
++aufs-$(CONFIG_AUFS_DEBUG) += debug.o
++aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
+diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
+--- /usr/share/empty/fs/aufs/module.c  1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/module.c     2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,210 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -18658,133 +21546,208 @@ diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
-+ * support for loopback block device as a branch
++ * module global variables and operations
 + */
 +
-+#include <linux/loop.h>
++#include <linux/module.h>
++#include <linux/seq_file.h>
 +#include "aufs.h"
 +
++void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
++{
++      if (new_sz <= nused)
++              return p;
++
++      p = krealloc(p, new_sz, gfp);
++      if (p)
++              memset(p + nused, 0, new_sz - nused);
++      return p;
++}
++
++/* ---------------------------------------------------------------------- */
++
 +/*
-+ * test if two lower dentries have overlapping branches.
++ * aufs caches
 + */
-+int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
++struct kmem_cache *au_cachep[AuCache_Last];
++static int __init au_cache_init(void)
 +{
-+      struct super_block *h_sb;
-+      struct loop_device *l;
-+
-+      h_sb = h_adding->d_sb;
-+      if (MAJOR(h_sb->s_dev) != LOOP_MAJOR)
++      au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
++      if (au_cachep[AuCache_DINFO])
++              /* SLAB_DESTROY_BY_RCU */
++              au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
++                                                      au_icntnr_init_once);
++      if (au_cachep[AuCache_ICNTNR])
++              au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
++                                                     au_fi_init_once);
++      if (au_cachep[AuCache_FINFO])
++              au_cachep[AuCache_VDIR] = AuCache(au_vdir);
++      if (au_cachep[AuCache_VDIR])
++              au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
++      if (au_cachep[AuCache_DEHSTR])
 +              return 0;
 +
-+      l = h_sb->s_bdev->bd_disk->private_data;
-+      h_adding = l->lo_backing_file->f_dentry;
-+      /*
-+       * h_adding can be local NFS.
-+       * in this case aufs cannot detect the loop.
-+       */
-+      if (unlikely(h_adding->d_sb == sb))
-+              return 1;
-+      return !!au_test_subdir(h_adding, sb->s_root);
++      return -ENOMEM;
 +}
 +
-+/* true if a kernel thread named 'loop[0-9].*' accesses a file */
-+int au_test_loopback_kthread(void)
++static void au_cache_fin(void)
 +{
-+      int ret;
-+      struct task_struct *tsk = current;
-+      char c, comm[sizeof(tsk->comm)];
++      int i;
 +
-+      ret = 0;
-+      if (tsk->flags & PF_KTHREAD) {
-+              get_task_comm(comm, tsk);
-+              c = comm[4];
-+              ret = ('0' <= c && c <= '9'
-+                     && !strncmp(comm, "loop", 4));
-+      }
++      /*
++       * Make sure all delayed rcu free inodes are flushed before we
++       * destroy cache.
++       */
++      rcu_barrier();
 +
-+      return ret;
++      /* excluding AuCache_HNOTIFY */
++      BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
++      for (i = 0; i < AuCache_HNOTIFY; i++)
++              if (au_cachep[i]) {
++                      kmem_cache_destroy(au_cachep[i]);
++                      au_cachep[i] = NULL;
++              }
 +}
 +
 +/* ---------------------------------------------------------------------- */
 +
-+#define au_warn_loopback_step 16
-+static int au_warn_loopback_nelem = au_warn_loopback_step;
-+static unsigned long *au_warn_loopback_array;
++int au_dir_roflags;
 +
-+void au_warn_loopback(struct super_block *h_sb)
-+{
-+      int i, new_nelem;
-+      unsigned long *a, magic;
-+      static DEFINE_SPINLOCK(spin);
++#ifdef CONFIG_AUFS_SBILIST
++/*
++ * iterate_supers_type() doesn't protect us from
++ * remounting (branch management)
++ */
++struct au_splhead au_sbilist;
++#endif
++
++struct lock_class_key au_lc_key[AuLcKey_Last];
++
++/*
++ * functions for module interface.
++ */
++MODULE_LICENSE("GPL");
++/* MODULE_LICENSE("GPL v2"); */
++MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
++MODULE_DESCRIPTION(AUFS_NAME
++      " -- Advanced multi layered unification filesystem");
++MODULE_VERSION(AUFS_VERSION);
++MODULE_ALIAS_FS(AUFS_NAME);
 +
-+      magic = h_sb->s_magic;
-+      spin_lock(&spin);
-+      a = au_warn_loopback_array;
-+      for (i = 0; i < au_warn_loopback_nelem && *a; i++)
-+              if (a[i] == magic) {
-+                      spin_unlock(&spin);
-+                      return;
-+              }
++/* this module parameter has no meaning when SYSFS is disabled */
++int sysaufs_brs = 1;
++MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
++module_param_named(brs, sysaufs_brs, int, S_IRUGO);
 +
-+      /* h_sb is new to us, print it */
-+      if (i < au_warn_loopback_nelem) {
-+              a[i] = magic;
-+              goto pr;
-+      }
++/* this module parameter has no meaning when USER_NS is disabled */
++static bool au_userns;
++MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
++module_param_named(allow_userns, au_userns, bool, S_IRUGO);
 +
-+      /* expand the array */
-+      new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
-+      a = au_kzrealloc(au_warn_loopback_array,
-+                       au_warn_loopback_nelem * sizeof(unsigned long),
-+                       new_nelem * sizeof(unsigned long), GFP_ATOMIC);
-+      if (a) {
-+              au_warn_loopback_nelem = new_nelem;
-+              au_warn_loopback_array = a;
-+              a[i] = magic;
-+              goto pr;
-+      }
++/* ---------------------------------------------------------------------- */
 +
-+      spin_unlock(&spin);
-+      AuWarn1("realloc failed, ignored\n");
-+      return;
++static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
 +
-+pr:
-+      spin_unlock(&spin);
-+      pr_warn("you may want to try another patch for loopback file "
-+              "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
++int au_seq_path(struct seq_file *seq, struct path *path)
++{
++      return seq_path(seq, path, au_esc_chars);
 +}
 +
-+int au_loopback_init(void)
++/* ---------------------------------------------------------------------- */
++
++static int __init aufs_init(void)
 +{
-+      int err;
-+      struct super_block *sb __maybe_unused;
++      int err, i;
++      char *p;
 +
-+      AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
++      p = au_esc_chars;
++      for (i = 1; i <= ' '; i++)
++              *p++ = i;
++      *p++ = '\\';
++      *p++ = '\x7f';
++      *p = 0;
 +
-+      err = 0;
-+      au_warn_loopback_array = kcalloc(au_warn_loopback_step,
-+                                       sizeof(unsigned long), GFP_NOFS);
-+      if (unlikely(!au_warn_loopback_array))
-+              err = -ENOMEM;
++      au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
++
++      au_sbilist_init();
++      sysaufs_brs_init();
++      au_debug_init();
++      au_dy_init();
++      err = sysaufs_init();
++      if (unlikely(err))
++              goto out;
++      err = au_procfs_init();
++      if (unlikely(err))
++              goto out_sysaufs;
++      err = au_wkq_init();
++      if (unlikely(err))
++              goto out_procfs;
++      err = au_loopback_init();
++      if (unlikely(err))
++              goto out_wkq;
++      err = au_hnotify_init();
++      if (unlikely(err))
++              goto out_loopback;
++      err = au_sysrq_init();
++      if (unlikely(err))
++              goto out_hin;
++      err = au_cache_init();
++      if (unlikely(err))
++              goto out_sysrq;
++
++      aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
++      err = register_filesystem(&aufs_fs_type);
++      if (unlikely(err))
++              goto out_cache;
++
++      /* since we define pr_fmt, call printk directly */
++      printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
++      goto out; /* success */
 +
++out_cache:
++      au_cache_fin();
++out_sysrq:
++      au_sysrq_fin();
++out_hin:
++      au_hnotify_fin();
++out_loopback:
++      au_loopback_fin();
++out_wkq:
++      au_wkq_fin();
++out_procfs:
++      au_procfs_fin();
++out_sysaufs:
++      sysaufs_fin();
++      au_dy_fin();
++out:
 +      return err;
 +}
 +
-+void au_loopback_fin(void)
++static void __exit aufs_exit(void)
 +{
-+      kfree(au_warn_loopback_array);
++      unregister_filesystem(&aufs_fs_type);
++      au_cache_fin();
++      au_sysrq_fin();
++      au_hnotify_fin();
++      au_loopback_fin();
++      au_wkq_fin();
++      au_procfs_fin();
++      sysaufs_fin();
++      au_dy_fin();
 +}
-diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
---- /usr/share/empty/fs/aufs/loop.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/loop.h       2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,50 @@
++
++module_init(aufs_init);
++module_exit(aufs_exit);
+diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
+--- /usr/share/empty/fs/aufs/module.h  1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/module.h     2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,104 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -18797,152 +21760,102 @@ diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
-+ * support for loopback mount as a branch
++ * module initialization and module-global
 + */
 +
-+#ifndef __AUFS_LOOP_H__
-+#define __AUFS_LOOP_H__
++#ifndef __AUFS_MODULE_H__
++#define __AUFS_MODULE_H__
 +
 +#ifdef __KERNEL__
 +
-+struct dentry;
-+struct super_block;
-+
-+#ifdef CONFIG_AUFS_BDEV_LOOP
-+/* loop.c */
-+int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
-+int au_test_loopback_kthread(void);
-+void au_warn_loopback(struct super_block *h_sb);
++#include <linux/slab.h>
 +
-+int au_loopback_init(void);
-+void au_loopback_fin(void);
-+#else
-+AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
-+         struct dentry *h_adding)
-+AuStubInt0(au_test_loopback_kthread, void)
-+AuStubVoid(au_warn_loopback, struct super_block *h_sb)
++struct path;
++struct seq_file;
 +
-+AuStubInt0(au_loopback_init, void)
-+AuStubVoid(au_loopback_fin, void)
-+#endif /* BLK_DEV_LOOP */
++/* module parameters */
++extern int sysaufs_brs;
 +
-+#endif /* __KERNEL__ */
-+#endif /* __AUFS_LOOP_H__ */
-diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
---- /usr/share/empty/fs/aufs/magic.mk  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/magic.mk     2012-08-26 08:39:00.760508065 +0200
-@@ -0,0 +1,54 @@
++/* ---------------------------------------------------------------------- */
 +
-+# defined in ${srctree}/fs/fuse/inode.c
-+# tristate
-+ifdef CONFIG_FUSE_FS
-+ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
-+endif
++extern int au_dir_roflags;
 +
-+# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
-+# tristate
-+ifdef CONFIG_OCFS2_FS
-+ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
-+endif
++enum {
++      AuLcNonDir_FIINFO,
++      AuLcNonDir_DIINFO,
++      AuLcNonDir_IIINFO,
 +
-+# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
-+# tristate
-+ifdef CONFIG_OCFS2_FS_O2CB
-+ccflags-y += -DDLMFS_MAGIC=0x76a9f425
-+endif
++      AuLcDir_FIINFO,
++      AuLcDir_DIINFO,
++      AuLcDir_IIINFO,
 +
-+# defined in ${srctree}/fs/cifs/cifsfs.c
-+# tristate
-+ifdef CONFIG_CIFS_FS
-+ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
-+endif
++      AuLcSymlink_DIINFO,
++      AuLcSymlink_IIINFO,
 +
-+# defined in ${srctree}/fs/xfs/xfs_sb.h
-+# tristate
-+ifdef CONFIG_XFS_FS
-+ccflags-y += -DXFS_SB_MAGIC=0x58465342
-+endif
++      AuLcKey_Last
++};
++extern struct lock_class_key au_lc_key[AuLcKey_Last];
 +
-+# defined in ${srctree}/fs/configfs/mount.c
-+# tristate
-+ifdef CONFIG_CONFIGFS_FS
-+ccflags-y += -DCONFIGFS_MAGIC=0x62656570
-+endif
++void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
++int au_seq_path(struct seq_file *seq, struct path *path);
 +
-+# defined in ${srctree}/fs/9p/v9fs.h
-+# tristate
-+ifdef CONFIG_9P_FS
-+ccflags-y += -DV9FS_MAGIC=0x01021997
-+endif
++#ifdef CONFIG_PROC_FS
++/* procfs.c */
++int __init au_procfs_init(void);
++void au_procfs_fin(void);
++#else
++AuStubInt0(au_procfs_init, void);
++AuStubVoid(au_procfs_fin, void);
++#endif
 +
-+# defined in ${srctree}/fs/ubifs/ubifs.h
-+# tristate
-+ifdef CONFIG_UBIFS_FS
-+ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
-+endif
++/* ---------------------------------------------------------------------- */
 +
-+# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
-+# tristate
-+ifdef CONFIG_HFSPLUS_FS
-+ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
-+endif
-diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
---- /usr/share/empty/fs/aufs/Makefile  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/Makefile     2012-08-26 08:39:00.757174634 +0200
-@@ -0,0 +1,42 @@
++/* kmem cache */
++enum {
++      AuCache_DINFO,
++      AuCache_ICNTNR,
++      AuCache_FINFO,
++      AuCache_VDIR,
++      AuCache_DEHSTR,
++      AuCache_HNOTIFY, /* must be last */
++      AuCache_Last
++};
 +
-+include ${src}/magic.mk
-+ifeq (${CONFIG_AUFS_FS},m)
-+include ${src}/conf.mk
-+endif
-+-include ${src}/priv_def.mk
++#define AuCacheFlags          (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
++#define AuCache(type)         KMEM_CACHE(type, AuCacheFlags)
++#define AuCacheCtor(type, ctor)       \
++      kmem_cache_create(#type, sizeof(struct type), \
++                        __alignof__(struct type), AuCacheFlags, ctor)
 +
-+# cf. include/linux/kernel.h
-+# enable pr_debug
-+ccflags-y += -DDEBUG
-+# sparse requires the full pathname
-+ifdef M
-+ccflags-y += -include ${M}/../../include/linux/aufs_type.h
-+else
-+ccflags-y += -include ${srctree}/include/linux/aufs_type.h
-+endif
++extern struct kmem_cache *au_cachep[];
 +
-+obj-$(CONFIG_AUFS_FS) += aufs.o
-+aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
-+      wkq.o vfsub.o dcsub.o \
-+      cpup.o whout.o wbr_policy.o \
-+      dinfo.o dentry.o \
-+      dynop.o \
-+      finfo.o file.o f_op.o \
-+      dir.o vdir.o \
-+      iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
-+      ioctl.o
++#define AuCacheFuncs(name, index) \
++static inline struct au_##name *au_cache_alloc_##name(void) \
++{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
++static inline void au_cache_free_##name(struct au_##name *p) \
++{ kmem_cache_free(au_cachep[AuCache_##index], p); }
 +
-+# all are boolean
-+aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
-+aufs-$(CONFIG_SYSFS) += sysfs.o
-+aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
-+aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
-+aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
-+aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
-+aufs-$(CONFIG_AUFS_EXPORT) += export.o
-+aufs-$(CONFIG_AUFS_POLL) += poll.o
-+aufs-$(CONFIG_AUFS_RDU) += rdu.o
-+aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
-+aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
-+aufs-$(CONFIG_AUFS_DEBUG) += debug.o
-+aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
-diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
---- /usr/share/empty/fs/aufs/module.c  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/module.c     2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,202 @@
++AuCacheFuncs(dinfo, DINFO);
++AuCacheFuncs(icntnr, ICNTNR);
++AuCacheFuncs(finfo, FINFO);
++AuCacheFuncs(vdir, VDIR);
++AuCacheFuncs(vdir_dehstr, DEHSTR);
++#ifdef CONFIG_AUFS_HNOTIFY
++AuCacheFuncs(hnotify, HNOTIFY);
++#endif
++
++#endif /* __KERNEL__ */
++#endif /* __AUFS_MODULE_H__ */
+diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
+--- /usr/share/empty/fs/aufs/mvdown.c  1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/mvdown.c     2015-06-22 08:27:37.884168534 +0200
+@@ -0,0 +1,694 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2011-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -18955,309 +21868,692 @@ diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
-+ * module global variables and operations
++ * move-down, opposite of copy-up
 + */
 +
-+#include <linux/module.h>
-+#include <linux/seq_file.h>
 +#include "aufs.h"
 +
-+void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
++struct au_mvd_args {
++      struct {
++              struct super_block *h_sb;
++              struct dentry *h_parent;
++              struct au_hinode *hdir;
++              struct inode *h_dir, *h_inode;
++              struct au_pin pin;
++      } info[AUFS_MVDOWN_NARRAY];
++
++      struct aufs_mvdown mvdown;
++      struct dentry *dentry, *parent;
++      struct inode *inode, *dir;
++      struct super_block *sb;
++      aufs_bindex_t bopq, bwh, bfound;
++      unsigned char rename_lock;
++};
++
++#define mvd_errno             mvdown.au_errno
++#define mvd_bsrc              mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
++#define mvd_src_brid          mvdown.stbr[AUFS_MVDOWN_UPPER].brid
++#define mvd_bdst              mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
++#define mvd_dst_brid          mvdown.stbr[AUFS_MVDOWN_LOWER].brid
++
++#define mvd_h_src_sb          info[AUFS_MVDOWN_UPPER].h_sb
++#define mvd_h_src_parent      info[AUFS_MVDOWN_UPPER].h_parent
++#define mvd_hdir_src          info[AUFS_MVDOWN_UPPER].hdir
++#define mvd_h_src_dir         info[AUFS_MVDOWN_UPPER].h_dir
++#define mvd_h_src_inode               info[AUFS_MVDOWN_UPPER].h_inode
++#define mvd_pin_src           info[AUFS_MVDOWN_UPPER].pin
++
++#define mvd_h_dst_sb          info[AUFS_MVDOWN_LOWER].h_sb
++#define mvd_h_dst_parent      info[AUFS_MVDOWN_LOWER].h_parent
++#define mvd_hdir_dst          info[AUFS_MVDOWN_LOWER].hdir
++#define mvd_h_dst_dir         info[AUFS_MVDOWN_LOWER].h_dir
++#define mvd_h_dst_inode               info[AUFS_MVDOWN_LOWER].h_inode
++#define mvd_pin_dst           info[AUFS_MVDOWN_LOWER].pin
++
++#define AU_MVD_PR(flag, ...) do {                     \
++              if (flag)                               \
++                      pr_err(__VA_ARGS__);            \
++      } while (0)
++
++static int find_lower_writable(struct au_mvd_args *a)
 +{
-+      if (new_sz <= nused)
-+              return p;
++      struct super_block *sb;
++      aufs_bindex_t bindex, bend;
++      struct au_branch *br;
 +
-+      p = krealloc(p, new_sz, gfp);
-+      if (p)
-+              memset(p + nused, 0, new_sz - nused);
-+      return p;
-+}
++      sb = a->sb;
++      bindex = a->mvd_bsrc;
++      bend = au_sbend(sb);
++      if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
++              for (bindex++; bindex <= bend; bindex++) {
++                      br = au_sbr(sb, bindex);
++                      if (au_br_fhsm(br->br_perm)
++                          && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
++                              return bindex;
++              }
++      else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
++              for (bindex++; bindex <= bend; bindex++) {
++                      br = au_sbr(sb, bindex);
++                      if (!au_br_rdonly(br))
++                              return bindex;
++              }
++      else
++              for (bindex++; bindex <= bend; bindex++) {
++                      br = au_sbr(sb, bindex);
++                      if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
++                              if (au_br_rdonly(br))
++                                      a->mvdown.flags
++                                              |= AUFS_MVDOWN_ROLOWER_R;
++                              return bindex;
++                      }
++              }
 +
-+/* ---------------------------------------------------------------------- */
++      return -1;
++}
 +
-+/*
-+ * aufs caches
-+ */
-+struct kmem_cache *au_cachep[AuCache_Last];
-+static int __init au_cache_init(void)
++/* make the parent dir on bdst */
++static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
 +{
-+      au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
-+      if (au_cachep[AuCache_DINFO])
-+              /* SLAB_DESTROY_BY_RCU */
-+              au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
-+                                                      au_icntnr_init_once);
-+      if (au_cachep[AuCache_ICNTNR])
-+              au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
-+                                                     au_fi_init_once);
-+      if (au_cachep[AuCache_FINFO])
-+              au_cachep[AuCache_VDIR] = AuCache(au_vdir);
-+      if (au_cachep[AuCache_VDIR])
-+              au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
-+      if (au_cachep[AuCache_DEHSTR])
-+              return 0;
++      int err;
 +
-+      return -ENOMEM;
++      err = 0;
++      a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
++      a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
++      a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
++      a->mvd_h_dst_parent = NULL;
++      if (au_dbend(a->parent) >= a->mvd_bdst)
++              a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
++      if (!a->mvd_h_dst_parent) {
++              err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
++              if (unlikely(err)) {
++                      AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
++                      goto out;
++              }
++              a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
++      }
++
++out:
++      AuTraceErr(err);
++      return err;
 +}
 +
-+static void au_cache_fin(void)
++/* lock them all */
++static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
 +{
-+      int i;
++      int err;
++      struct dentry *h_trap;
 +
-+      /*
-+       * Make sure all delayed rcu free inodes are flushed before we
-+       * destroy cache.
-+       */
-+      rcu_barrier();
++      a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
++      a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
++      err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
++                   au_opt_udba(a->sb),
++                   AuPin_MNT_WRITE | AuPin_DI_LOCKED);
++      AuTraceErr(err);
++      if (unlikely(err)) {
++              AU_MVD_PR(dmsg, "pin_dst failed\n");
++              goto out;
++      }
 +
-+      /* excluding AuCache_HNOTIFY */
-+      BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
-+      for (i = 0; i < AuCache_HNOTIFY; i++)
-+              if (au_cachep[i]) {
-+                      kmem_cache_destroy(au_cachep[i]);
-+                      au_cachep[i] = NULL;
++      if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
++              a->rename_lock = 0;
++              au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
++                          AuLsc_DI_PARENT, AuLsc_I_PARENT3,
++                          au_opt_udba(a->sb),
++                          AuPin_MNT_WRITE | AuPin_DI_LOCKED);
++              err = au_do_pin(&a->mvd_pin_src);
++              AuTraceErr(err);
++              a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
++              if (unlikely(err)) {
++                      AU_MVD_PR(dmsg, "pin_src failed\n");
++                      goto out_dst;
 +              }
++              goto out; /* success */
++      }
++
++      a->rename_lock = 1;
++      au_pin_hdir_unlock(&a->mvd_pin_dst);
++      err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
++                   au_opt_udba(a->sb),
++                   AuPin_MNT_WRITE | AuPin_DI_LOCKED);
++      AuTraceErr(err);
++      a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
++      if (unlikely(err)) {
++              AU_MVD_PR(dmsg, "pin_src failed\n");
++              au_pin_hdir_lock(&a->mvd_pin_dst);
++              goto out_dst;
++      }
++      au_pin_hdir_unlock(&a->mvd_pin_src);
++      h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
++                                 a->mvd_h_dst_parent, a->mvd_hdir_dst);
++      if (h_trap) {
++              err = (h_trap != a->mvd_h_src_parent);
++              if (err)
++                      err = (h_trap != a->mvd_h_dst_parent);
++      }
++      BUG_ON(err); /* it should never happen */
++      if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
++              err = -EBUSY;
++              AuTraceErr(err);
++              vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
++                                  a->mvd_h_dst_parent, a->mvd_hdir_dst);
++              au_pin_hdir_lock(&a->mvd_pin_src);
++              au_unpin(&a->mvd_pin_src);
++              au_pin_hdir_lock(&a->mvd_pin_dst);
++              goto out_dst;
++      }
++      goto out; /* success */
++
++out_dst:
++      au_unpin(&a->mvd_pin_dst);
++out:
++      AuTraceErr(err);
++      return err;
 +}
 +
-+/* ---------------------------------------------------------------------- */
++static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      if (!a->rename_lock)
++              au_unpin(&a->mvd_pin_src);
++      else {
++              vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
++                                  a->mvd_h_dst_parent, a->mvd_hdir_dst);
++              au_pin_hdir_lock(&a->mvd_pin_src);
++              au_unpin(&a->mvd_pin_src);
++              au_pin_hdir_lock(&a->mvd_pin_dst);
++      }
++      au_unpin(&a->mvd_pin_dst);
++}
 +
-+int au_dir_roflags;
++/* copy-down the file */
++static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      int err;
++      struct au_cp_generic cpg = {
++              .dentry = a->dentry,
++              .bdst   = a->mvd_bdst,
++              .bsrc   = a->mvd_bsrc,
++              .len    = -1,
++              .pin    = &a->mvd_pin_dst,
++              .flags  = AuCpup_DTIME | AuCpup_HOPEN
++      };
++
++      AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
++      if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
++              au_fset_cpup(cpg.flags, OVERWRITE);
++      if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
++              au_fset_cpup(cpg.flags, RWDST);
++      err = au_sio_cpdown_simple(&cpg);
++      if (unlikely(err))
++              AU_MVD_PR(dmsg, "cpdown failed\n");
++
++      AuTraceErr(err);
++      return err;
++}
 +
-+#ifdef CONFIG_AUFS_SBILIST
 +/*
-+ * iterate_supers_type() doesn't protect us from
-+ * remounting (branch management)
++ * unlink the whiteout on bdst if exist which may be created by UDBA while we
++ * were sleeping
 + */
-+struct au_splhead au_sbilist;
-+#endif
++static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      int err;
++      struct path h_path;
++      struct au_branch *br;
++      struct inode *delegated;
 +
-+struct lock_class_key au_lc_key[AuLcKey_Last];
++      br = au_sbr(a->sb, a->mvd_bdst);
++      h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
++      err = PTR_ERR(h_path.dentry);
++      if (IS_ERR(h_path.dentry)) {
++              AU_MVD_PR(dmsg, "wh_lkup failed\n");
++              goto out;
++      }
++
++      err = 0;
++      if (h_path.dentry->d_inode) {
++              h_path.mnt = au_br_mnt(br);
++              delegated = NULL;
++              err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
++                                 &delegated, /*force*/0);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal unlink\n");
++                      iput(delegated);
++              }
++              if (unlikely(err))
++                      AU_MVD_PR(dmsg, "wh_unlink failed\n");
++      }
++      dput(h_path.dentry);
++
++out:
++      AuTraceErr(err);
++      return err;
++}
 +
 +/*
-+ * functions for module interface.
++ * unlink the topmost h_dentry
 + */
-+MODULE_LICENSE("GPL");
-+/* MODULE_LICENSE("GPL v2"); */
-+MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
-+MODULE_DESCRIPTION(AUFS_NAME
-+      " -- Advanced multi layered unification filesystem");
-+MODULE_VERSION(AUFS_VERSION);
++static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      int err;
++      struct path h_path;
++      struct inode *delegated;
 +
-+/* this module parameter has no meaning when SYSFS is disabled */
-+int sysaufs_brs = 1;
-+MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
-+module_param_named(brs, sysaufs_brs, int, S_IRUGO);
++      h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
++      h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
++      delegated = NULL;
++      err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
++      if (unlikely(err == -EWOULDBLOCK)) {
++              pr_warn("cannot retry for NFSv4 delegation"
++                      " for an internal unlink\n");
++              iput(delegated);
++      }
++      if (unlikely(err))
++              AU_MVD_PR(dmsg, "unlink failed\n");
 +
-+/* ---------------------------------------------------------------------- */
++      AuTraceErr(err);
++      return err;
++}
 +
-+static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
++/* Since mvdown succeeded, we ignore an error of this function */
++static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      int err;
++      struct au_branch *br;
 +
-+int au_seq_path(struct seq_file *seq, struct path *path)
++      a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
++      br = au_sbr(a->sb, a->mvd_bsrc);
++      err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
++      if (!err) {
++              br = au_sbr(a->sb, a->mvd_bdst);
++              a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
++              err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
++      }
++      if (!err)
++              a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
++      else
++              AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
++}
++
++/*
++ * copy-down the file and unlink the bsrc file.
++ * - unlink the bdst whout if exist
++ * - copy-down the file (with whtmp name and rename)
++ * - unlink the bsrc file
++ */
++static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
 +{
-+      return seq_path(seq, path, au_esc_chars);
++      int err;
++
++      err = au_do_mkdir(dmsg, a);
++      if (!err)
++              err = au_do_lock(dmsg, a);
++      if (unlikely(err))
++              goto out;
++
++      /*
++       * do not revert the activities we made on bdst since they should be
++       * harmless in aufs.
++       */
++
++      err = au_do_cpdown(dmsg, a);
++      if (!err)
++              err = au_do_unlink_wh(dmsg, a);
++      if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
++              err = au_do_unlink(dmsg, a);
++      if (unlikely(err))
++              goto out_unlock;
++
++      AuDbg("%pd2, 0x%x, %d --> %d\n",
++            a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
++      if (find_lower_writable(a) < 0)
++              a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
++
++      if (a->mvdown.flags & AUFS_MVDOWN_STFS)
++              au_do_stfs(dmsg, a);
++
++      /* maintain internal array */
++      if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
++              au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
++              au_set_dbstart(a->dentry, a->mvd_bdst);
++              au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
++              au_set_ibstart(a->inode, a->mvd_bdst);
++      }
++      if (au_dbend(a->dentry) < a->mvd_bdst)
++              au_set_dbend(a->dentry, a->mvd_bdst);
++      if (au_ibend(a->inode) < a->mvd_bdst)
++              au_set_ibend(a->inode, a->mvd_bdst);
++
++out_unlock:
++      au_do_unlock(dmsg, a);
++out:
++      AuTraceErr(err);
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++/* make sure the file is idle */
++static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      int err, plinked;
++
++      err = 0;
++      plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
++      if (au_dbstart(a->dentry) == a->mvd_bsrc
++          && au_dcount(a->dentry) == 1
++          && atomic_read(&a->inode->i_count) == 1
++          /* && a->mvd_h_src_inode->i_nlink == 1 */
++          && (!plinked || !au_plink_test(a->inode))
++          && a->inode->i_nlink == 1)
++              goto out;
++
++      err = -EBUSY;
++      AU_MVD_PR(dmsg,
++                "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
++                a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
++                atomic_read(&a->inode->i_count), a->inode->i_nlink,
++                a->mvd_h_src_inode->i_nlink,
++                plinked, plinked ? au_plink_test(a->inode) : 0);
++
++out:
++      AuTraceErr(err);
++      return err;
 +}
 +
-+/* ---------------------------------------------------------------------- */
-+
-+static int __init aufs_init(void)
++/* make sure the parent dir is fine */
++static int au_mvd_args_parent(const unsigned char dmsg,
++                            struct au_mvd_args *a)
 +{
-+      int err, i;
-+      char *p;
-+
-+      p = au_esc_chars;
-+      for (i = 1; i <= ' '; i++)
-+              *p++ = i;
-+      *p++ = '\\';
-+      *p++ = '\x7f';
-+      *p = 0;
-+
-+      au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
++      int err;
++      aufs_bindex_t bindex;
 +
-+      au_sbilist_init();
-+      sysaufs_brs_init();
-+      au_debug_init();
-+      au_dy_init();
-+      err = sysaufs_init();
-+      if (unlikely(err))
++      err = 0;
++      if (unlikely(au_alive_dir(a->parent))) {
++              err = -ENOENT;
++              AU_MVD_PR(dmsg, "parent dir is dead\n");
 +              goto out;
-+      err = au_procfs_init();
-+      if (unlikely(err))
-+              goto out_sysaufs;
-+      err = au_wkq_init();
-+      if (unlikely(err))
-+              goto out_procfs;
-+      err = au_loopback_init();
-+      if (unlikely(err))
-+              goto out_wkq;
-+      err = au_hnotify_init();
-+      if (unlikely(err))
-+              goto out_loopback;
-+      err = au_sysrq_init();
-+      if (unlikely(err))
-+              goto out_hin;
-+      err = au_cache_init();
-+      if (unlikely(err))
-+              goto out_sysrq;
-+      err = register_filesystem(&aufs_fs_type);
-+      if (unlikely(err))
-+              goto out_cache;
-+      /* since we define pr_fmt, call printk directly */
-+      printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
-+      goto out; /* success */
++      }
++
++      a->bopq = au_dbdiropq(a->parent);
++      bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
++      AuDbg("b%d\n", bindex);
++      if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
++                   || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
++              err = -EINVAL;
++              a->mvd_errno = EAU_MVDOWN_OPAQUE;
++              AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
++                        a->bopq, a->mvd_bdst);
++      }
 +
-+out_cache:
-+      au_cache_fin();
-+out_sysrq:
-+      au_sysrq_fin();
-+out_hin:
-+      au_hnotify_fin();
-+out_loopback:
-+      au_loopback_fin();
-+out_wkq:
-+      au_wkq_fin();
-+out_procfs:
-+      au_procfs_fin();
-+out_sysaufs:
-+      sysaufs_fin();
-+      au_dy_fin();
 +out:
++      AuTraceErr(err);
 +      return err;
 +}
 +
-+static void __exit aufs_exit(void)
++static int au_mvd_args_intermediate(const unsigned char dmsg,
++                                  struct au_mvd_args *a)
 +{
-+      unregister_filesystem(&aufs_fs_type);
-+      au_cache_fin();
-+      au_sysrq_fin();
-+      au_hnotify_fin();
-+      au_loopback_fin();
-+      au_wkq_fin();
-+      au_procfs_fin();
-+      sysaufs_fin();
-+      au_dy_fin();
-+}
++      int err;
++      struct au_dinfo *dinfo, *tmp;
 +
-+module_init(aufs_init);
-+module_exit(aufs_exit);
-diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
---- /usr/share/empty/fs/aufs/module.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/module.h     2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,105 @@
-+/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
-+ *
-+ * This program, aufs is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-+ */
++      /* lookup the next lower positive entry */
++      err = -ENOMEM;
++      tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
++      if (unlikely(!tmp))
++              goto out;
 +
-+/*
-+ * module initialization and module-global
-+ */
++      a->bfound = -1;
++      a->bwh = -1;
++      dinfo = au_di(a->dentry);
++      au_di_cp(tmp, dinfo);
++      au_di_swap(tmp, dinfo);
 +
-+#ifndef __AUFS_MODULE_H__
-+#define __AUFS_MODULE_H__
++      /* returns the number of positive dentries */
++      err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
++      if (!err)
++              a->bwh = au_dbwh(a->dentry);
++      else if (err > 0)
++              a->bfound = au_dbstart(a->dentry);
 +
-+#ifdef __KERNEL__
++      au_di_swap(tmp, dinfo);
++      au_rw_write_unlock(&tmp->di_rwsem);
++      au_di_free(tmp);
++      if (unlikely(err < 0))
++              AU_MVD_PR(dmsg, "failed look-up lower\n");
 +
-+#include <linux/slab.h>
++      /*
++       * here, we have these cases.
++       * bfound == -1
++       *      no positive dentry under bsrc. there are more sub-cases.
++       *      bwh < 0
++       *              there no whiteout, we can safely move-down.
++       *      bwh <= bsrc
++       *              impossible
++       *      bsrc < bwh && bwh < bdst
++       *              there is a whiteout on RO branch. cannot proceed.
++       *      bwh == bdst
++       *              there is a whiteout on the RW target branch. it should
++       *              be removed.
++       *      bdst < bwh
++       *              there is a whiteout somewhere unrelated branch.
++       * -1 < bfound && bfound <= bsrc
++       *      impossible.
++       * bfound < bdst
++       *      found, but it is on RO branch between bsrc and bdst. cannot
++       *      proceed.
++       * bfound == bdst
++       *      found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
++       *      error.
++       * bdst < bfound
++       *      found, after we create the file on bdst, it will be hidden.
++       */
 +
-+struct path;
-+struct seq_file;
++      AuDebugOn(a->bfound == -1
++                && a->bwh != -1
++                && a->bwh <= a->mvd_bsrc);
++      AuDebugOn(-1 < a->bfound
++                && a->bfound <= a->mvd_bsrc);
 +
-+/* module parameters */
-+extern int sysaufs_brs;
++      err = -EINVAL;
++      if (a->bfound == -1
++          && a->mvd_bsrc < a->bwh
++          && a->bwh != -1
++          && a->bwh < a->mvd_bdst) {
++              a->mvd_errno = EAU_MVDOWN_WHITEOUT;
++              AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
++                        a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
++              goto out;
++      } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
++              a->mvd_errno = EAU_MVDOWN_UPPER;
++              AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
++                        a->mvd_bdst, a->bfound);
++              goto out;
++      }
 +
-+/* ---------------------------------------------------------------------- */
++      err = 0; /* success */
 +
-+extern int au_dir_roflags;
++out:
++      AuTraceErr(err);
++      return err;
++}
 +
-+enum {
-+      AuLcNonDir_FIINFO,
-+      AuLcNonDir_DIINFO,
-+      AuLcNonDir_IIINFO,
++static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      int err;
 +
-+      AuLcDir_FIINFO,
-+      AuLcDir_DIINFO,
-+      AuLcDir_IIINFO,
++      err = 0;
++      if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
++          && a->bfound == a->mvd_bdst)
++              err = -EEXIST;
++      AuTraceErr(err);
++      return err;
++}
 +
-+      AuLcSymlink_DIINFO,
-+      AuLcSymlink_IIINFO,
++static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
++{
++      int err;
++      struct au_branch *br;
 +
-+      AuLcKey_Last
-+};
-+extern struct lock_class_key au_lc_key[AuLcKey_Last];
++      err = -EISDIR;
++      if (unlikely(S_ISDIR(a->inode->i_mode)))
++              goto out;
 +
-+void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
-+int au_seq_path(struct seq_file *seq, struct path *path);
++      err = -EINVAL;
++      if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
++              a->mvd_bsrc = au_ibstart(a->inode);
++      else {
++              a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
++              if (unlikely(a->mvd_bsrc < 0
++                           || (a->mvd_bsrc < au_dbstart(a->dentry)
++                               || au_dbend(a->dentry) < a->mvd_bsrc
++                               || !au_h_dptr(a->dentry, a->mvd_bsrc))
++                           || (a->mvd_bsrc < au_ibstart(a->inode)
++                               || au_ibend(a->inode) < a->mvd_bsrc
++                               || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
++                      a->mvd_errno = EAU_MVDOWN_NOUPPER;
++                      AU_MVD_PR(dmsg, "no upper\n");
++                      goto out;
++              }
++      }
++      if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
++              a->mvd_errno = EAU_MVDOWN_BOTTOM;
++              AU_MVD_PR(dmsg, "on the bottom\n");
++              goto out;
++      }
++      a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
++      br = au_sbr(a->sb, a->mvd_bsrc);
++      err = au_br_rdonly(br);
++      if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
++              if (unlikely(err))
++                      goto out;
++      } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
++                   || IS_APPEND(a->mvd_h_src_inode))) {
++              if (err)
++                      a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
++              /* go on */
++      } else
++              goto out;
 +
-+#ifdef CONFIG_PROC_FS
-+/* procfs.c */
-+int __init au_procfs_init(void);
-+void au_procfs_fin(void);
-+#else
-+AuStubInt0(au_procfs_init, void);
-+AuStubVoid(au_procfs_fin, void);
-+#endif
++      err = -EINVAL;
++      if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
++              a->mvd_bdst = find_lower_writable(a);
++              if (unlikely(a->mvd_bdst < 0)) {
++                      a->mvd_errno = EAU_MVDOWN_BOTTOM;
++                      AU_MVD_PR(dmsg, "no writable lower branch\n");
++                      goto out;
++              }
++      } else {
++              a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
++              if (unlikely(a->mvd_bdst < 0
++                           || au_sbend(a->sb) < a->mvd_bdst)) {
++                      a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
++                      AU_MVD_PR(dmsg, "no lower brid\n");
++                      goto out;
++              }
++      }
 +
-+/* ---------------------------------------------------------------------- */
++      err = au_mvd_args_busy(dmsg, a);
++      if (!err)
++              err = au_mvd_args_parent(dmsg, a);
++      if (!err)
++              err = au_mvd_args_intermediate(dmsg, a);
++      if (!err)
++              err = au_mvd_args_exist(dmsg, a);
++      if (!err)
++              AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
 +
-+/* kmem cache */
-+enum {
-+      AuCache_DINFO,
-+      AuCache_ICNTNR,
-+      AuCache_FINFO,
-+      AuCache_VDIR,
-+      AuCache_DEHSTR,
-+      AuCache_HNOTIFY, /* must be last */
-+      AuCache_Last
-+};
++out:
++      AuTraceErr(err);
++      return err;
++}
 +
-+#define AuCacheFlags          (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
-+#define AuCache(type)         KMEM_CACHE(type, AuCacheFlags)
-+#define AuCacheCtor(type, ctor)       \
-+      kmem_cache_create(#type, sizeof(struct type), \
-+                        __alignof__(struct type), AuCacheFlags, ctor)
++int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
++{
++      int err, e;
++      unsigned char dmsg;
++      struct au_mvd_args *args;
 +
-+extern struct kmem_cache *au_cachep[];
++      err = -EPERM;
++      if (unlikely(!capable(CAP_SYS_ADMIN)))
++              goto out;
 +
-+#define AuCacheFuncs(name, index) \
-+static inline struct au_##name *au_cache_alloc_##name(void) \
-+{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
-+static inline void au_cache_free_##name(struct au_##name *p) \
-+{ kmem_cache_free(au_cachep[AuCache_##index], p); }
++      err = -ENOMEM;
++      args = kmalloc(sizeof(*args), GFP_NOFS);
++      if (unlikely(!args))
++              goto out;
 +
-+AuCacheFuncs(dinfo, DINFO);
-+AuCacheFuncs(icntnr, ICNTNR);
-+AuCacheFuncs(finfo, FINFO);
-+AuCacheFuncs(vdir, VDIR);
-+AuCacheFuncs(vdir_dehstr, DEHSTR);
-+#ifdef CONFIG_AUFS_HNOTIFY
-+AuCacheFuncs(hnotify, HNOTIFY);
-+#endif
++      err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
++      if (!err)
++              err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
++      if (unlikely(err)) {
++              err = -EFAULT;
++              AuTraceErr(err);
++              goto out_free;
++      }
++      AuDbg("flags 0x%x\n", args->mvdown.flags);
++      args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
++      args->mvdown.au_errno = 0;
++      args->dentry = dentry;
++      args->inode = dentry->d_inode;
++      args->sb = dentry->d_sb;
 +
-+#endif /* __KERNEL__ */
-+#endif /* __AUFS_MODULE_H__ */
++      err = -ENOENT;
++      dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
++      args->parent = dget_parent(dentry);
++      args->dir = args->parent->d_inode;
++      mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
++      dput(args->parent);
++      if (unlikely(args->parent != dentry->d_parent)) {
++              AU_MVD_PR(dmsg, "parent dir is moved\n");
++              goto out_dir;
++      }
++
++      mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
++      err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
++      if (unlikely(err))
++              goto out_inode;
++
++      di_write_lock_parent(args->parent);
++      err = au_mvd_args(dmsg, args);
++      if (unlikely(err))
++              goto out_parent;
++
++      err = au_do_mvdown(dmsg, args);
++      if (unlikely(err))
++              goto out_parent;
++
++      au_cpup_attr_timesizes(args->dir);
++      au_cpup_attr_timesizes(args->inode);
++      au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
++      /* au_digen_dec(dentry); */
++
++out_parent:
++      di_write_unlock(args->parent);
++      aufs_read_unlock(dentry, AuLock_DW);
++out_inode:
++      mutex_unlock(&args->inode->i_mutex);
++out_dir:
++      mutex_unlock(&args->dir->i_mutex);
++out_free:
++      e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
++      if (unlikely(e))
++              err = -EFAULT;
++      kfree(args);
++out:
++      AuTraceErr(err);
++      return err;
++}
 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 --- /usr/share/empty/fs/aufs/opts.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/opts.c       2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,1677 @@
++++ linux/fs/aufs/opts.c       2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,1854 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -19270,8 +22566,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -19287,11 +22582,11 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +
 +enum {
 +      Opt_br,
-+      Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
-+      Opt_idel, Opt_imod, Opt_ireorder,
-+      Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
++      Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
++      Opt_idel, Opt_imod,
++      Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
 +      Opt_rdblk_def, Opt_rdhash_def,
-+      Opt_xino, Opt_zxino, Opt_noxino,
++      Opt_xino, Opt_noxino,
 +      Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
 +      Opt_trunc_xino_path, Opt_itrunc_xino,
 +      Opt_trunc_xib, Opt_notrunc_xib,
@@ -19299,14 +22594,15 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      Opt_plink, Opt_noplink, Opt_list_plink,
 +      Opt_udba,
 +      Opt_dio, Opt_nodio,
-+      /* Opt_lock, Opt_unlock, */
-+      Opt_cmd, Opt_cmd_args,
 +      Opt_diropq_a, Opt_diropq_w,
 +      Opt_warn_perm, Opt_nowarn_perm,
 +      Opt_wbr_copyup, Opt_wbr_create,
++      Opt_fhsm_sec,
 +      Opt_refrof, Opt_norefrof,
 +      Opt_verbose, Opt_noverbose,
 +      Opt_sum, Opt_nosum, Opt_wsum,
++      Opt_dirperm1, Opt_nodirperm1,
++      Opt_acl, Opt_noacl,
 +      Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
 +};
 +
@@ -19360,6 +22656,12 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      {Opt_dio, "dio"},
 +      {Opt_nodio, "nodio"},
 +
++#ifdef CONFIG_AUFS_FHSM
++      {Opt_fhsm_sec, "fhsm_sec=%d"},
++#else
++      {Opt_ignore_silent, "fhsm_sec=%d"},
++#endif
++
 +      {Opt_diropq_a, "diropq=always"},
 +      {Opt_diropq_a, "diropq=a"},
 +      {Opt_diropq_w, "diropq=whiteouted"},
@@ -19369,9 +22671,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      {Opt_nowarn_perm, "nowarn_perm"},
 +
 +      /* keep them temporary */
-+      {Opt_ignore_silent, "coo=%s"},
 +      {Opt_ignore_silent, "nodlgt"},
-+      {Opt_ignore_silent, "nodirperm1"},
 +      {Opt_ignore_silent, "clean_plink"},
 +
 +#ifdef CONFIG_AUFS_SHWH
@@ -19379,7 +22679,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +#endif
 +      {Opt_noshwh, "noshwh"},
 +
-+      {Opt_rendir, "rendir=%d"},
++      {Opt_dirperm1, "dirperm1"},
++      {Opt_nodirperm1, "nodirperm1"},
 +
 +      {Opt_refrof, "refrof"},
 +      {Opt_norefrof, "norefrof"},
@@ -19407,6 +22708,15 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      {Opt_wbr_copyup, "copyup=%s"},
 +      {Opt_wbr_copyup, "copyup_policy=%s"},
 +
++      /* generic VFS flag */
++#ifdef CONFIG_FS_POSIX_ACL
++      {Opt_acl, "acl"},
++      {Opt_noacl, "noacl"},
++#else
++      {Opt_ignore_silent, "acl"},
++      {Opt_ignore_silent, "noacl"},
++#endif
++
 +      /* internal use for the scripts */
 +      {Opt_ignore_silent, "si=%s"},
 +
@@ -19424,17 +22734,42 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +
 +/* ---------------------------------------------------------------------- */
 +
-+static const char *au_parser_pattern(int val, struct match_token *token)
++static const char *au_parser_pattern(int val, match_table_t tbl)
 +{
-+      while (token->pattern) {
-+              if (token->token == val)
-+                      return token->pattern;
-+              token++;
++      struct match_token *p;
++
++      p = tbl;
++      while (p->pattern) {
++              if (p->token == val)
++                      return p->pattern;
++              p++;
 +      }
 +      BUG();
 +      return "??";
 +}
 +
++static const char *au_optstr(int *val, match_table_t tbl)
++{
++      struct match_token *p;
++      int v;
++
++      v = *val;
++      if (!v)
++              goto out;
++      p = tbl;
++      while (p->pattern) {
++              if (p->token
++                  && (v & p->token) == p->token) {
++                      *val &= ~p->token;
++                      return p->pattern;
++              }
++              p++;
++      }
++
++out:
++      return NULL;
++}
++
 +/* ---------------------------------------------------------------------- */
 +
 +static match_table_t brperm = {
@@ -19444,18 +22779,34 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      {0, NULL}
 +};
 +
-+static match_table_t brrattr = {
++static match_table_t brattr = {
++      /* general */
++      {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
++      {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
++      /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
++      {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
++#ifdef CONFIG_AUFS_FHSM
++      {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
++#endif
++#ifdef CONFIG_AUFS_XATTR
++      {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
++      {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
++      {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
++      {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
++      {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
++      {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
++#endif
++
++      /* ro/rr branch */
 +      {AuBrRAttr_WH, AUFS_BRRATTR_WH},
-+      {0, NULL}
-+};
 +
-+static match_table_t brwattr = {
++      /* rw branch */
++      {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
 +      {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
++
 +      {0, NULL}
 +};
 +
-+#define AuBrStr_LONGEST       AUFS_BRPERM_RW "+" AUFS_BRWATTR_NLWH
-+
 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
 +{
 +      int attr, v;
@@ -19467,9 +22818,11 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              if (p)
 +                      *p = 0;
 +              v = match_token(str, table, args);
-+              if (v)
++              if (v) {
++                      if (v & AuBrAttr_CMOO_Mask)
++                              attr &= ~AuBrAttr_CMOO_Mask;
 +                      attr |= v;
-+              else {
++              else {
 +                      if (p)
 +                              *p = '+';
 +                      pr_warn("ignored branch attribute %s\n", str);
@@ -19482,11 +22835,42 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      return attr;
 +}
 +
++static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
++{
++      int sz;
++      const char *p;
++      char *q;
++
++      q = str->a;
++      *q = 0;
++      p = au_optstr(&perm, brattr);
++      if (p) {
++              sz = strlen(p);
++              memcpy(q, p, sz + 1);
++              q += sz;
++      } else
++              goto out;
++
++      do {
++              p = au_optstr(&perm, brattr);
++              if (p) {
++                      *q++ = '+';
++                      sz = strlen(p);
++                      memcpy(q, p, sz + 1);
++                      q += sz;
++              }
++      } while (p);
++
++out:
++      return q - str->a;
++}
++
 +static int noinline_for_stack br_perm_val(char *perm)
 +{
-+      int val;
++      int val, bad, sz;
 +      char *p;
 +      substring_t args[MAX_OPT_ARGS];
++      au_br_perm_str_t attr;
 +
 +      p = strchr(perm, '+');
 +      if (p)
@@ -19502,62 +22886,62 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      if (!p)
 +              goto out;
 +
-+      switch (val) {
++      val |= br_attr_val(p + 1, brattr, args);
++
++      bad = 0;
++      switch (val & AuBrPerm_Mask) {
 +      case AuBrPerm_RO:
 +      case AuBrPerm_RR:
-+              val |= br_attr_val(p + 1, brrattr, args);
++              bad = val & AuBrWAttr_Mask;
++              val &= ~AuBrWAttr_Mask;
 +              break;
 +      case AuBrPerm_RW:
-+              val |= br_attr_val(p + 1, brwattr, args);
++              bad = val & AuBrRAttr_Mask;
++              val &= ~AuBrRAttr_Mask;
 +              break;
 +      }
 +
++      /*
++       * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
++       * does not treat it as an error, just warning.
++       * this is a tiny guard for the user operation.
++       */
++      if (val & AuBrAttr_UNPIN) {
++              bad |= AuBrAttr_UNPIN;
++              val &= ~AuBrAttr_UNPIN;
++      }
++
++      if (unlikely(bad)) {
++              sz = au_do_optstr_br_attr(&attr, bad);
++              AuDebugOn(!sz);
++              pr_warn("ignored branch attribute %s\n", attr.a);
++      }
++
 +out:
 +      return val;
 +}
 +
-+/* Caller should free the return value */
-+char *au_optstr_br_perm(int brperm)
++void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
 +{
-+      char *p, a[sizeof(AuBrStr_LONGEST)];
++      au_br_perm_str_t attr;
++      const char *p;
++      char *q;
 +      int sz;
 +
-+#define SetPerm(str) do {                     \
-+              sz = sizeof(str);               \
-+              memcpy(a, str, sz);             \
-+              p = a + sz - 1;                 \
-+      } while (0)
-+
-+#define AppendAttr(flag, str) do {                    \
-+              if (brperm & flag) {            \
-+                      sz = sizeof(str);       \
-+                      *p++ = '+';             \
-+                      memcpy(p, str, sz);     \
-+                      p += sz - 1;            \
-+              }                               \
-+      } while (0)
++      q = str->a;
++      p = au_optstr(&perm, brperm);
++      AuDebugOn(!p || !*p);
++      sz = strlen(p);
++      memcpy(q, p, sz + 1);
++      q += sz;
 +
-+      switch (brperm & AuBrPerm_Mask) {
-+      case AuBrPerm_RO:
-+              SetPerm(AUFS_BRPERM_RO);
-+              break;
-+      case AuBrPerm_RR:
-+              SetPerm(AUFS_BRPERM_RR);
-+              break;
-+      case AuBrPerm_RW:
-+              SetPerm(AUFS_BRPERM_RW);
-+              break;
-+      default:
-+              AuDebugOn(1);
++      sz = au_do_optstr_br_attr(&attr, perm);
++      if (sz) {
++              *q++ = '+';
++              memcpy(q, attr.a, sz + 1);
 +      }
 +
-+      AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
-+      AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
-+
-+      AuDebugOn(strlen(a) >= sizeof(a));
-+      return kstrdup(a, GFP_NOFS);
-+#undef SetPerm
-+#undef AppendAttr
++      AuDebugOn(strlen(str->a) >= sizeof(str->a));
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -19583,7 +22967,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +
 +const char *au_optstr_udba(int udba)
 +{
-+      return au_parser_pattern(udba, (void *)udbalevel);
++      return au_parser_pattern(udba, udbalevel);
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -19602,6 +22986,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
 +      {AuWbrCreate_PMFS, "pmfs"},
 +      {AuWbrCreate_PMFSV, "pmfs:%d"},
++      {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
++      {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
 +
 +      {-1, NULL}
 +};
@@ -19671,6 +23057,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      create->wbr_create = err;
 +      switch (err) {
 +      case AuWbrCreate_MFSRRV:
++      case AuWbrCreate_PMFSRRV:
 +              e = au_wbr_mfs_wmark(&args[0], str, create);
 +              if (!e)
 +                      e = au_wbr_mfs_sec(&args[1], str, create);
@@ -19678,6 +23065,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +                      err = e;
 +              break;
 +      case AuWbrCreate_MFSRR:
++      case AuWbrCreate_PMFSRR:
 +              e = au_wbr_mfs_wmark(&args[0], str, create);
 +              if (unlikely(e)) {
 +                      err = e;
@@ -19701,7 +23089,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +
 +const char *au_optstr_wbr_create(int wbr_create)
 +{
-+      return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
++      return au_parser_pattern(wbr_create, au_wbr_create_policy);
 +}
 +
 +static match_table_t au_wbr_copyup_policy = {
@@ -19723,7 +23111,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +
 +const char *au_optstr_wbr_copyup(int wbr_copyup)
 +{
-+      return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
++      return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -19797,9 +23185,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +                      break;
 +              case Opt_xino:
 +                      u.xino = &opt->xino;
-+                      AuDbg("xino {%s %.*s}\n",
-+                                u.xino->path,
-+                                AuDLNPair(u.xino->file->f_dentry));
++                      AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
 +                      break;
 +              case Opt_trunc_xino:
 +                      AuLabel(trunc_xino);
@@ -19812,7 +23198,6 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +                      u.xino_itrunc = &opt->xino_itrunc;
 +                      AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
 +                      break;
-+
 +              case Opt_noxino:
 +                      AuLabel(noxino);
 +                      break;
@@ -19828,6 +23213,12 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              case Opt_noshwh:
 +                      AuLabel(noshwh);
 +                      break;
++              case Opt_dirperm1:
++                      AuLabel(dirperm1);
++                      break;
++              case Opt_nodirperm1:
++                      AuLabel(nodirperm1);
++                      break;
 +              case Opt_plink:
 +                      AuLabel(plink);
 +                      break;
@@ -19894,6 +23285,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +                                        u.create->mfsrr_watermark);
 +                              break;
 +                      case AuWbrCreate_MFSRRV:
++                      case AuWbrCreate_PMFSRRV:
 +                              AuDbg("%llu watermark, %d sec\n",
 +                                        u.create->mfsrr_watermark,
 +                                        u.create->mfs_second);
@@ -19904,6 +23296,15 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +                      AuDbg("copyup %d, %s\n", opt->wbr_copyup,
 +                                au_optstr_wbr_copyup(opt->wbr_copyup));
 +                      break;
++              case Opt_fhsm_sec:
++                      AuDbg("fhsm_sec %u\n", opt->fhsm_second);
++                      break;
++              case Opt_acl:
++                      AuLabel(acl);
++                      break;
++              case Opt_noacl:
++                      AuLabel(noacl);
++                      break;
 +              default:
 +                      BUG();
 +              }
@@ -20085,7 +23486,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              goto out;
 +
 +      err = -EINVAL;
-+      if (unlikely(file->f_dentry->d_sb == sb)) {
++      if (unlikely(file->f_path.dentry->d_sb == sb)) {
 +              fput(file);
 +              pr_err("%s must be outside\n", args[0].from);
 +              goto out;
@@ -20330,6 +23731,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              case Opt_notrunc_xib:
 +              case Opt_shwh:
 +              case Opt_noshwh:
++              case Opt_dirperm1:
++              case Opt_nodirperm1:
 +              case Opt_plink:
 +              case Opt_noplink:
 +              case Opt_list_plink:
@@ -20348,6 +23751,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              case Opt_wsum:
 +              case Opt_rdblk_def:
 +              case Opt_rdhash_def:
++              case Opt_acl:
++              case Opt_noacl:
 +                      err = 0;
 +                      opt->type = token;
 +                      break;
@@ -20380,6 +23785,20 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +                              pr_err("wrong value, %s\n", opt_str);
 +                      break;
 +
++              case Opt_fhsm_sec:
++                      if (unlikely(match_int(&a->args[0], &n)
++                                   || n < 0)) {
++                              pr_err("bad integer in %s\n", opt_str);
++                              break;
++                      }
++                      if (sysaufs_brs) {
++                              opt->fhsm_second = n;
++                              opt->type = token;
++                      } else
++                              pr_warn("ignored %s\n", opt_str);
++                      err = 0;
++                      break;
++
 +              case Opt_ignore:
 +                      pr_warn("ignored %s\n", opt_str);
 +                      /*FALLTHROUGH*/
@@ -20433,6 +23852,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      switch (create->wbr_create) {
 +      case AuWbrCreate_MFSRRV:
 +      case AuWbrCreate_MFSRR:
++      case AuWbrCreate_PMFSRR:
++      case AuWbrCreate_PMFSRRV:
 +              sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
 +              /*FALLTHROUGH*/
 +      case AuWbrCreate_MFS:
@@ -20494,6 +23915,10 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              au_fset_opts(opts->flags, REFRESH_DYAOP);
 +              break;
 +
++      case Opt_fhsm_sec:
++              au_fhsm_set(sbinfo, opt->fhsm_second);
++              break;
++
 +      case Opt_diropq_a:
 +              au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
 +              break;
@@ -20569,6 +23994,13 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              au_opt_clr(sbinfo->si_mntflags, SHWH);
 +              break;
 +
++      case Opt_dirperm1:
++              au_opt_set(sbinfo->si_mntflags, DIRPERM1);
++              break;
++      case Opt_nodirperm1:
++              au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
++              break;
++
 +      case Opt_trunc_xino:
 +              au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
 +              break;
@@ -20590,6 +24022,13 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              au_fclr_opts(opts->flags, TRUNC_XIB);
 +              break;
 +
++      case Opt_acl:
++              sb->s_flags |= MS_POSIXACL;
++              break;
++      case Opt_noacl:
++              sb->s_flags &= ~MS_POSIXACL;
++              break;
++
 +      default:
 +              err = 0;
 +              break;
@@ -20618,7 +24057,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              goto add;
 +      case Opt_prepend:
 +              opt->add.bindex = 0;
-+      add:
++      add: /* indented label */
 +      case Opt_add:
 +              err = au_br_add(sb, &opt->add,
 +                              au_ftest_opts(opts->flags, REMOUNT));
@@ -20675,7 +24114,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              au_xino_brid_set(sb, -1);
 +
 +              /* safe d_parent access */
-+              parent = opt->xino.file->f_dentry->d_parent;
++              parent = opt->xino.file->f_path.dentry->d_parent;
 +              root = sb->s_root;
 +              bend = au_sbend(sb);
 +              for (bindex = 0; bindex <= bend; bindex++) {
@@ -20700,7 +24139,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
 +                 unsigned int pending)
 +{
-+      int err;
++      int err, fhsm;
 +      aufs_bindex_t bindex, bend;
 +      unsigned char do_plink, skip, do_free;
 +      struct au_branch *br;
@@ -20726,7 +24165,12 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +          && !au_opt_test(sbinfo->si_mntflags, XINO))
 +              pr_warn("udba=*notify requires xino\n");
 +
++      if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
++              pr_warn("dirperm1 breaks the protection"
++                      " by the permission bits on the lower branch\n");
++
 +      err = 0;
++      fhsm = 0;
 +      root = sb->s_root;
 +      dir = root->d_inode;
 +      do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
@@ -20735,8 +24179,17 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              skip = 0;
 +              h_dir = au_h_iptr(dir, bindex);
 +              br = au_sbr(sb, bindex);
-+              do_free = 0;
 +
++              if ((br->br_perm & AuBrAttr_ICEX)
++                  && !h_dir->i_op->listxattr)
++                      br->br_perm &= ~AuBrAttr_ICEX;
++#if 0
++              if ((br->br_perm & AuBrAttr_ICEX_SEC)
++                  && (au_br_sb(br)->s_flags & MS_NOSEC))
++                      br->br_perm &= ~AuBrAttr_ICEX_SEC;
++#endif
++
++              do_free = 0;
 +              wbr = br->br_wbr;
 +              if (wbr)
 +                      wbr_wh_read_lock(wbr);
@@ -20769,6 +24222,11 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              if (wbr)
 +                      wbr_wh_read_unlock(wbr);
 +
++              if (au_br_fhsm(br->br_perm)) {
++                      fhsm++;
++                      AuDebugOn(!br->br_fhsm);
++              }
++
 +              if (skip)
 +                      continue;
 +
@@ -20776,7 +24234,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
 +              if (wbr)
 +                      wbr_wh_write_lock(wbr);
-+              err = au_wh_init(au_h_dptr(root, bindex), br, sb);
++              err = au_wh_init(br, sb);
 +              if (wbr)
 +                      wbr_wh_write_unlock(wbr);
 +              au_hn_imtx_unlock(hdir);
@@ -20787,6 +24245,20 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              }
 +      }
 +
++      if (fhsm >= 2) {
++              au_fset_si(sbinfo, FHSM);
++              for (bindex = bend; bindex >= 0; bindex--) {
++                      br = au_sbr(sb, bindex);
++                      if (au_br_fhsm(br->br_perm)) {
++                              au_fhsm_set_bottom(sb, bindex);
++                              break;
++                      }
++              }
++      } else {
++              au_fclr_si(sbinfo, FHSM);
++              au_fhsm_set_bottom(sb, -1);
++      }
++
 +      return err;
 +}
 +
@@ -20799,6 +24271,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +      struct au_opt_xino *opt_xino, xino;
 +      struct au_sbinfo *sbinfo;
 +      struct au_branch *br;
++      struct inode *dir;
 +
 +      SiMustWriteLock(sb);
 +
@@ -20872,7 +24345,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +              /* go on even if err */
 +      }
 +      if (au_opt_test(tmp, UDBA_HNOTIFY)) {
-+              struct inode *dir = sb->s_root->d_inode;
++              dir = sb->s_root->d_inode;
 +              au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
 +      }
 +
@@ -20935,10 +24408,10 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +}
 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
 --- /usr/share/empty/fs/aufs/opts.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/opts.h       2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,209 @@
++++ linux/fs/aufs/opts.h       2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,211 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -20951,8 +24424,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -20980,7 +24452,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
 +#define AuOpt_UDBA_HNOTIFY    (1 << 4)
 +#define AuOpt_SHWH            (1 << 5)        /* show whiteout */
 +#define AuOpt_PLINK           (1 << 6)        /* pseudo-link */
-+#define AuOpt_DIRPERM1                (1 << 7)        /* unimplemented */
++#define AuOpt_DIRPERM1                (1 << 7)        /* ignore the lower dir's perm
++                                                 bits */
 +#define AuOpt_REFROF          (1 << 8)        /* unimplemented */
 +#define AuOpt_ALWAYS_DIROPQ   (1 << 9)        /* policy to creating diropq */
 +#define AuOpt_SUM             (1 << 10)       /* summation for statfs(2) */
@@ -21041,6 +24514,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
 +      AuWbrCreate_MFSRRV,     /* mfs then rr with seconds */
 +      AuWbrCreate_PMFS,       /* parent and mfs */
 +      AuWbrCreate_PMFSV,      /* parent and mfs with seconds */
++      AuWbrCreate_PMFSRR,     /* parent, mfs and round-robin */
++      AuWbrCreate_PMFSRRV,    /* plus seconds */
 +
 +      AuWbrCreate_Def = AuWbrCreate_TDP
 +};
@@ -21103,6 +24578,7 @@ diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
 +              int                     udba;
 +              struct au_opt_wbr_create wbr_create;
 +              int                     wbr_copyup;
++              unsigned int            fhsm_second;
 +      };
 +};
 +
@@ -21128,7 +24604,8 @@ diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
 +
 +/* ---------------------------------------------------------------------- */
 +
-+char *au_optstr_br_perm(int brperm);
++/* opts.c */
++void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
 +const char *au_optstr_udba(int udba);
 +const char *au_optstr_wbr_copyup(int wbr_copyup);
 +const char *au_optstr_wbr_create(int wbr_create);
@@ -21142,16 +24619,14 @@ diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
 +
 +unsigned int au_opt_udba(struct super_block *sb);
 +
-+/* ---------------------------------------------------------------------- */
-+
 +#endif /* __KERNEL__ */
 +#endif /* __AUFS_OPTS_H__ */
 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 --- /usr/share/empty/fs/aufs/plink.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/plink.c      2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,511 @@
++++ linux/fs/aufs/plink.c      2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,532 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -21164,8 +24639,7 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -21271,19 +24745,12 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +
 +/* ---------------------------------------------------------------------- */
 +
-+struct pseudo_link {
-+      union {
-+              struct list_head list;
-+              struct rcu_head rcu;
-+      };
-+      struct inode *inode;
-+};
-+
 +#ifdef CONFIG_AUFS_DEBUG
 +void au_plink_list(struct super_block *sb)
 +{
++      int i;
 +      struct au_sbinfo *sbinfo;
-+      struct list_head *plink_list;
++      struct hlist_head *plink_hlist;
 +      struct pseudo_link *plink;
 +
 +      SiMustAnyLock(sb);
@@ -21292,20 +24759,22 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +      AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
 +      AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
 +
-+      plink_list = &sbinfo->si_plink.head;
-+      rcu_read_lock();
-+      list_for_each_entry_rcu(plink, plink_list, list)
-+              AuDbg("%lu\n", plink->inode->i_ino);
-+      rcu_read_unlock();
++      for (i = 0; i < AuPlink_NHASH; i++) {
++              plink_hlist = &sbinfo->si_plink[i].head;
++              rcu_read_lock();
++              hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
++                      AuDbg("%lu\n", plink->inode->i_ino);
++              rcu_read_unlock();
++      }
 +}
 +#endif
 +
 +/* is the inode pseudo-linked? */
 +int au_plink_test(struct inode *inode)
 +{
-+      int found;
++      int found, i;
 +      struct au_sbinfo *sbinfo;
-+      struct list_head *plink_list;
++      struct hlist_head *plink_hlist;
 +      struct pseudo_link *plink;
 +
 +      sbinfo = au_sbi(inode->i_sb);
@@ -21314,9 +24783,10 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +      AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
 +
 +      found = 0;
-+      plink_list = &sbinfo->si_plink.head;
++      i = au_plink_hash(inode->i_ino);
++      plink_hlist = &sbinfo->si_plink[i].head;
 +      rcu_read_lock();
-+      list_for_each_entry_rcu(plink, plink_list, list)
++      hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
 +              if (plink->inode == inode) {
 +                      found = 1;
 +                      break;
@@ -21412,9 +24882,9 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +{
 +      int err;
 +      struct path h_path = {
-+              .mnt = br->br_mnt
++              .mnt = au_br_mnt(br)
 +      };
-+      struct inode *h_dir;
++      struct inode *h_dir, *delegated;
 +
 +      h_dir = h_parent->d_inode;
 +      mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
@@ -21429,14 +24899,27 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +      /* todo: is it really safe? */
 +      if (h_path.dentry->d_inode
 +          && h_path.dentry->d_inode != h_dentry->d_inode) {
-+              err = vfsub_unlink(h_dir, &h_path, /*force*/0);
++              delegated = NULL;
++              err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal unlink\n");
++                      iput(delegated);
++              }
 +              dput(h_path.dentry);
 +              h_path.dentry = NULL;
 +              if (!err)
 +                      goto again;
 +      }
-+      if (!err && !h_path.dentry->d_inode)
-+              err = vfsub_link(h_dentry, h_dir, &h_path);
++      if (!err && !h_path.dentry->d_inode) {
++              delegated = NULL;
++              err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal link\n");
++                      iput(delegated);
++              }
++      }
 +      dput(h_path.dentry);
 +
 +out:
@@ -21495,7 +24978,7 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +static void do_put_plink(struct pseudo_link *plink, int do_del)
 +{
 +      if (do_del)
-+              list_del(&plink->list);
++              hlist_del(&plink->hlist);
 +      iput(plink->inode);
 +      kfree(plink);
 +}
@@ -21518,30 +25001,23 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +{
 +      struct super_block *sb;
 +      struct au_sbinfo *sbinfo;
-+      struct list_head *plink_list;
++      struct hlist_head *plink_hlist;
 +      struct pseudo_link *plink, *tmp;
-+      int found, err, cnt;
++      struct au_sphlhead *sphl;
++      int found, err, cnt, i;
 +
 +      sb = inode->i_sb;
 +      sbinfo = au_sbi(sb);
 +      AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
 +      AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
 +
-+      cnt = 0;
-+      found = 0;
-+      plink_list = &sbinfo->si_plink.head;
-+      rcu_read_lock();
-+      list_for_each_entry_rcu(plink, plink_list, list) {
-+              cnt++;
-+              if (plink->inode == inode) {
-+                      found = 1;
-+                      break;
-+              }
-+      }
-+      rcu_read_unlock();
++      found = au_plink_test(inode);
 +      if (found)
 +              return;
 +
++      i = au_plink_hash(inode->i_ino);
++      sphl = sbinfo->si_plink + i;
++      plink_hlist = &sphl->head;
 +      tmp = kmalloc(sizeof(*plink), GFP_NOFS);
 +      if (tmp)
 +              tmp->inode = au_igrab(inode);
@@ -21550,20 +25026,22 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +              goto out;
 +      }
 +
-+      spin_lock(&sbinfo->si_plink.spin);
-+      list_for_each_entry(plink, plink_list, list) {
++      spin_lock(&sphl->spin);
++      hlist_for_each_entry(plink, plink_hlist, hlist) {
 +              if (plink->inode == inode) {
 +                      found = 1;
 +                      break;
 +              }
 +      }
 +      if (!found)
-+              list_add_rcu(&tmp->list, plink_list);
-+      spin_unlock(&sbinfo->si_plink.spin);
++              hlist_add_head_rcu(&tmp->hlist, plink_hlist);
++      spin_unlock(&sphl->spin);
 +      if (!found) {
-+              cnt++;
-+              WARN_ONCE(cnt > AUFS_PLINK_WARN,
-+                        "unexpectedly many pseudo links, %d\n", cnt);
++              cnt = au_sphl_count(sphl);
++#define msg "unexpectedly unblanced or too many pseudo-links"
++              if (cnt > AUFS_PLINK_WARN)
++                      AuWarn1(msg ", %d\n", cnt);
++#undef msg
 +              err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
 +      } else {
 +              do_put_plink(tmp, 0);
@@ -21574,7 +25052,7 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +      if (unlikely(err)) {
 +              pr_warn("err %d, damaged pseudo link.\n", err);
 +              if (tmp) {
-+                      au_spl_del_rcu(&tmp->list, &sbinfo->si_plink);
++                      au_sphl_del_rcu(&tmp->hlist, sphl);
 +                      call_rcu(&tmp->rcu, do_put_plink_rcu);
 +              }
 +      }
@@ -21583,9 +25061,11 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +/* free all plinks */
 +void au_plink_put(struct super_block *sb, int verbose)
 +{
++      int i, warned;
 +      struct au_sbinfo *sbinfo;
-+      struct list_head *plink_list;
-+      struct pseudo_link *plink, *tmp;
++      struct hlist_head *plink_hlist;
++      struct hlist_node *tmp;
++      struct pseudo_link *plink;
 +
 +      SiMustWriteLock(sb);
 +
@@ -21593,12 +25073,18 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +      AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
 +      AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
 +
-+      plink_list = &sbinfo->si_plink.head;
 +      /* no spin_lock since sbinfo is write-locked */
-+      WARN(verbose && !list_empty(plink_list), "pseudo-link is not flushed");
-+      list_for_each_entry_safe(plink, tmp, plink_list, list)
-+              do_put_plink(plink, 0);
-+      INIT_LIST_HEAD(plink_list);
++      warned = 0;
++      for (i = 0; i < AuPlink_NHASH; i++) {
++              plink_hlist = &sbinfo->si_plink[i].head;
++              if (!warned && verbose && !hlist_empty(plink_hlist)) {
++                      pr_warn("pseudo-link is not flushed");
++                      warned = 1;
++              }
++              hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
++                      do_put_plink(plink, 0);
++              INIT_HLIST_HEAD(plink_hlist);
++      }
 +}
 +
 +void au_plink_clean(struct super_block *sb, int verbose)
@@ -21612,15 +25098,44 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +      aufs_write_unlock(root);
 +}
 +
++static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
++{
++      int do_put;
++      aufs_bindex_t bstart, bend, bindex;
++
++      do_put = 0;
++      bstart = au_ibstart(inode);
++      bend = au_ibend(inode);
++      if (bstart >= 0) {
++              for (bindex = bstart; bindex <= bend; bindex++) {
++                      if (!au_h_iptr(inode, bindex)
++                          || au_ii_br_id(inode, bindex) != br_id)
++                              continue;
++                      au_set_h_iptr(inode, bindex, NULL, 0);
++                      do_put = 1;
++                      break;
++              }
++              if (do_put)
++                      for (bindex = bstart; bindex <= bend; bindex++)
++                              if (au_h_iptr(inode, bindex)) {
++                                      do_put = 0;
++                                      break;
++                              }
++      } else
++              do_put = 1;
++
++      return do_put;
++}
++
 +/* free the plinks on a branch specified by @br_id */
 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
 +{
 +      struct au_sbinfo *sbinfo;
-+      struct list_head *plink_list;
-+      struct pseudo_link *plink, *tmp;
++      struct hlist_head *plink_hlist;
++      struct hlist_node *tmp;
++      struct pseudo_link *plink;
 +      struct inode *inode;
-+      aufs_bindex_t bstart, bend, bindex;
-+      unsigned char do_put;
++      int i, do_put;
 +
 +      SiMustWriteLock(sb);
 +
@@ -21628,45 +25143,26 @@ diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
 +      AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
 +      AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
 +
-+      plink_list = &sbinfo->si_plink.head;
 +      /* no spin_lock since sbinfo is write-locked */
-+      list_for_each_entry_safe(plink, tmp, plink_list, list) {
-+              do_put = 0;
-+              inode = au_igrab(plink->inode);
-+              ii_write_lock_child(inode);
-+              bstart = au_ibstart(inode);
-+              bend = au_ibend(inode);
-+              if (bstart >= 0) {
-+                      for (bindex = bstart; bindex <= bend; bindex++) {
-+                              if (!au_h_iptr(inode, bindex)
-+                                  || au_ii_br_id(inode, bindex) != br_id)
-+                                      continue;
-+                              au_set_h_iptr(inode, bindex, NULL, 0);
-+                              do_put = 1;
-+                              break;
-+                      }
-+              } else
-+                      do_put_plink(plink, 1);
-+
-+              if (do_put) {
-+                      for (bindex = bstart; bindex <= bend; bindex++)
-+                              if (au_h_iptr(inode, bindex)) {
-+                                      do_put = 0;
-+                                      break;
-+                              }
++      for (i = 0; i < AuPlink_NHASH; i++) {
++              plink_hlist = &sbinfo->si_plink[i].head;
++              hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
++                      inode = au_igrab(plink->inode);
++                      ii_write_lock_child(inode);
++                      do_put = au_plink_do_half_refresh(inode, br_id);
 +                      if (do_put)
 +                              do_put_plink(plink, 1);
++                      ii_write_unlock(inode);
++                      iput(inode);
 +              }
-+              ii_write_unlock(inode);
-+              iput(inode);
 +      }
 +}
 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
 --- /usr/share/empty/fs/aufs/poll.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/poll.c       2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,56 @@
++++ linux/fs/aufs/poll.c       2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,52 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -21679,54 +25175,153 @@ diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * poll operation
++ * There is only one filesystem which implements ->poll operation, currently.
++ */
++
++#include "aufs.h"
++
++unsigned int aufs_poll(struct file *file, poll_table *wait)
++{
++      unsigned int mask;
++      int err;
++      struct file *h_file;
++      struct super_block *sb;
++
++      /* We should pretend an error happened. */
++      mask = POLLERR /* | POLLIN | POLLOUT */;
++      sb = file->f_path.dentry->d_sb;
++      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
++
++      h_file = au_read_pre(file, /*keep_fi*/0);
++      err = PTR_ERR(h_file);
++      if (IS_ERR(h_file))
++              goto out;
++
++      /* it is not an error if h_file has no operation */
++      mask = DEFAULT_POLLMASK;
++      if (h_file->f_op->poll)
++              mask = h_file->f_op->poll(h_file, wait);
++      fput(h_file); /* instead of au_read_post() */
++
++out:
++      si_read_unlock(sb);
++      AuTraceErr((int)mask);
++      return mask;
++}
+diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
+--- /usr/share/empty/fs/aufs/posix_acl.c       1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/posix_acl.c  2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,99 @@
++/*
++ * Copyright (C) 2014-2015 Junjiro R. Okajima
++ *
++ * This program, aufs is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * posix acl operations
 + */
 +
-+/*
-+ * poll operation
-+ * There is only one filesystem which implements ->poll operation, currently.
-+ */
++#include <linux/fs.h>
++#include <linux/posix_acl.h>
++#include "aufs.h"
++
++struct posix_acl *aufs_get_acl(struct inode *inode, int type)
++{
++      struct posix_acl *acl;
++      int err;
++      aufs_bindex_t bindex;
++      struct inode *h_inode;
++      struct super_block *sb;
++
++      acl = NULL;
++      sb = inode->i_sb;
++      si_read_lock(sb, AuLock_FLUSH);
++      ii_read_lock_child(inode);
++      if (!(sb->s_flags & MS_POSIXACL))
++              goto out;
++
++      bindex = au_ibstart(inode);
++      h_inode = au_h_iptr(inode, bindex);
++      if (unlikely(!h_inode
++                   || ((h_inode->i_mode & S_IFMT)
++                       != (inode->i_mode & S_IFMT)))) {
++              err = au_busy_or_stale();
++              acl = ERR_PTR(err);
++              goto out;
++      }
 +
-+#include "aufs.h"
++      /* always topmost only */
++      acl = get_acl(h_inode, type);
 +
-+unsigned int aufs_poll(struct file *file, poll_table *wait)
++out:
++      ii_read_unlock(inode);
++      si_read_unlock(sb);
++
++      AuTraceErrPtr(acl);
++      return acl;
++}
++
++int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 +{
-+      unsigned int mask;
 +      int err;
-+      struct file *h_file;
++      ssize_t ssz;
 +      struct dentry *dentry;
-+      struct super_block *sb;
-+
-+      /* We should pretend an error happened. */
-+      mask = POLLERR /* | POLLIN | POLLOUT */;
-+      dentry = file->f_dentry;
-+      sb = dentry->d_sb;
-+      si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
-+      err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
-+      if (unlikely(err))
-+              goto out;
++      struct au_srxattr arg = {
++              .type = AU_ACL_SET,
++              .u.acl_set = {
++                      .acl    = acl,
++                      .type   = type
++              },
++      };
 +
-+      /* it is not an error if h_file has no operation */
-+      mask = DEFAULT_POLLMASK;
-+      h_file = au_hf_top(file);
-+      if (h_file->f_op && h_file->f_op->poll)
-+              mask = h_file->f_op->poll(h_file, wait);
++      mutex_lock(&inode->i_mutex);
++      if (inode->i_ino == AUFS_ROOT_INO)
++              dentry = dget(inode->i_sb->s_root);
++      else {
++              dentry = d_find_alias(inode);
++              if (!dentry)
++                      dentry = d_find_any_alias(inode);
++              if (!dentry) {
++                      pr_warn("cannot handle this inode, "
++                              "please report to aufs-users ML\n");
++                      err = -ENOENT;
++                      goto out;
++              }
++      }
 +
-+      di_read_unlock(dentry, AuLock_IR);
-+      fi_read_unlock(file);
++      ssz = au_srxattr(dentry, &arg);
++      dput(dentry);
++      err = ssz;
++      if (ssz >= 0)
++              err = 0;
 +
 +out:
-+      si_read_unlock(sb);
-+      AuTraceErr((int)mask);
-+      return mask;
++      mutex_unlock(&inode->i_mutex);
++      return err;
 +}
 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
 --- /usr/share/empty/fs/aufs/procfs.c  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/procfs.c     2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,170 @@
++++ linux/fs/aufs/procfs.c     2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,169 @@
 +/*
-+ * Copyright (C) 2010-2013 Junjiro R. Okajima
++ * Copyright (C) 2010-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -21739,8 +25334,7 @@ diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -21897,10 +25491,10 @@ diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
 +}
 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 --- /usr/share/empty/fs/aufs/rdu.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/rdu.c        2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,384 @@
++++ linux/fs/aufs/rdu.c        2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,388 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -21913,8 +25507,7 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -21937,6 +25530,7 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +      do { (flags) &= ~AuRdu_##name; } while (0)
 +
 +struct au_rdu_arg {
++      struct dir_context              ctx;
 +      struct aufs_rdu                 *rdu;
 +      union au_rdu_ent_ul             ent;
 +      unsigned long                   end;
@@ -21945,11 +25539,11 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +      int                             err;
 +};
 +
-+static int au_rdu_fill(void *__arg, const char *name, int nlen,
++static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
 +                     loff_t offset, u64 h_ino, unsigned int d_type)
 +{
 +      int err, len;
-+      struct au_rdu_arg *arg = __arg;
++      struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
 +      struct aufs_rdu *rdu = arg->rdu;
 +      struct au_rdu_ent ent;
 +
@@ -22007,7 +25601,7 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +              arg->err = 0;
 +              au_fclr_rdu(cookie->flags, CALLED);
 +              /* smp_mb(); */
-+              err = vfsub_readdir(h_file, au_rdu_fill, arg);
++              err = vfsub_iterate_dir(h_file, &arg->ctx);
 +              if (err >= 0)
 +                      err = arg->err;
 +      } while (!err
@@ -22024,7 +25618,11 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +{
 +      int err;
 +      aufs_bindex_t bend;
-+      struct au_rdu_arg arg;
++      struct au_rdu_arg arg = {
++              .ctx = {
++                      .actor = au_rdu_fill
++              }
++      };
 +      struct dentry *dentry;
 +      struct inode *inode;
 +      struct file *h_file;
@@ -22045,7 +25643,7 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +      arg.end += rdu->sz;
 +
 +      err = -ENOTDIR;
-+      if (unlikely(!file->f_op || !file->f_op->readdir))
++      if (unlikely(!file->f_op->iterate))
 +              goto out;
 +
 +      err = security_file_permission(file, MAY_READ);
@@ -22053,7 +25651,7 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +      if (unlikely(err))
 +              goto out;
 +
-+      dentry = file->f_dentry;
++      dentry = file->f_path.dentry;
 +      inode = dentry->d_inode;
 +#if 1
 +      mutex_lock(&inode->i_mutex);
@@ -22137,7 +25735,7 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +      err = 0;
 +      nent = rdu->nent;
 +      u = &rdu->ent;
-+      sb = file->f_dentry->d_sb;
++      sb = file->f_path.dentry->d_sb;
 +      si_read_lock(sb, AuLock_FLUSH);
 +      while (nent-- > 0) {
 +              /* unnecessary to support mmap_sem since this is a dir */
@@ -22285,10 +25883,10 @@ diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
 +#endif
 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
 --- /usr/share/empty/fs/aufs/rwsem.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/rwsem.h      2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,188 @@
++++ linux/fs/aufs/rwsem.h      2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,191 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -22301,8 +25899,7 @@ diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -22426,7 +26023,9 @@ diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
 +/* why is not _nested version defined */
 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
 +{
-+      int ret = down_read_trylock(&rw->rwsem);
++      int ret;
++
++      ret = down_read_trylock(&rw->rwsem);
 +      if (ret)
 +              AuDbgRcntInc(rw);
 +      return ret;
@@ -22434,7 +26033,9 @@ diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
 +
 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
 +{
-+      int ret = down_write_trylock(&rw->rwsem);
++      int ret;
++
++      ret = down_write_trylock(&rw->rwsem);
 +      if (ret)
 +              AuDbgWcntInc(rw);
 +      return ret;
@@ -22477,10 +26078,10 @@ diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
 +#endif /* __AUFS_RWSEM_H__ */
 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
 --- /usr/share/empty/fs/aufs/sbinfo.c  1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sbinfo.c     2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,343 @@
++++ linux/fs/aufs/sbinfo.c     2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,354 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -22493,8 +26094,7 @@ diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -22508,11 +26108,13 @@ diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
 + */
 +void au_si_free(struct kobject *kobj)
 +{
++      int i;
 +      struct au_sbinfo *sbinfo;
 +      char *locked __maybe_unused; /* debug only */
 +
 +      sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
-+      AuDebugOn(!list_empty(&sbinfo->si_plink.head));
++      for (i = 0; i < AuPlink_NHASH; i++)
++              AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
 +      AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
 +
 +      au_rw_write_lock(&sbinfo->si_rwsem);
@@ -22534,7 +26136,7 @@ diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
 +
 +int au_si_alloc(struct super_block *sb)
 +{
-+      int err;
++      int err, i;
 +      struct au_sbinfo *sbinfo;
 +      static struct lock_class_key aufs_si;
 +
@@ -22570,32 +26172,42 @@ diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
 +      atomic_long_set(&sbinfo->si_nfiles, 0);
 +
 +      sbinfo->si_bend = -1;
++      sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
 +
 +      sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
 +      sbinfo->si_wbr_create = AuWbrCreate_Def;
 +      sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
 +      sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
 +
++      au_fhsm_init(sbinfo);
++
 +      sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
 +
++      sbinfo->si_xino_jiffy = jiffies;
++      sbinfo->si_xino_expire
++              = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
 +      mutex_init(&sbinfo->si_xib_mtx);
 +      sbinfo->si_xino_brid = -1;
 +      /* leave si_xib_last_pindex and si_xib_next_bit */
 +
++      au_sphl_init(&sbinfo->si_aopen);
++
 +      sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
 +      sbinfo->si_rdblk = AUFS_RDBLK_DEF;
 +      sbinfo->si_rdhash = AUFS_RDHASH_DEF;
 +      sbinfo->si_dirwh = AUFS_DIRWH_DEF;
 +
-+      au_spl_init(&sbinfo->si_plink);
++      for (i = 0; i < AuPlink_NHASH; i++)
++              au_sphl_init(sbinfo->si_plink + i);
 +      init_waitqueue_head(&sbinfo->si_plink_wq);
 +      spin_lock_init(&sbinfo->si_plink_maint_lock);
 +
++      au_sphl_init(&sbinfo->si_files);
++
 +      /* leave other members for sysaufs and si_mnt. */
 +      sbinfo->si_sb = sb;
 +      sb->s_fs_info = sbinfo;
 +      si_pid_set(sb);
-+      au_debug_sbinfo_init(sbinfo);
 +      return 0; /* success */
 +
 +out_br:
@@ -22824,10 +26436,10 @@ diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
 +}
 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
 --- /usr/share/empty/fs/aufs/spl.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/spl.h        2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,62 @@
++++ linux/fs/aufs/spl.h        2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,111 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -22840,8 +26452,7 @@ diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -22886,14 +26497,64 @@ diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
 +      spin_unlock(&spl->spin);
 +}
 +
++/* ---------------------------------------------------------------------- */
++
++struct au_sphlhead {
++      spinlock_t              spin;
++      struct hlist_head       head;
++};
++
++static inline void au_sphl_init(struct au_sphlhead *sphl)
++{
++      spin_lock_init(&sphl->spin);
++      INIT_HLIST_HEAD(&sphl->head);
++}
++
++static inline void au_sphl_add(struct hlist_node *hlist,
++                             struct au_sphlhead *sphl)
++{
++      spin_lock(&sphl->spin);
++      hlist_add_head(hlist, &sphl->head);
++      spin_unlock(&sphl->spin);
++}
++
++static inline void au_sphl_del(struct hlist_node *hlist,
++                             struct au_sphlhead *sphl)
++{
++      spin_lock(&sphl->spin);
++      hlist_del(hlist);
++      spin_unlock(&sphl->spin);
++}
++
++static inline void au_sphl_del_rcu(struct hlist_node *hlist,
++                                 struct au_sphlhead *sphl)
++{
++      spin_lock(&sphl->spin);
++      hlist_del_rcu(hlist);
++      spin_unlock(&sphl->spin);
++}
++
++static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
++{
++      unsigned long cnt;
++      struct hlist_node *pos;
++
++      cnt = 0;
++      spin_lock(&sphl->spin);
++      hlist_for_each(pos, &sphl->head)
++              cnt++;
++      spin_unlock(&sphl->spin);
++      return cnt;
++}
++
 +#endif /* __KERNEL__ */
 +#endif /* __AUFS_SPL_H__ */
 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 --- /usr/share/empty/fs/aufs/super.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/super.c      2013-03-14 20:07:41.221457313 +0100
-@@ -0,0 +1,993 @@
++++ linux/fs/aufs/super.c      2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,1007 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -22906,8 +26567,7 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -22915,11 +26575,9 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 + */
 +
 +#include <linux/mm.h>
-+#include <linux/module.h>
 +#include <linux/seq_file.h>
 +#include <linux/statfs.h>
 +#include <linux/vmalloc.h>
-+#include <linux/writeback.h>
 +#include "aufs.h"
 +
 +/*
@@ -22991,25 +26649,21 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +      struct path path;
 +      struct au_hdentry *hdp;
 +      struct au_branch *br;
-+      char *perm;
++      au_br_perm_str_t perm;
 +
 +      err = 0;
 +      bend = au_sbend(sb);
 +      hdp = au_di(sb->s_root)->di_hdentry;
 +      for (bindex = 0; !err && bindex <= bend; bindex++) {
 +              br = au_sbr(sb, bindex);
-+              path.mnt = br->br_mnt;
++              path.mnt = au_br_mnt(br);
 +              path.dentry = hdp[bindex].hd_dentry;
 +              err = au_seq_path(seq, &path);
 +              if (err > 0) {
-+                      perm = au_optstr_br_perm(br->br_perm);
-+                      if (perm) {
-+                              err = seq_printf(seq, "=%s", perm);
-+                              kfree(perm);
-+                              if (err == -1)
-+                                      err = -E2BIG;
-+                      } else
-+                              err = -ENOMEM;
++                      au_optstr_br_perm(&perm, br->br_perm);
++                      err = seq_printf(seq, "=%s", perm.a);
++                      if (err == -1)
++                              err = -E2BIG;
 +              }
 +              if (!err && bindex != bend)
 +                      err = seq_putc(seq, ':');
@@ -23025,14 +26679,14 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +
 +      AuRwMustAnyLock(&sbinfo->si_rwsem);
 +
-+      seq_printf(m, ",create=");
++      seq_puts(m, ",create=");
 +      pat = au_optstr_wbr_create(v);
 +      switch (v) {
 +      case AuWbrCreate_TDP:
 +      case AuWbrCreate_RR:
 +      case AuWbrCreate_MFS:
 +      case AuWbrCreate_PMFS:
-+              seq_printf(m, pat);
++              seq_puts(m, pat);
 +              break;
 +      case AuWbrCreate_MFSV:
 +              seq_printf(m, /*pat*/"mfs:%lu",
@@ -23054,6 +26708,16 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +                         jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
 +                         / MSEC_PER_SEC);
 +              break;
++      case AuWbrCreate_PMFSRR:
++              seq_printf(m, /*pat*/"pmfsrr:%llu",
++                         sbinfo->si_wbr_mfs.mfsrr_watermark);
++              break;
++      case AuWbrCreate_PMFSRRV:
++              seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
++                         sbinfo->si_wbr_mfs.mfsrr_watermark,
++                         jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
++                         / MSEC_PER_SEC);
++              break;
 +      }
 +}
 +
@@ -23085,7 +26749,7 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +              hdp = au_di(sb->s_root)->di_hdentry;
 +              h_root = hdp[0 + bindex].hd_dentry;
 +      }
-+      d = f->f_dentry;
++      d = f->f_path.dentry;
 +      name = &d->d_name;
 +      /* safe ->d_parent because the file is unlinked */
 +      if (d->d_parent == h_root
@@ -23126,8 +26790,11 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +              seq_printf(m, "," #str "=%u", val); \
 +} while (0)
 +
-+      /* lock free root dinfo */
 +      sb = dentry->d_sb;
++      if (sb->s_flags & MS_POSIXACL)
++              seq_puts(m, ",acl");
++
++      /* lock free root dinfo */
 +      si_noflush_read_lock(sb);
 +      sbinfo = au_sbi(sb);
 +      seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
@@ -23145,7 +26812,7 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +      AuBool(SHWH, shwh);
 +      AuBool(PLINK, plink);
 +      AuBool(DIO, dio);
-+      /* AuBool(DIRPERM1, dirperm1); */
++      AuBool(DIRPERM1, dirperm1);
 +      /* AuBool(REFROF, refrof); */
 +
 +      v = sbinfo->si_wbr_create;
@@ -23168,6 +26835,8 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +      AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
 +      AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
 +
++      au_fhsm_show(m, sbinfo);
++
 +      AuBool(SUM, sum);
 +      /* AuBool(SUM_W, wsum); */
 +      AuBool(WARN_PERM, warn_perm);
@@ -23369,7 +27038,7 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
 +{
 +      void *array;
-+      unsigned long long n;
++      unsigned long long n, sz;
 +
 +      array = NULL;
 +      n = 0;
@@ -23382,9 +27051,10 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +              goto out;
 +      }
 +
-+      array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
++      sz = sizeof(array) * *hint;
++      array = kzalloc(sz, GFP_NOFS);
 +      if (unlikely(!array))
-+              array = vmalloc(sizeof(array) * *hint);
++              array = vzalloc(sz);
 +      if (unlikely(!array)) {
 +              array = ERR_PTR(-ENOMEM);
 +              goto out;
@@ -23551,6 +27221,8 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +      sigen = au_sigen(sb);
 +      for (ull = 0; ull < max; ull++) {
 +              inode = array[ull];
++              if (unlikely(!inode))
++                      break;
 +              if (au_iigen(inode, NULL) != sigen) {
 +                      ii_write_lock_child(inode);
 +                      e = au_refresh_hinode_self(inode);
@@ -23684,6 +27356,7 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +              au_dy_arefresh(do_dx);
 +      }
 +
++      au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
 +      aufs_write_unlock(root);
 +
 +out_mtx:
@@ -23779,7 +27452,9 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +      sb->s_d_op = &aufs_dop;
 +      sb->s_magic = AUFS_SUPER_MAGIC;
 +      sb->s_maxbytes = 0;
++      sb->s_stack_depth = 1;
 +      au_export_init(sb);
++      /* au_xattr_init(sb); */
 +
 +      err = alloc_root(sb);
 +      if (unlikely(err)) {
@@ -23859,6 +27534,7 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +      if (sbinfo) {
 +              au_sbilist_del(sb);
 +              aufs_write_lock(sb->s_root);
++              au_fhsm_fin(sb);
 +              if (sbinfo->si_wbr_create_ops->fin)
 +                      sbinfo->si_wbr_create_ops->fin(sb);
 +              if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
@@ -23872,14 +27548,13 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +              aufs_write_unlock(sb->s_root);
 +              au_nwt_flush(&sbinfo->si_nowait);
 +      }
-+      generic_shutdown_super(sb);
++      kill_anon_super(sb);
 +}
 +
 +struct file_system_type aufs_fs_type = {
 +      .name           = AUFS_FSTYPE,
-+      .fs_flags       =
-+              FS_RENAME_DOES_D_MOVE   /* a race between rename and others */
-+              | FS_REVAL_DOT,         /* for NFS branch and udba */
++      /* a race between rename and others */
++      .fs_flags       = FS_RENAME_DOES_D_MOVE,
 +      .mount          = aufs_mount,
 +      .kill_sb        = aufs_kill_sb,
 +      /* no need to __module_get() and module_put(). */
@@ -23887,10 +27562,10 @@ diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
 +};
 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 --- /usr/share/empty/fs/aufs/super.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/super.h      2013-03-14 20:07:18.764260309 +0100
-@@ -0,0 +1,538 @@
++++ linux/fs/aufs/super.h      2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,638 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -23903,8 +27578,7 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -23930,8 +27604,15 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      int (*copyup)(struct dentry *dentry);
 +};
 +
++#define AuWbr_DIR     1               /* target is a dir */
++#define AuWbr_PARENT  (1 << 1)        /* always require a parent */
++
++#define au_ftest_wbr(flags, name)     ((flags) & AuWbr_##name)
++#define au_fset_wbr(flags, name)      { (flags) |= AuWbr_##name; }
++#define au_fclr_wbr(flags, name)      { (flags) &= ~AuWbr_##name; }
++
 +struct au_wbr_create_operations {
-+      int (*create)(struct dentry *dentry, int isdir);
++      int (*create)(struct dentry *dentry, unsigned int flags);
 +      int (*init)(struct super_block *sb);
 +      int (*fin)(struct super_block *sb);
 +};
@@ -23946,6 +27627,35 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      unsigned long long      mfsrr_watermark;
 +};
 +
++struct pseudo_link {
++      union {
++              struct hlist_node hlist;
++              struct rcu_head rcu;
++      };
++      struct inode *inode;
++};
++
++#define AuPlink_NHASH 100
++static inline int au_plink_hash(ino_t ino)
++{
++      return ino % AuPlink_NHASH;
++}
++
++/* File-based Hierarchical Storage Management */
++struct au_fhsm {
++#ifdef CONFIG_AUFS_FHSM
++      /* allow only one process who can receive the notification */
++      spinlock_t              fhsm_spin;
++      pid_t                   fhsm_pid;
++      wait_queue_head_t       fhsm_wqh;
++      atomic_t                fhsm_readable;
++
++      /* these are protected by si_rwsem */
++      unsigned long           fhsm_expire;
++      aufs_bindex_t           fhsm_bottom;
++#endif
++};
++
 +struct au_branch;
 +struct au_sbinfo {
 +      /* nowait tasks in the system-wide workqueue */
@@ -23965,14 +27675,15 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      } au_si_pid;
 +
 +      /*
-+       * dirty approach to protect sb->sb_inodes and ->s_files from remount.
++       * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
++       * remount.
 +       */
 +      atomic_long_t           si_ninodes, si_nfiles;
 +
 +      /* branch management */
 +      unsigned int            si_generation;
 +
-+      /* see above flags */
++      /* see AuSi_ flags */
 +      unsigned char           au_si_status;
 +
 +      aufs_bindex_t           si_bend;
@@ -23994,6 +27705,9 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      /* most free space */
 +      struct au_wbr_mfs       si_wbr_mfs;
 +
++      /* File-based Hierarchical Storage Management */
++      struct au_fhsm          si_fhsm;
++
 +      /* mount flags */
 +      /* include/asm-ia64/siginfo.h defines a macro named si_flags */
 +      unsigned int            si_mntflags;
@@ -24007,6 +27721,8 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      unsigned long           si_xib_last_pindex;
 +      int                     si_xib_next_bit;
 +      aufs_bindex_t           si_xino_brid;
++      unsigned long           si_xino_jiffy;
++      unsigned long           si_xino_expire;
 +      /* reserved for future use */
 +      /* unsigned long long   si_xib_limit; */        /* Max xib file size */
 +
@@ -24016,6 +27732,9 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      atomic_t                si_xigen_next;
 +#endif
 +
++      /* dirty trick to suppoer atomic_open */
++      struct au_sphlhead      si_aopen;
++
 +      /* vdir parameters */
 +      unsigned long           si_rdcache;     /* max cache time in jiffies */
 +      unsigned int            si_rdblk;       /* deblk size */
@@ -24029,18 +27748,15 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +       */
 +      unsigned int            si_dirwh;
 +
-+      /*
-+       * rename(2) a directory with all children.
-+       */
-+      /* reserved for future use */
-+      /* int                  si_rendir; */
-+
 +      /* pseudo_link list */
-+      struct au_splhead       si_plink;
++      struct au_sphlhead      si_plink[AuPlink_NHASH];
 +      wait_queue_head_t       si_plink_wq;
 +      spinlock_t              si_plink_maint_lock;
 +      pid_t                   si_plink_maint_pid;
 +
++      /* file list */
++      struct au_sphlhead      si_files;
++
 +      /*
 +       * sysfs and lifetime management.
 +       * this is not a small structure and it may be a waste of memory in case
@@ -24049,7 +27765,9 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +       */
 +      struct kobject          si_kobj;
 +#ifdef CONFIG_DEBUG_FS
-+      struct dentry            *si_dbgaufs, *si_dbgaufs_xib;
++      struct dentry            *si_dbgaufs;
++      struct dentry            *si_dbgaufs_plink;
++      struct dentry            *si_dbgaufs_xib;
 +#ifdef CONFIG_AUFS_EXPORT
 +      struct dentry            *si_dbgaufs_xigen;
 +#endif
@@ -24070,6 +27788,14 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 + * if it is false, refreshing dirs at access time is unnecesary
 + */
 +#define AuSi_FAILED_REFRESH_DIR       1
++
++#define AuSi_FHSM             (1 << 1)        /* fhsm is active now */
++
++#ifndef CONFIG_AUFS_FHSM
++#undef AuSi_FHSM
++#define AuSi_FHSM             0
++#endif
++
 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
 +                                         unsigned int flag)
 +{
@@ -24146,6 +27872,48 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
 +extern struct au_wbr_create_operations au_wbr_create_ops[];
 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
++int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
++int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
++
++/* mvdown.c */
++int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
++
++#ifdef CONFIG_AUFS_FHSM
++/* fhsm.c */
++
++static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
++{
++      pid_t pid;
++
++      spin_lock(&fhsm->fhsm_spin);
++      pid = fhsm->fhsm_pid;
++      spin_unlock(&fhsm->fhsm_spin);
++
++      return pid;
++}
++
++void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
++void au_fhsm_wrote_all(struct super_block *sb, int force);
++int au_fhsm_fd(struct super_block *sb, int oflags);
++int au_fhsm_br_alloc(struct au_branch *br);
++void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
++void au_fhsm_fin(struct super_block *sb);
++void au_fhsm_init(struct au_sbinfo *sbinfo);
++void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
++void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
++#else
++AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
++         int force)
++AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
++AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
++AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
++AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
++AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
++AuStubVoid(au_fhsm_fin, struct super_block *sb)
++AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
++AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
++AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
++#endif
 +
 +/* ---------------------------------------------------------------------- */
 +
@@ -24177,10 +27945,7 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +AuStubInt0(au_xigen_new, struct inode *inode)
 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
 +AuStubVoid(au_xigen_clr, struct super_block *sb)
-+static inline int au_busy_or_stale(void)
-+{
-+      return -EBUSY;
-+}
++AuStub(int, au_busy_or_stale, return -EBUSY, void)
 +#endif /* CONFIG_AUFS_EXPORT */
 +
 +/* ---------------------------------------------------------------------- */
@@ -24222,8 +27987,8 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
 +#else
 +AuStubVoid(au_sbilist_init, void)
-+AuStubVoid(au_sbilist_add, struct super_block*)
-+AuStubVoid(au_sbilist_del, struct super_block*)
++AuStubVoid(au_sbilist_add, struct super_block *sb)
++AuStubVoid(au_sbilist_del, struct super_block *sb)
 +AuStubVoid(au_sbilist_lock, void)
 +AuStubVoid(au_sbilist_unlock, void)
 +#define AuGFP_SBILIST GFP_NOFS
@@ -24234,12 +27999,13 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
 +{
 +      /*
-+       * This function is a dynamic '__init' fucntion actually,
++       * This function is a dynamic '__init' function actually,
 +       * so the tiny check for si_rwsem is unnecessary.
 +       */
 +      /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
 +#ifdef CONFIG_DEBUG_FS
 +      sbinfo->si_dbgaufs = NULL;
++      sbinfo->si_dbgaufs_plink = NULL;
 +      sbinfo->si_dbgaufs_xib = NULL;
 +#ifdef CONFIG_AUFS_EXPORT
 +      sbinfo->si_dbgaufs_xigen = NULL;
@@ -24257,16 +28023,19 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +
 +static inline int si_pid_test(struct super_block *sb)
 +{
-+      pid_t bit = si_pid_bit();
++      pid_t bit;
++
++      bit = si_pid_bit();
 +      if (bit < PID_MAX_DEFAULT)
 +              return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
-+      else
-+              return si_pid_test_slow(sb);
++      return si_pid_test_slow(sb);
 +}
 +
 +static inline void si_pid_set(struct super_block *sb)
 +{
-+      pid_t bit = si_pid_bit();
++      pid_t bit;
++
++      bit = si_pid_bit();
 +      if (bit < PID_MAX_DEFAULT) {
 +              AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
 +              set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
@@ -24277,7 +28046,9 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +
 +static inline void si_pid_clr(struct super_block *sb)
 +{
-+      pid_t bit = si_pid_bit();
++      pid_t bit;
++
++      bit = si_pid_bit();
 +      if (bit < PID_MAX_DEFAULT) {
 +              AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
 +              clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
@@ -24307,7 +28078,9 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +
 +static inline int si_noflush_read_trylock(struct super_block *sb)
 +{
-+      int locked = __si_read_trylock(sb);
++      int locked;
++
++      locked = __si_read_trylock(sb);
 +      if (locked)
 +              si_pid_set(sb);
 +      return locked;
@@ -24321,13 +28094,15 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +
 +static inline int si_noflush_write_trylock(struct super_block *sb)
 +{
-+      int locked = __si_write_trylock(sb);
++      int locked;
++
++      locked = __si_write_trylock(sb);
 +      if (locked)
 +              si_pid_set(sb);
 +      return locked;
 +}
 +
-+#if 0 /* unused */
++#if 0 /* reserved */
 +static inline int si_read_trylock(struct super_block *sb, int flags)
 +{
 +      if (au_ftest_lock(flags, FLUSH))
@@ -24342,7 +28117,7 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      __si_read_unlock(sb);
 +}
 +
-+#if 0 /* unused */
++#if 0 /* reserved */
 +static inline int si_write_trylock(struct super_block *sb, int flags)
 +{
 +      if (au_ftest_lock(flags, FLUSH))
@@ -24357,7 +28132,7 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +      __si_write_unlock(sb);
 +}
 +
-+#if 0 /* unused */
++#if 0 /* reserved */
 +static inline void si_downgrade_lock(struct super_block *sb)
 +{
 +      __si_downgrade_lock(sb);
@@ -24429,10 +28204,10 @@ diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
 +#endif /* __AUFS_SUPER_H__ */
 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysaufs.c    2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,105 @@
++++ linux/fs/aufs/sysaufs.c    2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,104 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -24445,8 +28220,7 @@ diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -24538,10 +28312,10 @@ diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
 +}
 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysaufs.h    2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,104 @@
++++ linux/fs/aufs/sysaufs.h    2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,101 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -24554,8 +28328,7 @@ diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -24612,6 +28385,10 @@ diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
 +                       char *buf);
++long au_brinfo_ioctl(struct file *file, unsigned long arg);
++#ifdef CONFIG_COMPAT
++long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
++#endif
 +
 +void sysaufs_br_init(struct au_branch *br);
 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
@@ -24623,14 +28400,8 @@ diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
 +#define sysaufs_attr_group    NULL
 +
 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
-+
-+static inline
-+ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
-+                       char *buf)
-+{
-+      return 0;
-+}
-+
++AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
++       struct attribute *attr, char *buf)
 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
@@ -24646,10 +28417,10 @@ diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
 +#endif /* __SYSAUFS_H__ */
 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 --- /usr/share/empty/fs/aufs/sysfs.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysfs.c      2013-02-19 08:40:03.950226347 +0100
-@@ -0,0 +1,257 @@
++++ linux/fs/aufs/sysfs.c      2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,372 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -24662,14 +28433,14 @@ diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
 + * sysfs interface
 + */
 +
++#include <linux/compat.h>
 +#include <linux/seq_file.h>
 +#include "aufs.h"
 +
@@ -24728,13 +28499,13 @@ diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 + * unlinked.
 + */
 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
-+                       aufs_bindex_t bindex)
++                       aufs_bindex_t bindex, int idx)
 +{
 +      int err;
 +      struct path path;
 +      struct dentry *root;
 +      struct au_branch *br;
-+      char *perm;
++      au_br_perm_str_t perm;
 +
 +      AuDbg("b%d\n", bindex);
 +
@@ -24742,18 +28513,23 @@ diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 +      root = sb->s_root;
 +      di_read_lock_parent(root, !AuLock_IR);
 +      br = au_sbr(sb, bindex);
-+      path.mnt = br->br_mnt;
-+      path.dentry = au_h_dptr(root, bindex);
-+      au_seq_path(seq, &path);
++
++      switch (idx) {
++      case AuBrSysfs_BR:
++              path.mnt = au_br_mnt(br);
++              path.dentry = au_h_dptr(root, bindex);
++              au_seq_path(seq, &path);
++              au_optstr_br_perm(&perm, br->br_perm);
++              err = seq_printf(seq, "=%s\n", perm.a);
++              break;
++      case AuBrSysfs_BRID:
++              err = seq_printf(seq, "%d\n", br->br_id);
++              break;
++      }
 +      di_read_unlock(root, !AuLock_IR);
-+      perm = au_optstr_br_perm(br->br_perm);
-+      if (perm) {
-+              err = seq_printf(seq, "=%s\n", perm);
-+              kfree(perm);
-+              if (err == -1)
-+                      err = -E2BIG;
-+      } else
-+              err = -ENOMEM;
++      if (err == -1)
++              err = -E2BIG;
++
 +      return err;
 +}
 +
@@ -24775,13 +28551,15 @@ diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 +      return seq;
 +}
 +
-+#define SysaufsBr_PREFIX "br"
++#define SysaufsBr_PREFIX      "br"
++#define SysaufsBrid_PREFIX    "brid"
 +
 +/* todo: file size may exceed PAGE_SIZE */
 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
 +                      char *buf)
 +{
 +      ssize_t err;
++      int idx;
 +      long l;
 +      aufs_bindex_t bend;
 +      struct au_sbinfo *sbinfo;
@@ -24823,49 +28601,146 @@ diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 +              cattr++;
 +      }
 +
-+      bend = au_sbend(sb);
-+      if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
++      if (!strncmp(name, SysaufsBrid_PREFIX,
++                   sizeof(SysaufsBrid_PREFIX) - 1)) {
++              idx = AuBrSysfs_BRID;
++              name += sizeof(SysaufsBrid_PREFIX) - 1;
++      } else if (!strncmp(name, SysaufsBr_PREFIX,
++                          sizeof(SysaufsBr_PREFIX) - 1)) {
++              idx = AuBrSysfs_BR;
 +              name += sizeof(SysaufsBr_PREFIX) - 1;
-+              err = kstrtol(name, 10, &l);
-+              if (!err) {
-+                      if (l <= bend)
-+                              err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l);
-+                      else
-+                              err = -ENOENT;
++      } else
++                BUG();
++
++      err = kstrtol(name, 10, &l);
++      if (!err) {
++              bend = au_sbend(sb);
++              if (l <= bend)
++                      err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
++              else
++                      err = -ENOENT;
++      }
++
++out_seq:
++      if (!err) {
++              err = seq->count;
++              /* sysfs limit */
++              if (unlikely(err == PAGE_SIZE))
++                      err = -EFBIG;
++      }
++      kfree(seq);
++out_unlock:
++      si_read_unlock(sb);
++out:
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
++{
++      int err;
++      int16_t brid;
++      aufs_bindex_t bindex, bend;
++      size_t sz;
++      char *buf;
++      struct seq_file *seq;
++      struct au_branch *br;
++
++      si_read_lock(sb, AuLock_FLUSH);
++      bend = au_sbend(sb);
++      err = bend + 1;
++      if (!arg)
++              goto out;
++
++      err = -ENOMEM;
++      buf = (void *)__get_free_page(GFP_NOFS);
++      if (unlikely(!buf))
++              goto out;
++
++      seq = au_seq(buf, PAGE_SIZE);
++      err = PTR_ERR(seq);
++      if (IS_ERR(seq))
++              goto out_buf;
++
++      sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
++      for (bindex = 0; bindex <= bend; bindex++, arg++) {
++              err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
++              if (unlikely(err))
++                      break;
++
++              br = au_sbr(sb, bindex);
++              brid = br->br_id;
++              BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
++              err = __put_user(brid, &arg->id);
++              if (unlikely(err))
++                      break;
++
++              BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
++              err = __put_user(br->br_perm, &arg->perm);
++              if (unlikely(err))
++                      break;
++
++              au_seq_path(seq, &br->br_path);
++              err = seq_putc(seq, '\0');
++              if (!err && seq->count <= sz) {
++                      err = copy_to_user(arg->path, seq->buf, seq->count);
++                      seq->count = 0;
++                      if (unlikely(err))
++                              break;
++              } else {
++                      err = -E2BIG;
++                      goto out_seq;
 +              }
-+              goto out_seq;
 +      }
-+      BUG();
++      if (unlikely(err))
++              err = -EFAULT;
 +
 +out_seq:
-+      if (!err) {
-+              err = seq->count;
-+              /* sysfs limit */
-+              if (unlikely(err == PAGE_SIZE))
-+                      err = -EFBIG;
-+      }
 +      kfree(seq);
-+out_unlock:
-+      si_read_unlock(sb);
++out_buf:
++      free_page((unsigned long)buf);
 +out:
++      si_read_unlock(sb);
 +      return err;
 +}
 +
++long au_brinfo_ioctl(struct file *file, unsigned long arg)
++{
++      return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
++}
++
++#ifdef CONFIG_COMPAT
++long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
++{
++      return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
++}
++#endif
++
 +/* ---------------------------------------------------------------------- */
 +
 +void sysaufs_br_init(struct au_branch *br)
 +{
-+      struct attribute *attr = &br->br_attr;
++      int i;
++      struct au_brsysfs *br_sysfs;
++      struct attribute *attr;
 +
-+      sysfs_attr_init(attr);
-+      attr->name = br->br_name;
-+      attr->mode = S_IRUGO;
++      br_sysfs = br->br_sysfs;
++      for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
++              attr = &br_sysfs->attr;
++              sysfs_attr_init(attr);
++              attr->name = br_sysfs->name;
++              attr->mode = S_IRUGO;
++              br_sysfs++;
++      }
 +}
 +
 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
 +{
 +      struct au_branch *br;
 +      struct kobject *kobj;
++      struct au_brsysfs *br_sysfs;
++      int i;
 +      aufs_bindex_t bend;
 +
 +      dbgaufs_brs_del(sb, bindex);
@@ -24877,16 +28752,21 @@ diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 +      bend = au_sbend(sb);
 +      for (; bindex <= bend; bindex++) {
 +              br = au_sbr(sb, bindex);
-+              sysfs_remove_file(kobj, &br->br_attr);
++              br_sysfs = br->br_sysfs;
++              for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
++                      sysfs_remove_file(kobj, &br_sysfs->attr);
++                      br_sysfs++;
++              }
 +      }
 +}
 +
 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
 +{
-+      int err;
++      int err, i;
 +      aufs_bindex_t bend;
 +      struct kobject *kobj;
 +      struct au_branch *br;
++      struct au_brsysfs *br_sysfs;
 +
 +      dbgaufs_brs_add(sb, bindex);
 +
@@ -24897,20 +28777,26 @@ diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
 +      bend = au_sbend(sb);
 +      for (; bindex <= bend; bindex++) {
 +              br = au_sbr(sb, bindex);
-+              snprintf(br->br_name, sizeof(br->br_name), SysaufsBr_PREFIX
-+                       "%d", bindex);
-+              err = sysfs_create_file(kobj, &br->br_attr);
-+              if (unlikely(err))
-+                      pr_warn("failed %s under sysfs(%d)\n",
-+                              br->br_name, err);
++              br_sysfs = br->br_sysfs;
++              snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
++                       SysaufsBr_PREFIX "%d", bindex);
++              snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
++                       SysaufsBrid_PREFIX "%d", bindex);
++              for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
++                      err = sysfs_create_file(kobj, &br_sysfs->attr);
++                      if (unlikely(err))
++                              pr_warn("failed %s under sysfs(%d)\n",
++                                      br_sysfs->name, err);
++                      br_sysfs++;
++              }
 +      }
 +}
 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
 --- /usr/share/empty/fs/aufs/sysrq.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysrq.c      2013-03-14 20:07:41.221457313 +0100
-@@ -0,0 +1,148 @@
++++ linux/fs/aufs/sysrq.c      2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,157 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -24923,8 +28809,7 @@ diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -24942,20 +28827,24 @@ diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
 +      char *plevel;
 +      struct au_sbinfo *sbinfo;
 +      struct file *file;
++      struct au_sphlhead *files;
++      struct au_finfo *finfo;
 +
 +      plevel = au_plevel;
 +      au_plevel = KERN_WARNING;
 +
-+      sbinfo = au_sbi(sb);
 +      /* since we define pr_fmt, call printk directly */
++#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
++
++      sbinfo = au_sbi(sb);
 +      printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
-+      printk(KERN_WARNING AUFS_NAME ": superblock\n");
++      pr("superblock\n");
 +      au_dpri_sb(sb);
 +
 +#if 0
-+      printk(KERN_WARNING AUFS_NAME ": root dentry\n");
++      pr("root dentry\n");
 +      au_dpri_dentry(sb->s_root);
-+      printk(KERN_WARNING AUFS_NAME ": root inode\n");
++      pr("root inode\n");
 +      au_dpri_inode(sb->s_root->d_inode);
 +#endif
 +
@@ -24983,7 +28872,8 @@ diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
 +#if 1
 +      {
 +              struct inode *i;
-+              printk(KERN_WARNING AUFS_NAME ": isolated inode\n");
++
++              pr("isolated inode\n");
 +              spin_lock(&inode_sb_list_lock);
 +              list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
 +                      spin_lock(&i->i_lock);
@@ -24994,17 +28884,21 @@ diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
 +              spin_unlock(&inode_sb_list_lock);
 +      }
 +#endif
-+      printk(KERN_WARNING AUFS_NAME ": files\n");
-+      lg_global_lock(&files_lglock);
-+      do_file_list_for_each_entry(sb, file) {
++      pr("files\n");
++      files = &au_sbi(sb)->si_files;
++      spin_lock(&files->spin);
++      hlist_for_each_entry(finfo, &files->head, fi_hlist) {
 +              umode_t mode;
-+              mode = file->f_dentry->d_inode->i_mode;
-+              if (!special_file(mode) || au_special_file(mode))
++
++              file = finfo->fi_file;
++              mode = file_inode(file)->i_mode;
++              if (!special_file(mode))
 +                      au_dpri_file(file);
-+      } while_file_list_for_each_entry;
-+      lg_global_unlock(&files_lglock);
-+      printk(KERN_WARNING AUFS_NAME ": done\n");
++      }
++      spin_unlock(&files->spin);
++      pr("done\n");
 +
++#undef pr
 +      au_plevel = plevel;
 +}
 +
@@ -25053,16 +28947,17 @@ diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
 +void au_sysrq_fin(void)
 +{
 +      int err;
++
 +      err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
 +      if (unlikely(err))
 +              pr_err("err %d (ignored)\n", err);
 +}
 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 --- /usr/share/empty/fs/aufs/vdir.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/vdir.c       2013-03-14 20:07:41.221457313 +0100
-@@ -0,0 +1,885 @@
++++ linux/fs/aufs/vdir.c       2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,888 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -25075,8 +28970,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -25140,8 +29034,10 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +{
 +      struct hlist_head *head;
 +      unsigned int u;
++      size_t sz;
 +
-+      head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
++      sz = sizeof(*nhash->nh_head) * num_hash;
++      head = kmalloc(sz, gfp);
 +      if (head) {
 +              nhash->nh_num = num_hash;
 +              nhash->nh_head = head;
@@ -25168,24 +29064,20 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +
 +static void au_nhash_wh_do_free(struct hlist_head *head)
 +{
-+      struct au_vdir_wh *tpos;
-+      struct hlist_node *pos, *node;
++      struct au_vdir_wh *pos;
++      struct hlist_node *node;
 +
-+      hlist_for_each_entry_safe(tpos, pos, node, head, wh_hash) {
-+              /* hlist_del(pos); */
-+              kfree(tpos);
-+      }
++      hlist_for_each_entry_safe(pos, node, head, wh_hash)
++              kfree(pos);
 +}
 +
 +static void au_nhash_de_do_free(struct hlist_head *head)
 +{
-+      struct au_vdir_dehstr *tpos;
-+      struct hlist_node *pos, *node;
++      struct au_vdir_dehstr *pos;
++      struct hlist_node *node;
 +
-+      hlist_for_each_entry_safe(tpos, pos, node, head, hash) {
-+              /* hlist_del(pos); */
-+              au_cache_free_vdir_dehstr(tpos);
-+      }
++      hlist_for_each_entry_safe(pos, node, head, hash)
++              au_cache_free_vdir_dehstr(pos);
 +}
 +
 +static void au_nhash_do_free(struct au_nhash *nhash,
@@ -25224,15 +29116,14 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      int num;
 +      unsigned int u, n;
 +      struct hlist_head *head;
-+      struct au_vdir_wh *tpos;
-+      struct hlist_node *pos;
++      struct au_vdir_wh *pos;
 +
 +      num = 0;
 +      n = whlist->nh_num;
 +      head = whlist->nh_head;
 +      for (u = 0; u < n; u++, head++)
-+              hlist_for_each_entry(tpos, pos, head, wh_hash)
-+                      if (tpos->wh_bindex == btgt && ++num > limit)
++              hlist_for_each_entry(pos, head, wh_hash)
++                      if (pos->wh_bindex == btgt && ++num > limit)
 +                              return 1;
 +      return 0;
 +}
@@ -25264,13 +29155,12 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
 +{
 +      struct hlist_head *head;
-+      struct au_vdir_wh *tpos;
-+      struct hlist_node *pos;
++      struct au_vdir_wh *pos;
 +      struct au_vdir_destr *str;
 +
 +      head = au_name_hash(whlist, name, nlen);
-+      hlist_for_each_entry(tpos, pos, head, wh_hash) {
-+              str = &tpos->wh_str;
++      hlist_for_each_entry(pos, head, wh_hash) {
++              str = &pos->wh_str;
 +              AuDbg("%.*s\n", str->len, str->name);
 +              if (au_nhash_test_name(str, name, nlen))
 +                      return 1;
@@ -25282,13 +29172,12 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +static int test_known(struct au_nhash *delist, char *name, int nlen)
 +{
 +      struct hlist_head *head;
-+      struct au_vdir_dehstr *tpos;
-+      struct hlist_node *pos;
++      struct au_vdir_dehstr *pos;
 +      struct au_vdir_destr *str;
 +
 +      head = au_name_hash(delist, name, nlen);
-+      hlist_for_each_entry(tpos, pos, head, hash) {
-+              str = tpos->str;
++      hlist_for_each_entry(pos, head, hash) {
++              str = pos->str;
 +              AuDbg("%.*s\n", str->len, str->name);
 +              if (au_nhash_test_name(str, name, nlen))
 +                      return 1;
@@ -25434,7 +29323,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      struct super_block *sb;
 +      int err;
 +
-+      sb = file->f_dentry->d_sb;
++      sb = file->f_path.dentry->d_sb;
 +      SiMustAnyLock(sb);
 +
 +      err = -ENOMEM;
@@ -25507,6 +29396,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +#endif
 +
 +struct fillvdir_arg {
++      struct dir_context      ctx;
 +      struct file             *file;
 +      struct au_vdir          *vdir;
 +      struct au_nhash         delist;
@@ -25516,18 +29406,18 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      int                     err;
 +};
 +
-+static int fillvdir(void *__arg, const char *__name, int nlen,
++static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
 +                  loff_t offset __maybe_unused, u64 h_ino,
 +                  unsigned int d_type)
 +{
-+      struct fillvdir_arg *arg = __arg;
++      struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
 +      char *name = (void *)__name;
 +      struct super_block *sb;
 +      ino_t ino;
 +      const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
 +
 +      arg->err = 0;
-+      sb = arg->file->f_dentry->d_sb;
++      sb = arg->file->f_path.dentry->d_sb;
 +      au_fset_fillvdir(arg->flags, CALLED);
 +      /* smp_mb(); */
 +      if (nlen <= AUFS_WH_PFX_LEN
@@ -25536,7 +29426,6 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +                  || au_nhash_test_known_wh(&arg->whlist, name, nlen))
 +                      goto out; /* already exists or whiteouted */
 +
-+              sb = arg->file->f_dentry->d_sb;
 +              arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
 +              if (!arg->err) {
 +                      if (unlikely(nlen > AUFS_MAX_NAMELEN))
@@ -25577,8 +29466,8 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      int err;
 +      unsigned int nh, u;
 +      struct hlist_head *head;
-+      struct au_vdir_wh *tpos;
-+      struct hlist_node *pos, *n;
++      struct au_vdir_wh *pos;
++      struct hlist_node *n;
 +      char *p, *o;
 +      struct au_vdir_destr *destr;
 +
@@ -25595,11 +29484,11 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      p += AUFS_WH_PFX_LEN;
 +      for (u = 0; u < nh; u++) {
 +              head = whlist->nh_head + u;
-+              hlist_for_each_entry_safe(tpos, pos, n, head, wh_hash) {
-+                      destr = &tpos->wh_str;
++              hlist_for_each_entry_safe(pos, n, head, wh_hash) {
++                      destr = &pos->wh_str;
 +                      memcpy(p, destr->name, destr->len);
 +                      err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
-+                                      tpos->wh_ino, tpos->wh_type, delist);
++                                      pos->wh_ino, pos->wh_type, delist);
 +                      if (unlikely(err))
 +                              break;
 +              }
@@ -25626,7 +29515,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      struct super_block *sb;
 +
 +      file = arg->file;
-+      sb = file->f_dentry->d_sb;
++      sb = file->f_path.dentry->d_sb;
 +      SiMustAnyLock(sb);
 +
 +      rdhash = au_sbi(sb)->si_rdhash;
@@ -25668,10 +29557,15 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +                      arg->err = 0;
 +                      au_fclr_fillvdir(arg->flags, CALLED);
 +                      /* smp_mb(); */
-+                      err = vfsub_readdir(hf, fillvdir, arg);
++                      err = vfsub_iterate_dir(hf, &arg->ctx);
 +                      if (err >= 0)
 +                              err = arg->err;
 +              } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
++
++              /*
++               * dir_relax() may be good for concurrency, but aufs should not
++               * use it since it will cause a lockdep problem.
++               */
 +      }
 +
 +      if (!err && shwh)
@@ -25690,12 +29584,16 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      int err;
 +      unsigned long expire;
 +      unsigned char do_read;
-+      struct fillvdir_arg arg;
++      struct fillvdir_arg arg = {
++              .ctx = {
++                      .actor = fillvdir
++              }
++      };
 +      struct inode *inode;
 +      struct au_vdir *vdir, *allocated;
 +
 +      err = 0;
-+      inode = file->f_dentry->d_inode;
++      inode = file_inode(file);
 +      IMustLock(inode);
 +      SiMustAnyLock(inode->i_sb);
 +
@@ -25727,7 +29625,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      arg.vdir = vdir;
 +      err = au_do_read_vdir(&arg);
 +      if (!err) {
-+              /* file->f_pos = 0; */
++              /* file->f_pos = 0; */ /* todo: ctx->pos? */
 +              vdir->vd_version = inode->i_version;
 +              vdir->vd_last.ul = 0;
 +              vdir->vd_last.p.deblk = vdir->vd_deblk[0];
@@ -25800,6 +29698,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      struct inode *inode;
 +      struct au_vdir *vdir_cache, *allocated;
 +
++      /* test file->f_pos here instead of ctx->pos */
 +      err = read_vdir(file, !file->f_pos);
 +      if (unlikely(err))
 +              goto out;
@@ -25813,13 +29712,14 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +                      goto out;
 +              allocated = vdir_cache;
 +      } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
++              /* test file->f_pos here instead of ctx->pos */
 +              err = reinit_vdir(vdir_cache);
 +              if (unlikely(err))
 +                      goto out;
 +      } else
 +              return 0; /* success */
 +
-+      inode = file->f_dentry->d_inode;
++      inode = file_inode(file);
 +      err = copy_vdir(vdir_cache, au_ivdir(inode));
 +      if (!err) {
 +              file->f_version = inode->i_version;
@@ -25844,7 +29744,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +}
 +
 +/* returns true or false */
-+static int seek_vdir(struct file *file)
++static int seek_vdir(struct file *file, struct dir_context *ctx)
 +{
 +      int valid;
 +      unsigned int deblk_sz;
@@ -25857,17 +29757,17 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      vdir_cache = au_fvdir_cache(file);
 +      offset = calc_offset(vdir_cache);
 +      AuDbg("offset %lld\n", offset);
-+      if (file->f_pos == offset)
++      if (ctx->pos == offset)
 +              goto out;
 +
 +      vdir_cache->vd_last.ul = 0;
 +      vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
-+      if (!file->f_pos)
++      if (!ctx->pos)
 +              goto out;
 +
 +      valid = 0;
 +      deblk_sz = vdir_cache->vd_deblk_sz;
-+      ul = div64_u64(file->f_pos, deblk_sz);
++      ul = div64_u64(ctx->pos, deblk_sz);
 +      AuDbg("ul %lu\n", ul);
 +      if (ul >= vdir_cache->vd_nblk)
 +              goto out;
@@ -25878,7 +29778,7 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +              deblk_end.deblk = p.deblk + deblk_sz;
 +              offset = ul;
 +              offset *= deblk_sz;
-+              while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
++              while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
 +                      unsigned int l;
 +
 +                      l = calc_size(p.de->de_str.len);
@@ -25899,16 +29799,15 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +      return valid;
 +}
 +
-+int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
++int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
 +{
-+      int err;
 +      unsigned int l, deblk_sz;
 +      union au_vdir_deblk_p deblk_end;
 +      struct au_vdir *vdir_cache;
 +      struct au_vdir_de *de;
 +
 +      vdir_cache = au_fvdir_cache(file);
-+      if (!seek_vdir(file))
++      if (!seek_vdir(file, ctx))
 +              return 0;
 +
 +      deblk_sz = vdir_cache->vd_deblk_sz;
@@ -25918,12 +29817,11 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +              while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
 +                      de = vdir_cache->vd_last.p.de;
 +                      AuDbg("%.*s, off%lld, i%lu, dt%d\n",
-+                            de->de_str.len, de->de_str.name, file->f_pos,
++                            de->de_str.len, de->de_str.name, ctx->pos,
 +                            (unsigned long)de->de_ino, de->de_type);
-+                      err = filldir(dirent, de->de_str.name, de->de_str.len,
-+                                    file->f_pos, de->de_ino, de->de_type);
-+                      if (unlikely(err)) {
-+                              AuTraceErr(err);
++                      if (unlikely(!dir_emit(ctx, de->de_str.name,
++                                             de->de_str.len, de->de_ino,
++                                             de->de_type))) {
 +                              /* todo: ignore the error caused by udba? */
 +                              /* return err; */
 +                              return 0;
@@ -25931,13 +29829,13 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +
 +                      l = calc_size(de->de_str.len);
 +                      vdir_cache->vd_last.p.deblk += l;
-+                      file->f_pos += l;
++                      ctx->pos += l;
 +              }
 +              if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
 +                      vdir_cache->vd_last.ul++;
 +                      vdir_cache->vd_last.p.deblk
 +                              = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
-+                      file->f_pos = deblk_sz * vdir_cache->vd_last.ul;
++                      ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
 +                      continue;
 +              }
 +              break;
@@ -25948,10 +29846,10 @@ diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
 +}
 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 --- /usr/share/empty/fs/aufs/vfsub.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/vfsub.c      2013-03-14 20:07:41.221457313 +0100
-@@ -0,0 +1,777 @@
++++ linux/fs/aufs/vfsub.c      2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,846 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -25964,15 +29862,13 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
 + * sub-routines for VFS
 + */
 +
-+#include <linux/ima.h>
 +#include <linux/namei.h>
 +#include <linux/security.h>
 +#include <linux/splice.h>
@@ -25993,7 +29889,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      h_sb = h_path->dentry->d_sb;
 +      *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
 +      if (*did)
-+              err = vfs_getattr(h_path->mnt, h_path->dentry, &st);
++              err = vfs_getattr(h_path, &st);
 +
 +      return err;
 +}
@@ -26030,6 +29926,57 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      return file;
 +}
 +
++/*
++ * Ideally this function should call VFS:do_last() in order to keep all its
++ * checkings. But it is very hard for aufs to regenerate several VFS internal
++ * structure such as nameidata. This is a second (or third) best approach.
++ * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
++ */
++int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
++                    struct vfsub_aopen_args *args, struct au_branch *br)
++{
++      int err;
++      struct file *file = args->file;
++      /* copied from linux/fs/namei.c:atomic_open() */
++      struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
++
++      IMustLock(dir);
++      AuDebugOn(!dir->i_op->atomic_open);
++
++      err = au_br_test_oflag(args->open_flag, br);
++      if (unlikely(err))
++              goto out;
++
++      args->file->f_path.dentry = DENTRY_NOT_SET;
++      args->file->f_path.mnt = au_br_mnt(br);
++      err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
++                                   args->create_mode, args->opened);
++      if (err >= 0) {
++              /* some filesystems don't set FILE_CREATED while succeeded? */
++              if (*args->opened & FILE_CREATED)
++                      fsnotify_create(dir, dentry);
++      } else
++              goto out;
++
++
++      if (!err) {
++              /* todo: call VFS:may_open() here */
++              err = open_check_o_direct(file);
++              /* todo: ima_file_check() too? */
++              if (!err && (args->open_flag & __FMODE_EXEC))
++                      err = deny_write_access(file);
++              if (unlikely(err))
++                      /* note that the file is created and still opened */
++                      goto out;
++      }
++
++      atomic_inc(&br->br_count);
++      fsnotify_open(file);
++
++out:
++      return err;
++}
++
 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
 +{
 +      int err;
@@ -26111,7 +30058,9 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      if (unlikely(err))
 +              goto out;
 +
++      lockdep_off();
 +      err = vfs_create(dir, path->dentry, mode, want_excl);
++      lockdep_on();
 +      if (!err) {
 +              struct path tmp = *path;
 +              int did;
@@ -26142,7 +30091,9 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      if (unlikely(err))
 +              goto out;
 +
++      lockdep_off();
 +      err = vfs_symlink(dir, path->dentry, symname);
++      lockdep_on();
 +      if (!err) {
 +              struct path tmp = *path;
 +              int did;
@@ -26173,7 +30124,9 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      if (unlikely(err))
 +              goto out;
 +
++      lockdep_off();
 +      err = vfs_mknod(dir, path->dentry, mode, dev);
++      lockdep_on();
 +      if (!err) {
 +              struct path tmp = *path;
 +              int did;
@@ -26200,7 +30153,8 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      return -EMLINK;
 +}
 +
-+int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
++int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
++             struct inode **delegated_inode)
 +{
 +      int err;
 +      struct dentry *d;
@@ -26220,7 +30174,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +              goto out;
 +
 +      lockdep_off();
-+      err = vfs_link(src_dentry, dir, path->dentry);
++      err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
 +      lockdep_on();
 +      if (!err) {
 +              struct path tmp = *path;
@@ -26242,7 +30196,8 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +}
 +
 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
-+               struct inode *dir, struct path *path)
++               struct inode *dir, struct path *path,
++               struct inode **delegated_inode)
 +{
 +      int err;
 +      struct path tmp = {
@@ -26256,13 +30211,14 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      d = path->dentry;
 +      path->dentry = d->d_parent;
 +      tmp.dentry = src_dentry->d_parent;
-+      err = security_path_rename(&tmp, src_dentry, path, d);
++      err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
 +      path->dentry = d;
 +      if (unlikely(err))
 +              goto out;
 +
 +      lockdep_off();
-+      err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
++      err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
++                       delegated_inode, /*flags*/0);
 +      lockdep_on();
 +      if (!err) {
 +              int did;
@@ -26296,7 +30252,9 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      if (unlikely(err))
 +              goto out;
 +
++      lockdep_off();
 +      err = vfs_mkdir(dir, path->dentry, mode);
++      lockdep_on();
 +      if (!err) {
 +              struct path tmp = *path;
 +              int did;
@@ -26413,8 +30371,8 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      int err;
 +
 +      err = 0;
-+      if (file->f_op && file->f_op->flush) {
-+              if (!au_test_nfs(file->f_dentry->d_sb))
++      if (file->f_op->flush) {
++              if (!au_test_nfs(file->f_path.dentry->d_sb))
 +                      err = file->f_op->flush(file, id);
 +              else {
 +                      lockdep_off();
@@ -26428,12 +30386,14 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      return err;
 +}
 +
-+int vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
++int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
 +{
 +      int err;
 +
++      AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
++
 +      lockdep_off();
-+      err = vfs_readdir(file, filldir, arg);
++      err = iterate_dir(file, ctx);
 +      lockdep_on();
 +      if (err >= 0)
 +              vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
@@ -26492,23 +30452,18 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +{
 +      int err;
 +      struct inode *h_inode;
++      struct super_block *h_sb;
 +
-+      h_inode = h_path->dentry->d_inode;
 +      if (!h_file) {
-+              err = vfsub_mnt_want_write(h_path->mnt);
-+              if (err)
-+                      goto out;
-+              err = inode_permission(h_inode, MAY_WRITE);
-+              if (err)
-+                      goto out_mnt;
-+              err = get_write_access(h_inode);
-+              if (err)
-+                      goto out_mnt;
-+              err = break_lease(h_inode, O_WRONLY);
-+              if (err)
-+                      goto out_inode;
++              err = vfsub_truncate(h_path, length);
++              goto out;
 +      }
 +
++      h_inode = h_path->dentry->d_inode;
++      h_sb = h_inode->i_sb;
++      lockdep_off();
++      sb_start_write(h_sb);
++      lockdep_on();
 +      err = locks_verify_truncate(h_inode, h_file, length);
 +      if (!err)
 +              err = security_path_truncate(h_path);
@@ -26517,13 +30472,10 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +              err = do_truncate(h_path->dentry, length, attr, h_file);
 +              lockdep_on();
 +      }
++      lockdep_off();
++      sb_end_write(h_sb);
++      lockdep_on();
 +
-+out_inode:
-+      if (!h_file)
-+              put_write_access(h_inode);
-+out_mnt:
-+      if (!h_file)
-+              vfsub_mnt_drop_write(h_path->mnt);
 +out:
 +      return err;
 +}
@@ -26548,9 +30500,11 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      int err, do_sio, wkq_err;
 +
 +      do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
-+      if (!do_sio)
++      if (!do_sio) {
++              lockdep_off();
 +              err = vfsub_mkdir(dir, path, mode);
-+      else {
++              lockdep_on();
++      } else {
 +              struct au_vfsub_mkdir_args args = {
 +                      .errp   = &err,
 +                      .dir    = dir,
@@ -26582,9 +30536,11 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      int err, do_sio, wkq_err;
 +
 +      do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
-+      if (!do_sio)
++      if (!do_sio) {
++              lockdep_off();
 +              err = vfsub_rmdir(dir, path);
-+      else {
++              lockdep_on();
++      } else {
 +              struct au_vfsub_rmdir_args args = {
 +                      .errp   = &err,
 +                      .dir    = dir,
@@ -26604,6 +30560,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      int *errp;
 +      struct path *path;
 +      struct iattr *ia;
++      struct inode **delegated_inode;
 +};
 +
 +static void call_notify_change(void *args)
@@ -26616,20 +30573,25 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +
 +      *a->errp = -EPERM;
 +      if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
-+              *a->errp = notify_change(a->path->dentry, a->ia);
++              lockdep_off();
++              *a->errp = notify_change(a->path->dentry, a->ia,
++                                       a->delegated_inode);
++              lockdep_on();
 +              if (!*a->errp)
 +                      vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
 +      }
 +      AuTraceErr(*a->errp);
 +}
 +
-+int vfsub_notify_change(struct path *path, struct iattr *ia)
++int vfsub_notify_change(struct path *path, struct iattr *ia,
++                      struct inode **delegated_inode)
 +{
 +      int err;
 +      struct notify_change_args args = {
-+              .errp   = &err,
-+              .path   = path,
-+              .ia     = ia
++              .errp                   = &err,
++              .path                   = path,
++              .ia                     = ia,
++              .delegated_inode        = delegated_inode
 +      };
 +
 +      call_notify_change(&args);
@@ -26637,13 +30599,15 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      return err;
 +}
 +
-+int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
++int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
++                          struct inode **delegated_inode)
 +{
 +      int err, wkq_err;
 +      struct notify_change_args args = {
-+              .errp   = &err,
-+              .path   = path,
-+              .ia     = ia
++              .errp                   = &err,
++              .path                   = path,
++              .ia                     = ia,
++              .delegated_inode        = delegated_inode
 +      };
 +
 +      wkq_err = au_wkq_wait(call_notify_change, &args);
@@ -26659,6 +30623,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      int *errp;
 +      struct inode *dir;
 +      struct path *path;
++      struct inode **delegated_inode;
 +};
 +
 +static void call_unlink(void *args)
@@ -26667,7 +30632,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +      struct dentry *d = a->path->dentry;
 +      struct inode *h_inode;
 +      const int stop_sillyrename = (au_test_nfs(d->d_sb)
-+                                    && d->d_count == 1);
++                                    && au_dcount(d) == 1);
 +
 +      IMustLock(a->dir);
 +
@@ -26684,7 +30649,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +              ihold(h_inode);
 +
 +      lockdep_off();
-+      *a->errp = vfs_unlink(a->dir, d);
++      *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
 +      lockdep_on();
 +      if (!*a->errp) {
 +              struct path tmp = {
@@ -26706,13 +30671,15 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 + * @dir: must be locked.
 + * @dentry: target dentry.
 + */
-+int vfsub_unlink(struct inode *dir, struct path *path, int force)
++int vfsub_unlink(struct inode *dir, struct path *path,
++               struct inode **delegated_inode, int force)
 +{
 +      int err;
 +      struct unlink_args args = {
-+              .errp   = &err,
-+              .dir    = dir,
-+              .path   = path
++              .errp                   = &err,
++              .dir                    = dir,
++              .path                   = path,
++              .delegated_inode        = delegated_inode
 +      };
 +
 +      if (!force)
@@ -26729,10 +30696,10 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
 +}
 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 --- /usr/share/empty/fs/aufs/vfsub.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/vfsub.h      2013-03-14 20:07:41.224790724 +0100
-@@ -0,0 +1,284 @@
++++ linux/fs/aufs/vfsub.h      2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,286 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -26745,8 +30712,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -26759,45 +30725,15 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +#ifdef __KERNEL__
 +
 +#include <linux/fs.h>
-+#include <linux/lglock.h>
 +#include <linux/mount.h>
++#include <linux/xattr.h>
 +#include "debug.h"
 +
 +/* copied from linux/fs/internal.h */
 +/* todo: BAD approach!! */
-+extern struct lglock vfsmount_lock;
++extern void __mnt_drop_write(struct vfsmount *);
 +extern spinlock_t inode_sb_list_lock;
-+
-+/* copied from linux/fs/file_table.c */
-+extern struct lglock files_lglock;
-+#ifdef CONFIG_SMP
-+/*
-+ * These macros iterate all files on all CPUs for a given superblock.
-+ * files_lglock must be held globally.
-+ */
-+#define do_file_list_for_each_entry(__sb, __file)             \
-+{                                                             \
-+      int i;                                                  \
-+      for_each_possible_cpu(i) {                              \
-+              struct list_head *list;                         \
-+              list = per_cpu_ptr((__sb)->s_files, i);         \
-+              list_for_each_entry((__file), list, f_u.fu_list)
-+
-+#define while_file_list_for_each_entry                                \
-+      }                                                       \
-+}
-+
-+#else
-+
-+#define do_file_list_for_each_entry(__sb, __file)             \
-+{                                                             \
-+      struct list_head *list;                                 \
-+      list = &(sb)->s_files;                                  \
-+      list_for_each_entry((__file), list, f_u.fu_list)
-+
-+#define while_file_list_for_each_entry                                \
-+}
-+#endif
++extern int open_check_o_direct(struct file *f);
 +
 +/* ---------------------------------------------------------------------- */
 +
@@ -26805,7 +30741,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
 +/* reduce? gave up. */
 +enum {
-+      AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
++      AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
 +      AuLsc_I_PARENT,         /* lower inode, parent first */
 +      AuLsc_I_PARENT2,        /* copyup dirs */
 +      AuLsc_I_PARENT3,        /* copyup wh */
@@ -26833,17 +30769,12 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +      clear_nlink(inode);
 +}
 +
-+/* ---------------------------------------------------------------------- */
-+
-+/* cf. i_[ug]id_read() in linux/include/fs.h */
-+static inline uid_t vfsub_ia_uid(struct iattr *ia)
-+{
-+      return from_kuid(&init_user_ns, ia->ia_uid);
-+}
-+
-+static inline gid_t vfsub_ia_gid(struct iattr *ia)
++static inline int vfsub_native_ro(struct inode *inode)
 +{
-+      return from_kgid(&init_user_ns, ia->ia_gid);
++      return (inode->i_sb->s_flags & MS_RDONLY)
++              || IS_RDONLY(inode)
++              /* || IS_APPEND(inode) */
++              || IS_IMMUTABLE(inode);
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -26851,6 +30782,15 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +int vfsub_update_h_iattr(struct path *h_path, int *did);
 +struct file *vfsub_dentry_open(struct path *path, int flags);
 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
++struct vfsub_aopen_args {
++      struct file     *file;
++      unsigned int    open_flag;
++      umode_t         create_mode;
++      int             *opened;
++};
++struct au_branch;
++int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
++                    struct vfsub_aopen_args *args, struct au_branch *br);
 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
 +
 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
@@ -26875,6 +30815,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
 +{
 +      int err;
++
 +      lockdep_off();
 +      err = mnt_want_write(mnt);
 +      lockdep_on();
@@ -26888,6 +30829,15 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +      lockdep_on();
 +}
 +
++#if 0 /* reserved */
++static inline void vfsub_mnt_drop_write_file(struct file *file)
++{
++      lockdep_off();
++      mnt_drop_write_file(file);
++      lockdep_on();
++}
++#endif
++
 +/* ---------------------------------------------------------------------- */
 +
 +struct au_hinode;
@@ -26902,9 +30852,10 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +                const char *symname);
 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
-+             struct path *path);
++             struct path *path, struct inode **delegated_inode);
 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
-+               struct inode *hdir, struct path *path);
++               struct inode *hdir, struct path *path,
++               struct inode **delegated_inode);
 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
 +int vfsub_rmdir(struct inode *dir, struct path *path);
 +
@@ -26919,7 +30870,12 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
 +                    loff_t *ppos);
 +int vfsub_flush(struct file *file, fl_owner_t id);
-+int vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
++int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
++
++static inline loff_t vfsub_f_size_read(struct file *file)
++{
++      return i_size_read(file_inode(file));
++}
 +
 +static inline unsigned int vfsub_file_flags(struct file *file)
 +{
@@ -26932,11 +30888,13 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +      return flags;
 +}
 +
++#if 0 /* reserved */
 +static inline void vfsub_file_accessed(struct file *h_file)
 +{
 +      file_accessed(h_file);
 +      vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
 +}
++#endif
 +
 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
 +                                   struct dentry *h_dentry)
@@ -26952,7 +30910,7 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
 +                                  int flags)
 +{
-+      return update_time(h_inode, ts, flags);
++      return generic_update_time(h_inode, ts, flags);
 +      /* no vfsub_update_h_iattr() since we don't have struct path */
 +}
 +
@@ -26961,6 +30919,17 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +                   unsigned int flags);
 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
 +                     loff_t *ppos, size_t len, unsigned int flags);
++
++static inline long vfsub_truncate(struct path *path, loff_t length)
++{
++      long err;
++
++      lockdep_off();
++      err = vfs_truncate(path, length);
++      lockdep_on();
++      return err;
++}
++
 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
 +              struct file *h_file);
 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
@@ -26979,48 +30948,48 @@ diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
 +
 +/* ---------------------------------------------------------------------- */
 +
-+/* dirty workaround for strict type of fmode_t */
-+union vfsub_fmu {
-+      fmode_t fm;
-+      unsigned int ui;
-+};
++int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
++int vfsub_sio_rmdir(struct inode *dir, struct path *path);
++int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
++                          struct inode **delegated_inode);
++int vfsub_notify_change(struct path *path, struct iattr *ia,
++                      struct inode **delegated_inode);
++int vfsub_unlink(struct inode *dir, struct path *path,
++               struct inode **delegated_inode, int force);
 +
-+static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
++/* ---------------------------------------------------------------------- */
++
++static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
++                               const void *value, size_t size, int flags)
 +{
-+      union vfsub_fmu u = {
-+              .fm = fm
-+      };
++      int err;
 +
-+      BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
++      lockdep_off();
++      err = vfs_setxattr(dentry, name, value, size, flags);
++      lockdep_on();
 +
-+      return u.ui;
++      return err;
 +}
 +
-+static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
++static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
 +{
-+      union vfsub_fmu u = {
-+              .ui = ui
-+      };
-+
-+      return u.fm;
-+}
++      int err;
 +
-+/* ---------------------------------------------------------------------- */
++      lockdep_off();
++      err = vfs_removexattr(dentry, name);
++      lockdep_on();
 +
-+int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
-+int vfsub_sio_rmdir(struct inode *dir, struct path *path);
-+int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
-+int vfsub_notify_change(struct path *path, struct iattr *ia);
-+int vfsub_unlink(struct inode *dir, struct path *path, int force);
++      return err;
++}
 +
 +#endif /* __KERNEL__ */
 +#endif /* __AUFS_VFSUB_H__ */
 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 --- /usr/share/empty/fs/aufs/wbr_policy.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wbr_policy.c 2013-02-19 08:40:03.953559833 +0100
-@@ -0,0 +1,700 @@
++++ linux/fs/aufs/wbr_policy.c 2015-06-22 08:27:37.887501948 +0200
+@@ -0,0 +1,765 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -27033,8 +31002,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -27058,14 +31026,15 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      ia.ia_uid = h_isrc->i_uid;
 +      ia.ia_gid = h_isrc->i_gid;
 +      sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
-+      au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc);
-+      err = vfsub_sio_notify_change(h_path, &ia);
++      au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
++      /* no delegation since it is just created */
++      err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
 +
 +      /* is this nfs only? */
 +      if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
 +              ia.ia_valid = ATTR_FORCE | ATTR_MODE;
 +              ia.ia_mode = h_isrc->i_mode;
-+              err = vfsub_sio_notify_change(h_path, &ia);
++              err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
 +      }
 +
 +      return err;
@@ -27081,13 +31050,8 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +#define au_fclr_cpdown(flags, name) \
 +      do { (flags) &= ~AuCpdown_##name; } while (0)
 +
-+struct au_cpdown_dir_args {
-+      struct dentry *parent;
-+      unsigned int flags;
-+};
-+
 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
-+                           struct au_cpdown_dir_args *a)
++                           unsigned int *flags)
 +{
 +      int err;
 +      struct dentry *opq_dentry;
@@ -27097,7 +31061,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      if (IS_ERR(opq_dentry))
 +              goto out;
 +      dput(opq_dentry);
-+      au_fset_cpdown(a->flags, DIROPQ);
++      au_fset_cpdown(*flags, DIROPQ);
 +
 +out:
 +      return err;
@@ -27118,7 +31082,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +
 +      err = 0;
 +      if (h_path.dentry->d_inode) {
-+              h_path.mnt = br->br_mnt;
++              h_path.mnt = au_br_mnt(br);
 +              err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
 +                                        dentry);
 +      }
@@ -27129,6 +31093,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +}
 +
 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
++                       struct au_pin *pin,
 +                       struct dentry *h_parent, void *arg)
 +{
 +      int err, rerr;
@@ -27136,7 +31101,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      struct path h_path;
 +      struct dentry *parent;
 +      struct inode *h_dir, *h_inode, *inode, *dir;
-+      struct au_cpdown_dir_args *args = arg;
++      unsigned int *flags = arg;
 +
 +      bstart = au_dbstart(dentry);
 +      /* dentry is di-locked */
@@ -27146,7 +31111,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      AuDebugOn(h_dir != au_h_iptr(dir, bdst));
 +      IMustLock(h_dir);
 +
-+      err = au_lkup_neg(dentry, bdst);
++      err = au_lkup_neg(dentry, bdst, /*wh*/0);
 +      if (unlikely(err < 0))
 +              goto out;
 +      h_path.dentry = au_h_dptr(dentry, bdst);
@@ -27155,19 +31120,19 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +                            S_IRWXU | S_IRUGO | S_IXUGO);
 +      if (unlikely(err))
 +              goto out_put;
-+      au_fset_cpdown(args->flags, MADE_DIR);
++      au_fset_cpdown(*flags, MADE_DIR);
 +
 +      bopq = au_dbdiropq(dentry);
-+      au_fclr_cpdown(args->flags, WHED);
-+      au_fclr_cpdown(args->flags, DIROPQ);
++      au_fclr_cpdown(*flags, WHED);
++      au_fclr_cpdown(*flags, DIROPQ);
 +      if (au_dbwh(dentry) == bdst)
-+              au_fset_cpdown(args->flags, WHED);
-+      if (!au_ftest_cpdown(args->flags, PARENT_OPQ) && bopq <= bdst)
-+              au_fset_cpdown(args->flags, PARENT_OPQ);
++              au_fset_cpdown(*flags, WHED);
++      if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
++              au_fset_cpdown(*flags, PARENT_OPQ);
 +      h_inode = h_path.dentry->d_inode;
 +      mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+      if (au_ftest_cpdown(args->flags, WHED)) {
-+              err = au_cpdown_dir_opq(dentry, bdst, args);
++      if (au_ftest_cpdown(*flags, WHED)) {
++              err = au_cpdown_dir_opq(dentry, bdst, flags);
 +              if (unlikely(err)) {
 +                      mutex_unlock(&h_inode->i_mutex);
 +                      goto out_dir;
@@ -27179,7 +31144,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      if (unlikely(err))
 +              goto out_opq;
 +
-+      if (au_ftest_cpdown(args->flags, WHED)) {
++      if (au_ftest_cpdown(*flags, WHED)) {
 +              err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
 +              if (unlikely(err))
 +                      goto out_opq;
@@ -27190,27 +31155,28 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +              au_set_ibend(inode, bdst);
 +      au_set_h_iptr(inode, bdst, au_igrab(h_inode),
 +                    au_hi_flags(inode, /*isdir*/1));
++      au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
 +      goto out; /* success */
 +
 +      /* revert */
 +out_opq:
-+      if (au_ftest_cpdown(args->flags, DIROPQ)) {
++      if (au_ftest_cpdown(*flags, DIROPQ)) {
 +              mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
 +              rerr = au_diropq_remove(dentry, bdst);
 +              mutex_unlock(&h_inode->i_mutex);
 +              if (unlikely(rerr)) {
-+                      AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
-+                              AuDLNPair(dentry), bdst, rerr);
++                      AuIOErr("failed removing diropq for %pd b%d (%d)\n",
++                              dentry, bdst, rerr);
 +                      err = -EIO;
 +                      goto out;
 +              }
 +      }
 +out_dir:
-+      if (au_ftest_cpdown(args->flags, MADE_DIR)) {
++      if (au_ftest_cpdown(*flags, MADE_DIR)) {
 +              rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
 +              if (unlikely(rerr)) {
-+                      AuIOErr("failed removing %.*s b%d (%d)\n",
-+                              AuDLNPair(dentry), bdst, rerr);
++                      AuIOErr("failed removing %pd b%d (%d)\n",
++                              dentry, bdst, rerr);
 +                      err = -EIO;
 +              }
 +      }
@@ -27226,13 +31192,10 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
 +{
 +      int err;
-+      struct au_cpdown_dir_args args = {
-+              .parent = dget_parent(dentry),
-+              .flags  = 0
-+      };
++      unsigned int flags;
 +
-+      err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &args);
-+      dput(args.parent);
++      flags = 0;
++      err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
 +
 +      return err;
 +}
@@ -27241,7 +31204,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +
 +/* policies for create */
 +
-+static int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
++int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
 +{
 +      int err, i, j, ndentry;
 +      aufs_bindex_t bopq;
@@ -27288,7 +31251,8 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +}
 +
 +/* top down parent */
-+static int au_wbr_create_tdp(struct dentry *dentry, int isdir __maybe_unused)
++static int au_wbr_create_tdp(struct dentry *dentry,
++                           unsigned int flags __maybe_unused)
 +{
 +      int err;
 +      aufs_bindex_t bstart, bindex;
@@ -27377,7 +31341,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      return err;
 +}
 +
-+static int au_wbr_create_rr(struct dentry *dentry, int isdir)
++static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
 +{
 +      int err, nbr;
 +      unsigned int u;
@@ -27394,7 +31358,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      bend = au_sbend(sb);
 +      nbr = bend + 1;
 +      for (bindex = 0; bindex <= bend; bindex++) {
-+              if (!isdir) {
++              if (!au_ftest_wbr(flags, DIR)) {
 +                      err = atomic_dec_return(next) + 1;
 +                      /* modulo for 0 is meaningless */
 +                      if (unlikely(!err))
@@ -27421,11 +31385,12 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +/* ---------------------------------------------------------------------- */
 +
 +/* most free space */
-+static void au_mfs(struct dentry *dentry)
++static void au_mfs(struct dentry *dentry, struct dentry *parent)
 +{
 +      struct super_block *sb;
 +      struct au_branch *br;
 +      struct au_wbr_mfs *mfs;
++      struct dentry *h_parent;
 +      aufs_bindex_t bindex, bend;
 +      int err;
 +      unsigned long long b, bavail;
@@ -27445,14 +31410,26 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      MtxMustLock(&mfs->mfs_lock);
 +      mfs->mfs_bindex = -EROFS;
 +      mfs->mfsrr_bytes = 0;
-+      bend = au_sbend(sb);
-+      for (bindex = 0; bindex <= bend; bindex++) {
++      if (!parent) {
++              bindex = 0;
++              bend = au_sbend(sb);
++      } else {
++              bindex = au_dbstart(parent);
++              bend = au_dbtaildir(parent);
++      }
++
++      for (; bindex <= bend; bindex++) {
++              if (parent) {
++                      h_parent = au_h_dptr(parent, bindex);
++                      if (!h_parent || !h_parent->d_inode)
++                              continue;
++              }
 +              br = au_sbr(sb, bindex);
 +              if (au_br_rdonly(br))
 +                      continue;
 +
 +              /* sb->s_root for NFS is unreliable */
-+              h_path.mnt = br->br_mnt;
++              h_path.mnt = au_br_mnt(br);
 +              h_path.dentry = h_path.mnt->mnt_root;
 +              err = vfs_statfs(&h_path, st);
 +              if (unlikely(err)) {
@@ -27477,9 +31454,10 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      kfree(st);
 +}
 +
-+static int au_wbr_create_mfs(struct dentry *dentry, int isdir __maybe_unused)
++static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
 +{
 +      int err;
++      struct dentry *parent;
 +      struct super_block *sb;
 +      struct au_wbr_mfs *mfs;
 +
@@ -27488,14 +31466,18 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +              goto out;
 +
 +      sb = dentry->d_sb;
++      parent = NULL;
++      if (au_ftest_wbr(flags, PARENT))
++              parent = dget_parent(dentry);
 +      mfs = &au_sbi(sb)->si_wbr_mfs;
 +      mutex_lock(&mfs->mfs_lock);
 +      if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
 +          || mfs->mfs_bindex < 0
 +          || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
-+              au_mfs(dentry);
++              au_mfs(dentry, parent);
 +      mutex_unlock(&mfs->mfs_lock);
 +      err = mfs->mfs_bindex;
++      dput(parent);
 +
 +      if (err >= 0)
 +              err = au_wbr_nonopq(dentry, err);
@@ -27526,17 +31508,17 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +/* ---------------------------------------------------------------------- */
 +
 +/* most free space and then round robin */
-+static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
++static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
 +{
 +      int err;
 +      struct au_wbr_mfs *mfs;
 +
-+      err = au_wbr_create_mfs(dentry, isdir);
++      err = au_wbr_create_mfs(dentry, flags);
 +      if (err >= 0) {
 +              mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
 +              mutex_lock(&mfs->mfs_lock);
 +              if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
-+                      err = au_wbr_create_rr(dentry, isdir);
++                      err = au_wbr_create_rr(dentry, flags);
 +              mutex_unlock(&mfs->mfs_lock);
 +      }
 +
@@ -27557,7 +31539,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +/* ---------------------------------------------------------------------- */
 +
 +/* top down parent and most free space */
-+static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
++static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
 +{
 +      int err, e2;
 +      unsigned long long b;
@@ -27566,7 +31548,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      struct dentry *parent, *h_parent;
 +      struct au_branch *br;
 +
-+      err = au_wbr_create_tdp(dentry, isdir);
++      err = au_wbr_create_tdp(dentry, flags);
 +      if (unlikely(err < 0))
 +              goto out;
 +      parent = dget_parent(dentry);
@@ -27575,7 +31557,7 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      if (bstart == bend)
 +              goto out_parent; /* success */
 +
-+      e2 = au_wbr_create_mfs(dentry, isdir);
++      e2 = au_wbr_create_mfs(dentry, flags);
 +      if (e2 < 0)
 +              goto out_parent; /* success */
 +
@@ -27610,12 +31592,46 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +
 +/* ---------------------------------------------------------------------- */
 +
++/*
++ * - top down parent
++ * - most free space with parent
++ * - most free space round-robin regardless parent
++ */
++static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
++{
++      int err;
++      unsigned long long watermark;
++      struct super_block *sb;
++      struct au_branch *br;
++      struct au_wbr_mfs *mfs;
++
++      err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
++      if (unlikely(err < 0))
++              goto out;
++
++      sb = dentry->d_sb;
++      br = au_sbr(sb, err);
++      mfs = &au_sbi(sb)->si_wbr_mfs;
++      mutex_lock(&mfs->mfs_lock);
++      watermark = mfs->mfsrr_watermark;
++      mutex_unlock(&mfs->mfs_lock);
++      if (br->br_wbr->wbr_bytes < watermark)
++              /* regardless the parent dir */
++              err = au_wbr_create_mfsrr(dentry, flags);
++
++out:
++      AuDbg("b%d\n", err);
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
 +/* policies for copyup */
 +
 +/* top down parent */
 +static int au_wbr_copyup_tdp(struct dentry *dentry)
 +{
-+      return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
++      return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
 +}
 +
 +/* bottom up parent */
@@ -27651,12 +31667,10 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +}
 +
 +/* bottom up */
-+static int au_wbr_copyup_bu(struct dentry *dentry)
++int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
 +{
 +      int err;
-+      aufs_bindex_t bstart;
 +
-+      bstart = au_dbstart(dentry);
 +      err = au_wbr_bu(dentry->d_sb, bstart);
 +      AuDbg("b%d\n", err);
 +      if (err > bstart)
@@ -27666,6 +31680,16 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +      return err;
 +}
 +
++static int au_wbr_copyup_bu(struct dentry *dentry)
++{
++      int err;
++      aufs_bindex_t bstart;
++
++      bstart = au_dbstart(dentry);
++      err = au_wbr_do_copyup_bu(dentry, bstart);
++      return err;
++}
++
 +/* ---------------------------------------------------------------------- */
 +
 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
@@ -27717,14 +31741,24 @@ diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
 +              .create = au_wbr_create_pmfs,
 +              .init   = au_wbr_create_init_mfs,
 +              .fin    = au_wbr_create_fin_mfs
++      },
++      [AuWbrCreate_PMFSRR] = {
++              .create = au_wbr_create_pmfsrr,
++              .init   = au_wbr_create_init_mfsrr,
++              .fin    = au_wbr_create_fin_mfs
++      },
++      [AuWbrCreate_PMFSRRV] = {
++              .create = au_wbr_create_pmfsrr,
++              .init   = au_wbr_create_init_mfsrr,
++              .fin    = au_wbr_create_fin_mfs
 +      }
 +};
 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 --- /usr/share/empty/fs/aufs/whout.c   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/whout.c      2013-03-14 20:07:41.224790724 +0100
-@@ -0,0 +1,1042 @@
++++ linux/fs/aufs/whout.c      2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,1064 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -27737,8 +31771,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -27789,8 +31822,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 + * test if the @wh_name exists under @h_parent.
 + * @try_sio specifies the necessary of super-io.
 + */
-+int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
-+             struct au_branch *br, int try_sio)
++int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
 +{
 +      int err;
 +      struct dentry *wh_dentry;
@@ -27798,22 +31830,25 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      if (!try_sio)
 +              wh_dentry = vfsub_lkup_one(wh_name, h_parent);
 +      else
-+              wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
++              wh_dentry = au_sio_lkup_one(wh_name, h_parent);
 +      err = PTR_ERR(wh_dentry);
-+      if (IS_ERR(wh_dentry))
++      if (IS_ERR(wh_dentry)) {
++              if (err == -ENAMETOOLONG)
++                      err = 0;
 +              goto out;
++      }
 +
 +      err = 0;
 +      if (!wh_dentry->d_inode)
 +              goto out_wh; /* success */
 +
 +      err = 1;
-+      if (S_ISREG(wh_dentry->d_inode->i_mode))
++      if (d_is_reg(wh_dentry))
 +              goto out_wh; /* success */
 +
 +      err = -EIO;
-+      AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
-+              AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
++      AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
++              wh_dentry, wh_dentry->d_inode->i_mode);
 +
 +out_wh:
 +      dput(wh_dentry);
@@ -27824,13 +31859,13 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +/*
 + * test if the @h_dentry sets opaque or not.
 + */
-+int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
++int au_diropq_test(struct dentry *h_dentry)
 +{
 +      int err;
 +      struct inode *h_dir;
 +
 +      h_dir = h_dentry->d_inode;
-+      err = au_wh_test(h_dentry, &diropq_name, br,
++      err = au_wh_test(h_dentry, &diropq_name,
 +                       au_test_h_perm_sio(h_dir, MAY_EXEC));
 +      return err;
 +}
@@ -27874,7 +31909,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      qs.name = name;
 +      for (i = 0; i < 3; i++) {
 +              sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
-+              dentry = au_sio_lkup_one(&qs, h_parent, br);
++              dentry = au_sio_lkup_one(&qs, h_parent);
 +              if (IS_ERR(dentry) || !dentry->d_inode)
 +                      goto out_name;
 +              dput(dentry);
@@ -27899,9 +31934,9 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +{
 +      int err;
 +      struct path h_path = {
-+              .mnt = br->br_mnt
++              .mnt = au_br_mnt(br)
 +      };
-+      struct inode *h_dir;
++      struct inode *h_dir, *delegated;
 +      struct dentry *h_parent;
 +
 +      h_parent = h_dentry->d_parent; /* dir inode is locked */
@@ -27914,8 +31949,14 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +              goto out;
 +
 +      /* under the same dir, no need to lock_rename() */
-+      err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
++      delegated = NULL;
++      err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
 +      AuTraceErr(err);
++      if (unlikely(err == -EWOULDBLOCK)) {
++              pr_warn("cannot retry for NFSv4 delegation"
++                      " for an internal rename\n");
++              iput(delegated);
++      }
 +      dput(h_path.dentry);
 +
 +out:
@@ -27930,7 +31971,8 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +
 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
 +{
-+      int force;
++      int err, force;
++      struct inode *delegated;
 +
 +      /*
 +       * forces superio when the dir has a sticky bit.
@@ -27938,7 +31980,14 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +       */
 +      force = (h_dir->i_mode & S_ISVTX)
 +              && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
-+      return vfsub_unlink(h_dir, h_path, force);
++      delegated = NULL;
++      err = vfsub_unlink(h_dir, h_path, &delegated, force);
++      if (unlikely(err == -EWOULDBLOCK)) {
++              pr_warn("cannot retry for NFSv4 delegation"
++                      " for an internal unlink\n");
++              iput(delegated);
++      }
++      return err;
 +}
 +
 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
@@ -27958,7 +32007,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +{
 +      int err;
 +      struct path h_path = {
-+              .mnt = br->br_mnt
++              .mnt = au_br_mnt(br)
 +      };
 +
 +      err = 0;
@@ -27967,7 +32016,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +              err = PTR_ERR(h_path.dentry);
 +      else {
 +              if (h_path.dentry->d_inode
-+                  && S_ISREG(h_path.dentry->d_inode->i_mode))
++                  && d_is_reg(h_path.dentry))
 +                      err = do_unlink_wh(h_parent->d_inode, &h_path);
 +              dput(h_path.dentry);
 +      }
@@ -27984,21 +32033,25 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +                      const int isdir)
 +{
 +      int err;
++      struct inode *delegated;
 +
 +      if (!whpath->dentry->d_inode)
 +              return;
 +
-+      err = vfsub_mnt_want_write(whpath->mnt);
-+      if (!err) {
-+              if (isdir)
-+                      err = vfsub_rmdir(h_dir, whpath);
-+              else
-+                      err = vfsub_unlink(h_dir, whpath, /*force*/0);
-+              vfsub_mnt_drop_write(whpath->mnt);
++      if (isdir)
++              err = vfsub_rmdir(h_dir, whpath);
++      else {
++              delegated = NULL;
++              err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal unlink\n");
++                      iput(delegated);
++              }
 +      }
 +      if (unlikely(err))
-+              pr_warn("failed removing %.*s (%d), ignored.\n",
-+                      AuDLNPair(whpath->dentry), err);
++              pr_warn("failed removing %pd (%d), ignored.\n",
++                      whpath->dentry, err);
 +}
 +
 +static int test_linkable(struct dentry *h_root)
@@ -28008,8 +32061,8 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      if (h_dir->i_op->link)
 +              return 0;
 +
-+      pr_err("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
-+             AuDLNPair(h_root), au_sbtype(h_root->d_sb));
++      pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
++             h_root, au_sbtype(h_root->d_sb));
 +      return -ENOSYS;
 +}
 +
@@ -28024,15 +32077,11 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +
 +              if (au_test_nfs(path->dentry->d_sb))
 +                      mode |= S_IXUGO;
-+              err = vfsub_mnt_want_write(path->mnt);
-+              if (!err) {
-+                      err = vfsub_mkdir(h_dir, path, mode);
-+                      vfsub_mnt_drop_write(path->mnt);
-+              }
-+      } else if (S_ISDIR(path->dentry->d_inode->i_mode))
++              err = vfsub_mkdir(h_dir, path, mode);
++      } else if (d_is_dir(path->dentry))
 +              err = 0;
 +      else
-+              pr_err("unknown %.*s exists\n", AuDLNPair(path->dentry));
++              pr_err("unknown %pd exists\n", path->dentry);
 +
 +      return err;
 +}
@@ -28055,9 +32104,9 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +
 +/*
 + * returns tri-state,
-+ * minus: error, caller should print the mesage
++ * minus: error, caller should print the message
 + * zero: succuess
-+ * plus: error, caller should NOT print the mesage
++ * plus: error, caller should NOT print the message
 + */
 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
 +                              int do_plink, struct au_wh_base base[],
@@ -28122,18 +32171,12 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      err = -EEXIST;
 +      h_dir = h_root->d_inode;
 +      if (!base[AuBrWh_BASE].dentry->d_inode) {
-+              err = vfsub_mnt_want_write(h_path->mnt);
-+              if (!err) {
-+                      h_path->dentry = base[AuBrWh_BASE].dentry;
-+                      err = vfsub_create(h_dir, h_path, WH_MASK,
-+                                         /*want_excl*/true);
-+                      vfsub_mnt_drop_write(h_path->mnt);
-+              }
-+      } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
++              h_path->dentry = base[AuBrWh_BASE].dentry;
++              err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
++      } else if (d_is_reg(base[AuBrWh_BASE].dentry))
 +              err = 0;
 +      else
-+              pr_err("unknown %.*s/%.*s exists\n",
-+                     AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
++              pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
 +      if (unlikely(err))
 +              goto out;
 +
@@ -28160,16 +32203,14 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +/*
 + * initialize the whiteout base file/dir for @br.
 + */
-+int au_wh_init(struct dentry *h_root, struct au_branch *br,
-+             struct super_block *sb)
++int au_wh_init(struct au_branch *br, struct super_block *sb)
 +{
 +      int err, i;
 +      const unsigned char do_plink
 +              = !!au_opt_test(au_mntflags(sb), PLINK);
-+      struct path path = {
-+              .mnt = br->br_mnt
-+      };
 +      struct inode *h_dir;
++      struct path path = br->br_path;
++      struct dentry *h_root = path.dentry;
 +      struct au_wbr *wbr = br->br_wbr;
 +      static const struct qstr base_name[] = {
 +              [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
@@ -28238,8 +32279,8 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      goto out; /* success */
 +
 +out_err:
-+      pr_err("an error(%d) on the writable branch %.*s(%s)\n",
-+             err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
++      pr_err("an error(%d) on the writable branch %pd(%s)\n",
++             err, h_root, au_sbtype(h_root->d_sb));
 +out:
 +      for (i = 0; i < AuBrWh_Last; i++)
 +              dput(base[i].dentry);
@@ -28265,7 +32306,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      struct path h_path;
 +      struct reinit_br_wh *a = arg;
 +      struct au_wbr *wbr;
-+      struct inode *dir;
++      struct inode *dir, *delegated;
 +      struct dentry *h_root;
 +      struct au_hinode *hdir;
 +
@@ -28283,31 +32324,36 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      dir = a->sb->s_root->d_inode;
 +      hdir = au_hi(dir, bindex);
 +      h_root = au_h_dptr(a->sb->s_root, bindex);
++      AuDebugOn(h_root != au_br_dentry(a->br));
 +
 +      au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
 +      wbr_wh_write_lock(wbr);
 +      err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
 +                        h_root, a->br);
 +      if (!err) {
-+              err = vfsub_mnt_want_write(a->br->br_mnt);
-+              if (!err) {
-+                      h_path.dentry = wbr->wbr_whbase;
-+                      h_path.mnt = a->br->br_mnt;
-+                      err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
-+                      vfsub_mnt_drop_write(a->br->br_mnt);
++              h_path.dentry = wbr->wbr_whbase;
++              h_path.mnt = au_br_mnt(a->br);
++              delegated = NULL;
++              err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
++                                 /*force*/0);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal unlink\n");
++                      iput(delegated);
 +              }
 +      } else {
-+              pr_warn("%.*s is moved, ignored\n",
-+                      AuDLNPair(wbr->wbr_whbase));
++              pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
 +              err = 0;
 +      }
 +      dput(wbr->wbr_whbase);
 +      wbr->wbr_whbase = NULL;
 +      if (!err)
-+              err = au_wh_init(h_root, a->br, a->sb);
++              err = au_wh_init(a->br, a->sb);
 +      wbr_wh_write_unlock(wbr);
 +      au_hn_imtx_unlock(hdir);
 +      di_read_unlock(a->sb->s_root, AuLock_IR);
++      if (!err)
++              au_fhsm_wrote(a->sb, bindex, /*force*/0);
 +
 +out:
 +      if (wbr)
@@ -28368,18 +32414,24 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      struct au_branch *br;
 +      struct au_wbr *wbr;
 +      struct dentry *h_parent;
-+      struct inode *h_dir;
++      struct inode *h_dir, *delegated;
 +
 +      h_parent = wh->d_parent; /* dir inode is locked */
 +      h_dir = h_parent->d_inode;
 +      IMustLock(h_dir);
 +
 +      br = au_sbr(sb, bindex);
-+      h_path.mnt = br->br_mnt;
++      h_path.mnt = au_br_mnt(br);
 +      wbr = br->br_wbr;
 +      wbr_wh_read_lock(wbr);
 +      if (wbr->wbr_whbase) {
-+              err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
++              delegated = NULL;
++              err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
++              if (unlikely(err == -EWOULDBLOCK)) {
++                      pr_warn("cannot retry for NFSv4 delegation"
++                              " for an internal link\n");
++                      iput(delegated);
++              }
 +              if (!err || err != -EMLINK)
 +                      goto out;
 +
@@ -28389,6 +32441,8 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +
 +      /* return this error in this context */
 +      err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
++      if (!err)
++              au_fhsm_wrote(sb, bindex, /*force*/0);
 +
 +out:
 +      wbr_wh_read_unlock(wbr);
@@ -28424,7 +32478,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      } else {
 +              struct path tmp = {
 +                      .dentry = opq_dentry,
-+                      .mnt    = br->br_mnt
++                      .mnt    = au_br_mnt(br)
 +              };
 +              err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
 +              if (!err)
@@ -28513,9 +32567,10 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
 +      if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
 +              err = link_or_create_wh(sb, bindex, wh_dentry);
-+              if (!err)
++              if (!err) {
 +                      au_set_dbwh(dentry, bindex);
-+              else {
++                      au_fhsm_wrote(sb, bindex, /*force*/0);
++              } else {
 +                      dput(wh_dentry);
 +                      wh_dentry = ERR_PTR(err);
 +              }
@@ -28535,8 +32590,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      struct qstr wh_name;
 +      char *p;
 +      struct hlist_head *head;
-+      struct au_vdir_wh *tpos;
-+      struct hlist_node *pos;
++      struct au_vdir_wh *pos;
 +      struct au_vdir_destr *str;
 +
 +      err = -ENOMEM;
@@ -28551,11 +32605,11 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      n = whlist->nh_num;
 +      head = whlist->nh_head;
 +      for (ul = 0; !err && ul < n; ul++, head++) {
-+              hlist_for_each_entry(tpos, pos, head, wh_hash) {
-+                      if (tpos->wh_bindex != bindex)
++              hlist_for_each_entry(pos, head, wh_hash) {
++                      if (pos->wh_bindex != bindex)
 +                              continue;
 +
-+                      str = &tpos->wh_str;
++                      str = &pos->wh_str;
 +                      if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
 +                              memcpy(p, str->name, str->len);
 +                              wh_name.len = AUFS_WH_PFX_LEN + str->len;
@@ -28641,6 +32695,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +                 struct dentry *wh_dentry, struct au_nhash *whlist)
 +{
 +      int err;
++      unsigned int h_nlink;
 +      struct path h_tmp;
 +      struct inode *wh_inode, *h_dir;
 +      struct au_branch *br;
@@ -28676,21 +32731,24 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +
 +      if (!err) {
 +              h_tmp.dentry = wh_dentry;
-+              h_tmp.mnt = br->br_mnt;
++              h_tmp.mnt = au_br_mnt(br);
++              h_nlink = h_dir->i_nlink;
 +              err = vfsub_rmdir(h_dir, &h_tmp);
++              /* some fs doesn't change the parent nlink in some cases */
++              h_nlink -= h_dir->i_nlink;
 +      }
 +
 +      if (!err) {
 +              if (au_ibstart(dir) == bindex) {
 +                      /* todo: dir->i_mutex is necessary */
 +                      au_cpup_attr_timesizes(dir);
-+                      vfsub_drop_nlink(dir);
++                      if (h_nlink)
++                              vfsub_drop_nlink(dir);
 +              }
 +              return 0; /* success */
 +      }
 +
-+      pr_warn("failed removing %.*s(%d), ignored\n",
-+              AuDLNPair(wh_dentry), err);
++      pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
 +      return err;
 +}
 +
@@ -28720,21 +32778,20 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      h_parent = dget_parent(a->wh_dentry);
 +      h_dir = h_parent->d_inode;
 +      hdir = au_hi(a->dir, bindex);
++      err = vfsub_mnt_want_write(au_br_mnt(a->br));
++      if (unlikely(err))
++              goto out_mnt;
 +      au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
 +      err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
 +                        a->br);
-+      if (!err) {
-+              err = vfsub_mnt_want_write(a->br->br_mnt);
-+              if (!err) {
-+                      err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry,
-+                                           &a->whlist);
-+                      vfsub_mnt_drop_write(a->br->br_mnt);
-+              }
-+      }
++      if (!err)
++              err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
 +      au_hn_imtx_unlock(hdir);
++      vfsub_mnt_drop_write(au_br_mnt(a->br));
++
++out_mnt:
 +      dput(h_parent);
 +      ii_write_unlock(a->dir);
-+
 +out:
 +      /* mutex_unlock(&a->dir->i_mutex); */
 +      au_whtmp_rmdir_free(a);
@@ -28760,17 +32817,16 @@ diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
 +      args->wh_dentry = dget(wh_dentry);
 +      wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
 +      if (unlikely(wkq_err)) {
-+              pr_warn("rmdir error %.*s (%d), ignored\n",
-+                      AuDLNPair(wh_dentry), wkq_err);
++              pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
 +              au_whtmp_rmdir_free(args);
 +      }
 +}
 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
 --- /usr/share/empty/fs/aufs/whout.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/whout.h      2013-02-19 08:40:03.953559833 +0100
-@@ -0,0 +1,88 @@
++++ linux/fs/aufs/whout.h      2015-06-22 08:27:37.890835363 +0200
+@@ -0,0 +1,85 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -28783,8 +32839,7 @@ diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -28800,17 +32855,15 @@ diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
 +
 +/* whout.c */
 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
++int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
++int au_diropq_test(struct dentry *h_dentry);
 +struct au_branch;
-+int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
-+             struct au_branch *br, int try_sio);
-+int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
 +                           struct qstr *prefix);
 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
 +                      struct dentry *dentry);
-+int au_wh_init(struct dentry *h_parent, struct au_branch *br,
-+             struct super_block *sb);
++int au_wh_init(struct au_branch *br, struct super_block *sb);
 +
 +/* diropq flags */
 +#define AuDiropq_CREATE       1
@@ -28859,10 +32912,10 @@ diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
 +#endif /* __AUFS_WHOUT_H__ */
 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
 --- /usr/share/empty/fs/aufs/wkq.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wkq.c        2013-02-19 08:40:03.953559833 +0100
-@@ -0,0 +1,214 @@
++++ linux/fs/aufs/wkq.c        2015-06-22 08:27:37.890835363 +0200
+@@ -0,0 +1,213 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -28875,8 +32928,7 @@ diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -28925,7 +32977,7 @@ diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
 +/*
 + * Since struct completion is large, try allocating it dynamically.
 + */
-+#if defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS)
++#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
 +#define AuWkqCompDeclare(name)        struct completion *comp = NULL
 +
 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
@@ -28967,7 +33019,8 @@ diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
 +{
 +      if (au_ftest_wkq(wkinfo->flags, NEST)) {
 +              if (au_wkq_test()) {
-+                      AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
++                      AuWarn1("wkq from wkq, unless silly-rename on NFS,"
++                              " due to a dead dir by UDBA?\n");
 +                      AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
 +              }
 +      } else
@@ -29038,145 +33091,491 @@ diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
 +              kobject_get(wkinfo->kobj);
 +              __module_get(THIS_MODULE); /* todo: ?? */
 +
-+              au_wkq_run(wkinfo);
-+      } else {
-+              err = -ENOMEM;
-+              au_nwt_done(&au_sbi(sb)->si_nowait);
++              au_wkq_run(wkinfo);
++      } else {
++              err = -ENOMEM;
++              au_nwt_done(&au_sbi(sb)->si_nowait);
++      }
++
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++void au_nwt_init(struct au_nowait_tasks *nwt)
++{
++      atomic_set(&nwt->nw_len, 0);
++      /* smp_mb(); */ /* atomic_set */
++      init_waitqueue_head(&nwt->nw_wq);
++}
++
++void au_wkq_fin(void)
++{
++      destroy_workqueue(au_wkq);
++}
++
++int __init au_wkq_init(void)
++{
++      int err;
++
++      err = 0;
++      au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
++      if (IS_ERR(au_wkq))
++              err = PTR_ERR(au_wkq);
++      else if (!au_wkq)
++              err = -ENOMEM;
++
++      return err;
++}
+diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
+--- /usr/share/empty/fs/aufs/wkq.h     1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/wkq.h        2015-06-22 08:27:37.890835363 +0200
+@@ -0,0 +1,91 @@
++/*
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
++ *
++ * This program, aufs is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * workqueue for asynchronous/super-io operations
++ * todo: try new credentials management scheme
++ */
++
++#ifndef __AUFS_WKQ_H__
++#define __AUFS_WKQ_H__
++
++#ifdef __KERNEL__
++
++struct super_block;
++
++/* ---------------------------------------------------------------------- */
++
++/*
++ * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
++ */
++struct au_nowait_tasks {
++      atomic_t                nw_len;
++      wait_queue_head_t       nw_wq;
++};
++
++/* ---------------------------------------------------------------------- */
++
++typedef void (*au_wkq_func_t)(void *args);
++
++/* wkq flags */
++#define AuWkq_WAIT    1
++#define AuWkq_NEST    (1 << 1)
++#define au_ftest_wkq(flags, name)     ((flags) & AuWkq_##name)
++#define au_fset_wkq(flags, name) \
++      do { (flags) |= AuWkq_##name; } while (0)
++#define au_fclr_wkq(flags, name) \
++      do { (flags) &= ~AuWkq_##name; } while (0)
++
++#ifndef CONFIG_AUFS_HNOTIFY
++#undef AuWkq_NEST
++#define AuWkq_NEST    0
++#endif
++
++/* wkq.c */
++int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
++int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
++                unsigned int flags);
++void au_nwt_init(struct au_nowait_tasks *nwt);
++int __init au_wkq_init(void);
++void au_wkq_fin(void);
++
++/* ---------------------------------------------------------------------- */
++
++static inline int au_wkq_test(void)
++{
++      return current->flags & PF_WQ_WORKER;
++}
++
++static inline int au_wkq_wait(au_wkq_func_t func, void *args)
++{
++      return au_wkq_do_wait(AuWkq_WAIT, func, args);
++}
++
++static inline void au_nwt_done(struct au_nowait_tasks *nwt)
++{
++      if (atomic_dec_and_test(&nwt->nw_len))
++              wake_up_all(&nwt->nw_wq);
++}
++
++static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
++{
++      wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
++      return 0;
++}
++
++#endif /* __KERNEL__ */
++#endif /* __AUFS_WKQ_H__ */
+diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
+--- /usr/share/empty/fs/aufs/xattr.c   1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/xattr.c      2015-06-22 08:27:37.890835363 +0200
+@@ -0,0 +1,344 @@
++/*
++ * Copyright (C) 2014-2015 Junjiro R. Okajima
++ *
++ * This program, aufs is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * handling xattr functions
++ */
++
++#include <linux/xattr.h>
++#include "aufs.h"
++
++static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
++{
++      if (!ignore_flags)
++              goto out;
++      switch (err) {
++      case -ENOMEM:
++      case -EDQUOT:
++              goto out;
++      }
++
++      if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
++              err = 0;
++              goto out;
++      }
++
++#define cmp(brattr, prefix) do {                                      \
++              if (!strncmp(name, XATTR_##prefix##_PREFIX,             \
++                           XATTR_##prefix##_PREFIX_LEN)) {            \
++                      if (ignore_flags & AuBrAttr_ICEX_##brattr)      \
++                              err = 0;                                \
++                      goto out;                                       \
++              }                                                       \
++      } while (0)
++
++      cmp(SEC, SECURITY);
++      cmp(SYS, SYSTEM);
++      cmp(TR, TRUSTED);
++      cmp(USR, USER);
++#undef cmp
++
++      if (ignore_flags & AuBrAttr_ICEX_OTH)
++              err = 0;
++
++out:
++      return err;
++}
++
++static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
++
++static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
++                          char *name, char **buf, unsigned int ignore_flags,
++                          unsigned int verbose)
++{
++      int err;
++      ssize_t ssz;
++      struct inode *h_idst;
++
++      ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
++      err = ssz;
++      if (unlikely(err <= 0)) {
++              if (err == -ENODATA
++                  || (err == -EOPNOTSUPP
++                      && ((ignore_flags & au_xattr_out_of_list)
++                          || (au_test_nfs_noacl(h_src->d_inode)
++                              && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
++                                  || !strcmp(name,
++                                             XATTR_NAME_POSIX_ACL_DEFAULT))))
++                          ))
++                      err = 0;
++              if (err && (verbose || au_debug_test()))
++                      pr_err("%s, err %d\n", name, err);
++              goto out;
++      }
++
++      /* unlock it temporary */
++      h_idst = h_dst->d_inode;
++      mutex_unlock(&h_idst->i_mutex);
++      err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
++      mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
++      if (unlikely(err)) {
++              if (verbose || au_debug_test())
++                      pr_err("%s, err %d\n", name, err);
++              err = au_xattr_ignore(err, name, ignore_flags);
++      }
++
++out:
++      return err;
++}
++
++int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
++                unsigned int verbose)
++{
++      int err, unlocked, acl_access, acl_default;
++      ssize_t ssz;
++      struct inode *h_isrc, *h_idst;
++      char *value, *p, *o, *e;
++
++      /* try stopping to update the source inode while we are referencing */
++      /* there should not be the parent-child relationship between them */
++      h_isrc = h_src->d_inode;
++      h_idst = h_dst->d_inode;
++      mutex_unlock(&h_idst->i_mutex);
++      mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
++      mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
++      unlocked = 0;
++
++      /* some filesystems don't list POSIX ACL, for example tmpfs */
++      ssz = vfs_listxattr(h_src, NULL, 0);
++      err = ssz;
++      if (unlikely(err < 0)) {
++              AuTraceErr(err);
++              if (err == -ENODATA
++                  || err == -EOPNOTSUPP)
++                      err = 0;        /* ignore */
++              goto out;
++      }
++
++      err = 0;
++      p = NULL;
++      o = NULL;
++      if (ssz) {
++              err = -ENOMEM;
++              p = kmalloc(ssz, GFP_NOFS);
++              o = p;
++              if (unlikely(!p))
++                      goto out;
++              err = vfs_listxattr(h_src, p, ssz);
++      }
++      mutex_unlock(&h_isrc->i_mutex);
++      unlocked = 1;
++      AuDbg("err %d, ssz %zd\n", err, ssz);
++      if (unlikely(err < 0))
++              goto out_free;
++
++      err = 0;
++      e = p + ssz;
++      value = NULL;
++      acl_access = 0;
++      acl_default = 0;
++      while (!err && p < e) {
++              acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
++                                     sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
++              acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
++                                      sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
++                                      - 1);
++              err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
++                                     verbose);
++              p += strlen(p) + 1;
++      }
++      AuTraceErr(err);
++      ignore_flags |= au_xattr_out_of_list;
++      if (!err && !acl_access) {
++              err = au_do_cpup_xattr(h_dst, h_src,
++                                     XATTR_NAME_POSIX_ACL_ACCESS, &value,
++                                     ignore_flags, verbose);
++              AuTraceErr(err);
++      }
++      if (!err && !acl_default) {
++              err = au_do_cpup_xattr(h_dst, h_src,
++                                     XATTR_NAME_POSIX_ACL_DEFAULT, &value,
++                                     ignore_flags, verbose);
++              AuTraceErr(err);
++      }
++
++      kfree(value);
++
++out_free:
++      kfree(o);
++out:
++      if (!unlocked)
++              mutex_unlock(&h_isrc->i_mutex);
++      AuTraceErr(err);
++      return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++enum {
++      AU_XATTR_LIST,
++      AU_XATTR_GET
++};
++
++struct au_lgxattr {
++      int type;
++      union {
++              struct {
++                      char    *list;
++                      size_t  size;
++              } list;
++              struct {
++                      const char      *name;
++                      void            *value;
++                      size_t          size;
++              } get;
++      } u;
++};
++
++static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
++{
++      ssize_t err;
++      struct path h_path;
++      struct super_block *sb;
++
++      sb = dentry->d_sb;
++      err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
++      if (unlikely(err))
++              goto out;
++      err = au_h_path_getattr(dentry, /*force*/1, &h_path);
++      if (unlikely(err))
++              goto out_si;
++      if (unlikely(!h_path.dentry))
++              /* illegally overlapped or something */
++              goto out_di; /* pretending success */
++
++      /* always topmost entry only */
++      switch (arg->type) {
++      case AU_XATTR_LIST:
++              err = vfs_listxattr(h_path.dentry,
++                                  arg->u.list.list, arg->u.list.size);
++              break;
++      case AU_XATTR_GET:
++              err = vfs_getxattr(h_path.dentry,
++                                 arg->u.get.name, arg->u.get.value,
++                                 arg->u.get.size);
++              break;
 +      }
 +
++out_di:
++      di_read_unlock(dentry, AuLock_IR);
++out_si:
++      si_read_unlock(sb);
++out:
++      AuTraceErr(err);
 +      return err;
 +}
 +
-+/* ---------------------------------------------------------------------- */
-+
-+void au_nwt_init(struct au_nowait_tasks *nwt)
++ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
 +{
-+      atomic_set(&nwt->nw_len, 0);
-+      /* smp_mb(); */ /* atomic_set */
-+      init_waitqueue_head(&nwt->nw_wq);
-+}
++      struct au_lgxattr arg = {
++              .type = AU_XATTR_LIST,
++              .u.list = {
++                      .list   = list,
++                      .size   = size
++              },
++      };
 +
-+void au_wkq_fin(void)
-+{
-+      destroy_workqueue(au_wkq);
++      return au_lgxattr(dentry, &arg);
 +}
 +
-+int __init au_wkq_init(void)
++ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
++                    size_t size)
 +{
-+      int err;
-+
-+      err = 0;
-+      BUILD_BUG_ON(!WQ_RESCUER);
-+      au_wkq = alloc_workqueue(AUFS_WKQ_NAME, !WQ_RESCUER, WQ_DFL_ACTIVE);
-+      if (IS_ERR(au_wkq))
-+              err = PTR_ERR(au_wkq);
-+      else if (!au_wkq)
-+              err = -ENOMEM;
++      struct au_lgxattr arg = {
++              .type = AU_XATTR_GET,
++              .u.get = {
++                      .name   = name,
++                      .value  = value,
++                      .size   = size
++              },
++      };
 +
-+      return err;
++      return au_lgxattr(dentry, &arg);
 +}
-diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
---- /usr/share/empty/fs/aufs/wkq.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wkq.h        2013-02-19 08:40:03.953559833 +0100
-@@ -0,0 +1,92 @@
-+/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
-+ *
-+ * This program, aufs is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-+ */
-+
-+/*
-+ * workqueue for asynchronous/super-io operations
-+ * todo: try new credentials management scheme
-+ */
-+
-+#ifndef __AUFS_WKQ_H__
-+#define __AUFS_WKQ_H__
-+
-+#ifdef __KERNEL__
-+
-+struct super_block;
-+
-+/* ---------------------------------------------------------------------- */
 +
-+/*
-+ * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
-+ */
-+struct au_nowait_tasks {
-+      atomic_t                nw_len;
-+      wait_queue_head_t       nw_wq;
-+};
-+
-+/* ---------------------------------------------------------------------- */
-+
-+typedef void (*au_wkq_func_t)(void *args);
++int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
++                size_t size, int flags)
++{
++      struct au_srxattr arg = {
++              .type = AU_XATTR_SET,
++              .u.set = {
++                      .name   = name,
++                      .value  = value,
++                      .size   = size,
++                      .flags  = flags
++              },
++      };
 +
-+/* wkq flags */
-+#define AuWkq_WAIT    1
-+#define AuWkq_NEST    (1 << 1)
-+#define au_ftest_wkq(flags, name)     ((flags) & AuWkq_##name)
-+#define au_fset_wkq(flags, name) \
-+      do { (flags) |= AuWkq_##name; } while (0)
-+#define au_fclr_wkq(flags, name) \
-+      do { (flags) &= ~AuWkq_##name; } while (0)
++      return au_srxattr(dentry, &arg);
++}
 +
-+#ifndef CONFIG_AUFS_HNOTIFY
-+#undef AuWkq_NEST
-+#define AuWkq_NEST    0
-+#endif
++int aufs_removexattr(struct dentry *dentry, const char *name)
++{
++      struct au_srxattr arg = {
++              .type = AU_XATTR_REMOVE,
++              .u.remove = {
++                      .name   = name
++              },
++      };
 +
-+/* wkq.c */
-+int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
-+int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
-+                unsigned int flags);
-+void au_nwt_init(struct au_nowait_tasks *nwt);
-+int __init au_wkq_init(void);
-+void au_wkq_fin(void);
++      return au_srxattr(dentry, &arg);
++}
 +
 +/* ---------------------------------------------------------------------- */
 +
-+static inline int au_wkq_test(void)
++#if 0
++static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
++                          const char *name, size_t name_len, int type)
 +{
-+      return current->flags & PF_WQ_WORKER;
++      return aufs_listxattr(dentry, list, list_size);
 +}
 +
-+static inline int au_wkq_wait(au_wkq_func_t func, void *args)
++static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
++                      size_t size, int type)
 +{
-+      return au_wkq_do_wait(AuWkq_WAIT, func, args);
++      return aufs_getxattr(dentry, name, buffer, size);
 +}
 +
-+static inline void au_nwt_done(struct au_nowait_tasks *nwt)
++static int au_xattr_set(struct dentry *dentry, const char *name,
++                      const void *value, size_t size, int flags, int type)
 +{
-+      if (atomic_dec_and_test(&nwt->nw_len))
-+              wake_up_all(&nwt->nw_wq);
++      return aufs_setxattr(dentry, name, value, size, flags);
 +}
 +
-+static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
++static const struct xattr_handler au_xattr_handler = {
++      /* no prefix, no flags */
++      .list   = au_xattr_list,
++      .get    = au_xattr_get,
++      .set    = au_xattr_set
++      /* why no remove? */
++};
++
++static const struct xattr_handler *au_xattr_handlers[] = {
++      &au_xattr_handler
++};
++
++void au_xattr_init(struct super_block *sb)
 +{
-+      wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
-+      return 0;
++      /* sb->s_xattr = au_xattr_handlers; */
 +}
-+
-+#endif /* __KERNEL__ */
-+#endif /* __AUFS_WKQ_H__ */
++#endif
 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 --- /usr/share/empty/fs/aufs/xino.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/xino.c       2013-03-14 20:07:41.224790724 +0100
-@@ -0,0 +1,1265 @@
++++ linux/fs/aufs/xino.c       2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,1322 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -29189,8 +33588,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +/*
@@ -29198,6 +33596,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 + */
 +
 +#include <linux/seq_file.h>
++#include <linux/statfs.h>
 +#include "aufs.h"
 +
 +/* todo: unnecessary to support mmap_sem since kernel-space? */
@@ -29222,7 +33621,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +
 +#if 0 /* reserved for future use */
 +      if (err > 0)
-+              fsnotify_access(file->f_dentry);
++              fsnotify_access(file->f_path.dentry);
 +#endif
 +
 +      return err;
@@ -29251,7 +33650,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +
 +#if 0 /* reserved for future use */
 +      if (err > 0)
-+              fsnotify_modify(file->f_dentry);
++              fsnotify_modify(file->f_path.dentry);
 +#endif
 +
 +      return err;
@@ -29314,12 +33713,12 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +{
 +      struct file *file;
 +      struct dentry *base, *parent;
-+      struct inode *dir;
++      struct inode *dir, *delegated;
 +      struct qstr *name;
 +      struct path path;
 +      int err;
 +
-+      base = base_file->f_dentry;
++      base = base_file->f_path.dentry;
 +      parent = base->d_parent; /* dir inode is locked */
 +      dir = parent->d_inode;
 +      IMustLock(dir);
@@ -29329,8 +33728,8 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
 +      if (IS_ERR(path.dentry)) {
 +              file = (void *)path.dentry;
-+              pr_err("%.*s lookup err %ld\n",
-+                     AuLNPair(name), PTR_ERR(path.dentry));
++              pr_err("%pd lookup err %ld\n",
++                     base, PTR_ERR(path.dentry));
 +              goto out;
 +      }
 +
@@ -29338,31 +33737,36 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
 +      if (unlikely(err)) {
 +              file = ERR_PTR(err);
-+              pr_err("%.*s create err %d\n", AuLNPair(name), err);
++              pr_err("%pd create err %d\n", base, err);
 +              goto out_dput;
 +      }
 +
-+      path.mnt = base_file->f_vfsmnt;
++      path.mnt = base_file->f_path.mnt;
 +      file = vfsub_dentry_open(&path,
 +                               O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
 +                               /* | __FMODE_NONOTIFY */);
 +      if (IS_ERR(file)) {
-+              pr_err("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
++              pr_err("%pd open err %ld\n", base, PTR_ERR(file));
 +              goto out_dput;
 +      }
 +
-+      err = vfsub_unlink(dir, &file->f_path, /*force*/0);
++      delegated = NULL;
++      err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
++      if (unlikely(err == -EWOULDBLOCK)) {
++              pr_warn("cannot retry for NFSv4 delegation"
++                      " for an internal unlink\n");
++              iput(delegated);
++      }
 +      if (unlikely(err)) {
-+              pr_err("%.*s unlink err %d\n", AuLNPair(name), err);
++              pr_err("%pd unlink err %d\n", base, err);
 +              goto out_fput;
 +      }
 +
 +      if (copy_src) {
 +              /* no one can touch copy_src xino */
-+              err = au_copy_file(file, copy_src,
-+                                 i_size_read(copy_src->f_dentry->d_inode));
++              err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
 +              if (unlikely(err)) {
-+                      pr_err("%.*s copy err %d\n", AuLNPair(name), err);
++                      pr_err("%pd copy err %d\n", base, err);
 +                      goto out_fput;
 +              }
 +      }
@@ -29397,7 +33801,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +              ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
 +              au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
 +      } else {
-+              ldir->parent = dget_parent(xino->f_dentry);
++              ldir->parent = dget_parent(xino->f_path.dentry);
 +              ldir->mtx = &ldir->parent->d_inode->i_mutex;
 +              mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
 +      }
@@ -29420,38 +33824,56 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
 +{
 +      int err;
++      unsigned long jiffy;
++      blkcnt_t blocks;
 +      aufs_bindex_t bi, bend;
++      struct kstatfs *st;
 +      struct au_branch *br;
 +      struct file *new_xino, *file;
 +      struct super_block *h_sb;
 +      struct au_xino_lock_dir ldir;
 +
++      err = -ENOMEM;
++      st = kzalloc(sizeof(*st), GFP_NOFS);
++      if (unlikely(!st))
++              goto out;
++
 +      err = -EINVAL;
 +      bend = au_sbend(sb);
 +      if (unlikely(bindex < 0 || bend < bindex))
-+              goto out;
++              goto out_st;
 +      br = au_sbr(sb, bindex);
 +      file = br->br_xino.xi_file;
 +      if (!file)
-+              goto out;
++              goto out_st;
++
++      err = vfs_statfs(&file->f_path, st);
++      if (unlikely(err))
++              AuErr1("statfs err %d, ignored\n", err);
++      jiffy = jiffies;
++      blocks = file_inode(file)->i_blocks;
++      pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
++              bindex, (u64)blocks, st->f_bfree, st->f_blocks);
 +
 +      au_xino_lock_dir(sb, file, &ldir);
 +      /* mnt_want_write() is unnecessary here */
 +      new_xino = au_xino_create2(file, file);
 +      au_xino_unlock_dir(&ldir);
 +      err = PTR_ERR(new_xino);
-+      if (IS_ERR(new_xino))
-+              goto out;
++      if (IS_ERR(new_xino)) {
++              pr_err("err %d, ignored\n", err);
++              goto out_st;
++      }
 +      err = 0;
 +      fput(file);
 +      br->br_xino.xi_file = new_xino;
 +
-+      h_sb = br->br_mnt->mnt_sb;
++      h_sb = au_br_sb(br);
 +      for (bi = 0; bi <= bend; bi++) {
 +              if (unlikely(bi == bindex))
 +                      continue;
 +              br = au_sbr(sb, bi);
-+              if (br->br_mnt->mnt_sb != h_sb)
++              if (au_br_sb(br) != h_sb)
 +                      continue;
 +
 +              fput(br->br_xino.xi_file);
@@ -29459,6 +33881,18 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +              get_file(new_xino);
 +      }
 +
++      err = vfs_statfs(&new_xino->f_path, st);
++      if (!err) {
++              pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
++                      bindex, (u64)file_inode(new_xino)->i_blocks,
++                      st->f_bfree, st->f_blocks);
++              if (file_inode(new_xino)->i_blocks < blocks)
++                      au_sbi(sb)->si_xino_jiffy = jiffy;
++      } else
++              AuErr1("statfs err %d, ignored\n", err);
++
++out_st:
++      kfree(st);
 +out:
 +      return err;
 +}
@@ -29486,15 +33920,9 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      ii_read_lock_parent(dir);
 +      bindex = au_br_index(sb, br->br_id);
 +      err = au_xino_trunc(sb, bindex);
-+      if (!err
-+          && br->br_xino.xi_file->f_dentry->d_inode->i_blocks
-+          >= br->br_xino_upper)
-+              br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
-+
 +      ii_read_unlock(dir);
 +      if (unlikely(err))
-+              pr_warn("err b%d, upper %llu, (%d)\n",
-+                      bindex, (unsigned long long)br->br_xino_upper, err);
++              pr_warn("err b%d, (%d)\n", bindex, err);
 +      atomic_dec(&br->br_xino_running);
 +      atomic_dec(&br->br_count);
 +      si_write_unlock(sb);
@@ -29502,13 +33930,36 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      kfree(args);
 +}
 +
++static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
++{
++      int err;
++      struct kstatfs st;
++      struct au_sbinfo *sbinfo;
++
++      /* todo: si_xino_expire and the ratio should be customizable */
++      sbinfo = au_sbi(sb);
++      if (time_before(jiffies,
++                      sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
++              return 0;
++
++      /* truncation border */
++      err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
++      if (unlikely(err)) {
++              AuErr1("statfs err %d, ignored\n", err);
++              return 0;
++      }
++      if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
++              return 0;
++
++      return 1;
++}
++
 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
 +{
 +      struct xino_do_trunc_args *args;
 +      int wkq_err;
 +
-+      if (br->br_xino.xi_file->f_dentry->d_inode->i_blocks
-+          < br->br_xino_upper)
++      if (!xino_trunc_test(sb, br))
 +              return;
 +
 +      if (atomic_inc_return(&br->br_xino_running) > 1)
@@ -29586,7 +34037,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +                             h_ino, ino);
 +      if (!err) {
 +              if (au_opt_test(mnt_flags, TRUNC_XINO)
-+                  && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
++                  && au_test_fs_trunc_xino(au_br_sb(br)))
 +                      xino_try_trunc(sb, br);
 +              return 0; /* success */
 +      }
@@ -29644,7 +34095,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +
 +      pos = pindex;
 +      pos *= PAGE_SIZE;
-+      if (i_size_read(xib->f_dentry->d_inode) >= pos + PAGE_SIZE)
++      if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
 +              sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
 +      else {
 +              memset(p, 0, PAGE_SIZE);
@@ -29739,7 +34190,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +              err = au_xino_do_write(xwrite, br->br_xino.xi_file,
 +                                     h_inode->i_ino, /*ino*/0);
 +              if (!err && try_trunc
-+                  && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
++                  && au_test_fs_trunc_xino(au_br_sb(br)))
 +                      xino_try_trunc(sb, br);
 +      }
 +}
@@ -29777,7 +34228,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      }
 +
 +      file = sbinfo->si_xib;
-+      pend = i_size_read(file->f_dentry->d_inode) / PAGE_SIZE;
++      pend = vfsub_f_size_read(file) / PAGE_SIZE;
 +      for (ul = pindex + 1; ul <= pend; ul++) {
 +              err = xib_pindex(sb, ul);
 +              if (unlikely(err))
@@ -29830,7 +34281,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      pos *= sizeof(*ino);
 +
 +      file = au_sbr(sb, bindex)->br_xino.xi_file;
-+      if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*ino))
++      if (vfsub_f_size_read(file) < pos + sizeof(*ino))
 +              return 0; /* no ino */
 +
 +      sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
@@ -29854,7 +34305,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +{
 +      struct file *file;
 +      struct dentry *h_parent, *d;
-+      struct inode *h_dir;
++      struct inode *h_dir, *inode;
 +      int err;
 +
 +      /*
@@ -29872,11 +34323,16 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      }
 +
 +      /* keep file count */
-+      h_parent = dget_parent(file->f_dentry);
++      err = 0;
++      inode = file_inode(file);
++      h_parent = dget_parent(file->f_path.dentry);
 +      h_dir = h_parent->d_inode;
 +      mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
 +      /* mnt_want_write() is unnecessary here */
-+      err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
++      /* no delegation since it is just created */
++      if (inode->i_nlink)
++              err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
++                                 /*force*/0);
 +      mutex_unlock(&h_dir->i_mutex);
 +      dput(h_parent);
 +      if (unlikely(err)) {
@@ -29886,7 +34342,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      }
 +
 +      err = -EINVAL;
-+      d = file->f_dentry;
++      d = file->f_path.dentry;
 +      if (unlikely(sb == d->d_sb)) {
 +              if (!silent)
 +                      pr_err("%s must be outside\n", fname);
@@ -29946,10 +34402,10 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      shared_br = NULL;
 +      bend = au_sbend(sb);
 +      if (do_test) {
-+              tgt_sb = br->br_mnt->mnt_sb;
++              tgt_sb = au_br_sb(br);
 +              for (bindex = 0; bindex <= bend; bindex++) {
 +                      b = au_sbr(sb, bindex);
-+                      if (tgt_sb == b->br_mnt->mnt_sb) {
++                      if (tgt_sb == au_br_sb(b)) {
 +                              shared_br = b;
 +                              break;
 +                      }
@@ -30005,7 +34461,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      MtxMustLock(&sbinfo->si_xib_mtx);
 +      p = sbinfo->si_xib_buf;
 +      func = sbinfo->si_xread;
-+      pend = i_size_read(file->f_dentry->d_inode);
++      pend = vfsub_f_size_read(file);
 +      pos = 0;
 +      while (pos < pend) {
 +              sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
@@ -30075,7 +34531,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +              goto out;
 +
 +      file = sbinfo->si_xib;
-+      if (i_size_read(file->f_dentry->d_inode) <= PAGE_SIZE)
++      if (vfsub_f_size_read(file) <= PAGE_SIZE)
 +              goto out;
 +
 +      au_xino_lock_dir(sb, file, &ldir);
@@ -30118,12 +34574,12 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +{
 +      const struct file_operations *fop = h_file->f_op;
 +
-+      if (fop) {
-+              if (fop->read)
-+                      return fop->read;
-+              if (fop->aio_read)
-+                      return do_sync_read;
-+      }
++      if (fop->read)
++              return fop->read;
++      if (fop->aio_read)
++              return do_sync_read;
++      if (fop->read_iter)
++              return new_sync_read;
 +      return ERR_PTR(-ENOSYS);
 +}
 +
@@ -30131,12 +34587,12 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +{
 +      const struct file_operations *fop = h_file->f_op;
 +
-+      if (fop) {
-+              if (fop->write)
-+                      return fop->write;
-+              if (fop->aio_write)
-+                      return do_sync_write;
-+      }
++      if (fop->write)
++              return fop->write;
++      if (fop->aio_write)
++              return do_sync_write;
++      if (fop->write_iter)
++              return new_sync_write;
 +      return ERR_PTR(-ENOSYS);
 +}
 +
@@ -30185,7 +34641,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +
 +      sbinfo->si_xib_last_pindex = 0;
 +      sbinfo->si_xib_next_bit = 0;
-+      if (i_size_read(file->f_dentry->d_inode) < PAGE_SIZE) {
++      if (vfsub_f_size_read(file) < PAGE_SIZE) {
 +              pos = 0;
 +              err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
 +                                PAGE_SIZE, &pos);
@@ -30319,18 +34775,16 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +
 +      err = 0;
 +      sbinfo = au_sbi(sb);
-+      parent = dget_parent(xino->file->f_dentry);
++      parent = dget_parent(xino->file->f_path.dentry);
 +      if (remount) {
 +              skip = 0;
-+              dname = &xino->file->f_dentry->d_name;
++              dname = &xino->file->f_path.dentry->d_name;
 +              cur_xino = sbinfo->si_xib;
 +              if (cur_xino) {
-+                      cur_parent = dget_parent(cur_xino->f_dentry);
-+                      cur_name = &cur_xino->f_dentry->d_name;
++                      cur_parent = dget_parent(cur_xino->f_path.dentry);
++                      cur_name = &cur_xino->f_path.dentry->d_name;
 +                      skip = (cur_parent == parent
-+                              && dname->len == cur_name->len
-+                              && !memcmp(dname->name, cur_name->name,
-+                                         dname->len));
++                              && au_qstreq(dname, cur_name));
 +                      dput(cur_parent);
 +              }
 +              if (skip)
@@ -30352,6 +34806,8 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +
 +      /* reset all */
 +      AuIOErr("failed creating xino(%d).\n", err);
++      au_xigen_clr(sb);
++      xino_clear_xib(sb);
 +
 +out:
 +      dput(parent);
@@ -30378,7 +34834,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +      for (bindex = 0; bindex <= bend; bindex++) {
 +              br = au_sbr(sb, bindex);
 +              if (au_br_writable(br->br_perm)
-+                  && !au_test_fs_bad_xino(br->br_mnt->mnt_sb)) {
++                  && !au_test_fs_bad_xino(au_br_sb(br))) {
 +                      bwr = bindex;
 +                      break;
 +              }
@@ -30389,7 +34845,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +              page = (void *)__get_free_page(GFP_NOFS);
 +              if (unlikely(!page))
 +                      goto out;
-+              path.mnt = br->br_mnt;
++              path.mnt = au_br_mnt(br);
 +              path.dentry = au_h_dptr(sb->s_root, bwr);
 +              p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
 +              file = (void *)p;
@@ -30405,7 +34861,7 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +              file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
 +              if (IS_ERR(file))
 +                      goto out;
-+              h_sb = file->f_dentry->d_sb;
++              h_sb = file->f_path.dentry->d_sb;
 +              if (unlikely(au_test_fs_bad_xino(h_sb))) {
 +                      pr_err("xino doesn't support %s(%s)\n",
 +                             AUFS_XINO_DEFPATH, au_sbtype(h_sb));
@@ -30440,35 +34896,12 @@ diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
 +out:
 +      return err;
 +}
-diff -urN /usr/share/empty/include/linux/aufs_type.h linux/include/linux/aufs_type.h
---- /usr/share/empty/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/include/linux/aufs_type.h    2013-02-19 08:40:03.953559833 +0100
-@@ -0,0 +1,19 @@
-+/*
-+ * Copyright (C) 2012-2013 Junjiro R. Okajima
-+ *
-+ * This program, aufs is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-+ */
-+
-+#include <uapi/linux/aufs_type.h>
 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
 --- /usr/share/empty/include/uapi/linux/aufs_type.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux/include/uapi/linux/aufs_type.h       2013-03-14 20:07:41.224790724 +0100
-@@ -0,0 +1,234 @@
++++ linux/include/uapi/linux/aufs_type.h       2015-06-22 08:29:23.710091096 +0200
+@@ -0,0 +1,419 @@
 +/*
-+ * Copyright (C) 2005-2013 Junjiro R. Okajima
++ * Copyright (C) 2005-2015 Junjiro R. Okajima
 + *
 + * This program, aufs is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
@@ -30481,8 +34914,7 @@ diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/lin
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +
 +#ifndef __AUFS_TYPE_H__
@@ -30509,7 +34941,7 @@ diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/lin
 +
 +#include <linux/limits.h>
 +
-+#define AUFS_VERSION  "3.8-20130311"
++#define AUFS_VERSION  "3.x-rcN-20150622"
 +
 +/* todo? move this to linux-2.6.19/include/magic.h */
 +#define AUFS_SUPER_MAGIC      ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
@@ -30546,15 +34978,15 @@ diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/lin
 +#define AUFS_WH_PFX           ".wh."
 +#define AUFS_WH_PFX_LEN               ((int)sizeof(AUFS_WH_PFX) - 1)
 +#define AUFS_WH_TMP_LEN               4
-+/* a limit for rmdir/rename a dir */
++/* a limit for rmdir/rename a dir and copyup */
 +#define AUFS_MAX_NAMELEN      (NAME_MAX \
 +                              - AUFS_WH_PFX_LEN * 2   /* doubly whiteouted */\
 +                              - 1                     /* dot */\
 +                              - AUFS_WH_TMP_LEN)      /* hex */
 +#define AUFS_XINO_FNAME               "." AUFS_NAME ".xino"
 +#define AUFS_XINO_DEFPATH     "/tmp/" AUFS_XINO_FNAME
-+#define AUFS_XINO_TRUNC_INIT  64 /* blocks */
-+#define AUFS_XINO_TRUNC_STEP  4  /* blocks */
++#define AUFS_XINO_DEF_SEC     30 /* seconds */
++#define AUFS_XINO_DEF_TRUNC   45 /* percentage */
 +#define AUFS_DIRWH_DEF                3
 +#define AUFS_RDCACHE_DEF      10 /* seconds */
 +#define AUFS_RDCACHE_MAX      3600 /* seconds */
@@ -30563,7 +34995,8 @@ diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/lin
 +#define AUFS_WKQ_NAME         AUFS_NAME "d"
 +#define AUFS_MFS_DEF_SEC      30 /* seconds */
 +#define AUFS_MFS_MAX_SEC      3600 /* seconds */
-+#define AUFS_PLINK_WARN               100 /* number of plinks */
++#define AUFS_FHSM_CACHE_DEF_SEC       30 /* seconds */
++#define AUFS_PLINK_WARN               50 /* number of plinks in a single bucket */
 +
 +/* pseudo-link maintenace under /proc */
 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
@@ -30586,8 +35019,117 @@ diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/lin
 +#define AUFS_BRPERM_RW                "rw"
 +#define AUFS_BRPERM_RO                "ro"
 +#define AUFS_BRPERM_RR                "rr"
++#define AUFS_BRATTR_COO_REG   "coo_reg"
++#define AUFS_BRATTR_COO_ALL   "coo_all"
++#define AUFS_BRATTR_FHSM      "fhsm"
++#define AUFS_BRATTR_UNPIN     "unpin"
++#define AUFS_BRATTR_ICEX      "icex"
++#define AUFS_BRATTR_ICEX_SEC  "icexsec"
++#define AUFS_BRATTR_ICEX_SYS  "icexsys"
++#define AUFS_BRATTR_ICEX_TR   "icextr"
++#define AUFS_BRATTR_ICEX_USR  "icexusr"
++#define AUFS_BRATTR_ICEX_OTH  "icexoth"
 +#define AUFS_BRRATTR_WH               "wh"
 +#define AUFS_BRWATTR_NLWH     "nolwh"
++#define AUFS_BRWATTR_MOO      "moo"
++
++#define AuBrPerm_RW           1               /* writable, hardlinkable wh */
++#define AuBrPerm_RO           (1 << 1)        /* readonly */
++#define AuBrPerm_RR           (1 << 2)        /* natively readonly */
++#define AuBrPerm_Mask         (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
++
++#define AuBrAttr_COO_REG      (1 << 3)        /* copy-up on open */
++#define AuBrAttr_COO_ALL      (1 << 4)
++#define AuBrAttr_COO_Mask     (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
++
++#define AuBrAttr_FHSM         (1 << 5)        /* file-based hsm */
++#define AuBrAttr_UNPIN                (1 << 6)        /* rename-able top dir of
++                                                 branch. meaningless since
++                                                 linux-3.18-rc1 */
++
++/* ignore error in copying XATTR */
++#define AuBrAttr_ICEX_SEC     (1 << 7)
++#define AuBrAttr_ICEX_SYS     (1 << 8)
++#define AuBrAttr_ICEX_TR      (1 << 9)
++#define AuBrAttr_ICEX_USR     (1 << 10)
++#define AuBrAttr_ICEX_OTH     (1 << 11)
++#define AuBrAttr_ICEX         (AuBrAttr_ICEX_SEC      \
++                               | AuBrAttr_ICEX_SYS    \
++                               | AuBrAttr_ICEX_TR     \
++                               | AuBrAttr_ICEX_USR    \
++                               | AuBrAttr_ICEX_OTH)
++
++#define AuBrRAttr_WH          (1 << 12)       /* whiteout-able */
++#define AuBrRAttr_Mask                AuBrRAttr_WH
++
++#define AuBrWAttr_NoLinkWH    (1 << 13)       /* un-hardlinkable whiteouts */
++#define AuBrWAttr_MOO         (1 << 14)       /* move-up on open */
++#define AuBrWAttr_Mask                (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
++
++#define AuBrAttr_CMOO_Mask    (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
++
++/* #warning test userspace */
++#ifdef __KERNEL__
++#ifndef CONFIG_AUFS_FHSM
++#undef AuBrAttr_FHSM
++#define AuBrAttr_FHSM         0
++#endif
++#ifndef CONFIG_AUFS_XATTR
++#undef        AuBrAttr_ICEX
++#define AuBrAttr_ICEX         0
++#undef        AuBrAttr_ICEX_SEC
++#define AuBrAttr_ICEX_SEC     0
++#undef        AuBrAttr_ICEX_SYS
++#define AuBrAttr_ICEX_SYS     0
++#undef        AuBrAttr_ICEX_TR
++#define AuBrAttr_ICEX_TR      0
++#undef        AuBrAttr_ICEX_USR
++#define AuBrAttr_ICEX_USR     0
++#undef        AuBrAttr_ICEX_OTH
++#define AuBrAttr_ICEX_OTH     0
++#endif
++#endif
++
++/* the longest combination */
++/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
++#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW                   \
++                             "+" AUFS_BRATTR_COO_REG          \
++                             "+" AUFS_BRATTR_FHSM             \
++                             "+" AUFS_BRATTR_UNPIN            \
++                             "+" AUFS_BRATTR_ICEX_SEC         \
++                             "+" AUFS_BRATTR_ICEX_SYS         \
++                             "+" AUFS_BRATTR_ICEX_USR         \
++                             "+" AUFS_BRATTR_ICEX_OTH         \
++                             "+" AUFS_BRWATTR_NLWH)
++
++typedef struct {
++      char a[AuBrPermStrSz];
++} au_br_perm_str_t;
++
++static inline int au_br_writable(int brperm)
++{
++      return brperm & AuBrPerm_RW;
++}
++
++static inline int au_br_whable(int brperm)
++{
++      return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
++}
++
++static inline int au_br_wh_linkable(int brperm)
++{
++      return !(brperm & AuBrWAttr_NoLinkWH);
++}
++
++static inline int au_br_cmoo(int brperm)
++{
++      return brperm & AuBrAttr_CMOO_Mask;
++}
++
++static inline int au_br_fhsm(int brperm)
++{
++      return brperm & AuBrAttr_FHSM;
++}
 +
 +/* ---------------------------------------------------------------------- */
 +
@@ -30597,11 +35139,11 @@ diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/lin
 +      AuCtl_RDU,
 +      AuCtl_RDU_INO,
 +
-+      /* pathconf wrapper */
-+      AuCtl_WBR_FD,
-+
-+      /* busy inode */
-+      AuCtl_IBUSY
++      AuCtl_WBR_FD,   /* pathconf wrapper */
++      AuCtl_IBUSY,    /* busy inode */
++      AuCtl_MVDOWN,   /* move-down */
++      AuCtl_BR,       /* info about branches */
++      AuCtl_FHSM_FD   /* connection for fhsm */
 +};
 +
 +/* borrowed from linux/include/linux/kernel.h */
@@ -30693,12 +35235,87 @@ diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/lin
 +
 +/* ---------------------------------------------------------------------- */
 +
++/* error code for move-down */
++/* the actual message strings are implemented in aufs-util.git */
++enum {
++      EAU_MVDOWN_OPAQUE = 1,
++      EAU_MVDOWN_WHITEOUT,
++      EAU_MVDOWN_UPPER,
++      EAU_MVDOWN_BOTTOM,
++      EAU_MVDOWN_NOUPPER,
++      EAU_MVDOWN_NOLOWERBR,
++      EAU_Last
++};
++
++/* flags for move-down */
++#define AUFS_MVDOWN_DMSG      1
++#define AUFS_MVDOWN_OWLOWER   (1 << 1)        /* overwrite lower */
++#define AUFS_MVDOWN_KUPPER    (1 << 2)        /* keep upper */
++#define AUFS_MVDOWN_ROLOWER   (1 << 3)        /* do even if lower is RO */
++#define AUFS_MVDOWN_ROLOWER_R (1 << 4)        /* did on lower RO */
++#define AUFS_MVDOWN_ROUPPER   (1 << 5)        /* do even if upper is RO */
++#define AUFS_MVDOWN_ROUPPER_R (1 << 6)        /* did on upper RO */
++#define AUFS_MVDOWN_BRID_UPPER        (1 << 7)        /* upper brid */
++#define AUFS_MVDOWN_BRID_LOWER        (1 << 8)        /* lower brid */
++#define AUFS_MVDOWN_FHSM_LOWER        (1 << 9)        /* find fhsm attr for lower */
++#define AUFS_MVDOWN_STFS      (1 << 10)       /* req. stfs */
++#define AUFS_MVDOWN_STFS_FAILED       (1 << 11)       /* output: stfs is unusable */
++#define AUFS_MVDOWN_BOTTOM    (1 << 12)       /* output: no more lowers */
++
++/* index for move-down */
++enum {
++      AUFS_MVDOWN_UPPER,
++      AUFS_MVDOWN_LOWER,
++      AUFS_MVDOWN_NARRAY
++};
++
++/*
++ * additional info of move-down
++ * number of free blocks and inodes.
++ * subset of struct kstatfs, but smaller and always 64bit.
++ */
++struct aufs_stfs {
++      uint64_t        f_blocks;
++      uint64_t        f_bavail;
++      uint64_t        f_files;
++      uint64_t        f_ffree;
++};
++
++struct aufs_stbr {
++      int16_t                 brid;   /* optional input */
++      int16_t                 bindex; /* output */
++      struct aufs_stfs        stfs;   /* output when AUFS_MVDOWN_STFS set */
++} __aligned(8);
++
++struct aufs_mvdown {
++      uint32_t                flags;                  /* input/output */
++      struct aufs_stbr        stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
++      int8_t                  au_errno;               /* output */
++} __aligned(8);
++
++/* ---------------------------------------------------------------------- */
++
++union aufs_brinfo {
++      /* PATH_MAX may differ between kernel-space and user-space */
++      char    _spacer[4096];
++      struct {
++              int16_t id;
++              int     perm;
++              char    path[0];
++      };
++} __aligned(8);
++
++/* ---------------------------------------------------------------------- */
++
 +#define AuCtlType             'A'
 +#define AUFS_CTL_RDU          _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
 +#define AUFS_CTL_RDU_INO      _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
 +#define AUFS_CTL_WBR_FD               _IOW(AuCtlType, AuCtl_WBR_FD, \
 +                                   struct aufs_wbr_fd)
 +#define AUFS_CTL_IBUSY                _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
++#define AUFS_CTL_MVDOWN               _IOWR(AuCtlType, AuCtl_MVDOWN, \
++                                    struct aufs_mvdown)
++#define AUFS_CTL_BRINFO               _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
++#define AUFS_CTL_FHSM_FD      _IOW(AuCtlType, AuCtl_FHSM_FD, int)
 +
 +#endif /* __AUFS_TYPE_H__ */
-
This page took 0.921641 seconds and 4 git commands to generate.