[packages/kernel] - up to 3.16.1 (builds on x86_64; not tested runtime)

arekm arekm at pld-linux.org
Thu Aug 14 11:39:27 CEST 2014


commit 076b876ecc3a67cef4a0595132374ac1bea1d0be
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Aug 14 11:39:10 2014 +0200

    - up to 3.16.1 (builds on x86_64; not tested runtime)

 kernel-aufs3.patch       | 2771 +++++++++++++++++++++++++++++++++++-----------
 kernel-imq.patch         |    8 +-
 kernel-multiarch.config  |  159 ++-
 kernel-small_fixes.patch |  157 ---
 kernel.spec              |    8 +-
 5 files changed, 2248 insertions(+), 855 deletions(-)
---
diff --git a/kernel.spec b/kernel.spec
index c924138..21eded8 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -69,8 +69,8 @@
 %endif
 
 %define		rel		1
-%define		basever		3.15
-%define		postver		.8
+%define		basever		3.16
+%define		postver		.1
 
 # define this to '-%{basever}' for longterm branch
 %define		versuffix	%{nil}
@@ -113,10 +113,10 @@ Epoch:		3
 License:	GPL v2
 Group:		Base/Kernel
 Source0:	http://www.kernel.org/pub/linux/kernel/v3.x/linux-%{basever}.tar.xz
-# Source0-md5:	97ca1625bb40368dc41b9a7971549071
+# Source0-md5:	5c569ed649a0c9711879f333e90c5386
 %if "%{postver}" != ".0"
 Patch0:		http://www.kernel.org/pub/linux/kernel/v3.x/patch-%{version}.xz
-# Patch0-md5:	f1d3ed3137ecbb37ec520748bd65dac0
+# Patch0-md5:	9da4b0f5e343455b8141bcfa47e88cf5
 %endif
 Source1:	kernel.sysconfig
 
diff --git a/kernel-aufs3.patch b/kernel-aufs3.patch
index 0a5f5a3..2edef24 100644
--- a/kernel-aufs3.patch
+++ b/kernel-aufs3.patch
@@ -1,4 +1,4 @@
-aufs3.15 kbuild patch
+aufs3.16 kbuild patch
 
 diff --git a/fs/Kconfig b/fs/Kconfig
 index 312393f..78632ed 100644
@@ -13,16 +13,16 @@ index 312393f..78632ed 100644
  endif # MISC_FILESYSTEMS
  
 diff --git a/fs/Makefile b/fs/Makefile
-index f9cb987..a0c580f 100644
+index 4030cbf..5bd169a 100644
 --- a/fs/Makefile
 +++ b/fs/Makefile
-@@ -126,3 +126,4 @@ obj-y				+= exofs/ # Multiple modules
+@@ -125,3 +125,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/
 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
-index 6929571..351ca48 100644
+index 24e9033..fe9a8d4 100644
 --- a/include/uapi/linux/Kbuild
 +++ b/include/uapi/linux/Kbuild
 @@ -56,6 +56,7 @@ header-y += atmppp.h
@@ -33,10 +33,10 @@ index 6929571..351ca48 100644
  header-y += auto_fs.h
  header-y += auto_fs4.h
  header-y += auxvec.h
-aufs3.15 base patch
+aufs3.16 base patch
 
 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
-index f70a230..138104b 100644
+index 6cb1beb..30efd68 100644
 --- a/drivers/block/loop.c
 +++ b/drivers/block/loop.c
 @@ -692,6 +692,24 @@ static inline int is_loop_device(struct file *file)
@@ -65,7 +65,7 @@ index f70a230..138104b 100644
  
  static ssize_t loop_attr_show(struct device *dev, char *page,
 diff --git a/fs/inode.c b/fs/inode.c
-index f96d2a6..2d72083 100644
+index 6eecb7f..b225c0f 100644
 --- a/fs/inode.c
 +++ b/fs/inode.c
 @@ -1496,7 +1496,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
@@ -78,10 +78,10 @@ index f96d2a6..2d72083 100644
  	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 e246954..4797013 100644
+index f5cb9ba..9ba380c 100644
 --- a/fs/splice.c
 +++ b/fs/splice.c
-@@ -1103,8 +1103,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
+@@ -1114,8 +1114,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
  /*
   * Attempt to initiate a splice from pipe to file.
   */
@@ -92,7 +92,7 @@ index e246954..4797013 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,
+@@ -1131,9 +1131,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.
   */
@@ -106,10 +106,10 @@ index e246954..4797013 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 8780312..3ff3e89 100644
+index e11d60c..2f32b35 100644
 --- a/include/linux/fs.h
 +++ b/include/linux/fs.h
-@@ -2606,6 +2606,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
+@@ -2618,6 +2618,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);
  
@@ -118,10 +118,10 @@ index 8780312..3ff3e89 100644
  
  extern int generic_show_options(struct seq_file *m, struct dentry *root);
 diff --git a/include/linux/splice.h b/include/linux/splice.h
-index 0e43906..304169e 100644
+index da2751d..2e0fca6 100644
 --- a/include/linux/splice.h
 +++ b/include/linux/splice.h
-@@ -93,4 +93,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;
@@ -132,13 +132,13 @@ index 0e43906..304169e 100644
 +			 struct pipe_inode_info *pipe, size_t len,
 +			 unsigned int flags);
  #endif
-aufs3.15 mmap patch
+aufs3.16 mmap patch
 
 diff --git a/fs/buffer.c b/fs/buffer.c
-index 9ddb9fc..1059a0b 100644
+index eba6e4f..31f0b2d 100644
 --- a/fs/buffer.c
 +++ b/fs/buffer.c
-@@ -2448,7 +2448,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
+@@ -2460,7 +2460,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...
  	 */
@@ -148,162 +148,97 @@ index 9ddb9fc..1059a0b 100644
  	ret = __block_page_mkwrite(vma, vmf, get_block);
  	sb_end_pagefault(sb);
 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
-index d4a3574..e44a744 100644
+index d4a3574..1397181 100644
 --- a/fs/proc/nommu.c
 +++ b/fs/proc/nommu.c
-@@ -45,7 +45,9 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
+@@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
  	file = region->vm_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 c4b2646..dc3c0dc 100644
+index cfa63ee..bf4919e 100644
 --- a/fs/proc/task_mmu.c
 +++ b/fs/proc/task_mmu.c
-@@ -265,7 +265,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
+@@ -265,7 +265,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;
-@@ -1408,6 +1410,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
- 	seq_printf(m, "%08lx %s", vma->vm_start, buffer);
- 
- 	if (file) {
-+		file = vma_pr_or_file(vma);
- 		seq_printf(m, " file=");
- 		seq_path(m, &file->f_path, "\n\t= ");
- 	} else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
+@@ -1390,7 +1393,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 task_struct *task = proc_priv->task;
+ 	struct mm_struct *mm = vma->vm_mm;
+ 	struct mm_walk walk = {};
 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
-index 678455d..ad0ce45 100644
+index 678455d..0ef7ef4 100644
 --- a/fs/proc/task_nommu.c
 +++ b/fs/proc/task_nommu.c
-@@ -141,7 +141,9 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
+@@ -141,7 +141,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(file);
 +		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 d677706..192e7ac4 100644
+index e03dd29..dd32624 100644
 --- a/include/linux/mm.h
 +++ b/include/linux/mm.h
-@@ -18,6 +18,9 @@
- #include <linux/pfn.h>
- #include <linux/bit_spinlock.h>
- #include <linux/shrinker.h>
-+#include <linux/dcache.h>
-+#include <linux/file.h>
-+#include <linux/fs.h>
- 
- struct mempolicy;
- struct anon_vma;
-@@ -1173,6 +1176,87 @@ static inline int fixup_user_fault(struct task_struct *tsk,
+@@ -1184,6 +1184,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
  }
  #endif
  
