-aufs3.13 kbuild patch
+aufs3.16 kbuild patch
diff --git a/fs/Kconfig b/fs/Kconfig
-index c229f82..397b473 100644
+index 312393f..78632ed 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
-@@ -212,6 +212,7 @@ source "fs/ufs/Kconfig"
+@@ -209,6 +209,7 @@ source "fs/ufs/Kconfig"
source "fs/exofs/Kconfig"
source "fs/f2fs/Kconfig"
source "fs/efivarfs/Kconfig"
endif # MISC_FILESYSTEMS
diff --git a/fs/Makefile b/fs/Makefile
-index 4fe6df3..4a57676 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 33d2b8f..b55eeb9 100644
+index 24e9033..fe9a8d4 100644
--- a/include/uapi/linux/Kbuild
+++ b/include/uapi/linux/Kbuild
@@ -56,6 +56,7 @@ header-y += atmppp.h
header-y += auto_fs.h
header-y += auto_fs4.h
header-y += auxvec.h
-aufs3.13 base patch
+aufs3.16 base patch
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
-index c8dac73..2e229ac 100644
+index 6cb1beb..30efd68 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
-@@ -691,6 +691,24 @@ static inline int is_loop_device(struct file *file)
+@@ -692,6 +692,24 @@ static inline int is_loop_device(struct file *file)
return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
}
static ssize_t loop_attr_show(struct device *dev, char *page,
diff --git a/fs/inode.c b/fs/inode.c
-index 4bcdad3..bc83168 100644
+index 6eecb7f..b225c0f 100644
--- a/fs/inode.c
+++ b/fs/inode.c
-@@ -1497,7 +1497,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
+@@ -1496,7 +1496,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
* This does the actual work of updating an inodes time or version. Must have
* had called mnt_want_write() before calling this.
*/
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 46a08f7..719ca3e 100644
+index f5cb9ba..9ba380c 100644
--- a/fs/splice.c
+++ b/fs/splice.c
-@@ -1093,8 +1093,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
+@@ -1114,8 +1114,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
/*
* Attempt to initiate a splice from pipe to file.
*/
{
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
loff_t *, size_t, unsigned int);
-@@ -1110,9 +1110,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.
*/
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 121f11f..39bf86d 100644
+index e11d60c..2f32b35 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
-@@ -2657,6 +2657,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);
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 74575cb..bfc6fb6 100644
+index da2751d..2e0fca6 100644
--- a/include/linux/splice.h
+++ b/include/linux/splice.h
-@@ -92,4 +92,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;
+ struct pipe_inode_info *pipe, size_t len,
+ unsigned int flags);
#endif
-aufs3.13 standalone patch
+aufs3.16 mmap patch
+
+diff --git a/fs/buffer.c b/fs/buffer.c
+index eba6e4f..31f0b2d 100644
+--- a/fs/buffer.c
++++ b/fs/buffer.c
+@@ -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...
+ */
+- file_update_time(vma->vm_file);
++ vma_file_update_time(vma);
+
+ 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..1397181 100644
+--- a/fs/proc/nommu.c
++++ b/fs/proc/nommu.c
+@@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
+ file = region->vm_file;
+
+ 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 cfa63ee..bf4919e 100644
+--- a/fs/proc/task_mmu.c
++++ b/fs/proc/task_mmu.c
+@@ -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;
+@@ -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..0ef7ef4 100644
+--- a/fs/proc/task_nommu.c
++++ b/fs/proc/task_nommu.c
+@@ -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 e03dd29..dd32624 100644
+--- a/include/linux/mm.h
++++ b/include/linux/mm.h
+@@ -1184,6 +1184,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
+ }
+ #endif
+
++#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 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 96c5750..a087ecd 100644
+--- a/include/linux/mm_types.h
++++ b/include/linux/mm_types.h
+@@ -232,6 +232,7 @@ struct vm_region {
+ unsigned long vm_top; /* region allocated to here */
+ unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
+ struct file *vm_file; /* the backing file or NULL */
++ struct file *vm_prfile; /* the virtual backing file or NULL */
+
+ int vm_usage; /* region usage count (access under nommu_region_sem) */
+ bool vm_icache_flushed : 1; /* true if the icache has been flushed for
+@@ -300,6 +301,7 @@ struct vm_area_struct {
+ unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
+ units, *not* PAGE_CACHE_SIZE */
+ struct file * vm_file; /* File we map to (can be NULL). */
++ struct file *vm_prfile; /* shadow of vm_file */
+ void * vm_private_data; /* was vm_pte (shared mem) */
+
+ #ifndef CONFIG_MMU
+diff --git a/kernel/fork.c b/kernel/fork.c
+index 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)
+ struct inode *inode = file_inode(file);
+ struct address_space *mapping = file->f_mapping;
+
+- get_file(file);
++ vma_get_file(tmp);
+ if (tmp->vm_flags & VM_DENYWRITE)
+ atomic_dec(&inode->i_writecount);
+ 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 900edfa..f4dda0c 100644
+--- a/mm/filemap.c
++++ b/mm/filemap.c
+@@ -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);
+- file_update_time(vma->vm_file);
++ vma_file_update_time(vma);
+ lock_page(page);
+ if (page->mapping != inode->i_mapping) {
+ unlock_page(page);
+diff --git a/mm/fremap.c b/mm/fremap.c
+index 72b8fa3..a00bbf0 100644
+--- a/mm/fremap.c
++++ b/mm/fremap.c
+@@ -224,16 +224,28 @@ get_write_lock:
+ */
+ if (mapping_cap_account_dirty(mapping)) {
+ unsigned long addr;
+- struct file *file = get_file(vma->vm_file);
++ struct file *file = vma->vm_file,
++ *prfile = vma->vm_prfile;
++
+ /* mmap_region may free vma; grab the info now */
+ vm_flags = vma->vm_flags;
+
++ vma_get_file(vma);
+ addr = mmap_region(file, start, size, vm_flags, pgoff);
+- fput(file);
++ vma_fput(vma);
+ if (IS_ERR_VALUE(addr)) {
+ err = addr;
+ } else {
+ 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;
++ if (new_vma != vma)
++ get_file(prfile);
++ }
+ err = 0;
+ }
+ goto out_freed;
+diff --git a/mm/madvise.c b/mm/madvise.c
+index a402f8f..134e15d 100644
+--- a/mm/madvise.c
++++ b/mm/madvise.c
+@@ -327,12 +327,12 @@ static long madvise_remove(struct vm_area_struct *vma,
+ * vma's reference to the file) can go away as soon as we drop
+ * mmap_sem.
+ */
+- get_file(f);
++ vma_get_file(vma);
+ up_read(¤t->mm->mmap_sem);
+ error = do_fallocate(f,
+ FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+ offset, end - start);
+- fput(f);
++ vma_fput(vma);
+ down_read(¤t->mm->mmap_sem);
+ return error;
+ }
+diff --git a/mm/memory.c b/mm/memory.c
+index 8b44f76..69a72bf 100644
+--- a/mm/memory.c
++++ b/mm/memory.c
+@@ -2161,7 +2161,7 @@ reuse:
+ set_page_dirty_balance(dirty_page);
+ /* file_update_time outside page_lock */
+ if (vma->vm_file)
+- file_update_time(vma->vm_file);
++ vma_file_update_time(vma);
+ }
+ put_page(dirty_page);
+ if (page_mkwrite) {
+diff --git a/mm/mmap.c b/mm/mmap.c
+index 129b847..869d1d7 100644
+--- a/mm/mmap.c
++++ b/mm/mmap.c
+@@ -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)
+- fput(vma->vm_file);
++ vma_fput(vma);
+ mpol_put(vma_policy(vma));
+ kmem_cache_free(vm_area_cachep, vma);
+ return next;
+@@ -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);
+- fput(file);
++ vma_fput(vma);
+ }
+ if (next->anon_vma)
+ anon_vma_merge(vma, next);
+@@ -1643,8 +1643,8 @@ out:
+ return addr;
+
+ unmap_and_free_vma:
++ vma_fput(vma);
+ vma->vm_file = NULL;
+- fput(file);
+
+ /* Undo any partial mapping done by a device driver. */
+ unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
+@@ -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)
+- get_file(new->vm_file);
++ vma_get_file(new);
+
+ if (new->vm_ops && new->vm_ops->open)
+ new->vm_ops->open(new);
+@@ -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)
+- fput(new->vm_file);
++ vma_fput(new);
+ unlink_anon_vmas(new);
+ out_free_mpol:
+ mpol_put(vma_policy(new));
+@@ -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)
+- get_file(new_vma->vm_file);
++ vma_get_file(new_vma);
+ if (new_vma->vm_ops && new_vma->vm_ops->open)
+ new_vma->vm_ops->open(new_vma);
+ vma_link(mm, new_vma, prev, rb_link, rb_parent);
+diff --git a/mm/msync.c b/mm/msync.c
+index 992a167..ce1915b 100644
+--- a/mm/msync.c
++++ b/mm/msync.c
+@@ -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);
+ 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 4a852f6..b369644 100644
+--- a/mm/nommu.c
++++ b/mm/nommu.c
+@@ -658,7 +658,7 @@ static void __put_nommu_region(struct vm_region *region)
+ up_write(&nommu_region_sem);
+
+ if (region->vm_file)
+- fput(region->vm_file);
++ vmr_fput(region);
+
+ /* IO memory and memory shared directly out of the pagecache
+ * from ramfs/tmpfs mustn't be released here */
+@@ -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)
+- fput(vma->vm_file);
++ vma_fput(vma);
+ put_nommu_region(vma->vm_region);
+ kmem_cache_free(vm_area_cachep, vma);
+ }
+@@ -1385,7 +1385,7 @@ unsigned long do_mmap_pgoff(struct file *file,
+ goto error_just_free;
+ }
+ }
+- fput(region->vm_file);
++ vmr_fput(region);
+ kmem_cache_free(vm_region_jar, region);
+ region = pregion;
+ result = start;
+@@ -1461,10 +1461,10 @@ error_just_free:
+ up_write(&nommu_region_sem);
+ error:
+ if (region->vm_file)
+- fput(region->vm_file);
++ vmr_fput(region);
+ kmem_cache_free(vm_region_jar, region);
+ if (vma->vm_file)
+- fput(vma->vm_file);
++ vma_fput(vma);
+ kmem_cache_free(vm_area_cachep, vma);
+ kleave(" = %d", ret);
+ return ret;
+diff --git a/mm/prfile.c b/mm/prfile.c
+new file mode 100644
+index 0000000..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 bc83168..6dd1207 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;
/*
* Empty aops. Can be used for the cases where the user does not
-@@ -1513,6 +1514,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
+@@ -1512,6 +1513,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
mark_inode_dirty_sync(inode);
return 0;
}
/**
* touch_atime - update the access time
diff --git a/fs/namespace.c b/fs/namespace.c
-index be32ebc..d3f6f59 100644
+index 182bc41..c88e101 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
-@@ -425,6 +425,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
+@@ -453,6 +453,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
mnt_dec_writers(real_mount(mnt));
preempt_enable();
}
/**
* mnt_drop_write - give up write access to a mount
-@@ -1509,6 +1510,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
+@@ -1564,6 +1565,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
}
return 0;
}
static void cleanup_group_ids(struct mount *mnt, struct mount *end)
{
diff --git a/fs/notify/group.c b/fs/notify/group.c
-index bd2625b..2ff2a0f 100644
+index ad19959..adf290d 100644
--- a/fs/notify/group.c
+++ b/fs/notify/group.c
@@ -22,6 +22,7 @@
#include <linux/fsnotify_backend.h>
#include "fsnotify.h"
-@@ -65,6 +66,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
+@@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
{
atomic_inc(&group->refcnt);
}
/*
* Drop a reference to a group. Free it if it's through.
-@@ -74,6 +76,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
+@@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
if (atomic_dec_and_test(&group->refcnt))
fsnotify_final_destroy_group(group);
}
/*
* Create a new fsnotify_group and hold a reference for the group returned.
-@@ -102,6 +105,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
+@@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
return group;
}
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)
static int fsnotify_mark_destroy(void *ignored)
{
diff --git a/fs/open.c b/fs/open.c
-index 4b3e1ed..ce49f2b 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,
long vfs_truncate(struct path *path, loff_t length)
{
+@@ -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;
+ }
++EXPORT_SYMBOL(do_fallocate);
+
+ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
+ {
diff --git a/fs/splice.c b/fs/splice.c
-index 719ca3e..6300dc8 100644
+index 9ba380c..3419932 100644
--- a/fs/splice.c
+++ b/fs/splice.c
-@@ -1106,6 +1106,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);
}
/*
* Attempt to initiate a splice from a file to a pipe.
-@@ -1132,6 +1133,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);
}
}
+EXPORT_SYMBOL(cap_mmap_file);
diff --git a/security/device_cgroup.c b/security/device_cgroup.c
-index 7c2a0a7..a37c054 100644
+index d9d69e6..3f6f471 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -7,6 +7,7 @@
#include <linux/list.h>
#include <linux/uaccess.h>
#include <linux/seq_file.h>
-@@ -745,6 +746,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);
}
int devcgroup_inode_mknod(int mode, dev_t dev)
{
diff --git a/security/security.c b/security/security.c
-index 15b6928..ae6eba6 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)
+EXPORT_SYMBOL(security_path_link);
int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
- struct path *new_dir, struct dentry *new_dentry)
-@@ -449,6 +452,7 @@ int security_path_truncate(struct path *path)
+ struct path *new_dir, struct dentry *new_dentry,
+@@ -458,6 +461,7 @@ int security_path_truncate(struct path *path)
return 0;
return security_ops->path_truncate(path);
}
int security_path_chmod(struct path *path, umode_t mode)
{
-@@ -456,6 +460,7 @@ int security_path_chmod(struct path *path, umode_t mode)
+@@ -465,6 +469,7 @@ int security_path_chmod(struct path *path, umode_t mode)
return 0;
return security_ops->path_chmod(path, mode);
}
int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
{
-@@ -463,6 +468,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
+@@ -472,6 +477,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
return 0;
return security_ops->path_chown(path, uid, gid);
}
int security_path_chroot(struct path *path)
{
-@@ -539,6 +545,7 @@ int security_inode_readlink(struct dentry *dentry)
+@@ -557,6 +563,7 @@ int security_inode_readlink(struct dentry *dentry)
return 0;
return security_ops->inode_readlink(dentry);
}
int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
{
-@@ -553,6 +560,7 @@ int security_inode_permission(struct inode *inode, int mask)
+@@ -571,6 +578,7 @@ int security_inode_permission(struct inode *inode, int mask)
return 0;
return security_ops->inode_permission(inode, mask);
}
int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
{
-@@ -675,6 +683,7 @@ int security_file_permission(struct file *file, int mask)
+@@ -693,6 +701,7 @@ int security_file_permission(struct file *file, int mask)
return fsnotify_perm(file, mask);
}
int security_file_alloc(struct file *file)
{
-@@ -735,6 +744,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
+@@ -753,6 +762,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
return ret;
return ima_file_mmap(file, prot);
}
{
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-01-27 23:16:52.651751827 +0100
++++ 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
+ 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-01-27 23:16:52.651751827 +0100
++++ 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
+ 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-01-20 20:16:14.729463171 +0100
++++ 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
+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-01-20 20:16:14.729463171 +0100
-@@ -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
+#
+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,
+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-01-20 20:16:14.729463171 +0100
-@@ -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
+#
+"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
+ 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-01-20 20:16:14.729463171 +0100
++++ 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
+ 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-01-20 20:16:14.729463171 +0100
++++ 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
+ 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-01-20 20:16:14.729463171 +0100
++++ 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
+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-01-20 20:16:14.729463171 +0100
++++ 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
+ 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-01-20 20:16:14.729463171 +0100
++++ 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
+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-01-20 20:16:14.729463171 +0100
++++ 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
+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-01-20 20:16:14.732796615 +0100
-@@ -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
+#
+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.
+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.
+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-01-20 20:16:14.729463171 +0100
-@@ -0,0 +1,344 @@
++++ 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
+aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
+
+Note: it becomes clear that "Aufs was rejected. Let's give it up."
-+According to Christoph Hellwig, linux rejects all union-type filesystems
-+but UnionMount.
++ According to Christoph Hellwig, linux rejects all union-type
++ filesystems but UnionMount.
+<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
+
++PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
++ UnionMount, and he pointed out an issue around a directory mutex
++ lock and aufs addressed it. But it is still unsure whether aufs will
++ be merged (or any other union solution).
++<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
++
+
+1. Features
+----------------------------------------
+ then run "make install_ulib" too. And refer to the aufs manual in
+ detail.
+
++There several other patches in aufs3-standalone.git. They are all
++optional. When you meet some problems, they will help you.
++- aufs3-loopback.patch
++ Supports a nested loopback mount in a branch-fs. This patch is
++ unnecessary until aufs produces a message like "you may want to try
++ another patch for loopback file".
++- vfs-ino.patch
++ Modifies a system global kernel internal function get_next_ino() in
++ order to stop assigning 0 for an inode-number. Not directly related to
++ aufs, but recommended generally.
++- tmpfs-idr.patch
++ Keeps the tmpfs inode number as the lowest value. Effective to reduce
++ the size of aufs XINO files for tmpfs branch. Also it prevents the
++ duplication of inode number, which is important for backup tools and
++ other utilities. When you find aufs XINO files for tmpfs branch
++ growing too much, try this patch.
++
+
+4. Usage
+----------------------------------------
+"pemasu from Finland" made a donation (2013/7).
+The Parted Magic Project made a donation (2013/9 and 11).
+Pavel Barta made a donation (2013/10).
++Nikolay Pertsev made a donation (2014/5).
++James B made a donation (2014/7).
++Stefano Di Biase made a donation (2014/8).
+
+Thank you very much.
+Donations are always, including future donations, very important and
+# 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-01-20 20:16:14.732796615 +0100
++++ linux/fs/aufs/aufs.h 2014-01-30 21:10:02.827480967 +0100
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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-01-20 20:16:14.732796615 +0100
-@@ -0,0 +1,1219 @@
++++ linux/fs/aufs/branch.c 2014-08-14 10:16:04.512608923 +0200
+@@ -0,0 +1,1447 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ 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)
+ 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);
+ if (!err)
+ return add_branch; /* success */
+
++out_wbr:
+ kfree(add_branch->br_wbr);
-+
+out_hnotify:
+ au_hnotify_fin_br(add_branch);
+out_br:
+
+/* ---------------------------------------------------------------------- */
+
++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
+ */
+ 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;
+
+ return err;
+}
+
-+static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
-+ const aufs_bindex_t bindex,
-+ const aufs_bindex_t bend)
++static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
++ struct file **to_free, int *idx)
+{
-+ struct au_branch **brp, **p;
++ int err;
++ unsigned char matched, unmatched;
++ aufs_bindex_t bindex, bend;
++ struct au_fidir *fidir;
++ struct au_hfile *hfile;
+
-+ AuRwMustWriteLock(&sbinfo->si_rwsem);
++ 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;
+
-+ brp = sbinfo->si_branch + bindex;
-+ if (bindex < bend)
-+ memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
-+ sbinfo->si_branch[0 + bend] = NULL;
-+ sbinfo->si_bend--;
++ if (hfile->hf_br->br_id == br_id)
++ matched = 1;
++ else
++ unmatched = 1;
++ if (matched && unmatched)
++ break;
++ }
++ if (!matched)
++ goto out; /* success */
+
-+ p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
-+ if (p)
-+ sbinfo->si_branch = p;
-+ /* harmless error */
++ if (unmatched) {
++ get_file(file);
++ to_free[*idx] = file;
++ (*idx)++;
++ } else
++ err = -EBUSY;
++
++out:
++ return err;
+}
+
-+static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
-+ const aufs_bindex_t bend)
++static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
++ struct file **to_free, int opened)
+{
-+ struct au_hdentry *hdp, *p;
-+
-+ AuRwMustWriteLock(&dinfo->di_rwsem);
++ 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;
+
-+ hdp = dinfo->di_hdentry;
-+ if (bindex < bend)
-+ memmove(hdp + bindex, hdp + bindex + 1,
-+ sizeof(*hdp) * (bend - bindex));
-+ hdp[0 + bend].hd_dentry = NULL;
-+ dinfo->di_bend--;
++ 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)
++{
++ struct au_branch **brp, **p;
++
++ AuRwMustWriteLock(&sbinfo->si_rwsem);
++
++ brp = sbinfo->si_branch + bindex;
++ if (bindex < bend)
++ memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
++ sbinfo->si_branch[0 + bend] = NULL;
++ sbinfo->si_bend--;
++
++ p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
++ if (p)
++ sbinfo->si_branch = p;
++ /* harmless error */
++}
++
++static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
++ const aufs_bindex_t bend)
++{
++ struct au_hdentry *hdp, *p;
++
++ AuRwMustWriteLock(&dinfo->di_rwsem);
++
++ hdp = dinfo->di_hdentry;
++ if (bindex < bend)
++ memmove(hdp + bindex, hdp + bindex + 1,
++ sizeof(*hdp) * (bend - bindex));
++ hdp[0 + bend].hd_dentry = NULL;
++ dinfo->di_bend--;
+
+ p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
+ if (p)
+ 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 */
+ }
+ 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;
+ }
+ }
+
-+ 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;
+ }
+
+ 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 {
+ }
+
+ 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);
+
+ 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;
+}
+
+ || 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;
+ unsigned int mnt_flags;
+ unsigned long long ull, max;
+ aufs_bindex_t br_id;
-+ unsigned char verbose;
++ unsigned char verbose, writer;
+ struct file *file, *hf, **array;
+ struct inode *inode;
+ struct au_hfile *hfile;
+ 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);
+ hf = hfile->hf_file;
+ /* fi_read_unlock(file); */
+ spin_lock(&hf->f_lock);
-+ hf->f_mode &= ~FMODE_WRITE;
++ writer = !!(hf->f_mode & FMODE_WRITER);
++ hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
+ spin_unlock(&hf->f_lock);
-+ if (!file_check_writeable(hf)) {
++ if (writer) {
++ put_write_access(file_inode(hf));
+ __mnt_drop_write(hf->f_path.mnt);
-+ file_release_write(hf);
+ }
+ }
+
+ 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);
+ 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 */
+ }
+ }
+ }
++ 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-01-20 20:16:14.732796615 +0100
-@@ -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
+ *
+#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 {
+ atomic_t br_count;
+
+ struct au_wbr *br_wbr;
++ struct au_br_fhsm *br_fhsm;
+
+ /* xino truncation */
+ atomic_t br_xino_running;
+ 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)
+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;
+#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-01-20 20:16:14.732796615 +0100
++++ linux/fs/aufs/conf.mk 2014-08-14 10:15:45.118609182 +0200
@@ -0,0 +1,37 @@
+
+AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
+ SBILIST \
+ HNOTIFY HFSNOTIFY \
+ EXPORT INO_T_64 \
++ FHSM \
+ RDU \
-+ SP_IATTR \
+ SHWH \
+ BR_RAMFS \
+ BR_FUSE POLL \
+-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-01-20 20:16:14.732796615 +0100
-@@ -0,0 +1,1277 @@
++++ linux/fs/aufs/cpup.c 2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,1301 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+
+ /*
+ * 0 can happen in revalidating.
-+ * h_inode->i_mutex is not held, but it is harmless since once i_nlink
-+ * reaches 0, it will never become positive.
++ * h_inode->i_mutex may not be held here, but it is harmless since once
++ * i_nlink reaches 0, it will never become positive except O_TMPFILE
++ * case.
++ * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
++ * the incorrect link count.
+ */
+ set_nlink(inode, h_inode->i_nlink);
+
+ int err, rerr;
+ loff_t l;
+ struct path h_path;
-+ struct inode *h_src_inode;
++ struct inode *h_src_inode, *h_dst_inode;
+
+ err = 0;
+ h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
+ if (!err && rerr)
+ err = rerr;
+ }
++ if (!err && (h_src_inode->i_state & I_LINKABLE)) {
++ h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
++ h_dst_inode = h_path.dentry->d_inode;
++ spin_lock(&h_dst_inode->i_lock);
++ h_dst_inode->i_state |= I_LINKABLE;
++ spin_unlock(&h_dst_inode->i_lock);
++ }
+
+out:
+ return err;
+ 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;
+ }
+ 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)
+ if (!au_opt_test(mnt_flags, UDBA_NONE)
+ && !isdir
+ && au_opt_test(mnt_flags, XINO)
-+ && h_inode->i_nlink == 1
++ && (h_inode->i_nlink == 1
++ || (h_inode->i_state & I_LINKABLE))
+ /* todo: unnecessary? */
+ /* && cpg->dentry->d_inode->i_nlink == 1 */
+ && cpg->bdst < cpg->bsrc
+ 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;
+ goto out_rev;
+
+ if (!isdir
-+ && h_src->d_inode->i_nlink > 1
++ && (h_src->d_inode->i_nlink > 1
++ || h_src->d_inode->i_state & I_LINKABLE)
+ && plink)
+ au_plink_append(inode, cpg->bdst, h_dst);
+
+}
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-01-20 20:16:14.732796615 +0100
++++ linux/fs/aufs/cpup.h 2014-01-30 21:10:02.827480967 +0100
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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-01-20 20:16:14.732796615 +0100
++++ linux/fs/aufs/dbgaufs.c 2014-01-30 21:10:02.827480967 +0100
@@ -0,0 +1,432 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+}
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-01-20 20:16:14.732796615 +0100
++++ linux/fs/aufs/dbgaufs.h 2014-01-30 21:10:02.827480967 +0100
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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-01-20 20:16:14.732796615 +0100
++++ linux/fs/aufs/dcsub.c 2014-01-30 21:10:02.827480967 +0100
@@ -0,0 +1,243 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+}
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-01-20 20:16:14.736130059 +0100
-@@ -0,0 +1,98 @@
++++ linux/fs/aufs/dcsub.h 2014-08-14 10:15:45.118609182 +0200
+@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+{
+ int err;
+ struct inode *inode = d->d_inode;
++
+ err = 0;
+ if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
+ err = -ENOENT;
+ return err;
+}
+
++static inline int au_d_linkable(struct dentry *d)
++{
++ int err;
++ struct inode *inode = d->d_inode;
++
++ err = au_d_hashed_positive(d);
++ if (err
++ && inode
++ && (inode->i_state & I_LINKABLE))
++ err = 0;
++ return err;
++}
++
+static inline int au_d_alive(struct dentry *d)
+{
+ int err;
+ struct inode *inode;
++
+ err = 0;
+ if (!IS_ROOT(d))
+ err = au_d_hashed_positive(d);
+static inline int au_alive_dir(struct dentry *d)
+{
+ int err;
++
+ err = au_d_alive(d);
+ if (unlikely(err || IS_DEADDIR(d->d_inode)))
+ err = -ENOENT;
+ return err;
+}
+
++static inline int au_qstreq(struct qstr *a, struct qstr *b)
++{
++ return a->len == b->len
++ && !memcmp(a->name, b->name, a->len);
++}
++
+#endif /* __KERNEL__ */
+#endif /* __AUFS_DCSUB_H__ */
diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
--- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/debug.c 2014-01-20 20:16:14.736130059 +0100
-@@ -0,0 +1,517 @@
++++ linux/fs/aufs/debug.c 2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,519 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+{
+ 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));
+ 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;
+ dinfo = au_di(dentry);
+ if (!dinfo)
+ return;
-+ dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
++ dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
+ dinfo->di_bstart, dinfo->di_bend,
-+ dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
++ dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
++ dinfo->di_tmpfile);
+ if (dinfo->di_bstart < 0)
+ return;
+ hdp = dinfo->di_hdentry;
+}
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-01-20 20:16:14.736130059 +0100
++++ linux/fs/aufs/debug.h 2014-01-30 21:10:02.827480967 +0100
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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-01-27 23:16:52.701753487 +0100
-@@ -0,0 +1,1081 @@
++++ linux/fs/aufs/dentry.c 2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,1094 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+#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)
+ 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;
+ 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;
+
+ 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);
+{
+ 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,
+ 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;
+
+ 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);
+ 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;
+ 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",
+ 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;
+ 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;
+ if (!ebrange)
+ ebrange = au_do_refresh_hdentry(dentry, parent);
+
-+ if (d_unhashed(dentry) || ebrange) {
++ if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
+ AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
+ if (inode)
+ err = au_refresh_hinode_self(inode);
+ int err;
+ umode_t mode, h_mode;
+ aufs_bindex_t bindex, btail, bstart, ibs, ibe;
-+ unsigned char plus, unhashed, is_root, h_plus, h_nfs;
++ unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
+ struct inode *h_inode, *h_cached_inode;
+ struct dentry *h_dentry;
+ struct qstr *name, *h_name;
+ unhashed = !!d_unhashed(dentry);
+ is_root = !!IS_ROOT(dentry);
+ name = &dentry->d_name;
++ tmpfile = au_di(dentry)->di_tmpfile;
+
+ /*
+ * Theoretically, REVAL test should be unnecessary in case of
+ * {FS,I}NOTIFY.
+ * But {fs,i}notify doesn't fire some necessary events,
+ * IN_ATTRIB for atime/nlink/pageio
-+ * IN_DELETE for NFS dentry
+ * Let's do REVAL test too.
+ */
+ if (do_udba && inode) {
+ && !is_root
+ && ((!h_nfs
+ && (unhashed != !!d_unhashed(h_dentry)
-+ || name->len != h_name->len
-+ || memcmp(name->name, h_name->name,
-+ name->len)))
++ || (!tmpfile
++ && !au_qstreq(name, h_name))
++ ))
+ || (h_nfs
+ && !(flags & LOOKUP_OPEN)
+ && (h_dentry->d_flags
+ & DCACHE_NFSFS_RENAMED)))
+ )) {
-+ AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
-+ unhashed, d_unhashed(h_dentry),
-+ dentry, h_dentry);
++ int h_unhashed;
++
++ h_unhashed = d_unhashed(h_dentry);
+ spin_unlock(&h_dentry->d_lock);
++ AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
++ unhashed, h_unhashed, dentry, h_dentry);
+ goto err;
+ }
+ spin_unlock(&h_dentry->d_lock);
+ h_cached_inode = au_h_iptr(inode, bindex);
+
+ if (!h_nfs) {
-+ if (unlikely(plus != h_plus))
++ if (unlikely(plus != h_plus && !tmpfile))
+ goto err;
+ } else {
+ if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
+ err = -EINVAL;
+ if (!(flags & LOOKUP_OPEN)
+ && inode
++ && !(inode->i_state && I_LINKABLE)
+ && (IS_DEADDIR(inode) || !inode->i_nlink))
+ goto out_inval;
+
+};
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-01-20 20:16:14.736130059 +0100
++++ linux/fs/aufs/dentry.h 2014-08-14 10:15:45.121942630 +0200
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+
+ struct au_rwsem di_rwsem;
+ aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
++ unsigned char di_tmpfile; /* to allow the different name */
+ struct au_hdentry *di_hdentry;
+} ____cacheline_aligned_in_smp;
+
+/* 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);
+
+#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-01-20 20:16:14.736130059 +0100
-@@ -0,0 +1,542 @@
++++ linux/fs/aufs/dinfo.c 2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,544 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ dinfo->di_bend = -1;
+ dinfo->di_bwh = -1;
+ dinfo->di_bdiropq = -1;
++ dinfo->di_tmpfile = 0;
+ for (i = 0; i < nbr; i++)
+ dinfo->di_hdentry[i].hd_id = -1;
+ goto out;
+
+/*
+ * extended version of au_h_dptr().
-+ * returns a hashed and positive h_dentry in bindex, NULL, or error.
++ * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
++ * error.
+ */
+struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
+{
+ if (au_dbstart(dentry) <= bindex
+ && bindex <= au_dbend(dentry))
+ h_dentry = au_h_dptr(dentry, bindex);
-+ if (h_dentry && !au_d_hashed_positive(h_dentry)) {
++ if (h_dentry && !au_d_linkable(h_dentry)) {
+ dget(h_dentry);
+ goto out; /* success */
+ }
+ h_dentry = d_find_alias(h_inode);
+ if (h_dentry) {
+ if (!IS_ERR(h_dentry)) {
-+ if (!au_d_hashed_positive(h_dentry))
++ if (!au_d_linkable(h_dentry))
+ goto out; /* success */
+ dput(h_dentry);
+ } else
+}
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-01-27 23:16:52.701753487 +0100
-@@ -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
+ *
+ 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);
+ .actor = au_diractor(test_empty_cb)
+ }
+ };
++ int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
+
+ SiMustAnyLock(dentry->d_sb);
+
+ 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;
+
+ 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);
+ }
+ }
+
+};
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-01-20 20:16:14.736130059 +0100
++++ linux/fs/aufs/dir.h 2014-01-30 21:10:02.830814411 +0100
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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-01-20 20:16:14.736130059 +0100
++++ linux/fs/aufs/dynop.c 2014-01-30 21:10:02.830814411 +0100
@@ -0,0 +1,379 @@
+/*
+ * Copyright (C) 2010-2014 Junjiro R. Okajima
+}
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-01-20 20:16:14.736130059 +0100
++++ linux/fs/aufs/dynop.h 2014-01-30 21:10:02.830814411 +0100
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2010-2014 Junjiro R. Okajima
+#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-01-20 20:16:14.736130059 +0100
++++ linux/fs/aufs/export.c 2014-01-30 21:10:02.830814411 +0100
@@ -0,0 +1,831 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ BUILD_BUG_ON(sizeof(u) != sizeof(int));
+ atomic_set(&sbinfo->si_xigen_next, u);
+}
-diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
---- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/file.c 2014-01-20 20:16:14.736130059 +0100
-@@ -0,0 +1,724 @@
+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) 2005-2014 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
-+ * handling file/dir, and address_space operation
++ * File-based Hierarchy Storage Management
+ */
+
-+#ifdef CONFIG_AUFS_DEBUG
-+#include <linux/migrate.h>
-+#endif
-+#include <linux/pagemap.h>
++#include <linux/anon_inodes.h>
++#include <linux/poll.h>
++#include <linux/seq_file.h>
++#include <linux/statfs.h>
+#include "aufs.h"
+
-+/* drop flags for writing */
-+unsigned int au_file_roflags(unsigned int flags)
++static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
+{
-+ flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
-+ flags |= O_RDONLY | O_NOATIME;
-+ return flags;
-+}
++ 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-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,835 @@
++/*
++ * Copyright (C) 2005-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, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * handling file/dir, and address_space operation
++ */
++
++#ifdef CONFIG_AUFS_DEBUG
++#include <linux/migrate.h>
++#endif
++#include <linux/pagemap.h>
++#include "aufs.h"
++
++/* drop flags for writing */
++unsigned int au_file_roflags(unsigned int flags)
++{
++ flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
++ flags |= O_RDONLY | O_NOATIME;
++ return flags;
++}
+
+/* common functions to regular file and dir */
+struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
+ atomic_inc(&br->br_count);
+ h_path.dentry = h_dentry;
+ h_path.mnt = au_br_mnt(br);
-+ if (!au_special_file(h_inode->i_mode))
-+ h_file = vfsub_dentry_open(&h_path, flags);
-+ else {
-+ /* this block depends upon the configuration */
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_write_unlock(file);
-+ si_read_unlock(sb);
-+ h_file = vfsub_dentry_open(&h_path, flags);
-+ si_noflush_read_lock(sb);
-+ fi_write_lock(file);
-+ di_read_lock_child(dentry, AuLock_IR);
-+ }
++ h_file = vfsub_dentry_open(&h_path, flags);
+ if (IS_ERR(h_file))
+ goto out_br;
+
+ 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);
+ }
+
+ struct file *h_file, *h_file_tmp;
+
+ dentry = file->f_dentry;
-+ AuDebugOn(au_special_file(dentry->d_inode->i_mode));
+ bstart = au_dbstart(dentry);
+ h_file_tmp = NULL;
+ if (au_fbstart(file) == bstart) {
+ err = au_reopen_wh(file, bcpup, hi_wh);
+
+ if (!err
-+ && inode->i_nlink > 1
++ && (inode->i_nlink > 1
++ || (inode->i_state & I_LINKABLE))
+ && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
+ au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
+
+
+ sb = cpg.dentry->d_sb;
+ inode = cpg.dentry->d_inode;
-+ AuDebugOn(au_special_file(inode->i_mode));
+ cpg.bsrc = au_fbstart(file);
+ err = au_test_ro(sb, cpg.bsrc, inode);
+ if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
+ err = 0;
+ dentry = file->f_dentry;
+ inode = dentry->d_inode;
-+ AuDebugOn(au_special_file(inode->i_mode));
+ sigen = au_sigen(dentry->d_sb);
+ fi_write_lock(file);
+ figen = au_figen(file);
+
+/* 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; }
+
+/*
+static int aufs_launder_page(struct page *page)
+{ AuUnsupport(); return 0; }
+static int aufs_is_partially_uptodate(struct page *page,
-+ read_descriptor_t *desc,
-+ unsigned long from)
++ unsigned long from,
++ unsigned long count)
+{ AuUnsupport(); return 0; }
+static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
+ bool *writeback)
+};
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-01-20 20:16:14.736130059 +0100
-@@ -0,0 +1,312 @@
++++ linux/fs/aufs/file.h 2014-08-14 10:15:45.121942630 +0200
+@@ -0,0 +1,289 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+int au_do_open_nondir(struct file *file, int flags);
+int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
+
-+#ifdef CONFIG_AUFS_SP_IATTR
-+/* f_op_sp.c */
-+struct au_finfo *au_fi_sp(struct file *file);
-+int au_special_file(umode_t mode);
-+void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
-+#else
-+static inline struct au_finfo *au_fi_sp(struct file *file)
-+{
-+ return NULL;
-+}
-+AuStubInt0(au_special_file, umode_t mode)
-+static inline void au_init_special_fop(struct inode *inode, umode_t mode,
-+ dev_t rdev)
-+{
-+ init_special_inode(inode, mode, rdev);
-+}
-+#endif
-+
+/* finfo.c */
+void au_hfput(struct au_hfile *hf, struct file *file);
+void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
+
+static inline struct au_finfo *au_fi(struct file *file)
+{
-+ struct au_finfo *finfo;
-+
-+ finfo = au_fi_sp(file);
-+ if (!finfo)
-+ finfo = file->private_data;
-+ return finfo;
++ return file->private_data;
+}
+
+/* ---------------------------------------------------------------------- */
+#endif /* CONFIG_MMU */
+
+/* handle vma->vm_prfile */
-+/*static inline void au_vm_prfile_set(struct vm_area_struct *vma,
++static inline void au_vm_prfile_set(struct vm_area_struct *vma,
+ struct file *file)
+{
+ get_file(file);
+ get_file(file);
+ vma->vm_region->vm_prfile = file;
+#endif
-+}*/
++}
+
+#endif /* __KERNEL__ */
+#endif /* __AUFS_FILE_H__ */
diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
--- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/finfo.c 2014-01-20 20:16:14.736130059 +0100
++++ linux/fs/aufs/finfo.c 2014-01-30 21:10:02.850815069 +0100
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+}
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-01-20 20:16:14.736130059 +0100
-@@ -0,0 +1,718 @@
++++ 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
+ *
+ struct file *h_file;
+ struct dentry *dentry;
+ struct au_finfo *finfo;
++ struct inode *h_inode;
+
+ FiMustWriteLock(file);
+
+ if (IS_ERR(h_file))
+ err = PTR_ERR(h_file);
+ else {
++ if ((flags & __O_TMPFILE)
++ && !(flags & O_EXCL)) {
++ h_inode = file_inode(h_file);
++ spin_lock(&h_inode->i_lock);
++ h_inode->i_state |= I_LINKABLE;
++ spin_unlock(&h_inode->i_lock);
++ }
+ au_set_fbstart(file, bindex);
+ au_set_h_fptr(file, bindex, h_file);
+ au_update_figen(file);
-+ 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; */
+ }
+ 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;
+
+ 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);
+ 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);
+
+ 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;
+ 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 */
+ 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;
+
+ 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);
+
+ 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;
+ 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);
+ 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);
++
++out:
++ si_read_unlock(sb);
++ mutex_unlock(&inode->i_mutex);
++ return err;
++}
++
++static long aufs_fallocate(struct file *file, int mode, loff_t offset,
++ loff_t len)
++{
++ long err;
++ struct au_pin pin;
++ struct dentry *dentry;
++ struct super_block *sb;
++ struct inode *inode;
++ struct file *h_file;
++
++ dentry = file->f_dentry;
++ sb = dentry->d_sb;
++ inode = dentry->d_inode;
++ au_mtx_and_read_lock(inode);
++
++ err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
++ if (unlikely(err))
++ goto out;
++
++ err = au_ready_to_write(file, -1, &pin);
++ di_downgrade_lock(dentry, AuLock_IR);
++ if (unlikely(err)) {
++ di_read_unlock(dentry, AuLock_IR);
++ fi_write_unlock(file);
++ goto out;
++ }
++
++ h_file = au_hf_top(file);
++ get_file(h_file);
++ au_unpin(&pin);
++ di_read_unlock(dentry, AuLock_IR);
++ fi_write_unlock(file);
++
++ lockdep_off();
++ err = do_fallocate(h_file, mode, offset, len);
++ lockdep_on();
++ ii_write_lock_child(inode);
++ au_cpup_attr_timesizes(inode);
++ inode->i_mode = file_inode(h_file)->i_mode;
+ ii_write_unlock(inode);
+ fput(h_file);
+
+ * The similar scenario is applied to aufs_readlink() too.
+ */
+
++#if 0 /* stop calling security_file_mmap() */
+/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
+#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
+
+ | AuConv_VM_MAP(flags, DENYWRITE)
+ | AuConv_VM_MAP(flags, LOCKED);
+}
++#endif
+
+static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ lockdep_on();
+
+ au_vm_file_reset(vma, h_file);
-+ err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
-+ au_flag_conv(vma->vm_flags));
++ /*
++ * we cannot call security_mmap_file() here since it may acquire
++ * mmap_sem or i_mutex.
++ *
++ * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
++ * au_flag_conv(vma->vm_flags));
++ */
+ if (!err)
+ err = h_file->f_op->mmap(h_file, vma);
+ if (unlikely(err))
+ goto out_reset;
+
-+ // au_vm_prfile_set(vma, file);
++ au_vm_prfile_set(vma, file);
+ /* update without lock, I don't think it a problem */
+ fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
+ goto out_fput; /* success */
+
+ .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
+ .splice_read = aufs_splice_read,
+#if 0
+ .aio_splice_write = aufs_aio_splice_write,
-+ .aio_splice_read = aufs_aio_splice_read
++ .aio_splice_read = aufs_aio_splice_read,
+#endif
++ .fallocate = aufs_fallocate
+};
-diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
---- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/f_op_sp.c 2014-01-20 20:16:14.736130059 +0100
-@@ -0,0 +1,382 @@
-+/*
-+ * Copyright (C) 2005-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, see <http://www.gnu.org/licenses/>.
-+ */
-+
-+/*
-+ * file operations for special files.
-+ * while they exist in aufs virtually,
-+ * their file I/O is handled out of aufs.
-+ */
-+
-+#include <linux/aio.h>
-+#include "aufs.h"
-+
-+/*
-+ * I don't think the size of this list grows much.
-+ * so here is a very simple list implemented in order to find finfo matching a
-+ * given file.
-+ */
-+static struct au_sphlhead au_finfo_sp = {
-+ .spin = __SPIN_LOCK_INITIALIZER(au_finfo_sp.spin),
-+ .head = HLIST_HEAD_INIT
-+};
-+
-+struct au_finfo_sp {
-+ struct hlist_node hlist;
-+ struct file *file;
-+ struct au_finfo *finfo;
-+};
-+
-+struct au_finfo *au_fi_sp(struct file *file)
-+{
-+ struct au_finfo *finfo;
-+ struct au_finfo_sp *sp;
-+
-+ finfo = NULL;
-+ spin_lock(&au_finfo_sp.spin);
-+ hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
-+ if (sp->file != file)
-+ continue;
-+ finfo = sp->finfo;
-+ break;
-+ }
-+ spin_unlock(&au_finfo_sp.spin);
-+
-+ return finfo;
-+}
-+
-+static int au_fi_sp_add(struct file *file)
-+{
-+ int err;
-+ struct au_finfo_sp *sp;
-+
-+ err = -ENOMEM;
-+ sp = kmalloc(sizeof(*sp), GFP_NOFS);
-+ if (sp) {
-+ err = 0;
-+ sp->file = file;
-+ sp->finfo = file->private_data;
-+ spin_lock(&au_finfo_sp.spin);
-+ hlist_add_head(&sp->hlist, &au_finfo_sp.head);
-+ spin_unlock(&au_finfo_sp.spin);
-+ }
-+ return err;
-+}
-+
-+static void au_fi_sp_del(struct file *file)
-+{
-+ struct au_finfo_sp *sp, *do_free;
-+
-+ do_free = NULL;
-+ spin_lock(&au_finfo_sp.spin);
-+ hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
-+ if (sp->file != file)
-+ continue;
-+ hlist_del(&sp->hlist);
-+ do_free = sp;
-+ break;
-+ }
-+ spin_unlock(&au_finfo_sp.spin);
-+ kfree(do_free);
-+}
-+
-+/* ---------------------------------------------------------------------- */
-+
-+static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
-+ unsigned long nv, loff_t pos)
-+{
-+ ssize_t err;
-+ aufs_bindex_t bstart;
-+ unsigned char wbr;
-+ struct file *file, *h_file;
-+ struct super_block *sb;
-+
-+ file = kio->ki_filp;
-+ sb = file->f_dentry->d_sb;
-+ si_read_lock(sb, AuLock_FLUSH);
-+ fi_read_lock(file);
-+ bstart = au_fbstart(file);
-+ h_file = au_hf_top(file);
-+ fi_read_unlock(file);
-+ wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
-+ si_read_unlock(sb);
-+
-+ /* do not change the file in kio */
-+ AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
-+ err = h_file->f_op->aio_read(kio, iov, nv, pos);
-+ if (err > 0 && wbr)
-+ file_accessed(h_file);
-+
-+ return err;
-+}
-+
-+static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
-+ unsigned long nv, loff_t pos)
-+{
-+ ssize_t err;
-+ aufs_bindex_t bstart;
-+ unsigned char wbr;
-+ struct super_block *sb;
-+ struct file *file, *h_file;
-+
-+ file = kio->ki_filp;
-+ sb = file->f_dentry->d_sb;
-+ si_read_lock(sb, AuLock_FLUSH);
-+ fi_read_lock(file);
-+ bstart = au_fbstart(file);
-+ h_file = au_hf_top(file);
-+ fi_read_unlock(file);
-+ wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
-+ si_read_unlock(sb);
-+
-+ /* do not change the file in kio */
-+ AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
-+ err = h_file->f_op->aio_write(kio, iov, nv, pos);
-+ return err;
-+}
-+
-+/* ---------------------------------------------------------------------- */
-+
-+static int aufs_release_sp(struct inode *inode, struct file *file)
-+{
-+ int err;
-+ struct file *h_file;
-+
-+ fi_read_lock(file);
-+ h_file = au_hf_top(file);
-+ fi_read_unlock(file);
-+ /* close this fifo in aufs */
-+ err = h_file->f_op->release(inode, file); /* ignore */
-+ aufs_release_nondir(inode, file); /* ignore */
-+ au_fi_sp_del(file);
-+ return err;
-+}
-+
-+/* ---------------------------------------------------------------------- */
-+
-+/* currently, support only FIFO */
-+enum {
-+ AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
-+ /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
-+ AuSp_Last
-+};
-+static int aufs_open_sp(struct inode *inode, struct file *file);
-+static struct au_sp_fop {
-+ int done;
-+ struct file_operations fop; /* not 'const' */
-+ spinlock_t spin;
-+} au_sp_fop[AuSp_Last] = {
-+ [AuSp_FIFO] = {
-+ .fop = {
-+ .owner = THIS_MODULE,
-+ .open = aufs_open_sp
-+ }
-+ }
-+};
-+
-+static void au_init_fop_sp(struct file *file)
-+{
-+ struct au_sp_fop *p;
-+ int i;
-+ struct file *h_file;
-+
-+ p = au_sp_fop;
-+ if (unlikely(!p->done)) {
-+ /* initialize first time only */
-+ static DEFINE_SPINLOCK(spin);
-+
-+ spin_lock(&spin);
-+ if (!p->done) {
-+ BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
-+ != AuSp_Last);
-+ for (i = 0; i < AuSp_Last; i++)
-+ spin_lock_init(&p[i].spin);
-+ p->done = 1;
-+ }
-+ spin_unlock(&spin);
-+ }
-+
-+ switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
-+ case FMODE_READ:
-+ i = AuSp_FIFO_R;
-+ break;
-+ case FMODE_WRITE:
-+ i = AuSp_FIFO_W;
-+ break;
-+ case FMODE_READ | FMODE_WRITE:
-+ i = AuSp_FIFO_RW;
-+ break;
-+ default:
-+ BUG();
-+ }
-+
-+ p += i;
-+ if (unlikely(!p->done)) {
-+ /* initialize first time only */
-+ h_file = au_hf_top(file);
-+ spin_lock(&p->spin);
-+ if (!p->done) {
-+ p->fop = *h_file->f_op;
-+ p->fop.owner = THIS_MODULE;
-+ if (p->fop.aio_read)
-+ p->fop.aio_read = aufs_aio_read_sp;
-+ if (p->fop.aio_write)
-+ p->fop.aio_write = aufs_aio_write_sp;
-+ p->fop.release = aufs_release_sp;
-+ p->done = 1;
-+ }
-+ spin_unlock(&p->spin);
-+ }
-+ file->f_op = &p->fop;
-+}
-+
-+static int au_cpup_sp(struct dentry *dentry)
-+{
-+ int err;
-+ struct au_pin pin;
-+ struct au_wr_dir_args wr_dir_args = {
-+ .force_btgt = -1,
-+ .flags = 0
-+ };
-+ struct au_cp_generic cpg = {
-+ .dentry = dentry,
-+ .bdst = -1,
-+ .bsrc = -1,
-+ .len = -1,
-+ .pin = &pin,
-+ .flags = AuCpup_DTIME
-+ };
-+
-+ AuDbg("%pd\n", dentry);
-+
-+ di_read_unlock(dentry, AuLock_IR);
-+ di_write_lock_child(dentry);
-+ err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
-+ if (unlikely(err < 0))
-+ goto out;
-+ cpg.bdst = err;
-+ err = 0;
-+ if (cpg.bdst == au_dbstart(dentry))
-+ goto out; /* success */
-+
-+ err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
-+ AuPin_MNT_WRITE);
-+ if (!err) {
-+ err = au_sio_cpup_simple(&cpg);
-+ au_unpin(&pin);
-+ }
-+
-+out:
-+ di_downgrade_lock(dentry, AuLock_IR);
-+ return err;
-+}
-+
-+static int au_do_open_sp(struct file *file, int flags)
-+{
-+ int err;
-+ struct dentry *dentry;
-+ struct super_block *sb;
-+ struct file *h_file;
-+ struct inode *h_inode;
-+
-+ err = au_fi_sp_add(file);
-+ if (unlikely(err))
-+ goto out;
-+
-+ dentry = file->f_dentry;
-+ AuDbg("%pd\n", dentry);
-+
-+ /*
-+ * try copying-up.
-+ * operate on the ro branch is not an error.
-+ */
-+ au_cpup_sp(dentry); /* ignore */
-+
-+ /* prepare h_file */
-+ err = au_do_open_nondir(file, vfsub_file_flags(file));
-+ if (unlikely(err))
-+ goto out_del;
-+
-+ sb = dentry->d_sb;
-+ h_file = au_hf_top(file);
-+ h_inode = file_inode(h_file);
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_write_unlock(file);
-+ si_read_unlock(sb);
-+ /* open this fifo in aufs */
-+ err = h_inode->i_fop->open(file_inode(file), file);
-+ si_noflush_read_lock(sb);
-+ fi_write_lock(file);
-+ di_read_lock_child(dentry, AuLock_IR);
-+ if (!err) {
-+ au_init_fop_sp(file);
-+ goto out; /* success */
-+ }
-+
-+out_del:
-+ au_fi_sp_del(file);
-+out:
-+ return err;
-+}
-+
-+static int aufs_open_sp(struct inode *inode, struct file *file)
-+{
-+ int err;
-+ struct super_block *sb;
-+
-+ sb = file->f_dentry->d_sb;
-+ si_read_lock(sb, AuLock_FLUSH);
-+ err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
-+ si_read_unlock(sb);
-+ return err;
-+}
-+
-+/* ---------------------------------------------------------------------- */
-+
-+void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
-+{
-+ init_special_inode(inode, mode, rdev);
-+
-+ switch (mode & S_IFMT) {
-+ case S_IFIFO:
-+ inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
-+ /*FALLTHROUGH*/
-+ case S_IFCHR:
-+ case S_IFBLK:
-+ case S_IFSOCK:
-+ break;
-+ default:
-+ AuDebugOn(1);
-+ }
-+}
-+
-+int au_special_file(umode_t mode)
-+{
-+ int ret;
-+
-+ ret = 0;
-+ switch (mode & S_IFMT) {
-+ case S_IFIFO:
-+#if 0
-+ case S_IFCHR:
-+ case S_IFBLK:
-+ case S_IFSOCK:
-+#endif
-+ ret = 1;
-+ }
-+
-+ return ret;
-+}
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-01-20 20:16:14.739463504 +0100
++++ linux/fs/aufs/fstype.h 2014-01-30 21:10:02.850815069 +0100
@@ -0,0 +1,469 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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-01-20 20:16:14.739463504 +0100
-@@ -0,0 +1,295 @@
++++ linux/fs/aufs/hfsnotify.c 2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ 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);
+}
+}
+
+static int au_hfsn_handle_event(struct fsnotify_group *group,
++ struct inode *inode,
+ struct fsnotify_mark *inode_mark,
+ struct fsnotify_mark *vfsmount_mark,
-+ struct fsnotify_event *event)
++ u32 mask, void *data, int data_type,
++ const unsigned char *file_name, u32 cookie)
+{
+ int err;
+ struct au_hnotify *hnotify;
+ struct inode *h_dir, *h_inode;
-+ __u32 mask;
-+ struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
++ struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
+
-+ AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
++ AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
+
+ err = 0;
+ /* if FS_UNMOUNT happens, there must be another bug */
-+ mask = event->mask;
+ AuDebugOn(mask & FS_UNMOUNT);
+ if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
+ goto out;
+
-+ h_dir = event->to_tell;
-+ h_inode = event->inode;
++ h_dir = inode;
++ h_inode = NULL;
+#ifdef AuDbgHnotify
+ au_debug_on();
+ if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
+ return err;
+}
+
-+/* isn't it waste to ask every registered 'group'? */
-+/* copied from linux/fs/notify/inotify/inotify_fsnotiry.c */
-+/* it should be exported to modules */
-+static bool au_hfsn_should_send_event(struct fsnotify_group *group,
-+ struct inode *h_inode,
-+ struct fsnotify_mark *inode_mark,
-+ struct fsnotify_mark *vfsmount_mark,
-+ __u32 mask, void *data, int data_type)
-+{
-+ mask = (mask & ~FS_EVENT_ON_CHILD);
-+ return inode_mark->mask & mask;
-+}
-+
+static struct fsnotify_ops au_hfsn_ops = {
-+ .should_send_event = au_hfsn_should_send_event,
+ .handle_event = au_hfsn_handle_event,
+ .free_group_priv = au_hfsn_free_group
+};
+};
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-01-20 20:16:14.739463504 +0100
++++ linux/fs/aufs/hfsplus.c 2014-01-30 21:10:02.850815069 +0100
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010-2014 Junjiro R. Okajima
+}
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-01-27 23:16:52.711753818 +0100
-@@ -0,0 +1,710 @@
++++ linux/fs/aufs/hnotify.c 2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,714 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+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)
+ && a->inode
+ && a->h_inode) {
+ mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
-+ if (!a->h_inode->i_nlink)
++ if (!a->h_inode->i_nlink
++ && !(a->h_inode->i_state & I_LINKABLE))
+ hn_xino(a->inode, a->h_inode); /* ignore this error */
+ mutex_unlock(&a->h_inode->i_mutex);
+ }
+
+ /* make the generation obsolete */
+ if (au_ftest_hnjob(a->flags, GEN)) {
-+ int err = -1;
++ e = -1;
+ if (a->inode)
-+ err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
++ e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
+ isdir);
-+ if (err && a->dentry)
++ if (e && a->dentry)
+ hn_gen_by_name(a->dentry, isdir);
+ /* ignore this error */
+ }
+ au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
+ /*FALLTHROUGH*/
+ case FS_CREATE:
-+ AuDebugOn(!h_child_name || !h_child_inode);
++ AuDebugOn(!h_child_name);
+ break;
+
+ case FS_DELETE:
+ p[len] = 0;
+ }
+
++ /* NFS fires the event for silly-renamed one from kworker */
+ f = 0;
-+ if (!dir->i_nlink)
++ if (!dir->i_nlink
++ || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
+ f = AuWkq_NEST;
+ err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
+ if (unlikely(err)) {
+}
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-01-20 20:16:14.739463504 +0100
-@@ -0,0 +1,275 @@
++++ linux/fs/aufs/iinfo.c 2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,277 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ struct inode *h_i;
+
+ h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
-+ if (h_i && !h_i->i_nlink)
++ if (h_i
++ && !h_i->i_nlink
++ && !(h_i->i_state & I_LINKABLE))
+ au_set_h_iptr(inode, bindex, NULL, 0);
+ }
+ }
+}
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-01-20 20:16:14.739463504 +0100
-@@ -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
+ *
+ case S_IFSOCK:
+ btail = au_dbtail(dentry);
+ inode->i_op = &aufs_iop;
-+ au_init_special_fop(inode, mode, h_inode->i_rdev);
++ init_special_inode(inode, mode, h_inode->i_rdev);
+ break;
+ default:
+ AuIOErr("Unknown file type 0%o\n", mode);
+ struct inode *inode)
+{
+ int err;
++ struct inode *hi;
+
+ err = au_br_rdonly(au_sbr(sb, bindex));
+
+ * 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;
+ }
+}
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-01-20 20:16:14.739463504 +0100
-@@ -0,0 +1,599 @@
++++ linux/fs/aufs/inode.h 2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,601 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+#define AuWrDir_ADD_ENTRY 1
+#define AuWrDir_TMP_WHENTRY (1 << 1)
+#define AuWrDir_ISDIR (1 << 2)
++#define AuWrDir_TMPFILE (1 << 3)
+#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
+#define au_fset_wrdir(flags, name) \
+ do { (flags) |= AuWrDir_##name; } while (0)
+int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
+int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
+ bool want_excl);
++int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
+int aufs_link(struct dentry *src_dentry, struct inode *dir,
+ struct dentry *dentry);
+int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
+#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-01-20 20:16:14.739463504 +0100
-@@ -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
+ *
+ * plink-management and readdir in userspace.
+ * assist the pathconf(3) wrapper library.
+ * move-down
++ * File-based Hierarchical Storage Management.
+ */
+
+#include <linux/compat.h>
+ 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);
+ 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);
+ }
+#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-01-20 20:16:14.739463504 +0100
-@@ -0,0 +1,762 @@
++++ 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
+ *
+ 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))
+ 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 */
+ }
+
+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;
+
+ /* 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);
+ return add_simple(dir, dentry, &arg);
+}
+
++int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
++{
++ int err;
++ aufs_bindex_t bindex;
++ struct super_block *sb;
++ struct dentry *parent, *h_parent, *h_dentry;
++ struct inode *h_dir, *inode;
++ struct vfsmount *h_mnt;
++ struct au_wr_dir_args wr_dir_args = {
++ .force_btgt = -1,
++ .flags = AuWrDir_TMPFILE
++ };
++
++ /* copy-up may happen */
++ mutex_lock(&dir->i_mutex);
++
++ sb = dir->i_sb;
++ err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
++ if (unlikely(err))
++ goto out;
++
++ err = au_di_init(dentry);
++ if (unlikely(err))
++ goto out_si;
++
++ err = -EBUSY;
++ parent = d_find_any_alias(dir);
++ AuDebugOn(!parent);
++ di_write_lock_parent(parent);
++ if (unlikely(parent->d_inode != dir))
++ goto out_parent;
++
++ err = au_digen_test(parent, au_sigen(sb));
++ if (unlikely(err))
++ goto out_parent;
++
++ bindex = au_dbstart(parent);
++ au_set_dbstart(dentry, bindex);
++ au_set_dbend(dentry, bindex);
++ err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
++ bindex = err;
++ if (unlikely(err < 0))
++ goto out_parent;
++
++ err = -EOPNOTSUPP;
++ h_dir = au_h_iptr(dir, bindex);
++ if (unlikely(!h_dir->i_op->tmpfile))
++ goto out_parent;
++
++ h_mnt = au_sbr_mnt(sb, bindex);
++ err = vfsub_mnt_want_write(h_mnt);
++ if (unlikely(err))
++ goto out_parent;
++
++ h_parent = au_h_dptr(parent, bindex);
++ err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
++ if (unlikely(err))
++ goto out_mnt;
++
++ err = -ENOMEM;
++ h_dentry = d_alloc(h_parent, &dentry->d_name);
++ if (unlikely(!h_dentry))
++ goto out_mnt;
++
++ err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
++ if (unlikely(err))
++ goto out_dentry;
++
++ au_set_dbstart(dentry, bindex);
++ au_set_dbend(dentry, bindex);
++ au_set_h_dptr(dentry, bindex, dget(h_dentry));
++ inode = au_new_inode(dentry, /*must_new*/1);
++ if (IS_ERR(inode)) {
++ err = PTR_ERR(inode);
++ au_set_h_dptr(dentry, bindex, NULL);
++ au_set_dbstart(dentry, -1);
++ au_set_dbend(dentry, -1);
++ } else {
++ if (!inode->i_nlink)
++ set_nlink(inode, 1);
++ d_tmpfile(dentry, inode);
++ au_di(dentry)->di_tmpfile = 1;
++
++ /* update without i_mutex */
++ if (au_ibstart(dir) == au_dbstart(dentry))
++ au_cpup_attr_timesizes(dir);
++ }
++
++out_dentry:
++ dput(h_dentry);
++out_mnt:
++ vfsub_mnt_drop_write(h_mnt);
++out_parent:
++ di_write_unlock(parent);
++ dput(parent);
++ di_write_unlock(dentry);
++ if (!err)
++#if 0
++ /* verbose coding for lock class name */
++ au_rw_class(&au_di(dentry)->di_rwsem,
++ au_lc_key + AuLcNonDir_DIINFO);
++#else
++ ;
++#endif
++ else {
++ au_di_fin(dentry);
++ dentry->d_fsdata = NULL;
++ }
++out_si:
++ si_read_unlock(sb);
++out:
++ mutex_unlock(&dir->i_mutex);
++ return err;
++}
++
+/* ---------------------------------------------------------------------- */
+
+struct au_link_args {
+ AuLock_NOPLM | AuLock_GEN);
+ if (unlikely(err))
+ goto out_kfree;
-+ err = au_d_hashed_positive(src_dentry);
++ err = au_d_linkable(src_dentry);
+ if (unlikely(err))
+ goto out_unlock;
+ err = au_d_may_add(dentry);
+ a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
+ a->bsrc = au_ibstart(inode);
+ h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
++ if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
++ h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
+ if (!h_src_dentry) {
+ a->bsrc = au_dbstart(src_dentry);
+ h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
+ AuDebugOn(!h_src_dentry);
-+ } else if (IS_ERR(h_src_dentry))
++ } else if (IS_ERR(h_src_dentry)) {
++ err = PTR_ERR(h_src_dentry);
+ goto out_parent;
++ }
+
+ if (au_opt_test(au_mntflags(sb), PLINK)) {
+ if (a->bdst < a->bsrc
+ 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:
+}
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-01-27 23:16:52.715087263 +0100
-@@ -0,0 +1,1127 @@
++++ 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
+ *
+ 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
+ else
+ BUG();
+ }
-+ if (!err && add_entry) {
++ if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
+ h_parent = au_h_dptr(parent, bcpup);
+ h_dir = h_parent->d_inode;
+ mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
+ aufs_bindex_t bcpup, bstart, src_bstart;
+ const unsigned char add_entry
+ = au_ftest_wrdir(args->flags, ADD_ENTRY)
-+ | au_ftest_wrdir(args->flags, TMP_WHENTRY);
++ | au_ftest_wrdir(args->flags, TMP_WHENTRY)
++ | au_ftest_wrdir(args->flags, TMPFILE);
+ struct super_block *sb;
+ struct dentry *parent;
+ struct au_sbinfo *sbinfo;
+ au_set_dbstart(dentry, bcpup);
+ au_set_dbend(dentry, bcpup);
+ }
-+ AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
++ AuDebugOn(add_entry
++ && !au_ftest_wrdir(args->flags, TMPFILE)
++ && !au_h_dptr(dentry, bcpup));
+ }
+
+out:
+ if (!err)
+ goto out; /* success */
+
++ au_unpin(p);
++
+out_err:
+ pr_err("err %d\n", err);
+ err = au_busy_or_stale();
+ 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;
+
+ /* 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);
+ h_inode = au_h_iptr(inode, au_ibstart(inode));
+ err = vfsub_update_time(h_inode, ts, flags);
+ lockdep_off();
++ if (!err)
++ au_cpup_attr_timesizes(inode);
+ ii_write_unlock(inode);
+ si_read_unlock(sb);
+ lockdep_on();
++
++ if (!err && (flags & S_VERSION))
++ inode_inc_iversion(inode);
++
+ return err;
+}
+
+ .setattr = aufs_setattr,
+ .getattr = aufs_getattr,
+
-+ .update_time = aufs_update_time
++ .update_time = aufs_update_time,
+ /* no support for atomic_open() */
++
++ .tmpfile = aufs_tmpfile
+};
+
+struct inode_operations aufs_iop = {
+};
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-01-20 20:16:14.739463504 +0100
-@@ -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
+ *
+ * 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;
+}
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-01-20 20:16:14.739463504 +0100
-@@ -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
+ *
+ au_hn_imtx_unlock(a->src_hinode);
+ if (IS_ERR(diropq))
+ err = PTR_ERR(diropq);
-+ dput(diropq);
++ else
++ dput(diropq);
+
+ return err;
+}
+ 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;
+
+}
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-01-20 20:16:14.732796615 +0100
-@@ -0,0 +1,179 @@
++++ 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
+ /* 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
+ shows better performance in most cases.
+ See detail in aufs.5.
+
-+config AUFS_SP_IATTR
-+ bool "Respect the attributes (mtime/ctime mainly) of special files"
-+ help
-+ When you write something to a special file, some attributes of it
-+ (mtime/ctime mainly) may be updated. Generally such updates are
-+ less important (actually some device drivers and NFS ignore
-+ it). But some applications (such like test program) requires
-+ such updates. If you need these updates, then enable this
-+ configuration which introduces some overhead.
-+ Currently this configuration handles FIFO only.
-+
+config AUFS_SHWH
+ bool "Show whiteouts"
+ help
+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-01-20 20:16:14.739463504 +0100
++++ linux/fs/aufs/loop.c 2014-01-30 21:10:02.850815069 +0100
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+}
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-01-20 20:16:14.739463504 +0100
++++ linux/fs/aufs/loop.h 2014-01-30 21:10:02.850815069 +0100
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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 2013-07-06 13:20:47.750198454 +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
+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-01-20 20:16:14.732796615 +0100
++++ linux/fs/aufs/Makefile 2014-08-14 10:15:45.118609182 +0200
@@ -0,0 +1,42 @@
+
+include ${src}/magic.mk
+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_SP_IATTR) += f_op_sp.o
+aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
+aufs-$(CONFIG_AUFS_DEBUG) += debug.o
+aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
--- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/module.c 2014-01-20 20:16:14.739463504 +0100
-@@ -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
+ *
+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 */
+ 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 */
+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-01-20 20:16:14.742796949 +0100
++++ linux/fs/aufs/module.h 2014-01-30 21:10:02.850815069 +0100
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#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-01-20 20:16:14.742796949 +0100
-@@ -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
+ *
+};
+
+#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
+ 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)
+{
+ 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
+ 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);
+
+/* ---------------------------------------------------------------------- */
+
-+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)
+{
+ 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))
+}
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-01-27 23:16:52.715087263 +0100
-@@ -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
+ *
+ 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
+};
+
+ {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"},
+ {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
+#endif
+ {Opt_noshwh, "noshwh"},
+
++ {Opt_dirperm1, "dirperm1"},
++ {Opt_nodirperm1, "nodirperm1"},
++
+ {Opt_rendir, "rendir=%d"},
+
+ {Opt_refrof, "refrof"},
+
+/* ---------------------------------------------------------------------- */
+
-+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 = {
+};
+
+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;
+ 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);
+ 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)
+ 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));
+}
+
+/* ---------------------------------------------------------------------- */
+
+const char *au_optstr_udba(int udba)
+{
-+ return au_parser_pattern(udba, (void *)udbalevel);
++ return au_parser_pattern(udba, udbalevel);
+}
+
+/* ---------------------------------------------------------------------- */
+
+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 = {
+
+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);
+}
+
+/* ---------------------------------------------------------------------- */
+ case Opt_noshwh:
+ AuLabel(noshwh);
+ break;
++ case Opt_dirperm1:
++ AuLabel(dirperm1);
++ break;
++ case Opt_nodirperm1:
++ AuLabel(nodirperm1);
++ break;
+ case Opt_plink:
+ AuLabel(plink);
+ break;
+ 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();
+ }
+ 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:
+ 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*/
+ 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;
+ 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;
+int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
+ unsigned int pending)
+{
-+ int err;
++ int err, fhsm;
+ aufs_bindex_t bindex, bend;
+ unsigned char do_plink, skip, do_free;
+ struct au_branch *br;
+ && !au_opt_test(sbinfo->si_mntflags, XINO))
+ pr_warn("udba=*notify requires xino\n");
+
++ if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
++ pr_warn("dirperm1 breaks the protection"
++ " by the permission bits on the lower branch\n");
++
+ err = 0;
++ fhsm = 0;
+ root = sb->s_root;
+ dir = root->d_inode;
+ do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
+ if (wbr)
+ wbr_wh_read_unlock(wbr);
+
++ if (au_br_fhsm(br->br_perm)) {
++ fhsm++;
++ AuDebugOn(!br->br_fhsm);
++ }
++
+ if (skip)
+ continue;
+
+ }
+ }
+
++ if (fhsm >= 2)
++ au_fset_si(sbinfo, FHSM);
++ else
++ au_fclr_si(sbinfo, FHSM);
++
+ return err;
+}
+
+ struct au_opt_xino *opt_xino, xino;
+ struct au_sbinfo *sbinfo;
+ struct au_branch *br;
++ struct inode *dir;
+
+ SiMustWriteLock(sb);
+
+ /* go on even if err */
+ }
+ if (au_opt_test(tmp, UDBA_HNOTIFY)) {
-+ struct inode *dir = sb->s_root->d_inode;
++ dir = sb->s_root->d_inode;
+ au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
+ }
+
+}
diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
--- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/opts.h 2014-01-20 20:16:14.742796949 +0100
-@@ -0,0 +1,210 @@
++++ linux/fs/aufs/opts.h 2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+#ifdef __KERNEL__
+
+#include <linux/path.h>
++#include "branch.h"
+
+struct file;
+struct super_block;
+#define AuOpt_UDBA_HNOTIFY (1 << 4)
+#define AuOpt_SHWH (1 << 5) /* show whiteout */
+#define AuOpt_PLINK (1 << 6) /* pseudo-link */
-+#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
++#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
++ bits */
+#define AuOpt_REFROF (1 << 8) /* unimplemented */
+#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
+#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
+ int udba;
+ struct au_opt_wbr_create wbr_create;
+ int wbr_copyup;
++ unsigned int fhsm_second;
+ };
+};
+
+
+/* ---------------------------------------------------------------------- */
+
-+char *au_optstr_br_perm(int brperm);
++void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
+const char *au_optstr_udba(int udba);
+const char *au_optstr_wbr_copyup(int wbr_copyup);
+const char *au_optstr_wbr_create(int wbr_create);
+#endif /* __AUFS_OPTS_H__ */
diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
--- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/plink.c 2014-01-20 20:16:14.742796949 +0100
++++ linux/fs/aufs/plink.c 2014-01-30 21:10:02.857481956 +0100
@@ -0,0 +1,532 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+}
diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
--- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/poll.c 2014-01-20 20:16:14.742796949 +0100
++++ linux/fs/aufs/poll.c 2014-01-30 21:10:02.857481956 +0100
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+}
diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
--- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/procfs.c 2014-01-20 20:16:14.742796949 +0100
++++ linux/fs/aufs/procfs.c 2014-01-30 21:10:02.857481956 +0100
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2010-2014 Junjiro R. Okajima
+}
diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
--- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/rdu.c 2014-01-20 20:16:14.742796949 +0100
++++ linux/fs/aufs/rdu.c 2014-01-30 21:10:02.857481956 +0100
@@ -0,0 +1,388 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#endif
diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
--- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/rwsem.h 2014-01-20 20:16:14.742796949 +0100
-@@ -0,0 +1,187 @@
++++ linux/fs/aufs/rwsem.h 2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+/* why is not _nested version defined */
+static inline int au_rw_read_trylock(struct au_rwsem *rw)
+{
-+ int ret = down_read_trylock(&rw->rwsem);
++ int ret;
++
++ ret = down_read_trylock(&rw->rwsem);
+ if (ret)
+ AuDbgRcntInc(rw);
+ return ret;
+
+static inline int au_rw_write_trylock(struct au_rwsem *rw)
+{
-+ int ret = down_write_trylock(&rw->rwsem);
++ int ret;
++
++ ret = down_write_trylock(&rw->rwsem);
+ if (ret)
+ AuDbgWcntInc(rw);
+ return ret;
+#endif /* __AUFS_RWSEM_H__ */
diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
--- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sbinfo.c 2014-01-20 20:16:14.742796949 +0100
-@@ -0,0 +1,351 @@
++++ linux/fs/aufs/sbinfo.c 2014-08-14 10:15:45.128609525 +0200
+@@ -0,0 +1,353 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
+ sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
+
++ au_fhsm_init(sbinfo);
++
+ sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
+
+ sbinfo->si_xino_jiffy = jiffies;
+}
diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
--- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/spl.h 2014-01-20 20:16:14.742796949 +0100
++++ linux/fs/aufs/spl.h 2014-01-30 21:10:02.857481956 +0100
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#endif /* __AUFS_SPL_H__ */
diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
--- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/super.c 2014-01-20 20:16:14.742796949 +0100
-@@ -0,0 +1,1001 @@
++++ linux/fs/aufs/super.c 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,1004 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ struct path path;
+ struct au_hdentry *hdp;
+ struct au_branch *br;
-+ char *perm;
++ au_br_perm_str_t perm;
+
+ err = 0;
+ bend = au_sbend(sb);
+ path.dentry = hdp[bindex].hd_dentry;
+ err = au_seq_path(seq, &path);
+ if (err > 0) {
-+ perm = au_optstr_br_perm(br->br_perm);
-+ if (perm) {
-+ err = seq_printf(seq, "=%s", perm);
-+ kfree(perm);
-+ if (err == -1)
-+ err = -E2BIG;
-+ } else
-+ err = -ENOMEM;
++ au_optstr_br_perm(&perm, br->br_perm);
++ err = seq_printf(seq, "=%s", perm.a);
++ if (err == -1)
++ err = -E2BIG;
+ }
+ if (!err && bindex != bend)
+ err = seq_putc(seq, ':');
+ AuBool(SHWH, shwh);
+ AuBool(PLINK, plink);
+ AuBool(DIO, dio);
-+ /* AuBool(DIRPERM1, dirperm1); */
++ AuBool(DIRPERM1, dirperm1);
+ /* AuBool(REFROF, refrof); */
+
+ v = sbinfo->si_wbr_create;
+ AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
+ AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
+
++ au_fhsm_show(m, sbinfo);
++
+ AuBool(SUM, sum);
+ /* AuBool(SUM_W, wsum); */
+ AuBool(WARN_PERM, warn_perm);
+void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
+{
+ void *array;
-+ unsigned long long n;
++ unsigned long long n, sz;
+
+ array = NULL;
+ n = 0;
+ goto out;
+ }
+
-+ array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
++ sz = sizeof(array) * *hint;
++ array = kzalloc(sz, GFP_NOFS);
+ if (unlikely(!array))
-+ array = vmalloc(sizeof(array) * *hint);
++ array = vzalloc(sz);
+ if (unlikely(!array)) {
+ array = ERR_PTR(-ENOMEM);
+ goto out;
+ sigen = au_sigen(sb);
+ for (ull = 0; ull < max; ull++) {
+ inode = array[ull];
++ if (unlikely(!inode))
++ break;
+ if (au_iigen(inode, NULL) != sigen) {
+ ii_write_lock_child(inode);
+ e = au_refresh_hinode_self(inode);
+ au_dy_arefresh(do_dx);
+ }
+
++ au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
+ aufs_write_unlock(root);
+
+out_mtx:
+ if (sbinfo) {
+ au_sbilist_del(sb);
+ aufs_write_lock(sb->s_root);
++ au_fhsm_fin(sb);
+ if (sbinfo->si_wbr_create_ops->fin)
+ sbinfo->si_wbr_create_ops->fin(sb);
+ if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
+ aufs_write_unlock(sb->s_root);
+ au_nwt_flush(&sbinfo->si_nowait);
+ }
-+ generic_shutdown_super(sb);
++ kill_anon_super(sb);
+}
+
+struct file_system_type aufs_fs_type = {
+};
diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
--- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/super.h 2014-01-20 20:16:14.742796949 +0100
-@@ -0,0 +1,571 @@
++++ linux/fs/aufs/super.h 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,642 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ return ino % AuPlink_NHASH;
+}
+
++/* File-based Hierarchical Storage Management */
++struct au_fhsm {
++#ifdef CONFIG_AUFS_FHSM
++ /* allow only one process who can receive the notification */
++ spinlock_t fhsm_spin;
++ pid_t fhsm_pid;
++ wait_queue_head_t fhsm_wqh;
++ atomic_t fhsm_readable;
++
++ /* only this is protected by si_rwsem */
++ unsigned long fhsm_expire;
++#endif
++};
++
+struct au_branch;
+struct au_sbinfo {
+ /* nowait tasks in the system-wide workqueue */
+ /* most free space */
+ struct au_wbr_mfs si_wbr_mfs;
+
++ /* File-based Hierarchical Storage Management */
++ struct au_fhsm si_fhsm;
++
+ /* mount flags */
+ /* include/asm-ia64/siginfo.h defines a macro named si_flags */
+ unsigned int si_mntflags;
+ * if it is false, refreshing dirs at access time is unnecesary
+ */
+#define AuSi_FAILED_REFRESH_DIR 1
++
++#define AuSi_FHSM (1 << 1) /* fhsm is active now */
++
++#ifndef CONFIG_AUFS_FHSM
++#undef AuSi_FHSM
++#define AuSi_FHSM 0
++#endif
++
+static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
+ unsigned int flag)
+{
+extern struct au_wbr_create_operations au_wbr_create_ops[];
+int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
+int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
++int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
+
+/* mvdown.c */
+int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
+
++#ifdef CONFIG_AUFS_FHSM
++/* fhsm.c */
++
++static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
++{
++ pid_t pid;
++
++ spin_lock(&fhsm->fhsm_spin);
++ pid = fhsm->fhsm_pid;
++ spin_unlock(&fhsm->fhsm_spin);
++
++ return pid;
++}
++
++void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
++void au_fhsm_wrote_all(struct super_block *sb, int force);
++int au_fhsm_fd(struct super_block *sb, int oflags);
++int au_fhsm_br_alloc(struct au_branch *br);
++void au_fhsm_fin(struct super_block *sb);
++void au_fhsm_init(struct au_sbinfo *sbinfo);
++void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
++void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
++#else
++AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
++ int force)
++AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
++AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
++AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm);
++AuStubInt0(au_fhsm_br_alloc, struct au_branch *br);
++AuStubVoid(au_fhsm_fin, struct super_block *sb)
++AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
++AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
++AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
++#endif
++
+/* ---------------------------------------------------------------------- */
+
+static inline struct au_sbinfo *au_sbi(struct super_block *sb)
+
+static inline int si_pid_test(struct super_block *sb)
+{
-+ pid_t bit = si_pid_bit();
++ pid_t bit;
++
++ bit = si_pid_bit();
+ if (bit < PID_MAX_DEFAULT)
+ return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
+ else
+
+static inline void si_pid_set(struct super_block *sb)
+{
-+ pid_t bit = si_pid_bit();
++ pid_t bit;
++
++ bit = si_pid_bit();
+ if (bit < PID_MAX_DEFAULT) {
+ AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
+ set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
+
+static inline void si_pid_clr(struct super_block *sb)
+{
-+ pid_t bit = si_pid_bit();
++ pid_t bit;
++
++ bit = si_pid_bit();
+ if (bit < PID_MAX_DEFAULT) {
+ AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
+ clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
+
+static inline int si_noflush_read_trylock(struct super_block *sb)
+{
-+ int locked = __si_read_trylock(sb);
++ int locked;
++
++ locked = __si_read_trylock(sb);
+ if (locked)
+ si_pid_set(sb);
+ return locked;
+
+static inline int si_noflush_write_trylock(struct super_block *sb)
+{
-+ int locked = __si_write_trylock(sb);
++ int locked;
++
++ locked = __si_write_trylock(sb);
+ if (locked)
+ si_pid_set(sb);
+ return locked;
+#endif /* __AUFS_SUPER_H__ */
diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
--- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysaufs.c 2014-01-20 20:16:14.749463838 +0100
++++ linux/fs/aufs/sysaufs.c 2014-01-30 21:10:02.857481956 +0100
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+}
diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
--- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysaufs.h 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,103 @@
++++ linux/fs/aufs/sysaufs.h 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
+ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
+ char *buf);
++long au_brinfo_ioctl(struct file *file, unsigned long arg);
++#ifdef CONFIG_COMPAT
++long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
++#endif
+
+void sysaufs_br_init(struct au_branch *br);
+void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
+#endif /* __SYSAUFS_H__ */
diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
--- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysfs.c 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,296 @@
++++ linux/fs/aufs/sysfs.c 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,372 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ * sysfs interface
+ */
+
++#include <linux/compat.h>
+#include <linux/seq_file.h>
+#include "aufs.h"
+
+ struct path path;
+ struct dentry *root;
+ struct au_branch *br;
-+ char *perm;
++ au_br_perm_str_t perm;
+
+ AuDbg("b%d\n", bindex);
+
+ path.mnt = au_br_mnt(br);
+ path.dentry = au_h_dptr(root, bindex);
+ au_seq_path(seq, &path);
-+ di_read_unlock(root, !AuLock_IR);
-+ perm = au_optstr_br_perm(br->br_perm);
-+ if (perm) {
-+ err = seq_printf(seq, "=%s\n", perm);
-+ kfree(perm);
-+ if (err == -1)
-+ err = -E2BIG;
-+ } else
-+ err = -ENOMEM;
++ au_optstr_br_perm(&perm, br->br_perm);
++ err = seq_printf(seq, "=%s\n", perm.a);
+ break;
+ case AuBrSysfs_BRID:
+ err = seq_printf(seq, "%d\n", br->br_id);
-+ di_read_unlock(root, !AuLock_IR);
-+ if (err == -1)
-+ err = -E2BIG;
+ break;
+ }
++ di_read_unlock(root, !AuLock_IR);
++ if (err == -1)
++ err = -E2BIG;
+
+ return err;
+}
+
+/* ---------------------------------------------------------------------- */
+
++static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
++{
++ int err;
++ int16_t brid;
++ aufs_bindex_t bindex, bend;
++ size_t sz;
++ char *buf;
++ struct seq_file *seq;
++ struct au_branch *br;
++
++ si_read_lock(sb, AuLock_FLUSH);
++ bend = au_sbend(sb);
++ err = bend + 1;
++ if (!arg)
++ goto out;
++
++ err = -ENOMEM;
++ buf = (void *)__get_free_page(GFP_NOFS);
++ if (unlikely(!buf))
++ goto out;
++
++ seq = au_seq(buf, PAGE_SIZE);
++ err = PTR_ERR(seq);
++ if (IS_ERR(seq))
++ goto out_buf;
++
++ sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
++ for (bindex = 0; bindex <= bend; bindex++, arg++) {
++ err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
++ if (unlikely(err))
++ break;
++
++ br = au_sbr(sb, bindex);
++ brid = br->br_id;
++ BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
++ err = __put_user(brid, &arg->id);
++ if (unlikely(err))
++ break;
++
++ BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
++ err = __put_user(br->br_perm, &arg->perm);
++ if (unlikely(err))
++ break;
++
++ au_seq_path(seq, &br->br_path);
++ err = seq_putc(seq, '\0');
++ if (!err && seq->count <= sz) {
++ err = copy_to_user(arg->path, seq->buf, seq->count);
++ seq->count = 0;
++ if (unlikely(err))
++ break;
++ } else {
++ err = -E2BIG;
++ goto out_seq;
++ }
++ }
++ if (unlikely(err))
++ err = -EFAULT;
++
++out_seq:
++ kfree(seq);
++out_buf:
++ free_page((unsigned long)buf);
++out:
++ si_read_unlock(sb);
++ return err;
++}
++
++long au_brinfo_ioctl(struct file *file, unsigned long arg)
++{
++ return au_brinfo(file->f_dentry->d_sb, (void __user *)arg);
++}
++
++#ifdef CONFIG_COMPAT
++long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
++{
++ return au_brinfo(file->f_dentry->d_sb, compat_ptr(arg));
++}
++#endif
++
++/* ---------------------------------------------------------------------- */
++
+void sysaufs_br_init(struct au_branch *br)
+{
+ int i;
+}
diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
--- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysrq.c 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,154 @@
++++ linux/fs/aufs/sysrq.c 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+#if 1
+ {
+ struct inode *i;
++
+ pr("isolated inode\n");
+ spin_lock(&inode_sb_list_lock);
+ list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
+ spin_lock(&files->spin);
+ hlist_for_each_entry(finfo, &files->head, fi_hlist) {
+ umode_t mode;
++
+ file = finfo->fi_file;
+ mode = file_inode(file)->i_mode;
-+ if (!special_file(mode) || au_special_file(mode))
++ if (!special_file(mode))
+ au_dpri_file(file);
+ }
+ spin_unlock(&files->spin);
+void au_sysrq_fin(void)
+{
+ int err;
++
+ err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
+ if (unlikely(err))
+ pr_err("err %d (ignored)\n", err);
+}
diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
--- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/vdir.c 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,887 @@
++++ linux/fs/aufs/vdir.c 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,889 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+{
+ struct hlist_head *head;
+ unsigned int u;
++ size_t sz;
+
-+ head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
++ sz = sizeof(*nhash->nh_head) * num_hash;
++ head = kmalloc(sz, gfp);
+ if (head) {
+ nhash->nh_num = num_hash;
+ nhash->nh_head = head;
+}
diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
--- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/vfsub.c 2014-01-20 20:16:14.749463838 +0100
++++ linux/fs/aufs/vfsub.c 2014-08-14 10:16:04.515942371 +0200
@@ -0,0 +1,782 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ d = path->dentry;
+ path->dentry = d->d_parent;
+ tmp.dentry = src_dentry->d_parent;
-+ err = security_path_rename(&tmp, src_dentry, path, d);
++ err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
+ path->dentry = d;
+ if (unlikely(err))
+ goto out;
+
+ lockdep_off();
+ err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
-+ delegated_inode);
++ delegated_inode, /*flags*/0);
+ lockdep_on();
+ if (!err) {
+ int did;
+}
diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
--- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/vfsub.h 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,282 @@
++++ linux/fs/aufs/vfsub.h 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,284 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
+{
+ int err;
++
+ lockdep_off();
+ err = mnt_want_write(mnt);
+ lockdep_on();
+static inline long vfsub_truncate(struct path *path, loff_t length)
+{
+ long err;
++
+ lockdep_off();
+ err = vfs_truncate(path, length);
+ lockdep_on();
+#endif /* __AUFS_VFSUB_H__ */
diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
--- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wbr_policy.c 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,756 @@
++++ linux/fs/aufs/wbr_policy.c 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,765 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ au_set_ibend(inode, bdst);
+ au_set_h_iptr(inode, bdst, au_igrab(h_inode),
+ au_hi_flags(inode, /*isdir*/1));
++ au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
+ goto out; /* success */
+
+ /* revert */
+}
+
+/* bottom up */
-+static int au_wbr_copyup_bu(struct dentry *dentry)
++int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
+{
+ int err;
-+ aufs_bindex_t bstart;
+
-+ bstart = au_dbstart(dentry);
+ err = au_wbr_bu(dentry->d_sb, bstart);
+ AuDbg("b%d\n", err);
+ if (err > bstart)
+ return err;
+}
+
++static int au_wbr_copyup_bu(struct dentry *dentry)
++{
++ int err;
++ aufs_bindex_t bstart;
++
++ bstart = au_dbstart(dentry);
++ err = au_wbr_do_copyup_bu(dentry, bstart);
++ return err;
++}
++
+/* ---------------------------------------------------------------------- */
+
+struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
+};
diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
--- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/whout.c 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,1052 @@
++++ linux/fs/aufs/whout.c 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,1056 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ * test if the @wh_name exists under @h_parent.
+ * @try_sio specifies the necessary of super-io.
+ */
-+int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
-+ struct au_branch *br, int try_sio)
++int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
+{
+ int err;
+ struct dentry *wh_dentry;
+ if (!try_sio)
+ wh_dentry = vfsub_lkup_one(wh_name, h_parent);
+ else
-+ wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
++ wh_dentry = au_sio_lkup_one(wh_name, h_parent);
+ err = PTR_ERR(wh_dentry);
+ if (IS_ERR(wh_dentry))
+ goto out;
+/*
+ * test if the @h_dentry sets opaque or not.
+ */
-+int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
++int au_diropq_test(struct dentry *h_dentry)
+{
+ int err;
+ struct inode *h_dir;
+
+ h_dir = h_dentry->d_inode;
-+ err = au_wh_test(h_dentry, &diropq_name, br,
++ err = au_wh_test(h_dentry, &diropq_name,
+ au_test_h_perm_sio(h_dir, MAY_EXEC));
+ return err;
+}
+ qs.name = name;
+ for (i = 0; i < 3; i++) {
+ sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
-+ dentry = au_sio_lkup_one(&qs, h_parent, br);
++ dentry = au_sio_lkup_one(&qs, h_parent);
+ if (IS_ERR(dentry) || !dentry->d_inode)
+ goto out_name;
+ dput(dentry);
+ wbr_wh_write_unlock(wbr);
+ au_hn_imtx_unlock(hdir);
+ di_read_unlock(a->sb->s_root, AuLock_IR);
++ if (!err)
++ au_fhsm_wrote(a->sb, bindex, /*force*/0);
+
+out:
+ if (wbr)
+
+ /* return this error in this context */
+ err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
++ if (!err)
++ au_fhsm_wrote(sb, bindex, /*force*/0);
+
+out:
+ wbr_wh_read_unlock(wbr);
+ wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
+ if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
+ err = link_or_create_wh(sb, bindex, wh_dentry);
-+ if (!err)
++ if (!err) {
+ au_set_dbwh(dentry, bindex);
-+ else {
++ au_fhsm_wrote(sb, bindex, /*force*/0);
++ } else {
+ dput(wh_dentry);
+ wh_dentry = ERR_PTR(err);
+ }
+}
diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
--- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/whout.h 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,86 @@
++++ linux/fs/aufs/whout.h 2014-08-14 10:15:45.131942973 +0200
+@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+/* whout.c */
+int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
+struct au_branch;
-+int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
-+ struct au_branch *br, int try_sio);
-+int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
++int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
++int au_diropq_test(struct dentry *h_dentry);
+struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
+ struct qstr *prefix);
+int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
+#endif /* __AUFS_WHOUT_H__ */
diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
--- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wkq.c 2014-01-20 20:16:14.749463838 +0100
-@@ -0,0 +1,212 @@
++++ linux/fs/aufs/wkq.c 2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+{
+ if (au_ftest_wkq(wkinfo->flags, NEST)) {
+ if (au_wkq_test()) {
-+ AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
++ AuWarn1("wkq from wkq, unless silly-rename on NFS,"
++ " due to a dead dir by UDBA?\n");
+ AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
+ }
+ } else
+}
diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
--- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wkq.h 2014-01-20 20:16:14.752797282 +0100
++++ linux/fs/aufs/wkq.h 2014-01-30 21:10:02.860815399 +0100
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+#endif /* __AUFS_WKQ_H__ */
diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
--- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/xino.c 2014-01-20 20:16:14.752797282 +0100
-@@ -0,0 +1,1314 @@
++++ linux/fs/aufs/xino.c 2014-08-14 10:16:04.515942371 +0200
+@@ -0,0 +1,1316 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+ return fop->read;
+ if (fop->aio_read)
+ return do_sync_read;
++ if (fop->read_iter)
++ return new_sync_read;
+ return ERR_PTR(-ENOSYS);
+}
+
+ return fop->write;
+ if (fop->aio_write)
+ return do_sync_write;
++ if (fop->write_iter)
++ return new_sync_write;
+ return ERR_PTR(-ENOSYS);
+}
+
+ cur_parent = dget_parent(cur_xino->f_dentry);
+ cur_name = &cur_xino->f_dentry->d_name;
+ skip = (cur_parent == parent
-+ && dname->len == cur_name->len
-+ && !memcmp(dname->name, cur_name->name,
-+ dname->len));
++ && au_qstreq(dname, cur_name));
+ dput(cur_parent);
+ }
+ if (skip)
+}
diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
--- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/include/uapi/linux/aufs_type.h 2014-01-27 23:17:06.205534916 +0100
-@@ -0,0 +1,281 @@
++++ linux/include/uapi/linux/aufs_type.h 2014-08-14 10:16:04.522609267 +0200
+@@ -0,0 +1,380 @@
+/*
+ * Copyright (C) 2005-2014 Junjiro R. Okajima
+ *
+
+#include <linux/limits.h>
+
-+#define AUFS_VERSION "3.13-20140127"
++#define AUFS_VERSION "3.16-20140811"
+
+/* todo? move this to linux-2.6.19/include/magic.h */
+#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
+#define AUFS_WKQ_NAME AUFS_NAME "d"
+#define AUFS_MFS_DEF_SEC 30 /* seconds */
+#define AUFS_MFS_MAX_SEC 3600 /* seconds */
++#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
+#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
+
+/* pseudo-link maintenace under /proc */
+#define AUFS_BRPERM_RW "rw"
+#define AUFS_BRPERM_RO "ro"
+#define AUFS_BRPERM_RR "rr"
++#define AUFS_BRATTR_COO_REG "coo_reg"
++#define AUFS_BRATTR_COO_ALL "coo_all"
++#define AUFS_BRATTR_FHSM "fhsm"
++#define AUFS_BRATTR_UNPIN "unpin"
+#define AUFS_BRRATTR_WH "wh"
+#define AUFS_BRWATTR_NLWH "nolwh"
-+#define AUFS_BRATTR_UNPIN "unpin"
++#define AUFS_BRWATTR_MOO "moo"
++
++#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
++#define AuBrPerm_RO (1 << 1) /* readonly */
++#define AuBrPerm_RR (1 << 2) /* natively readonly */
++#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
++
++#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
++#define AuBrAttr_COO_ALL (1 << 4)
++#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
++
++#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
++#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
++ branch */
++
++#define AuBrRAttr_WH (1 << 7) /* whiteout-able */
++#define AuBrRAttr_Mask AuBrRAttr_WH
++
++#define AuBrWAttr_NoLinkWH (1 << 8) /* un-hardlinkable whiteouts */
++#define AuBrWAttr_MOO (1 << 9) /* move-up on open */
++#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
++
++#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
++
++#ifdef __KERNEL__
++#ifndef CONFIG_AUFS_FHSM
++#undef AuBrAttr_FHSM
++#define AuBrAttr_FHSM 0
++#endif
++#endif
++
++/* the longest combination */
++#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
++ "+" AUFS_BRATTR_COO_REG \
++ "+" AUFS_BRATTR_FHSM \
++ "+" AUFS_BRATTR_UNPIN \
++ "+" AUFS_BRWATTR_NLWH)
++
++typedef struct {
++ char a[AuBrPermStrSz];
++} au_br_perm_str_t;
++
++static inline int au_br_writable(int brperm)
++{
++ return brperm & AuBrPerm_RW;
++}
++
++static inline int au_br_whable(int brperm)
++{
++ return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
++}
++
++static inline int au_br_wh_linkable(int brperm)
++{
++ return !(brperm & AuBrWAttr_NoLinkWH);
++}
++
++static inline int au_br_cmoo(int brperm)
++{
++ return brperm & AuBrAttr_CMOO_Mask;
++}
++
++static inline int au_br_fhsm(int brperm)
++{
++ return brperm & AuBrAttr_FHSM;
++}
+
+/* ---------------------------------------------------------------------- */
+
+ AuCtl_RDU,
+ AuCtl_RDU_INO,
+
-+ /* pathconf wrapper */
-+ AuCtl_WBR_FD,
-+
-+ /* busy inode */
-+ AuCtl_IBUSY,
-+
-+ /* move-down */
-+ AuCtl_MVDOWN
++ AuCtl_WBR_FD, /* pathconf wrapper */
++ AuCtl_IBUSY, /* busy inode */
++ AuCtl_MVDOWN, /* move-down */
++ AuCtl_BR, /* info about branches */
++ AuCtl_FHSM_FD /* connection for fhsm */
+};
+
+/* borrowed from linux/include/linux/kernel.h */
+#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
+#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
+#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
-+/* will be added more */
++#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
++#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
++#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
++#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
+
++/* index for move-down */
+enum {
+ AUFS_MVDOWN_UPPER,
+ AUFS_MVDOWN_LOWER,
+ AUFS_MVDOWN_NARRAY
+};
+
++/*
++ * additional info of move-down
++ * number of free blocks and inodes.
++ * subset of struct kstatfs, but smaller and always 64bit.
++ */
++struct aufs_stfs {
++ uint64_t f_blocks;
++ uint64_t f_bavail;
++ uint64_t f_files;
++ uint64_t f_ffree;
++};
++
++struct aufs_stbr {
++ int16_t brid; /* optional input */
++ int16_t bindex; /* output */
++ struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
++} __aligned(8);
++
+struct aufs_mvdown {
-+ uint32_t flags;
++ uint32_t flags; /* input/output */
++ struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
++ int8_t au_errno; /* output */
++} __aligned(8);
++
++/* ---------------------------------------------------------------------- */
++
++union aufs_brinfo {
++ /* PATH_MAX may differ between kernel-space and user-space */
++ char _spacer[4096];
+ struct {
-+ int16_t bindex;
-+ int16_t brid;
-+ } a[AUFS_MVDOWN_NARRAY];
-+ int8_t au_errno;
-+ /* will be added more */
++ int16_t id;
++ int perm;
++ char path[0];
++ };
+} __aligned(8);
+
+/* ---------------------------------------------------------------------- */
+#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
+#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
+ struct aufs_mvdown)
++#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
++#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
+
+#endif /* __AUFS_TYPE_H__ */
+aufs3.16 loopback patch
+
+diff --git a/drivers/block/loop.c b/drivers/block/loop.c
+index 30efd68..77b31b4 100644
+--- a/drivers/block/loop.c
++++ b/drivers/block/loop.c
+@@ -514,7 +514,7 @@ out:
+ }
+
+ struct switch_request {
+- struct file *file;
++ struct file *file, *virt_file;
+ struct completion wait;
+ };
+
+@@ -576,7 +576,8 @@ static int loop_thread(void *data)
+ * First it needs to flush existing IO, it does this by sending a magic
+ * BIO down the pipe. The completion of this BIO does the actual switch.
+ */
+-static int loop_switch(struct loop_device *lo, struct file *file)
++static int loop_switch(struct loop_device *lo, struct file *file,
++ struct file *virt_file)
+ {
+ struct switch_request w;
+ struct bio *bio = bio_alloc(GFP_KERNEL, 0);
+@@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
+ return -ENOMEM;
+ init_completion(&w.wait);
+ w.file = file;
++ w.virt_file = virt_file;
+ bio->bi_private = &w;
+ bio->bi_bdev = NULL;
+ loop_make_request(lo->lo_queue, bio);
+@@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
+ if (!lo->lo_thread)
+ return 0;
+
+- return loop_switch(lo, NULL);
++ return loop_switch(lo, NULL, NULL);
+ }
+
+ /*
+@@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
+ mapping = file->f_mapping;
+ mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
+ lo->lo_backing_file = file;
++ lo->lo_backing_virt_file = p->virt_file;
+ lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
+ mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
+ lo->old_gfp_mask = mapping_gfp_mask(mapping);
+@@ -627,6 +630,13 @@ out:
+ complete(&p->wait);
+ }
+
++static struct file *loop_real_file(struct file *file)
++{
++ struct file *f = NULL;
++ if (file->f_dentry->d_sb->s_op->real_loop)
++ f = file->f_dentry->d_sb->s_op->real_loop(file);
++ return f;
++}
+
+ /*
+ * loop_change_fd switched the backing store of a loopback device to
+@@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
+ unsigned int arg)
+ {
+ struct file *file, *old_file;
++ struct file *f, *virt_file = NULL, *old_virt_file;
+ struct inode *inode;
+ int error;
+
+@@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
+ file = fget(arg);
+ if (!file)
+ goto out;
++ f = loop_real_file(file);
++ if (f) {
++ virt_file = file;
++ file = f;
++ get_file(file);
++ }
+
+ inode = file->f_mapping->host;
+ old_file = lo->lo_backing_file;
++ old_virt_file = lo->lo_backing_virt_file;
+
+ error = -EINVAL;
+
+@@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
+ goto out_putf;
+
+ /* and ... switch */
+- error = loop_switch(lo, file);
++ error = loop_switch(lo, file, virt_file);
+ if (error)
+ goto out_putf;
+
+ fput(old_file);
++ if (old_virt_file)
++ fput(old_virt_file);
+ if (lo->lo_flags & LO_FLAGS_PARTSCAN)
+ ioctl_by_bdev(bdev, BLKRRPART, 0);
+ return 0;
+
+ out_putf:
+ fput(file);
++ if (virt_file)
++ fput(virt_file);
+ out:
+ return error;
+ }
+@@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
+ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
+ struct block_device *bdev, unsigned int arg)
+ {
+- struct file *file, *f;
++ struct file *file, *f, *virt_file = NULL;
+ struct inode *inode;
+ struct address_space *mapping;
+ unsigned lo_blocksize;
+@@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
+ file = fget(arg);
+ if (!file)
+ goto out;
++ f = loop_real_file(file);
++ if (f) {
++ virt_file = file;
++ file = f;
++ get_file(file);
++ }
+
+ error = -EBUSY;
+ if (lo->lo_state != Lo_unbound)
+@@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
+ lo->lo_device = bdev;
+ lo->lo_flags = lo_flags;
+ lo->lo_backing_file = file;
++ lo->lo_backing_virt_file = virt_file;
+ lo->transfer = transfer_none;
+ lo->ioctl = NULL;
+ lo->lo_sizelimit = 0;
+@@ -948,6 +977,7 @@ out_clr:
+ lo->lo_thread = NULL;
+ lo->lo_device = NULL;
+ lo->lo_backing_file = NULL;
++ lo->lo_backing_virt_file = NULL;
+ lo->lo_flags = 0;
+ set_capacity(lo->lo_disk, 0);
+ invalidate_bdev(bdev);
+@@ -957,6 +987,8 @@ out_clr:
+ lo->lo_state = Lo_unbound;
+ out_putf:
+ fput(file);
++ if (virt_file)
++ fput(virt_file);
+ out:
+ /* This is safe: open() is still holding a reference. */
+ module_put(THIS_MODULE);
+@@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
+ static int loop_clr_fd(struct loop_device *lo)
+ {
+ struct file *filp = lo->lo_backing_file;
++ struct file *virt_filp = lo->lo_backing_virt_file;
+ gfp_t gfp = lo->old_gfp_mask;
+ struct block_device *bdev = lo->lo_device;
+
+@@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
+
+ spin_lock_irq(&lo->lo_lock);
+ lo->lo_backing_file = NULL;
++ lo->lo_backing_virt_file = NULL;
+ spin_unlock_irq(&lo->lo_lock);
+
+ loop_release_xfer(lo);
+@@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
+ * bd_mutex which is usually taken before lo_ctl_mutex.
+ */
+ fput(filp);
++ if (virt_filp)
++ fput(virt_filp);
+ return 0;
+ }
+
+diff --git a/drivers/block/loop.h b/drivers/block/loop.h
+index 90df5d6..cb91822 100644
+--- a/drivers/block/loop.h
++++ b/drivers/block/loop.h
+@@ -44,7 +44,7 @@ struct loop_device {
+ int (*ioctl)(struct loop_device *, int cmd,
+ unsigned long arg);
+
+- struct file * lo_backing_file;
++ struct file * lo_backing_file, *lo_backing_virt_file;
+ struct block_device *lo_device;
+ unsigned lo_blocksize;
+ void *key_data;
+diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
+index 24ced51..69fa5cc 100644
+--- a/fs/aufs/f_op.c
++++ b/fs/aufs/f_op.c
+@@ -367,7 +367,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
+ err = -EINVAL;
+ h_file = au_hf_top(file);
+ get_file(h_file);
+- if (au_test_loopback_kthread()) {
++ if (0 && au_test_loopback_kthread()) {
+ au_warn_loopback(h_file->f_dentry->d_sb);
+ if (file->f_mapping != h_file->f_mapping) {
+ file->f_mapping = h_file->f_mapping;
+diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
+index 3b03b52..4ab749d 100644
+--- a/fs/aufs/loop.c
++++ b/fs/aufs/loop.c
+@@ -130,3 +130,19 @@ void au_loopback_fin(void)
+ symbol_put(loop_backing_file);
+ kfree(au_warn_loopback_array);
+ }
++
++/* ---------------------------------------------------------------------- */
++
++/* support the loopback block device insude aufs */
++
++struct file *aufs_real_loop(struct file *file)
++{
++ struct file *f;
++
++ BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
++ fi_read_lock(file);
++ f = au_hf_top(file);
++ fi_read_unlock(file);
++ AuDebugOn(!f);
++ return f;
++}
+diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
+index da8b756..28cb7ea 100644
+--- a/fs/aufs/loop.h
++++ b/fs/aufs/loop.h
+@@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
+
+ int au_loopback_init(void);
+ void au_loopback_fin(void);
++
++struct file *aufs_real_loop(struct file *file);
+ #else
++AuStub(struct file *, loop_backing_file, return NULL)
++
+ AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
+ struct dentry *h_adding)
+ AuStubInt0(au_test_loopback_kthread, void)
+@@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
+
+ AuStubInt0(au_loopback_init, void)
+ AuStubVoid(au_loopback_fin, void)
++
++AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
+ #endif /* BLK_DEV_LOOP */
+
+ #endif /* __KERNEL__ */
+diff --git a/fs/aufs/super.c b/fs/aufs/super.c
+index 45146eb..fccd7d6 100644
+--- a/fs/aufs/super.c
++++ b/fs/aufs/super.c
+@@ -809,7 +809,10 @@ static const struct super_operations aufs_sop = {
+ .statfs = aufs_statfs,
+ .put_super = aufs_put_super,
+ .sync_fs = aufs_sync_fs,
+- .remount_fs = aufs_remount_fs
++ .remount_fs = aufs_remount_fs,
++#ifdef CONFIG_AUFS_BDEV_LOOP
++ .real_loop = aufs_real_loop
++#endif
+ };
+
+ /* ---------------------------------------------------------------------- */
+diff --git a/include/linux/fs.h b/include/linux/fs.h
+index 2f32b35..f94f0e6 100644
+--- a/include/linux/fs.h
++++ b/include/linux/fs.h
+@@ -1561,6 +1561,10 @@ struct super_operations {
+ int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
+ long (*nr_cached_objects)(struct super_block *, int);
+ long (*free_cached_objects)(struct super_block *, long, int);
++#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
++ /* and aufs */
++ struct file *(*real_loop)(struct file *);
++#endif
+ };
+
+ /*