-+/*
-+ * Mainly for aufs which mmap(2) diffrent file and wants to print different path
-+ * in /proc/PID/maps.
-+ */
-+/* #define AUFS_DEBUG_MMAP */
-+static inline void aufs_trace(struct file *f, struct file *pr,
-+			      const char func[], int line, const char func2[])
-+{
-+#ifdef AUFS_DEBUG_MMAP
-+	if (pr)
-+		pr_info("%s:%d: %s, %p\n", func, line, func2,
-+			f ? (char *)f->f_dentry->d_name.name : "(null)");
-+#endif
-+}
-+
-+static inline 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;
-+	aufs_trace(f, pr, func, line, __func__);
-+	return (f && pr) ? pr : f;
-+}
-+
-+static inline void vmr_do_fput(struct vm_region *region,
-+			       const char func[], int line)
-+{
-+	struct file *f = region->vm_file, *pr = region->vm_prfile;
-+	aufs_trace(f, pr, func, line, __func__);
-+	fput(f);
-+	if (f && pr)
-+		fput(pr);
-+}
-+
-+static inline 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;
-+	aufs_trace(f, pr, func, line, __func__);
-+	file_update_time(f);
-+	if (f && pr)
-+		file_update_time(pr);
-+}
-+
-+static inline 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;
-+	aufs_trace(f, pr, func, line, __func__);
-+	return (f && pr) ? pr : f;
-+}
-+
-+static inline 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;
-+	aufs_trace(f, pr, func, line, __func__);
-+	get_file(f);
-+	if (f && pr)
-+		get_file(pr);
-+}
-+
-+static inline void vma_do_fput(struct vm_area_struct *vma,
-+			       const char func[], int line)
-+{
-+	struct file *f = vma->vm_file, *pr = vma->vm_prfile;
-+	aufs_trace(f, pr, func, line, __func__);
-+	fput(f);
-+	if (f && pr)
-+		fput(pr);
-+}
++#ifdef CONFIG_MMU
++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 vmr_pr_or_file(region)		vmr_do_pr_or_file(region, __func__, \
-+							  __LINE__)
-+#define vmr_fput(region)		vmr_do_fput(region, __func__, __LINE__)
 +#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__)
++#else
++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 8967e20..a57b589 100644
+index 96c5750..a087ecd 100644
 --- a/include/linux/mm_types.h
 +++ b/include/linux/mm_types.h
 @@ -232,6 +232,7 @@ struct vm_region {
@@ -323,7 +258,7 @@ index 8967e20..a57b589 100644
  
  #ifndef CONFIG_MMU
 diff --git a/kernel/fork.c b/kernel/fork.c
-index 54a8d26..dcf08b6 100644
+index 6a13c46..714302c 100644
 --- a/kernel/fork.c
 +++ b/kernel/fork.c
 @@ -416,7 +416,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
@@ -335,11 +270,24 @@ index 54a8d26..dcf08b6 100644
  			if (tmp->vm_flags & VM_DENYWRITE)
  				atomic_dec(&inode->i_writecount);
  			mutex_lock(&mapping->i_mmap_mutex);
+diff --git a/mm/Makefile b/mm/Makefile
+index 4064f3e..0003fdf 100644
+--- a/mm/Makefile
++++ b/mm/Makefile
+@@ -18,7 +18,7 @@ obj-y			:= filemap.o mempool.o oom_kill.o fadvise.o \
+ 			   mm_init.o mmu_context.o percpu.o slab_common.o \
+ 			   compaction.o balloon_compaction.o vmacache.o \
+ 			   interval_tree.o list_lru.o workingset.o \
+-			   iov_iter.o $(mmu-y)
++			   iov_iter.o prfile.o $(mmu-y)
+ 
+ obj-y += init-mm.o
+ 
 diff --git a/mm/filemap.c b/mm/filemap.c
-index 088358c..138a88c 100644
+index 900edfa..f4dda0c 100644
 --- a/mm/filemap.c
 +++ b/mm/filemap.c
-@@ -2091,7 +2091,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
+@@ -2040,7 +2040,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);
@@ -349,10 +297,10 @@ index 088358c..138a88c 100644
  	if (page->mapping != inode->i_mapping) {
  		unlock_page(page);
 diff --git a/mm/fremap.c b/mm/fremap.c
-index 34feba6..8d6c451 100644
+index 72b8fa3..a00bbf0 100644
 --- a/mm/fremap.c
 +++ b/mm/fremap.c
-@@ -223,16 +223,27 @@ get_write_lock:
+@@ -224,16 +224,28 @@ get_write_lock:
  		 */
  		if (mapping_cap_account_dirty(mapping)) {
  			unsigned long addr;
@@ -373,6 +321,7 @@ index 34feba6..8d6c451 100644
  				BUG_ON(addr != start);
 +				if (prfile) {
 +					struct vm_area_struct *new_vma;
++
 +					new_vma = find_vma(mm, addr);
 +					if (!new_vma->vm_prfile)
 +						new_vma->vm_prfile = prfile;
@@ -402,10 +351,10 @@ index a402f8f..134e15d 100644
  	return error;
  }
 diff --git a/mm/memory.c b/mm/memory.c
-index 037b812..6e7d241 100644
+index 8b44f76..69a72bf 100644
 --- a/mm/memory.c
 +++ b/mm/memory.c
-@@ -2805,7 +2805,7 @@ reuse:
+@@ -2161,7 +2161,7 @@ reuse:
  			set_page_dirty_balance(dirty_page);
  			/* file_update_time outside page_lock */
  			if (vma->vm_file)
@@ -415,10 +364,10 @@ index 037b812..6e7d241 100644
  		put_page(dirty_page);
  		if (page_mkwrite) {
 diff --git a/mm/mmap.c b/mm/mmap.c
-index b1202cf..40dd067 100644
+index 129b847..869d1d7 100644
 --- a/mm/mmap.c
 +++ b/mm/mmap.c
-@@ -250,7 +250,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
+@@ -253,7 +253,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)
@@ -427,7 +376,7 @@ index b1202cf..40dd067 100644
  	mpol_put(vma_policy(vma));
  	kmem_cache_free(vm_area_cachep, vma);
  	return next;
-@@ -861,7 +861,7 @@ again:			remove_next = 1 + (end > next->vm_end);
+@@ -863,7 +863,7 @@ again:			remove_next = 1 + (end > next->vm_end);
  	if (remove_next) {
  		if (file) {
  			uprobe_munmap(next, next->vm_start, next->vm_end);
@@ -436,7 +385,7 @@ index b1202cf..40dd067 100644
  		}
  		if (next->anon_vma)
  			anon_vma_merge(vma, next);
-@@ -1641,8 +1641,8 @@ out:
+@@ -1643,8 +1643,8 @@ out:
  unmap_and_free_vma:
  	if (vm_flags & VM_DENYWRITE)
  		allow_write_access(file);
@@ -446,7 +395,7 @@ index b1202cf..40dd067 100644
  
  	/* Undo any partial mapping done by a device driver. */
  	unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
-@@ -2432,7 +2432,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
+@@ -2434,7 +2434,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
  		goto out_free_mpol;
  
  	if (new->vm_file)
@@ -455,7 +404,7 @@ index b1202cf..40dd067 100644
  
  	if (new->vm_ops && new->vm_ops->open)
  		new->vm_ops->open(new);
-@@ -2451,7 +2451,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
+@@ -2453,7 +2453,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)
@@ -464,7 +413,7 @@ index b1202cf..40dd067 100644
  	unlink_anon_vmas(new);
   out_free_mpol:
  	mpol_put(vma_policy(new));
-@@ -2840,7 +2840,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
+@@ -2842,7 +2842,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)
@@ -474,27 +423,30 @@ index b1202cf..40dd067 100644
  				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 632df45..02d770e 100644
+index 992a167..ce1915b 100644
 --- a/mm/msync.c
 +++ b/mm/msync.c
-@@ -80,10 +80,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
+@@ -84,13 +84,13 @@ 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(file, 0);
+ 			if (vma->vm_flags & VM_NONLINEAR)
+ 				error = vfs_fsync(file, 1);
+ 			else
+ 				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 85f8d66..9f471fa 100644
+index 4a852f6..b369644 100644
 --- a/mm/nommu.c
 +++ b/mm/nommu.c
-@@ -655,7 +655,7 @@ static void __put_nommu_region(struct vm_region *region)
+@@ -658,7 +658,7 @@ static void __put_nommu_region(struct vm_region *region)
  		up_write(&nommu_region_sem);
  
  		if (region->vm_file)
@@ -503,7 +455,7 @@ index 85f8d66..9f471fa 100644
  
  		/* IO memory and memory shared directly out of the pagecache
  		 * from ramfs/tmpfs mustn't be released here */
-@@ -820,7 +820,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
+@@ -823,7 +823,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)
@@ -512,7 +464,7 @@ index 85f8d66..9f471fa 100644
  	put_nommu_region(vma->vm_region);
  	kmem_cache_free(vm_area_cachep, vma);
  }
-@@ -1382,7 +1382,7 @@ unsigned long do_mmap_pgoff(struct file *file,
+@@ -1385,7 +1385,7 @@ unsigned long do_mmap_pgoff(struct file *file,
  					goto error_just_free;
  				}
  			}
@@ -521,7 +473,7 @@ index 85f8d66..9f471fa 100644
  			kmem_cache_free(vm_region_jar, region);
  			region = pregion;
  			result = start;
-@@ -1458,10 +1458,10 @@ error_just_free:
+@@ -1461,10 +1461,10 @@ error_just_free:
  	up_write(&nommu_region_sem);
  error:
  	if (region->vm_file)
@@ -534,10 +486,102 @@ index 85f8d66..9f471fa 100644
  	kmem_cache_free(vm_area_cachep, vma);
  	kleave(" = %d", ret);
  	return ret;
-aufs3.15 standalone patch
+diff --git a/mm/prfile.c b/mm/prfile.c
+new file mode 100644
+index 0000000..fc708d2
+--- /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_dentry->d_name.name : "(null)");
++#endif
++}
++
++#ifdef CONFIG_MMU
++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);
++}
++#else
++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;
++
++	prfile_trace(f, pr, func, line, __func__);
++	fput(f);
++	if (f && pr)
++		fput(pr);
++}
++#endif /* CONFIG_MMU */
+aufs3.16 standalone patch
 
 diff --git a/fs/inode.c b/fs/inode.c
-index 2d72083..30b69da 100644
+index b225c0f..73259c8 100644
 --- a/fs/inode.c
 +++ b/fs/inode.c
 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
@@ -613,7 +657,7 @@ index ad19959..adf290d 100644
  int fsnotify_fasync(int fd, struct file *file, int on)
  {
 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
-index 923fe4a..176b435 100644
+index d90deaa..60b4239 100644
 --- a/fs/notify/mark.c
 +++ b/fs/notify/mark.c
 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
@@ -649,7 +693,7 @@ index 923fe4a..176b435 100644
  static int fsnotify_mark_destroy(void *ignored)
  {
 diff --git a/fs/open.c b/fs/open.c
-index 9d64679..1aa876a 100644
+index d6fd3ac..5e99d8b 100644
 --- a/fs/open.c
 +++ b/fs/open.c
 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
@@ -660,7 +704,7 @@ index 9d64679..1aa876a 100644
  
  long vfs_truncate(struct path *path, loff_t length)
  {
-@@ -299,6 +300,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
+@@ -298,6 +299,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
  	sb_end_write(inode->i_sb);
  	return ret;
  }
@@ -669,10 +713,10 @@ index 9d64679..1aa876a 100644
  SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
  {
 diff --git a/fs/splice.c b/fs/splice.c
-index 4797013..44b603a 100644
+index 9ba380c..3419932 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,
+@@ -1127,6 +1127,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
  
  	return splice_write(pipe, out, ppos, len, flags);
  }
@@ -680,7 +724,7 @@ index 4797013..44b603a 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,
+@@ -1153,6 +1154,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
  
  	return splice_read(in, ppos, pipe, len, flags);
  }
@@ -705,7 +749,7 @@ index b9d613e..ba3b618 100644
  }
 +EXPORT_SYMBOL(cap_mmap_file);
 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
-index 9134dbf..4d4217a 100644
+index d9d69e6..3f6f471 100644
 --- a/security/device_cgroup.c
 +++ b/security/device_cgroup.c
 @@ -7,6 +7,7 @@
@@ -716,7 +760,7 @@ index 9134dbf..4d4217a 100644
  #include <linux/list.h>
  #include <linux/uaccess.h>
  #include <linux/seq_file.h>
-@@ -856,6 +857,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);
  }
@@ -725,7 +769,7 @@ index 9134dbf..4d4217a 100644
  int devcgroup_inode_mknod(int mode, dev_t dev)
  {
 diff --git a/security/security.c b/security/security.c
-index 8b774f3..e3190b9 100644
+index 31614e9..b223a66 100644
 --- a/security/security.c
 +++ b/security/security.c
 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
@@ -810,7 +854,7 @@ index 8b774f3..e3190b9 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	2014-06-24 00:14:06.769385243 +0200
++++ 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
@@ -864,7 +908,7 @@ 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	2014-06-24 00:14:06.769385243 +0200
++++ 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
@@ -899,7 +943,7 @@ 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	2014-06-24 00:14:06.772718759 +0200
++++ linux/Documentation/filesystems/aufs/design/01intro.txt	2014-01-30 21:10:02.807480310 +0100
 @@ -0,0 +1,161 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -1064,8 +1108,8 @@ 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	2014-06-24 00:14:06.772718759 +0200
-@@ -0,0 +1,242 @@
++++ linux/Documentation/filesystems/aufs/design/02struct.txt	2014-08-14 10:15:45.115275734 +0200
+@@ -0,0 +1,251 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
 +# 
@@ -1300,6 +1344,15 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +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.
++- 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,
@@ -1310,8 +1363,8 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt li
 +For this purpose, use "aumvdown" command in aufs-util.git.
 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	2014-06-24 00:14:06.772718759 +0200
-@@ -0,0 +1,105 @@
++++ linux/Documentation/filesystems/aufs/design/03lookup.txt	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,133 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
 +# 
@@ -1354,6 +1407,34 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt li
 +"Revalidate Dentry and UDBA" in detail.
 +
 +
++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"
++- the internal copy-up is activated and "/rw/dirA" is created and its
++  permission bits are set to world readble.
++- 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 best solution for this case. So aufs
++implements 'dirperm1' and 'nodirperm1' 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.
++
++
 +Loopback Mount
 +----------------------------------------------------------------------
 +Basically aufs supports any type of filesystem and block device for a
@@ -1419,7 +1500,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt li
 +   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	2014-06-24 00:14:06.772718759 +0200
++++ linux/Documentation/filesystems/aufs/design/04branch.txt	2014-01-30 21:10:02.807480310 +0100
 @@ -0,0 +1,75 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -1498,7 +1579,7 @@ 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	2014-06-24 00:14:06.772718759 +0200
++++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt	2014-01-30 21:10:02.807480310 +0100
 @@ -0,0 +1,64 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -1564,9 +1645,133 @@ 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/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	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,120 @@
++
++# Copyright (C) 2011-2014 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
++
++
++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-Lower".
++Here the word "colder" means that the less used files, and "lower" means
++that the position in the order of the stacked branches.
++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	2014-06-24 00:14:06.772718759 +0200
++++ linux/Documentation/filesystems/aufs/design/06mmap.txt	2014-01-30 21:10:02.807480310 +0100
 @@ -0,0 +1,46 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -1616,7 +1821,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linu
 +switching the approach.
 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	2014-06-24 00:14:06.772718759 +0200
++++ linux/Documentation/filesystems/aufs/design/07export.txt	2014-01-30 21:10:02.807480310 +0100
 @@ -0,0 +1,58 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -1678,7 +1883,7 @@ 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	2014-06-24 00:14:06.772718759 +0200
++++ linux/Documentation/filesystems/aufs/design/08shwh.txt	2014-01-30 21:10:02.807480310 +0100
 @@ -0,0 +1,52 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -1734,7 +1939,7 @@ 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	2014-06-24 00:14:06.772718759 +0200
++++ linux/Documentation/filesystems/aufs/design/10dynop.txt	2014-01-30 21:10:02.807480310 +0100
 @@ -0,0 +1,46 @@
 +
 +# Copyright (C) 2010-2014 Junjiro R. Okajima
@@ -1784,8 +1989,8 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt lin
 +vm_operations_struct 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	2014-06-24 00:14:06.772718759 +0200
-@@ -0,0 +1,95 @@
++++ linux/Documentation/filesystems/aufs/design/99plan.txt	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,58 @@
 +
 +# Copyright (C) 2005-2014 Junjiro R. Okajima
 +# 
@@ -1809,32 +2014,6 @@ 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.
@@ -1842,17 +2021,6 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linu
 +currecnly.
 +
 +
-+Copy-up on Open (coo=)
-+----------------------------------------------------------------------
-+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.
@@ -1883,8 +2051,8 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linu
 +Otherwise from /new.
 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	2014-06-24 00:14:06.769385243 +0200
-@@ -0,0 +1,368 @@
++++ linux/Documentation/filesystems/aufs/README	2014-08-14 10:15:45.115275734 +0200
+@@ -0,0 +1,370 @@
 +
 +Aufs3 -- advanced multi layered unification filesystem version 3.x
 +http://aufs.sf.net
@@ -1915,7 +2083,7 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +    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://lkml.org/lkml/2013/3/12/637>
++<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
 +
 +
 +1. Features
@@ -2236,6 +2404,8 @@ diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documenta
 +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).
 +
 +Thank you very much.
 +Donations are always, including future donations, very important and
@@ -2255,7 +2425,7 @@ 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	2014-06-24 00:14:06.776052275 +0200
++++ linux/fs/aufs/aufs.h	2014-01-30 21:10:02.827480967 +0100
 @@ -0,0 +1,59 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -2318,8 +2488,8 @@ 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	2014-06-24 00:14:06.776052275 +0200
-@@ -0,0 +1,1220 @@
++++ linux/fs/aufs/branch.c	2014-08-14 10:16:04.512608923 +0200
+@@ -0,0 +1,1447 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -2398,6 +2568,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)
@@ -2493,6 +2668,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);
@@ -2501,8 +2683,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:
@@ -2885,6 +3067,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
 + */
@@ -2991,6 +3221,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;
 +
@@ -3045,6 +3277,139 @@ 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, unmatched;
++	aufs_bindex_t bindex, bend;
++	struct au_fidir *fidir;
++	struct au_hfile *hfile;
++
++	err = 0;
++	matched = 0;
++	unmatched = 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;
++		else
++			unmatched = 1;
++		if (matched && unmatched)
++			break;
++	}
++	if (!matched)
++		goto out; /* success */
++
++	if (unmatched) {
++		get_file(file);
++		to_free[*idx] = file;
++		(*idx)++;
++	} else
++		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 inode *inode;
++	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);
++		inode = file_inode(file);
++		if (!S_ISDIR(inode->i_mode)) {
++			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(!S_ISDIR(file_inode(file)->i_mode));
++		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)
@@ -3137,17 +3502,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 */
@@ -3167,10 +3544,20 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +	}
 +	br = au_sbr(sb, bindex);
 +	AuDebugOn(!path_equal(&br->br_path, &del->h_path));
-+	i = atomic_read(&br->br_count);
-+	if (unlikely(i)) {
-+		AuVerbose(verbose, "%d file(s) opened\n", i);
-+		goto out;
++
++	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;
@@ -3184,7 +3571,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;
@@ -3192,7 +3579,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 {
@@ -3202,10 +3598,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);
 +
@@ -3220,6 +3616,8 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +		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;
 +}
 +
@@ -3319,52 +3717,6 @@ 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 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);
-+}
-+
 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
 +{
 +	int err, do_warn;
@@ -3388,6 +3740,8 @@ 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("%pD\n", file); */
 +		fi_read_lock(file);
@@ -3463,6 +3817,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +	aufs_bindex_t bindex;
 +	struct dentry *root;
 +	struct au_branch *br;
++	struct au_br_fhsm *bf;
 +
 +	root = sb->s_root;
 +	bindex = au_find_dbindex(root, mod->h_root);
@@ -3484,11 +3839,21 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +	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);
 +		if (unlikely(err))
-+			goto out;
++			goto out_bf;
 +
 +		if (!au_br_writable(mod->perm)) {
 +			/* rw --> ro, file might be mmapped */
@@ -3524,26 +3889,58 @@ diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
 +			}
 +		}
 +	}
++	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 ((br->br_perm & AuBrAttr_UNPIN)
++	    && !(mod->perm & AuBrAttr_UNPIN))
++		au_br_dflags_force(br);
++	else if (!(br->br_perm & AuBrAttr_UNPIN)
++		 && (mod->perm & AuBrAttr_UNPIN))
++		au_br_dflags_restore(br);
++	*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) {
-+		if ((br->br_perm & AuBrAttr_UNPIN)
-+		    && !(mod->perm & AuBrAttr_UNPIN))
-+			au_br_dflags_force(br);
-+		else if (!(br->br_perm & AuBrAttr_UNPIN)
-+			 && (mod->perm & AuBrAttr_UNPIN))
-+			au_br_dflags_restore(br);
-+		*do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
-+		br->br_perm = mod->perm;
++		stfs->f_blocks = kstfs.f_blocks;
++		stfs->f_bavail = kstfs.f_bavail;
++		stfs->f_files = kstfs.f_files;
++		stfs->f_ffree = kstfs.f_ffree;
 +	}
 +
-+out:
-+	AuTraceErr(err);
 +	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	2014-06-24 00:14:06.776052275 +0200
-@@ -0,0 +1,264 @@
++++ linux/fs/aufs/branch.h	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,268 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -3589,6 +3986,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 {
@@ -3639,6 +4046,7 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +	atomic_t		br_count;
 +
 +	struct au_wbr		*br_wbr;
++	struct au_br_fhsm	*br_fhsm;
 +
 +	/* xino truncation */
 +	atomic_t		br_xino_running;
@@ -3670,34 +4078,6 @@ diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
 +	return au_br_mnt(br)->mnt_sb;
 +}
 +
-+/* 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 */
-+
-+#define AuBrAttr_UNPIN		(1 << 5)	/* rename-able top dir of
-+						   branch */
-+
-+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_rdonly(struct au_branch *br)
 +{
 +	return ((au_br_sb(br)->s_flags & MS_RDONLY)
@@ -3731,6 +4111,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;
@@ -3806,12 +4188,31 @@ 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	2014-06-24 00:14:06.776052275 +0200
-@@ -0,0 +1,36 @@
++++ linux/fs/aufs/conf.mk	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,37 @@
 +
 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
 +
@@ -3825,6 +4226,7 @@ diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
 +	SBILIST \
 +	HNOTIFY HFSNOTIFY \
 +	EXPORT INO_T_64 \
++	FHSM \
 +	RDU \
 +	SHWH \
 +	BR_RAMFS \
@@ -3850,8 +4252,8 @@ 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	2014-06-24 00:14:06.779385790 +0200
-@@ -0,0 +1,1289 @@
++++ linux/fs/aufs/cpup.c	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,1301 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -4351,7 +4753,7 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +	int err;
 +	umode_t mode;
 +	unsigned int mnt_flags;
-+	unsigned char isdir;
++	unsigned char isdir, isreg, force;
 +	const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
 +	struct au_dtime dt;
 +	struct path h_path;
@@ -4382,10 +4784,12 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +	}
 +	h_path.dentry = h_dst;
 +
++	isreg = 0;
 +	isdir = 0;
 +	mode = h_inode->i_mode;
 +	switch (mode & S_IFMT) {
 +	case S_IFREG:
++		isreg = 1;
 +		err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
 +				   /*want_excl*/true);
 +		if (!err)
@@ -4434,6 +4838,16 @@ diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
 +		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;
@@ -5143,7 +5557,7 @@ 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	2014-06-24 00:14:06.779385790 +0200
++++ linux/fs/aufs/cpup.h	2014-01-30 21:10:02.827480967 +0100
 @@ -0,0 +1,94 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -5241,7 +5655,7 @@ 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	2014-06-24 00:14:06.779385790 +0200
++++ linux/fs/aufs/dbgaufs.c	2014-01-30 21:10:02.827480967 +0100
 @@ -0,0 +1,432 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -5677,7 +6091,7 @@ 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	2014-06-24 00:14:06.779385790 +0200
++++ linux/fs/aufs/dbgaufs.h	2014-01-30 21:10:02.827480967 +0100
 @@ -0,0 +1,48 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -5729,7 +6143,7 @@ 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	2014-06-24 00:14:06.779385790 +0200
++++ linux/fs/aufs/dcsub.c	2014-01-30 21:10:02.827480967 +0100
 @@ -0,0 +1,243 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -5976,8 +6390,8 @@ 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	2014-06-24 00:14:06.779385790 +0200
-@@ -0,0 +1,116 @@
++++ linux/fs/aufs/dcsub.h	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,120 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -6044,6 +6458,7 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 +{
 +	int err;
 +	struct inode *inode = d->d_inode;
++
 +	err = 0;
 +	if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
 +		err = -ENOENT;
@@ -6054,6 +6469,7 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 +{
 +	int err;
 +	struct inode *inode = d->d_inode;
++
 +	err = au_d_hashed_positive(d);
 +	if (err
 +	    && inode
@@ -6066,6 +6482,7 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 +{
 +	int err;
 +	struct inode *inode;
++
 +	err = 0;
 +	if (!IS_ROOT(d))
 +		err = au_d_hashed_positive(d);
@@ -6080,6 +6497,7 @@ 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;
@@ -6096,8 +6514,8 @@ diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
 +#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	2014-06-24 00:14:06.779385790 +0200
-@@ -0,0 +1,518 @@
++++ linux/fs/aufs/debug.c	2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,519 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -6277,6 +6695,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));
@@ -6291,7 +6710,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +	     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;
@@ -6618,7 +7037,7 @@ diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
 +}
 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	2014-06-24 00:14:06.779385790 +0200
++++ linux/fs/aufs/debug.h	2014-01-30 21:10:02.827480967 +0100
 @@ -0,0 +1,247 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -6869,8 +7288,8 @@ 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	2014-06-24 00:14:06.779385790 +0200
-@@ -0,0 +1,1084 @@
++++ linux/fs/aufs/dentry.c	2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,1094 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -6896,6 +7315,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)
@@ -6922,12 +7342,14 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +	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;
@@ -6941,7 +7363,10 @@ 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 (!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))
 +		goto out;
 +
@@ -6965,7 +7390,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +		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);
@@ -6999,7 +7424,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,
@@ -7008,8 +7433,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;
 +
@@ -7021,6 +7448,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +	isdir = !!(inode && S_ISDIR(inode->i_mode));
 +	if (!type)
 +		au_fset_lkup(args.flags, ALLOW_NEG);
++	dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
 +
 +	npositive = 0;
 +	parent = dget_parent(dentry);
@@ -7052,6 +7480,8 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +		if (IS_ERR(h_dentry))
 +			goto out_parent;
 +		au_fclr_lkup(args.flags, ALLOW_NEG);
++		if (dirperm1)
++			au_fset_lkup(args.flags, IGNORE_PERM);
 +
 +		if (au_dbwh(dentry) >= 0)
 +			break;
@@ -7078,7 +7508,7 @@ 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, %pd, err %d\n",
@@ -7092,8 +7522,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;
@@ -7130,7 +7559,7 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +	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, br);
++		h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
 +	err = PTR_ERR(h_dentry);
 +	if (IS_ERR(h_dentry))
 +		goto out;
@@ -7957,8 +8386,8 @@ diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
 +};
 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	2014-06-24 00:14:06.779385790 +0200
-@@ -0,0 +1,234 @@
++++ linux/fs/aufs/dentry.h	2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,233 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -8007,8 +8436,7 @@ 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);
 +
@@ -8195,7 +8623,7 @@ 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	2014-06-24 00:14:06.779385790 +0200
++++ linux/fs/aufs/dinfo.c	2014-08-14 10:15:45.121942630 +0200
 @@ -0,0 +1,544 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -8743,8 +9171,8 @@ 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	2014-06-24 00:14:06.779385790 +0200
-@@ -0,0 +1,639 @@
++++ linux/fs/aufs/dir.c	2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,645 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -8964,6 +9392,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_dentry->d_sb)->si_files);
 +		vdir_cache = fidir->fd_vdir_cache; /* lock-free */
 +		if (vdir_cache)
 +			au_vdir_free(vdir_cache);
@@ -9301,6 +9731,7 @@ diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
 +			.actor = au_diractor(test_empty_cb)
 +		}
 +	};
++	int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
 +
 +	SiMustAnyLock(dentry->d_sb);
 +
@@ -9316,8 +9747,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;
 +
@@ -9329,7 +9763,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);
 +		}
 +	}
 +
@@ -9386,7 +9820,7 @@ 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	2014-06-24 00:14:06.779385790 +0200
++++ linux/fs/aufs/dir.h	2014-01-30 21:10:02.830814411 +0100
 @@ -0,0 +1,136 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -9526,7 +9960,7 @@ 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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/dynop.c	2014-01-30 21:10:02.830814411 +0100
 @@ -0,0 +1,379 @@
 +/*
 + * Copyright (C) 2010-2014 Junjiro R. Okajima
@@ -9909,7 +10343,7 @@ 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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/dynop.h	2014-01-30 21:10:02.830814411 +0100
 @@ -0,0 +1,75 @@
 +/*
 + * Copyright (C) 2010-2014 Junjiro R. Okajima
@@ -9988,7 +10422,7 @@ 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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/export.c	2014-01-30 21:10:02.830814411 +0100
 @@ -0,0 +1,831 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -10821,10 +11255,424 @@ 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/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	2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,410 @@
++/*
++ * Copyright (C) 2011-2014 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
++ */
++
++/*
++ * File-based Hierarchy Storage Management
++ */
++
++#include <linux/anon_inodes.h>
++#include <linux/poll.h>
++#include <linux/seq_file.h>
++#include <linux/statfs.h>
++#include "aufs.h"
++
++static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
++{
++	struct au_br_fhsm *bf;
++
++	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);
++	}
++}
++
++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 au_branch *br;
++	struct au_br_fhsm *bf;
++
++	br = au_sbr(sb, bindex);
++	AuDebugOn(au_br_rdonly(br));
++	bf = br->br_fhsm;
++	AuDebugOn(!bf);
++
++	if (do_lock)
++		mutex_lock(&bf->bf_lock);
++	else
++		MtxMustLock(&bf->bf_lock);
++
++	/* sb->s_root for NFS is unreliable */
++	err = au_br_stfs(br, &bf->bf_stfs);
++	if (unlikely(err)) {
++		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;
++}
++
++void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
++{
++	int err;
++	unsigned char do_notify;
++	aufs_bindex_t bend, blower;
++	struct au_sbinfo *sbinfo;
++	struct au_fhsm *fhsm;
++	struct au_branch *br;
++	struct au_br_fhsm *bf;
++
++	AuDbg("b%d, force %d\n", bindex, force);
++	SiMustAnyLock(sb);
++
++	sbinfo = au_sbi(sb);
++	fhsm = &sbinfo->si_fhsm;
++	if (!au_ftest_si(sbinfo, FHSM))
++		return;
++
++	do_notify = 0;
++	bend = au_sbend(sb);
++	for (blower = bindex + 1; blower <= bend; blower++) {
++		br = au_sbr(sb, blower);
++		if (au_br_fhsm(br->br_perm)) {
++			do_notify = 1;
++			break;
++		}
++	}
++	if (!do_notify)
++		return;
++
++	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);
++}
++
++void au_fhsm_wrote_all(struct super_block *sb, int force)
++{
++	aufs_bindex_t bindex, bend;
++	struct au_branch *br;
++
++	/* exclude the bottom */
++	bend = au_sbend(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);
++	}
++}
++
++/* ---------------------------------------------------------------------- */
++
++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_fhsm_do_read_one(struct aufs_stbr __user *stbr,
++			      struct aufs_stfs *stfs, __s16 brid)
++{
++	int err;
++
++	err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
++	if (!err)
++		err = __put_user(brid, &stbr->brid);
++	if (unlikely(err))
++		err = -EFAULT;
++
++	return err;
++}
++
++static ssize_t au_fhsm_do_read(struct super_block *sb,
++			       struct aufs_stbr __user *stbr, size_t count)
++{
++	ssize_t err;
++	int nstbr;
++	aufs_bindex_t bindex, bend;
++	struct au_branch *br;
++	struct au_br_fhsm *bf;
++
++	/* except the bottom branch */
++	err = 0;
++	nstbr = 0;
++	bend = au_sbend(sb);
++	for (bindex = 0; !err && bindex < bend; bindex++) {
++		br = au_sbr(sb, bindex);
++		if (!au_br_fhsm(br->br_perm))
++			continue;
++
++		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;
++
++	return err;
++}
++
++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;
++
++	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;
++
++	/* 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_sbend(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_rw_read_unlock(&sbinfo->si_rwsem);
++	if (!readable)
++		goto need_data;
++
++out:
++	return err;
++}
++
++static int au_fhsm_release(struct inode *inode, struct file *file)
++{
++	struct au_sbinfo *sbinfo;
++	struct au_fhsm *fhsm;
++
++	/* 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, fd;
++	struct au_sbinfo *sbinfo;
++	struct au_fhsm *fhsm;
++
++	err = -EPERM;
++	if (unlikely(!capable(CAP_SYS_ADMIN)))
++		goto out;
++
++	err = -EINVAL;
++	if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
++		goto out;
++
++	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;
++}
++
++/* ---------------------------------------------------------------------- */
++
++int au_fhsm_br_alloc(struct au_branch *br)
++{
++	int err;
++
++	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;
++
++	return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++void au_fhsm_fin(struct super_block *sb)
++{
++	au_fhsm_notify(sb, /*val*/-1);
++}
++
++void au_fhsm_init(struct au_sbinfo *sbinfo)
++{
++	struct au_fhsm *fhsm;
++
++	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);
++}
++
++void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
++{
++	sbinfo->si_fhsm.fhsm_expire
++		= msecs_to_jiffies(sec * MSEC_PER_SEC);
++}
++
++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	2014-06-24 00:14:06.782719306 +0200
-@@ -0,0 +1,711 @@
++++ linux/fs/aufs/file.c	2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,835 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -10936,24 +11784,149 @@ diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
 +	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 *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);
++	inode = dentry->d_inode;
++	IiMustWriteLock(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 (!S_ISREG(inode->i_mode))
++		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, int (*open)(struct file *file, int flags),
 +	       struct au_fidir *fidir)
 +{
 +	int err;
 +	struct dentry *dentry;
++	struct au_finfo *finfo;
 +
 +	err = au_finfo_init(file, fidir);
 +	if (unlikely(err))
 +		goto out;
 +
 +	dentry = file->f_dentry;
-+	di_read_lock_child(dentry, AuLock_IR);
-+	err = open(file, vfsub_file_flags(file));
++	di_write_lock_child(dentry);
++	err = au_cmoo(dentry);
++	di_downgrade_lock(dentry, AuLock_IR);
++	if (!err)
++		err = open(file, vfsub_file_flags(file));
 +	di_read_unlock(dentry, AuLock_IR);
 +
++	finfo = au_fi(file);
++	if (!err) {
++		finfo->fi_file = file;
++		au_sphl_add(&finfo->fi_hlist,
++			    &au_sbi(file->f_dentry->d_sb)->si_files);
++	}
 +	fi_write_unlock(file);
 +	if (unlikely(err)) {
-+		au_fi(file)->fi_hdir = NULL;
++		finfo->fi_hdir = NULL;
 +		au_finfo_fin(file);
 +	}
 +
@@ -11459,8 +12432,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)
++			      struct iov_iter *iter, loff_t offset)
 +{ BUG(); return 0; }
 +
 +/*
@@ -11538,7 +12510,7 @@ 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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/file.h	2014-08-14 10:15:45.121942630 +0200
 @@ -0,0 +1,289 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -11831,7 +12803,7 @@ diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
 +#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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/finfo.c	2014-01-30 21:10:02.850815069 +0100
 @@ -0,0 +1,156 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -11991,8 +12963,8 @@ 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	2014-06-24 00:14:06.782719306 +0200
-@@ -0,0 +1,782 @@
++++ linux/fs/aufs/f_op.c	2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,813 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -12051,8 +13023,6 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +		au_set_fbstart(file, bindex);
 +		au_set_h_fptr(file, bindex, h_file);
 +		au_update_figen(file);
-+		finfo->fi_file = file;
-+		au_sphl_add(&finfo->fi_hlist, &au_sbi(dentry->d_sb)->si_files);
 +		/* todo: necessary? */
 +		/* file->f_ra = h_file->f_ra; */
 +	}
@@ -12178,10 +13148,12 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +			  size_t count, loff_t *ppos)
 +{
 +	ssize_t err;
++	blkcnt_t blks;
++	aufs_bindex_t bstart;
 +	struct au_pin pin;
 +	struct dentry *dentry;
++	struct inode *inode, *h_inode;
 +	struct super_block *sb;
-+	struct inode *inode;
 +	struct file *h_file;
 +	char __user *buf = (char __user *)ubuf;
 +
@@ -12202,8 +13174,11 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +		goto out;
 +	}
 +
++	bstart = au_fbstart(file);
 +	h_file = au_hf_top(file);
 +	get_file(h_file);
++	h_inode = h_file->f_dentry->d_inode;
++	blks = h_inode->i_blocks;
 +	au_unpin(&pin);
 +	di_read_unlock(dentry, AuLock_IR);
 +	fi_write_unlock(file);
@@ -12212,6 +13187,9 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +	ii_write_lock_child(inode);
 +	au_cpup_attr_timesizes(inode);
 +	inode->i_mode = file_inode(h_file)->i_mode;
++	AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
++	if (err > 0)
++		au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
 +	ii_write_unlock(inode);
 +	fput(h_file);
 +
@@ -12221,41 +13199,50 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +	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)
++static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
++			  struct iov_iter *iov_iter)
 +{
 +	ssize_t err;
 +	struct file *file;
-+	ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
-+			loff_t);
++	ssize_t (*iter)(struct kiocb *, struct iov_iter *);
++	ssize_t (*aio)(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;
++	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;
++	}
++
++	file = kio->ki_filp;
++	kio->ki_filp = h_file;
++	if (iter) {
 +		lockdep_off();
-+		err = func(kio, iov, nv, pos);
++		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();
-+		kio->ki_filp = file;
 +	} else
 +		/* currently there is no such fs */
 +		WARN_ON_ONCE(1);
++	kio->ki_filp = file;
 +
 +out:
 +	return err;
 +}
 +
-+static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
-+			     unsigned long nv, loff_t pos)
++static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
 +{
 +	ssize_t err;
 +	struct file *file, *h_file;
@@ -12275,7 +13262,7 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +	di_read_unlock(dentry, AuLock_IR);
 +	fi_read_unlock(file);
 +
-+	err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
++	err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
 +	/* todo: necessary? */
 +	/* file->f_ra = h_file->f_ra; */
 +	/* update without lock, I don't think it a problem */
@@ -12287,13 +13274,14 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +	return err;
 +}
 +
-+static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
-+			      unsigned long nv, loff_t pos)
++static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
 +{
 +	ssize_t err;
++	blkcnt_t blks;
++	aufs_bindex_t bstart;
 +	struct au_pin pin;
 +	struct dentry *dentry;
-+	struct inode *inode;
++	struct inode *inode, *h_inode;
 +	struct file *file, *h_file;
 +	struct super_block *sb;
 +
@@ -12315,16 +13303,22 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +		goto out;
 +	}
 +
++	bstart = au_fbstart(file);
 +	h_file = au_hf_top(file);
 +	get_file(h_file);
++	h_inode = h_file->f_dentry->d_inode;
++	blks = h_inode->i_blocks;
 +	au_unpin(&pin);
 +	di_read_unlock(dentry, AuLock_IR);
 +	fi_write_unlock(file);
 +
-+	err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
++	err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
 +	ii_write_lock_child(inode);
 +	au_cpup_attr_timesizes(inode);
 +	inode->i_mode = file_inode(h_file)->i_mode;
++	AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
++	if (err > 0)
++		au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
 +	ii_write_unlock(inode);
 +	fput(h_file);
 +
@@ -12380,11 +13374,13 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +		  size_t len, unsigned int flags)
 +{
 +	ssize_t err;
++	blkcnt_t blks;
++	aufs_bindex_t bstart;
 +	struct au_pin pin;
 +	struct dentry *dentry;
-+	struct inode *inode;
-+	struct file *h_file;
++	struct inode *inode, *h_inode;
 +	struct super_block *sb;
++	struct file *h_file;
 +
 +	dentry = file->f_dentry;
 +	sb = dentry->d_sb;
@@ -12403,8 +13399,11 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +		goto out;
 +	}
 +
++	bstart = au_fbstart(file);
 +	h_file = au_hf_top(file);
 +	get_file(h_file);
++	h_inode = h_file->f_dentry->d_inode;
++	blks = h_inode->i_blocks;
 +	au_unpin(&pin);
 +	di_read_unlock(dentry, AuLock_IR);
 +	fi_write_unlock(file);
@@ -12413,6 +13412,9 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +	ii_write_lock_child(inode);
 +	au_cpup_attr_timesizes(inode);
 +	inode->i_mode = file_inode(h_file)->i_mode;
++	AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
++	if (err > 0)
++		au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
 +	ii_write_unlock(inode);
 +	fput(h_file);
 +
@@ -12750,8 +13752,9 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +
 +	.read		= aufs_read,
 +	.write		= aufs_write,
-+	.aio_read	= aufs_aio_read,
-+	.aio_write	= aufs_aio_write,
++	.read_iter	= aufs_read_iter,
++	.write_iter	= aufs_write_iter,
++
 +#ifdef CONFIG_AUFS_POLL
 +	.poll		= aufs_poll,
 +#endif
@@ -12777,7 +13780,7 @@ diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
 +};
 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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/fstype.h	2014-01-30 21:10:02.850815069 +0100
 @@ -0,0 +1,469 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -13250,7 +14253,7 @@ diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
 +#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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/hfsnotify.c	2014-08-14 10:16:04.515942371 +0200
 @@ -0,0 +1,281 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -13287,7 +14290,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);
 +}
@@ -13535,7 +14538,7 @@ 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	2014-06-24 00:14:06.782719306 +0200
++++ linux/fs/aufs/hfsplus.c	2014-01-30 21:10:02.850815069 +0100
 @@ -0,0 +1,56 @@
 +/*
 + * Copyright (C) 2010-2014 Junjiro R. Okajima
@@ -13595,8 +14598,8 @@ 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	2014-06-24 00:14:06.782719306 +0200
-@@ -0,0 +1,713 @@
++++ linux/fs/aufs/hnotify.c	2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,714 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -13916,6 +14919,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)
@@ -13933,11 +14937,11 @@ diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
 +
 +	/* 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 */
 +	}
@@ -14312,7 +15316,7 @@ 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	2014-06-24 00:14:06.786052822 +0200
++++ linux/fs/aufs/iinfo.c	2014-08-14 10:15:45.128609525 +0200
 @@ -0,0 +1,277 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -14593,8 +15597,8 @@ 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	2014-06-24 00:14:06.786052822 +0200
-@@ -0,0 +1,491 @@
++++ linux/fs/aufs/inode.c	2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,492 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -15051,6 +16055,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));
 +
@@ -15063,7 +16068,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;
 +	}
@@ -15088,7 +16093,7 @@ 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	2014-06-24 00:14:06.786052822 +0200
++++ linux/fs/aufs/inode.h	2014-08-14 10:15:45.128609525 +0200
 @@ -0,0 +1,601 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -15693,8 +16698,8 @@ 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	2014-06-24 00:14:06.786052822 +0200
-@@ -0,0 +1,201 @@
++++ linux/fs/aufs/ioctl.c	2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,214 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -15717,6 +16722,7 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 + * plink-management and readdir in userspace.
 + * assist the pathconf(3) wrapper library.
 + * move-down
++ * File-based Hierarchical Storage Management.
 + */
 +
 +#include <linux/compat.h>
@@ -15833,6 +16839,14 @@ 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:
++		err = au_fhsm_fd(file->f_dentry->d_sb, arg);
++		break;
++
 +	default:
 +		/* do not call the lower */
 +		AuDbg("0x%x\n", cmd);
@@ -15882,6 +16896,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);
 +	}
@@ -15898,8 +16916,8 @@ diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
 +#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	2014-06-24 00:14:06.782719306 +0200
-@@ -0,0 +1,881 @@
++++ linux/fs/aufs/i_op_add.c	2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,885 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -15935,17 +16953,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))
@@ -15960,6 +16980,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +		if (au_ibstart(dir) == au_dbstart(dentry))
 +			au_cpup_attr_timesizes(dir);
 +		dir->i_version++;
++		au_fhsm_wrote(sb, bindex, /*force*/0);
 +		return 0; /* success */
 +	}
 +
@@ -16132,7 +17153,7 @@ 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 dentry *wh_dentry, *parent;
@@ -16194,7 +17215,6 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +
 +	/* revert */
 +	if (unlikely(created && err && a->h_path.dentry->d_inode)) {
-+		int rerr;
 +		/* no delegation since it is just created */
 +		rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
 +				    /*force*/0);
@@ -16643,6 +17663,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
 +	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:
@@ -16783,8 +17805,8 @@ 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	2014-06-24 00:14:06.782719306 +0200
-@@ -0,0 +1,1138 @@
++++ linux/fs/aufs/i_op.c	2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,1142 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -16889,7 +17911,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
@@ -17333,6 +18357,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +	if (!err)
 +		goto out; /* success */
 +
++	au_unpin(p);
++
 +out_err:
 +	pr_err("err %d\n", err);
 +	err = au_busy_or_stale();
@@ -17678,7 +18704,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +			struct dentry *dentry, struct kstat *st)
 +{
 +	int err;
-+	unsigned int mnt_flags;
++	unsigned int mnt_flags, sigen;
 +	aufs_bindex_t bindex;
 +	unsigned char udba_none, positive;
 +	struct super_block *sb, *h_sb;
@@ -17695,7 +18721,7 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +
 +	/* 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);
@@ -17925,8 +18951,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
 +};
 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	2014-06-24 00:14:06.782719306 +0200
-@@ -0,0 +1,506 @@
++++ linux/fs/aufs/i_op_del.c	2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,507 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -18055,11 +19081,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;
@@ -18435,8 +19462,8 @@ diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
 +}
 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	2014-06-24 00:14:06.786052822 +0200
-@@ -0,0 +1,1032 @@
++++ linux/fs/aufs/i_op_ren.c	2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,1034 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -18721,7 +19748,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;
 +}
@@ -18821,6 +19849,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;
 +
@@ -19471,8 +20500,8 @@ 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	2014-06-24 00:14:06.776052275 +0200
-@@ -0,0 +1,168 @@
++++ linux/fs/aufs/Kconfig	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,177 @@
 +config AUFS_FS
 +	tristate "Aufs (Advanced multi layered unification filesystem) support"
 +	help
@@ -19562,6 +20591,15 @@ 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_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
@@ -19643,7 +20681,7 @@ diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
 +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	2014-06-24 00:14:06.786052822 +0200
++++ linux/fs/aufs/loop.c	2014-01-30 21:10:02.850815069 +0100
 @@ -0,0 +1,145 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -19792,7 +20830,7 @@ diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
 +}
 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	2014-06-24 00:14:06.786052822 +0200
++++ linux/fs/aufs/loop.h	2014-01-30 21:10:02.850815069 +0100
 @@ -0,0 +1,52 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -19848,7 +20886,7 @@ diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
 +#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	2014-06-24 00:14:06.786052822 +0200
++++ linux/fs/aufs/magic.mk	2014-01-30 21:10:02.850815069 +0100
 @@ -0,0 +1,54 @@
 +
 +# defined in ${srctree}/fs/fuse/inode.c
@@ -19906,8 +20944,8 @@ diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
 +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	2014-06-24 00:14:06.776052275 +0200
-@@ -0,0 +1,41 @@
++++ linux/fs/aufs/Makefile	2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,42 @@
 +
 +include ${src}/magic.mk
 +ifeq (${CONFIG_AUFS_FS},m)
@@ -19944,6 +20982,7 @@ diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
 +aufs-$(CONFIG_AUFS_EXPORT) += export.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
@@ -19951,8 +20990,8 @@ diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
 +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	2014-06-24 00:14:06.786052822 +0200
-@@ -0,0 +1,202 @@
++++ linux/fs/aufs/module.c	2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,210 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -20064,6 +21103,11 @@ diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
 +
++/* 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);
++
 +/* ---------------------------------------------------------------------- */
 +
 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
@@ -20114,9 +21158,12 @@ diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
 +	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 */
@@ -20157,7 +21204,7 @@ diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
 +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	2014-06-24 00:14:06.786052822 +0200
++++ linux/fs/aufs/module.h	2014-01-30 21:10:02.850815069 +0100
 @@ -0,0 +1,104 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
@@ -20265,8 +21312,8 @@ diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
 +#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	2014-06-24 00:14:06.786052822 +0200
-@@ -0,0 +1,627 @@
++++ linux/fs/aufs/mvdown.c	2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,657 @@
 +/*
 + * Copyright (C) 2011-2014 Junjiro R. Okajima
 + *
@@ -20308,10 +21355,10 @@ diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
 +};
 +
 +#define mvd_errno		mvdown.au_errno
-+#define mvd_bsrc		mvdown.a[AUFS_MVDOWN_UPPER].bindex
-+#define mvd_src_brid		mvdown.a[AUFS_MVDOWN_UPPER].brid
-+#define mvd_bdst		mvdown.a[AUFS_MVDOWN_LOWER].bindex
-+#define mvd_dst_brid		mvdown.a[AUFS_MVDOWN_LOWER].brid
++#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
@@ -20330,6 +21377,42 @@ diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
 +			pr_err(__VA_ARGS__);		\
 +	} while (0)
 +
++static int find_lower_writable(struct au_mvd_args *a)
++{
++	struct super_block *sb;
++	aufs_bindex_t bindex, bend;
++	struct au_branch *br;
++
++	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;
++}
++
 +/* make the parent dir on bdst */
 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
 +{
@@ -20497,6 +21580,26 @@ diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
 +	return err;
 +}
 +
++/* 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;
++
++	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
@@ -20526,6 +21629,12 @@ diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
 +	if (unlikely(err))
 +		goto out_unlock;
 +
++	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);
@@ -20547,36 +21656,6 @@ diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
 +
 +/* ---------------------------------------------------------------------- */
 +
-+static int find_lower_writable(struct au_mvd_args *a)
-+{
-+	struct super_block *sb;
-+	aufs_bindex_t bindex, bend;
-+	struct au_branch *br;
-+
-+	sb = a->sb;
-+	bindex = a->mvd_bsrc;
-+	bend = au_sbend(sb);
-+	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;
-+}
-+
 +/* make sure the file is idle */
 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
 +{
@@ -20822,8 +21901,6 @@ diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
 +	if (unlikely(!capable(CAP_SYS_ADMIN)))
 +		goto out;
 +
-+	WARN_ONCE(1, "move-down is still testing...\n");
-+
 +	err = -ENOMEM;
 +	args = kmalloc(sizeof(*args), GFP_NOFS);
 +	if (unlikely(!args))
@@ -20896,8 +21973,8 @@ diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
 +}
 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	2014-06-24 00:14:06.786052822 +0200
-@@ -0,0 +1,1701 @@
++++ linux/fs/aufs/opts.c	2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,1790 @@
 +/*
 + * Copyright (C) 2005-2014 Junjiro R. Okajima
 + *
@@ -20945,9 +22022,11 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +	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_tail, Opt_ignore, Opt_ignore_silent, Opt_err
 +};
 +
@@ -21001,6 +22080,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"},
@@ -21010,9 +22095,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
@@ -21020,6 +22103,9 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +#endif
 +	{Opt_noshwh, "noshwh"},
 +
++	{Opt_dirperm1, "dirperm1"},
++	{Opt_nodirperm1, "nodirperm1"},
++
 +	{Opt_rendir, "rendir=%d"},
 +
 +	{Opt_refrof, "refrof"},
@@ -21065,17 +22151,37 @@ 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;
++	p = tbl;
++	while (p->token) {
++		if ((v & p->token) == p->token) {
++			*val &= ~p->token;
++			return p->pattern;
++		}
++		p++;
++	}
++	return NULL;
++}
++
 +/* ---------------------------------------------------------------------- */
 +
 +static match_table_t brperm = {
@@ -21086,16 +22192,22 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +};
 +
 +static match_table_t brattr = {
++	/* general */
++	{AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
++	{AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
 +	{AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
++	{AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
++
++	/* ro/rr branch */
 +	{AuBrRAttr_WH, AUFS_BRRATTR_WH},
++
++	/* rw branch */
++	{AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
 +	{AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
++
 +	{0, NULL}
 +};
 +
-+#define AuBrStr_LONGEST	AUFS_BRPERM_RW \
-+	"+" AUFS_BRATTR_UNPIN \
-+	"+" AUFS_BRWATTR_NLWH
-+
 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
 +{
 +	int attr, v;
@@ -21107,9 +22219,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);
@@ -21122,11 +22236,43 @@ 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;
++
++	sz = 0;
++	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 sz;
++}
++
 +static int noinline_for_stack br_perm_val(char *perm)
 +{
-+	int val;
-+	char *p, *q;
++	int val, bad, sz;
++	char *p;
 +	substring_t args[MAX_OPT_ARGS];
++	au_br_perm_str_t attr;
 +
 +	p = strchr(perm, '+');
 +	if (p)
@@ -21142,83 +22288,51 @@ diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
 +	if (!p)
 +		goto out;
 +
-+	p++;
-+	while (1) {
-+		q = strchr(p, '+');
-+		if (q)
-+			*q = 0;
-+		val |= br_attr_val(p, brattr, args);
-+		if (q) {
-+			*q = '+';
-+			p = q + 1;
-+		} else
-+			break;
-+	}
++	val |= br_attr_val(p + 1, brattr, args);
++
++	bad = 0;
 +	switch (val & AuBrPerm_Mask) {
 +	case AuBrPerm_RO:
 +	case AuBrPerm_RR:
-+		if (unlikely(val & AuBrWAttr_NoLinkWH)) {
-+			pr_warn("ignored branch attribute %s\n",
-+				AUFS_BRWATTR_NLWH);
-+			val &= ~AuBrWAttr_NoLinkWH;
-+		}
++		bad = val & AuBrWAttr_Mask;
++		val &= ~AuBrWAttr_Mask;
 +		break;
 +	case AuBrPerm_RW:
-+		if (unlikely(val & AuBrRAttr_WH)) {
-+			pr_warn("ignored branch attribute %s\n",
-+				AUFS_BRRATTR_WH);
-+			val &= ~AuBrRAttr_WH;
-+		}
++		bad = val & AuBrRAttr_Mask;
++		val &= ~AuBrRAttr_Mask;
 +		break;
 +	}
++	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(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
-+	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));
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -21244,7 +22358,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);
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -21366,7 +22480,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 = {
@@ -21388,7 +22502,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);
 +}
 +
 +/* ---------------------------------------------------------------------- */
@@ -21491,6 +22605,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;
@@ -21568,6 +22688,9 @@ 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;
 +		default:
 +			BUG();
 +		}
@@ -21994,6 +23117,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:
@@ -22044,6 +23169,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*/
@@ -22160,6 +23299,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;
@@ -22235,6 +23378,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;
@@ -22366,7 +23516,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,
<Skipped 2076 lines>
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/kernel.git/commitdiff/076b876ecc3a67cef4a0595132374ac1bea1d0be



More information about the pld-cvs-commit mailing list