-aufs3.x-rcN kbuild patch
+aufs3.13 kbuild patch
diff --git a/fs/Kconfig b/fs/Kconfig
-index 9fe0b34..c4311f8 100644
+index c229f82..397b473 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
-@@ -215,6 +215,7 @@ source "fs/pstore/Kconfig"
- source "fs/sysv/Kconfig"
- source "fs/ufs/Kconfig"
+@@ -212,6 +212,7 @@ source "fs/ufs/Kconfig"
source "fs/exofs/Kconfig"
+ source "fs/f2fs/Kconfig"
+ source "fs/efivarfs/Kconfig"
+source "fs/aufs/Kconfig"
endif # MISC_FILESYSTEMS
diff --git a/fs/Makefile b/fs/Makefile
-index afc1096..5c5ac76 100644
+index 4fe6df3..4a57676 100644
--- a/fs/Makefile
+++ b/fs/Makefile
-@@ -123,3 +123,4 @@ obj-$(CONFIG_GFS2_FS) += gfs2/
- obj-$(CONFIG_EXOFS_FS) += exofs/
+@@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
obj-$(CONFIG_CEPH_FS) += ceph/
obj-$(CONFIG_PSTORE) += pstore/
+ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
+obj-$(CONFIG_AUFS_FS) += aufs/
-diff --git a/include/linux/Kbuild b/include/linux/Kbuild
-index 619b565..29f386b 100644
---- a/include/linux/Kbuild
-+++ b/include/linux/Kbuild
-@@ -65,6 +65,7 @@ header-y += atmppp.h
+diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
+index 33d2b8f..b55eeb9 100644
+--- a/include/uapi/linux/Kbuild
++++ b/include/uapi/linux/Kbuild
+@@ -56,6 +56,7 @@ header-y += atmppp.h
header-y += atmsap.h
header-y += atmsvc.h
header-y += audit.h
header-y += auto_fs.h
header-y += auto_fs4.h
header-y += auxvec.h
-aufs3.x-rcN base patch
+aufs3.13 base patch
-diff --git a/fs/namei.c b/fs/namei.c
-index 0b3138d..8edad02 100644
---- a/fs/namei.c
-+++ b/fs/namei.c
-@@ -1748,7 +1748,7 @@ static struct dentry *__lookup_hash(struct qstr *name,
- * needs parent already locked. Doesn't follow mounts.
- * SMP-safe.
+diff --git a/drivers/block/loop.c b/drivers/block/loop.c
+index c8dac73..2e229ac 100644
+--- a/drivers/block/loop.c
++++ b/drivers/block/loop.c
+@@ -691,6 +691,24 @@ static inline int is_loop_device(struct file *file)
+ return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
+ }
+
++/*
++ * for AUFS
++ * no get/put for file.
++ */
++struct file *loop_backing_file(struct super_block *sb)
++{
++ struct file *ret;
++ struct loop_device *l;
++
++ ret = NULL;
++ if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
++ l = sb->s_bdev->bd_disk->private_data;
++ ret = l->lo_backing_file;
++ }
++ return ret;
++}
++EXPORT_SYMBOL(loop_backing_file);
++
+ /* loop sysfs attributes */
+
+ static ssize_t loop_attr_show(struct device *dev, char *page,
+diff --git a/fs/inode.c b/fs/inode.c
+index 4bcdad3..bc83168 100644
+--- a/fs/inode.c
++++ b/fs/inode.c
+@@ -1497,7 +1497,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.
*/
--static struct dentry *lookup_hash(struct nameidata *nd)
-+struct dentry *lookup_hash(struct nameidata *nd)
+-static int update_time(struct inode *inode, struct timespec *time, int flags)
++int update_time(struct inode *inode, struct timespec *time, int flags)
{
- return __lookup_hash(&nd->last, nd->path.dentry, nd);
- }
+ 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 fa2defa..e3569b0 100644
+index 46a08f7..719ca3e 100644
--- a/fs/splice.c
+++ b/fs/splice.c
-@@ -1085,8 +1085,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
+@@ -1093,8 +1093,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);
-@@ -1113,9 +1113,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
+@@ -1110,9 +1110,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/namei.h b/include/linux/namei.h
-index 409328d..40afdc0 100644
---- a/include/linux/namei.h
-+++ b/include/linux/namei.h
-@@ -84,6 +84,7 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
- extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
- int (*open)(struct inode *, struct file *));
+diff --git a/include/linux/fs.h b/include/linux/fs.h
+index 121f11f..39bf86d 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 *);
+ extern int inode_newsize_ok(const struct inode *, loff_t offset);
+ extern void setattr_copy(struct inode *inode, const struct iattr *attr);
-+extern struct dentry *lookup_hash(struct nameidata *nd);
- extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
++extern int update_time(struct inode *, struct timespec *, int);
+ extern int file_update_time(struct file *file);
- extern int follow_down_one(struct path *);
+ 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 26e5b61..3ffef2f 100644
+index 74575cb..bfc6fb6 100644
--- a/include/linux/splice.h
+++ b/include/linux/splice.h
-@@ -91,4 +91,10 @@ extern void splice_shrink_spd(struct pipe_inode_info *,
+@@ -92,4 +92,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.x-rcN standalone patch
+aufs3.13 standalone patch
-diff --git a/fs/file_table.c b/fs/file_table.c
-index c322794..2aad244 100644
---- a/fs/file_table.c
-+++ b/fs/file_table.c
-@@ -443,6 +443,8 @@ void file_sb_list_del(struct file *file)
- }
- }
-
-+EXPORT_SYMBOL(file_sb_list_del);
-+
- #ifdef CONFIG_SMP
-
- /*
diff --git a/fs/inode.c b/fs/inode.c
-index ec79246..46ac6f9 100644
+index bc83168..6dd1207 100644
--- a/fs/inode.c
+++ b/fs/inode.c
-@@ -65,6 +65,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
+@@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
__cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
/*
* Empty aops. Can be used for the cases where the user does not
-diff --git a/fs/namei.c b/fs/namei.c
-index 8edad02..50e8718 100644
---- a/fs/namei.c
-+++ b/fs/namei.c
-@@ -1752,6 +1752,7 @@ struct dentry *lookup_hash(struct nameidata *nd)
- {
- return __lookup_hash(&nd->last, nd->path.dentry, nd);
+@@ -1513,6 +1514,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
+ mark_inode_dirty_sync(inode);
+ return 0;
}
-+EXPORT_SYMBOL(lookup_hash);
++EXPORT_SYMBOL(update_time);
/**
- * lookup_one_len - filesystem helper to lookup single pathname component
+ * touch_atime - update the access time
diff --git a/fs/namespace.c b/fs/namespace.c
-index b4febb2..598a308 100644
+index be32ebc..d3f6f59 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
-@@ -1508,6 +1508,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
+@@ -425,6 +425,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
+ mnt_dec_writers(real_mount(mnt));
+ preempt_enable();
+ }
++EXPORT_SYMBOL_GPL(__mnt_drop_write);
+
+ /**
+ * mnt_drop_write - give up write access to a mount
+@@ -1509,6 +1510,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
}
return 0;
}
+EXPORT_SYMBOL(iterate_mounts);
- static void cleanup_group_ids(struct vfsmount *mnt, struct vfsmount *end)
+ static void cleanup_group_ids(struct mount *mnt, struct mount *end)
{
diff --git a/fs/notify/group.c b/fs/notify/group.c
-index 63fc294..6f4adca 100644
+index bd2625b..2ff2a0f 100644
--- a/fs/notify/group.c
+++ b/fs/notify/group.c
@@ -22,6 +22,7 @@
#include <linux/fsnotify_backend.h>
#include "fsnotify.h"
-@@ -70,6 +71,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
+@@ -65,6 +66,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
+ {
+ atomic_inc(&group->refcnt);
+ }
++EXPORT_SYMBOL(fsnotify_get_group);
+
+ /*
+ * Drop a reference to a group. Free it if it's through.
+@@ -74,6 +76,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
if (atomic_dec_and_test(&group->refcnt))
- fsnotify_destroy_group(group);
+ fsnotify_final_destroy_group(group);
}
+EXPORT_SYMBOL(fsnotify_put_group);
/*
* Create a new fsnotify_group and hold a reference for the group returned.
-@@ -102,3 +104,4 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
+@@ -102,6 +105,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
return group;
}
+EXPORT_SYMBOL(fsnotify_alloc_group);
+
+ int fsnotify_fasync(int fd, struct file *file, int on)
+ {
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
-index e14587d..be6533b 100644
+index 923fe4a..176b435 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
-@@ -112,6 +112,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
- if (atomic_dec_and_test(&mark->refcnt))
+@@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
mark->free_mark(mark);
+ }
}
+EXPORT_SYMBOL(fsnotify_put_mark);
/*
* Any time a mark is getting freed we end up here.
-@@ -189,6 +190,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
- if (unlikely(atomic_dec_and_test(&group->num_marks)))
- fsnotify_final_destroy_group(group);
+@@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
+ fsnotify_destroy_mark_locked(mark, group);
+ mutex_unlock(&group->mark_mutex);
}
+EXPORT_SYMBOL(fsnotify_destroy_mark);
void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
{
-@@ -276,6 +278,7 @@ err:
+@@ -275,6 +277,7 @@ err:
return ret;
}
+EXPORT_SYMBOL(fsnotify_add_mark);
- /*
- * clear any marks in a group in which mark->flags & flags is true
-@@ -331,6 +334,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
+ int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
+ struct inode *inode, struct vfsmount *mnt, int allow_dups)
+@@ -336,6 +339,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
atomic_set(&mark->refcnt, 1);
mark->free_mark = free_mark;
}
static int fsnotify_mark_destroy(void *ignored)
{
diff --git a/fs/open.c b/fs/open.c
-index f711921..d742fc0 100644
+index 4b3e1ed..ce49f2b 100644
--- a/fs/open.c
+++ b/fs/open.c
-@@ -60,6 +60,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
+@@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
mutex_unlock(&dentry->d_inode->i_mutex);
return ret;
}
+EXPORT_SYMBOL(do_truncate);
- static long do_sys_truncate(const char __user *pathname, loff_t length)
+ long vfs_truncate(struct path *path, loff_t length)
{
diff --git a/fs/splice.c b/fs/splice.c
-index e3569b0..9dc07b7 100644
+index 719ca3e..6300dc8 100644
--- a/fs/splice.c
+++ b/fs/splice.c
-@@ -1109,6 +1109,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
+@@ -1106,6 +1106,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.
-@@ -1135,6 +1136,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
+@@ -1132,6 +1133,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
return splice_read(in, ppos, pipe, len, flags);
}
/**
* splice_direct_to_actor - splices data directly between two non-pipes
diff --git a/security/commoncap.c b/security/commoncap.c
-index a93b3b7..024282c 100644
+index b9d613e..ba3b618 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
-@@ -971,3 +971,4 @@ int cap_file_mmap(struct file *file, unsigned long reqprot,
+@@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
}
return ret;
}
-+EXPORT_SYMBOL(cap_file_mmap);
++EXPORT_SYMBOL(cap_mmap_addr);
+
+ int cap_mmap_file(struct file *file, unsigned long reqprot,
+ unsigned long prot, unsigned long flags)
+ {
+ return 0;
+ }
++EXPORT_SYMBOL(cap_mmap_file);
diff --git a/security/device_cgroup.c b/security/device_cgroup.c
-index 4450fbe..2c437e5 100644
+index 7c2a0a7..a37c054 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
-@@ -500,6 +500,7 @@ found:
-
- return -EPERM;
+@@ -7,6 +7,7 @@
+ #include <linux/device_cgroup.h>
+ #include <linux/cgroup.h>
+ #include <linux/ctype.h>
++#include <linux/export.h>
+ #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)
+ return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
+ access);
}
+EXPORT_SYMBOL(__devcgroup_inode_permission);
int devcgroup_inode_mknod(int mode, dev_t dev)
{
diff --git a/security/security.c b/security/security.c
-index d9e1533..466ee5c 100644
+index 15b6928..ae6eba6 100644
--- a/security/security.c
+++ b/security/security.c
-@@ -373,6 +373,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
+@@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
return 0;
return security_ops->path_rmdir(dir, dentry);
}
int security_path_unlink(struct path *dir, struct dentry *dentry)
{
-@@ -389,6 +390,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
+@@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
return 0;
return security_ops->path_symlink(dir, dentry, old_name);
}
int security_path_link(struct dentry *old_dentry, struct path *new_dir,
struct dentry *new_dentry)
-@@ -397,6 +399,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
+@@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
return 0;
return security_ops->path_link(old_dentry, new_dir, new_dentry);
}
int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
struct path *new_dir, struct dentry *new_dentry)
-@@ -415,6 +418,7 @@ int security_path_truncate(struct path *path)
+@@ -449,6 +452,7 @@ int security_path_truncate(struct path *path)
return 0;
return security_ops->path_truncate(path);
}
+EXPORT_SYMBOL(security_path_truncate);
- int security_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
- mode_t mode)
-@@ -423,6 +427,7 @@ int security_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
+ int security_path_chmod(struct path *path, umode_t mode)
+ {
+@@ -456,6 +460,7 @@ int security_path_chmod(struct path *path, umode_t mode)
return 0;
- return security_ops->path_chmod(dentry, mnt, mode);
+ return security_ops->path_chmod(path, mode);
}
+EXPORT_SYMBOL(security_path_chmod);
- int security_path_chown(struct path *path, uid_t uid, gid_t gid)
+ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
{
-@@ -430,6 +435,7 @@ int security_path_chown(struct path *path, uid_t uid, gid_t gid)
+@@ -463,6 +468,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)
{
-@@ -506,6 +512,7 @@ int security_inode_readlink(struct dentry *dentry)
+@@ -539,6 +545,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)
{
-@@ -520,6 +527,7 @@ int security_inode_permission(struct inode *inode, int mask)
+@@ -553,6 +560,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)
{
-@@ -619,6 +627,7 @@ int security_file_permission(struct file *file, int mask)
+@@ -675,6 +683,7 @@ int security_file_permission(struct file *file, int mask)
return fsnotify_perm(file, mask);
}
int security_file_alloc(struct file *file)
{
-@@ -646,6 +655,7 @@ int security_file_mmap(struct file *file, unsigned long reqprot,
+@@ -735,6 +744,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
return ret;
return ima_file_mmap(file, prot);
}
-+EXPORT_SYMBOL(security_file_mmap);
++EXPORT_SYMBOL(security_mmap_file);
- int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
- unsigned long prot)
+ int security_mmap_addr(unsigned long addr)
+ {
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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,37 @@
++++ linux/Documentation/ABI/testing/debugfs-aufs 2014-01-30 21:10:02.794146538 +0100
+@@ -0,0 +1,50 @@
+What: /debug/aufs/si_<id>/
+Date: March 2009
-+Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact: J. R. Okajima <hooanon05g@gmail.com>
+Description:
+ Under /debug/aufs, a directory named si_<id> is created
+ per aufs mount, where <id> is a unique id generated
+ internally.
+
++What: /debug/aufs/si_<id>/plink
++Date: Apr 2013
++Contact: J. R. Okajima <hooanon05g@gmail.com>
++Description:
++ It has three lines and shows the information about the
++ pseudo-link. The first line is a single number
++ representing a number of buckets. The second line is a
++ number of pseudo-links per buckets (separated by a
++ blank). The last line is a single number representing a
++ total number of psedo-links.
++ When the aufs mount option 'noplink' is specified, it
++ will show "1\n0\n0\n".
++
+What: /debug/aufs/si_<id>/xib
+Date: March 2009
-+Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact: J. R. Okajima <hooanon05g@gmail.com>
+Description:
+ It shows the consumed blocks by xib (External Inode Number
+ Bitmap), its block size and file size.
+
+What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
+Date: March 2009
-+Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact: J. R. Okajima <hooanon05g@gmail.com>
+Description:
+ It shows the consumed blocks by xino (External Inode Number
+ Translation Table), its link count, block size and file
+
+What: /debug/aufs/si_<id>/xigen
+Date: March 2009
-+Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact: J. R. Okajima <hooanon05g@gmail.com>
+Description:
+ It shows the consumed blocks by xigen (External Inode
+ Generation Table), its block size and file size.
+ 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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,24 @@
++++ linux/Documentation/ABI/testing/sysfs-aufs 2014-01-30 21:10:02.794146538 +0100
+@@ -0,0 +1,31 @@
+What: /sys/fs/aufs/si_<id>/
+Date: March 2009
-+Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact: J. R. Okajima <hooanon05g@gmail.com>
+Description:
+ Under /sys/fs/aufs, a directory named si_<id> is created
+ per aufs mount, where <id> is a unique id generated
+
+What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
+Date: March 2009
-+Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact: J. R. Okajima <hooanon05g@gmail.com>
+Description:
+ It shows the abolute path of a member directory (which
+ is called branch) in aufs, and its permission.
+
++What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
++Date: July 2013
++Contact: J. R. Okajima <hooanon05g@gmail.com>
++Description:
++ It shows the id of a member directory (which is called
++ branch) in aufs.
++
+What: /sys/fs/aufs/si_<id>/xi_path
+Date: March 2009
-+Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
++Contact: J. R. Okajima <hooanon05g@gmail.com>
+Description:
+ It shows the abolute path of XINO (External Inode Number
+ Bitmap, Translation Table and Generation Table) file
+ 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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,162 @@
++++ linux/Documentation/filesystems/aufs/design/01intro.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,161 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Introduction
+----------------------------------------
+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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,226 @@
++++ linux/Documentation/filesystems/aufs/design/02struct.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,242 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Basic Aufs Internal Structure
+
+internally and makes change to the new file on the upper writable branch.
+When the trigger systemcall does not update the timestamps of the parent
+dir, aufs reverts it after copy-up.
++
++
++Move-down (aufs3.9 and later)
++----------------------------------------------------------------------
++"Copy-up" is one of the essential feature in aufs. It copies a file from
++the lower readonly branch to the upper writable branch when a user
++changes something about the file.
++"Move-down" is an opposite action of copy-up. Basically this action is
++ran manually instead of automatically and internally.
++
++Sometimes users want to move-down a file from the upper writable branch
++to the lower readonly or writable branch. For instance,
++- the free space of the upper writable branch is going to run out.
++- create a new intermediate branch between the upper and lower branch.
++- etc.
++
++For this purpose, use "aumvdown" command in aufs-util.git.
diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,106 @@
++++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,105 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Lookup in a Branch
+----------------------------------------------------------------------
+ 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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,76 @@
++++ linux/Documentation/filesystems/aufs/design/04branch.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,75 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Branch Manipulation
+
+ 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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,65 @@
++++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,64 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Policies to Select One among Multiple Writable Branches
+----------------------------------------------------------------------
+ copyup policy.
diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
--- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
-+++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,47 @@
++++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,46 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+mmap(2) -- File Memory Mapping
+----------------------------------------------------------------------
+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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,59 @@
++++ linux/Documentation/filesystems/aufs/design/07export.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,58 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Export Aufs via NFS
+----------------------------------------------------------------------
+ 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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,53 @@
++++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,52 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Show Whiteout Mode (shwh)
+----------------------------------------------------------------------
+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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,47 @@
++++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,46 @@
+
-+# Copyright (C) 2010-2011 Junjiro R. Okajima
++# Copyright (C) 2010-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Dynamically customizable FS operations
+----------------------------------------------------------------------
+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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,96 @@
++++ linux/Documentation/filesystems/aufs/design/99plan.txt 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,95 @@
+
-+# Copyright (C) 2005-2011 Junjiro R. Okajima
++# Copyright (C) 2005-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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Plan
+
+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 2011-10-24 20:51:51.580466925 +0200
-@@ -0,0 +1,313 @@
++++ linux/Documentation/filesystems/aufs/README 2014-01-30 21:10:02.807480310 +0100
+@@ -0,0 +1,344 @@
+
+Aufs3 -- advanced multi layered unification filesystem version 3.x
+http://aufs.sf.net
+The aufs3-linux tree includes the whole linux mainline GIT tree,
+git://git.kernel.org/.../torvalds/linux.git.
+And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
-+build aufs3 as an externel kernel module.
++build aufs3 as an external kernel module.
+
+On the other hand, the aufs3-standalone tree has only aufs source files
+and necessary patches, and you can select CONFIG_AUFS_FS=m.
+
+o aufs3-linux tree
+$ git clone --reference /your/linux/git/tree \
-+ git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-linux.git \
++ git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
+ aufs3-linux.git
+- if you don't have linux GIT tree, then remove "--reference ..."
+$ cd aufs3-linux.git
+$ git checkout origin/aufs3.0
+
+o aufs3-standalone tree
-+$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git \
++$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
+ aufs3-standalone.git
+$ cd aufs3-standalone.git
+$ git checkout origin/aufs3.0
+
+o aufs-util tree
-+$ git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git \
++$ git clone git://git.code.sf.net/p/aufs/aufs-util \
+ aufs-util.git
+$ cd aufs-util.git
+$ git checkout origin/aufs3.0
+
-+You may not be able to find the GIT branch in aufs-util for your
-+version. In this case, you should git-checkout the branch for the
++Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
++The minor version number, 'x' in '3.x', of aufs may not always
++follow the minor version number of the kernel.
++Because changes in the kernel that cause the use of a new
++minor version number do not always require changes to aufs-util.
++
++Since aufs-util has its own minor version number, you may not be
++able to find a GIT branch in aufs-util for your kernel's
++exact minor version number.
++In this case, you should git-checkout the branch for the
+nearest lower number.
-+If you are using linux-3.10 and aufs3.10 (which are not released yet),
-+but the "aufs3.10" branch doesn't exit in this repository, then
-+"aufs3.9", "aufs3.8", ... or something is the branch for you.
++
++For (an unreleased) example:
++If you are using "linux-3.10" and the "aufs3.10" branch
++does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
++or something numerically smaller is the branch for your kernel.
++
+Also you can view all branches by
+ $ git branch -a
+
+Make sure you have git-checkout'ed the correct branch.
+
+For aufs3-linux tree,
-+- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS.
++- enable CONFIG_AUFS_FS.
+- set other aufs configurations if necessary.
+
+For aufs3-standalone tree,
+1.
+- apply ./aufs3-kbuild.patch to your kernel source files.
+- apply ./aufs3-base.patch too.
-+- apply ./aufs3-proc_map.patch too, if you want to make /proc/PID/maps (and
-+ others including lsof(1)) show the file path on aufs instead of the
-+ path on the branch fs.
++- apply ./aufs3-mmap.patch too.
+- apply ./aufs3-standalone.patch too, if you have a plan to set
+ CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
-+- copy ./{Documentation,fs,include/linux/aufs_type.h} files to your
-+ kernel source tree. Never copy ./include/linux/Kbuild.
-+- enable CONFIG_EXPERIMENTAL and CONFIG_AUFS_FS, you can select either
++- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
++ kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
++- enable CONFIG_AUFS_FS, you can select either
+ =m or =y.
+- and build your kernel as usual.
+- install the built kernel.
-+- install the header files too by "make headers_install".
++ Note: Since linux-3.9, every filesystem module requires an alias
++ "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
++ modules.aliases file if you set CONFIG_AUFS_FS=m.
++- install the header files too by "make headers_install" to the
++ directory where you specify. By default, it is $PWD/usr.
++ "make help" shows a brief note for headers_install.
+- and reboot your system.
+
+2.
+- module only (CONFIG_AUFS_FS=m).
+- apply ./aufs3-base.patch to your kernel source files.
-+- apply ./aufs3-proc_map.patch too to your kernel source files,
-+ if you want to make /proc/PID/maps (and others including lsof(1)) show
-+ the file path on aufs instead of the path on the branch fs.
++- apply ./aufs3-mmap.patch too.
+- apply ./aufs3-standalone.patch too.
+- build your kernel, don't forget "make headers_install", and reboot.
+- edit ./config.mk and set other aufs configurations if necessary.
-+ Note: You should read ./fs/aufs/Kconfig carefully which describes
++ Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
+ every aufs configurations.
+- build the module by simple "make".
++ Note: Since linux-3.9, every filesystem module requires an alias
++ "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
++ modules.aliases file.
+- you can specify ${KDIR} make variable which points to your kernel
+ source tree.
+- install the files
+ + run "make install" to install the aufs module, or copy the built
-+ ./aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
-+ + run "make headers_install" to install the aufs header file (you can
-+ specify DESTDIR), or copty ./usr/include/linux/aufs_type.h to
-+ /usr/include/linux or wherever you like.
++ $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
++ + run "make install_headers" (instead of headers_install) to install
++ the modified aufs header file (you can specify DESTDIR which is
++ available in aufs standalone version's Makefile only), or copy
++ $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
++ you like manually. By default, the target directory is $PWD/usr.
+- no need to apply aufs3-kbuild.patch, nor copying source files to your
+ kernel source tree.
+
-+Note: The haeder file aufs_type.h is necessary to build aufs-util
++Note: The header file aufs_type.h is necessary to build aufs-util
+ as well as "make headers_install" in the kernel source tree.
+ headers_install is subject to be forgotten, but it is essentially
+ necessary, not only for building aufs-util.
+
+And then,
+- read README in aufs-util, build and install it
++- note that your distribution may contain an obsoleted version of
++ aufs_type.h in /usr/include/linux or something. When you build aufs
++ utilities, make sure that your compiler refers the correct aufs header
++ file which is built by "make headers_install."
+- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
+ then run "make install_ulib" too. And refer to the aufs manual in
+ detail.
+ Since Apr 2010, Tomas M (the author of Slax and Linux Live
+ scripts) is making "doubling" donations.
+ Unfortunately I cannot list all of the donators, but I really
-+ appriciate.
++ appreciate.
+ It ends Aug 2010, but the ordinary donation URL is still available.
+ <http://sourceforge.net/donate/index.php?group_id=167503>
+Dai Itasaka made a donation (2007/8).
+Pavel Pronskiy made a donation (2011/2).
+Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
+ Networks (Ed Wildgoose) made a donation for hardware (2011/3).
-+Max Lekomcev (DOM-TV project) made a donation (2011/7).
++Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
++11).
+Sam Liddicott made a donation (2011/9).
++Era Scarecrow made a donation (2013/4).
++Bor Ratajc made a donation (2013/4).
++Alessandro Gorreta made a donation (2013/4).
++POIRETTE Marc made a donation (2013/4).
++Alessandro Gorreta made a donation (2013/4).
++lauri kasvandik made a donation (2013/5).
++"pemasu from Finland" made a donation (2013/7).
++The Parted Magic Project made a donation (2013/9 and 11).
++Pavel Barta made a donation (2013/10).
+
+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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,60 @@
++++ linux/fs/aufs/aufs.h 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,59 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,1170 @@
++++ linux/fs/aufs/branch.c 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,1219 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ */
+
+#include <linux/compat.h>
-+#include <linux/file.h>
+#include <linux/statfs.h>
+#include "aufs.h"
+
+/*
+ * free a single branch
+ */
++
++/* prohibit rmdir to the root of the branch */
++/* todo: another new flag? */
++static void au_br_dflags_force(struct au_branch *br)
++{
++ struct dentry *h_dentry;
++
++ h_dentry = au_br_dentry(br);
++ spin_lock(&h_dentry->d_lock);
++ br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
++ h_dentry->d_flags |= DCACHE_MOUNTED;
++ spin_unlock(&h_dentry->d_lock);
++}
++
++/* restore its d_flags */
++static void au_br_dflags_restore(struct au_branch *br)
++{
++ struct dentry *h_dentry;
++
++ if (br->br_dflags)
++ return;
++
++ h_dentry = au_br_dentry(br);
++ spin_lock(&h_dentry->d_lock);
++ h_dentry->d_flags &= ~DCACHE_MOUNTED;
++ spin_unlock(&h_dentry->d_lock);
++}
++
+static void au_br_do_free(struct au_branch *br)
+{
+ int i;
+ else
+ break;
+
-+ mntput(br->br_mnt);
++ au_br_dflags_restore(br);
++
++ /* recursive lock, s_umount of branch's */
++ lockdep_off();
++ path_put(&br->br_path);
++ lockdep_on();
+ kfree(wbr);
+ kfree(br);
+}
+ if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
+ h_inode = au_h_dptr(root, 0)->d_inode;
+ if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
-+ || h_inode->i_uid != inode->i_uid
-+ || h_inode->i_gid != inode->i_gid)
-+ pr_warning("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
-+ add->pathname,
-+ inode->i_uid, inode->i_gid,
-+ (inode->i_mode & S_IALLUGO),
-+ h_inode->i_uid, h_inode->i_gid,
-+ (h_inode->i_mode & S_IALLUGO));
++ || !uid_eq(h_inode->i_uid, inode->i_uid)
++ || !gid_eq(h_inode->i_gid, inode->i_gid))
++ pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
++ add->pathname,
++ i_uid_read(inode), i_gid_read(inode),
++ (inode->i_mode & S_IALLUGO),
++ i_uid_read(h_inode), i_gid_read(h_inode),
++ (h_inode->i_mode & S_IALLUGO));
+ }
+
+out:
+ * initialize or clean the whiteouts for an adding branch
+ */
+static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
-+ int new_perm, struct dentry *h_root)
++ int new_perm)
+{
+ int err, old_perm;
+ aufs_bindex_t bindex;
+ struct au_wbr *wbr;
+ struct au_hinode *hdir;
+
++ err = vfsub_mnt_want_write(au_br_mnt(br));
++ if (unlikely(err))
++ goto out;
++
+ wbr = br->br_wbr;
+ old_perm = br->br_perm;
+ br->br_perm = new_perm;
+ hdir = au_hi(sb->s_root->d_inode, bindex);
+ au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
+ } else {
-+ h_mtx = &h_root->d_inode->i_mutex;
++ h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
+ mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
+ }
+ if (!wbr)
-+ err = au_wh_init(h_root, br, sb);
++ err = au_wh_init(br, sb);
+ else {
+ wbr_wh_write_lock(wbr);
-+ err = au_wh_init(h_root, br, sb);
++ err = au_wh_init(br, sb);
+ wbr_wh_write_unlock(wbr);
+ }
+ if (hdir)
+ au_hn_imtx_unlock(hdir);
+ else
+ mutex_unlock(h_mtx);
++ vfsub_mnt_drop_write(au_br_mnt(br));
+ br->br_perm = old_perm;
+
+ if (!err && wbr && !au_br_writable(new_perm)) {
+ br->br_wbr = NULL;
+ }
+
++out:
+ return err;
+}
+
+static int au_wbr_init(struct au_branch *br, struct super_block *sb,
-+ int perm, struct path *path)
++ int perm)
+{
+ int err;
+ struct kstatfs kst;
+ struct au_wbr *wbr;
-+ struct dentry *h_dentry;
+
+ wbr = br->br_wbr;
+ au_rw_init(&wbr->wbr_wh_rwsem);
+
+ /*
+ * a limit for rmdir/rename a dir
-+ * cf. AUFS_MAX_NAMELEN in include/linux/aufs_type.h
++ * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
+ */
-+ err = vfs_statfs(path, &kst);
++ err = vfs_statfs(&br->br_path, &kst);
+ if (unlikely(err))
+ goto out;
+ err = -EINVAL;
-+ h_dentry = path->dentry;
+ if (kst.f_namelen >= NAME_MAX)
-+ err = au_br_init_wh(sb, br, perm, h_dentry);
++ err = au_br_init_wh(sb, br, perm);
+ else
-+ pr_err("%.*s(%s), unsupported namelen %ld\n",
-+ AuDLNPair(h_dentry), au_sbtype(h_dentry->d_sb),
-+ kst.f_namelen);
++ pr_err("%pd(%s), unsupported namelen %ld\n",
++ au_br_dentry(br),
++ au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
+
+out:
+ return err;
+ memset(&br->br_xino, 0, sizeof(br->br_xino));
+ mutex_init(&br->br_xino.xi_nondir_mtx);
+ br->br_perm = add->perm;
-+ br->br_mnt = add->path.mnt; /* set first, mntget() later */
++ BUILD_BUG_ON(sizeof(br->br_dflags)
++ != sizeof(br->br_path.dentry->d_flags));
++ br->br_dflags = DCACHE_MOUNTED;
++ br->br_path = add->path; /* set first, path_get() later */
+ spin_lock_init(&br->br_dykey_lock);
+ memset(br->br_dykey, 0, sizeof(br->br_dykey));
+ atomic_set(&br->br_count, 0);
-+ br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
+ atomic_set(&br->br_xino_running, 0);
+ br->br_id = au_new_br_id(sb);
+ AuDebugOn(br->br_id < 0);
+
+ if (au_br_writable(add->perm)) {
-+ err = au_wbr_init(br, sb, add->perm, &add->path);
++ err = au_wbr_init(br, sb, add->perm);
+ if (unlikely(err))
+ goto out_err;
+ }
+ }
+
+ sysaufs_br_init(br);
-+ mntget(add->path.mnt);
++ path_get(&br->br_path);
+ goto out; /* success */
+
+out_err:
-+ br->br_mnt = NULL;
++ memset(&br->br_path, 0, sizeof(br->br_path));
+out:
+ return err;
+}
+ iinfo->ii_bstart = 0;
+}
+
-+static void au_br_do_add(struct super_block *sb, struct dentry *h_dentry,
-+ struct au_branch *br, aufs_bindex_t bindex)
++static void au_br_do_add(struct super_block *sb, struct au_branch *br,
++ aufs_bindex_t bindex)
+{
-+ struct dentry *root;
++ struct dentry *root, *h_dentry;
+ struct inode *root_inode;
+ aufs_bindex_t bend, amount;
+
++ au_br_dflags_force(br);
++
+ root = sb->s_root;
+ root_inode = root->d_inode;
+ bend = au_sbend(sb);
+ amount = bend + 1 - bindex;
++ h_dentry = au_br_dentry(br);
+ au_sbilist_lock();
+ au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
+ au_br_do_add_hdp(au_di(root), bindex, bend, amount);
+ }
+
+ add_bindex = add->bindex;
-+ h_dentry = add->path.dentry;
+ if (!remount)
-+ au_br_do_add(sb, h_dentry, add_branch, add_bindex);
++ au_br_do_add(sb, add_branch, add_bindex);
+ else {
+ sysaufs_brs_del(sb, add_bindex);
-+ au_br_do_add(sb, h_dentry, add_branch, add_bindex);
++ au_br_do_add(sb, add_branch, add_bindex);
+ sysaufs_brs_add(sb, add_bindex);
+ }
+
++ h_dentry = add->path.dentry;
+ if (!add_bindex) {
+ au_cpup_attr_all(root_inode, /*force*/1);
+ sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
+ ndentry = dpage->ndentry;
+ for (j = 0; !err && j < ndentry; j++) {
+ d = dpage->dentries[j];
-+ AuDebugOn(!d->d_count);
++ AuDebugOn(!d_count(d));
+ if (!au_digen_test(d, sigen)) {
+ di_read_lock_child(d, AuLock_IR);
+ if (unlikely(au_dbrange_test(d))) {
+ && au_h_dptr(d, bindex)
+ && au_test_dbusy(d, bstart, bend)) {
+ err = -EBUSY;
-+ AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
++ AuVerbose(verbose, "busy %pd\n", d);
+ AuDbgDentry(d);
+ }
+ di_read_unlock(d, AuLock_IR);
+ continue;
+
+ /* AuDbgInode(i); */
-+ if (au_iigen(i) == sigen)
++ if (au_iigen(i, NULL) == sigen)
+ ii_read_lock_child(i);
+ else {
+ ii_write_lock_child(i);
+ goto out;
+ }
+ 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);
+
+out_wh:
+ /* revert */
-+ rerr = au_br_init_wh(sb, br, br->br_perm, del->h_path.dentry);
++ rerr = au_br_init_wh(sb, br, br->br_perm);
+ if (rerr)
-+ pr_warning("failed re-creating base whiteout, %s. (%d)\n",
-+ del->pathname, rerr);
++ pr_warn("failed re-creating base whiteout, %s. (%d)\n",
++ del->pathname, rerr);
+out:
+ return err;
+}
+{
+ 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;
-+ lg_global_lock(files_lglock);
-+ do_file_list_for_each_entry(sb, f) {
-+ if (au_fi(f)
-+ && file_count(f)
-+ && !special_file(f->f_dentry->d_inode->i_mode)) {
++ 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);
+ }
-+ } while_file_list_for_each_entry;
-+ lg_global_unlock(files_lglock);
++ }
++ spin_unlock(&files->spin);
+
+ return n;
+}
+ for (ull = 0; ull < max; ull++) {
+ file = array[ull];
+
-+ /* AuDbg("%.*s\n", AuDLNPair(file->f_dentry)); */
++ /* AuDbg("%pD\n", file); */
+ fi_read_lock(file);
+ if (unlikely(au_test_mmapped(file))) {
+ err = -EBUSY;
-+ AuVerbose(verbose, "mmapped %.*s\n",
-+ AuDLNPair(file->f_dentry));
++ AuVerbose(verbose, "mmapped %pD\n", file);
+ AuDbgFile(file);
+ FiMustNoWaiters(file);
+ fi_read_unlock(file);
+ goto out_array;
+ }
+
-+ inode = file->f_dentry->d_inode;
++ inode = file_inode(file);
+ hfile = &au_fi(file)->fi_htop;
+ hf = hfile->hf_file;
+ if (!S_ISREG(inode->i_mode)
+ continue;
+
+ /* todo: already flushed? */
-+ /* cf. fs/super.c:mark_files_ro() */
++ /*
++ * fs/super.c:mark_files_ro() is gone, but aufs keeps its
++ * approach which resets f_mode and calls mnt_drop_write() and
++ * file_release_write() for each file, because the branch
++ * attribute in aufs world is totally different from the native
++ * fs rw/ro mode.
++ */
+ /* fi_read_lock(file); */
+ hfile = &au_fi(file)->fi_htop;
+ hf = hfile->hf_file;
+ hf->f_mode &= ~FMODE_WRITE;
+ spin_unlock(&hf->f_lock);
+ if (!file_check_writeable(hf)) {
++ __mnt_drop_write(hf->f_path.mnt);
+ file_release_write(hf);
-+ mnt_drop_write(hf->f_vfsmnt);
+ }
+ }
+
+{
+ int err, rerr;
+ aufs_bindex_t bindex;
-+ struct path path;
+ struct dentry *root;
+ struct au_branch *br;
+
+ goto out;
+
+ br = au_sbr(sb, bindex);
++ AuDebugOn(mod->h_root != au_br_dentry(br));
+ if (br->br_perm == mod->perm)
+ return 0; /* success */
+
+ if (au_br_writable(br->br_perm)) {
+ /* remove whiteout base */
-+ err = au_br_init_wh(sb, br, mod->perm, mod->h_root);
++ err = au_br_init_wh(sb, br, mod->perm);
+ if (unlikely(err))
+ goto out;
+
+ rerr = -ENOMEM;
+ br->br_wbr = kmalloc(sizeof(*br->br_wbr),
+ GFP_NOFS);
-+ if (br->br_wbr) {
-+ path.mnt = br->br_mnt;
-+ path.dentry = mod->h_root;
-+ rerr = au_wbr_init(br, sb, br->br_perm,
-+ &path);
-+ }
++ if (br->br_wbr)
++ rerr = au_wbr_init(br, sb, br->br_perm);
+ if (unlikely(rerr)) {
+ AuIOErr("nested error %d (%d)\n",
+ rerr, err);
+ err = -ENOMEM;
+ br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
+ if (br->br_wbr) {
-+ path.mnt = br->br_mnt;
-+ path.dentry = mod->h_root;
-+ err = au_wbr_init(br, sb, mod->perm, &path);
++ err = au_wbr_init(br, sb, mod->perm);
+ if (unlikely(err)) {
+ kfree(br->br_wbr);
+ br->br_wbr = NULL;
+ }
+
+ if (!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;
+ }
+}
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 2011-10-24 20:51:51.580466925 +0200
-@@ -0,0 +1,232 @@
++++ linux/fs/aufs/branch.h 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,264 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/fs.h>
+#include <linux/mount.h>
-+#include <linux/aufs_type.h>
+#include "dynop.h"
+#include "rwsem.h"
+#include "super.h"
+/* ext2 has 3 types of operations at least, ext3 has 4 */
+#define AuBrDynOp (AuDyLast * 4)
+
++#ifdef CONFIG_AUFS_HFSNOTIFY
++/* support for asynchronous destruction */
++struct au_br_hfsnotify {
++ struct fsnotify_group *hfsn_group;
++};
++#endif
++
++/* sysfs entries */
++struct au_brsysfs {
++ char name[16];
++ struct attribute attr;
++};
++
++enum {
++ AuBrSysfs_BR,
++ AuBrSysfs_BRID,
++ AuBrSysfs_Last
++};
++
+/* protected by superblock rwsem */
+struct au_branch {
+ struct au_xino_file br_xino;
+ aufs_bindex_t br_id;
+
+ int br_perm;
-+ struct vfsmount *br_mnt;
++ unsigned int br_dflags;
++ struct path br_path;
+ spinlock_t br_dykey_lock;
+ struct au_dykey *br_dykey[AuBrDynOp];
+ atomic_t br_count;
+ struct au_wbr *br_wbr;
+
+ /* xino truncation */
-+ blkcnt_t br_xino_upper; /* watermark in blocks */
+ atomic_t br_xino_running;
+
+#ifdef CONFIG_AUFS_HFSNOTIFY
-+ struct fsnotify_group *br_hfsn_group;
-+ struct fsnotify_ops br_hfsn_ops;
++ struct au_br_hfsnotify *br_hfsn;
+#endif
+
+#ifdef CONFIG_SYSFS
-+ /* an entry under sysfs per mount-point */
-+ char br_name[8];
-+ struct attribute br_attr;
++ /* entries under sysfs per mount-point */
++ struct au_brsysfs br_sysfs[AuBrSysfs_Last];
+#endif
+};
+
+/* ---------------------------------------------------------------------- */
+
++static inline struct vfsmount *au_br_mnt(struct au_branch *br)
++{
++ return br->br_path.mnt;
++}
++
++static inline struct dentry *au_br_dentry(struct au_branch *br)
++{
++ return br->br_path.dentry;
++}
++
++static inline struct super_block *au_br_sb(struct au_branch *br)
++{
++ 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 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_rdonly(struct au_branch *br)
+{
-+ return ((br->br_mnt->mnt_sb->s_flags & MS_RDONLY)
++ return ((au_br_sb(br)->s_flags & MS_RDONLY)
+ || !au_br_writable(br->br_perm))
+ ? -EROFS : 0;
+}
+static inline
+struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
+{
-+ return au_sbr(sb, bindex)->br_mnt;
++ return au_br_mnt(au_sbr(sb, bindex));
+}
+
+static inline
+struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
+{
-+ return au_sbr_mnt(sb, bindex)->mnt_sb;
++ return au_br_sb(au_sbr(sb, bindex));
+}
+
+static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,38 @@
++++ linux/fs/aufs/conf.mk 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,37 @@
+
+AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
+
+ HNOTIFY HFSNOTIFY \
+ EXPORT INO_T_64 \
+ RDU \
-+ PROC_MAP \
+ SP_IATTR \
+ SHWH \
+ BR_RAMFS \
+-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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,1080 @@
++++ linux/fs/aufs/cpup.c 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,1277 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * copy-up functions, see wbr_policy.c for copy-down
+ */
+
-+#include <linux/file.h>
+#include <linux/fs_stack.h>
+#include <linux/mm.h>
-+#include <linux/uaccess.h>
+#include "aufs.h"
+
-+void au_cpup_attr_flags(struct inode *dst, struct inode *src)
++void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
+{
+ const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
-+ | S_NOATIME | S_NOCMTIME;
++ | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
++
++ BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
+
-+ dst->i_flags |= src->i_flags & ~mask;
++ dst->i_flags |= iflags & ~mask;
+ if (au_test_fs_notime(dst->i_sb))
+ dst->i_flags |= S_NOATIME | S_NOCMTIME;
+}
+ && au_plink_test(inode))
+ return;
+
-+ inode->i_nlink = h_inode->i_nlink;
++ /*
++ * 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.
++ */
++ set_nlink(inode, h_inode->i_nlink);
+
+ /*
+ * fewer nlink makes find(1) noisy, but larger nlink doesn't.
+ inode->i_uid = h_inode->i_uid;
+ inode->i_gid = h_inode->i_gid;
+ au_cpup_attr_timesizes(inode);
-+ au_cpup_attr_flags(inode, h_inode);
++ au_cpup_attr_flags(inode, h_inode->i_flags);
+}
+
+void au_cpup_igen(struct inode *inode, struct inode *h_inode)
+ attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
+ | ATTR_ATIME | ATTR_ATIME_SET;
+
-+ err = vfsub_notify_change(&dt->dt_h_path, &attr);
++ /* no delegation since this is a directory */
++ err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
+ if (unlikely(err))
-+ pr_warning("restoring timestamps failed(%d). ignored\n", err);
++ pr_warn("restoring timestamps failed(%d). ignored\n", err);
+}
+
+/* ---------------------------------------------------------------------- */
+
++/* internal use only */
++struct au_cpup_reg_attr {
++ int valid;
++ struct kstat st;
++ unsigned int iflags; /* inode->i_flags */
++};
++
+static noinline_for_stack
-+int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src)
++int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
++ struct au_cpup_reg_attr *h_src_attr)
+{
+ int err, sbits;
+ struct iattr ia;
+ struct path h_path;
+ struct inode *h_isrc, *h_idst;
++ struct kstat *h_st;
+
+ h_path.dentry = au_h_dptr(dst, bindex);
+ h_idst = h_path.dentry->d_inode;
+ ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
+ | ATTR_ATIME | ATTR_MTIME
+ | ATTR_ATIME_SET | ATTR_MTIME_SET;
-+ ia.ia_uid = h_isrc->i_uid;
-+ ia.ia_gid = h_isrc->i_gid;
-+ ia.ia_atime = h_isrc->i_atime;
-+ ia.ia_mtime = h_isrc->i_mtime;
-+ if (h_idst->i_mode != h_isrc->i_mode
-+ && !S_ISLNK(h_idst->i_mode)) {
-+ ia.ia_valid |= ATTR_MODE;
-+ ia.ia_mode = h_isrc->i_mode;
++ if (h_src_attr && h_src_attr->valid) {
++ h_st = &h_src_attr->st;
++ ia.ia_uid = h_st->uid;
++ ia.ia_gid = h_st->gid;
++ ia.ia_atime = h_st->atime;
++ ia.ia_mtime = h_st->mtime;
++ if (h_idst->i_mode != h_st->mode
++ && !S_ISLNK(h_idst->i_mode)) {
++ ia.ia_valid |= ATTR_MODE;
++ ia.ia_mode = h_st->mode;
++ }
++ sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
++ au_cpup_attr_flags(h_idst, h_src_attr->iflags);
++ } else {
++ ia.ia_uid = h_isrc->i_uid;
++ ia.ia_gid = h_isrc->i_gid;
++ ia.ia_atime = h_isrc->i_atime;
++ ia.ia_mtime = h_isrc->i_mtime;
++ if (h_idst->i_mode != h_isrc->i_mode
++ && !S_ISLNK(h_idst->i_mode)) {
++ ia.ia_valid |= ATTR_MODE;
++ ia.ia_mode = h_isrc->i_mode;
++ }
++ sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
++ au_cpup_attr_flags(h_idst, h_isrc->i_flags);
+ }
-+ sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
-+ au_cpup_attr_flags(h_idst, h_isrc);
-+ err = vfsub_notify_change(&h_path, &ia);
++ /* no delegation since it is just created */
++ err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
+
+ /* is this nfs only? */
+ if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
+ ia.ia_valid = ATTR_FORCE | ATTR_MODE;
+ ia.ia_mode = h_isrc->i_mode;
-+ err = vfsub_notify_change(&h_path, &ia);
++ err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
+ }
+
+ return err;
+ wbytes -= b;
+ p += b;
+ }
++ if (unlikely(err < 0))
++ break;
+ } else {
+ loff_t res;
+
+ ia->ia_size = dst->f_pos;
+ ia->ia_valid = ATTR_SIZE | ATTR_FILE;
+ ia->ia_file = dst;
-+ h_mtx = &dst->f_dentry->d_inode->i_mutex;
++ h_mtx = &file_inode(dst)->i_mutex;
+ mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
-+ err = vfsub_notify_change(&dst->f_path, ia);
++ /* no delegation since it is just created */
++ err = vfsub_notify_change(&dst->f_path, ia,
++ /*delegated*/NULL);
+ mutex_unlock(h_mtx);
+ }
+ }
+ * to support a sparse file which is opened with O_APPEND,
+ * we need to close the file.
+ */
-+static int au_cp_regular(struct dentry *dentry, aufs_bindex_t bdst,
-+ aufs_bindex_t bsrc, loff_t len)
++static int au_cp_regular(struct au_cp_generic *cpg)
+{
+ int err, i;
+ enum { SRC, DST };
+ aufs_bindex_t bindex;
+ unsigned int flags;
+ struct dentry *dentry;
++ int force_wr;
+ struct file *file;
-+ void *label, *label_file;
++ void *label;
+ } *f, file[] = {
+ {
-+ .bindex = bsrc,
++ .bindex = cpg->bsrc,
+ .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
-+ .file = NULL,
-+ .label = &&out,
-+ .label_file = &&out_src
++ .label = &&out
+ },
+ {
-+ .bindex = bdst,
++ .bindex = cpg->bdst,
+ .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
-+ .file = NULL,
-+ .label = &&out_src,
-+ .label_file = &&out_dst
++ .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
++ .label = &&out_src
+ }
+ };
+ struct super_block *sb;
+
+ /* bsrc branch can be ro/rw. */
-+ sb = dentry->d_sb;
++ sb = cpg->dentry->d_sb;
+ f = file;
+ for (i = 0; i < 2; i++, f++) {
-+ f->dentry = au_h_dptr(dentry, f->bindex);
-+ f->file = au_h_open(dentry, f->bindex, f->flags, /*file*/NULL);
++ f->dentry = au_h_dptr(cpg->dentry, f->bindex);
++ f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
++ /*file*/NULL, f->force_wr);
+ err = PTR_ERR(f->file);
+ if (IS_ERR(f->file))
+ goto *f->label;
-+ err = -EINVAL;
-+ if (unlikely(!f->file->f_op))
-+ goto *f->label_file;
+ }
+
+ /* try stopping to update while we copyup */
+ IMustLock(file[SRC].dentry->d_inode);
-+ err = au_copy_file(file[DST].file, file[SRC].file, len);
++ err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
+
-+out_dst:
+ fput(file[DST].file);
+ au_sbr_put(sb, file[DST].bindex);
++
+out_src:
+ fput(file[SRC].file);
+ au_sbr_put(sb, file[SRC].bindex);
+ return err;
+}
+
-+static int au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
-+ aufs_bindex_t bsrc, loff_t len,
-+ struct inode *h_dir, struct path *h_path)
++static int au_do_cpup_regular(struct au_cp_generic *cpg,
++ struct au_cpup_reg_attr *h_src_attr)
+{
+ int err, rerr;
+ loff_t l;
++ struct path h_path;
++ struct inode *h_src_inode;
+
+ err = 0;
-+ l = i_size_read(au_h_iptr(dentry->d_inode, bsrc));
-+ if (len == -1 || l < len)
-+ len = l;
-+ if (len)
-+ err = au_cp_regular(dentry, bdst, bsrc, len);
-+ if (!err)
-+ goto out; /* success */
++ h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
++ l = i_size_read(h_src_inode);
++ if (cpg->len == -1 || l < cpg->len)
++ cpg->len = l;
++ if (cpg->len) {
++ /* try stopping to update while we are referencing */
++ mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
++ au_pin_hdir_unlock(cpg->pin);
+
-+ rerr = vfsub_unlink(h_dir, h_path, /*force*/0);
-+ if (rerr) {
-+ AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
-+ AuDLNPair(h_path->dentry), err, rerr);
-+ err = -EIO;
++ h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
++ h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
++ h_src_attr->iflags = h_src_inode->i_flags;
++ err = vfs_getattr(&h_path, &h_src_attr->st);
++ if (unlikely(err)) {
++ mutex_unlock(&h_src_inode->i_mutex);
++ goto out;
++ }
++ h_src_attr->valid = 1;
++ err = au_cp_regular(cpg);
++ mutex_unlock(&h_src_inode->i_mutex);
++ rerr = au_pin_hdir_relock(cpg->pin);
++ if (!err && rerr)
++ err = rerr;
+ }
+
+out:
+ goto out;
+
+ err = -ENOMEM;
-+ sym.k = __getname_gfp(GFP_NOFS);
++ sym.k = (void *)__get_free_page(GFP_NOFS);
+ if (unlikely(!sym.k))
+ goto out;
+
++ /* unnecessary to support mmap_sem since symlink is not mmap-able */
+ old_fs = get_fs();
+ set_fs(KERNEL_DS);
+ symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
+ sym.k[symlen] = 0;
+ err = vfsub_symlink(h_dir, h_path, sym.k);
+ }
-+ __putname(sym.k);
++ free_page((unsigned long)sym.k);
+
+out:
+ return err;
+}
+
-+/* return with the lower dst inode is locked */
+static noinline_for_stack
-+int cpup_entry(struct dentry *dentry, aufs_bindex_t bdst,
-+ aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+ struct dentry *dst_parent)
++int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
++ struct au_cpup_reg_attr *h_src_attr)
+{
+ int err;
+ umode_t mode;
+ unsigned int mnt_flags;
+ unsigned char isdir;
-+ const unsigned char do_dt = !!au_ftest_cpup(flags, DTIME);
++ const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
+ struct au_dtime dt;
+ struct path h_path;
+ struct dentry *h_src, *h_dst, *h_parent;
+ struct super_block *sb;
+
+ /* bsrc branch can be ro/rw. */
-+ h_src = au_h_dptr(dentry, bsrc);
++ h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
+ h_inode = h_src->d_inode;
-+ AuDebugOn(h_inode != au_h_iptr(dentry->d_inode, bsrc));
++ AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
+
+ /* try stopping to be referenced while we are creating */
-+ h_dst = au_h_dptr(dentry, bdst);
++ h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
++ if (au_ftest_cpup(cpg->flags, RENAME))
++ AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
++ AUFS_WH_PFX_LEN));
+ h_parent = h_dst->d_parent; /* dir inode is locked */
+ h_dir = h_parent->d_inode;
+ IMustLock(h_dir);
+ AuDebugOn(h_parent != h_dst->d_parent);
+
-+ sb = dentry->d_sb;
-+ h_path.mnt = au_sbr_mnt(sb, bdst);
++ sb = cpg->dentry->d_sb;
++ h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
+ if (do_dt) {
+ h_path.dentry = h_parent;
+ au_dtime_store(&dt, dst_parent, &h_path);
+ mode = h_inode->i_mode;
+ switch (mode & S_IFMT) {
+ case S_IFREG:
-+ /* try stopping to update while we are referencing */
-+ IMustLock(h_inode);
-+ err = vfsub_create(h_dir, &h_path, mode | S_IWUSR);
++ err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
++ /*want_excl*/true);
+ if (!err)
-+ err = au_do_cpup_regular
-+ (dentry, bdst, bsrc, len,
-+ au_h_iptr(dst_parent->d_inode, bdst), &h_path);
++ err = au_do_cpup_regular(cpg, h_src_attr);
+ break;
+ case S_IFDIR:
+ isdir = 1;
+ * strange behaviour from the users view,
+ * particularry setattr case
+ */
-+ if (au_ibstart(dst_parent->d_inode) == bdst)
++ if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
+ au_cpup_attr_nlink(dst_parent->d_inode,
+ /*force*/1);
-+ au_cpup_attr_nlink(dentry->d_inode, /*force*/1);
++ au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
+ }
+ break;
+ case S_IFLNK:
+ && au_opt_test(mnt_flags, XINO)
+ && h_inode->i_nlink == 1
+ /* todo: unnecessary? */
-+ /* && dentry->d_inode->i_nlink == 1 */
-+ && bdst < bsrc
-+ && !au_ftest_cpup(flags, KEEPLINO))
-+ au_xino_write(sb, bsrc, h_inode->i_ino, /*ino*/0);
++ /* && cpg->dentry->d_inode->i_nlink == 1 */
++ && cpg->bdst < cpg->bsrc
++ && !au_ftest_cpup(cpg->flags, KEEPLINO))
++ au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
+ /* ignore this error */
+
+ if (do_dt)
+ return err;
+}
+
++static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
++{
++ int err;
++ struct dentry *dentry, *h_dentry, *h_parent, *parent;
++ struct inode *h_dir;
++ aufs_bindex_t bdst;
++
++ dentry = cpg->dentry;
++ bdst = cpg->bdst;
++ h_dentry = au_h_dptr(dentry, bdst);
++ if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
++ dget(h_dentry);
++ au_set_h_dptr(dentry, bdst, NULL);
++ err = au_lkup_neg(dentry, bdst, /*wh*/0);
++ if (!err)
++ h_path->dentry = dget(au_h_dptr(dentry, bdst));
++ au_set_h_dptr(dentry, bdst, h_dentry);
++ } else {
++ err = 0;
++ parent = dget_parent(dentry);
++ h_parent = au_h_dptr(parent, bdst);
++ dput(parent);
++ h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
++ if (IS_ERR(h_path->dentry))
++ err = PTR_ERR(h_path->dentry);
++ }
++ if (unlikely(err))
++ goto out;
++
++ h_parent = h_dentry->d_parent; /* dir inode is locked */
++ h_dir = h_parent->d_inode;
++ IMustLock(h_dir);
++ AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
++ /* no delegation since it is just created */
++ err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
++ dput(h_path->dentry);
++
++out:
++ return err;
++}
++
+/*
+ * copyup the @dentry from @bsrc to @bdst.
+ * the caller must set the both of lower dentries.
+ * @len is for truncating when it is -1 copyup the entire file.
+ * in link/rename cases, @dst_parent may be different from the real one.
++ * basic->bsrc can be larger than basic->bdst.
+ */
-+static int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
-+ aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+ struct dentry *dst_parent)
++static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
+{
+ int err, rerr;
+ aufs_bindex_t old_ibstart;
+ unsigned char isdir, plink;
-+ struct au_dtime dt;
-+ struct path h_path;
+ struct dentry *h_src, *h_dst, *h_parent;
-+ struct inode *dst_inode, *h_dir, *inode;
++ struct inode *dst_inode, *h_dir, *inode, *delegated;
+ struct super_block *sb;
++ struct au_branch *br;
++ /* to reuduce stack size */
++ struct {
++ struct au_dtime dt;
++ struct path h_path;
++ struct au_cpup_reg_attr h_src_attr;
++ } *a;
+
-+ AuDebugOn(bsrc <= bdst);
++ err = -ENOMEM;
++ a = kmalloc(sizeof(*a), GFP_NOFS);
++ if (unlikely(!a))
++ goto out;
++ a->h_src_attr.valid = 0;
+
-+ sb = dentry->d_sb;
-+ h_path.mnt = au_sbr_mnt(sb, bdst);
-+ h_dst = au_h_dptr(dentry, bdst);
++ sb = cpg->dentry->d_sb;
++ br = au_sbr(sb, cpg->bdst);
++ a->h_path.mnt = au_br_mnt(br);
++ h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
+ h_parent = h_dst->d_parent; /* dir inode is locked */
+ h_dir = h_parent->d_inode;
+ IMustLock(h_dir);
+
-+ h_src = au_h_dptr(dentry, bsrc);
-+ inode = dentry->d_inode;
++ h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
++ inode = cpg->dentry->d_inode;
+
+ if (!dst_parent)
-+ dst_parent = dget_parent(dentry);
++ dst_parent = dget_parent(cpg->dentry);
+ else
+ dget(dst_parent);
+
+ plink = !!au_opt_test(au_mntflags(sb), PLINK);
-+ dst_inode = au_h_iptr(inode, bdst);
++ dst_inode = au_h_iptr(inode, cpg->bdst);
+ if (dst_inode) {
+ if (unlikely(!plink)) {
+ err = -EIO;
+ AuIOErr("hi%lu(i%lu) exists on b%d "
+ "but plink is disabled\n",
-+ dst_inode->i_ino, inode->i_ino, bdst);
-+ goto out;
++ dst_inode->i_ino, inode->i_ino, cpg->bdst);
++ goto out_parent;
+ }
+
+ if (dst_inode->i_nlink) {
-+ const int do_dt = au_ftest_cpup(flags, DTIME);
++ const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
+
-+ h_src = au_plink_lkup(inode, bdst);
++ h_src = au_plink_lkup(inode, cpg->bdst);
+ err = PTR_ERR(h_src);
+ if (IS_ERR(h_src))
-+ goto out;
++ goto out_parent;
+ if (unlikely(!h_src->d_inode)) {
+ err = -EIO;
+ AuIOErr("i%lu exists on a upper branch "
+ "but not pseudo-linked\n",
+ inode->i_ino);
+ dput(h_src);
-+ goto out;
++ goto out_parent;
+ }
+
+ if (do_dt) {
-+ h_path.dentry = h_parent;
-+ au_dtime_store(&dt, dst_parent, &h_path);
++ a->h_path.dentry = h_parent;
++ au_dtime_store(&a->dt, dst_parent, &a->h_path);
+ }
-+ h_path.dentry = h_dst;
-+ err = vfsub_link(h_src, h_dir, &h_path);
++
++ a->h_path.dentry = h_dst;
++ delegated = NULL;
++ err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
++ if (!err && au_ftest_cpup(cpg->flags, RENAME))
++ err = au_do_ren_after_cpup(cpg, &a->h_path);
+ if (do_dt)
-+ au_dtime_revert(&dt);
++ au_dtime_revert(&a->dt);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal link\n");
++ iput(delegated);
++ }
+ dput(h_src);
-+ goto out;
++ goto out_parent;
+ } else
+ /* todo: cpup_wh_file? */
+ /* udba work */
+ au_update_ibrange(inode, /*do_put_zero*/1);
+ }
+
++ isdir = S_ISDIR(inode->i_mode);
+ old_ibstart = au_ibstart(inode);
-+ err = cpup_entry(dentry, bdst, bsrc, len, flags, dst_parent);
++ err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
+ if (unlikely(err))
-+ goto out;
++ goto out_rev;
+ dst_inode = h_dst->d_inode;
+ mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
++ /* todo: necessary? */
++ /* au_pin_hdir_unlock(cpg->pin); */
+
-+ err = cpup_iattr(dentry, bdst, h_src);
-+ isdir = S_ISDIR(dst_inode->i_mode);
-+ if (!err) {
-+ if (bdst < old_ibstart) {
-+ if (S_ISREG(inode->i_mode)) {
-+ err = au_dy_iaop(inode, bdst, dst_inode);
-+ if (unlikely(err))
-+ goto out_rev;
++ err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
++ if (unlikely(err)) {
++ /* todo: necessary? */
++ /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
++ mutex_unlock(&dst_inode->i_mutex);
++ goto out_rev;
++ }
++
++ if (cpg->bdst < old_ibstart) {
++ if (S_ISREG(inode->i_mode)) {
++ err = au_dy_iaop(inode, cpg->bdst, dst_inode);
++ if (unlikely(err)) {
++ /* ignore an error */
++ /* au_pin_hdir_relock(cpg->pin); */
++ mutex_unlock(&dst_inode->i_mutex);
++ goto out_rev;
+ }
-+ au_set_ibstart(inode, bdst);
+ }
-+ au_set_h_iptr(inode, bdst, au_igrab(dst_inode),
-+ au_hi_flags(inode, isdir));
-+ mutex_unlock(&dst_inode->i_mutex);
-+ if (!isdir
-+ && h_src->d_inode->i_nlink > 1
-+ && plink)
-+ au_plink_append(inode, bdst, h_dst);
-+ goto out; /* success */
++ au_set_ibstart(inode, cpg->bdst);
++ } else
++ au_set_ibend(inode, cpg->bdst);
++ au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
++ au_hi_flags(inode, isdir));
++
++ /* todo: necessary? */
++ /* err = au_pin_hdir_relock(cpg->pin); */
++ mutex_unlock(&dst_inode->i_mutex);
++ if (unlikely(err))
++ goto out_rev;
++
++ if (!isdir
++ && h_src->d_inode->i_nlink > 1
++ && plink)
++ au_plink_append(inode, cpg->bdst, h_dst);
++
++ if (au_ftest_cpup(cpg->flags, RENAME)) {
++ a->h_path.dentry = h_dst;
++ err = au_do_ren_after_cpup(cpg, &a->h_path);
+ }
++ if (!err)
++ goto out_parent; /* success */
+
+ /* revert */
+out_rev:
-+ h_path.dentry = h_parent;
-+ mutex_unlock(&dst_inode->i_mutex);
-+ au_dtime_store(&dt, dst_parent, &h_path);
-+ h_path.dentry = h_dst;
-+ if (!isdir)
-+ rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
-+ else
-+ rerr = vfsub_rmdir(h_dir, &h_path);
-+ au_dtime_revert(&dt);
++ a->h_path.dentry = h_parent;
++ au_dtime_store(&a->dt, dst_parent, &a->h_path);
++ a->h_path.dentry = h_dst;
++ rerr = 0;
++ if (h_dst->d_inode) {
++ if (!isdir) {
++ /* no delegation since it is just created */
++ rerr = vfsub_unlink(h_dir, &a->h_path,
++ /*delegated*/NULL, /*force*/0);
++ } else
++ rerr = vfsub_rmdir(h_dir, &a->h_path);
++ }
++ au_dtime_revert(&a->dt);
+ if (rerr) {
+ AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
+ err = -EIO;
+ }
-+
-+out:
++out_parent:
+ dput(dst_parent);
++ kfree(a);
++out:
+ return err;
+}
+
++#if 0 /* unused */
+struct au_cpup_single_args {
+ int *errp;
-+ struct dentry *dentry;
-+ aufs_bindex_t bdst, bsrc;
-+ loff_t len;
-+ unsigned int flags;
++ struct au_cp_generic *cpg;
+ struct dentry *dst_parent;
+};
+
+static void au_call_cpup_single(void *args)
+{
+ struct au_cpup_single_args *a = args;
-+ *a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
-+ a->flags, a->dst_parent);
++
++ au_pin_hdir_acquire_nest(a->cpg->pin);
++ *a->errp = au_cpup_single(a->cpg, a->dst_parent);
++ au_pin_hdir_release(a->cpg->pin);
+}
++#endif
+
+/*
+ * prevent SIGXFSZ in copy-up.
+ * testing CAP_MKNOD is for generic fs,
+ * but CAP_FSETID is for xfs only, currently.
+ */
-+static int au_cpup_sio_test(struct super_block *sb, umode_t mode)
++static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
+{
+ int do_sio;
++ struct super_block *sb;
++ struct inode *h_dir;
+
+ do_sio = 0;
++ sb = au_pinned_parent(pin)->d_sb;
+ if (!au_wkq_test()
+ && (!au_sbi(sb)->si_plink_maint_pid
+ || au_plink_maint(sb, AuLock_NOPLM))) {
+ if (!do_sio)
+ do_sio = ((mode & (S_ISUID | S_ISGID))
+ && !capable(CAP_FSETID));
++ /* this workaround may be removed in the future */
++ if (!do_sio) {
++ h_dir = au_pinned_h_dir(pin);
++ do_sio = h_dir->i_mode & S_ISVTX;
++ }
+ }
+
+ return do_sio;
+}
+
-+int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
-+ aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+ struct dentry *dst_parent)
++#if 0 /* unused */
++int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
+{
+ int err, wkq_err;
+ struct dentry *h_dentry;
+
-+ h_dentry = au_h_dptr(dentry, bsrc);
-+ if (!au_cpup_sio_test(dentry->d_sb, h_dentry->d_inode->i_mode))
-+ err = au_cpup_single(dentry, bdst, bsrc, len, flags,
-+ dst_parent);
++ h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
++ if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
++ err = au_cpup_single(cpg, dst_parent);
+ else {
+ struct au_cpup_single_args args = {
+ .errp = &err,
-+ .dentry = dentry,
-+ .bdst = bdst,
-+ .bsrc = bsrc,
-+ .len = len,
-+ .flags = flags,
++ .cpg = cpg,
+ .dst_parent = dst_parent
+ };
+ wkq_err = au_wkq_wait(au_call_cpup_single, &args);
+
+ return err;
+}
++#endif
+
+/*
+ * copyup the @dentry from the first active lower branch to @bdst,
+ * using au_cpup_single().
+ */
-+static int au_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+ unsigned int flags)
++static int au_cpup_simple(struct au_cp_generic *cpg)
+{
+ int err;
-+ aufs_bindex_t bsrc, bend;
++ unsigned int flags_orig;
++ struct dentry *dentry;
+
-+ bend = au_dbend(dentry);
-+ for (bsrc = bdst + 1; bsrc <= bend; bsrc++)
-+ if (au_h_dptr(dentry, bsrc))
-+ break;
++ AuDebugOn(cpg->bsrc < 0);
++
++ dentry = cpg->dentry;
++ DiMustWriteLock(dentry);
+
-+ err = au_lkup_neg(dentry, bdst);
++ err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
+ if (!err) {
-+ err = au_cpup_single(dentry, bdst, bsrc, len, flags, NULL);
++ flags_orig = cpg->flags;
++ au_fset_cpup(cpg->flags, RENAME);
++ err = au_cpup_single(cpg, NULL);
++ cpg->flags = flags_orig;
+ if (!err)
+ return 0; /* success */
+
+ /* revert */
-+ au_set_h_dptr(dentry, bdst, NULL);
-+ au_set_dbstart(dentry, bsrc);
++ au_set_h_dptr(dentry, cpg->bdst, NULL);
++ au_set_dbstart(dentry, cpg->bsrc);
+ }
+
+ return err;
+
+struct au_cpup_simple_args {
+ int *errp;
-+ struct dentry *dentry;
-+ aufs_bindex_t bdst;
-+ loff_t len;
-+ unsigned int flags;
++ struct au_cp_generic *cpg;
+};
+
+static void au_call_cpup_simple(void *args)
+{
+ struct au_cpup_simple_args *a = args;
-+ *a->errp = au_cpup_simple(a->dentry, a->bdst, a->len, a->flags);
++
++ au_pin_hdir_acquire_nest(a->cpg->pin);
++ *a->errp = au_cpup_simple(a->cpg);
++ au_pin_hdir_release(a->cpg->pin);
+}
+
-+int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+ unsigned int flags)
++static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
+{
+ int err, wkq_err;
-+ struct dentry *parent;
++ struct dentry *dentry, *parent;
++ struct file *h_file;
+ struct inode *h_dir;
+
++ dentry = cpg->dentry;
++ h_file = NULL;
++ if (au_ftest_cpup(cpg->flags, HOPEN)) {
++ AuDebugOn(cpg->bsrc < 0);
++ h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
++ err = PTR_ERR(h_file);
++ if (IS_ERR(h_file))
++ goto out;
++ }
++
+ parent = dget_parent(dentry);
-+ h_dir = au_h_iptr(parent->d_inode, bdst);
++ h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
+ if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
-+ && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
-+ err = au_cpup_simple(dentry, bdst, len, flags);
++ && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
++ err = au_cpup_simple(cpg);
+ else {
+ struct au_cpup_simple_args args = {
+ .errp = &err,
-+ .dentry = dentry,
-+ .bdst = bdst,
-+ .len = len,
-+ .flags = flags
++ .cpg = cpg
+ };
+ wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
+ if (unlikely(wkq_err))
+ }
+
+ dput(parent);
++ if (h_file)
++ au_h_open_post(dentry, cpg->bsrc, h_file);
++
++out:
+ return err;
+}
+
++int au_sio_cpup_simple(struct au_cp_generic *cpg)
++{
++ aufs_bindex_t bsrc, bend;
++ struct dentry *dentry, *h_dentry;
++
++ if (cpg->bsrc < 0) {
++ dentry = cpg->dentry;
++ bend = au_dbend(dentry);
++ for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
++ h_dentry = au_h_dptr(dentry, bsrc);
++ if (h_dentry) {
++ AuDebugOn(!h_dentry->d_inode);
++ break;
++ }
++ }
++ AuDebugOn(bsrc > bend);
++ cpg->bsrc = bsrc;
++ }
++ AuDebugOn(cpg->bsrc <= cpg->bdst);
++ return au_do_sio_cpup_simple(cpg);
++}
++
++int au_sio_cpdown_simple(struct au_cp_generic *cpg)
++{
++ AuDebugOn(cpg->bdst <= cpg->bsrc);
++ return au_do_sio_cpup_simple(cpg);
++}
++
+/* ---------------------------------------------------------------------- */
+
+/*
+ * copyup the deleted file for writing.
+ */
-+static int au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
-+ struct dentry *wh_dentry, struct file *file,
-+ loff_t len)
++static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
++ struct file *file)
+{
+ int err;
-+ aufs_bindex_t bstart;
-+ struct au_dinfo *dinfo;
++ unsigned int flags_orig;
++ aufs_bindex_t bsrc_orig;
+ struct dentry *h_d_dst, *h_d_start;
++ struct au_dinfo *dinfo;
+ struct au_hdentry *hdp;
+
-+ dinfo = au_di(dentry);
++ dinfo = au_di(cpg->dentry);
+ AuRwMustWriteLock(&dinfo->di_rwsem);
+
-+ bstart = dinfo->di_bstart;
++ bsrc_orig = cpg->bsrc;
++ cpg->bsrc = dinfo->di_bstart;
+ hdp = dinfo->di_hdentry;
-+ h_d_dst = hdp[0 + bdst].hd_dentry;
-+ dinfo->di_bstart = bdst;
-+ hdp[0 + bdst].hd_dentry = wh_dentry;
++ h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
++ dinfo->di_bstart = cpg->bdst;
++ hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
++ h_d_start = NULL;
+ if (file) {
-+ h_d_start = hdp[0 + bstart].hd_dentry;
-+ hdp[0 + bstart].hd_dentry = au_hf_top(file)->f_dentry;
++ h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
++ hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
+ }
-+ err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME,
-+ /*h_parent*/NULL);
++ flags_orig = cpg->flags;
++ cpg->flags = !AuCpup_DTIME;
++ err = au_cpup_single(cpg, /*h_parent*/NULL);
++ cpg->flags = flags_orig;
+ if (file) {
+ if (!err)
+ err = au_reopen_nondir(file);
-+ hdp[0 + bstart].hd_dentry = h_d_start;
++ hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
+ }
-+ hdp[0 + bdst].hd_dentry = h_d_dst;
-+ dinfo->di_bstart = bstart;
++ hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
++ dinfo->di_bstart = cpg->bsrc;
++ cpg->bsrc = bsrc_orig;
+
+ return err;
+}
+
-+static int au_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+ struct file *file)
++static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
+{
+ int err;
++ aufs_bindex_t bdst;
+ struct au_dtime dt;
-+ struct dentry *parent, *h_parent, *wh_dentry;
++ struct dentry *dentry, *parent, *h_parent, *wh_dentry;
+ struct au_branch *br;
+ struct path h_path;
+
++ dentry = cpg->dentry;
++ bdst = cpg->bdst;
+ br = au_sbr(dentry->d_sb, bdst);
+ parent = dget_parent(dentry);
+ h_parent = au_h_dptr(parent, bdst);
+ goto out;
+
+ h_path.dentry = h_parent;
-+ h_path.mnt = br->br_mnt;
++ h_path.mnt = au_br_mnt(br);
+ au_dtime_store(&dt, parent, &h_path);
-+ err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len);
++ err = au_do_cpup_wh(cpg, wh_dentry, file);
+ if (unlikely(err))
+ goto out_wh;
+
+ dget(wh_dentry);
+ h_path.dentry = wh_dentry;
-+ if (!S_ISDIR(wh_dentry->d_inode->i_mode))
-+ err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
-+ else
++ if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
++ /* no delegation since it is just created */
++ err = vfsub_unlink(h_parent->d_inode, &h_path,
++ /*delegated*/NULL, /*force*/0);
++ } else
+ err = vfsub_rmdir(h_parent->d_inode, &h_path);
+ if (unlikely(err)) {
-+ AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
-+ AuDLNPair(wh_dentry), err);
++ AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
++ wh_dentry, err);
+ err = -EIO;
+ }
+ au_dtime_revert(&dt);
+
+struct au_cpup_wh_args {
+ int *errp;
-+ struct dentry *dentry;
-+ aufs_bindex_t bdst;
-+ loff_t len;
++ struct au_cp_generic *cpg;
+ struct file *file;
+};
+
+static void au_call_cpup_wh(void *args)
+{
+ struct au_cpup_wh_args *a = args;
-+ *a->errp = au_cpup_wh(a->dentry, a->bdst, a->len, a->file);
++
++ au_pin_hdir_acquire_nest(a->cpg->pin);
++ *a->errp = au_cpup_wh(a->cpg, a->file);
++ au_pin_hdir_release(a->cpg->pin);
+}
+
-+int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+ struct file *file)
++int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
+{
+ int err, wkq_err;
-+ struct dentry *parent, *h_orph, *h_parent, *h_dentry;
-+ struct inode *dir, *h_dir, *h_tmpdir, *h_inode;
++ aufs_bindex_t bdst;
++ struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
++ struct inode *dir, *h_dir, *h_tmpdir;
+ struct au_wbr *wbr;
++ struct au_pin wh_pin, *pin_orig;
+
++ dentry = cpg->dentry;
++ bdst = cpg->bdst;
+ parent = dget_parent(dentry);
+ dir = parent->d_inode;
+ h_orph = NULL;
+ h_parent = NULL;
+ h_dir = au_igrab(au_h_iptr(dir, bdst));
+ h_tmpdir = h_dir;
++ pin_orig = NULL;
+ if (!h_dir->i_nlink) {
+ wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
+ h_orph = wbr->wbr_orph;
+ h_tmpdir = h_orph->d_inode;
+ au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
+
-+ /* this temporary unlock is safe */
+ if (file)
+ h_dentry = au_hf_top(file)->f_dentry;
+ else
+ h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
-+ h_inode = h_dentry->d_inode;
-+ IMustLock(h_inode);
-+ mutex_unlock(&h_inode->i_mutex);
+ mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
-+ mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
+ /* todo: au_h_open_pre()? */
++
++ pin_orig = cpg->pin;
++ au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
++ AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
++ cpg->pin = &wh_pin;
+ }
+
+ if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
-+ && !au_cpup_sio_test(dentry->d_sb, dentry->d_inode->i_mode))
-+ err = au_cpup_wh(dentry, bdst, len, file);
++ && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
++ err = au_cpup_wh(cpg, file);
+ else {
+ struct au_cpup_wh_args args = {
+ .errp = &err,
-+ .dentry = dentry,
-+ .bdst = bdst,
-+ .len = len,
++ .cpg = cpg,
+ .file = file
+ };
+ wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
+ /* todo: au_h_open_post()? */
+ au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
+ au_set_h_dptr(parent, bdst, h_parent);
++ AuDebugOn(!pin_orig);
++ cpg->pin = pin_orig;
+ }
+ iput(h_dir);
+ dput(parent);
+/* cf. revalidate function in file.c */
+int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
+ int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
++ struct au_pin *pin,
+ struct dentry *h_parent, void *arg),
+ void *arg)
+{
+ au_pin_set_dentry(&pin, d);
+ err = au_do_pin(&pin);
+ if (!err) {
-+ err = cp(d, bdst, h_parent, arg);
++ err = cp(d, bdst, &pin, h_parent, arg);
+ au_unpin(&pin);
+ }
+ }
+}
+
+static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
++ struct au_pin *pin,
+ struct dentry *h_parent __maybe_unused ,
+ void *arg __maybe_unused)
+{
-+ return au_sio_cpup_simple(dentry, bdst, -1, AuCpup_DTIME);
++ struct au_cp_generic cpg = {
++ .dentry = dentry,
++ .bdst = bdst,
++ .bsrc = -1,
++ .len = 0,
++ .pin = pin,
++ .flags = AuCpup_DTIME
++ };
++ return au_sio_cpup_simple(&cpg);
+}
+
+int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,83 @@
++++ linux/fs/aufs/cpup.h 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,94 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#ifdef __KERNEL__
+
+#include <linux/path.h>
-+#include <linux/time.h>
-+#include <linux/aufs_type.h>
+
+struct inode;
+struct file;
++struct au_pin;
+
-+void au_cpup_attr_flags(struct inode *dst, struct inode *src);
++void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
+void au_cpup_attr_timesizes(struct inode *inode);
+void au_cpup_attr_nlink(struct inode *inode, int force);
+void au_cpup_attr_changeable(struct inode *inode);
+
+/* ---------------------------------------------------------------------- */
+
++struct au_cp_generic {
++ struct dentry *dentry;
++ aufs_bindex_t bdst, bsrc;
++ loff_t len;
++ struct au_pin *pin;
++ unsigned int flags;
++};
++
+/* cpup flags */
-+#define AuCpup_DTIME 1 /* do dtime_store/revert */
-+#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
-+ for link(2) */
++#define AuCpup_DTIME 1 /* do dtime_store/revert */
++#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
++ for link(2) */
++#define AuCpup_RENAME (1 << 2) /* rename after cpup */
++#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
++ cpup */
++#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
++ existing entry */
++#define AuCpup_RWDST (1 << 5) /* force write target even if
++ the branch is marked as RO */
++
+#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
+#define au_fset_cpup(flags, name) \
+ do { (flags) |= AuCpup_##name; } while (0)
+ do { (flags) &= ~AuCpup_##name; } while (0)
+
+int au_copy_file(struct file *dst, struct file *src, loff_t len);
-+int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
-+ aufs_bindex_t bsrc, loff_t len, unsigned int flags,
-+ struct dentry *dst_parent);
-+int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+ unsigned int flags);
-+int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
-+ struct file *file);
++int au_sio_cpup_simple(struct au_cp_generic *cpg);
++int au_sio_cpdown_simple(struct au_cp_generic *cpg);
++int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
+
+int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
+ int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
++ struct au_pin *pin,
+ struct dentry *h_parent, void *arg),
+ void *arg);
+int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,334 @@
++++ linux/fs/aufs/dbgaufs.c 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,432 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ if (!xf)
+ goto out;
+
-+ err = vfs_getattr(xf->f_vfsmnt, xf->f_dentry, &st);
++ err = vfs_getattr(&xf->f_path, &st);
+ if (!err) {
+ if (do_fcnt)
+ p->n = snprintf
+
+/* ---------------------------------------------------------------------- */
+
++struct dbgaufs_plink_arg {
++ int n;
++ char a[];
++};
++
++static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
++ struct file *file)
++{
++ free_page((unsigned long)file->private_data);
++ return 0;
++}
++
++static int dbgaufs_plink_open(struct inode *inode, struct file *file)
++{
++ int err, i, limit;
++ unsigned long n, sum;
++ struct dbgaufs_plink_arg *p;
++ struct au_sbinfo *sbinfo;
++ struct super_block *sb;
++ struct au_sphlhead *sphl;
++
++ err = -ENOMEM;
++ p = (void *)get_zeroed_page(GFP_NOFS);
++ if (unlikely(!p))
++ goto out;
++
++ err = -EFBIG;
++ sbinfo = inode->i_private;
++ sb = sbinfo->si_sb;
++ si_noflush_read_lock(sb);
++ if (au_opt_test(au_mntflags(sb), PLINK)) {
++ limit = PAGE_SIZE - sizeof(p->n);
++
++ /* the number of buckets */
++ n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
++ p->n += n;
++ limit -= n;
++
++ sum = 0;
++ for (i = 0, sphl = sbinfo->si_plink;
++ i < AuPlink_NHASH;
++ i++, sphl++) {
++ n = au_sphl_count(sphl);
++ sum += n;
++
++ n = snprintf(p->a + p->n, limit, "%lu ", n);
++ p->n += n;
++ limit -= n;
++ if (unlikely(limit <= 0))
++ goto out_free;
++ }
++ p->a[p->n - 1] = '\n';
++
++ /* the sum of plinks */
++ n = snprintf(p->a + p->n, limit, "%lu\n", sum);
++ p->n += n;
++ limit -= n;
++ if (unlikely(limit <= 0))
++ goto out_free;
++ } else {
++#define str "1\n0\n0\n"
++ p->n = sizeof(str) - 1;
++ strcpy(p->a, str);
++#undef str
++ }
++ si_read_unlock(sb);
++
++ err = 0;
++ file->private_data = p;
++ goto out; /* success */
++
++out_free:
++ free_page((unsigned long)p);
++out:
++ return err;
++}
++
++static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
++ size_t count, loff_t *ppos)
++{
++ struct dbgaufs_plink_arg *p;
++
++ p = file->private_data;
++ return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
++}
++
++static const struct file_operations dbgaufs_plink_fop = {
++ .owner = THIS_MODULE,
++ .open = dbgaufs_plink_open,
++ .release = dbgaufs_plink_release,
++ .read = dbgaufs_plink_read
++};
++
++/* ---------------------------------------------------------------------- */
++
+static int dbgaufs_xib_open(struct inode *inode, struct file *file)
+{
+ int err;
+ || memcmp(name->name, DbgaufsXi_PREFIX,
+ sizeof(DbgaufsXi_PREFIX) - 1)))
+ goto out;
-+ err = strict_strtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
++ err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
+ if (unlikely(err))
+ goto out;
+
+ for (; bindex <= bend; bindex++) {
+ br = au_sbr(sb, bindex);
+ xi = &br->br_xino;
-+ if (xi->xi_dbgaufs) {
-+ debugfs_remove(xi->xi_dbgaufs);
-+ xi->xi_dbgaufs = NULL;
-+ }
++ debugfs_remove(xi->xi_dbgaufs);
++ xi->xi_dbgaufs = NULL;
+ }
+}
+
+ if (unlikely(!sbinfo->si_dbgaufs_xib))
+ goto out_dir;
+
++ sbinfo->si_dbgaufs_plink = debugfs_create_file
++ ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
++ &dbgaufs_plink_fop);
++ if (unlikely(!sbinfo->si_dbgaufs_plink))
++ goto out_dir;
++
+ err = dbgaufs_xigen_init(sbinfo);
+ if (!err)
+ goto out; /* success */
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,52 @@
++++ linux/fs/aufs/dbgaufs.h 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,48 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/init.h>
-+#include <linux/aufs_type.h>
-+
+struct super_block;
+struct au_sbinfo;
+
+#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 2011-08-24 13:30:24.731313534 +0200
++++ linux/fs/aufs/dcsub.c 2014-01-30 21:10:02.827480967 +0100
@@ -0,0 +1,243 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ dpages->ndpage++;
+ }
+
-+ AuDebugOn(!dentry->d_count);
++ AuDebugOn(!d_count(dentry));
+ dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
+ return 0; /* success */
+
+ return err;
+}
+
++/* try d_walk() in linux/fs/dcache.c */
+int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
+ au_dpages_test test, void *arg)
+{
+ if (this_parent->d_sb == sb
+ && !IS_ROOT(this_parent)
+ && au_di(this_parent)
-+ && this_parent->d_count
++ && d_count(this_parent)
+ && (!test || test(this_parent, arg))) {
+ err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
+ if (unlikely(err))
+
+ next = tmp->next;
+ spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
-+ if (dentry->d_count) {
++ if (d_count(dentry)) {
+ if (!list_empty(&dentry->d_subdirs)) {
+ spin_unlock(&this_parent->d_lock);
+ spin_release(&dentry->d_lock.dep_map, 1,
+ write_seqlock(&rename_lock);
+ spin_lock(&dentry->d_lock);
+ if (do_include
-+ && dentry->d_count
++ && d_count(dentry)
+ && (!test || test(dentry, arg)))
+ err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
+ spin_unlock(&dentry->d_lock);
+ goto out;
+
+ /*
-+ * vfsmount_lock is unnecessary since this is a traverse in a single
++ * RCU for vfsmount is unnecessary since this is a traverse in a single
+ * mount
+ */
+ while (!IS_ROOT(dentry)) {
+ dentry = dentry->d_parent; /* rename_lock is locked */
+ spin_lock(&dentry->d_lock);
-+ if (dentry->d_count
++ if (d_count(dentry)
+ && (!test || test(dentry, arg)))
+ err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
+ spin_unlock(&dentry->d_lock);
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,95 @@
++++ linux/fs/aufs/dcsub.h 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,98 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#include <linux/dcache.h>
+#include <linux/fs.h>
-+#include <linux/types.h>
+
+struct dentry;
+
+
+/* ---------------------------------------------------------------------- */
+
++/*
++ * todo: in linux-3.13, several similar (but faster) helpers are added to
++ * include/linux/dcache.h. Try them (in the future).
++ */
++
+static inline int au_d_hashed_positive(struct dentry *d)
+{
+ int err;
+#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 2011-10-24 20:51:51.580466925 +0200
-@@ -0,0 +1,490 @@
++++ linux/fs/aufs/debug.c 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,517 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * debug print functions
+ */
+
-+#include <linux/module.h>
+#include <linux/vt_kern.h>
+#include "aufs.h"
+
-+int aufs_debug;
++/* Returns 0, or -errno. arg is in kp->arg. */
++static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
++{
++ int err, n;
++
++ err = kstrtoint(val, 0, &n);
++ if (!err) {
++ if (n > 0)
++ au_debug_on();
++ else
++ au_debug_off();
++ }
++ return err;
++}
++
++/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
++static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
++{
++ atomic_t *a;
++
++ a = kp->arg;
++ return sprintf(buffer, "%d", atomic_read(a));
++}
++
++static struct kernel_param_ops param_ops_atomic_t = {
++ .set = param_atomic_t_set,
++ .get = param_atomic_t_get
++ /* void (*free)(void *arg) */
++};
++
++atomic_t aufs_debug = ATOMIC_INIT(0);
+MODULE_PARM_DESC(debug, "debug print");
-+module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
++module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
+
+char *au_plevel = KERN_DEBUG;
+#define dpri(fmt, ...) do { \
+{
+ unsigned long ul, n;
+ struct hlist_head *head;
-+ struct au_vdir_wh *tpos;
-+ struct hlist_node *pos;
++ struct au_vdir_wh *pos;
+
+ n = whlist->nh_num;
+ head = whlist->nh_head;
+ for (ul = 0; ul < n; ul++) {
-+ hlist_for_each_entry(tpos, pos, head, wh_hash)
++ hlist_for_each_entry(pos, head, wh_hash)
+ dpri("b%d, %.*s, %d\n",
-+ tpos->wh_bindex,
-+ tpos->wh_str.len, tpos->wh_str.name,
-+ tpos->wh_str.len);
++ pos->wh_bindex,
++ pos->wh_str.len, pos->wh_str.name,
++ pos->wh_str.len);
+ head++;
+ }
+}
+ return -1;
+ }
+
-+ /* the type of i_blocks depends upon CONFIG_LSF */
++ /* the type of i_blocks depends upon CONFIG_LBDAF */
+ BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
+ && sizeof(inode->i_blocks) != sizeof(u64));
+ if (wh) {
+ if (!iinfo)
+ return;
+ dpri("i-1: bstart %d, bend %d, gen %d\n",
-+ iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode));
++ iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
+ if (iinfo->ii_bstart < 0)
+ return;
+ hn = 0;
+ struct dentry *d;
+
+ spin_lock(&inode->i_lock);
-+ list_for_each_entry(d, &inode->i_dentry, d_alias)
++ hlist_for_each_entry(d, &inode->i_dentry, d_alias)
+ au_dpri_dentry(d);
+ spin_unlock(&inode->i_lock);
+}
+ }
+ /* do not call dget_parent() here */
+ /* note: access d_xxx without d_lock */
-+ dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
-+ bindex,
-+ AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
++ dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
++ bindex, dentry, dentry,
+ dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
-+ dentry->d_count, dentry->d_flags);
++ d_count(dentry), dentry->d_flags,
++ d_unhashed(dentry) ? "un" : "");
+ hn = -1;
+ if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
+ struct au_iinfo *iinfo = au_ii(dentry->d_inode);
+
+ if (!br || IS_ERR(br))
+ goto out;
-+ mnt = br->br_mnt;
++ mnt = au_br_mnt(br);
+ if (!mnt || IS_ERR(mnt))
+ goto out;
+ sb = mnt->mnt_sb;
+
+ a->mnt.mnt_sb = sb;
+ a->fake.br_perm = 0;
-+ a->fake.br_mnt = &a->mnt;
++ a->fake.br_path.mnt = &a->mnt;
+ a->fake.br_xino.xi_file = NULL;
+ atomic_set(&a->fake.br_count, 0);
+ smp_mb(); /* atomic_set */
+
+void au_dbg_iattr(struct iattr *ia)
+{
-+#define AuBit(name) if (ia->ia_valid & ATTR_ ## name) \
-+ dpri(#name "\n")
++#define AuBit(name) \
++ do { \
++ if (ia->ia_valid & ATTR_ ## name) \
++ dpri(#name "\n"); \
++ } while (0)
+ AuBit(MODE);
+ AuBit(UID);
+ AuBit(GID);
+ continue;
+ h_inode = au_h_iptr(inode, bindex);
+ if (unlikely(h_inode != h_dentry->d_inode)) {
-+ int old = au_debug_test();
-+ if (!old)
-+ au_debug(1);
++ au_debug_on();
+ AuDbg("b%d, %s:%d\n", bindex, func, line);
+ AuDbgDentry(dentry);
+ AuDbgInode(inode);
-+ if (!old)
-+ au_debug(0);
++ au_debug_off();
+ BUG();
+ }
+ }
+ AuDebugOn(destr.len < NAME_MAX);
+
+#ifdef CONFIG_4KSTACKS
-+ pr_warning("CONFIG_4KSTACKS is defined.\n");
++ pr_warn("CONFIG_4KSTACKS is defined.\n");
+#endif
+
+#ifdef AuForceNoBrs
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,252 @@
++++ linux/fs/aufs/debug.h 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,247 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <asm/system.h>
-+#include <linux/bug.h>
-+/* #include <linux/err.h> */
-+#include <linux/init.h>
++#include <linux/atomic.h>
+#include <linux/module.h>
+#include <linux/kallsyms.h>
-+/* #include <linux/kernel.h> */
-+#include <linux/delay.h>
-+/* #include <linux/kd.h> */
+#include <linux/sysrq.h>
-+#include <linux/aufs_type.h>
-+
-+#include <asm/system.h>
+
+#ifdef CONFIG_AUFS_DEBUG
+#define AuDebugOn(a) BUG_ON(a)
+
+/* module parameter */
-+extern int aufs_debug;
-+static inline void au_debug(int n)
++extern atomic_t aufs_debug;
++static inline void au_debug_on(void)
++{
++ atomic_inc(&aufs_debug);
++}
++static inline void au_debug_off(void)
+{
-+ aufs_debug = n;
-+ smp_mb();
++ atomic_dec_if_positive(&aufs_debug);
+}
+
+static inline int au_debug_test(void)
+{
-+ return aufs_debug;
++ return atomic_read(&aufs_debug) > 0;
+}
+#else
+#define AuDebugOn(a) do {} while (0)
-+AuStubVoid(au_debug, int n)
++AuStubVoid(au_debug_on, void)
++AuStubVoid(au_debug_off, void)
+AuStubInt0(au_debug_test, void)
+#endif /* CONFIG_AUFS_DEBUG */
+
++#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
++
+/* ---------------------------------------------------------------------- */
+
+/* debug print */
+#define AuWarn1(fmt, ...) do { \
+ static unsigned char _c; \
+ if (!_c++) \
-+ pr_warning(fmt, ##__VA_ARGS__); \
++ pr_warn(fmt, ##__VA_ARGS__); \
+} while (0)
+
+#define AuErr1(fmt, ...) do { \
+
+/* dirty macros for debug print, use with "%.*s" and caution */
+#define AuLNPair(qstr) (qstr)->len, (qstr)->name
-+#define AuDLNPair(d) AuLNPair(&(d)->d_name)
+
+/* ---------------------------------------------------------------------- */
+
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,1140 @@
++++ linux/fs/aufs/dentry.c 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,1081 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#include <linux/namei.h>
+#include "aufs.h"
+
-+static void au_h_nd(struct nameidata *h_nd, struct nameidata *nd)
-+{
-+ if (nd) {
-+ *h_nd = *nd;
-+
-+ /*
-+ * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
-+ * due to whiteout and branch permission.
-+ */
-+ h_nd->flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
-+ | LOOKUP_FOLLOW | LOOKUP_EXCL);
-+ /* unnecessary? */
-+ h_nd->intent.open.file = NULL;
-+ } else
-+ memset(h_nd, 0, sizeof(*h_nd));
-+}
-+
-+struct au_lkup_one_args {
-+ struct dentry **errp;
-+ struct qstr *name;
-+ struct dentry *h_parent;
-+ struct au_branch *br;
-+ struct nameidata *nd;
-+};
-+
-+struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
-+ struct au_branch *br, struct nameidata *nd)
-+{
-+ struct dentry *h_dentry;
-+ int err;
-+ struct nameidata h_nd;
-+
-+ if (au_test_fs_null_nd(h_parent->d_sb))
-+ return vfsub_lookup_one_len(name->name, h_parent, name->len);
-+
-+ au_h_nd(&h_nd, nd);
-+ h_nd.path.dentry = h_parent;
-+ h_nd.path.mnt = br->br_mnt;
-+
-+ err = vfsub_name_hash(name->name, &h_nd.last, name->len);
-+ h_dentry = ERR_PTR(err);
-+ if (!err) {
-+ path_get(&h_nd.path);
-+ h_dentry = vfsub_lookup_hash(&h_nd);
-+ path_put(&h_nd.path);
-+ }
-+
-+ AuTraceErrPtr(h_dentry);
-+ return h_dentry;
-+}
-+
-+static void au_call_lkup_one(void *args)
-+{
-+ struct au_lkup_one_args *a = args;
-+ *a->errp = au_lkup_one(a->name, a->h_parent, a->br, a->nd);
-+}
-+
+#define AuLkup_ALLOW_NEG 1
+#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
+#define au_fset_lkup(flags, name) \
+struct au_do_lookup_args {
+ unsigned int flags;
+ mode_t type;
-+ struct nameidata *nd;
+};
+
+/*
+ return NULL; /* success */
+
+real_lookup:
-+ h_dentry = au_lkup_one(&dentry->d_name, h_parent, br, args->nd);
++ h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
+ if (IS_ERR(h_dentry))
+ goto out;
+
+ * otherwise an error.
+ * can be called at unlinking with @type is zero.
+ */
-+int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
-+ struct nameidata *nd)
++int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
+{
+ int npositive, err;
+ aufs_bindex_t bindex, btail, bdiropq;
+ unsigned char isdir;
+ struct qstr whname;
+ struct au_do_lookup_args args = {
-+ .flags = 0,
-+ .type = type,
-+ .nd = nd
++ .flags = 0,
++ .type = type
+ };
+ const struct qstr *name = &dentry->d_name;
+ struct dentry *parent;
+ if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
+ && au_dbstart(dentry) < 0)) {
+ err = -EIO;
-+ AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
-+ AuDLNPair(dentry), err);
++ AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
++ dentry, err);
+ }
+
+out_parent:
+ int wkq_err;
+
+ if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
-+ dentry = au_lkup_one(name, parent, br, /*nd*/NULL);
++ dentry = vfsub_lkup_one(name, parent);
+ else {
-+ struct au_lkup_one_args args = {
-+ .errp = &dentry,
-+ .name = name,
-+ .h_parent = parent,
-+ .br = br,
-+ .nd = NULL
++ struct vfsub_lkup_one_args args = {
++ .errp = &dentry,
++ .name = name,
++ .parent = parent
+ };
+
-+ wkq_err = au_wkq_wait(au_call_lkup_one, &args);
++ wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
+ if (unlikely(wkq_err))
+ dentry = ERR_PTR(wkq_err);
+ }
+/*
+ * lookup @dentry on @bindex which should be negative.
+ */
-+int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
++int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
+{
+ int err;
+ struct dentry *parent, *h_parent, *h_dentry;
++ struct au_branch *br;
+
+ parent = dget_parent(dentry);
+ h_parent = au_h_dptr(parent, bindex);
-+ h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent,
-+ au_sbr(dentry->d_sb, bindex));
++ br = au_sbr(dentry->d_sb, bindex);
++ if (wh)
++ h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
++ else
++ h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
+ err = PTR_ERR(h_dentry);
+ if (IS_ERR(h_dentry))
+ goto out;
+ if (unlikely(h_dentry->d_inode)) {
+ err = -EIO;
-+ AuIOErr("%.*s should be negative on b%d.\n",
-+ AuDLNPair(h_dentry), bindex);
++ AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
+ dput(h_dentry);
+ goto out;
+ }
+struct au_iattr {
+ unsigned long i_ino;
+ /* unsigned int i_nlink; */
-+ uid_t i_uid;
-+ gid_t i_gid;
++ kuid_t i_uid;
++ kgid_t i_gid;
+ u64 i_version;
+/*
+ loff_t i_size;
+{
+ return ia->i_ino != h_inode->i_ino
+ /* || ia->i_nlink != h_inode->i_nlink */
-+ || ia->i_uid != h_inode->i_uid
-+ || ia->i_gid != h_inode->i_gid
++ || !uid_eq(ia->i_uid, h_inode->i_uid)
++ || !gid_eq(ia->i_gid, h_inode->i_gid)
+ || ia->i_version != h_inode->i_version
+/*
+ || ia->i_size != h_inode->i_size
+ goto out;
+
+ /* main purpose is namei.c:cached_lookup() and d_revalidate */
-+ h_d = au_lkup_one(&h_dentry->d_name, h_parent, br, /*nd*/NULL);
++ h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
+ err = PTR_ERR(h_d);
+ if (IS_ERR(h_d))
+ goto out;
+ /* shrink_dcache_parent(dentry); */
+ err = au_hide_children(dentry);
+ if (unlikely(err))
-+ AuIOErr("%.*s, failed hiding children, ignored %d\n",
-+ AuDLNPair(dentry), err);
++ AuIOErr("%pd, failed hiding children, ignored %d\n",
++ dentry, err);
+ }
+ au_do_hide(dentry);
+}
+ * if current working dir is removed, it returns an error.
+ * but the dentry is legal.
+ */
-+ err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0, /*nd*/NULL);
++ err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
+ AuDbgDentry(dentry);
+ au_di_swap(tmp, dinfo);
+ if (err == -ENOENT)
+ au_update_digen(dentry);
+out:
+ if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
-+ AuIOErr("failed refreshing %.*s, %d\n",
-+ AuDLNPair(dentry), err);
++ AuIOErr("failed refreshing %pd, %d\n", dentry, err);
+ AuDbgDentry(dentry);
+ }
+ AuTraceErr(err);
+ return err;
+}
+
-+static noinline_for_stack
-+int au_do_h_d_reval(struct dentry *h_dentry, struct nameidata *nd,
-+ struct dentry *dentry, aufs_bindex_t bindex)
++static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
++ struct dentry *dentry, aufs_bindex_t bindex)
+{
+ int err, valid;
-+ int (*reval)(struct dentry *, struct nameidata *);
+
+ err = 0;
+ if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
+ goto out;
-+ reval = h_dentry->d_op->d_revalidate;
+
+ AuDbg("b%d\n", bindex);
-+ if (au_test_fs_null_nd(h_dentry->d_sb))
-+ /* it may return tri-state */
-+ valid = reval(h_dentry, NULL);
-+ else {
-+ struct nameidata h_nd;
-+ int locked;
-+ struct dentry *parent;
-+
-+ au_h_nd(&h_nd, nd);
-+ parent = nd->path.dentry;
-+ locked = (nd && nd->path.dentry != dentry);
-+ if (locked)
-+ di_read_lock_parent(parent, AuLock_IR);
-+ BUG_ON(bindex > au_dbend(parent));
-+ h_nd.path.dentry = au_h_dptr(parent, bindex);
-+ BUG_ON(!h_nd.path.dentry);
-+ h_nd.path.mnt = au_sbr(parent->d_sb, bindex)->br_mnt;
-+ path_get(&h_nd.path);
-+ valid = reval(h_dentry, &h_nd);
-+ path_put(&h_nd.path);
-+ if (locked)
-+ di_read_unlock(parent, AuLock_IR);
-+ }
++ /*
++ * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
++ * due to whiteout and branch permission.
++ */
++ flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
++ | LOOKUP_FOLLOW | LOOKUP_EXCL);
++ /* it may return tri-state */
++ valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
+
+ if (unlikely(valid < 0))
+ err = valid;
+
+/* todo: remove this */
+static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
-+ struct nameidata *nd, int do_udba)
++ unsigned int flags, int do_udba)
+{
+ int err;
+ umode_t mode, h_mode;
+ aufs_bindex_t bindex, btail, bstart, ibs, ibe;
-+ unsigned char plus, unhashed, is_root, h_plus;
++ unsigned char plus, unhashed, is_root, h_plus, h_nfs;
+ struct inode *h_inode, *h_cached_inode;
+ struct dentry *h_dentry;
+ struct qstr *name, *h_name;
+ if (!h_dentry)
+ continue;
+
-+ AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
++ AuDbg("b%d, %pd\n", bindex, h_dentry);
++ h_nfs = !!au_test_nfs(h_dentry->d_sb);
+ spin_lock(&h_dentry->d_lock);
+ h_name = &h_dentry->d_name;
+ if (unlikely(do_udba
+ && !is_root
-+ && (unhashed != !!d_unhashed(h_dentry)
-+ || name->len != h_name->len
-+ || memcmp(name->name, h_name->name, name->len))
++ && ((!h_nfs
++ && (unhashed != !!d_unhashed(h_dentry)
++ || name->len != h_name->len
++ || memcmp(name->name, h_name->name,
++ name->len)))
++ || (h_nfs
++ && !(flags & LOOKUP_OPEN)
++ && (h_dentry->d_flags
++ & DCACHE_NFSFS_RENAMED)))
+ )) {
-+ AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
-+ unhashed, d_unhashed(h_dentry),
-+ AuDLNPair(dentry), AuDLNPair(h_dentry));
++ AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
++ unhashed, d_unhashed(h_dentry),
++ dentry, h_dentry);
+ spin_unlock(&h_dentry->d_lock);
+ goto err;
+ }
+ spin_unlock(&h_dentry->d_lock);
+
-+ err = au_do_h_d_reval(h_dentry, nd, dentry, bindex);
++ err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
+ if (unlikely(err))
+ /* do not goto err, to keep the errno */
+ break;
+ if (inode && ibs <= bindex && bindex <= ibe)
+ h_cached_inode = au_h_iptr(inode, bindex);
+
-+ if (unlikely(plus != h_plus
-+ || mode != h_mode
++ if (!h_nfs) {
++ if (unlikely(plus != h_plus))
++ goto err;
++ } else {
++ if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
++ && !is_root
++ && !IS_ROOT(h_dentry)
++ && unhashed != d_unhashed(h_dentry)))
++ goto err;
++ }
++ if (unlikely(mode != h_mode
+ || h_cached_inode != h_inode))
+ goto err;
+ continue;
+
-+ err:
++err:
+ err = -EINVAL;
+ break;
+ }
+
++ AuTraceErr(err);
+ return err;
+}
+
+/*
+ * if valid returns 1, otherwise 0.
+ */
-+static int aufs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
++static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
+{
+ int valid, err;
+ unsigned int sigen;
+ struct inode *inode;
+
+ /* todo: support rcu-walk? */
-+ if (nd && (nd->flags & LOOKUP_RCU))
++ if (flags & LOOKUP_RCU)
+ return -ECHILD;
+
+ valid = 0;
+ di_downgrade_lock(dentry, AuLock_IR);
+
+ err = -EINVAL;
-+ if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
++ if (!(flags & LOOKUP_OPEN)
++ && inode
++ && (IS_DEADDIR(inode) || !inode->i_nlink))
+ goto out_inval;
+
+ do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
+ }
+ }
+
-+ err = h_d_revalidate(dentry, inode, nd, do_udba);
++ err = h_d_revalidate(dentry, inode, flags, do_udba);
+ if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
+ err = -EIO;
-+ AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
-+ AuDLNPair(dentry), err);
++ AuDbg("both of real entry and whiteout found, %p, err %d\n",
++ dentry, err);
+ }
+ goto out_inval;
+
+ valid = !err;
+out:
+ if (!valid) {
-+ AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
++ AuDbg("%pd invalid, %d\n", dentry, valid);
+ d_drop(dentry);
+ }
+ return valid;
+}
+
+const struct dentry_operations aufs_dop = {
-+ .d_revalidate = aufs_d_revalidate,
-+ .d_release = aufs_d_release
++ .d_revalidate = aufs_d_revalidate,
++ .d_weak_revalidate = aufs_d_revalidate,
++ .d_release = aufs_d_release
+};
diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
--- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/dentry.h 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,238 @@
++++ linux/fs/aufs/dentry.h 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,233 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#ifdef __KERNEL__
+
+#include <linux/dcache.h>
-+#include <linux/aufs_type.h>
+#include "rwsem.h"
+
+struct au_hdentry {
+/* dentry.c */
+extern const struct dentry_operations aufs_dop;
+struct au_branch;
-+struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
-+ struct au_branch *br, struct nameidata *nd);
+struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
+ struct au_branch *br);
+int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
+ struct dentry *h_parent, struct au_branch *br);
+
-+int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
-+ struct nameidata *nd);
-+int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex);
++int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
++int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
+int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
+int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
+
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,543 @@
++++ linux/fs/aufs/dinfo.c 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,542 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ return NULL;
+ AuDebugOn(bindex < 0);
+ d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
-+ AuDebugOn(d && d->d_count <= 0);
++ AuDebugOn(d && d_count(d) <= 0);
+ return d;
+}
+
+}
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 2011-10-24 20:52:23.677857076 +0200
-@@ -0,0 +1,627 @@
++++ linux/fs/aufs/dir.c 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,639 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * directory operations
+ */
+
-+#include <linux/file.h>
+#include <linux/fs_stack.h>
+#include "aufs.h"
+
+void au_add_nlink(struct inode *dir, struct inode *h_dir)
+{
++ unsigned int nlink;
++
+ AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
+
-+ dir->i_nlink += h_dir->i_nlink - 2;
++ nlink = dir->i_nlink;
++ nlink += h_dir->i_nlink - 2;
+ if (h_dir->i_nlink < 2)
-+ dir->i_nlink += 2;
++ nlink += 2;
++ smp_mb(); /* for i_nlink */
++ /* 0 can happen in revaliding */
++ set_nlink(dir, nlink);
+}
+
+void au_sub_nlink(struct inode *dir, struct inode *h_dir)
+{
++ unsigned int nlink;
++
+ AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
+
-+ dir->i_nlink -= h_dir->i_nlink - 2;
++ nlink = dir->i_nlink;
++ nlink -= h_dir->i_nlink - 2;
+ if (h_dir->i_nlink < 2)
-+ dir->i_nlink -= 2;
++ nlink -= 2;
++ smp_mb(); /* for i_nlink */
++ /* nlink == 0 means the branch-fs is broken */
++ set_nlink(dir, nlink);
+}
+
+loff_t au_dir_size(struct file *file, struct dentry *dentry)
+
+ sz = 0;
+ if (file) {
-+ AuDebugOn(!file->f_dentry);
-+ AuDebugOn(!file->f_dentry->d_inode);
-+ AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode));
++ AuDebugOn(!file_inode(file));
++ AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
+
+ bend = au_fbend_dir(file);
+ for (bindex = au_fbstart(file);
+ bindex <= bend && sz < KMALLOC_MAX_SIZE;
+ bindex++) {
+ h_file = au_hf_dir(file, bindex);
-+ if (h_file
-+ && h_file->f_dentry
-+ && h_file->f_dentry->d_inode)
-+ sz += i_size_read(h_file->f_dentry->d_inode);
++ if (h_file && file_inode(h_file))
++ sz += vfsub_f_size_read(h_file);
+ }
+ } else {
+ AuDebugOn(!dentry);
+ if (h_file)
+ continue;
+
-+ h_file = au_h_open(dentry, bindex, flags, file);
++ h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
+ err = PTR_ERR(h_file);
+ if (IS_ERR(h_file))
+ goto out; /* close all? */
+
+ FiMustWriteLock(file);
+
++ err = 0;
+ dentry = file->f_dentry;
-+ err = au_alive_dir(dentry);
-+ if (unlikely(err))
-+ goto out;
-+
+ file->f_version = dentry->d_inode->i_version;
+ bindex = au_dbstart(dentry);
+ au_set_fbstart(file, bindex);
+ if (!h_dentry)
+ continue;
+
-+ h_file = au_h_open(dentry, bindex, flags, file);
++ h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
+ if (IS_ERR(h_file)) {
+ err = PTR_ERR(h_file);
+ break;
+ au_set_fbstart(file, -1);
+ au_set_fbend_dir(file, -1);
+
-+out:
+ return err;
+}
+
+ finfo = au_fi(file);
+ fidir = finfo->fi_hdir;
+ if (fidir) {
-+ /* remove me from sb->s_files */
-+ file_sb_list_del(file);
-+
+ vdir_cache = fidir->fd_vdir_cache; /* lock-free */
+ if (vdir_cache)
+ au_vdir_free(vdir_cache);
+ goto out;
+
+ sb = file->f_dentry->d_sb;
-+ inode = file->f_dentry->d_inode;
++ inode = file_inode(file);
+ bend = au_fbend_dir(file);
+ for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
+ h_file = au_hf_dir(file, bindex);
+
+/* ---------------------------------------------------------------------- */
+
-+static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
++static int aufs_iterate(struct file *file, struct dir_context *ctx)
+{
+ int err;
+ struct dentry *dentry;
-+ struct inode *inode;
++ struct inode *inode, *h_inode;
+ struct super_block *sb;
+
++ AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
++
+ dentry = file->f_dentry;
+ inode = dentry->d_inode;
+ IMustLock(inode);
+ if (unlikely(err))
+ goto out_unlock;
+
++ h_inode = au_h_iptr(inode, au_ibstart(inode));
+ if (!au_test_nfsd()) {
-+ err = au_vdir_fill_de(file, dirent, filldir);
-+ fsstack_copy_attr_atime(inode,
-+ au_h_iptr(inode, au_ibstart(inode)));
++ err = au_vdir_fill_de(file, ctx);
++ fsstack_copy_attr_atime(inode, h_inode);
+ } else {
+ /*
+ * nfsd filldir may call lookup_one_len(), vfs_getattr(),
+ * encode_fh() and others.
+ */
-+ struct inode *h_inode = au_h_iptr(inode, au_ibstart(inode));
-+
++ atomic_inc(&h_inode->i_count);
+ di_read_unlock(dentry, AuLock_IR);
+ si_read_unlock(sb);
-+ err = au_vdir_fill_de(file, dirent, filldir);
++ err = au_vdir_fill_de(file, ctx);
+ fsstack_copy_attr_atime(inode, h_inode);
+ fi_write_unlock(file);
++ iput(h_inode);
+
+ AuTraceErr(err);
+ return err;
+#endif
+
+struct test_empty_arg {
++ struct dir_context ctx;
+ struct au_nhash *whlist;
+ unsigned int flags;
+ int err;
+ aufs_bindex_t bindex;
+};
+
-+static int test_empty_cb(void *__arg, const char *__name, int namelen,
-+ loff_t offset __maybe_unused, u64 ino,
++static int test_empty_cb(struct dir_context *ctx, const char *__name,
++ int namelen, loff_t offset __maybe_unused, u64 ino,
+ unsigned int d_type)
+{
-+ struct test_empty_arg *arg = __arg;
++ struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
++ ctx);
+ char *name = (void *)__name;
+
+ arg->err = 0;
+
+ h_file = au_h_open(dentry, arg->bindex,
+ O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
-+ /*file*/NULL);
++ /*file*/NULL, /*force_wr*/0);
+ err = PTR_ERR(h_file);
+ if (IS_ERR(h_file))
+ goto out;
+
+ err = 0;
+ if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
-+ && !h_file->f_dentry->d_inode->i_nlink)
++ && !file_inode(h_file)->i_nlink)
+ goto out_put;
+
+ do {
+ arg->err = 0;
+ au_fclr_testempty(arg->flags, CALLED);
+ /* smp_mb(); */
-+ err = vfsub_readdir(h_file, test_empty_cb, arg);
++ err = vfsub_iterate_dir(h_file, &arg->ctx);
+ if (err >= 0)
+ err = arg->err;
+ } while (!err && au_ftest_testempty(arg->flags, CALLED));
+ unsigned int rdhash;
+ aufs_bindex_t bindex, bstart, btail;
+ struct au_nhash whlist;
-+ struct test_empty_arg arg;
++ struct test_empty_arg arg = {
++ .ctx = {
++ .actor = au_diractor(test_empty_cb)
++ }
++ };
+
+ SiMustAnyLock(dentry->d_sb);
+
+int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
+{
+ int err;
-+ struct test_empty_arg arg;
++ struct test_empty_arg arg = {
++ .ctx = {
++ .actor = au_diractor(test_empty_cb)
++ }
++ };
+ aufs_bindex_t bindex, btail;
+
+ err = 0;
+ .owner = THIS_MODULE,
+ .llseek = default_llseek,
+ .read = generic_read_dir,
-+ .readdir = aufs_readdir,
++ .iterate = aufs_iterate,
+ .unlocked_ioctl = aufs_ioctl_dir,
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = aufs_compat_ioctl_dir,
+};
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,138 @@
++++ linux/fs/aufs/dir.h 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,136 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#ifdef __KERNEL__
+
+#include <linux/fs.h>
-+#include <linux/aufs_type.h>
+
+/* ---------------------------------------------------------------------- */
+
+ unsigned char shwh);
+void au_vdir_free(struct au_vdir *vdir);
+int au_vdir_init(struct file *file);
-+int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
++int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
+
+/* ioctl.c */
+long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,377 @@
++++ linux/fs/aufs/dynop.c 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,379 @@
+/*
-+ * Copyright (C) 2010-2011 Junjiro R. Okajima
++ * Copyright (C) 2010-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, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ DySetAop(migratepage);
+ DySetAop(launder_page);
+ DySetAop(is_partially_uptodate);
++ DySetAop(is_dirty_writeback);
+ DySetAop(error_remove_page);
++ DySetAop(swap_activate);
++ DySetAop(swap_deactivate);
+
+ DyDbgSize(cnt, *h_aop);
+ dyaop->da_get_xip_mem = h_aop->get_xip_mem;
+
+ key->dk_op.dy_hop = op->dy_hop;
+ kref_init(&key->dk_kref);
-+ p->set(key, op->dy_hop, br->br_mnt->mnt_sb);
++ p->set(key, op->dy_hop, au_br_sb(br));
+ old = dy_gadd(spl, key);
+ if (old) {
+ kfree(key);
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,80 @@
++++ linux/fs/aufs/dynop.h 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,75 @@
+/*
-+ * Copyright (C) 2010-2011 Junjiro R. Okajima
++ * Copyright (C) 2010-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, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/fs.h>
-+#include <linux/mm.h>
-+#include <linux/rcupdate.h>
-+#include <linux/aufs_type.h>
+#include "inode.h"
+
+enum {AuDy_AOP, AuDyLast};
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,805 @@
++++ linux/fs/aufs/export.c 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,831 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ */
+
+#include <linux/exportfs.h>
-+#include <linux/file.h>
-+#include <linux/mnt_namespace.h>
++#include <linux/fs_struct.h>
+#include <linux/namei.h>
+#include <linux/nsproxy.h>
+#include <linux/random.h>
+#include <linux/writeback.h>
++#include "../fs/mount.h"
+#include "aufs.h"
+
+union conv {
+ return !!(dentry->d_flags & DCACHE_DISCONNECTED);
+}
+
++int au_test_nfsd(void)
++{
++ int ret;
++ struct task_struct *tsk = current;
++ char comm[sizeof(tsk->comm)];
++
++ ret = 0;
++ if (tsk->flags & PF_KTHREAD) {
++ get_task_comm(comm, tsk);
++ ret = !strcmp(comm, "nfsd");
++ }
++
++ return ret;
++}
++
+/* ---------------------------------------------------------------------- */
+/* inode generation external table */
+
+ file = sbinfo->si_xigen;
+ BUG_ON(!file);
+
-+ if (i_size_read(file->f_dentry->d_inode)
++ if (vfsub_f_size_read(file)
+ < pos + sizeof(inode->i_generation)) {
+ inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
+ sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
+ sigen = au_sigen(sb);
+ if (unlikely(is_bad_inode(inode)
+ || IS_DEADDIR(inode)
-+ || sigen != au_iigen(inode)))
++ || sigen != au_iigen(inode, NULL)))
+ goto out_iput;
+
+ dentry = NULL;
+ dentry = d_find_alias(inode);
+ else {
+ spin_lock(&inode->i_lock);
-+ list_for_each_entry(d, &inode->i_dentry, d_alias) {
++ hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
+ spin_lock(&d->d_lock);
+ if (!au_test_anon(d)
+ && d->d_parent->d_inode->i_ino == dir_ino) {
+static struct vfsmount *au_mnt_get(struct super_block *sb)
+{
+ int err;
++ struct path root;
+ struct au_compare_mnt_args args = {
+ .sb = sb
+ };
-+ struct mnt_namespace *ns;
-+
-+ br_read_lock(vfsmount_lock);
-+ /* no get/put ?? */
-+ AuDebugOn(!current->nsproxy);
-+ ns = current->nsproxy->mnt_ns;
-+ AuDebugOn(!ns);
-+ err = iterate_mounts(au_compare_mnt, &args, ns->root);
-+ br_read_unlock(vfsmount_lock);
++
++ get_fs_root(current->fs, &root);
++ rcu_read_lock();
++ err = iterate_mounts(au_compare_mnt, &args, root.mnt);
++ rcu_read_unlock();
++ path_put(&root);
+ AuDebugOn(!err);
+ AuDebugOn(!args.mnt);
+ return args.mnt;
+}
+
+struct find_name_by_ino {
++ struct dir_context ctx;
+ int called, found;
+ ino_t ino;
+ char *name;
+};
+
+static int
-+find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
-+ u64 ino, unsigned int d_type)
++find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
++ loff_t offset, u64 ino, unsigned int d_type)
+{
-+ struct find_name_by_ino *a = arg;
++ struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
++ ctx);
+
+ a->called++;
+ if (a->ino != ino)
+ struct dentry *dentry, *parent;
+ struct file *file;
+ struct inode *dir;
-+ struct find_name_by_ino arg;
++ struct find_name_by_ino arg = {
++ .ctx = {
++ .actor = au_diractor(find_name_by_ino)
++ }
++ };
+ int err;
+
+ parent = path->dentry;
+ goto out;
+
+ dentry = ERR_PTR(-ENOMEM);
-+ arg.name = __getname_gfp(GFP_NOFS);
++ arg.name = (void *)__get_free_page(GFP_NOFS);
+ if (unlikely(!arg.name))
+ goto out_file;
+ arg.ino = ino;
+ do {
+ arg.called = 0;
+ /* smp_mb(); */
-+ err = vfsub_readdir(file, find_name_by_ino, &arg);
++ err = vfsub_iterate_dir(file, &arg.ctx);
+ } while (!err && !arg.found && arg.called);
+ dentry = ERR_PTR(err);
+ if (unlikely(err))
+ goto out_name;
-+ dentry = ERR_PTR(-ENOENT);
++ /* instead of ENOENT */
++ dentry = ERR_PTR(-ESTALE);
+ if (!arg.found)
+ goto out_name;
+
-+ /* do not call au_lkup_one() */
++ /* do not call vfsub_lkup_one() */
+ dir = parent->d_inode;
+ mutex_lock(&dir->i_mutex);
+ dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
+ }
+
+out_name:
-+ __putname(arg.name);
++ free_page((unsigned long)arg.name);
+out_file:
+ fput(file);
+out:
+ struct path path;
+
+ br = au_sbr(sb, nsi_lock->bindex);
-+ h_mnt = br->br_mnt;
++ h_mnt = au_br_mnt(br);
+ h_sb = h_mnt->mnt_sb;
+ /* todo: call lower fh_to_dentry()? fh_to_parent()? */
+ h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
+
+/* ---------------------------------------------------------------------- */
+
-+static int aufs_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len,
-+ int connectable)
++static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
++ struct inode *dir)
+{
+ int err;
-+ aufs_bindex_t bindex, bend;
++ aufs_bindex_t bindex;
+ struct super_block *sb, *h_sb;
-+ struct inode *inode;
-+ struct dentry *parent, *h_parent;
++ struct dentry *dentry, *parent, *h_parent;
++ struct inode *h_dir;
+ struct au_branch *br;
+
-+ AuDebugOn(au_test_anon(dentry));
-+
-+ parent = NULL;
+ err = -ENOSPC;
+ if (unlikely(*max_len <= Fh_tail)) {
+ AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
+ }
+
+ err = FILEID_ROOT;
-+ if (IS_ROOT(dentry)) {
-+ AuDebugOn(dentry->d_inode->i_ino != AUFS_ROOT_INO);
++ if (inode->i_ino == AUFS_ROOT_INO) {
++ AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
+ goto out;
+ }
+
+ h_parent = NULL;
-+ err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_IR | AuLock_GEN);
++ sb = inode->i_sb;
++ err = si_read_lock(sb, AuLock_FLUSH);
+ if (unlikely(err))
+ goto out;
+
-+ inode = dentry->d_inode;
-+ AuDebugOn(!inode);
-+ sb = dentry->d_sb;
+#ifdef CONFIG_AUFS_DEBUG
+ if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
+ AuWarn1("NFS-exporting requires xino\n");
+#endif
+ err = -EIO;
-+ parent = dget_parent(dentry);
-+ di_read_lock_parent(parent, !AuLock_IR);
-+ bend = au_dbtaildir(parent);
-+ for (bindex = au_dbstart(parent); bindex <= bend; bindex++) {
-+ h_parent = au_h_dptr(parent, bindex);
-+ if (h_parent) {
-+ dget(h_parent);
-+ break;
-+ }
++ parent = NULL;
++ ii_read_lock_child(inode);
++ bindex = au_ibstart(inode);
++ if (!dir) {
++ dentry = d_find_alias(inode);
++ if (unlikely(!dentry))
++ goto out_unlock;
++ AuDebugOn(au_test_anon(dentry));
++ parent = dget_parent(dentry);
++ dput(dentry);
++ if (unlikely(!parent))
++ goto out_unlock;
++ dir = parent->d_inode;
+ }
++
++ ii_read_lock_parent(dir);
++ h_dir = au_h_iptr(dir, bindex);
++ ii_read_unlock(dir);
++ if (unlikely(!h_dir))
++ goto out_parent;
++ h_parent = d_find_alias(h_dir);
+ if (unlikely(!h_parent))
-+ goto out_unlock;
++ goto out_hparent;
+
+ err = -EPERM;
+ br = au_sbr(sb, bindex);
-+ h_sb = br->br_mnt->mnt_sb;
++ h_sb = au_br_sb(br);
+ if (unlikely(!h_sb->s_export_op)) {
+ AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
-+ goto out_dput;
++ goto out_hparent;
+ }
+
+ fh[Fh_br_id] = br->br_id;
+ fh[Fh_sigen] = au_sigen(sb);
+ encode_ino(fh + Fh_ino, inode->i_ino);
-+ encode_ino(fh + Fh_dir_ino, parent->d_inode->i_ino);
++ encode_ino(fh + Fh_dir_ino, dir->i_ino);
+ fh[Fh_igen] = inode->i_generation;
+
+ *max_len -= Fh_tail;
+ err = fh[Fh_h_type];
+ *max_len += Fh_tail;
+ /* todo: macros? */
-+ if (err != 255)
++ if (err != FILEID_INVALID)
+ err = 99;
+ else
+ AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
+
-+out_dput:
++out_hparent:
+ dput(h_parent);
-+out_unlock:
-+ di_read_unlock(parent, !AuLock_IR);
++out_parent:
+ dput(parent);
-+ aufs_read_unlock(dentry, AuLock_IR);
++out_unlock:
++ ii_read_unlock(inode);
++ si_read_unlock(sb);
+out:
+ if (unlikely(err < 0))
-+ err = 255;
++ err = FILEID_INVALID;
+ return err;
+}
+
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,676 @@
++++ linux/fs/aufs/file.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,724 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * handling file/dir, and address_space operation
+ */
+
-+#include <linux/file.h>
-+#include <linux/fsnotify.h>
-+#include <linux/namei.h>
++#ifdef CONFIG_AUFS_DEBUG
++#include <linux/migrate.h>
++#endif
+#include <linux/pagemap.h>
+#include "aufs.h"
+
+
+/* common functions to regular file and dir */
+struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
-+ struct file *file)
++ struct file *file, int force_wr)
+{
+ struct file *h_file;
+ struct dentry *h_dentry;
+ br = au_sbr(sb, bindex);
+ h_file = ERR_PTR(-EACCES);
+ exec_flag = flags & __FMODE_EXEC;
-+ if (exec_flag && (br->br_mnt->mnt_flags & MNT_NOEXEC))
++ if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
+ goto out;
+
+ /* drop flags for writing */
-+ if (au_test_ro(sb, bindex, dentry->d_inode))
++ if (au_test_ro(sb, bindex, dentry->d_inode)) {
++ if (force_wr && !(flags & O_WRONLY))
++ force_wr = 0;
+ flags = au_file_roflags(flags);
++ if (force_wr) {
++ h_file = ERR_PTR(-EROFS);
++ flags = au_file_roflags(flags);
++ if (unlikely(vfsub_native_ro(h_inode)
++ || IS_APPEND(h_inode)))
++ goto out;
++ flags &= ~O_ACCMODE;
++ flags |= O_WRONLY;
++ }
++ }
+ flags &= ~O_CREAT;
+ atomic_inc(&br->br_count);
+ h_path.dentry = h_dentry;
-+ h_path.mnt = br->br_mnt;
++ h_path.mnt = au_br_mnt(br);
+ if (!au_special_file(h_inode->i_mode))
+ h_file = vfsub_dentry_open(&h_path, flags);
+ else {
+ au_set_h_fptr(file, bstart, NULL);
+ }
+ AuDebugOn(au_fi(file)->fi_hdir);
-+ AuDebugOn(au_fbstart(file) < bstart);
++ /*
++ * it can happen
++ * file exists on both of rw and ro
++ * open --> dbstart and fbstart are both 0
++ * prepend a branch as rw, "rw" become ro
++ * remove rw/file
++ * delete the top branch, "rw" becomes rw again
++ * --> dbstart is 1, fbstart is still 0
++ * write --> fbstart is 0 but dbstart is 1
++ */
++ /* AuDebugOn(au_fbstart(file) < bstart); */
+
+ h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
-+ file);
++ file, /*force_wr*/0);
+ err = PTR_ERR(h_file);
-+ if (IS_ERR(h_file))
++ if (IS_ERR(h_file)) {
++ if (h_file_tmp) {
++ atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
++ au_set_h_fptr(file, bstart, h_file_tmp);
++ h_file_tmp = NULL;
++ }
+ goto out; /* todo: close all? */
++ }
+
+ err = 0;
+ au_set_fbstart(file, bstart);
+}
+
+static int au_ready_to_write_wh(struct file *file, loff_t len,
-+ aufs_bindex_t bcpup)
++ aufs_bindex_t bcpup, struct au_pin *pin)
+{
+ int err;
+ struct inode *inode, *h_inode;
-+ struct dentry *dentry, *h_dentry, *hi_wh;
++ struct dentry *h_dentry, *hi_wh;
++ struct au_cp_generic cpg = {
++ .dentry = file->f_dentry,
++ .bdst = bcpup,
++ .bsrc = -1,
++ .len = len,
++ .pin = pin
++ };
+
-+ dentry = file->f_dentry;
-+ au_update_dbstart(dentry);
-+ inode = dentry->d_inode;
++ au_update_dbstart(cpg.dentry);
++ inode = cpg.dentry->d_inode;
+ h_inode = NULL;
-+ if (au_dbstart(dentry) <= bcpup && au_dbend(dentry) >= bcpup) {
-+ h_dentry = au_h_dptr(dentry, bcpup);
++ if (au_dbstart(cpg.dentry) <= bcpup
++ && au_dbend(cpg.dentry) >= bcpup) {
++ h_dentry = au_h_dptr(cpg.dentry, bcpup);
+ if (h_dentry)
+ h_inode = h_dentry->d_inode;
+ }
+ hi_wh = au_hi_wh(inode, bcpup);
+ if (!hi_wh && !h_inode)
-+ err = au_sio_cpup_wh(dentry, bcpup, len, file);
++ err = au_sio_cpup_wh(&cpg, file);
+ else
+ /* already copied-up after unlink */
+ err = au_reopen_wh(file, bcpup, hi_wh);
+
+ if (!err
+ && inode->i_nlink > 1
-+ && au_opt_test(au_mntflags(dentry->d_sb), PLINK))
-+ au_plink_append(inode, bcpup, au_h_dptr(dentry, bcpup));
++ && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
++ au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
+
+ return err;
+}
+int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
+{
+ int err;
-+ aufs_bindex_t bstart, bcpup, dbstart;
-+ struct dentry *dentry, *parent, *h_dentry;
-+ struct inode *h_inode, *inode;
++ aufs_bindex_t dbstart;
++ struct dentry *parent, *h_dentry;
++ struct inode *inode;
+ struct super_block *sb;
+ struct file *h_file;
++ struct au_cp_generic cpg = {
++ .dentry = file->f_dentry,
++ .bdst = -1,
++ .bsrc = -1,
++ .len = len,
++ .pin = pin,
++ .flags = AuCpup_DTIME
++ };
+
-+ dentry = file->f_dentry;
-+ sb = dentry->d_sb;
-+ inode = dentry->d_inode;
++ sb = cpg.dentry->d_sb;
++ inode = cpg.dentry->d_inode;
+ AuDebugOn(au_special_file(inode->i_mode));
-+ bstart = au_fbstart(file);
-+ err = au_test_ro(sb, bstart, inode);
++ cpg.bsrc = au_fbstart(file);
++ err = au_test_ro(sb, cpg.bsrc, inode);
+ if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
-+ err = au_pin(pin, dentry, bstart, AuOpt_UDBA_NONE, /*flags*/0);
++ err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
++ /*flags*/0);
+ goto out;
+ }
+
+ /* need to cpup or reopen */
-+ parent = dget_parent(dentry);
++ parent = dget_parent(cpg.dentry);
+ di_write_lock_parent(parent);
-+ err = AuWbrCopyup(au_sbi(sb), dentry);
-+ bcpup = err;
++ err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
++ cpg.bdst = err;
+ if (unlikely(err < 0))
+ goto out_dgrade;
+ err = 0;
+
-+ if (!d_unhashed(dentry) && !au_h_dptr(parent, bcpup)) {
-+ err = au_cpup_dirs(dentry, bcpup);
++ if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
++ err = au_cpup_dirs(cpg.dentry, cpg.bdst);
+ if (unlikely(err))
+ goto out_dgrade;
+ }
+
-+ err = au_pin(pin, dentry, bcpup, AuOpt_UDBA_NONE,
++ err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
+ AuPin_DI_LOCKED | AuPin_MNT_WRITE);
+ if (unlikely(err))
+ goto out_dgrade;
+
+ h_dentry = au_hf_top(file)->f_dentry;
-+ h_inode = h_dentry->d_inode;
-+ dbstart = au_dbstart(dentry);
-+ if (dbstart <= bcpup) {
-+ h_dentry = au_h_dptr(dentry, bcpup);
++ dbstart = au_dbstart(cpg.dentry);
++ if (dbstart <= cpg.bdst) {
++ h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
+ AuDebugOn(!h_dentry);
-+ h_inode = h_dentry->d_inode;
-+ AuDebugOn(!h_inode);
-+ bstart = bcpup;
++ cpg.bsrc = cpg.bdst;
+ }
+
-+ if (dbstart <= bcpup /* just reopen */
-+ || !d_unhashed(dentry) /* copyup and reopen */
++ if (dbstart <= cpg.bdst /* just reopen */
++ || !d_unhashed(cpg.dentry) /* copyup and reopen */
+ ) {
-+ mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+ h_file = au_h_open_pre(dentry, bstart);
-+ if (IS_ERR(h_file)) {
++ h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
++ if (IS_ERR(h_file))
+ err = PTR_ERR(h_file);
-+ h_file = NULL;
-+ } else {
++ else {
+ di_downgrade_lock(parent, AuLock_IR);
-+ if (dbstart > bcpup)
-+ err = au_sio_cpup_simple(dentry, bcpup, len,
-+ AuCpup_DTIME);
++ if (dbstart > cpg.bdst)
++ err = au_sio_cpup_simple(&cpg);
+ if (!err)
+ err = au_reopen_nondir(file);
++ au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
+ }
-+ mutex_unlock(&h_inode->i_mutex);
-+ au_h_open_post(dentry, bstart, h_file);
+ } else { /* copyup as wh and reopen */
+ /*
+ * since writable hfsplus branch is not supported,
+ * h_open_pre/post() are unnecessary.
+ */
-+ mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+ err = au_ready_to_write_wh(file, len, bcpup);
++ err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
+ di_downgrade_lock(parent, AuLock_IR);
-+ mutex_unlock(&h_inode->i_mutex);
+ }
+
+ if (!err) {
+ int (*flush)(struct file *file, fl_owner_t id))
+{
+ int err;
-+ struct dentry *dentry;
+ struct super_block *sb;
+ struct inode *inode;
+
-+ dentry = file->f_dentry;
-+ sb = dentry->d_sb;
-+ inode = dentry->d_inode;
++ inode = file_inode(file);
++ sb = inode->i_sb;
+ si_noflush_read_lock(sb);
+ fi_read_lock(file);
+ ii_read_lock_child(inode);
+static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
+{
+ int err;
-+ aufs_bindex_t bstart;
+ struct au_pin pin;
+ struct au_finfo *finfo;
-+ struct dentry *dentry, *parent, *hi_wh;
++ struct dentry *parent, *hi_wh;
+ struct inode *inode;
+ struct super_block *sb;
++ struct au_cp_generic cpg = {
++ .dentry = file->f_dentry,
++ .bdst = -1,
++ .bsrc = -1,
++ .len = -1,
++ .pin = &pin,
++ .flags = AuCpup_DTIME
++ };
+
+ FiMustWriteLock(file);
+
+ err = 0;
+ finfo = au_fi(file);
-+ dentry = file->f_dentry;
-+ sb = dentry->d_sb;
-+ inode = dentry->d_inode;
-+ bstart = au_ibstart(inode);
-+ if (bstart == finfo->fi_btop || IS_ROOT(dentry))
++ sb = cpg.dentry->d_sb;
++ inode = cpg.dentry->d_inode;
++ cpg.bdst = au_ibstart(inode);
++ if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
+ goto out;
+
-+ parent = dget_parent(dentry);
-+ if (au_test_ro(sb, bstart, inode)) {
++ parent = dget_parent(cpg.dentry);
++ if (au_test_ro(sb, cpg.bdst, inode)) {
+ di_read_lock_parent(parent, !AuLock_IR);
-+ err = AuWbrCopyup(au_sbi(sb), dentry);
-+ bstart = err;
++ err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
++ cpg.bdst = err;
+ di_read_unlock(parent, !AuLock_IR);
+ if (unlikely(err < 0))
+ goto out_parent;
+ }
+
+ di_read_lock_parent(parent, AuLock_IR);
-+ hi_wh = au_hi_wh(inode, bstart);
++ hi_wh = au_hi_wh(inode, cpg.bdst);
+ if (!S_ISDIR(inode->i_mode)
+ && au_opt_test(au_mntflags(sb), PLINK)
+ && au_plink_test(inode)
-+ && !d_unhashed(dentry)) {
-+ err = au_test_and_cpup_dirs(dentry, bstart);
++ && !d_unhashed(cpg.dentry)
++ && cpg.bdst < au_dbstart(cpg.dentry)) {
++ err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
+ if (unlikely(err))
+ goto out_unlock;
+
+ /* always superio. */
-+ err = au_pin(&pin, dentry, bstart, AuOpt_UDBA_NONE,
++ err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
+ AuPin_DI_LOCKED | AuPin_MNT_WRITE);
-+ if (!err)
-+ err = au_sio_cpup_simple(dentry, bstart, -1,
-+ AuCpup_DTIME);
-+ au_unpin(&pin);
++ if (!err) {
++ err = au_sio_cpup_simple(&cpg);
++ au_unpin(&pin);
++ }
+ } else if (hi_wh) {
+ /* already copied-up after unlink */
-+ err = au_reopen_wh(file, bstart, hi_wh);
++ err = au_reopen_wh(file, cpg.bdst, hi_wh);
+ *need_reopen = 0;
+ }
+
+ for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
+ finfo->fi_btop++, p++)
+ if (p->hf_file) {
-+ if (p->hf_file->f_dentry
-+ && p->hf_file->f_dentry->d_inode)
++ if (file_inode(p->hf_file))
+ break;
+ else
+ au_hfput(p, file);
+ for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
+ fidir->fd_bbot--, p--)
+ if (p->hf_file) {
-+ if (p->hf_file->f_dentry
-+ && p->hf_file->f_dentry->d_inode)
++ if (file_inode(p->hf_file))
+ break;
+ else
+ au_hfput(p, file);
+
+static int aufs_set_page_dirty(struct page *page)
+{ AuUnsupport(); return 0; }
-+static void aufs_invalidatepage(struct page *page, unsigned long offset)
++static void aufs_invalidatepage(struct page *page, unsigned int offset,
++ unsigned int length)
+{ AuUnsupport(); }
+static int aufs_releasepage(struct page *page, gfp_t gfp)
+{ AuUnsupport(); return 0; }
+static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
-+ struct page *page)
++ struct page *page, enum migrate_mode mode)
+{ AuUnsupport(); return 0; }
+static int aufs_launder_page(struct page *page)
+{ AuUnsupport(); return 0; }
+ read_descriptor_t *desc,
+ unsigned long from)
+{ AuUnsupport(); return 0; }
++static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
++ bool *writeback)
++{ AuUnsupport(); }
+static int aufs_error_remove_page(struct address_space *mapping,
+ struct page *page)
+{ AuUnsupport(); return 0; }
++static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
++ sector_t *span)
++{ AuUnsupport(); return 0; }
++static void aufs_swap_deactivate(struct file *file)
++{ AuUnsupport(); }
+#endif /* CONFIG_AUFS_DEBUG */
+
+const struct address_space_operations aufs_aop = {
+ .migratepage = aufs_migratepage,
+ .launder_page = aufs_launder_page,
+ .is_partially_uptodate = aufs_is_partially_uptodate,
-+ .error_remove_page = aufs_error_remove_page
++ .is_dirty_writeback = aufs_is_dirty_writeback,
++ .error_remove_page = aufs_error_remove_page,
++ .swap_activate = aufs_swap_activate,
++ .swap_deactivate = aufs_swap_deactivate
+#endif /* CONFIG_AUFS_DEBUG */
+};
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,299 @@
++++ linux/fs/aufs/file.h 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,312 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
-+#include <linux/aufs_type.h>
+#include "rwsem.h"
+
+struct au_branch;
+ atomic_t fi_mmapped;
+ };
+ struct au_fidir *fi_hdir; /* for dir only */
++
++ struct hlist_node fi_hlist;
++ struct file *fi_file; /* very ugly */
+} ____cacheline_aligned_in_smp;
+
+/* ---------------------------------------------------------------------- */
+extern const struct address_space_operations aufs_aop;
+unsigned int au_file_roflags(unsigned int flags);
+struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
-+ struct file *file);
++ struct file *file, int force_wr);
+int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
+ struct au_fidir *fidir);
+int au_reopen_nondir(struct file *file);
+
+#ifdef CONFIG_AUFS_BR_HFSPLUS
+/* hfsplus.c */
-+struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex);
++struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
++ int force_wr);
+void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
+ struct file *h_file);
+#else
+static inline
-+struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
++struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
++ int force_wr)
+{
+ return NULL;
+}
+
+#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)
+#ifdef CONFIG_COMPAT
+long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
+ unsigned long arg);
++long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
++ unsigned long arg);
+#endif
+
+/* ---------------------------------------------------------------------- */
+
+static inline struct au_finfo *au_fi(struct file *file)
+{
-+ return file->private_data;
++ struct au_finfo *finfo;
++
++ finfo = au_fi_sp(file);
++ if (!finfo)
++ finfo = file->private_data;
++ return finfo;
+}
+
+/* ---------------------------------------------------------------------- */
+{
+ if (atomic_inc_return(&au_fi(f)->fi_mmapped))
+ return;
-+ pr_warning("fi_mmapped wrapped around\n");
++ pr_warn("fi_mmapped wrapped around\n");
+ while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
+ ;
+}
+#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)
+{
-+#ifdef CONFIG_AUFS_PROC_MAP
+ get_file(file);
+ vma->vm_prfile = file;
+#ifndef CONFIG_MMU
+ get_file(file);
+ vma->vm_region->vm_prfile = file;
+#endif
-+#endif
-+}
++}*/
+
+#endif /* __KERNEL__ */
+#endif /* __AUFS_FILE_H__ */
diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
--- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/finfo.c 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,153 @@
++++ linux/fs/aufs/finfo.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,156 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * file private data
+ */
+
-+#include <linux/file.h>
+#include "aufs.h"
+
+void au_hfput(struct au_hfile *hf, struct file *file)
+
+ err = 0;
+ au_nfiles_inc(dentry->d_sb);
++ /* verbose coding for lock class name */
++ if (!fidir)
++ au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
++ else
++ au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
+ au_rw_write_lock(&finfo->fi_rwsem);
+ finfo->fi_btop = -1;
+ finfo->fi_hdir = fidir;
+}
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 2011-10-24 20:52:23.677857076 +0200
-@@ -0,0 +1,711 @@
++++ linux/fs/aufs/f_op.c 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,718 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * file and vm operations
+ */
+
-+#include <linux/file.h>
++#include <linux/aio.h>
+#include <linux/fs_stack.h>
+#include <linux/mman.h>
-+#include <linux/mm.h>
+#include <linux/security.h>
+#include "aufs.h"
+
+
+ FiMustWriteLock(file);
+
++ err = 0;
+ dentry = file->f_dentry;
-+ err = au_d_alive(dentry);
-+ if (unlikely(err))
-+ goto out;
-+
+ finfo = au_fi(file);
+ memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
+ atomic_set(&finfo->fi_mmapped, 0);
+ bindex = au_dbstart(dentry);
-+ h_file = au_h_open(dentry, bindex, flags, file);
++ h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
+ if (IS_ERR(h_file))
+ err = PTR_ERR(h_file);
+ else {
+ 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; */
+ }
+
-+out:
+ return err;
+}
+
+ int err;
+ struct super_block *sb;
+
-+ AuDbg("%.*s, f_flags 0x%x, f_mode 0x%x\n",
-+ AuDLNPair(file->f_dentry), vfsub_file_flags(file),
-+ file->f_mode);
++ AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
++ file, vfsub_file_flags(file), file->f_mode);
+
+ sb = file->f_dentry->d_sb;
+ si_read_lock(sb, AuLock_FLUSH);
+ aufs_bindex_t bindex;
+
+ finfo = au_fi(file);
++ au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
+ bindex = finfo->fi_btop;
-+ if (bindex >= 0) {
-+ /* remove me from sb->s_files */
-+ file_sb_list_del(file);
++ if (bindex >= 0)
+ au_set_h_fptr(file, bindex, NULL);
-+ }
+
+ au_finfo_fin(file);
+ return 0;
+}
+
+/* ---------------------------------------------------------------------- */
++/*
++ * read and write functions acquire [fdi]_rwsem once, but release before
++ * mmap_sem. This is because to stop a race condition between mmap(2).
++ * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
++ * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
++ * read functions after [fdi]_rwsem are released, but it should be harmless.
++ */
+
+static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
+ loff_t *ppos)
+ goto out;
+
+ h_file = au_hf_top(file);
++ get_file(h_file);
++ di_read_unlock(dentry, AuLock_IR);
++ fi_read_unlock(file);
++
++ /* filedata may be obsoleted by concurrent copyup, but no problem */
+ err = vfsub_read_u(h_file, buf, count, ppos);
+ /* todo: necessary? */
+ /* file->f_ra = h_file->f_ra; */
-+ fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
++ /* update without lock, I don't think it a problem */
++ fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
++ fput(h_file);
+
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_read_unlock(file);
+out:
+ si_read_unlock(sb);
+ return err;
+ ssize_t err;
+ struct au_pin pin;
+ struct dentry *dentry;
++ struct super_block *sb;
+ struct inode *inode;
+ struct file *h_file;
+ char __user *buf = (char __user *)ubuf;
+
+ dentry = file->f_dentry;
++ sb = dentry->d_sb;
+ inode = dentry->d_inode;
+ au_mtx_and_read_lock(inode);
+
+
+ err = au_ready_to_write(file, -1, &pin);
+ di_downgrade_lock(dentry, AuLock_IR);
-+ if (unlikely(err))
-+ goto out_unlock;
++ if (unlikely(err)) {
++ di_read_unlock(dentry, AuLock_IR);
++ fi_write_unlock(file);
++ goto out;
++ }
+
+ h_file = au_hf_top(file);
++ get_file(h_file);
+ au_unpin(&pin);
++ di_read_unlock(dentry, AuLock_IR);
++ fi_write_unlock(file);
++
+ err = vfsub_write_u(h_file, buf, count, ppos);
++ ii_write_lock_child(inode);
+ au_cpup_attr_timesizes(inode);
-+ inode->i_mode = h_file->f_dentry->d_inode->i_mode;
++ inode->i_mode = file_inode(h_file)->i_mode;
++ ii_write_unlock(inode);
++ fput(h_file);
+
-+out_unlock:
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_write_unlock(file);
+out:
-+ si_read_unlock(inode->i_sb);
++ si_read_unlock(sb);
+ mutex_unlock(&inode->i_mutex);
+ return err;
+}
+ goto out;
+
+ h_file = au_hf_top(file);
++ get_file(h_file);
++ di_read_unlock(dentry, AuLock_IR);
++ fi_read_unlock(file);
++
+ err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
+ /* todo: necessary? */
+ /* file->f_ra = h_file->f_ra; */
-+ fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_read_unlock(file);
++ /* update without lock, I don't think it a problem */
++ fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
++ fput(h_file);
+
+out:
+ si_read_unlock(sb);
+ struct dentry *dentry;
+ struct inode *inode;
+ struct file *file, *h_file;
++ struct super_block *sb;
+
+ file = kio->ki_filp;
+ dentry = file->f_dentry;
++ sb = dentry->d_sb;
+ inode = dentry->d_inode;
+ au_mtx_and_read_lock(inode);
+
+
+ err = au_ready_to_write(file, -1, &pin);
+ di_downgrade_lock(dentry, AuLock_IR);
-+ if (unlikely(err))
-+ goto out_unlock;
++ if (unlikely(err)) {
++ di_read_unlock(dentry, AuLock_IR);
++ fi_write_unlock(file);
++ goto out;
++ }
+
-+ au_unpin(&pin);
+ h_file = au_hf_top(file);
++ get_file(h_file);
++ 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);
++ ii_write_lock_child(inode);
+ au_cpup_attr_timesizes(inode);
-+ inode->i_mode = h_file->f_dentry->d_inode->i_mode;
++ inode->i_mode = file_inode(h_file)->i_mode;
++ ii_write_unlock(inode);
++ fput(h_file);
+
-+out_unlock:
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_write_unlock(file);
+out:
-+ si_read_unlock(inode->i_sb);
++ si_read_unlock(sb);
+ mutex_unlock(&inode->i_mutex);
+ return err;
+}
+
+ err = -EINVAL;
+ h_file = au_hf_top(file);
++ get_file(h_file);
+ if (au_test_loopback_kthread()) {
+ au_warn_loopback(h_file->f_dentry->d_sb);
+ if (file->f_mapping != h_file->f_mapping) {
+ smp_mb(); /* unnecessary? */
+ }
+ }
++ di_read_unlock(dentry, AuLock_IR);
++ fi_read_unlock(file);
++
+ err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
+ /* todo: necessasry? */
+ /* file->f_ra = h_file->f_ra; */
-+ fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
-+
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_read_unlock(file);
++ /* update without lock, I don't think it a problem */
++ fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
++ fput(h_file);
+
+out:
+ si_read_unlock(sb);
+ struct dentry *dentry;
+ struct inode *inode;
+ struct file *h_file;
++ struct super_block *sb;
+
+ 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))
-+ goto out_unlock;
++ if (unlikely(err)) {
++ di_read_unlock(dentry, AuLock_IR);
++ fi_write_unlock(file);
++ goto out;
++ }
+
+ h_file = au_hf_top(file);
++ get_file(h_file);
+ au_unpin(&pin);
++ di_read_unlock(dentry, AuLock_IR);
++ fi_write_unlock(file);
++
+ err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
++ ii_write_lock_child(inode);
+ au_cpup_attr_timesizes(inode);
-+ inode->i_mode = h_file->f_dentry->d_inode->i_mode;
++ inode->i_mode = file_inode(h_file)->i_mode;
++ ii_write_unlock(inode);
++ fput(h_file);
+
-+out_unlock:
-+ di_read_unlock(dentry, AuLock_IR);
-+ fi_write_unlock(file);
+out:
-+ si_read_unlock(inode->i_sb);
++ si_read_unlock(sb);
+ mutex_unlock(&inode->i_mutex);
+ return err;
+}
+
+/* ---------------------------------------------------------------------- */
+
++/*
++ * The locking order around current->mmap_sem.
++ * - in most and regular cases
++ * file I/O syscall -- aufs_read() or something
++ * -- si_rwsem for read -- mmap_sem
++ * (Note that [fdi]i_rwsem are released before mmap_sem).
++ * - in mmap case
++ * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
++ * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
++ * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
++ * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
++ * It means that when aufs acquires si_rwsem for write, the process should never
++ * acquire mmap_sem.
++ *
++ * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
++ * problem either since any directory is not able to be mmap-ed.
++ * The similar scenario is applied to aufs_readlink() too.
++ */
++
+/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
+#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
+
+{
+ return AuConv_VM_MAP(flags, GROWSDOWN)
+ | AuConv_VM_MAP(flags, DENYWRITE)
-+ | AuConv_VM_MAP(flags, EXECUTABLE)
+ | AuConv_VM_MAP(flags, LOCKED);
+}
-+/*
-+ * This is another ugly approach to keep the lock order, particularly
-+ * mm->mmap_sem and aufs rwsem. The previous approach was reverted and you can
-+ * find it in git-log, if you want.
-+ *
-+ * native readdir: i_mutex, copy_to_user, mmap_sem
-+ * aufs readdir: i_mutex, rwsem, nested-i_mutex, copy_to_user, mmap_sem
-+ *
-+ * Before aufs_mmap() mmap_sem is acquired already, but aufs_mmap() has to
-+ * acquire aufs rwsem. It introduces a circular locking dependency.
-+ * To address this problem, aufs_mmap() delegates the part which requires aufs
-+ * rwsem to its internal workqueue.
-+ * But it is just a fake. A deadlock MAY happen between write() and mmap() for
-+ * the same file in a multi-threaded application.
-+ */
-+
-+struct au_mmap_pre_args {
-+ /* input */
-+ struct file *file;
-+ struct vm_area_struct *vma;
-+
-+ /* output */
-+ int *errp;
-+ struct file *h_file;
-+ struct au_branch *br;
-+};
+
-+static int au_mmap_pre(struct file *file, struct vm_area_struct *vma,
-+ struct file **h_file, struct au_branch **br)
++static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ int err;
+ aufs_bindex_t bstart;
+ const unsigned char wlock
-+ = !!(file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
++ = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
+ struct dentry *dentry;
+ struct super_block *sb;
++ struct file *h_file;
++ struct au_branch *br;
++ struct au_pin pin;
++
++ AuDbgVmRegion(file, vma);
+
+ dentry = file->f_dentry;
+ sb = dentry->d_sb;
++ lockdep_off();
+ si_read_lock(sb, AuLock_NOPLMW);
+ err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
+ if (unlikely(err))
+ goto out;
+
+ if (wlock) {
-+ struct au_pin pin;
-+
+ err = au_ready_to_write(file, -1, &pin);
+ di_write_unlock(dentry);
-+ if (unlikely(err))
-+ goto out_unlock;
++ if (unlikely(err)) {
++ fi_write_unlock(file);
++ goto out;
++ }
+ au_unpin(&pin);
+ } else
+ di_write_unlock(dentry);
++
+ bstart = au_fbstart(file);
-+ *br = au_sbr(sb, bstart);
-+ *h_file = au_hf_top(file);
-+ get_file(*h_file);
++ br = au_sbr(sb, bstart);
++ h_file = au_hf_top(file);
++ get_file(h_file);
+ au_set_mmapped(file);
-+
-+out_unlock:
+ fi_write_unlock(file);
-+out:
-+ si_read_unlock(sb);
-+ return err;
-+}
-+
-+static void au_call_mmap_pre(void *args)
-+{
-+ struct au_mmap_pre_args *a = args;
-+ *a->errp = au_mmap_pre(a->file, a->vma, &a->h_file, &a->br);
-+}
-+
-+static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
-+{
-+ int err, wkq_err;
-+ unsigned long prot;
-+ struct au_mmap_pre_args args = {
-+ .file = file,
-+ .vma = vma,
-+ .errp = &err
-+ };
-+
-+ AuDbgVmRegion(file, vma);
-+ wkq_err = au_wkq_wait_pre(au_call_mmap_pre, &args);
-+ if (unlikely(wkq_err))
-+ err = wkq_err;
-+ if (unlikely(err))
-+ goto out;
-+
-+ au_vm_file_reset(vma, args.h_file);
-+ prot = au_prot_conv(vma->vm_flags);
-+ err = security_file_mmap(args.h_file, /*reqprot*/prot, prot,
-+ au_flag_conv(vma->vm_flags), vma->vm_start, 0);
-+ if (unlikely(err))
-+ goto out_reset;
++ lockdep_on();
+
-+ err = args.h_file->f_op->mmap(args.h_file, vma);
++ au_vm_file_reset(vma, h_file);
++ err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
++ au_flag_conv(vma->vm_flags));
++ if (!err)
++ err = h_file->f_op->mmap(h_file, vma);
+ if (unlikely(err))
+ goto out_reset;
+
-+ au_vm_prfile_set(vma, file);
-+ vfsub_file_accessed(args.h_file);
++ //au_vm_prfile_set(vma, file);
+ /* update without lock, I don't think it a problem */
-+ fsstack_copy_attr_atime(file->f_dentry->d_inode,
-+ args.h_file->f_dentry->d_inode);
++ fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
+ goto out_fput; /* success */
+
+out_reset:
+ au_unset_mmapped(file);
+ au_vm_file_reset(vma, file);
+out_fput:
-+ fput(args.h_file);
++ fput(h_file);
++ lockdep_off();
+out:
++ si_read_unlock(sb);
++ lockdep_on();
++ AuTraceErr(err);
+ return err;
+}
+
+
+ err = -ENOSYS;
+ h_file = au_hf_top(file);
-+ if (h_file->f_op && h_file->f_op->aio_fsync) {
-+ struct dentry *h_d;
++ if (h_file->f_op->aio_fsync) {
+ struct mutex *h_mtx;
+
-+ h_d = h_file->f_dentry;
-+ h_mtx = &h_d->d_inode->i_mutex;
++ h_mtx = &file_inode(h_file)->i_mutex;
+ if (!is_sync_kiocb(kio)) {
+ get_file(h_file);
+ fput(file);
+ goto out;
+
+ h_file = au_hf_top(file);
-+ if (h_file->f_op && h_file->f_op->fasync)
++ if (h_file->f_op->fasync)
+ err = h_file->f_op->fasync(fd, h_file, flag);
+
+ di_read_unlock(dentry, AuLock_IR);
+#endif
+ .unlocked_ioctl = aufs_ioctl_nondir,
+#ifdef CONFIG_COMPAT
-+ .compat_ioctl = aufs_ioctl_nondir, /* same */
++ .compat_ioctl = aufs_compat_ioctl_nondir,
+#endif
+ .mmap = aufs_mmap,
+ .open = aufs_open_nondir,
+};
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,299 @@
++++ linux/fs/aufs/f_op_sp.c 2014-01-30 21:10:02.830814411 +0100
+@@ -0,0 +1,382 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * their file I/O is handled out of aufs.
+ */
+
-+#include <linux/fs_stack.h>
++#include <linux/aio.h>
+#include "aufs.h"
+
-+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;
++/*
++ * 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
++};
+
-+ 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);
++struct au_finfo_sp {
++ struct hlist_node hlist;
++ struct file *file;
++ struct au_finfo *finfo;
++};
+
-+ /* 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);
++struct au_finfo *au_fi_sp(struct file *file)
++{
++ struct au_finfo *finfo;
++ struct au_finfo_sp *sp;
+
-+ return err;
++ 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,
+ /* 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);
-+ if (err > 0 && wbr)
-+ file_update_time(h_file);
-+
+ return err;
+}
+
+ /* 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;
+}
+
+static int au_cpup_sp(struct dentry *dentry)
+{
+ int err;
-+ aufs_bindex_t bcpup;
+ 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("%.*s\n", AuDLNPair(dentry));
++ 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;
-+ bcpup = err;
++ cpg.bdst = err;
+ err = 0;
-+ if (bcpup == au_dbstart(dentry))
++ if (cpg.bdst == au_dbstart(dentry))
+ goto out; /* success */
+
-+ err = au_pin(&pin, dentry, bcpup, au_opt_udba(dentry->d_sb),
++ err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
+ AuPin_MNT_WRITE);
+ if (!err) {
-+ err = au_sio_cpup_simple(dentry, bcpup, -1, AuCpup_DTIME);
++ err = au_sio_cpup_simple(&cpg);
+ au_unpin(&pin);
+ }
+
+ struct file *h_file;
+ struct inode *h_inode;
+
++ err = au_fi_sp_add(file);
++ if (unlikely(err))
++ goto out;
++
+ dentry = file->f_dentry;
-+ AuDbg("%.*s\n", AuDLNPair(dentry));
++ AuDbg("%pd\n", dentry);
+
+ /*
+ * try copying-up.
+ /* prepare h_file */
+ err = au_do_open_nondir(file, vfsub_file_flags(file));
+ if (unlikely(err))
-+ goto out;
++ goto out_del;
+
+ sb = dentry->d_sb;
+ h_file = au_hf_top(file);
-+ h_inode = h_file->f_dentry->d_inode;
++ 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->f_dentry->d_inode, file);
++ 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)
++ if (!err) {
+ au_init_fop_sp(file);
++ goto out; /* success */
++ }
+
++out_del:
++ au_fi_sp_del(file);
+out:
+ return err;
+}
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,497 @@
++++ linux/fs/aufs/fstype.h 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,469 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#include <linux/fs.h>
+#include <linux/magic.h>
+#include <linux/romfs_fs.h>
-+#include <linux/aufs_type.h>
+
+static inline int au_test_aufs(struct super_block *sb)
+{
+#endif
+}
+
-+static inline int au_test_smbfs(struct super_block *sb __maybe_unused)
-+{
-+#if defined(CONFIG_SMB_FS) || defined(CONFIG_SMB_FS_MODULE)
-+ return sb->s_magic == SMB_SUPER_MAGIC;
-+#else
-+ return 0;
-+#endif
-+}
-+
+static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
+{
+#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
+
+static inline int au_test_ext4(struct super_block *sb __maybe_unused)
+{
-+#if defined(CONFIG_EXT4DEV_FS) || defined(CONFIG_EXT4DEV_FS_MODULE)
++#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
+ return sb->s_magic == EXT4_SUPER_MAGIC;
+#else
+ return 0;
+ || au_test_aufs(sb); /* will be supported in next version */
+}
+
-+/*
-+ * If the filesystem supports NFS-export, then it has to support NULL as
-+ * a nameidata parameter for ->create(), ->lookup() and ->d_revalidate().
-+ * We can apply this principle when we handle a lower filesystem.
-+ */
-+static inline int au_test_fs_null_nd(struct super_block *sb)
-+{
-+ return !!sb->s_export_op;
-+}
-+
+static inline int au_test_fs_remote(struct super_block *sb)
+{
+ return !au_test_tmpfs(sb)
+{
+ return au_test_nfs(sb)
+ || au_test_fuse(sb)
-+ /* || au_test_smbfs(sb) */ /* untested */
+ /* || au_test_ocfs2(sb) */ /* untested */
+ /* || au_test_btrfs(sb) */ /* untested */
+ /* || au_test_coda(sb) */ /* untested */
+ || au_test_ramfs(sb)
+#endif
+ || au_test_ubifs(sb)
-+ || au_test_btrfs(sb)
+ || au_test_hfsplus(sb);
+}
+
+{
+ return au_test_fs_remote(sb)
+ || au_test_fs_bad_iattr_size(sb)
-+#ifdef CONFIG_AUFS_BR_RAMFS
-+ || !(au_test_ramfs(sb) || au_test_fs_null_nd(sb))
-+#else
-+ || !au_test_fs_null_nd(sb) /* to keep xino code simple */
-+#endif
+ /* don't want unnecessary work for xino */
+ || au_test_aufs(sb)
+ || au_test_ecryptfs(sb)
+#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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,247 @@
++++ linux/fs/aufs/hfsnotify.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,295 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
+ | FS_CREATE | FS_EVENT_ON_CHILD);
+static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
++static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
+
+static void au_hfsn_free_mark(struct fsnotify_mark *mark)
+{
+ struct au_hnotify *hn = container_of(mark, struct au_hnotify,
+ hn_mark);
+ AuDbg("here\n");
-+ hn->hn_mark_dead = 1;
-+ smp_mb();
-+ wake_up_all(&au_hfsn_wq);
++ au_cache_free_hnotify(hn);
++ smp_mb__before_atomic_dec();
++ if (atomic64_dec_and_test(&au_hfsn_ifree))
++ wake_up(&au_hfsn_wq);
+}
+
+static int au_hfsn_alloc(struct au_hinode *hinode)
+{
++ int err;
+ struct au_hnotify *hn;
+ struct super_block *sb;
+ struct au_branch *br;
+ sb = hn->hn_aufs_inode->i_sb;
+ bindex = au_br_index(sb, hinode->hi_id);
+ br = au_sbr(sb, bindex);
-+ hn->hn_mark_dead = 0;
++ AuDebugOn(!br->br_hfsn);
++
+ mark = &hn->hn_mark;
+ fsnotify_init_mark(mark, au_hfsn_free_mark);
+ mark->mask = AuHfsnMask;
+ * by udba rename or rmdir, aufs assign a new inode to the known
+ * h_inode, so specify 1 to allow dups.
+ */
-+ return fsnotify_add_mark(mark, br->br_hfsn_group, hinode->hi_inode,
++ err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
+ /*mnt*/NULL, /*allow_dups*/1);
++ /* even if err */
++ fsnotify_put_mark(mark);
++
++ return err;
+}
+
-+static void au_hfsn_free(struct au_hinode *hinode)
++static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
+{
-+ struct au_hnotify *hn;
+ struct fsnotify_mark *mark;
++ unsigned long long ull;
++ struct fsnotify_group *group;
++
++ ull = atomic64_inc_return(&au_hfsn_ifree);
++ BUG_ON(!ull);
+
-+ hn = hinode->hi_notify;
+ mark = &hn->hn_mark;
-+ fsnotify_destroy_mark(mark);
-+ fsnotify_put_mark(mark);
++ spin_lock(&mark->lock);
++ group = mark->group;
++ fsnotify_get_group(group);
++ spin_unlock(&mark->lock);
++ fsnotify_destroy_mark(mark, group);
++ fsnotify_put_group(group);
+
-+ /* TODO: bad approach */
-+ wait_event(au_hfsn_wq, hn->hn_mark_dead);
++ /* free hn by myself */
++ return 0;
+}
+
+/* ---------------------------------------------------------------------- */
+static char *au_hfsn_name(u32 mask)
+{
+#ifdef CONFIG_AUFS_DEBUG
-+#define test_ret(flag) if (mask & flag) \
-+ return #flag;
++#define test_ret(flag) \
++ do { \
++ if (mask & flag) \
++ return #flag; \
++ } while (0)
+ test_ret(FS_ACCESS);
+ test_ret(FS_MODIFY);
+ test_ret(FS_ATTRIB);
+
+/* ---------------------------------------------------------------------- */
+
++static void au_hfsn_free_group(struct fsnotify_group *group)
++{
++ struct au_br_hfsnotify *hfsn = group->private;
++
++ AuDbg("here\n");
++ kfree(hfsn);
++}
++
+static int au_hfsn_handle_event(struct fsnotify_group *group,
+ struct fsnotify_mark *inode_mark,
+ struct fsnotify_mark *vfsmount_mark,
+ struct au_hnotify *hnotify;
+ struct inode *h_dir, *h_inode;
+ __u32 mask;
-+ struct qstr h_child_qstr = {
-+ .name = event->file_name,
-+ .len = event->name_len
-+ };
++ struct qstr h_child_qstr = QSTR_INIT(event->file_name, event->name_len);
+
+ AuDebugOn(event->data_type != FSNOTIFY_EVENT_INODE);
+
+ h_dir = event->to_tell;
+ h_inode = event->inode;
+#ifdef AuDbgHnotify
-+ au_debug(1);
++ au_debug_on();
+ if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
+ || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
+ AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
+ AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
+ /* WARN_ON(1); */
+ }
-+ au_debug(0);
++ au_debug_off();
+#endif
+
+ AuDebugOn(!inode_mark);
+
+static struct fsnotify_ops au_hfsn_ops = {
+ .should_send_event = au_hfsn_should_send_event,
-+ .handle_event = au_hfsn_handle_event
++ .handle_event = au_hfsn_handle_event,
++ .free_group_priv = au_hfsn_free_group
+};
+
+/* ---------------------------------------------------------------------- */
+
+static void au_hfsn_fin_br(struct au_branch *br)
+{
-+ if (br->br_hfsn_group)
-+ fsnotify_put_group(br->br_hfsn_group);
-+}
++ struct au_br_hfsnotify *hfsn;
+
-+static int au_hfsn_init_br(struct au_branch *br, int perm)
-+{
-+ br->br_hfsn_group = NULL;
-+ br->br_hfsn_ops = au_hfsn_ops;
-+ return 0;
++ hfsn = br->br_hfsn;
++ if (hfsn)
++ fsnotify_put_group(hfsn->hfsn_group);
+}
+
-+static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
++static int au_hfsn_init_br(struct au_branch *br, int perm)
+{
+ int err;
++ struct fsnotify_group *group;
++ struct au_br_hfsnotify *hfsn;
+
+ err = 0;
-+ if (udba != AuOpt_UDBA_HNOTIFY
-+ || !au_br_hnotifyable(perm)) {
-+ au_hfsn_fin_br(br);
-+ br->br_hfsn_group = NULL;
++ br->br_hfsn = NULL;
++ if (!au_br_hnotifyable(perm))
+ goto out;
-+ }
+
-+ if (br->br_hfsn_group)
++ err = -ENOMEM;
++ hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
++ if (unlikely(!hfsn))
+ goto out;
+
-+ br->br_hfsn_group = fsnotify_alloc_group(&br->br_hfsn_ops);
-+ if (IS_ERR(br->br_hfsn_group)) {
-+ err = PTR_ERR(br->br_hfsn_group);
++ err = 0;
++ group = fsnotify_alloc_group(&au_hfsn_ops);
++ if (IS_ERR(group)) {
++ err = PTR_ERR(group);
+ pr_err("fsnotify_alloc_group() failed, %d\n", err);
-+ br->br_hfsn_group = NULL;
++ goto out_hfsn;
+ }
+
++ group->private = hfsn;
++ hfsn->hfsn_group = group;
++ br->br_hfsn = hfsn;
++ goto out; /* success */
++
++out_hfsn:
++ kfree(hfsn);
+out:
-+ AuTraceErr(err);
+ return err;
+}
+
++static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
++{
++ int err;
++
++ err = 0;
++ if (!br->br_hfsn)
++ err = au_hfsn_init_br(br, perm);
++
++ return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++static void au_hfsn_fin(void)
++{
++ AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
++ wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
++}
++
+const struct au_hnotify_op au_hnotify_op = {
+ .ctl = au_hfsn_ctl,
+ .alloc = au_hfsn_alloc,
+ .free = au_hfsn_free,
+
++ .fin = au_hfsn_fin,
++
+ .reset_br = au_hfsn_reset_br,
+ .fin_br = au_hfsn_fin_br,
+ .init_br = au_hfsn_init_br
+};
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,58 @@
++++ linux/fs/aufs/hfsplus.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,56 @@
+/*
-+ * Copyright (C) 2010-2011 Junjiro R. Okajima
++ * Copyright (C) 2010-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, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * and au_h_open_post() after releasing it.
+ */
+
-+#include <linux/file.h>
+#include "aufs.h"
+
-+struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex)
++struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
++ int force_wr)
+{
+ struct file *h_file;
+ struct dentry *h_dentry;
+ h_dentry = au_h_dptr(dentry, bindex);
+ AuDebugOn(!h_dentry);
+ AuDebugOn(!h_dentry->d_inode);
-+ IMustLock(h_dentry->d_inode);
+
+ h_file = NULL;
+ if (au_test_hfsplus(h_dentry->d_sb)
+ && S_ISREG(h_dentry->d_inode->i_mode))
+ h_file = au_h_open(dentry, bindex,
+ O_RDONLY | O_NOATIME | O_LARGEFILE,
-+ /*file*/NULL);
++ /*file*/NULL, force_wr);
+ return h_file;
+}
+
+}
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 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,712 @@
++++ linux/fs/aufs/hnotify.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,710 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+ hn = hinode->hi_notify;
+ if (hn) {
-+ au_hnotify_op.free(hinode);
-+ au_cache_free_hnotify(hn);
+ hinode->hi_notify = NULL;
++ if (au_hnotify_op.free(hinode, hn))
++ au_cache_free_hnotify(hn);
+ }
+}
+
+
+ err = 0;
+ if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
-+ pr_warning("branch root dir was changed\n");
++ pr_warn("branch root dir was changed\n");
+ goto out;
+ }
+
+
+ err = 1;
+ if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
-+ pr_warning("branch root dir was changed\n");
++ pr_warn("branch root dir was changed\n");
+ err = 0;
+ goto out;
+ }
+ AuDebugOn(!name);
+ au_iigen_dec(inode);
+ spin_lock(&inode->i_lock);
-+ list_for_each_entry(d, &inode->i_dentry, d_alias) {
++ hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
+ spin_lock(&d->d_lock);
+ dname = &d->d_name;
+ if (dname->len != nlen
+ if (IS_ROOT(dentry)
+ /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
+ ) {
-+ pr_warning("branch root dir was changed\n");
++ pr_warn("branch root dir was changed\n");
+ return 0;
+ }
+
+ if (au_ftest_hnjob(a->flags, MNTPNT)
+ && a->dentry
+ && d_mountpoint(a->dentry))
-+ pr_warning("mount-point %.*s is removed or renamed\n",
-+ AuDLNPair(a->dentry));
++ pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
+
+ return 0;
+}
+ dentry = NULL;
+ spin_lock(&parent->d_lock);
+ list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
-+ /* AuDbg("%.*s\n", AuDLNPair(d)); */
++ /* AuDbg("%pd\n", d); */
+ spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
+ dname = &d->d_name;
+ if (dname->len != nlen || memcmp(dname->name, name, nlen))
+ au_digen_dec(d);
+ else
+ goto cont_unlock;
-+ if (d->d_count) {
++ if (d_count(d)) {
+ dentry = dget_dlock(d);
+ spin_unlock(&d->d_lock);
+ break;
+ }
+
-+ cont_unlock:
++cont_unlock:
+ spin_unlock(&d->d_lock);
+ }
+ spin_unlock(&parent->d_lock);
+ goto out;
+
+ if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
-+ pr_warning("wrong root branch\n");
++ pr_warn("wrong root branch\n");
+ iput(inode);
+ inode = NULL;
+ goto out;
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,264 @@
++++ linux/fs/aufs/iinfo.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,275 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ hinode->hi_whdentry = h_wh;
+}
+
-+void au_update_iigen(struct inode *inode)
++void au_update_iigen(struct inode *inode, int half)
+{
-+ atomic_set(&au_ii(inode)->ii_generation, au_sigen(inode->i_sb));
-+ /* smp_mb(); */ /* atomic_set */
++ struct au_iinfo *iinfo;
++ struct au_iigen *iigen;
++ unsigned int sigen;
++
++ sigen = au_sigen(inode->i_sb);
++ iinfo = au_ii(inode);
++ iigen = &iinfo->ii_generation;
++ spin_lock(&iinfo->ii_genspin);
++ iigen->ig_generation = sigen;
++ if (half)
++ au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
++ else
++ au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
++ spin_unlock(&iinfo->ii_genspin);
+}
+
+/* it may be called at remount time, too */
+ struct au_iinfo *iinfo = &c->iinfo;
+ static struct lock_class_key aufs_ii;
+
++ spin_lock_init(&iinfo->ii_genspin);
+ au_rw_init(&iinfo->ii_rwsem);
+ au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
+ inode_init_once(&c->vfs_inode);
+ for (i = 0; i < nbr; i++)
+ iinfo->ii_hinode[i].hi_id = -1;
+
-+ atomic_set(&iinfo->ii_generation, au_sigen(sb));
-+ /* smp_mb(); */ /* atomic_set */
++ iinfo->ii_generation.ig_generation = au_sigen(sb);
+ iinfo->ii_bstart = -1;
+ iinfo->ii_bend = -1;
+ iinfo->ii_vdir = NULL;
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,471 @@
++++ linux/fs/aufs/inode.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,491 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+static void au_refresh_hinode_attr(struct inode *inode, int do_version)
+{
+ au_cpup_attr_all(inode, /*force*/0);
-+ au_update_iigen(inode);
++ au_update_iigen(inode, /*half*/1);
+ if (do_version)
+ inode->i_version++;
+}
+static int reval_inode(struct inode *inode, struct dentry *dentry)
+{
+ int err;
++ unsigned int gen;
++ struct au_iigen iigen;
+ aufs_bindex_t bindex, bend;
+ struct inode *h_inode, *h_dinode;
+
+ bend = au_ibend(inode);
+ for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
+ h_inode = au_h_iptr(inode, bindex);
-+ if (h_inode && h_inode == h_dinode) {
-+ err = 0;
-+ if (au_iigen_test(inode, au_digen(dentry)))
-+ err = au_refresh_hinode(inode, dentry);
++ if (!h_inode || h_inode != h_dinode)
++ continue;
++
++ err = 0;
++ gen = au_iigen(inode, &iigen);
++ if (gen == au_digen(dentry)
++ && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
+ break;
-+ }
++
++ /* fully refresh inode using dentry */
++ err = au_refresh_hinode(inode, dentry);
++ if (!err)
++ au_update_iigen(inode, /*half*/0);
++ break;
+ }
+
+ if (unlikely(err))
+
+ AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
+ if (inode->i_state & I_NEW) {
++ /* verbose coding for lock class name */
++ if (unlikely(S_ISLNK(h_inode->i_mode)))
++ au_rw_class(&au_ii(inode)->ii_rwsem,
++ au_lc_key + AuLcSymlink_IIINFO);
++ else if (unlikely(S_ISDIR(h_inode->i_mode)))
++ au_rw_class(&au_ii(inode)->ii_rwsem,
++ au_lc_key + AuLcDir_IIINFO);
++ else /* likely */
++ au_rw_class(&au_ii(inode)->ii_rwsem,
++ au_lc_key + AuLcNonDir_IIINFO);
++
+ ii_write_lock_new_child(inode);
+ err = set_inode(inode, dentry);
+ if (!err) {
+
+ if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
+ AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
-+ " b%d, %s, %.*s, hi%lu, i%lu.\n",
-+ bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
++ " b%d, %s, %pd, hi%lu, i%lu.\n",
++ bstart, au_sbtype(h_dentry->d_sb), dentry,
+ (unsigned long)h_ino, (unsigned long)ino);
+ ino = 0;
+ err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
+
+int au_test_h_perm(struct inode *h_inode, int mask)
+{
-+ if (!current_fsuid())
++ if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
+ return 0;
+ return inode_permission(h_inode, mask);
+}
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,556 @@
++++ linux/fs/aufs/inode.h 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,599 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/fs.h>
+#include <linux/fsnotify.h>
-+#include <linux/aufs_type.h>
+#include "rwsem.h"
+
+struct vfsmount;
+#ifdef CONFIG_AUFS_HFSNOTIFY
+ /* never use fsnotify_add_vfsmount_mark() */
+ struct fsnotify_mark hn_mark;
-+ int hn_mark_dead;
+#endif
+ struct inode *hn_aufs_inode; /* no get/put */
+#endif
+ struct dentry *hi_whdentry;
+};
+
++/* ig_flags */
++#define AuIG_HALF_REFRESHED 1
++#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
++#define au_ig_fset(flags, name) \
++ do { (flags) |= AuIG_##name; } while (0)
++#define au_ig_fclr(flags, name) \
++ do { (flags) &= ~AuIG_##name; } while (0)
++
++struct au_iigen {
++ __u32 ig_generation, ig_flags;
++};
++
+struct au_vdir;
+struct au_iinfo {
-+ atomic_t ii_generation;
++ spinlock_t ii_genspin;
++ struct au_iigen ii_generation;
+ struct super_block *ii_hsb1; /* no get/put */
+
+ struct au_rwsem ii_rwsem;
+ struct dentry *parent;
+ struct au_hinode *hdir;
+ struct vfsmount *h_mnt;
++
++ /* temporary unlock/relock for copyup */
++ struct dentry *h_dentry, *h_parent;
++ struct au_branch *br;
++ struct task_struct *task;
+};
+
++void au_pin_hdir_unlock(struct au_pin *p);
++int au_pin_hdir_relock(struct au_pin *p);
++void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
++void au_pin_hdir_acquire_nest(struct au_pin *p);
++void au_pin_hdir_release(struct au_pin *p);
++
+/* ---------------------------------------------------------------------- */
+
+static inline struct au_iinfo *au_ii(struct inode *inode)
+
+/* au_wr_dir flags */
+#define AuWrDir_ADD_ENTRY 1
-+#define AuWrDir_ISDIR (1 << 1)
++#define AuWrDir_TMP_WHENTRY (1 << 1)
++#define AuWrDir_ISDIR (1 << 2)
+#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
+#define au_fset_wrdir(flags, name) \
+ do { (flags) |= AuWrDir_##name; } while (0)
+/* i_op_add.c */
+int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
+ struct dentry *h_parent, int isdir);
-+int aufs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
++int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
++ dev_t dev);
+int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
-+int aufs_create(struct inode *dir, struct dentry *dentry, int mode,
-+ struct nameidata *nd);
++int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
++ bool want_excl);
+int aufs_link(struct dentry *src_dentry, struct inode *dir,
+ struct dentry *dentry);
-+int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
++int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
+
+/* i_op_del.c */
+int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
+void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
+ struct inode *h_inode, unsigned int flags);
+
-+void au_update_iigen(struct inode *inode);
++void au_update_iigen(struct inode *inode, int half);
+void au_update_ibrange(struct inode *inode, int do_put_zero);
+
+void au_icntnr_init_once(void *_c);
+#endif
+}
+
-+static inline unsigned int au_iigen(struct inode *inode)
++static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
+{
-+ return atomic_read(&au_ii(inode)->ii_generation);
++ unsigned int gen;
++ struct au_iinfo *iinfo;
++
++ iinfo = au_ii(inode);
++ spin_lock(&iinfo->ii_genspin);
++ if (iigen)
++ *iigen = iinfo->ii_generation;
++ gen = iinfo->ii_generation.ig_generation;
++ spin_unlock(&iinfo->ii_genspin);
++
++ return gen;
+}
+
+/* tiny test for inode number */
+
+static inline void au_iigen_dec(struct inode *inode)
+{
-+ atomic_dec(&au_ii(inode)->ii_generation);
++ struct au_iinfo *iinfo;
++
++ iinfo = au_ii(inode);
++ spin_lock(&iinfo->ii_genspin);
++ iinfo->ii_generation.ig_generation--;
++ spin_unlock(&iinfo->ii_genspin);
+}
+
+static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
+ int err;
+
+ err = 0;
-+ if (unlikely(inode && au_iigen(inode) != sigen))
++ if (unlikely(inode && au_iigen(inode, NULL) != sigen))
+ err = -EIO;
+
+ return err;
+struct au_hnotify_op {
+ void (*ctl)(struct au_hinode *hinode, int do_set);
+ int (*alloc)(struct au_hinode *hinode);
-+ void (*free)(struct au_hinode *hinode);
++
++ /*
++ * if it returns true, the the caller should free hinode->hi_notify,
++ * otherwise ->free() frees it.
++ */
++ int (*free)(struct au_hinode *hinode,
++ struct au_hnotify *hn) __must_check;
+
+ void (*fin)(void);
+ int (*init)(void);
+#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 2011-10-24 20:51:51.580466925 +0200
-@@ -0,0 +1,197 @@
++++ linux/fs/aufs/ioctl.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,201 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * ioctl
+ * plink-management and readdir in userspace.
+ * assist the pathconf(3) wrapper library.
++ * move-down
+ */
+
++#include <linux/compat.h>
+#include <linux/file.h>
+#include "aufs.h"
+
+ }
+ AuDbg("wbi %d\n", wbi);
+ if (wbi >= 0)
-+ h_file = au_h_open(root, wbi, wbrfd.oflags, NULL);
++ h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
++ /*force_wr*/0);
+
+out_unlock:
+ aufs_read_unlock(root, AuLock_IR);
+ long err;
+
+ switch (cmd) {
++ case AUFS_CTL_MVDOWN:
++ err = au_mvdown(file->f_dentry, (void __user *)arg);
++ break;
++
+ case AUFS_CTL_WBR_FD:
+ err = au_wbr_fd(&file->f_path, (void __user *)arg);
+ break;
+ return err;
+}
+
-+#if 0 /* unused yet */
+long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+ return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
-+#endif
diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
--- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/i_op_add.c 2011-10-24 20:51:51.580466925 +0200
-@@ -0,0 +1,711 @@
++++ linux/fs/aufs/i_op_add.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,762 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
+ rerr = PTR_ERR(wh);
+ if (IS_ERR(wh)) {
-+ AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
-+ AuDLNPair(dentry), err, rerr);
++ AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
++ dentry, err, rerr);
+ err = -EIO;
+ } else
+ dput(wh);
+ unsigned int udba;
+ aufs_bindex_t bcpup;
+
-+ AuDbg("%.*s\n", AuDLNPair(dentry));
++ AuDbg("%pd\n", dentry);
+
+ err = au_wr_dir(dentry, src_dentry, wr_dir_args);
+ bcpup = err;
+ if (dt) {
+ struct path tmp = {
+ .dentry = h_parent,
-+ .mnt = br->br_mnt
++ .mnt = au_br_mnt(br)
+ };
+ au_dtime_store(dt, au_pinned_parent(pin), &tmp);
+ }
+ int type;
+ union {
+ struct {
-+ int mode;
-+ struct nameidata *nd;
++ umode_t mode;
++ bool want_excl;
+ } c;
+ struct {
+ const char *symname;
+ } s;
+ struct {
-+ int mode;
++ umode_t mode;
+ dev_t dev;
+ } m;
+ } u;
+ int err;
+ aufs_bindex_t bstart;
+ unsigned char created;
-+ struct au_dtime dt;
-+ struct au_pin pin;
-+ struct path h_path;
+ struct dentry *wh_dentry, *parent;
+ struct inode *h_dir;
-+ struct au_wr_dir_args wr_dir_args = {
-+ .force_btgt = -1,
-+ .flags = AuWrDir_ADD_ENTRY
-+ };
++ /* to reuduce stack size */
++ struct {
++ struct au_dtime dt;
++ struct au_pin pin;
++ struct path h_path;
++ struct au_wr_dir_args wr_dir_args;
++ } *a;
+
-+ AuDbg("%.*s\n", AuDLNPair(dentry));
++ AuDbg("%pd\n", dentry);
+ IMustLock(dir);
+
++ err = -ENOMEM;
++ a = kmalloc(sizeof(*a), GFP_NOFS);
++ if (unlikely(!a))
++ goto out;
++ a->wr_dir_args.force_btgt = -1;
++ a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
++
+ parent = dentry->d_parent; /* dir inode is locked */
+ err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
+ if (unlikely(err))
-+ goto out;
++ goto out_free;
+ err = au_d_may_add(dentry);
+ if (unlikely(err))
+ goto out_unlock;
+ di_write_lock_parent(parent);
-+ wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
-+ &wr_dir_args);
++ wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
++ &a->pin, &a->wr_dir_args);
+ err = PTR_ERR(wh_dentry);
+ if (IS_ERR(wh_dentry))
+ goto out_parent;
+
+ bstart = au_dbstart(dentry);
-+ h_path.dentry = au_h_dptr(dentry, bstart);
-+ h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
-+ h_dir = au_pinned_h_dir(&pin);
++ a->h_path.dentry = au_h_dptr(dentry, bstart);
++ a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
++ h_dir = au_pinned_h_dir(&a->pin);
+ switch (arg->type) {
+ case Creat:
-+ err = vfsub_create(h_dir, &h_path, arg->u.c.mode);
++ err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
++ arg->u.c.want_excl);
+ break;
+ case Symlink:
-+ err = vfsub_symlink(h_dir, &h_path, arg->u.s.symname);
++ err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
+ break;
+ case Mknod:
-+ err = vfsub_mknod(h_dir, &h_path, arg->u.m.mode, arg->u.m.dev);
++ err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
++ arg->u.m.dev);
+ break;
+ default:
+ BUG();
+ err = epilog(dir, bstart, wh_dentry, dentry);
+
+ /* revert */
-+ if (unlikely(created && err && h_path.dentry->d_inode)) {
++ if (unlikely(created && err && a->h_path.dentry->d_inode)) {
+ int rerr;
-+ rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
++ /* no delegation since it is just created */
++ rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
++ /*force*/0);
+ if (rerr) {
-+ AuIOErr("%.*s revert failure(%d, %d)\n",
-+ AuDLNPair(dentry), err, rerr);
++ AuIOErr("%pd revert failure(%d, %d)\n",
++ dentry, err, rerr);
+ err = -EIO;
+ }
-+ au_dtime_revert(&dt);
++ au_dtime_revert(&a->dt);
+ }
+
-+ au_unpin(&pin);
++ au_unpin(&a->pin);
+ dput(wh_dentry);
+
+out_parent:
+ d_drop(dentry);
+ }
+ aufs_read_unlock(dentry, AuLock_DW);
++out_free:
++ kfree(a);
+out:
+ return err;
+}
+
-+int aufs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
++int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
++ dev_t dev)
+{
+ struct simple_arg arg = {
+ .type = Mknod,
+ return add_simple(dir, dentry, &arg);
+}
+
-+int aufs_create(struct inode *dir, struct dentry *dentry, int mode,
-+ struct nameidata *nd)
++int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
++ bool want_excl)
+{
+ struct simple_arg arg = {
+ .type = Creat,
+ .u.c = {
-+ .mode = mode,
-+ .nd = nd
++ .mode = mode,
++ .want_excl = want_excl
+ }
+ };
+ return add_simple(dir, dentry, &arg);
+{
+ int err;
+ struct dentry *h_src_dentry;
-+ struct mutex *h_mtx;
-+ struct file *h_file;
++ struct au_cp_generic cpg = {
++ .dentry = src_dentry,
++ .bdst = a->bdst,
++ .bsrc = a->bsrc,
++ .len = -1,
++ .pin = &a->pin,
++ .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
++ };
+
+ di_read_lock_parent(a->src_parent, AuLock_IR);
+ err = au_test_and_cpup_dirs(src_dentry, a->bdst);
+ goto out;
+
+ h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
-+ h_mtx = &h_src_dentry->d_inode->i_mutex;
+ err = au_pin(&a->pin, src_dentry, a->bdst,
+ au_opt_udba(src_dentry->d_sb),
+ AuPin_DI_LOCKED | AuPin_MNT_WRITE);
+ if (unlikely(err))
+ goto out;
-+ mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
-+ h_file = au_h_open_pre(src_dentry, a->bsrc);
-+ if (IS_ERR(h_file)) {
-+ err = PTR_ERR(h_file);
-+ h_file = NULL;
-+ } else
-+ err = au_sio_cpup_simple(src_dentry, a->bdst, -1,
-+ AuCpup_DTIME /* | AuCpup_KEEPLINO */);
-+ mutex_unlock(h_mtx);
-+ au_h_open_post(src_dentry, a->bsrc, h_file);
++
++ err = au_sio_cpup_simple(&cpg);
+ au_unpin(&a->pin);
+
+out:
+ return err;
+}
+
-+static int au_cpup_or_link(struct dentry *src_dentry, struct au_link_args *a)
++static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
++ struct au_link_args *a)
+{
+ int err;
+ unsigned char plink;
-+ struct inode *h_inode, *inode;
++ aufs_bindex_t bend;
+ struct dentry *h_src_dentry;
++ struct inode *h_inode, *inode, *delegated;
+ struct super_block *sb;
+ struct file *h_file;
+
+ h_inode = au_h_iptr(inode, a->bdst);
+ if (!h_inode || !h_inode->i_nlink) {
+ /* copyup src_dentry as the name of dentry. */
-+ au_set_dbstart(src_dentry, a->bdst);
-+ au_set_h_dptr(src_dentry, a->bdst, dget(a->h_path.dentry));
-+ h_inode = au_h_dptr(src_dentry, a->bsrc)->d_inode;
-+ mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+ h_file = au_h_open_pre(src_dentry, a->bsrc);
-+ if (IS_ERR(h_file)) {
++ bend = au_dbend(dentry);
++ if (bend < a->bsrc)
++ au_set_dbend(dentry, a->bsrc);
++ au_set_h_dptr(dentry, a->bsrc,
++ dget(au_h_dptr(src_dentry, a->bsrc)));
++ dget(a->h_path.dentry);
++ au_set_h_dptr(dentry, a->bdst, NULL);
++ dentry->d_inode = src_dentry->d_inode; /* tmp */
++ h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
++ if (IS_ERR(h_file))
+ err = PTR_ERR(h_file);
-+ h_file = NULL;
-+ } else
-+ err = au_sio_cpup_single(src_dentry, a->bdst, a->bsrc,
-+ -1, AuCpup_KEEPLINO,
-+ a->parent);
-+ mutex_unlock(&h_inode->i_mutex);
-+ au_h_open_post(src_dentry, a->bsrc, h_file);
-+ au_set_h_dptr(src_dentry, a->bdst, NULL);
-+ au_set_dbstart(src_dentry, a->bsrc);
++ else {
++ struct au_cp_generic cpg = {
++ .dentry = dentry,
++ .bdst = a->bdst,
++ .bsrc = -1,
++ .len = -1,
++ .pin = &a->pin,
++ .flags = AuCpup_KEEPLINO
++ };
++ err = au_sio_cpup_simple(&cpg);
++ au_h_open_post(dentry, a->bsrc, h_file);
++ if (!err) {
++ dput(a->h_path.dentry);
++ a->h_path.dentry = au_h_dptr(dentry, a->bdst);
++ } else
++ au_set_h_dptr(dentry, a->bdst,
++ a->h_path.dentry);
++ }
++ dentry->d_inode = NULL; /* restore */
++ au_set_h_dptr(dentry, a->bsrc, NULL);
++ au_set_dbend(dentry, bend);
+ } else {
+ /* the inode of src_dentry already exists on a.bdst branch */
+ h_src_dentry = d_find_alias(h_inode);
+
+ }
+ if (h_src_dentry) {
++ delegated = NULL;
+ err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
-+ &a->h_path);
++ &a->h_path, &delegated);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal link\n");
++ iput(delegated);
++ }
+ dput(h_src_dentry);
+ } else {
+ AuIOErr("no dentry found for hi%lu on b%d\n",
+ struct au_dtime dt;
+ struct au_link_args *a;
+ struct dentry *wh_dentry, *h_src_dentry;
-+ struct inode *inode;
++ struct inode *inode, *delegated;
+ struct super_block *sb;
+ struct au_wr_dir_args wr_dir_args = {
+ /* .force_btgt = -1, */
+ if (au_opt_test(au_mntflags(sb), PLINK)) {
+ if (a->bdst < a->bsrc
+ /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
-+ err = au_cpup_or_link(src_dentry, a);
-+ else
++ err = au_cpup_or_link(src_dentry, dentry, a);
++ else {
++ delegated = NULL;
+ err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
-+ &a->h_path);
++ &a->h_path, &delegated);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal link\n");
++ iput(delegated);
++ }
++ }
+ dput(h_src_dentry);
+ } else {
+ /*
+ if (!err) {
+ h_src_dentry = au_h_dptr(src_dentry, a->bdst);
+ err = -ENOENT;
-+ if (h_src_dentry && h_src_dentry->d_inode)
++ if (h_src_dentry && h_src_dentry->d_inode) {
++ delegated = NULL;
+ err = vfsub_link(h_src_dentry,
+ au_pinned_h_dir(&a->pin),
-+ &a->h_path);
++ &a->h_path, &delegated);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry"
++ " for NFSv4 delegation"
++ " for an internal link\n");
++ iput(delegated);
++ }
++ }
+ }
+ }
+ if (unlikely(err))
+ goto out_unpin; /* success */
+
+out_revert:
-+ rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
++ /* no delegation since it is just created */
++ rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
++ /*delegated*/NULL, /*force*/0);
+ if (unlikely(rerr)) {
-+ AuIOErr("%.*s reverting failed(%d, %d)\n",
-+ AuDLNPair(dentry), err, rerr);
++ AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
+ err = -EIO;
+ }
+ au_dtime_revert(&dt);
+out_kfree:
+ kfree(a);
+out:
++ AuTraceErr(err);
+ return err;
+}
+
-+int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
++int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
+{
+ int err, rerr;
+ aufs_bindex_t bindex;
+ rerr = au_diropq_remove(dentry, bindex);
+ mutex_unlock(h_mtx);
+ if (rerr) {
-+ AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
-+ AuDLNPair(dentry), err, rerr);
++ AuIOErr("%pd reverting diropq failed(%d, %d)\n",
++ dentry, err, rerr);
+ err = -EIO;
+ }
+ }
+ AuLabel(revert dir);
+ rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
+ if (rerr) {
-+ AuIOErr("%.*s reverting dir failed(%d, %d)\n",
-+ AuDLNPair(dentry), err, rerr);
++ AuIOErr("%pd reverting dir failed(%d, %d)\n",
++ dentry, err, rerr);
+ err = -EIO;
+ }
+ au_dtime_revert(&a->dt);
+}
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 2011-10-24 20:52:23.677857076 +0200
-@@ -0,0 +1,974 @@
++++ linux/fs/aufs/i_op.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,1127 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#include <linux/mm.h>
+#include <linux/namei.h>
+#include <linux/security.h>
-+#include <linux/uaccess.h>
+#include "aufs.h"
+
+static int h_permission(struct inode *h_inode, int mask,
+ err = 0;
+ bindex = au_ibstart(inode);
+ br = au_sbr(sb, bindex);
-+ err = h_permission(h_inode, mask, br->br_mnt, br->br_perm);
++ err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
+ if (write_mask
+ && !err
+ && !special_file(h_inode->i_mode)) {
+ break;
+
+ br = au_sbr(sb, bindex);
-+ err = h_permission(h_inode, mask, br->br_mnt,
++ err = h_permission(h_inode, mask, au_br_mnt(br),
+ br->br_perm);
+ }
+ }
+/* ---------------------------------------------------------------------- */
+
+static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
-+ struct nameidata *nd)
++ unsigned int flags)
+{
+ struct dentry *ret, *parent;
+ struct inode *inode;
+
+ IMustLock(dir);
+
++ /* todo: support rcu-walk? */
++ ret = ERR_PTR(-ECHILD);
++ if (flags & LOOKUP_RCU)
++ goto out;
++
++ ret = ERR_PTR(-ENAMETOOLONG);
++ if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
++ goto out;
++
+ sb = dir->i_sb;
+ err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
+ ret = ERR_PTR(err);
+ if (unlikely(err))
+ goto out;
+
-+ ret = ERR_PTR(-ENAMETOOLONG);
-+ if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
-+ goto out_si;
+ err = au_di_init(dentry);
+ ret = ERR_PTR(err);
+ if (unlikely(err))
+ goto out_si;
+
++ inode = NULL;
+ npositive = 0; /* suppress a warning */
+ parent = dentry->d_parent; /* dir inode is locked */
+ di_read_lock_parent(parent, AuLock_IR);
+ err = au_digen_test(parent, au_sigen(sb));
+ if (!err) {
+ npositive = au_lkup_dentry(dentry, au_dbstart(parent),
-+ /*type*/0, nd);
++ /*type*/0);
+ err = npositive;
+ }
+ di_read_unlock(parent, AuLock_IR);
+ if (unlikely(err < 0))
+ goto out_unlock;
+
-+ inode = NULL;
+ if (npositive) {
+ inode = au_new_inode(dentry, /*must_new*/0);
+ ret = (void *)inode;
+ }
-+ if (IS_ERR(inode))
++ if (IS_ERR(inode)) {
++ inode = NULL;
+ goto out_unlock;
++ }
+
+ ret = d_splice_alias(inode, dentry);
++#if 0
++ if (unlikely(d_need_lookup(dentry))) {
++ spin_lock(&dentry->d_lock);
++ dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
++ spin_unlock(&dentry->d_lock);
++ } else
++#endif
+ if (unlikely(IS_ERR(ret) && inode)) {
+ ii_write_unlock(inode);
+ iput(inode);
++ inode = NULL;
+ }
+
+out_unlock:
+ di_write_unlock(dentry);
++ if (inode) {
++ /* verbose coding for lock class name */
++ if (unlikely(S_ISLNK(inode->i_mode)))
++ au_rw_class(&au_di(dentry)->di_rwsem,
++ au_lc_key + AuLcSymlink_DIINFO);
++ else if (unlikely(S_ISDIR(inode->i_mode)))
++ au_rw_class(&au_di(dentry)->di_rwsem,
++ au_lc_key + AuLcDir_DIINFO);
++ else /* likely */
++ au_rw_class(&au_di(dentry)->di_rwsem,
++ au_lc_key + AuLcNonDir_DIINFO);
++ }
+out_si:
+ si_read_unlock(sb);
+out:
+
+ err = 0;
+ if (!au_h_dptr(parent, bcpup)) {
-+ if (bstart < bcpup)
++ if (bstart > bcpup)
++ err = au_cpup_dirs(dentry, bcpup);
++ else if (bstart < bcpup)
+ err = au_cpdown_dirs(dentry, bcpup);
+ else
-+ err = au_cpup_dirs(dentry, bcpup);
++ BUG();
+ }
+ if (!err && add_entry) {
+ h_parent = au_h_dptr(parent, bcpup);
+ h_dir = h_parent->d_inode;
+ mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
-+ err = au_lkup_neg(dentry, bcpup);
++ err = au_lkup_neg(dentry, bcpup,
++ au_ftest_wrdir(add_entry, TMP_WHENTRY));
+ /* todo: no unlock here */
+ mutex_unlock(&h_dir->i_mutex);
+
+ struct au_wr_dir_args *args)
+{
+ int err;
++ unsigned int flags;
+ aufs_bindex_t bcpup, bstart, src_bstart;
-+ const unsigned char add_entry = !!au_ftest_wrdir(args->flags,
-+ ADD_ENTRY);
++ const unsigned char add_entry
++ = au_ftest_wrdir(args->flags, ADD_ENTRY)
++ | au_ftest_wrdir(args->flags, TMP_WHENTRY);
+ struct super_block *sb;
+ struct dentry *parent;
+ struct au_sbinfo *sbinfo;
+ if (src_bstart < bstart)
+ bcpup = src_bstart;
+ } else if (add_entry) {
-+ err = AuWbrCreate(sbinfo, dentry,
-+ au_ftest_wrdir(args->flags, ISDIR));
++ flags = 0;
++ if (au_ftest_wrdir(args->flags, ISDIR))
++ au_fset_wbr(flags, DIR);
++ err = AuWbrCreate(sbinfo, dentry, flags);
+ bcpup = err;
+ }
+
+
+/* ---------------------------------------------------------------------- */
+
++void au_pin_hdir_unlock(struct au_pin *p)
++{
++ if (p->hdir)
++ au_hn_imtx_unlock(p->hdir);
++}
++
++static int au_pin_hdir_lock(struct au_pin *p)
++{
++ int err;
++
++ err = 0;
++ if (!p->hdir)
++ goto out;
++
++ /* even if an error happens later, keep this lock */
++ au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
++
++ err = -EBUSY;
++ if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
++ goto out;
++
++ err = 0;
++ if (p->h_dentry)
++ err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
++ p->h_parent, p->br);
++
++out:
++ return err;
++}
++
++int au_pin_hdir_relock(struct au_pin *p)
++{
++ int err, i;
++ struct inode *h_i;
++ struct dentry *h_d[] = {
++ p->h_dentry,
++ p->h_parent
++ };
++
++ err = au_pin_hdir_lock(p);
++ if (unlikely(err))
++ goto out;
++
++ for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
++ if (!h_d[i])
++ continue;
++ h_i = h_d[i]->d_inode;
++ if (h_i)
++ err = !h_i->i_nlink;
++ }
++
++out:
++ return err;
++}
++
++void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
++{
++#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
++ p->hdir->hi_inode->i_mutex.owner = task;
++#endif
++}
++
++void au_pin_hdir_acquire_nest(struct au_pin *p)
++{
++ if (p->hdir) {
++ mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
++ p->lsc_hi, 0, NULL, _RET_IP_);
++ au_pin_hdir_set_owner(p, current);
++ }
++}
++
++void au_pin_hdir_release(struct au_pin *p)
++{
++ if (p->hdir) {
++ au_pin_hdir_set_owner(p, p->task);
++ mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
++ }
++}
++
+struct dentry *au_pinned_h_parent(struct au_pin *pin)
+{
+ if (pin && pin->parent)
+
+void au_unpin(struct au_pin *p)
+{
++ if (p->hdir)
++ au_pin_hdir_unlock(p);
+ if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
-+ mnt_drop_write(p->h_mnt);
++ vfsub_mnt_drop_write(p->h_mnt);
+ if (!p->hdir)
+ return;
+
-+ au_hn_imtx_unlock(p->hdir);
+ if (!au_ftest_pin(p->flags, DI_LOCKED))
+ di_read_unlock(p->parent, AuLock_IR);
+ iput(p->hdir->hi_inode);
+ p->parent = NULL;
+ p->hdir = NULL;
+ p->h_mnt = NULL;
++ /* do not clear p->task */
+}
+
+int au_do_pin(struct au_pin *p)
+{
+ int err;
+ struct super_block *sb;
-+ struct dentry *h_dentry, *h_parent;
-+ struct au_branch *br;
+ struct inode *h_dir;
+
+ err = 0;
+ sb = p->dentry->d_sb;
-+ br = au_sbr(sb, p->bindex);
++ p->br = au_sbr(sb, p->bindex);
+ if (IS_ROOT(p->dentry)) {
+ if (au_ftest_pin(p->flags, MNT_WRITE)) {
-+ p->h_mnt = br->br_mnt;
-+ err = mnt_want_write(p->h_mnt);
++ p->h_mnt = au_br_mnt(p->br);
++ err = vfsub_mnt_want_write(p->h_mnt);
+ if (unlikely(err)) {
+ au_fclr_pin(p->flags, MNT_WRITE);
+ goto out_err;
+ goto out;
+ }
+
-+ h_dentry = NULL;
++ p->h_dentry = NULL;
+ if (p->bindex <= au_dbend(p->dentry))
-+ h_dentry = au_h_dptr(p->dentry, p->bindex);
++ p->h_dentry = au_h_dptr(p->dentry, p->bindex);
+
+ p->parent = dget_parent(p->dentry);
+ if (!au_ftest_pin(p->flags, DI_LOCKED))
+ di_read_lock(p->parent, AuLock_IR, p->lsc_di);
+
+ h_dir = NULL;
-+ h_parent = au_h_dptr(p->parent, p->bindex);
++ p->h_parent = au_h_dptr(p->parent, p->bindex);
+ p->hdir = au_hi(p->parent->d_inode, p->bindex);
+ if (p->hdir)
+ h_dir = p->hdir->hi_inode;
+ * if DI_LOCKED is not set, then p->parent may be different
+ * and h_parent can be NULL.
+ */
-+ if (unlikely(!p->hdir || !h_dir || !h_parent)) {
++ if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
+ err = -EBUSY;
+ if (!au_ftest_pin(p->flags, DI_LOCKED))
+ di_read_unlock(p->parent, AuLock_IR);
+ goto out_err;
+ }
+
-+ au_igrab(h_dir);
-+ au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
-+
-+ if (unlikely(p->hdir->hi_inode != h_parent->d_inode)) {
-+ err = -EBUSY;
-+ goto out_unpin;
-+ }
-+ if (h_dentry) {
-+ err = au_h_verify(h_dentry, p->udba, h_dir, h_parent, br);
-+ if (unlikely(err)) {
-+ au_fclr_pin(p->flags, MNT_WRITE);
-+ goto out_unpin;
-+ }
-+ }
-+
+ if (au_ftest_pin(p->flags, MNT_WRITE)) {
-+ p->h_mnt = br->br_mnt;
-+ err = mnt_want_write(p->h_mnt);
++ p->h_mnt = au_br_mnt(p->br);
++ err = vfsub_mnt_want_write(p->h_mnt);
+ if (unlikely(err)) {
+ au_fclr_pin(p->flags, MNT_WRITE);
-+ goto out_unpin;
++ if (!au_ftest_pin(p->flags, DI_LOCKED))
++ di_read_unlock(p->parent, AuLock_IR);
++ dput(p->parent);
++ p->parent = NULL;
++ goto out_err;
+ }
+ }
-+ goto out; /* success */
+
-+out_unpin:
-+ au_unpin(p);
++ au_igrab(h_dir);
++ err = au_pin_hdir_lock(p);
++ if (!err)
++ goto out; /* success */
++
+out_err:
+ pr_err("err %d\n", err);
+ err = au_busy_or_stale();
+ p->parent = NULL;
+ p->hdir = NULL;
+ p->h_mnt = NULL;
++
++ p->h_dentry = NULL;
++ p->h_parent = NULL;
++ p->br = NULL;
++ p->task = current;
+}
+
+int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
+ aufs_bindex_t bstart, ibstart;
+ struct dentry *hi_wh, *parent;
+ struct inode *inode;
-+ struct file *h_file;
+ struct au_wr_dir_args wr_dir_args = {
+ .force_btgt = -1,
+ .flags = 0
+ sz = -1;
+ if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
+ sz = ia->ia_size;
++ mutex_unlock(&a->h_inode->i_mutex);
+
-+ h_file = NULL;
+ hi_wh = NULL;
+ if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
+ hi_wh = au_hi_wh(inode, a->btgt);
+ if (!hi_wh) {
-+ err = au_sio_cpup_wh(dentry, a->btgt, sz, /*file*/NULL);
++ struct au_cp_generic cpg = {
++ .dentry = dentry,
++ .bdst = a->btgt,
++ .bsrc = -1,
++ .len = sz,
++ .pin = &a->pin
++ };
++ err = au_sio_cpup_wh(&cpg, /*file*/NULL);
+ if (unlikely(err))
+ goto out_unlock;
+ hi_wh = au_hi_wh(inode, a->btgt);
+ goto out; /* success */
+
+ if (!d_unhashed(dentry)) {
-+ h_file = au_h_open_pre(dentry, bstart);
-+ if (IS_ERR(h_file)) {
-+ err = PTR_ERR(h_file);
-+ h_file = NULL;
-+ } else
-+ err = au_sio_cpup_simple(dentry, a->btgt, sz,
-+ AuCpup_DTIME);
++ struct au_cp_generic cpg = {
++ .dentry = dentry,
++ .bdst = a->btgt,
++ .bsrc = bstart,
++ .len = sz,
++ .pin = &a->pin,
++ .flags = AuCpup_DTIME | AuCpup_HOPEN
++ };
++ err = au_sio_cpup_simple(&cpg);
+ if (!err)
+ a->h_path.dentry = au_h_dptr(dentry, a->btgt);
+ } else if (!hi_wh)
+ a->h_path.dentry = hi_wh; /* do not dget here */
+
+out_unlock:
-+ mutex_unlock(&a->h_inode->i_mutex);
-+ au_h_open_post(dentry, bstart, h_file);
+ a->h_inode = a->h_path.dentry->d_inode;
-+ if (!err) {
-+ mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
++ if (!err)
+ goto out; /* success */
-+ }
-+
+ au_unpin(&a->pin);
+out_parent:
+ if (parent) {
+ dput(parent);
+ }
+out:
++ if (!err)
++ mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
+ return err;
+}
+
+static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
+{
+ int err;
-+ struct inode *inode;
++ struct inode *inode, *delegated;
+ struct super_block *sb;
+ struct file *file;
+ struct au_icpup_args *a;
+ a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
+ if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
+ == (ATTR_MODE | ATTR_CTIME)) {
-+ err = security_path_chmod(a->h_path.dentry, a->h_path.mnt,
-+ ia->ia_mode);
++ err = security_path_chmod(&a->h_path, ia->ia_mode);
+ if (unlikely(err))
+ goto out_unlock;
+ } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
+ mutex_unlock(&a->h_inode->i_mutex);
+ err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
+ mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
-+ } else
-+ err = vfsub_notify_change(&a->h_path, ia);
++ } else {
++ delegated = NULL;
++ while (1) {
++ err = vfsub_notify_change(&a->h_path, ia, &delegated);
++ if (delegated) {
++ err = break_deleg_wait(&delegated);
++ if (!err)
++ continue;
++ }
++ break;
++ }
++ }
+ if (!err)
+ au_cpup_attr_changeable(inode);
+
+static void au_refresh_iattr(struct inode *inode, struct kstat *st,
+ unsigned int nlink)
+{
++ unsigned int n;
++
+ inode->i_mode = st->mode;
++ /* don't i_[ug]id_write() here */
+ inode->i_uid = st->uid;
+ inode->i_gid = st->gid;
+ inode->i_atime = st->atime;
+
+ au_cpup_attr_nlink(inode, /*force*/0);
+ if (S_ISDIR(inode->i_mode)) {
-+ inode->i_nlink -= nlink;
-+ inode->i_nlink += st->nlink;
++ n = inode->i_nlink;
++ n -= nlink;
++ n += st->nlink;
++ smp_mb(); /* for i_nlink */
++ /* 0 can happen */
++ set_nlink(inode, n);
+ }
+
+ spin_lock(&inode->i_lock);
+ unsigned char udba_none, positive;
+ struct super_block *sb, *h_sb;
+ struct inode *inode;
-+ struct vfsmount *h_mnt;
-+ struct dentry *h_dentry;
++ struct path h_path;
+
+ sb = dentry->d_sb;
+ inode = dentry->d_inode;
+ di_read_lock_child(dentry, AuLock_IR);
+
+ bindex = au_ibstart(inode);
-+ h_mnt = au_sbr_mnt(sb, bindex);
-+ h_sb = h_mnt->mnt_sb;
++ h_path.mnt = au_sbr_mnt(sb, bindex);
++ h_sb = h_path.mnt->mnt_sb;
+ if (!au_test_fs_bad_iattr(h_sb) && udba_none)
+ goto out_fill; /* success */
+
-+ h_dentry = NULL;
++ h_path.dentry = NULL;
+ if (au_dbstart(dentry) == bindex)
-+ h_dentry = dget(au_h_dptr(dentry, bindex));
++ h_path.dentry = dget(au_h_dptr(dentry, bindex));
+ else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
-+ h_dentry = au_plink_lkup(inode, bindex);
-+ if (IS_ERR(h_dentry))
++ h_path.dentry = au_plink_lkup(inode, bindex);
++ if (IS_ERR(h_path.dentry))
+ goto out_fill; /* pretending success */
+ }
+ /* illegally overlapped or something */
-+ if (unlikely(!h_dentry))
++ if (unlikely(!h_path.dentry))
+ goto out_fill; /* pretending success */
+
-+ positive = !!h_dentry->d_inode;
++ positive = !!h_path.dentry->d_inode;
+ if (positive)
-+ err = vfs_getattr(h_mnt, h_dentry, st);
-+ dput(h_dentry);
++ err = vfs_getattr(&h_path, st);
++ dput(h_path.dentry);
+ if (!err) {
+ if (positive)
-+ au_refresh_iattr(inode, st, h_dentry->d_inode->i_nlink);
++ au_refresh_iattr(inode, st,
++ h_path.dentry->d_inode->i_nlink);
+ goto out_fill; /* success */
+ }
+ AuTraceErr(err);
+ } buf;
+
+ err = -ENOMEM;
-+ buf.k = __getname_gfp(GFP_NOFS);
++ buf.k = (void *)__get_free_page(GFP_NOFS);
+ if (unlikely(!buf.k))
+ goto out;
+
+ }
+
+out_name:
-+ __putname(buf.k);
++ free_page((unsigned long)buf.k);
+out:
-+ path_put(&nd->path);
+ AuTraceErr(err);
+ return ERR_PTR(err);
+}
+static void aufs_put_link(struct dentry *dentry __maybe_unused,
+ struct nameidata *nd, void *cookie __maybe_unused)
+{
-+ __putname(nd_get_link(nd));
++ char *p;
++
++ p = nd_get_link(nd);
++ if (!IS_ERR_OR_NULL(p))
++ free_page((unsigned long)p);
+}
+
+/* ---------------------------------------------------------------------- */
+
-+static void aufs_truncate_range(struct inode *inode __maybe_unused,
-+ loff_t start __maybe_unused,
-+ loff_t end __maybe_unused)
++static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
+{
-+ AuUnsupport();
++ int err;
++ struct super_block *sb;
++ struct inode *h_inode;
++
++ sb = inode->i_sb;
++ /* mmap_sem might be acquired already, cf. aufs_mmap() */
++ lockdep_off();
++ si_read_lock(sb, AuLock_FLUSH);
++ ii_write_lock_child(inode);
++ lockdep_on();
++ h_inode = au_h_iptr(inode, au_ibstart(inode));
++ err = vfsub_update_time(h_inode, ts, flags);
++ lockdep_off();
++ ii_write_unlock(inode);
++ si_read_unlock(sb);
++ lockdep_on();
++ return err;
+}
+
+/* ---------------------------------------------------------------------- */
+ .permission = aufs_permission,
+ .setattr = aufs_setattr,
+ .getattr = aufs_getattr,
++
+ .readlink = aufs_readlink,
+ .follow_link = aufs_follow_link,
-+ .put_link = aufs_put_link
++ .put_link = aufs_put_link,
++
++ /* .update_time = aufs_update_time */
+};
+
+struct inode_operations aufs_dir_iop = {
+
+ .permission = aufs_permission,
+ .setattr = aufs_setattr,
-+ .getattr = aufs_getattr
++ .getattr = aufs_getattr,
++
++ .update_time = aufs_update_time
++ /* no support for atomic_open() */
+};
+
+struct inode_operations aufs_iop = {
+ .permission = aufs_permission,
+ .setattr = aufs_setattr,
+ .getattr = aufs_getattr,
-+ .truncate_range = aufs_truncate_range
++
++ .update_time = aufs_update_time
+};
diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
--- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/i_op_del.c 2011-08-24 13:30:24.731313534 +0200
-@@ -0,0 +1,478 @@
++++ linux/fs/aufs/i_op_del.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,506 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ au_di_cp(tmp, dinfo);
+ au_di_swap(tmp, dinfo);
+ /* returns the number of positive dentries */
-+ need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0,
-+ /*nd*/NULL);
++ need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
+ au_di_swap(tmp, dinfo);
+ au_rw_write_unlock(&tmp->di_rwsem);
+ au_di_free(tmp);
+
+ err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
+ if (unlikely(err)) {
-+ AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
-+ AuDLNPair(h_dentry), bindex, err);
++ AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
++ h_dentry, bindex, err);
+ err = 0;
+ }
+
+ return 0;
+ }
+
-+ AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
-+ AuDLNPair(dentry), err, rerr);
++ AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
+ return -EIO;
+}
+
+{
+ int err;
+ aufs_bindex_t bwh, bindex, bstart;
-+ struct au_dtime dt;
-+ struct au_pin pin;
-+ struct path h_path;
-+ struct inode *inode, *h_dir;
++ struct inode *inode, *h_dir, *delegated;
+ struct dentry *parent, *wh_dentry;
++ /* to reuduce stack size */
++ struct {
++ struct au_dtime dt;
++ struct au_pin pin;
++ struct path h_path;
++ } *a;
+
+ IMustLock(dir);
+
++ err = -ENOMEM;
++ a = kmalloc(sizeof(*a), GFP_NOFS);
++ if (unlikely(!a))
++ goto out;
++
+ err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
+ if (unlikely(err))
-+ goto out;
++ goto out_free;
+ err = au_d_hashed_positive(dentry);
+ if (unlikely(err))
+ goto out_unlock;
+ bindex = -1;
+ parent = dentry->d_parent; /* dir inode is locked */
+ di_write_lock_parent(parent);
-+ wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &dt, &pin);
++ wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
++ &a->pin);
+ err = PTR_ERR(wh_dentry);
+ if (IS_ERR(wh_dentry))
+ goto out_parent;
+
-+ h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
-+ h_path.dentry = au_h_dptr(dentry, bstart);
-+ dget(h_path.dentry);
++ a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
++ a->h_path.dentry = au_h_dptr(dentry, bstart);
++ dget(a->h_path.dentry);
+ if (bindex == bstart) {
-+ h_dir = au_pinned_h_dir(&pin);
-+ err = vfsub_unlink(h_dir, &h_path, /*force*/0);
++ h_dir = au_pinned_h_dir(&a->pin);
++ delegated = NULL;
++ err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
++ }
+ } else {
+ /* dir inode is locked */
+ h_dir = wh_dentry->d_parent->d_inode;
+
+ /* update target timestamps */
+ if (bindex == bstart) {
-+ vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
-+ inode->i_ctime = h_path.dentry->d_inode->i_ctime;
++ vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
++ /*ignore*/
++ inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
+ } else
+ /* todo: this timestamp may be reverted later */
+ inode->i_ctime = h_dir->i_ctime;
+ if (wh_dentry) {
+ int rerr;
+
-+ rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
++ rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
++ &a->dt);
+ if (rerr)
+ err = rerr;
+ }
+
+out_unpin:
-+ au_unpin(&pin);
++ au_unpin(&a->pin);
+ dput(wh_dentry);
-+ dput(h_path.dentry);
++ dput(a->h_path.dentry);
+out_parent:
+ di_write_unlock(parent);
+out_unlock:
+ aufs_read_unlock(dentry, AuLock_DW);
++out_free:
++ kfree(a);
+out:
+ return err;
+}
+{
+ int err, rmdir_later;
+ aufs_bindex_t bwh, bindex, bstart;
-+ struct au_dtime dt;
-+ struct au_pin pin;
+ struct inode *inode;
+ struct dentry *parent, *wh_dentry, *h_dentry;
+ struct au_whtmp_rmdir *args;
++ /* to reuduce stack size */
++ struct {
++ struct au_dtime dt;
++ struct au_pin pin;
++ } *a;
+
+ IMustLock(dir);
+
++ err = -ENOMEM;
++ a = kmalloc(sizeof(*a), GFP_NOFS);
++ if (unlikely(!a))
++ goto out;
++
+ err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
+ if (unlikely(err))
-+ goto out;
++ goto out_free;
+ err = au_alive_dir(dentry);
+ if (unlikely(err))
+ goto out_unlock;
+ bstart = au_dbstart(dentry);
+ bwh = au_dbwh(dentry);
+ bindex = -1;
-+ wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &dt, &pin);
++ wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
++ &a->pin);
+ err = PTR_ERR(wh_dentry);
+ if (IS_ERR(wh_dentry))
+ goto out_parent;
+ if (wh_dentry) {
+ int rerr;
+
-+ rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, &dt);
++ rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
++ &a->dt);
+ if (rerr)
+ err = rerr;
+ }
+
+out_unpin:
-+ au_unpin(&pin);
++ au_unpin(&a->pin);
+ dput(wh_dentry);
+ dput(h_dentry);
+out_parent:
+ au_whtmp_rmdir_free(args);
+out_unlock:
+ aufs_read_unlock(dentry, AuLock_DW);
++out_free:
++ kfree(a);
+out:
+ AuTraceErr(err);
+ return err;
+}
diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
--- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/i_op_ren.c 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,1017 @@
++++ linux/fs/aufs/i_op_ren.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,1032 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ au_hn_imtx_unlock(a->src_hinode);
+ au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
+ if (rerr)
-+ RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
++ RevertFailure("remove diropq %pd", a->src_dentry);
+}
+
+static void au_ren_rev_rename(int err, struct au_ren_args *a)
+{
+ int rerr;
++ struct inode *delegated;
+
-+ a->h_path.dentry = au_lkup_one(&a->src_dentry->d_name, a->src_h_parent,
-+ a->br, /*nd*/NULL);
++ a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
++ a->src_h_parent);
+ rerr = PTR_ERR(a->h_path.dentry);
+ if (IS_ERR(a->h_path.dentry)) {
-+ RevertFailure("au_lkup_one %.*s", AuDLNPair(a->src_dentry));
++ RevertFailure("lkup one %pd", a->src_dentry);
+ return;
+ }
+
++ delegated = NULL;
+ rerr = vfsub_rename(a->dst_h_dir,
+ au_h_dptr(a->src_dentry, a->btgt),
-+ a->src_h_dir, &a->h_path);
++ a->src_h_dir, &a->h_path, &delegated);
++ if (unlikely(rerr == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal rename\n");
++ iput(delegated);
++ }
+ d_drop(a->h_path.dentry);
+ dput(a->h_path.dentry);
+ /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
+ if (rerr)
-+ RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
++ RevertFailure("rename %pd", a->src_dentry);
+}
+
+static void au_ren_rev_cpup(int err, struct au_ren_args *a)
+ int rerr;
+
+ a->h_path.dentry = a->dst_h_dentry;
-+ rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
++ /* no delegation since it is just created */
++ rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
++ /*force*/0);
+ au_set_h_dptr(a->src_dentry, a->btgt, NULL);
+ au_set_dbstart(a->src_dentry, a->src_bstart);
+ if (rerr)
-+ RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
++ RevertFailure("unlink %pd", a->dst_h_dentry);
+}
+
+static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
+{
+ int rerr;
++ struct inode *delegated;
+
-+ a->h_path.dentry = au_lkup_one(&a->dst_dentry->d_name, a->dst_h_parent,
-+ a->br, /*nd*/NULL);
++ a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
++ a->dst_h_parent);
+ rerr = PTR_ERR(a->h_path.dentry);
+ if (IS_ERR(a->h_path.dentry)) {
-+ RevertFailure("lookup %.*s", AuDLNPair(a->dst_dentry));
++ RevertFailure("lkup one %pd", a->dst_dentry);
+ return;
+ }
+ if (a->h_path.dentry->d_inode) {
+ return;
+ }
+
-+ rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
++ delegated = NULL;
++ rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
++ &delegated);
++ if (unlikely(rerr == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal rename\n");
++ iput(delegated);
++ }
+ d_drop(a->h_path.dentry);
+ dput(a->h_path.dentry);
+ if (!rerr)
+ au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
+ else
-+ RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
++ RevertFailure("rename %pd", a->h_dst);
+}
+
+static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
+ rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
+ au_set_dbwh(a->src_dentry, a->src_bwh);
+ if (rerr)
-+ RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
++ RevertFailure("unlink %pd", a->src_wh_dentry);
+}
+#undef RevertFailure
+
+{
+ int err;
+ struct dentry *d;
++ struct inode *delegated;
+
+ d = a->src_dentry;
+ if (au_dbstart(d) == a->btgt) {
+ && au_dbdiropq(d) == a->btgt)
+ au_fclr_ren(a->flags, DIROPQ);
+ AuDebugOn(au_dbstart(d) != a->btgt);
++ delegated = NULL;
+ err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
-+ a->dst_h_dir, &a->h_path);
-+ } else {
-+ struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
-+ struct file *h_file;
-+
-+ au_fset_ren(a->flags, CPUP);
-+ mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
-+ au_set_dbstart(d, a->btgt);
-+ au_set_h_dptr(d, a->btgt, dget(a->dst_h_dentry));
-+ h_file = au_h_open_pre(d, a->src_bstart);
-+ if (IS_ERR(h_file)) {
-+ err = PTR_ERR(h_file);
-+ h_file = NULL;
-+ } else
-+ err = au_sio_cpup_single(d, a->btgt, a->src_bstart, -1,
-+ !AuCpup_DTIME, a->dst_parent);
-+ mutex_unlock(h_mtx);
-+ au_h_open_post(d, a->src_bstart, h_file);
-+ if (!err) {
-+ d = a->dst_dentry;
-+ au_set_h_dptr(d, a->btgt, NULL);
-+ au_update_dbstart(d);
-+ } else {
-+ au_set_h_dptr(d, a->btgt, NULL);
-+ au_set_dbstart(d, a->src_bstart);
++ a->dst_h_dir, &a->h_path, &delegated);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal rename\n");
++ iput(delegated);
+ }
-+ }
++ } else
++ BUG();
++
+ if (!err && a->h_dst)
+ /* it will be set to dinfo later */
+ dget(a->h_dst);
+ || au_test_fs_remote(a->h_dst->d_sb)) {
+ err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
+ if (unlikely(err))
-+ pr_warning("failed removing whtmp dir %.*s (%d), "
-+ "ignored.\n", AuDLNPair(a->h_dst), err);
++ pr_warn("failed removing whtmp dir %pd (%d), "
++ "ignored.\n", a->h_dst, err);
+ } else {
+ au_nhash_wh_free(&a->thargs->whlist);
+ a->thargs->whlist = a->whlist;
+
+ d = a->dst_dentry;
+ au_set_h_dptr(d, a->btgt, NULL);
-+ err = au_lkup_neg(d, a->btgt);
++ err = au_lkup_neg(d, a->btgt, /*wh*/0);
+ if (unlikely(err))
+ goto out_whtmp;
+ a->dst_h_dentry = au_h_dptr(d, a->btgt);
+ }
+
-+ /* cpup src */
-+ if (a->dst_h_dentry->d_inode && a->src_bstart != a->btgt) {
-+ struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
-+ struct file *h_file;
-+
-+ mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
-+ AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
-+ h_file = au_h_open_pre(a->src_dentry, a->src_bstart);
-+ if (IS_ERR(h_file)) {
-+ err = PTR_ERR(h_file);
-+ h_file = NULL;
-+ } else
-+ err = au_sio_cpup_simple(a->src_dentry, a->btgt, -1,
-+ !AuCpup_DTIME);
-+ mutex_unlock(h_mtx);
-+ au_h_open_post(a->src_dentry, a->src_bstart, h_file);
-+ if (unlikely(err))
-+ goto out_whtmp;
-+ }
++ BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
+
+ /* rename by vfs_rename or cpup */
+ d = a->dst_dentry;
+ */
+static void au_ren_unlock(struct au_ren_args *a)
+{
-+ struct super_block *sb;
-+
-+ sb = a->dst_dentry->d_sb;
-+ if (au_ftest_ren(a->flags, MNT_WRITE))
-+ mnt_drop_write(a->br->br_mnt);
+ vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
+ a->dst_h_parent, a->dst_hdir);
++ if (au_ftest_ren(a->flags, MNT_WRITE))
++ vfsub_mnt_drop_write(au_br_mnt(a->br));
+}
+
+static int au_ren_lock(struct au_ren_args *a)
+ a->src_hdir = au_hi(a->src_dir, a->btgt);
+ a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
+ a->dst_hdir = au_hi(a->dst_dir, a->btgt);
++
++ err = vfsub_mnt_want_write(au_br_mnt(a->br));
++ if (unlikely(err))
++ goto out;
++ au_fset_ren(a->flags, MNT_WRITE);
+ a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
+ a->dst_h_parent, a->dst_hdir);
+ udba = au_opt_udba(a->src_dentry->d_sb);
+ err = au_h_verify(a->dst_h_dentry, udba,
+ a->dst_h_parent->d_inode, a->dst_h_parent,
+ a->br);
-+ if (!err) {
-+ err = mnt_want_write(a->br->br_mnt);
-+ if (unlikely(err))
-+ goto out_unlock;
-+ au_fset_ren(a->flags, MNT_WRITE);
++ if (!err)
+ goto out; /* success */
-+ }
+
+ err = au_busy_or_stale();
-+
-+out_unlock:
+ au_ren_unlock(a);
++
+out:
+ return err;
+}
+ /* reduce stack space */
+ struct au_ren_args *a;
+
-+ AuDbg("%.*s, %.*s\n", AuDLNPair(_src_dentry), AuDLNPair(_dst_dentry));
++ AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
+ IMustLock(_src_dir);
+ IMustLock(_dst_dir);
+
+ } else if (unlikely(d_unhashed(a->dst_dentry)))
+ goto out_unlock;
+
++ /*
++ * is it possible?
++ * yes, it happend (in linux-3.3-rcN) but I don't know why.
++ * there may exist a problem somewhere else.
++ */
++ err = -EINVAL;
++ if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
++ goto out_unlock;
++
+ au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
+ di_write_lock_parent(a->dst_parent);
+
+ if (unlikely(err < 0))
+ goto out_parent;
+ a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
-+ a->h_path.mnt = a->br->br_mnt;
++ a->h_path.mnt = au_br_mnt(a->br);
+
+ /* are they available to be renamed */
+ err = au_ren_may_dir(a);
+ if (err)
+ au_fset_ren(a->flags, WHSRC);
+
++ /* cpup src */
++ if (a->src_bstart != a->btgt) {
++ struct au_pin pin;
++
++ err = au_pin(&pin, a->src_dentry, a->btgt,
++ au_opt_udba(a->src_dentry->d_sb),
++ AuPin_DI_LOCKED | AuPin_MNT_WRITE);
++ if (!err) {
++ struct au_cp_generic cpg = {
++ .dentry = a->src_dentry,
++ .bdst = a->btgt,
++ .bsrc = a->src_bstart,
++ .len = -1,
++ .pin = &pin,
++ .flags = AuCpup_DTIME | AuCpup_HOPEN
++ };
++ AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
++ err = au_sio_cpup_simple(&cpg);
++ au_unpin(&pin);
++ }
++ if (unlikely(err))
++ goto out_children;
++ a->src_bstart = a->btgt;
++ a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
++ au_fset_ren(a->flags, WHSRC);
++ }
++
+ /* lock them all */
+ err = au_ren_lock(a);
+ if (unlikely(err))
++ /* leave the copied-up one */
+ goto out_children;
+
+ if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
+}
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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,203 @@
++++ linux/fs/aufs/Kconfig 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,179 @@
+config AUFS_FS
+ tristate "Aufs (Advanced multi layered unification filesystem) support"
-+ depends on EXPERIMENTAL
+ help
+ Aufs is a stackable unification filesystem such as Unionfs,
+ which unifies several directories and provides a merged single
+ shows better performance in most cases.
+ See detail in aufs.5.
+
-+config AUFS_PROC_MAP
-+ bool "support for /proc/maps and lsof(1)"
-+ depends on PROC_FS
-+ help
-+ When you issue mmap(2) in aufs, it is actually a direct mmap(2)
-+ call to the file on the branch fs since the file in aufs is
-+ purely virtual. And the file path printed in /proc/maps (and
-+ others) will be the path on the branch fs. In most cases, it
-+ does no harm. But some utilities like lsof(1) may confuse since
-+ the utility or user may expect the file path in aufs to be
-+ printed.
-+ To address this issue, aufs provides a patch which introduces a
-+ new member called vm_prfile into struct vm_are_struct. The patch
-+ is meaningless without enabling this configuration since nobody
-+ sets the new vm_prfile member.
-+ If you don't apply the patch, then enabling this configuration
-+ will cause a compile error.
-+ This approach is fragile since if someone else make some changes
-+ around vm_file, then vm_prfile may not work anymore. As a
-+ workaround such case, aufs provides this configuration. If you
-+ disable it, then lsof(1) may produce incorrect result but the
-+ problem will be gone even if the aufs patch is applied (I hope).
-+
+config AUFS_SP_IATTR
+ bool "Respect the attributes (mtime/ctime mainly) of special files"
+ help
+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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,133 @@
++++ linux/fs/aufs/loop.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,145 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * support for loopback block device as a branch
+ */
+
-+#include <linux/loop.h>
+#include "aufs.h"
+
++/* added into drivers/block/loop.c */
++static struct file *(*backing_file_func)(struct super_block *sb);
++
+/*
+ * test if two lower dentries have overlapping branches.
+ */
+int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
+{
+ struct super_block *h_sb;
-+ struct loop_device *l;
++ struct file *backing_file;
++
++ if (unlikely(!backing_file_func)) {
++ /* don't load "loop" module here */
++ backing_file_func = symbol_get(loop_backing_file);
++ if (unlikely(!backing_file_func))
++ /* "loop" module is not loaded */
++ return 0;
++ }
+
+ h_sb = h_adding->d_sb;
-+ if (MAJOR(h_sb->s_dev) != LOOP_MAJOR)
++ backing_file = backing_file_func(h_sb);
++ if (!backing_file)
+ return 0;
+
-+ l = h_sb->s_bdev->bd_disk->private_data;
-+ h_adding = l->lo_backing_file->f_dentry;
++ h_adding = backing_file->f_dentry;
+ /*
+ * h_adding can be local NFS.
+ * in this case aufs cannot detect the loop.
+{
+ int ret;
+ struct task_struct *tsk = current;
++ char c, comm[sizeof(tsk->comm)];
+
+ ret = 0;
+ if (tsk->flags & PF_KTHREAD) {
-+ const char c = tsk->comm[4];
++ get_task_comm(comm, tsk);
++ c = comm[4];
+ ret = ('0' <= c && c <= '9'
-+ && !strncmp(tsk->comm, "loop", 4));
++ && !strncmp(comm, "loop", 4));
+ }
+
+ return ret;
+
+pr:
+ spin_unlock(&spin);
-+ pr_warning("you may want to try another patch for loopback file "
-+ "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
++ pr_warn("you may want to try another patch for loopback file "
++ "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
+}
+
+int au_loopback_init(void)
+
+void au_loopback_fin(void)
+{
++ symbol_put(loop_backing_file);
+ kfree(au_warn_loopback_array);
+}
diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
--- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/loop.h 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,50 @@
++++ linux/fs/aufs/loop.h 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,52 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+struct super_block;
+
+#ifdef CONFIG_AUFS_BDEV_LOOP
++/* drivers/block/loop.c */
++struct file *loop_backing_file(struct super_block *sb);
++
+/* loop.c */
+int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
+int au_test_loopback_kthread(void);
+#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 2011-08-24 13:30:24.734646739 +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 2011-08-24 13:30:24.727980364 +0200
-@@ -0,0 +1,38 @@
++++ linux/fs/aufs/Makefile 2014-01-30 21:10:02.827480967 +0100
+@@ -0,0 +1,42 @@
+
+include ${src}/magic.mk
+ifeq (${CONFIG_AUFS_FS},m)
+# cf. include/linux/kernel.h
+# enable pr_debug
+ccflags-y += -DDEBUG
-+# sparse doesn't allow spaces
-+ccflags-y += -D'pr_fmt(fmt)=AUFS_NAME"\040%s:%d:%s[%d]:\040"fmt,__func__,__LINE__,current->comm,current->pid'
++# sparse requires the full pathname
++ifdef M
++ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
++else
++ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
++endif
+
+obj-$(CONFIG_AUFS_FS) += aufs.o
+aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
+ finfo.o file.o f_op.o \
+ dir.o vdir.o \
+ iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
-+ ioctl.o
++ mvdown.o ioctl.o
+
+# all are boolean
+aufs-$(CONFIG_PROC_FS) += procfs.o plink.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 2011-10-24 20:52:23.677857076 +0200
-@@ -0,0 +1,193 @@
++++ linux/fs/aufs/module.c 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,202 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+{
+ int i;
+
-+ /* including AuCache_HNOTIFY */
-+ for (i = 0; i < AuCache_Last; i++)
++ /*
++ * Make sure all delayed rcu free inodes are flushed before we
++ * destroy cache.
++ */
++ rcu_barrier();
++
++ /* excluding AuCache_HNOTIFY */
++ BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
++ for (i = 0; i < AuCache_HNOTIFY; i++)
+ if (au_cachep[i]) {
+ kmem_cache_destroy(au_cachep[i]);
+ au_cachep[i] = NULL;
+struct au_splhead au_sbilist;
+#endif
+
++struct lock_class_key au_lc_key[AuLcKey_Last];
++
+/*
+ * functions for module interface.
+ */
+MODULE_DESCRIPTION(AUFS_NAME
+ " -- Advanced multi layered unification filesystem");
+MODULE_VERSION(AUFS_VERSION);
++MODULE_ALIAS_FS(AUFS_NAME);
+
+/* this module parameter has no meaning when SYSFS is disabled */
+int sysaufs_brs = 1;
+
+/* ---------------------------------------------------------------------- */
+
-+static int __init aufs_init(void)
-+{
-+ int err, i;
-+ char *p;
++static int __init aufs_init(void)
++{
++ int err, i;
++ char *p;
++
++ p = au_esc_chars;
++ for (i = 1; i <= ' '; i++)
++ *p++ = i;
++ *p++ = '\\';
++ *p++ = '\x7f';
++ *p = 0;
++
++ au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
++
++ au_sbilist_init();
++ sysaufs_brs_init();
++ au_debug_init();
++ au_dy_init();
++ err = sysaufs_init();
++ if (unlikely(err))
++ goto out;
++ err = au_procfs_init();
++ if (unlikely(err))
++ goto out_sysaufs;
++ err = au_wkq_init();
++ if (unlikely(err))
++ goto out_procfs;
++ err = au_loopback_init();
++ if (unlikely(err))
++ goto out_wkq;
++ err = au_hnotify_init();
++ if (unlikely(err))
++ goto out_loopback;
++ err = au_sysrq_init();
++ if (unlikely(err))
++ goto out_hin;
++ err = au_cache_init();
++ if (unlikely(err))
++ goto out_sysrq;
++ err = register_filesystem(&aufs_fs_type);
++ if (unlikely(err))
++ goto out_cache;
++ /* since we define pr_fmt, call printk directly */
++ printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
++ goto out; /* success */
++
++out_cache:
++ au_cache_fin();
++out_sysrq:
++ au_sysrq_fin();
++out_hin:
++ au_hnotify_fin();
++out_loopback:
++ au_loopback_fin();
++out_wkq:
++ au_wkq_fin();
++out_procfs:
++ au_procfs_fin();
++out_sysaufs:
++ sysaufs_fin();
++ au_dy_fin();
++out:
++ return err;
++}
++
++static void __exit aufs_exit(void)
++{
++ unregister_filesystem(&aufs_fs_type);
++ au_cache_fin();
++ au_sysrq_fin();
++ au_hnotify_fin();
++ au_loopback_fin();
++ au_wkq_fin();
++ au_procfs_fin();
++ sysaufs_fin();
++ au_dy_fin();
++}
++
++module_init(aufs_init);
++module_exit(aufs_exit);
+diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
+--- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/module.h 2014-01-30 21:10:02.850815069 +0100
+@@ -0,0 +1,104 @@
++/*
++ * 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/>.
++ */
++
++/*
++ * module initialization and module-global
++ */
++
++#ifndef __AUFS_MODULE_H__
++#define __AUFS_MODULE_H__
++
++#ifdef __KERNEL__
++
++#include <linux/slab.h>
++
++struct path;
++struct seq_file;
++
++/* module parameters */
++extern int sysaufs_brs;
++
++/* ---------------------------------------------------------------------- */
++
++extern int au_dir_roflags;
++
++enum {
++ AuLcNonDir_FIINFO,
++ AuLcNonDir_DIINFO,
++ AuLcNonDir_IIINFO,
++
++ AuLcDir_FIINFO,
++ AuLcDir_DIINFO,
++ AuLcDir_IIINFO,
++
++ AuLcSymlink_DIINFO,
++ AuLcSymlink_IIINFO,
++
++ AuLcKey_Last
++};
++extern struct lock_class_key au_lc_key[AuLcKey_Last];
++
++void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
++int au_seq_path(struct seq_file *seq, struct path *path);
++
++#ifdef CONFIG_PROC_FS
++/* procfs.c */
++int __init au_procfs_init(void);
++void au_procfs_fin(void);
++#else
++AuStubInt0(au_procfs_init, void);
++AuStubVoid(au_procfs_fin, void);
++#endif
++
++/* ---------------------------------------------------------------------- */
++
++/* kmem cache */
++enum {
++ AuCache_DINFO,
++ AuCache_ICNTNR,
++ AuCache_FINFO,
++ AuCache_VDIR,
++ AuCache_DEHSTR,
++ AuCache_HNOTIFY, /* must be last */
++ AuCache_Last
++};
++
++#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
++#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
++#define AuCacheCtor(type, ctor) \
++ kmem_cache_create(#type, sizeof(struct type), \
++ __alignof__(struct type), AuCacheFlags, ctor)
++
++extern struct kmem_cache *au_cachep[];
++
++#define AuCacheFuncs(name, index) \
++static inline struct au_##name *au_cache_alloc_##name(void) \
++{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
++static inline void au_cache_free_##name(struct au_##name *p) \
++{ kmem_cache_free(au_cachep[AuCache_##index], p); }
++
++AuCacheFuncs(dinfo, DINFO);
++AuCacheFuncs(icntnr, ICNTNR);
++AuCacheFuncs(finfo, FINFO);
++AuCacheFuncs(vdir, VDIR);
++AuCacheFuncs(vdir_dehstr, DEHSTR);
++#ifdef CONFIG_AUFS_HNOTIFY
++AuCacheFuncs(hnotify, HNOTIFY);
++#endif
++
++#endif /* __KERNEL__ */
++#endif /* __AUFS_MODULE_H__ */
+diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
+--- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
++++ linux/fs/aufs/mvdown.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,627 @@
++/*
++ * Copyright (C) 2011-2014 Junjiro R. Okajima
++ *
++ * This program, aufs is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ */
++
++/*
++ * move-down, opposite of copy-up
++ */
++
++#include "aufs.h"
++
++struct au_mvd_args {
++ struct {
++ struct super_block *h_sb;
++ struct dentry *h_parent;
++ struct au_hinode *hdir;
++ struct inode *h_dir, *h_inode;
++ } info[AUFS_MVDOWN_NARRAY];
++
++ struct aufs_mvdown mvdown;
++ struct dentry *dentry, *parent;
++ struct inode *inode, *dir;
++ struct super_block *sb;
++ aufs_bindex_t bopq, bwh, bfound;
++ unsigned char rename_lock;
++ struct au_pin pin;
++};
++
++#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_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
++#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
++#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
++#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
++#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
++
++#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
++#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
++#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
++#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
++#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
++
++#define AU_MVD_PR(flag, ...) do { \
++ if (flag) \
++ pr_err(__VA_ARGS__); \
++ } while (0)
++
++/* make the parent dir on bdst */
++static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ int err;
++
++ err = 0;
++ a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
++ a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
++ a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
++ a->mvd_h_dst_parent = NULL;
++ if (au_dbend(a->parent) >= a->mvd_bdst)
++ a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
++ if (!a->mvd_h_dst_parent) {
++ err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
++ if (unlikely(err)) {
++ AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
++ goto out;
++ }
++ a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
++ }
++
++out:
++ AuTraceErr(err);
++ return err;
++}
++
++/* lock them all */
++static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ int err;
++ struct dentry *h_trap;
++
++ a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
++ a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
++ if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
++ a->rename_lock = 0;
++ err = au_pin(&a->pin, a->dentry, a->mvd_bdst,
++ au_opt_udba(a->sb),
++ AuPin_MNT_WRITE | AuPin_DI_LOCKED);
++ if (!err) {
++ a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
++ mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
++ AuLsc_I_PARENT3);
++ } else
++ AU_MVD_PR(dmsg, "pin failed\n");
++ goto out;
++ }
++
++ err = 0;
++ a->rename_lock = 1;
++ h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
++ a->mvd_h_dst_parent, a->mvd_hdir_dst);
++ if (h_trap) {
++ err = (h_trap != a->mvd_h_src_parent);
++ if (err)
++ err = (h_trap != a->mvd_h_dst_parent);
++ }
++ BUG_ON(err); /* it should never happen */
++
++out:
++ AuTraceErr(err);
++ return err;
++}
++
++static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ if (!a->rename_lock) {
++ mutex_unlock(&a->mvd_h_src_dir->i_mutex);
++ au_unpin(&a->pin);
++ } else
++ vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
++ a->mvd_h_dst_parent, a->mvd_hdir_dst);
++}
++
++/* copy-down the file */
++static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ int err;
++ struct au_cp_generic cpg = {
++ .dentry = a->dentry,
++ .bdst = a->mvd_bdst,
++ .bsrc = a->mvd_bsrc,
++ .len = -1,
++ .pin = &a->pin,
++ .flags = AuCpup_DTIME | AuCpup_HOPEN
++ };
++
++ AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
++ if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
++ au_fset_cpup(cpg.flags, OVERWRITE);
++ if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
++ au_fset_cpup(cpg.flags, RWDST);
++ err = au_sio_cpdown_simple(&cpg);
++ if (unlikely(err))
++ AU_MVD_PR(dmsg, "cpdown failed\n");
++
++ AuTraceErr(err);
++ return err;
++}
++
++/*
++ * unlink the whiteout on bdst if exist which may be created by UDBA while we
++ * were sleeping
++ */
++static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ int err;
++ struct path h_path;
++ struct au_branch *br;
++ struct inode *delegated;
++
++ br = au_sbr(a->sb, a->mvd_bdst);
++ h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
++ err = PTR_ERR(h_path.dentry);
++ if (IS_ERR(h_path.dentry)) {
++ AU_MVD_PR(dmsg, "wh_lkup failed\n");
++ goto out;
++ }
++
++ err = 0;
++ if (h_path.dentry->d_inode) {
++ h_path.mnt = au_br_mnt(br);
++ delegated = NULL;
++ err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
++ &delegated, /*force*/0);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
++ }
++ if (unlikely(err))
++ AU_MVD_PR(dmsg, "wh_unlink failed\n");
++ }
++ dput(h_path.dentry);
++
++out:
++ AuTraceErr(err);
++ return err;
++}
++
++/*
++ * unlink the topmost h_dentry
++ * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
++ * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
++ */
++static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ int err;
++ struct path h_path;
++ struct inode *delegated;
++
++ h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
++ h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
++ delegated = NULL;
++ err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
++ }
++ if (unlikely(err))
++ AU_MVD_PR(dmsg, "unlink failed\n");
++
++ AuTraceErr(err);
++ return err;
++}
++
++/*
++ * copy-down the file and unlink the bsrc file.
++ * - unlink the bdst whout if exist
++ * - copy-down the file (with whtmp name and rename)
++ * - unlink the bsrc file
++ */
++static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ int err;
++
++ err = au_do_mkdir(dmsg, a);
++ if (!err)
++ err = au_do_lock(dmsg, a);
++ if (unlikely(err))
++ goto out;
++
++ /*
++ * do not revert the activities we made on bdst since they should be
++ * harmless in aufs.
++ */
++
++ err = au_do_cpdown(dmsg, a);
++ if (!err)
++ err = au_do_unlink_wh(dmsg, a);
++ if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
++ err = au_do_unlink(dmsg, a);
++ if (unlikely(err))
++ goto out_unlock;
++
++ /* maintain internal array */
++ if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
++ au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
++ au_set_dbstart(a->dentry, a->mvd_bdst);
++ au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
++ au_set_ibstart(a->inode, a->mvd_bdst);
++ }
++ if (au_dbend(a->dentry) < a->mvd_bdst)
++ au_set_dbend(a->dentry, a->mvd_bdst);
++ if (au_ibend(a->inode) < a->mvd_bdst)
++ au_set_ibend(a->inode, a->mvd_bdst);
++
++out_unlock:
++ au_do_unlock(dmsg, a);
++out:
++ AuTraceErr(err);
++ return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
++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)
++{
++ int err, plinked;
++
++ err = 0;
++ plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
++ if (au_dbstart(a->dentry) == a->mvd_bsrc
++ && d_count(a->dentry) == 1
++ && atomic_read(&a->inode->i_count) == 1
++ /* && a->mvd_h_src_inode->i_nlink == 1 */
++ && (!plinked || !au_plink_test(a->inode))
++ && a->inode->i_nlink == 1)
++ goto out;
++
++ err = -EBUSY;
++ AU_MVD_PR(dmsg,
++ "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
++ a->mvd_bsrc, au_dbstart(a->dentry), d_count(a->dentry),
++ atomic_read(&a->inode->i_count), a->inode->i_nlink,
++ a->mvd_h_src_inode->i_nlink,
++ plinked, plinked ? au_plink_test(a->inode) : 0);
++
++out:
++ AuTraceErr(err);
++ return err;
++}
++
++/* make sure the parent dir is fine */
++static int au_mvd_args_parent(const unsigned char dmsg,
++ struct au_mvd_args *a)
++{
++ int err;
++ aufs_bindex_t bindex;
++
++ err = 0;
++ if (unlikely(au_alive_dir(a->parent))) {
++ err = -ENOENT;
++ AU_MVD_PR(dmsg, "parent dir is dead\n");
++ goto out;
++ }
++
++ a->bopq = au_dbdiropq(a->parent);
++ bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
++ AuDbg("b%d\n", bindex);
++ if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
++ || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
++ err = -EINVAL;
++ a->mvd_errno = EAU_MVDOWN_OPAQUE;
++ AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
++ a->bopq, a->mvd_bdst);
++ }
++
++out:
++ AuTraceErr(err);
++ return err;
++}
++
++static int au_mvd_args_intermediate(const unsigned char dmsg,
++ struct au_mvd_args *a)
++{
++ int err;
++ struct au_dinfo *dinfo, *tmp;
++
++ /* lookup the next lower positive entry */
++ err = -ENOMEM;
++ tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
++ if (unlikely(!tmp))
++ goto out;
++
++ a->bfound = -1;
++ a->bwh = -1;
++ dinfo = au_di(a->dentry);
++ au_di_cp(tmp, dinfo);
++ au_di_swap(tmp, dinfo);
++
++ /* returns the number of positive dentries */
++ err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
++ if (!err)
++ a->bwh = au_dbwh(a->dentry);
++ else if (err > 0)
++ a->bfound = au_dbstart(a->dentry);
++
++ au_di_swap(tmp, dinfo);
++ au_rw_write_unlock(&tmp->di_rwsem);
++ au_di_free(tmp);
++ if (unlikely(err < 0))
++ AU_MVD_PR(dmsg, "failed look-up lower\n");
+
-+ p = au_esc_chars;
-+ for (i = 1; i <= ' '; i++)
-+ *p++ = i;
-+ *p++ = '\\';
-+ *p++ = '\x7f';
-+ *p = 0;
++ /*
++ * here, we have these cases.
++ * bfound == -1
++ * no positive dentry under bsrc. there are more sub-cases.
++ * bwh < 0
++ * there no whiteout, we can safely move-down.
++ * bwh <= bsrc
++ * impossible
++ * bsrc < bwh && bwh < bdst
++ * there is a whiteout on RO branch. cannot proceed.
++ * bwh == bdst
++ * there is a whiteout on the RW target branch. it should
++ * be removed.
++ * bdst < bwh
++ * there is a whiteout somewhere unrelated branch.
++ * -1 < bfound && bfound <= bsrc
++ * impossible.
++ * bfound < bdst
++ * found, but it is on RO branch between bsrc and bdst. cannot
++ * proceed.
++ * bfound == bdst
++ * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
++ * error.
++ * bdst < bfound
++ * found, after we create the file on bdst, it will be hidden.
++ */
+
-+ au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
++ AuDebugOn(a->bfound == -1
++ && a->bwh != -1
++ && a->bwh <= a->mvd_bsrc);
++ AuDebugOn(-1 < a->bfound
++ && a->bfound <= a->mvd_bsrc);
+
-+ au_sbilist_init();
-+ sysaufs_brs_init();
-+ au_debug_init();
-+ au_dy_init();
-+ err = sysaufs_init();
-+ if (unlikely(err))
++ err = -EINVAL;
++ if (a->bfound == -1
++ && a->mvd_bsrc < a->bwh
++ && a->bwh != -1
++ && a->bwh < a->mvd_bdst) {
++ a->mvd_errno = EAU_MVDOWN_WHITEOUT;
++ AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
++ a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
+ goto out;
-+ err = au_procfs_init();
-+ if (unlikely(err))
-+ goto out_sysaufs;
-+ err = au_wkq_init();
-+ if (unlikely(err))
-+ goto out_procfs;
-+ err = au_loopback_init();
-+ if (unlikely(err))
-+ goto out_wkq;
-+ err = au_hnotify_init();
-+ if (unlikely(err))
-+ goto out_loopback;
-+ err = au_sysrq_init();
-+ if (unlikely(err))
-+ goto out_hin;
-+ err = au_cache_init();
-+ if (unlikely(err))
-+ goto out_sysrq;
-+ err = register_filesystem(&aufs_fs_type);
-+ if (unlikely(err))
-+ goto out_cache;
-+ /* since we define pr_fmt, call printk directly */
-+ printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
-+ goto out; /* success */
++ } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
++ a->mvd_errno = EAU_MVDOWN_UPPER;
++ AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
++ a->mvd_bdst, a->bfound);
++ goto out;
++ }
++
++ err = 0; /* success */
+
-+out_cache:
-+ au_cache_fin();
-+out_sysrq:
-+ au_sysrq_fin();
-+out_hin:
-+ au_hnotify_fin();
-+out_loopback:
-+ au_loopback_fin();
-+out_wkq:
-+ au_wkq_fin();
-+out_procfs:
-+ au_procfs_fin();
-+out_sysaufs:
-+ sysaufs_fin();
-+ au_dy_fin();
+out:
++ AuTraceErr(err);
+ return err;
+}
+
-+static void __exit aufs_exit(void)
++static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
+{
-+ unregister_filesystem(&aufs_fs_type);
-+ au_cache_fin();
-+ au_sysrq_fin();
-+ au_hnotify_fin();
-+ au_loopback_fin();
-+ au_wkq_fin();
-+ au_procfs_fin();
-+ sysaufs_fin();
-+ au_dy_fin();
-+}
++ int err;
+
-+module_init(aufs_init);
-+module_exit(aufs_exit);
-diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
---- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/module.h 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,91 @@
-+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
-+ *
-+ * This program, aufs is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-+ */
++ err = 0;
++ if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
++ && a->bfound == a->mvd_bdst)
++ err = -EEXIST;
++ AuTraceErr(err);
++ return err;
++}
+
-+/*
-+ * module initialization and module-global
-+ */
++static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
++{
++ int err;
++ struct au_branch *br;
+
-+#ifndef __AUFS_MODULE_H__
-+#define __AUFS_MODULE_H__
++ err = -EISDIR;
++ if (unlikely(S_ISDIR(a->inode->i_mode)))
++ goto out;
+
-+#ifdef __KERNEL__
++ err = -EINVAL;
++ if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
++ a->mvd_bsrc = au_ibstart(a->inode);
++ else {
++ a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
++ if (unlikely(a->mvd_bsrc < 0
++ || (a->mvd_bsrc < au_dbstart(a->dentry)
++ || au_dbend(a->dentry) < a->mvd_bsrc
++ || !au_h_dptr(a->dentry, a->mvd_bsrc))
++ || (a->mvd_bsrc < au_ibstart(a->inode)
++ || au_ibend(a->inode) < a->mvd_bsrc
++ || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
++ a->mvd_errno = EAU_MVDOWN_NOUPPER;
++ AU_MVD_PR(dmsg, "no upper\n");
++ goto out;
++ }
++ }
++ if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
++ a->mvd_errno = EAU_MVDOWN_BOTTOM;
++ AU_MVD_PR(dmsg, "on the bottom\n");
++ goto out;
++ }
++ a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
++ br = au_sbr(a->sb, a->mvd_bsrc);
++ err = au_br_rdonly(br);
++ if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
++ if (unlikely(err))
++ goto out;
++ } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
++ || IS_APPEND(a->mvd_h_src_inode))) {
++ if (err)
++ a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
++ /* go on */
++ } else
++ goto out;
+
-+#include <linux/slab.h>
++ err = -EINVAL;
++ if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
++ a->mvd_bdst = find_lower_writable(a);
++ if (unlikely(a->mvd_bdst < 0)) {
++ a->mvd_errno = EAU_MVDOWN_BOTTOM;
++ AU_MVD_PR(dmsg, "no writable lower branch\n");
++ goto out;
++ }
++ } else {
++ a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
++ if (unlikely(a->mvd_bdst < 0
++ || au_sbend(a->sb) < a->mvd_bdst)) {
++ a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
++ AU_MVD_PR(dmsg, "no lower brid\n");
++ goto out;
++ }
++ }
+
-+struct path;
-+struct seq_file;
++ err = au_mvd_args_busy(dmsg, a);
++ if (!err)
++ err = au_mvd_args_parent(dmsg, a);
++ if (!err)
++ err = au_mvd_args_intermediate(dmsg, a);
++ if (!err)
++ err = au_mvd_args_exist(dmsg, a);
++ if (!err)
++ AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
+
-+/* module parameters */
-+extern int sysaufs_brs;
++out:
++ AuTraceErr(err);
++ return err;
++}
+
-+/* ---------------------------------------------------------------------- */
++int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
++{
++ int err, e;
++ unsigned char dmsg;
++ struct au_mvd_args *args;
+
-+extern int au_dir_roflags;
++ err = -EPERM;
++ if (unlikely(!capable(CAP_SYS_ADMIN)))
++ goto out;
+
-+void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
-+int au_seq_path(struct seq_file *seq, struct path *path);
++ WARN_ONCE(1, "move-down is still testing...\n");
+
-+#ifdef CONFIG_PROC_FS
-+/* procfs.c */
-+int __init au_procfs_init(void);
-+void au_procfs_fin(void);
-+#else
-+AuStubInt0(au_procfs_init, void);
-+AuStubVoid(au_procfs_fin, void);
-+#endif
++ err = -ENOMEM;
++ args = kmalloc(sizeof(*args), GFP_NOFS);
++ if (unlikely(!args))
++ goto out;
+
-+/* ---------------------------------------------------------------------- */
++ err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
++ if (!err)
++ err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
++ if (unlikely(err)) {
++ err = -EFAULT;
++ AuTraceErr(err);
++ goto out_free;
++ }
++ AuDbg("flags 0x%x\n", args->mvdown.flags);
++ args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
++ args->mvdown.au_errno = 0;
++ args->dentry = dentry;
++ args->inode = dentry->d_inode;
++ args->sb = dentry->d_sb;
+
-+/* kmem cache */
-+enum {
-+ AuCache_DINFO,
-+ AuCache_ICNTNR,
-+ AuCache_FINFO,
-+ AuCache_VDIR,
-+ AuCache_DEHSTR,
-+#ifdef CONFIG_AUFS_HNOTIFY
-+ AuCache_HNOTIFY,
-+#endif
-+ AuCache_Last
-+};
++ err = -ENOENT;
++ dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
++ args->parent = dget_parent(dentry);
++ args->dir = args->parent->d_inode;
++ mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
++ dput(args->parent);
++ if (unlikely(args->parent != dentry->d_parent)) {
++ AU_MVD_PR(dmsg, "parent dir is moved\n");
++ goto out_dir;
++ }
+
-+#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
-+#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
-+#define AuCacheCtor(type, ctor) \
-+ kmem_cache_create(#type, sizeof(struct type), \
-+ __alignof__(struct type), AuCacheFlags, ctor)
++ mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
++ err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
++ if (unlikely(err))
++ goto out_inode;
+
-+extern struct kmem_cache *au_cachep[];
++ di_write_lock_parent(args->parent);
++ err = au_mvd_args(dmsg, args);
++ if (unlikely(err))
++ goto out_parent;
+
-+#define AuCacheFuncs(name, index) \
-+static inline struct au_##name *au_cache_alloc_##name(void) \
-+{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
-+static inline void au_cache_free_##name(struct au_##name *p) \
-+{ kmem_cache_free(au_cachep[AuCache_##index], p); }
++ AuDbgDentry(dentry);
++ AuDbgInode(args->inode);
++ err = au_do_mvdown(dmsg, args);
++ if (unlikely(err))
++ goto out_parent;
++ AuDbgDentry(dentry);
++ AuDbgInode(args->inode);
+
-+AuCacheFuncs(dinfo, DINFO);
-+AuCacheFuncs(icntnr, ICNTNR);
-+AuCacheFuncs(finfo, FINFO);
-+AuCacheFuncs(vdir, VDIR);
-+AuCacheFuncs(vdir_dehstr, DEHSTR);
-+#ifdef CONFIG_AUFS_HNOTIFY
-+AuCacheFuncs(hnotify, HNOTIFY);
-+#endif
++ au_cpup_attr_timesizes(args->dir);
++ au_cpup_attr_timesizes(args->inode);
++ au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
++ /* au_digen_dec(dentry); */
+
-+#endif /* __KERNEL__ */
-+#endif /* __AUFS_MODULE_H__ */
++out_parent:
++ di_write_unlock(args->parent);
++ aufs_read_unlock(dentry, AuLock_DW);
++out_inode:
++ mutex_unlock(&args->inode->i_mutex);
++out_dir:
++ mutex_unlock(&args->dir->i_mutex);
++out_free:
++ e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
++ if (unlikely(e))
++ err = -EFAULT;
++ kfree(args);
++out:
++ AuTraceErr(err);
++ return err;
++}
diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
--- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/opts.c 2011-10-24 20:51:51.580466925 +0200
-@@ -0,0 +1,1679 @@
++++ linux/fs/aufs/opts.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,1701 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * mount options/flags
+ */
+
-+#include <linux/file.h>
-+#include <linux/jiffies.h>
+#include <linux/namei.h>
+#include <linux/types.h> /* a distribution requires */
+#include <linux/parser.h>
+ {0, NULL}
+};
+
-+static match_table_t brrattr = {
++static match_table_t brattr = {
++ {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
+ {AuBrRAttr_WH, AUFS_BRRATTR_WH},
-+ {0, NULL}
-+};
-+
-+static match_table_t brwattr = {
+ {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
+ {0, NULL}
+};
+
-+#define AuBrStr_LONGEST AUFS_BRPERM_RW "+" AUFS_BRWATTR_NLWH
++#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[])
+{
+ else {
+ if (p)
+ *p = '+';
-+ pr_warning("ignored branch attribute %s\n", str);
++ pr_warn("ignored branch attribute %s\n", str);
+ break;
+ }
+ if (p)
+static int noinline_for_stack br_perm_val(char *perm)
+{
+ int val;
-+ char *p;
++ char *p, *q;
+ substring_t args[MAX_OPT_ARGS];
+
+ p = strchr(perm, '+');
+ if (!val) {
+ if (p)
+ *p = '+';
-+ pr_warning("ignored branch permission %s\n", perm);
++ pr_warn("ignored branch permission %s\n", perm);
+ val = AuBrPerm_RO;
+ goto out;
+ }
+ if (!p)
+ goto out;
+
-+ switch (val) {
++ 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;
++ }
++ switch (val & AuBrPerm_Mask) {
+ case AuBrPerm_RO:
+ case AuBrPerm_RR:
-+ val |= br_attr_val(p + 1, brrattr, args);
++ if (unlikely(val & AuBrWAttr_NoLinkWH)) {
++ pr_warn("ignored branch attribute %s\n",
++ AUFS_BRWATTR_NLWH);
++ val &= ~AuBrWAttr_NoLinkWH;
++ }
+ break;
+ case AuBrPerm_RW:
-+ val |= br_attr_val(p + 1, brwattr, args);
++ if (unlikely(val & AuBrRAttr_WH)) {
++ pr_warn("ignored branch attribute %s\n",
++ AUFS_BRRATTR_WH);
++ val &= ~AuBrRAttr_WH;
++ }
+ break;
+ }
+
+ AuDebugOn(1);
+ }
+
++ AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
+ AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
+ AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
+
+ {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
+ {AuWbrCreate_PMFS, "pmfs"},
+ {AuWbrCreate_PMFSV, "pmfs:%d"},
++ {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
++ {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
+
+ {-1, NULL}
+};
+/*
+ * cf. linux/lib/parser.c and cmdline.c
+ * gave up calling memparse() since it uses simple_strtoull() instead of
-+ * strict_...().
++ * kstrto...().
+ */
+static int noinline_for_stack
+au_match_ull(substring_t *s, unsigned long long *result)
+ if (len + 1 <= sizeof(a)) {
+ memcpy(a, s->from, len);
+ a[len] = '\0';
-+ err = strict_strtoull(a, 0, result);
++ err = kstrtoull(a, 0, result);
+ }
+ return err;
+}
+ create->wbr_create = err;
+ switch (err) {
+ case AuWbrCreate_MFSRRV:
++ case AuWbrCreate_PMFSRRV:
+ e = au_wbr_mfs_wmark(&args[0], str, create);
+ if (!e)
+ e = au_wbr_mfs_sec(&args[1], str, create);
+ err = e;
+ break;
+ case AuWbrCreate_MFSRR:
++ case AuWbrCreate_PMFSRR:
+ e = au_wbr_mfs_wmark(&args[0], str, create);
+ if (unlikely(e)) {
+ err = e;
+ break;
+ case Opt_xino:
+ u.xino = &opt->xino;
-+ AuDbg("xino {%s %.*s}\n",
-+ u.xino->path,
-+ AuDLNPair(u.xino->file->f_dentry));
++ AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
+ break;
+ case Opt_trunc_xino:
+ AuLabel(trunc_xino);
+ u.create->mfsrr_watermark);
+ break;
+ case AuWbrCreate_MFSRRV:
++ case AuWbrCreate_PMFSRRV:
+ AuDbg("%llu watermark, %d sec\n",
+ u.create->mfsrr_watermark,
+ u.create->mfs_second);
+ break;
+
+ case Opt_ignore:
-+ pr_warning("ignored %s\n", opt_str);
++ pr_warn("ignored %s\n", opt_str);
+ /*FALLTHROUGH*/
+ case Opt_ignore_silent:
+ skipped = 1;
+ switch (create->wbr_create) {
+ case AuWbrCreate_MFSRRV:
+ case AuWbrCreate_MFSRR:
++ case AuWbrCreate_PMFSRR:
++ case AuWbrCreate_PMFSRRV:
+ sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
+ /*FALLTHROUGH*/
+ case AuWbrCreate_MFS:
+ goto add;
+ case Opt_prepend:
+ opt->add.bindex = 0;
-+ add:
++ add: /* indented label */
+ case Opt_add:
+ err = au_br_add(sb, &opt->add,
+ au_ftest_opts(opts->flags, REMOUNT));
+
+ if (!(sb_flags & MS_RDONLY)) {
+ if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
-+ pr_warning("first branch should be rw\n");
++ pr_warn("first branch should be rw\n");
+ if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
-+ pr_warning("shwh should be used with ro\n");
++ pr_warn("shwh should be used with ro\n");
+ }
+
+ if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
+ && !au_opt_test(sbinfo->si_mntflags, XINO))
-+ pr_warning("udba=*notify requires xino\n");
++ pr_warn("udba=*notify requires xino\n");
+
+ err = 0;
+ root = sb->s_root;
+ au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
+ if (wbr)
+ wbr_wh_write_lock(wbr);
-+ err = au_wh_init(au_h_dptr(root, bindex), br, sb);
++ err = au_wh_init(br, sb);
+ if (wbr)
+ wbr_wh_write_unlock(wbr);
+ au_hn_imtx_unlock(hdir);
+}
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 2011-10-24 20:51:51.580466925 +0200
++++ linux/fs/aufs/opts.h 2014-01-30 21:10:02.857481956 +0100
@@ -0,0 +1,210 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#ifdef __KERNEL__
+
+#include <linux/path.h>
-+#include <linux/aufs_type.h>
+
+struct file;
+struct super_block;
+ AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
+ AuWbrCreate_PMFS, /* parent and mfs */
+ AuWbrCreate_PMFSV, /* parent and mfs with seconds */
++ AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
++ AuWbrCreate_PMFSRRV, /* plus seconds */
+
+ AuWbrCreate_Def = AuWbrCreate_TDP
+};
+#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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,515 @@
++++ linux/fs/aufs/plink.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,532 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+/* ---------------------------------------------------------------------- */
+
-+struct pseudo_link {
-+ union {
-+ struct list_head list;
-+ struct rcu_head rcu;
-+ };
-+ struct inode *inode;
-+};
-+
+#ifdef CONFIG_AUFS_DEBUG
+void au_plink_list(struct super_block *sb)
+{
++ int i;
+ struct au_sbinfo *sbinfo;
-+ struct list_head *plink_list;
++ struct hlist_head *plink_hlist;
+ struct pseudo_link *plink;
+
+ SiMustAnyLock(sb);
+ AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
+ AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
+
-+ plink_list = &sbinfo->si_plink.head;
-+ rcu_read_lock();
-+ list_for_each_entry_rcu(plink, plink_list, list)
-+ AuDbg("%lu\n", plink->inode->i_ino);
-+ rcu_read_unlock();
++ for (i = 0; i < AuPlink_NHASH; i++) {
++ plink_hlist = &sbinfo->si_plink[i].head;
++ rcu_read_lock();
++ hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
++ AuDbg("%lu\n", plink->inode->i_ino);
++ rcu_read_unlock();
++ }
+}
+#endif
+
+/* is the inode pseudo-linked? */
+int au_plink_test(struct inode *inode)
+{
-+ int found;
++ int found, i;
+ struct au_sbinfo *sbinfo;
-+ struct list_head *plink_list;
++ struct hlist_head *plink_hlist;
+ struct pseudo_link *plink;
+
+ sbinfo = au_sbi(inode->i_sb);
+ AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
+
+ found = 0;
-+ plink_list = &sbinfo->si_plink.head;
++ i = au_plink_hash(inode->i_ino);
++ plink_hlist = &sbinfo->si_plink[i].head;
+ rcu_read_lock();
-+ list_for_each_entry_rcu(plink, plink_list, list)
++ hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
+ if (plink->inode == inode) {
+ found = 1;
+ break;
+
+ h_mtx = &h_parent->d_inode->i_mutex;
+ mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
-+ h_dentry = au_lkup_one(tgtname, h_parent, br, /*nd*/NULL);
++ h_dentry = vfsub_lkup_one(tgtname, h_parent);
+ mutex_unlock(h_mtx);
+ return h_dentry;
+}
+ struct inode *h_dir;
+ int wkq_err;
+ char a[PLINK_NAME_LEN];
-+ struct qstr tgtname = {
-+ .name = a
-+ };
++ struct qstr tgtname = QSTR_INIT(a, 0);
+
+ AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
+
+ h_dir = h_parent->d_inode;
+ tgtname.len = plink_name(a, sizeof(a), inode, bindex);
+
-+ if (current_fsuid()) {
++ if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
+ struct au_do_plink_lkup_args args = {
+ .errp = &h_dentry,
+ .tgtname = &tgtname,
+{
+ int err;
+ struct path h_path = {
-+ .mnt = br->br_mnt
++ .mnt = au_br_mnt(br)
+ };
-+ struct inode *h_dir;
++ struct inode *h_dir, *delegated;
+
+ h_dir = h_parent->d_inode;
+ mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
+again:
-+ h_path.dentry = au_lkup_one(tgt, h_parent, br, /*nd*/NULL);
++ h_path.dentry = vfsub_lkup_one(tgt, h_parent);
+ err = PTR_ERR(h_path.dentry);
+ if (IS_ERR(h_path.dentry))
+ goto out;
+ /* todo: is it really safe? */
+ if (h_path.dentry->d_inode
+ && h_path.dentry->d_inode != h_dentry->d_inode) {
-+ err = vfsub_unlink(h_dir, &h_path, /*force*/0);
++ delegated = NULL;
++ err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
++ }
+ dput(h_path.dentry);
+ h_path.dentry = NULL;
+ if (!err)
+ goto again;
+ }
-+ if (!err && !h_path.dentry->d_inode)
-+ err = vfsub_link(h_dentry, h_dir, &h_path);
++ if (!err && !h_path.dentry->d_inode) {
++ delegated = NULL;
++ err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal link\n");
++ iput(delegated);
++ }
++ }
+ dput(h_path.dentry);
+
+out:
+ struct dentry *h_parent;
+ struct inode *h_dir;
+ char a[PLINK_NAME_LEN];
-+ struct qstr tgtname = {
-+ .name = a
-+ };
++ struct qstr tgtname = QSTR_INIT(a, 0);
+
+ wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
+ h_parent = wbr->wbr_plink;
+ tgtname.len = plink_name(a, sizeof(a), inode, bindex);
+
+ /* always superio. */
-+ if (current_fsuid()) {
++ if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
+ struct do_whplink_args args = {
+ .errp = &err,
+ .tgt = &tgtname,
+static void do_put_plink(struct pseudo_link *plink, int do_del)
+{
+ if (do_del)
-+ list_del(&plink->list);
++ hlist_del(&plink->hlist);
+ iput(plink->inode);
+ kfree(plink);
+}
+{
+ struct super_block *sb;
+ struct au_sbinfo *sbinfo;
-+ struct list_head *plink_list;
++ struct hlist_head *plink_hlist;
+ struct pseudo_link *plink, *tmp;
-+ int found, err, cnt;
++ struct au_sphlhead *sphl;
++ int found, err, cnt, i;
+
+ sb = inode->i_sb;
+ sbinfo = au_sbi(sb);
+ AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
+ AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
+
-+ cnt = 0;
-+ found = 0;
-+ plink_list = &sbinfo->si_plink.head;
-+ rcu_read_lock();
-+ list_for_each_entry_rcu(plink, plink_list, list) {
-+ cnt++;
-+ if (plink->inode == inode) {
-+ found = 1;
-+ break;
-+ }
-+ }
-+ rcu_read_unlock();
++ found = au_plink_test(inode);
+ if (found)
+ return;
+
++ i = au_plink_hash(inode->i_ino);
++ sphl = sbinfo->si_plink + i;
++ plink_hlist = &sphl->head;
+ tmp = kmalloc(sizeof(*plink), GFP_NOFS);
+ if (tmp)
+ tmp->inode = au_igrab(inode);
+ goto out;
+ }
+
-+ spin_lock(&sbinfo->si_plink.spin);
-+ list_for_each_entry(plink, plink_list, list) {
++ spin_lock(&sphl->spin);
++ hlist_for_each_entry(plink, plink_hlist, hlist) {
+ if (plink->inode == inode) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
-+ list_add_rcu(&tmp->list, plink_list);
-+ spin_unlock(&sbinfo->si_plink.spin);
++ hlist_add_head_rcu(&tmp->hlist, plink_hlist);
++ spin_unlock(&sphl->spin);
+ if (!found) {
-+ cnt++;
-+ WARN_ONCE(cnt > AUFS_PLINK_WARN,
-+ "unexpectedly many pseudo links, %d\n", cnt);
++ cnt = au_sphl_count(sphl);
++#define msg "unexpectedly unblanced or too many pseudo-links"
++ if (cnt > AUFS_PLINK_WARN)
++ AuWarn1(msg ", %d\n", cnt);
++#undef msg
+ err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
+ } else {
+ do_put_plink(tmp, 0);
+
+out:
+ if (unlikely(err)) {
-+ pr_warning("err %d, damaged pseudo link.\n", err);
++ pr_warn("err %d, damaged pseudo link.\n", err);
+ if (tmp) {
-+ au_spl_del_rcu(&tmp->list, &sbinfo->si_plink);
++ au_sphl_del_rcu(&tmp->hlist, sphl);
+ call_rcu(&tmp->rcu, do_put_plink_rcu);
+ }
+ }
+/* free all plinks */
+void au_plink_put(struct super_block *sb, int verbose)
+{
++ int i, warned;
+ struct au_sbinfo *sbinfo;
-+ struct list_head *plink_list;
-+ struct pseudo_link *plink, *tmp;
++ struct hlist_head *plink_hlist;
++ struct hlist_node *tmp;
++ struct pseudo_link *plink;
+
+ SiMustWriteLock(sb);
+
+ AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
+ AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
+
-+ plink_list = &sbinfo->si_plink.head;
+ /* no spin_lock since sbinfo is write-locked */
-+ WARN(verbose && !list_empty(plink_list), "pseudo-link is not flushed");
-+ list_for_each_entry_safe(plink, tmp, plink_list, list)
-+ do_put_plink(plink, 0);
-+ INIT_LIST_HEAD(plink_list);
++ warned = 0;
++ for (i = 0; i < AuPlink_NHASH; i++) {
++ plink_hlist = &sbinfo->si_plink[i].head;
++ if (!warned && verbose && !hlist_empty(plink_hlist)) {
++ pr_warn("pseudo-link is not flushed");
++ warned = 1;
++ }
++ hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
++ do_put_plink(plink, 0);
++ INIT_HLIST_HEAD(plink_hlist);
++ }
+}
+
+void au_plink_clean(struct super_block *sb, int verbose)
+ aufs_write_unlock(root);
+}
+
++static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
++{
++ int do_put;
++ aufs_bindex_t bstart, bend, bindex;
++
++ do_put = 0;
++ bstart = au_ibstart(inode);
++ bend = au_ibend(inode);
++ if (bstart >= 0) {
++ for (bindex = bstart; bindex <= bend; bindex++) {
++ if (!au_h_iptr(inode, bindex)
++ || au_ii_br_id(inode, bindex) != br_id)
++ continue;
++ au_set_h_iptr(inode, bindex, NULL, 0);
++ do_put = 1;
++ break;
++ }
++ if (do_put)
++ for (bindex = bstart; bindex <= bend; bindex++)
++ if (au_h_iptr(inode, bindex)) {
++ do_put = 0;
++ break;
++ }
++ } else
++ do_put = 1;
++
++ return do_put;
++}
++
+/* free the plinks on a branch specified by @br_id */
+void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
+{
+ struct au_sbinfo *sbinfo;
-+ struct list_head *plink_list;
-+ struct pseudo_link *plink, *tmp;
++ struct hlist_head *plink_hlist;
++ struct hlist_node *tmp;
++ struct pseudo_link *plink;
+ struct inode *inode;
-+ aufs_bindex_t bstart, bend, bindex;
-+ unsigned char do_put;
++ int i, do_put;
+
+ SiMustWriteLock(sb);
+
+ AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
+ AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
+
-+ plink_list = &sbinfo->si_plink.head;
+ /* no spin_lock since sbinfo is write-locked */
-+ list_for_each_entry_safe(plink, tmp, plink_list, list) {
-+ do_put = 0;
-+ inode = au_igrab(plink->inode);
-+ ii_write_lock_child(inode);
-+ bstart = au_ibstart(inode);
-+ bend = au_ibend(inode);
-+ if (bstart >= 0) {
-+ for (bindex = bstart; bindex <= bend; bindex++) {
-+ if (!au_h_iptr(inode, bindex)
-+ || au_ii_br_id(inode, bindex) != br_id)
-+ continue;
-+ au_set_h_iptr(inode, bindex, NULL, 0);
-+ do_put = 1;
-+ break;
-+ }
-+ } else
-+ do_put_plink(plink, 1);
-+
-+ if (do_put) {
-+ for (bindex = bstart; bindex <= bend; bindex++)
-+ if (au_h_iptr(inode, bindex)) {
-+ do_put = 0;
-+ break;
-+ }
++ for (i = 0; i < AuPlink_NHASH; i++) {
++ plink_hlist = &sbinfo->si_plink[i].head;
++ hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
++ inode = au_igrab(plink->inode);
++ ii_write_lock_child(inode);
++ do_put = au_plink_do_half_refresh(inode, br_id);
+ if (do_put)
+ do_put_plink(plink, 1);
++ ii_write_unlock(inode);
++ iput(inode);
+ }
-+ ii_write_unlock(inode);
-+ iput(inode);
+ }
+}
diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
--- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/poll.c 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,56 @@
++++ linux/fs/aufs/poll.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,55 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ /* it is not an error if h_file has no operation */
+ mask = DEFAULT_POLLMASK;
+ h_file = au_hf_top(file);
-+ if (h_file->f_op && h_file->f_op->poll)
++ if (h_file->f_op->poll)
+ mask = h_file->f_op->poll(h_file, wait);
+
+ di_read_unlock(dentry, AuLock_IR);
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,170 @@
++++ linux/fs/aufs/procfs.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,169 @@
+/*
-+ * Copyright (C) 2010-2011 Junjiro R. Okajima
++ * Copyright (C) 2010-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, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ } else if (unlikely(strncmp("si=", buf, 3)))
+ goto out;
+
-+ err = strict_strtoul(buf + 3, 16, &id);
++ err = kstrtoul(buf + 3, 16, &id);
+ if (unlikely(err))
+ goto out;
+
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,383 @@
++++ linux/fs/aufs/rdu.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,388 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#include <linux/compat.h>
+#include <linux/fs_stack.h>
+#include <linux/security.h>
-+#include <linux/uaccess.h>
-+#include <linux/aufs_type.h>
+#include "aufs.h"
+
+/* bits for struct aufs_rdu.flags */
+ do { (flags) &= ~AuRdu_##name; } while (0)
+
+struct au_rdu_arg {
++ struct dir_context ctx;
+ struct aufs_rdu *rdu;
+ union au_rdu_ent_ul ent;
+ unsigned long end;
+ int err;
+};
+
-+static int au_rdu_fill(void *__arg, const char *name, int nlen,
++static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
+ loff_t offset, u64 h_ino, unsigned int d_type)
+{
+ int err, len;
-+ struct au_rdu_arg *arg = __arg;
++ struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
+ struct aufs_rdu *rdu = arg->rdu;
+ struct au_rdu_ent ent;
+
+ if (unlikely(nlen > AUFS_MAX_NAMELEN))
+ ent.type = DT_UNKNOWN;
+
++ /* unnecessary to support mmap_sem since this is a dir */
+ err = -EFAULT;
+ if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
+ goto out;
+ loff_t offset;
+ struct au_rdu_cookie *cookie = &arg->rdu->cookie;
+
++ /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
+ offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
+ err = offset;
+ if (unlikely(offset != cookie->h_pos))
+ arg->err = 0;
+ au_fclr_rdu(cookie->flags, CALLED);
+ /* smp_mb(); */
-+ err = vfsub_readdir(h_file, au_rdu_fill, arg);
++ err = vfsub_iterate_dir(h_file, &arg->ctx);
+ if (err >= 0)
+ err = arg->err;
+ } while (!err
+{
+ int err;
+ aufs_bindex_t bend;
-+ struct au_rdu_arg arg;
++ struct au_rdu_arg arg = {
++ .ctx = {
++ .actor = au_diractor(au_rdu_fill)
++ }
++ };
+ struct dentry *dentry;
+ struct inode *inode;
+ struct file *h_file;
+ arg.end += rdu->sz;
+
+ err = -ENOTDIR;
-+ if (unlikely(!file->f_op || !file->f_op->readdir))
++ if (unlikely(!file->f_op->iterate))
+ goto out;
+
+ err = security_file_permission(file, MAY_READ);
+ sb = file->f_dentry->d_sb;
+ si_read_lock(sb, AuLock_FLUSH);
+ while (nent-- > 0) {
++ /* unnecessary to support mmap_sem since this is a dir */
+ err = copy_from_user(&ent, u->e, sizeof(ent));
+ if (!err)
+ err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
+#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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,189 @@
++++ linux/fs/aufs/rwsem.h 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,187 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/rwsem.h>
+#include "debug.h"
+
+struct au_rwsem {
+#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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,344 @@
++++ linux/fs/aufs/sbinfo.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,351 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * superblock private data
+ */
+
-+#include <linux/jiffies.h>
+#include "aufs.h"
+
+/*
+ */
+void au_si_free(struct kobject *kobj)
+{
++ int i;
+ struct au_sbinfo *sbinfo;
+ char *locked __maybe_unused; /* debug only */
+
+ sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
-+ AuDebugOn(!list_empty(&sbinfo->si_plink.head));
++ for (i = 0; i < AuPlink_NHASH; i++)
++ AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
+ AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
+
+ au_rw_write_lock(&sbinfo->si_rwsem);
+
+int au_si_alloc(struct super_block *sb)
+{
-+ int err;
++ int err, i;
+ struct au_sbinfo *sbinfo;
+ static struct lock_class_key aufs_si;
+
+ atomic_long_set(&sbinfo->si_nfiles, 0);
+
+ sbinfo->si_bend = -1;
++ sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
+
+ sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
+ sbinfo->si_wbr_create = AuWbrCreate_Def;
+
+ sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
+
++ sbinfo->si_xino_jiffy = jiffies;
++ sbinfo->si_xino_expire
++ = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
+ mutex_init(&sbinfo->si_xib_mtx);
+ sbinfo->si_xino_brid = -1;
+ /* leave si_xib_last_pindex and si_xib_next_bit */
+ sbinfo->si_rdhash = AUFS_RDHASH_DEF;
+ sbinfo->si_dirwh = AUFS_DIRWH_DEF;
+
-+ au_spl_init(&sbinfo->si_plink);
++ for (i = 0; i < AuPlink_NHASH; i++)
++ au_sphl_init(sbinfo->si_plink + i);
+ init_waitqueue_head(&sbinfo->si_plink_wq);
+ spin_lock_init(&sbinfo->si_plink_maint_lock);
+
++ au_sphl_init(&sbinfo->si_files);
++
+ /* leave other members for sysaufs and si_mnt. */
+ sbinfo->si_sb = sb;
+ sb->s_fs_info = sbinfo;
+
+ gen = ++au_sbi(sb)->si_generation;
+ au_update_digen(sb->s_root);
-+ au_update_iigen(sb->s_root->d_inode);
++ au_update_iigen(sb->s_root->d_inode, /*half*/0);
+ sb->s_root->d_inode->i_version++;
+ return gen;
+}
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,66 @@
++++ linux/fs/aufs/spl.h 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,111 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/spinlock.h>
-+#include <linux/list.h>
-+#include <linux/rculist.h>
-+
+struct au_splhead {
+ spinlock_t spin;
+ struct list_head head;
+ spin_unlock(&spl->spin);
+}
+
++/* ---------------------------------------------------------------------- */
++
++struct au_sphlhead {
++ spinlock_t spin;
++ struct hlist_head head;
++};
++
++static inline void au_sphl_init(struct au_sphlhead *sphl)
++{
++ spin_lock_init(&sphl->spin);
++ INIT_HLIST_HEAD(&sphl->head);
++}
++
++static inline void au_sphl_add(struct hlist_node *hlist,
++ struct au_sphlhead *sphl)
++{
++ spin_lock(&sphl->spin);
++ hlist_add_head(hlist, &sphl->head);
++ spin_unlock(&sphl->spin);
++}
++
++static inline void au_sphl_del(struct hlist_node *hlist,
++ struct au_sphlhead *sphl)
++{
++ spin_lock(&sphl->spin);
++ hlist_del(hlist);
++ spin_unlock(&sphl->spin);
++}
++
++static inline void au_sphl_del_rcu(struct hlist_node *hlist,
++ struct au_sphlhead *sphl)
++{
++ spin_lock(&sphl->spin);
++ hlist_del_rcu(hlist);
++ spin_unlock(&sphl->spin);
++}
++
++static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
++{
++ unsigned long cnt;
++ struct hlist_node *pos;
++
++ cnt = 0;
++ spin_lock(&sphl->spin);
++ hlist_for_each(pos, &sphl->head)
++ cnt++;
++ spin_unlock(&sphl->spin);
++ return cnt;
++}
++
+#endif /* __KERNEL__ */
+#endif /* __AUFS_SPL_H__ */
diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
--- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/super.c 2011-10-24 20:51:51.583800333 +0200
-@@ -0,0 +1,939 @@
++++ linux/fs/aufs/super.c 2014-03-13 19:59:53.391752805 +0100
+@@ -0,0 +1,1001 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * mount and super_block operations
+ */
+
-+#include <linux/buffer_head.h>
-+#include <linux/jiffies.h>
++#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+#include <linux/statfs.h>
+{
+ struct inode *inode = container_of(head, struct inode, i_rcu);
+
-+ INIT_LIST_HEAD(&inode->i_dentry);
++ INIT_HLIST_HEAD(&inode->i_dentry);
+ au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
+}
+
+ hdp = au_di(sb->s_root)->di_hdentry;
+ for (bindex = 0; !err && bindex <= bend; bindex++) {
+ br = au_sbr(sb, bindex);
-+ path.mnt = br->br_mnt;
++ path.mnt = au_br_mnt(br);
+ path.dentry = hdp[bindex].hd_dentry;
+ err = au_seq_path(seq, &path);
+ if (err > 0) {
+
+ AuRwMustAnyLock(&sbinfo->si_rwsem);
+
-+ seq_printf(m, ",create=");
++ seq_puts(m, ",create=");
+ pat = au_optstr_wbr_create(v);
+ switch (v) {
+ case AuWbrCreate_TDP:
+ case AuWbrCreate_RR:
+ case AuWbrCreate_MFS:
+ case AuWbrCreate_PMFS:
-+ seq_printf(m, pat);
++ seq_puts(m, pat);
+ break;
+ case AuWbrCreate_MFSV:
+ seq_printf(m, /*pat*/"mfs:%lu",
+ jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
+ / MSEC_PER_SEC);
+ break;
++ case AuWbrCreate_PMFSRR:
++ seq_printf(m, /*pat*/"pmfsrr:%llu",
++ sbinfo->si_wbr_mfs.mfsrr_watermark);
++ break;
++ case AuWbrCreate_PMFSRRV:
++ seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
++ sbinfo->si_wbr_mfs.mfsrr_watermark,
++ jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
++ / MSEC_PER_SEC);
++ break;
+ }
+}
+
-+static int au_show_xino(struct seq_file *seq, struct vfsmount *mnt)
++static int au_show_xino(struct seq_file *seq, struct super_block *sb)
+{
+#ifdef CONFIG_SYSFS
+ return 0;
+ int err;
+ const int len = sizeof(AUFS_XINO_FNAME) - 1;
+ aufs_bindex_t bindex, brid;
-+ struct super_block *sb;
+ struct qstr *name;
+ struct file *f;
+ struct dentry *d, *h_root;
+ AuRwMustAnyLock(&sbinfo->si_rwsem);
+
+ err = 0;
-+ sb = mnt->mnt_sb;
+ f = au_sbi(sb)->si_xib;
+ if (!f)
+ goto out;
+}
+
+/* seq_file will re-call me in case of too long string */
-+static int aufs_show_options(struct seq_file *m, struct vfsmount *mnt)
++static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
+{
+ int err;
+ unsigned int mnt_flags, v;
+} while (0)
+
+ /* lock free root dinfo */
-+ sb = mnt->mnt_sb;
++ sb = dentry->d_sb;
+ si_noflush_read_lock(sb);
+ sbinfo = au_sbi(sb);
+ seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
+
+ mnt_flags = au_mntflags(sb);
+ if (au_opt_test(mnt_flags, XINO)) {
-+ err = au_show_xino(m, mnt);
++ err = au_show_xino(m, sb);
+ if (unlikely(err))
+ goto out;
+ } else
+
+ old = a;
+ a += b;
-+ if (old < a)
++ if (old <= a)
++ return a;
++ return ULLONG_MAX;
++}
++
++static u64 au_mul_till_max(u64 a, long mul)
++{
++ u64 old;
++
++ old = a;
++ a *= mul;
++ if (old <= a)
+ return a;
+ return ULLONG_MAX;
+}
+static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
+{
+ int err;
++ long bsize, factor;
+ u64 blocks, bfree, bavail, files, ffree;
+ aufs_bindex_t bend, bindex, i;
+ unsigned char shared;
+ struct path h_path;
+ struct super_block *h_sb;
+
++ err = 0;
++ bsize = LONG_MAX;
++ files = 0;
++ ffree = 0;
+ blocks = 0;
+ bfree = 0;
+ bavail = 0;
-+ files = 0;
-+ ffree = 0;
-+
-+ err = 0;
+ bend = au_sbend(sb);
-+ for (bindex = bend; bindex >= 0; bindex--) {
++ for (bindex = 0; bindex <= bend; bindex++) {
+ h_path.mnt = au_sbr_mnt(sb, bindex);
+ h_sb = h_path.mnt->mnt_sb;
+ shared = 0;
-+ for (i = bindex + 1; !shared && i <= bend; i++)
++ for (i = 0; !shared && i < bindex; i++)
+ shared = (au_sbr_sb(sb, i) == h_sb);
+ if (shared)
+ continue;
+ if (unlikely(err))
+ goto out;
+
-+ blocks = au_add_till_max(blocks, buf->f_blocks);
-+ bfree = au_add_till_max(bfree, buf->f_bfree);
-+ bavail = au_add_till_max(bavail, buf->f_bavail);
++ if (bsize > buf->f_bsize) {
++ /*
++ * we will reduce bsize, so we have to expand blocks
++ * etc. to match them again
++ */
++ factor = (bsize / buf->f_bsize);
++ blocks = au_mul_till_max(blocks, factor);
++ bfree = au_mul_till_max(bfree, factor);
++ bavail = au_mul_till_max(bavail, factor);
++ bsize = buf->f_bsize;
++ }
++
++ factor = (buf->f_bsize / bsize);
++ blocks = au_add_till_max(blocks,
++ au_mul_till_max(buf->f_blocks, factor));
++ bfree = au_add_till_max(bfree,
++ au_mul_till_max(buf->f_bfree, factor));
++ bavail = au_add_till_max(bavail,
++ au_mul_till_max(buf->f_bavail, factor));
+ files = au_add_till_max(files, buf->f_files);
+ ffree = au_add_till_max(ffree, buf->f_ffree);
+ }
+
++ buf->f_bsize = bsize;
+ buf->f_blocks = blocks;
+ buf->f_bfree = bfree;
+ buf->f_bavail = bavail;
+ buf->f_files = files;
+ buf->f_ffree = ffree;
++ buf->f_frsize = 0;
+
+out:
+ return err;
+
+/* ---------------------------------------------------------------------- */
+
++static int aufs_sync_fs(struct super_block *sb, int wait)
++{
++ int err, e;
++ aufs_bindex_t bend, bindex;
++ struct au_branch *br;
++ struct super_block *h_sb;
++
++ err = 0;
++ si_noflush_read_lock(sb);
++ bend = au_sbend(sb);
++ for (bindex = 0; bindex <= bend; bindex++) {
++ br = au_sbr(sb, bindex);
++ if (!au_br_writable(br->br_perm))
++ continue;
++
++ h_sb = au_sbr_sb(sb, bindex);
++ if (h_sb->s_op->sync_fs) {
++ e = h_sb->s_op->sync_fs(h_sb, wait);
++ if (unlikely(e && !err))
++ err = e;
++ /* go on even if an error happens */
++ }
++ }
++ si_read_unlock(sb);
++
++ return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
+/* final actions when unmounting a file system */
+static void aufs_put_super(struct super_block *sb)
+{
+ sigen = au_sigen(sb);
+ for (ull = 0; ull < max; ull++) {
+ inode = array[ull];
-+ if (au_iigen(inode) != sigen) {
++ if (au_iigen(inode, NULL) != sigen) {
+ ii_write_lock_child(inode);
+ e = au_refresh_hinode_self(inode);
+ ii_write_unlock(inode);
+ .show_options = aufs_show_options,
+ .statfs = aufs_statfs,
+ .put_super = aufs_put_super,
++ .sync_fs = aufs_sync_fs,
+ .remount_fs = aufs_remount_fs
+};
+
+ inode->i_op = &aufs_dir_iop;
+ inode->i_fop = &aufs_dir_fop;
+ inode->i_mode = S_IFDIR;
-+ inode->i_nlink = 2;
++ set_nlink(inode, 2);
+ unlock_new_inode(inode);
+
-+ root = d_alloc_root(inode);
++ root = d_make_root(inode);
+ if (unlikely(!root))
-+ goto out_iput;
++ goto out;
+ err = PTR_ERR(root);
+ if (IS_ERR(root))
-+ goto out_iput;
++ goto out;
+
+ err = au_di_init(root);
+ if (!err) {
+ return 0; /* success */
+ }
+ dput(root);
-+ goto out; /* do not iput */
+
-+out_iput:
-+ iget_failed(inode);
+out:
+ return err;
-+
+}
+
+static int aufs_fill_super(struct super_block *sb, void *raw_data,
+ aufs_write_unlock(sb->s_root);
+ au_nwt_flush(&sbinfo->si_nowait);
+ }
-+ generic_shutdown_super(sb);
++ kill_anon_super(sb);
+}
+
+struct file_system_type aufs_fs_type = {
+ .name = AUFS_FSTYPE,
-+ .fs_flags =
-+ FS_RENAME_DOES_D_MOVE /* a race between rename and others */
-+ | FS_REVAL_DOT, /* for NFS branch and udba */
++ /* a race between rename and others */
++ .fs_flags = FS_RENAME_DOES_D_MOVE,
+ .mount = aufs_mount,
+ .kill_sb = aufs_kill_sb,
+ /* no need to __module_get() and module_put(). */
+};
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,547 @@
++++ linux/fs/aufs/super.h 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,571 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#ifdef __KERNEL__
+
+#include <linux/fs.h>
-+#include <linux/aufs_type.h>
+#include "rwsem.h"
+#include "spl.h"
+#include "wkq.h"
+ int (*copyup)(struct dentry *dentry);
+};
+
++#define AuWbr_DIR 1 /* target is a dir */
++#define AuWbr_PARENT (1 << 1) /* always require a parent */
++
++#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
++#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
++#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
++
+struct au_wbr_create_operations {
-+ int (*create)(struct dentry *dentry, int isdir);
++ int (*create)(struct dentry *dentry, unsigned int flags);
+ int (*init)(struct super_block *sb);
+ int (*fin)(struct super_block *sb);
+};
+ unsigned long long mfsrr_watermark;
+};
+
++struct pseudo_link {
++ union {
++ struct hlist_node hlist;
++ struct rcu_head rcu;
++ };
++ struct inode *inode;
++};
++
++#define AuPlink_NHASH 100
++static inline int au_plink_hash(ino_t ino)
++{
++ return ino % AuPlink_NHASH;
++}
++
+struct au_branch;
+struct au_sbinfo {
+ /* nowait tasks in the system-wide workqueue */
+ } au_si_pid;
+
+ /*
-+ * dirty approach to protect sb->sb_inodes and ->s_files from remount.
++ * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
++ * remount.
+ */
+ atomic_long_t si_ninodes, si_nfiles;
+
+ unsigned long si_xib_last_pindex;
+ int si_xib_next_bit;
+ aufs_bindex_t si_xino_brid;
++ unsigned long si_xino_jiffy;
++ unsigned long si_xino_expire;
+ /* reserved for future use */
+ /* unsigned long long si_xib_limit; */ /* Max xib file size */
+
+ /* int si_rendir; */
+
+ /* pseudo_link list */
-+ struct au_splhead si_plink;
++ struct au_sphlhead si_plink[AuPlink_NHASH];
+ wait_queue_head_t si_plink_wq;
+ spinlock_t si_plink_maint_lock;
+ pid_t si_plink_maint_pid;
+
++ /* file list */
++ struct au_sphlhead si_files;
++
+ /*
+ * sysfs and lifetime management.
+ * this is not a small structure and it may be a waste of memory in case
+ */
+ struct kobject si_kobj;
+#ifdef CONFIG_DEBUG_FS
-+ struct dentry *si_dbgaufs, *si_dbgaufs_xib;
++ struct dentry *si_dbgaufs;
++ struct dentry *si_dbgaufs_plink;
++ struct dentry *si_dbgaufs_xib;
+#ifdef CONFIG_AUFS_EXPORT
+ struct dentry *si_dbgaufs_xigen;
+#endif
+extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
+extern struct au_wbr_create_operations au_wbr_create_ops[];
+int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
++int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
++
++/* mvdown.c */
++int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
+
+/* ---------------------------------------------------------------------- */
+
+/* ---------------------------------------------------------------------- */
+
+#ifdef CONFIG_AUFS_EXPORT
++int au_test_nfsd(void);
+void au_export_init(struct super_block *sb);
-+
-+static inline int au_test_nfsd(void)
-+{
-+ struct task_struct *tsk = current;
-+
-+ return (tsk->flags & PF_KTHREAD)
-+ && !strcmp(tsk->comm, "nfsd");
-+}
-+
+void au_xigen_inc(struct inode *inode);
+int au_xigen_new(struct inode *inode);
+int au_xigen_set(struct super_block *sb, struct file *base);
+ return -ESTALE;
+}
+#else
-+AuStubVoid(au_export_init, struct super_block *sb)
+AuStubInt0(au_test_nfsd, void)
++AuStubVoid(au_export_init, struct super_block *sb)
+AuStubVoid(au_xigen_inc, struct inode *inode)
+AuStubInt0(au_xigen_new, struct inode *inode)
+AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
+ /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
+#ifdef CONFIG_DEBUG_FS
+ sbinfo->si_dbgaufs = NULL;
++ sbinfo->si_dbgaufs_plink = NULL;
+ sbinfo->si_dbgaufs_xib = NULL;
+#ifdef CONFIG_AUFS_EXPORT
+ sbinfo->si_dbgaufs_xigen = NULL;
+#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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,107 @@
++++ linux/fs/aufs/sysaufs.c 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,104 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * they are necessary regardless sysfs is disabled.
+ */
+
-+#include <linux/fs.h>
+#include <linux/random.h>
-+#include <linux/sysfs.h>
+#include "aufs.h"
+
+unsigned long sysaufs_si_mask;
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,105 @@
++++ linux/fs/aufs/sysaufs.h 2014-01-30 21:10:02.857481956 +0100
+@@ -0,0 +1,103 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#ifdef __KERNEL__
+
+#include <linux/sysfs.h>
-+#include <linux/aufs_type.h>
+#include "module.h"
+
+struct super_block;
+#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 2011-10-24 20:51:51.583800333 +0200
-@@ -0,0 +1,260 @@
++++ linux/fs/aufs/sysfs.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,296 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * sysfs interface
+ */
+
-+#include <linux/fs.h>
-+#include <linux/module.h>
+#include <linux/seq_file.h>
-+#include <linux/sysfs.h>
+#include "aufs.h"
+
+#ifdef CONFIG_AUFS_FS_MODULE
+ * unlinked.
+ */
+static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
-+ aufs_bindex_t bindex)
++ aufs_bindex_t bindex, int idx)
+{
+ int err;
+ struct path path;
+ root = sb->s_root;
+ di_read_lock_parent(root, !AuLock_IR);
+ br = au_sbr(sb, bindex);
-+ path.mnt = br->br_mnt;
-+ path.dentry = au_h_dptr(root, bindex);
-+ au_seq_path(seq, &path);
-+ 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);
++
++ switch (idx) {
++ case AuBrSysfs_BR:
++ 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;
++ break;
++ case AuBrSysfs_BRID:
++ err = seq_printf(seq, "%d\n", br->br_id);
++ di_read_unlock(root, !AuLock_IR);
+ if (err == -1)
+ err = -E2BIG;
-+ } else
-+ err = -ENOMEM;
++ break;
++ }
++
+ return err;
+}
+
+ return seq;
+}
+
-+#define SysaufsBr_PREFIX "br"
++#define SysaufsBr_PREFIX "br"
++#define SysaufsBrid_PREFIX "brid"
+
+/* todo: file size may exceed PAGE_SIZE */
+ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ ssize_t err;
++ int idx;
+ long l;
+ aufs_bindex_t bend;
+ struct au_sbinfo *sbinfo;
+ cattr++;
+ }
+
-+ bend = au_sbend(sb);
-+ if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
++ if (!strncmp(name, SysaufsBrid_PREFIX,
++ sizeof(SysaufsBrid_PREFIX) - 1)) {
++ idx = AuBrSysfs_BRID;
++ name += sizeof(SysaufsBrid_PREFIX) - 1;
++ } else if (!strncmp(name, SysaufsBr_PREFIX,
++ sizeof(SysaufsBr_PREFIX) - 1)) {
++ idx = AuBrSysfs_BR;
+ name += sizeof(SysaufsBr_PREFIX) - 1;
-+ err = strict_strtol(name, 10, &l);
-+ if (!err) {
-+ if (l <= bend)
-+ err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l);
-+ else
-+ err = -ENOENT;
-+ }
-+ goto out_seq;
++ } else
++ BUG();
++
++ err = kstrtol(name, 10, &l);
++ if (!err) {
++ bend = au_sbend(sb);
++ if (l <= bend)
++ err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
++ else
++ err = -ENOENT;
+ }
-+ BUG();
+
+out_seq:
+ if (!err) {
+
+void sysaufs_br_init(struct au_branch *br)
+{
-+ struct attribute *attr = &br->br_attr;
++ int i;
++ struct au_brsysfs *br_sysfs;
++ struct attribute *attr;
+
-+ sysfs_attr_init(attr);
-+ attr->name = br->br_name;
-+ attr->mode = S_IRUGO;
++ br_sysfs = br->br_sysfs;
++ for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
++ attr = &br_sysfs->attr;
++ sysfs_attr_init(attr);
++ attr->name = br_sysfs->name;
++ attr->mode = S_IRUGO;
++ br_sysfs++;
++ }
+}
+
+void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
+{
+ struct au_branch *br;
+ struct kobject *kobj;
++ struct au_brsysfs *br_sysfs;
++ int i;
+ aufs_bindex_t bend;
+
+ dbgaufs_brs_del(sb, bindex);
+ bend = au_sbend(sb);
+ for (; bindex <= bend; bindex++) {
+ br = au_sbr(sb, bindex);
-+ sysfs_remove_file(kobj, &br->br_attr);
++ br_sysfs = br->br_sysfs;
++ for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
++ sysfs_remove_file(kobj, &br_sysfs->attr);
++ br_sysfs++;
++ }
+ }
+}
+
+void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
+{
-+ int err;
++ int err, i;
+ aufs_bindex_t bend;
+ struct kobject *kobj;
+ struct au_branch *br;
++ struct au_brsysfs *br_sysfs;
+
+ dbgaufs_brs_add(sb, bindex);
+
+ bend = au_sbend(sb);
+ for (; bindex <= bend; bindex++) {
+ br = au_sbr(sb, bindex);
-+ snprintf(br->br_name, sizeof(br->br_name), SysaufsBr_PREFIX
-+ "%d", bindex);
-+ err = sysfs_create_file(kobj, &br->br_attr);
-+ if (unlikely(err))
-+ pr_warning("failed %s under sysfs(%d)\n",
-+ br->br_name, err);
++ br_sysfs = br->br_sysfs;
++ snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
++ SysaufsBr_PREFIX "%d", bindex);
++ snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
++ SysaufsBrid_PREFIX "%d", bindex);
++ for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
++ err = sysfs_create_file(kobj, &br_sysfs->attr);
++ if (unlikely(err))
++ pr_warn("failed %s under sysfs(%d)\n",
++ br_sysfs->name, err);
++ br_sysfs++;
++ }
+ }
+}
diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
--- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/sysrq.c 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,151 @@
++++ linux/fs/aufs/sysrq.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,154 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * magic sysrq hanlder
+ */
+
-+#include <linux/fs.h>
-+#include <linux/module.h>
-+#include <linux/moduleparam.h>
+/* #include <linux/sysrq.h> */
+#include <linux/writeback.h>
+#include "aufs.h"
+ char *plevel;
+ struct au_sbinfo *sbinfo;
+ struct file *file;
++ struct au_sphlhead *files;
++ struct au_finfo *finfo;
+
+ plevel = au_plevel;
+ au_plevel = KERN_WARNING;
+
-+ sbinfo = au_sbi(sb);
+ /* since we define pr_fmt, call printk directly */
++#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
++
++ sbinfo = au_sbi(sb);
+ printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
-+ printk(KERN_WARNING AUFS_NAME ": superblock\n");
++ pr("superblock\n");
+ au_dpri_sb(sb);
+
+#if 0
-+ printk(KERN_WARNING AUFS_NAME ": root dentry\n");
++ pr("root dentry\n");
+ au_dpri_dentry(sb->s_root);
-+ printk(KERN_WARNING AUFS_NAME ": root inode\n");
++ pr("root inode\n");
+ au_dpri_inode(sb->s_root->d_inode);
+#endif
+
+#if 1
+ {
+ struct inode *i;
-+ printk(KERN_WARNING AUFS_NAME ": isolated inode\n");
++ pr("isolated inode\n");
+ spin_lock(&inode_sb_list_lock);
+ list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
+ spin_lock(&i->i_lock);
-+ if (1 || list_empty(&i->i_dentry))
++ if (1 || hlist_empty(&i->i_dentry))
+ au_dpri_inode(i);
+ spin_unlock(&i->i_lock);
+ }
+ spin_unlock(&inode_sb_list_lock);
+ }
+#endif
-+ printk(KERN_WARNING AUFS_NAME ": files\n");
-+ lg_global_lock(files_lglock);
-+ do_file_list_for_each_entry(sb, file) {
++ pr("files\n");
++ files = &au_sbi(sb)->si_files;
++ spin_lock(&files->spin);
++ hlist_for_each_entry(finfo, &files->head, fi_hlist) {
+ umode_t mode;
-+ mode = file->f_dentry->d_inode->i_mode;
++ file = finfo->fi_file;
++ mode = file_inode(file)->i_mode;
+ if (!special_file(mode) || au_special_file(mode))
+ au_dpri_file(file);
-+ } while_file_list_for_each_entry;
-+ lg_global_unlock(files_lglock);
-+ printk(KERN_WARNING AUFS_NAME ": done\n");
++ }
++ spin_unlock(&files->spin);
++ pr("done\n");
+
++#undef pr
+ au_plevel = plevel;
+}
+
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,886 @@
++++ linux/fs/aufs/vdir.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,887 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * virtual or vertical directory
+ */
+
-+#include <linux/hash.h>
+#include "aufs.h"
+
+static unsigned int calc_size(int nlen)
+
+static void au_nhash_wh_do_free(struct hlist_head *head)
+{
-+ struct au_vdir_wh *tpos;
-+ struct hlist_node *pos, *node;
++ struct au_vdir_wh *pos;
++ struct hlist_node *node;
+
-+ hlist_for_each_entry_safe(tpos, pos, node, head, wh_hash) {
-+ /* hlist_del(pos); */
-+ kfree(tpos);
-+ }
++ hlist_for_each_entry_safe(pos, node, head, wh_hash)
++ kfree(pos);
+}
+
+static void au_nhash_de_do_free(struct hlist_head *head)
+{
-+ struct au_vdir_dehstr *tpos;
-+ struct hlist_node *pos, *node;
++ struct au_vdir_dehstr *pos;
++ struct hlist_node *node;
+
-+ hlist_for_each_entry_safe(tpos, pos, node, head, hash) {
-+ /* hlist_del(pos); */
-+ au_cache_free_vdir_dehstr(tpos);
-+ }
++ hlist_for_each_entry_safe(pos, node, head, hash)
++ au_cache_free_vdir_dehstr(pos);
+}
+
+static void au_nhash_do_free(struct au_nhash *nhash,
+ int num;
+ unsigned int u, n;
+ struct hlist_head *head;
-+ struct au_vdir_wh *tpos;
-+ struct hlist_node *pos;
++ struct au_vdir_wh *pos;
+
+ num = 0;
+ n = whlist->nh_num;
+ head = whlist->nh_head;
+ for (u = 0; u < n; u++, head++)
-+ hlist_for_each_entry(tpos, pos, head, wh_hash)
-+ if (tpos->wh_bindex == btgt && ++num > limit)
++ hlist_for_each_entry(pos, head, wh_hash)
++ if (pos->wh_bindex == btgt && ++num > limit)
+ return 1;
+ return 0;
+}
+int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
+{
+ struct hlist_head *head;
-+ struct au_vdir_wh *tpos;
-+ struct hlist_node *pos;
++ struct au_vdir_wh *pos;
+ struct au_vdir_destr *str;
+
+ head = au_name_hash(whlist, name, nlen);
-+ hlist_for_each_entry(tpos, pos, head, wh_hash) {
-+ str = &tpos->wh_str;
++ hlist_for_each_entry(pos, head, wh_hash) {
++ str = &pos->wh_str;
+ AuDbg("%.*s\n", str->len, str->name);
+ if (au_nhash_test_name(str, name, nlen))
+ return 1;
+static int test_known(struct au_nhash *delist, char *name, int nlen)
+{
+ struct hlist_head *head;
-+ struct au_vdir_dehstr *tpos;
-+ struct hlist_node *pos;
++ struct au_vdir_dehstr *pos;
+ struct au_vdir_destr *str;
+
+ head = au_name_hash(delist, name, nlen);
-+ hlist_for_each_entry(tpos, pos, head, hash) {
-+ str = tpos->str;
++ hlist_for_each_entry(pos, head, hash) {
++ str = pos->str;
+ AuDbg("%.*s\n", str->len, str->name);
+ if (au_nhash_test_name(str, name, nlen))
+ return 1;
+#endif
+
+struct fillvdir_arg {
++ struct dir_context ctx;
+ struct file *file;
+ struct au_vdir *vdir;
+ struct au_nhash delist;
+ int err;
+};
+
-+static int fillvdir(void *__arg, const char *__name, int nlen,
++static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
+ loff_t offset __maybe_unused, u64 h_ino,
+ unsigned int d_type)
+{
-+ struct fillvdir_arg *arg = __arg;
++ struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
+ char *name = (void *)__name;
+ struct super_block *sb;
+ ino_t ino;
+ int err;
+ unsigned int nh, u;
+ struct hlist_head *head;
-+ struct au_vdir_wh *tpos;
-+ struct hlist_node *pos, *n;
++ struct au_vdir_wh *pos;
++ struct hlist_node *n;
+ char *p, *o;
+ struct au_vdir_destr *destr;
+
+ AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
+
+ err = -ENOMEM;
-+ o = p = __getname_gfp(GFP_NOFS);
++ o = p = (void *)__get_free_page(GFP_NOFS);
+ if (unlikely(!p))
+ goto out;
+
+ p += AUFS_WH_PFX_LEN;
+ for (u = 0; u < nh; u++) {
+ head = whlist->nh_head + u;
-+ hlist_for_each_entry_safe(tpos, pos, n, head, wh_hash) {
-+ destr = &tpos->wh_str;
++ hlist_for_each_entry_safe(pos, n, head, wh_hash) {
++ destr = &pos->wh_str;
+ memcpy(p, destr->name, destr->len);
+ err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
-+ tpos->wh_ino, tpos->wh_type, delist);
++ pos->wh_ino, pos->wh_type, delist);
+ if (unlikely(err))
+ break;
+ }
+ }
+
-+ __putname(o);
++ free_page((unsigned long)o);
+
+out:
+ AuTraceErr(err);
+ arg->err = 0;
+ au_fclr_fillvdir(arg->flags, CALLED);
+ /* smp_mb(); */
-+ err = vfsub_readdir(hf, fillvdir, arg);
++ err = vfsub_iterate_dir(hf, &arg->ctx);
+ if (err >= 0)
+ err = arg->err;
+ } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
++
++ /*
++ * dir_relax() may be good for concurrency, but aufs should not
++ * use it since it will cause a lockdep problem.
++ */
+ }
+
+ if (!err && shwh)
+ int err;
+ unsigned long expire;
+ unsigned char do_read;
-+ struct fillvdir_arg arg;
++ struct fillvdir_arg arg = {
++ .ctx = {
++ .actor = au_diractor(fillvdir)
++ }
++ };
+ struct inode *inode;
+ struct au_vdir *vdir, *allocated;
+
+ err = 0;
-+ inode = file->f_dentry->d_inode;
++ inode = file_inode(file);
+ IMustLock(inode);
+ SiMustAnyLock(inode->i_sb);
+
+ arg.vdir = vdir;
+ err = au_do_read_vdir(&arg);
+ if (!err) {
-+ /* file->f_pos = 0; */
++ /* file->f_pos = 0; */ /* todo: ctx->pos? */
+ vdir->vd_version = inode->i_version;
+ vdir->vd_last.ul = 0;
+ vdir->vd_last.p.deblk = vdir->vd_deblk[0];
+ struct inode *inode;
+ struct au_vdir *vdir_cache, *allocated;
+
++ /* test file->f_pos here instead of ctx->pos */
+ err = read_vdir(file, !file->f_pos);
+ if (unlikely(err))
+ goto out;
+ goto out;
+ allocated = vdir_cache;
+ } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
++ /* test file->f_pos here instead of ctx->pos */
+ err = reinit_vdir(vdir_cache);
+ if (unlikely(err))
+ goto out;
+ } else
+ return 0; /* success */
+
-+ inode = file->f_dentry->d_inode;
++ inode = file_inode(file);
+ err = copy_vdir(vdir_cache, au_ivdir(inode));
+ if (!err) {
+ file->f_version = inode->i_version;
+}
+
+/* returns true or false */
-+static int seek_vdir(struct file *file)
++static int seek_vdir(struct file *file, struct dir_context *ctx)
+{
+ int valid;
+ unsigned int deblk_sz;
+ vdir_cache = au_fvdir_cache(file);
+ offset = calc_offset(vdir_cache);
+ AuDbg("offset %lld\n", offset);
-+ if (file->f_pos == offset)
++ if (ctx->pos == offset)
+ goto out;
+
+ vdir_cache->vd_last.ul = 0;
+ vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
-+ if (!file->f_pos)
++ if (!ctx->pos)
+ goto out;
+
+ valid = 0;
+ deblk_sz = vdir_cache->vd_deblk_sz;
-+ ul = div64_u64(file->f_pos, deblk_sz);
++ ul = div64_u64(ctx->pos, deblk_sz);
+ AuDbg("ul %lu\n", ul);
+ if (ul >= vdir_cache->vd_nblk)
+ goto out;
+ deblk_end.deblk = p.deblk + deblk_sz;
+ offset = ul;
+ offset *= deblk_sz;
-+ while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
++ while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
+ unsigned int l;
+
+ l = calc_size(p.de->de_str.len);
+ return valid;
+}
+
-+int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
++int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
+{
-+ int err;
+ unsigned int l, deblk_sz;
+ union au_vdir_deblk_p deblk_end;
+ struct au_vdir *vdir_cache;
+ struct au_vdir_de *de;
+
+ vdir_cache = au_fvdir_cache(file);
-+ if (!seek_vdir(file))
++ if (!seek_vdir(file, ctx))
+ return 0;
+
+ deblk_sz = vdir_cache->vd_deblk_sz;
+ while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
+ de = vdir_cache->vd_last.p.de;
+ AuDbg("%.*s, off%lld, i%lu, dt%d\n",
-+ de->de_str.len, de->de_str.name, file->f_pos,
++ de->de_str.len, de->de_str.name, ctx->pos,
+ (unsigned long)de->de_ino, de->de_type);
-+ err = filldir(dirent, de->de_str.name, de->de_str.len,
-+ file->f_pos, de->de_ino, de->de_type);
-+ if (unlikely(err)) {
-+ AuTraceErr(err);
++ if (unlikely(!dir_emit(ctx, de->de_str.name,
++ de->de_str.len, de->de_ino,
++ de->de_type))) {
+ /* todo: ignore the error caused by udba? */
+ /* return err; */
+ return 0;
+
+ l = calc_size(de->de_str.len);
+ vdir_cache->vd_last.p.deblk += l;
-+ file->f_pos += l;
++ ctx->pos += l;
+ }
+ if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
+ vdir_cache->vd_last.ul++;
+ vdir_cache->vd_last.p.deblk
+ = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
-+ file->f_pos = deblk_sz * vdir_cache->vd_last.ul;
++ ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
+ continue;
+ }
+ break;
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,836 @@
++++ linux/fs/aufs/vfsub.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,782 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * sub-routines for VFS
+ */
+
-+#include <linux/file.h>
+#include <linux/ima.h>
+#include <linux/namei.h>
+#include <linux/security.h>
+#include <linux/splice.h>
-+#include <linux/uaccess.h>
+#include "aufs.h"
+
+int vfsub_update_h_iattr(struct path *h_path, int *did)
+ h_sb = h_path->dentry->d_sb;
+ *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
+ if (*did)
-+ err = vfs_getattr(h_path->mnt, h_path->dentry, &st);
++ err = vfs_getattr(h_path, &st);
+
+ return err;
+}
+{
+ struct file *file;
+
-+ path_get(path);
-+ file = dentry_open(path->dentry, path->mnt,
-+ flags /* | __FMODE_NONOTIFY */,
++ file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
+ current_cred());
+ if (!IS_ERR_OR_NULL(file)
+ && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
+ return path.dentry;
+}
+
-+struct dentry *vfsub_lookup_hash(struct nameidata *nd)
-+{
-+ struct path path = {
-+ .mnt = nd->path.mnt
-+ };
-+
-+ IMustLock(nd->path.dentry->d_inode);
-+
-+ path.dentry = lookup_hash(nd);
-+ if (IS_ERR(path.dentry))
-+ goto out;
-+ if (path.dentry->d_inode)
-+ vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
-+
-+out:
-+ AuTraceErrPtr(path.dentry);
-+ return path.dentry;
-+}
-+
-+/*
-+ * this is "VFS:__lookup_one_len()" which was removed and merged into
-+ * VFS:lookup_one_len() by the commit.
-+ * 6a96ba5 2011-03-14 kill __lookup_one_len()
-+ * this function should always be equivalent to the corresponding part in
-+ * VFS:lookup_one_len().
-+ */
-+int vfsub_name_hash(const char *name, struct qstr *this, int len)
++void vfsub_call_lkup_one(void *args)
+{
-+ unsigned long hash;
-+ unsigned int c;
-+
-+ this->name = name;
-+ this->len = len;
-+ if (!len)
-+ return -EACCES;
-+
-+ hash = init_name_hash();
-+ while (len--) {
-+ c = *(const unsigned char *)name++;
-+ if (c == '/' || c == '\0')
-+ return -EACCES;
-+ hash = partial_name_hash(c, hash);
-+ }
-+ this->hash = end_name_hash(hash);
-+ return 0;
++ struct vfsub_lkup_one_args *a = args;
++ *a->errp = vfsub_lkup_one(a->name, a->parent);
+}
+
+/* ---------------------------------------------------------------------- */
+
+/* ---------------------------------------------------------------------- */
+
-+int vfsub_create(struct inode *dir, struct path *path, int mode)
++int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
+{
+ int err;
+ struct dentry *d;
+ if (unlikely(err))
+ goto out;
+
-+ if (au_test_fs_null_nd(dir->i_sb))
-+ err = vfs_create(dir, path->dentry, mode, NULL);
-+ else {
-+ struct nameidata h_nd;
-+
-+ memset(&h_nd, 0, sizeof(h_nd));
-+ h_nd.flags = LOOKUP_CREATE;
-+ h_nd.intent.open.flags = O_CREAT
-+ | vfsub_fmode_to_uint(FMODE_READ);
-+ h_nd.intent.open.create_mode = mode;
-+ h_nd.path.dentry = path->dentry->d_parent;
-+ h_nd.path.mnt = path->mnt;
-+ path_get(&h_nd.path);
-+ err = vfs_create(dir, path->dentry, mode, &h_nd);
-+ path_put(&h_nd.path);
-+ }
-+
++ err = vfs_create(dir, path->dentry, mode, want_excl);
+ if (!err) {
+ struct path tmp = *path;
+ int did;
+ return -EMLINK;
+}
+
-+int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
++int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
++ struct inode **delegated_inode)
+{
+ int err;
+ struct dentry *d;
+ if (unlikely(err))
+ return err;
+
++ /* we don't call may_linkat() */
+ d = path->dentry;
+ path->dentry = d->d_parent;
+ err = security_path_link(src_dentry, path, d);
+ goto out;
+
+ lockdep_off();
-+ err = vfs_link(src_dentry, dir, path->dentry);
++ err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
+ lockdep_on();
+ if (!err) {
+ struct path tmp = *path;
+}
+
+int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
-+ struct inode *dir, struct path *path)
++ struct inode *dir, struct path *path,
++ struct inode **delegated_inode)
+{
+ int err;
+ struct path tmp = {
+ goto out;
+
+ lockdep_off();
-+ err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
++ err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
++ delegated_inode);
+ lockdep_on();
+ if (!err) {
+ int did;
+
+/* ---------------------------------------------------------------------- */
+
++/* todo: support mmap_sem? */
+ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
+ loff_t *ppos)
+{
+ int err;
+
+ err = 0;
-+ if (file->f_op && file->f_op->flush) {
++ if (file->f_op->flush) {
+ if (!au_test_nfs(file->f_dentry->d_sb))
+ err = file->f_op->flush(file, id);
+ else {
+ return err;
+}
+
-+int vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
++int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
+{
+ int err;
+
++ AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
++
+ lockdep_off();
-+ err = vfs_readdir(file, filldir, arg);
++ err = iterate_dir(file, ctx);
+ lockdep_on();
+ if (err >= 0)
+ vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
+{
+ int err;
+ struct inode *h_inode;
++ struct super_block *h_sb;
+
-+ h_inode = h_path->dentry->d_inode;
+ if (!h_file) {
-+ err = mnt_want_write(h_path->mnt);
-+ if (err)
-+ goto out;
-+ err = inode_permission(h_inode, MAY_WRITE);
-+ if (err)
-+ goto out_mnt;
-+ err = get_write_access(h_inode);
-+ if (err)
-+ goto out_mnt;
-+ err = break_lease(h_inode, O_WRONLY);
-+ if (err)
-+ goto out_inode;
++ err = vfsub_truncate(h_path, length);
++ goto out;
+ }
+
++ h_inode = h_path->dentry->d_inode;
++ h_sb = h_inode->i_sb;
++ lockdep_off();
++ sb_start_write(h_sb);
++ lockdep_on();
+ err = locks_verify_truncate(h_inode, h_file, length);
+ if (!err)
+ err = security_path_truncate(h_path);
+ err = do_truncate(h_path->dentry, length, attr, h_file);
+ lockdep_on();
+ }
++ lockdep_off();
++ sb_end_write(h_sb);
++ lockdep_on();
+
-+out_inode:
-+ if (!h_file)
-+ put_write_access(h_inode);
-+out_mnt:
-+ if (!h_file)
-+ mnt_drop_write(h_path->mnt);
+out:
+ return err;
+}
+ int *errp;
+ struct path *path;
+ struct iattr *ia;
++ struct inode **delegated_inode;
+};
+
+static void call_notify_change(void *args)
+
+ *a->errp = -EPERM;
+ if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
-+ *a->errp = notify_change(a->path->dentry, a->ia);
++ *a->errp = notify_change(a->path->dentry, a->ia,
++ a->delegated_inode);
+ if (!*a->errp)
+ vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
+ }
+ AuTraceErr(*a->errp);
+}
+
-+int vfsub_notify_change(struct path *path, struct iattr *ia)
++int vfsub_notify_change(struct path *path, struct iattr *ia,
++ struct inode **delegated_inode)
+{
+ int err;
+ struct notify_change_args args = {
-+ .errp = &err,
-+ .path = path,
-+ .ia = ia
++ .errp = &err,
++ .path = path,
++ .ia = ia,
++ .delegated_inode = delegated_inode
+ };
+
+ call_notify_change(&args);
+ return err;
+}
+
-+int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
++int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
++ struct inode **delegated_inode)
+{
+ int err, wkq_err;
+ struct notify_change_args args = {
-+ .errp = &err,
-+ .path = path,
-+ .ia = ia
++ .errp = &err,
++ .path = path,
++ .ia = ia,
++ .delegated_inode = delegated_inode
+ };
+
+ wkq_err = au_wkq_wait(call_notify_change, &args);
+ int *errp;
+ struct inode *dir;
+ struct path *path;
++ struct inode **delegated_inode;
+};
+
+static void call_unlink(void *args)
+ struct dentry *d = a->path->dentry;
+ struct inode *h_inode;
+ const int stop_sillyrename = (au_test_nfs(d->d_sb)
-+ && d->d_count == 1);
++ && d_count(d) == 1);
+
+ IMustLock(a->dir);
+
+ ihold(h_inode);
+
+ lockdep_off();
-+ *a->errp = vfs_unlink(a->dir, d);
++ *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
+ lockdep_on();
+ if (!*a->errp) {
+ struct path tmp = {
+ * @dir: must be locked.
+ * @dentry: target dentry.
+ */
-+int vfsub_unlink(struct inode *dir, struct path *path, int force)
++int vfsub_unlink(struct inode *dir, struct path *path,
++ struct inode **delegated_inode, int force)
+{
+ int err;
+ struct unlink_args args = {
-+ .errp = &err,
-+ .dir = dir,
-+ .path = path
++ .errp = &err,
++ .dir = dir,
++ .path = path,
++ .delegated_inode = delegated_inode
+ };
+
+ if (!force)
+}
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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,232 @@
++++ linux/fs/aufs/vfsub.h 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,282 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#include <linux/fs.h>
+#include <linux/lglock.h>
++#include <linux/mount.h>
+#include "debug.h"
+
+/* copied from linux/fs/internal.h */
+/* todo: BAD approach!! */
-+DECLARE_BRLOCK(vfsmount_lock);
-+extern void file_sb_list_del(struct file *f);
++extern void __mnt_drop_write(struct vfsmount *);
+extern spinlock_t inode_sb_list_lock;
+
-+/* copied from linux/fs/file_table.c */
-+DECLARE_LGLOCK(files_lglock);
-+#ifdef CONFIG_SMP
-+/*
-+ * These macros iterate all files on all CPUs for a given superblock.
-+ * files_lglock must be held globally.
-+ */
-+#define do_file_list_for_each_entry(__sb, __file) \
-+{ \
-+ int i; \
-+ for_each_possible_cpu(i) { \
-+ struct list_head *list; \
-+ list = per_cpu_ptr((__sb)->s_files, i); \
-+ list_for_each_entry((__file), list, f_u.fu_list)
-+
-+#define while_file_list_for_each_entry \
-+ } \
-+}
-+
-+#else
-+
-+#define do_file_list_for_each_entry(__sb, __file) \
-+{ \
-+ struct list_head *list; \
-+ list = &(sb)->s_files; \
-+ list_for_each_entry((__file), list, f_u.fu_list)
-+
-+#define while_file_list_for_each_entry \
-+}
-+#endif
-+
+/* ---------------------------------------------------------------------- */
+
+/* lock subclass for lower inode */
+/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
+/* reduce? gave up. */
+enum {
-+ AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
++ AuLsc_I_Begin = I_MUTEX_NONDIR2, /* 4 */
+ AuLsc_I_PARENT, /* lower inode, parent first */
+ AuLsc_I_PARENT2, /* copyup dirs */
+ AuLsc_I_PARENT3, /* copyup wh */
+ clear_nlink(inode);
+}
+
++static inline int vfsub_native_ro(struct inode *inode)
++{
++ return (inode->i_sb->s_flags & MS_RDONLY)
++ || IS_RDONLY(inode)
++ /* || IS_APPEND(inode) */
++ || IS_IMMUTABLE(inode);
++}
++
+/* ---------------------------------------------------------------------- */
+
+int vfsub_update_h_iattr(struct path *h_path, int *did);
+struct file *vfsub_dentry_open(struct path *path, int flags);
+struct file *vfsub_filp_open(const char *path, int oflags, int mode);
+int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
++
+struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
+ int len);
-+struct dentry *vfsub_lookup_hash(struct nameidata *nd);
-+int vfsub_name_hash(const char *name, struct qstr *this, int len);
++
++struct vfsub_lkup_one_args {
++ struct dentry **errp;
++ struct qstr *name;
++ struct dentry *parent;
++};
++
++static inline struct dentry *vfsub_lkup_one(struct qstr *name,
++ struct dentry *parent)
++{
++ return vfsub_lookup_one_len(name->name, parent, name->len);
++}
++
++void vfsub_call_lkup_one(void *args);
++
++/* ---------------------------------------------------------------------- */
++
++static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
++{
++ int err;
++ lockdep_off();
++ err = mnt_want_write(mnt);
++ lockdep_on();
++ return err;
++}
++
++static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
++{
++ lockdep_off();
++ mnt_drop_write(mnt);
++ lockdep_on();
++}
++
++static inline void vfsub_mnt_drop_write_file(struct file *file)
++{
++ lockdep_off();
++ mnt_drop_write_file(file);
++ lockdep_on();
++}
+
+/* ---------------------------------------------------------------------- */
+
+void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
+ struct dentry *d2, struct au_hinode *hdir2);
+
-+int vfsub_create(struct inode *dir, struct path *path, int mode);
++int vfsub_create(struct inode *dir, struct path *path, int mode,
++ bool want_excl);
+int vfsub_symlink(struct inode *dir, struct path *path,
+ const char *symname);
+int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
+int vfsub_link(struct dentry *src_dentry, struct inode *dir,
-+ struct path *path);
++ struct path *path, struct inode **delegated_inode);
+int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
-+ struct inode *hdir, struct path *path);
++ struct inode *hdir, struct path *path,
++ struct inode **delegated_inode);
+int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
+int vfsub_rmdir(struct inode *dir, struct path *path);
+
+ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
+ loff_t *ppos);
+int vfsub_flush(struct file *file, fl_owner_t id);
-+int vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
++int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
++
++/* just for type-check */
++static inline filldir_t au_diractor(int (*func)(struct dir_context *,
++ const char *, int, loff_t, u64,
++ unsigned))
++{
++ return (filldir_t)func;
++}
++
++
++static inline loff_t vfsub_f_size_read(struct file *file)
++{
++ return i_size_read(file_inode(file));
++}
+
+static inline unsigned int vfsub_file_flags(struct file *file)
+{
+ .dentry = h_dentry,
+ .mnt = h_mnt
+ };
-+ touch_atime(h_mnt, h_dentry);
++ touch_atime(&h_path);
+ vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
+}
+
++static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
++ int flags)
++{
++ return update_time(h_inode, ts, flags);
++ /* no vfsub_update_h_iattr() since we don't have struct path */
++}
++
+long vfsub_splice_to(struct file *in, loff_t *ppos,
+ struct pipe_inode_info *pipe, size_t len,
+ unsigned int flags);
+long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
+ loff_t *ppos, size_t len, unsigned int flags);
++
++static inline long vfsub_truncate(struct path *path, loff_t length)
++{
++ long err;
++ lockdep_off();
++ err = vfs_truncate(path, length);
++ lockdep_on();
++ return err;
++}
++
+int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
+ struct file *h_file);
+int vfsub_fsync(struct file *file, struct path *path, int datasync);
+
+int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
+int vfsub_sio_rmdir(struct inode *dir, struct path *path);
-+int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
-+int vfsub_notify_change(struct path *path, struct iattr *ia);
-+int vfsub_unlink(struct inode *dir, struct path *path, int force);
++int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
++ struct inode **delegated_inode);
++int vfsub_notify_change(struct path *path, struct iattr *ia,
++ struct inode **delegated_inode);
++int vfsub_unlink(struct inode *dir, struct path *path,
++ struct inode **delegated_inode, int force);
+
+#endif /* __KERNEL__ */
+#endif /* __AUFS_VFSUB_H__ */
diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
--- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wbr_policy.c 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,700 @@
++++ linux/fs/aufs/wbr_policy.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,756 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ ia.ia_uid = h_isrc->i_uid;
+ ia.ia_gid = h_isrc->i_gid;
+ sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
-+ au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc);
-+ err = vfsub_sio_notify_change(h_path, &ia);
++ au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
++ /* no delegation since it is just created */
++ err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
+
+ /* is this nfs only? */
+ if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
+ ia.ia_valid = ATTR_FORCE | ATTR_MODE;
+ ia.ia_mode = h_isrc->i_mode;
-+ err = vfsub_sio_notify_change(h_path, &ia);
++ err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
+ }
+
+ return err;
+#define au_fclr_cpdown(flags, name) \
+ do { (flags) &= ~AuCpdown_##name; } while (0)
+
-+struct au_cpdown_dir_args {
-+ struct dentry *parent;
-+ unsigned int flags;
-+};
-+
+static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
-+ struct au_cpdown_dir_args *a)
++ unsigned int *flags)
+{
+ int err;
+ struct dentry *opq_dentry;
+ if (IS_ERR(opq_dentry))
+ goto out;
+ dput(opq_dentry);
-+ au_fset_cpdown(a->flags, DIROPQ);
++ au_fset_cpdown(*flags, DIROPQ);
+
+out:
+ return err;
+
+ err = 0;
+ if (h_path.dentry->d_inode) {
-+ h_path.mnt = br->br_mnt;
++ h_path.mnt = au_br_mnt(br);
+ err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
+ dentry);
+ }
+}
+
+static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
++ struct au_pin *pin,
+ struct dentry *h_parent, void *arg)
+{
+ int err, rerr;
+ struct path h_path;
+ struct dentry *parent;
+ struct inode *h_dir, *h_inode, *inode, *dir;
-+ struct au_cpdown_dir_args *args = arg;
++ unsigned int *flags = arg;
+
+ bstart = au_dbstart(dentry);
+ /* dentry is di-locked */
+ AuDebugOn(h_dir != au_h_iptr(dir, bdst));
+ IMustLock(h_dir);
+
-+ err = au_lkup_neg(dentry, bdst);
++ err = au_lkup_neg(dentry, bdst, /*wh*/0);
+ if (unlikely(err < 0))
+ goto out;
+ h_path.dentry = au_h_dptr(dentry, bdst);
+ S_IRWXU | S_IRUGO | S_IXUGO);
+ if (unlikely(err))
+ goto out_put;
-+ au_fset_cpdown(args->flags, MADE_DIR);
++ au_fset_cpdown(*flags, MADE_DIR);
+
+ bopq = au_dbdiropq(dentry);
-+ au_fclr_cpdown(args->flags, WHED);
-+ au_fclr_cpdown(args->flags, DIROPQ);
++ au_fclr_cpdown(*flags, WHED);
++ au_fclr_cpdown(*flags, DIROPQ);
+ if (au_dbwh(dentry) == bdst)
-+ au_fset_cpdown(args->flags, WHED);
-+ if (!au_ftest_cpdown(args->flags, PARENT_OPQ) && bopq <= bdst)
-+ au_fset_cpdown(args->flags, PARENT_OPQ);
++ au_fset_cpdown(*flags, WHED);
++ if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
++ au_fset_cpdown(*flags, PARENT_OPQ);
+ h_inode = h_path.dentry->d_inode;
+ mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
-+ if (au_ftest_cpdown(args->flags, WHED)) {
-+ err = au_cpdown_dir_opq(dentry, bdst, args);
++ if (au_ftest_cpdown(*flags, WHED)) {
++ err = au_cpdown_dir_opq(dentry, bdst, flags);
+ if (unlikely(err)) {
+ mutex_unlock(&h_inode->i_mutex);
+ goto out_dir;
+ if (unlikely(err))
+ goto out_opq;
+
-+ if (au_ftest_cpdown(args->flags, WHED)) {
++ if (au_ftest_cpdown(*flags, WHED)) {
+ err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
+ if (unlikely(err))
+ goto out_opq;
+
+ /* revert */
+out_opq:
-+ if (au_ftest_cpdown(args->flags, DIROPQ)) {
++ if (au_ftest_cpdown(*flags, DIROPQ)) {
+ mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
+ rerr = au_diropq_remove(dentry, bdst);
+ mutex_unlock(&h_inode->i_mutex);
+ if (unlikely(rerr)) {
-+ AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
-+ AuDLNPair(dentry), bdst, rerr);
++ AuIOErr("failed removing diropq for %pd b%d (%d)\n",
++ dentry, bdst, rerr);
+ err = -EIO;
+ goto out;
+ }
+ }
+out_dir:
-+ if (au_ftest_cpdown(args->flags, MADE_DIR)) {
++ if (au_ftest_cpdown(*flags, MADE_DIR)) {
+ rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
+ if (unlikely(rerr)) {
-+ AuIOErr("failed removing %.*s b%d (%d)\n",
-+ AuDLNPair(dentry), bdst, rerr);
++ AuIOErr("failed removing %pd b%d (%d)\n",
++ dentry, bdst, rerr);
+ err = -EIO;
+ }
+ }
+int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
+{
+ int err;
-+ struct au_cpdown_dir_args args = {
-+ .parent = dget_parent(dentry),
-+ .flags = 0
-+ };
++ unsigned int flags;
+
-+ err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &args);
-+ dput(args.parent);
++ flags = 0;
++ err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
+
+ return err;
+}
+
+/* policies for create */
+
-+static int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
++int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
+{
+ int err, i, j, ndentry;
+ aufs_bindex_t bopq;
+}
+
+/* top down parent */
-+static int au_wbr_create_tdp(struct dentry *dentry, int isdir __maybe_unused)
++static int au_wbr_create_tdp(struct dentry *dentry,
++ unsigned int flags __maybe_unused)
+{
+ int err;
+ aufs_bindex_t bstart, bindex;
+ return err;
+}
+
-+static int au_wbr_create_rr(struct dentry *dentry, int isdir)
++static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
+{
+ int err, nbr;
+ unsigned int u;
+ bend = au_sbend(sb);
+ nbr = bend + 1;
+ for (bindex = 0; bindex <= bend; bindex++) {
-+ if (!isdir) {
++ if (!au_ftest_wbr(flags, DIR)) {
+ err = atomic_dec_return(next) + 1;
+ /* modulo for 0 is meaningless */
+ if (unlikely(!err))
+/* ---------------------------------------------------------------------- */
+
+/* most free space */
-+static void au_mfs(struct dentry *dentry)
++static void au_mfs(struct dentry *dentry, struct dentry *parent)
+{
+ struct super_block *sb;
+ struct au_branch *br;
+ struct au_wbr_mfs *mfs;
++ struct dentry *h_parent;
+ aufs_bindex_t bindex, bend;
+ int err;
+ unsigned long long b, bavail;
+ MtxMustLock(&mfs->mfs_lock);
+ mfs->mfs_bindex = -EROFS;
+ mfs->mfsrr_bytes = 0;
-+ bend = au_sbend(sb);
-+ for (bindex = 0; bindex <= bend; bindex++) {
++ if (!parent) {
++ bindex = 0;
++ bend = au_sbend(sb);
++ } else {
++ bindex = au_dbstart(parent);
++ bend = au_dbtaildir(parent);
++ }
++
++ for (; bindex <= bend; bindex++) {
++ if (parent) {
++ h_parent = au_h_dptr(parent, bindex);
++ if (!h_parent || !h_parent->d_inode)
++ continue;
++ }
+ br = au_sbr(sb, bindex);
+ if (au_br_rdonly(br))
+ continue;
+
+ /* sb->s_root for NFS is unreliable */
-+ h_path.mnt = br->br_mnt;
++ h_path.mnt = au_br_mnt(br);
+ h_path.dentry = h_path.mnt->mnt_root;
+ err = vfs_statfs(&h_path, st);
+ if (unlikely(err)) {
+ kfree(st);
+}
+
-+static int au_wbr_create_mfs(struct dentry *dentry, int isdir __maybe_unused)
++static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
+{
+ int err;
++ struct dentry *parent;
+ struct super_block *sb;
+ struct au_wbr_mfs *mfs;
+
+ goto out;
+
+ sb = dentry->d_sb;
++ parent = NULL;
++ if (au_ftest_wbr(flags, PARENT))
++ parent = dget_parent(dentry);
+ mfs = &au_sbi(sb)->si_wbr_mfs;
+ mutex_lock(&mfs->mfs_lock);
+ if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
+ || mfs->mfs_bindex < 0
+ || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
-+ au_mfs(dentry);
++ au_mfs(dentry, parent);
+ mutex_unlock(&mfs->mfs_lock);
+ err = mfs->mfs_bindex;
++ dput(parent);
+
+ if (err >= 0)
+ err = au_wbr_nonopq(dentry, err);
+/* ---------------------------------------------------------------------- */
+
+/* most free space and then round robin */
-+static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
++static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
+{
+ int err;
+ struct au_wbr_mfs *mfs;
+
-+ err = au_wbr_create_mfs(dentry, isdir);
++ err = au_wbr_create_mfs(dentry, flags);
+ if (err >= 0) {
+ mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
+ mutex_lock(&mfs->mfs_lock);
+ if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
-+ err = au_wbr_create_rr(dentry, isdir);
++ err = au_wbr_create_rr(dentry, flags);
+ mutex_unlock(&mfs->mfs_lock);
+ }
+
+/* ---------------------------------------------------------------------- */
+
+/* top down parent and most free space */
-+static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
++static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
+{
+ int err, e2;
+ unsigned long long b;
+ struct dentry *parent, *h_parent;
+ struct au_branch *br;
+
-+ err = au_wbr_create_tdp(dentry, isdir);
++ err = au_wbr_create_tdp(dentry, flags);
+ if (unlikely(err < 0))
+ goto out;
+ parent = dget_parent(dentry);
+ if (bstart == bend)
+ goto out_parent; /* success */
+
-+ e2 = au_wbr_create_mfs(dentry, isdir);
++ e2 = au_wbr_create_mfs(dentry, flags);
+ if (e2 < 0)
+ goto out_parent; /* success */
+
+
+/* ---------------------------------------------------------------------- */
+
++/*
++ * - top down parent
++ * - most free space with parent
++ * - most free space round-robin regardless parent
++ */
++static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
++{
++ int err;
++ unsigned long long watermark;
++ struct super_block *sb;
++ struct au_branch *br;
++ struct au_wbr_mfs *mfs;
++
++ err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
++ if (unlikely(err < 0))
++ goto out;
++
++ sb = dentry->d_sb;
++ br = au_sbr(sb, err);
++ mfs = &au_sbi(sb)->si_wbr_mfs;
++ mutex_lock(&mfs->mfs_lock);
++ watermark = mfs->mfsrr_watermark;
++ mutex_unlock(&mfs->mfs_lock);
++ if (br->br_wbr->wbr_bytes < watermark)
++ /* regardless the parent dir */
++ err = au_wbr_create_mfsrr(dentry, flags);
++
++out:
++ AuDbg("b%d\n", err);
++ return err;
++}
++
++/* ---------------------------------------------------------------------- */
++
+/* policies for copyup */
+
+/* top down parent */
+static int au_wbr_copyup_tdp(struct dentry *dentry)
+{
-+ return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
++ return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
+}
+
+/* bottom up parent */
+ .create = au_wbr_create_pmfs,
+ .init = au_wbr_create_init_mfs,
+ .fin = au_wbr_create_fin_mfs
++ },
++ [AuWbrCreate_PMFSRR] = {
++ .create = au_wbr_create_pmfsrr,
++ .init = au_wbr_create_init_mfsrr,
++ .fin = au_wbr_create_fin_mfs
++ },
++ [AuWbrCreate_PMFSRRV] = {
++ .create = au_wbr_create_pmfsrr,
++ .init = au_wbr_create_init_mfsrr,
++ .fin = au_wbr_create_fin_mfs
+ }
+};
diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
--- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/whout.c 2011-10-24 20:51:51.583800333 +0200
-@@ -0,0 +1,1050 @@
++++ linux/fs/aufs/whout.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,1052 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * whiteout for logical deletion and opaque directory
+ */
+
-+#include <linux/fs.h>
+#include "aufs.h"
+
+#define WH_MASK S_IRUGO
+ * If a directory contains this file, then it is opaque. We start with the
+ * .wh. flag so that it is blocked by lookup.
+ */
-+static struct qstr diropq_name = {
-+ .name = AUFS_WH_DIROPQ,
-+ .len = sizeof(AUFS_WH_DIROPQ) - 1
-+};
++static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
++ sizeof(AUFS_WH_DIROPQ) - 1);
+
+/*
+ * generate whiteout name, which is NOT terminated by NULL.
+ struct dentry *wh_dentry;
+
+ if (!try_sio)
-+ wh_dentry = au_lkup_one(wh_name, h_parent, br, /*nd*/NULL);
++ wh_dentry = vfsub_lkup_one(wh_name, h_parent);
+ else
+ wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
+ err = PTR_ERR(wh_dentry);
+ goto out_wh; /* success */
+
+ err = -EIO;
-+ AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
-+ AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
++ AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
++ wh_dentry, wh_dentry->d_inode->i_mode);
+
+out_wh:
+ dput(wh_dentry);
+ goto out_name;
+ dput(dentry);
+ }
-+ /* pr_warning("could not get random name\n"); */
++ /* pr_warn("could not get random name\n"); */
+ dentry = ERR_PTR(-EEXIST);
+ AuDbg("%.*s\n", AuLNPair(&qs));
+ BUG();
+{
+ int err;
+ struct path h_path = {
-+ .mnt = br->br_mnt
++ .mnt = au_br_mnt(br)
+ };
-+ struct inode *h_dir;
++ struct inode *h_dir, *delegated;
+ struct dentry *h_parent;
+
+ h_parent = h_dentry->d_parent; /* dir inode is locked */
+ goto out;
+
+ /* under the same dir, no need to lock_rename() */
-+ err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
++ delegated = NULL;
++ err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
+ AuTraceErr(err);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal rename\n");
++ iput(delegated);
++ }
+ dput(h_path.dentry);
+
+out:
+
+static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
+{
-+ int force;
++ int err, force;
++ struct inode *delegated;
+
+ /*
+ * forces superio when the dir has a sticky bit.
+ * this may be a violation of unix fs semantics.
+ */
+ force = (h_dir->i_mode & S_ISVTX)
-+ && h_path->dentry->d_inode->i_uid != current_fsuid();
-+ return vfsub_unlink(h_dir, h_path, force);
++ && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
++ delegated = NULL;
++ err = vfsub_unlink(h_dir, h_path, &delegated, force);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
++ }
++ return err;
+}
+
+int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
+{
+ int err;
+ struct path h_path = {
-+ .mnt = br->br_mnt
++ .mnt = au_br_mnt(br)
+ };
+
+ err = 0;
-+ h_path.dentry = au_lkup_one(wh, h_parent, br, /*nd*/NULL);
++ h_path.dentry = vfsub_lkup_one(wh, h_parent);
+ if (IS_ERR(h_path.dentry))
+ err = PTR_ERR(h_path.dentry);
+ else {
+ const int isdir)
+{
+ int err;
++ struct inode *delegated;
+
+ if (!whpath->dentry->d_inode)
+ return;
+
-+ err = mnt_want_write(whpath->mnt);
-+ if (!err) {
-+ if (isdir)
-+ err = vfsub_rmdir(h_dir, whpath);
-+ else
-+ err = vfsub_unlink(h_dir, whpath, /*force*/0);
-+ mnt_drop_write(whpath->mnt);
++ if (isdir)
++ err = vfsub_rmdir(h_dir, whpath);
++ else {
++ delegated = NULL;
++ err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
++ }
+ }
+ if (unlikely(err))
-+ pr_warning("failed removing %.*s (%d), ignored.\n",
-+ AuDLNPair(whpath->dentry), err);
++ pr_warn("failed removing %pd (%d), ignored.\n",
++ whpath->dentry, err);
+}
+
+static int test_linkable(struct dentry *h_root)
+ if (h_dir->i_op->link)
+ return 0;
+
-+ pr_err("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
-+ AuDLNPair(h_root), au_sbtype(h_root->d_sb));
++ pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
++ h_root, au_sbtype(h_root->d_sb));
+ return -ENOSYS;
+}
+
+
+ if (au_test_nfs(path->dentry->d_sb))
+ mode |= S_IXUGO;
-+ err = mnt_want_write(path->mnt);
-+ if (!err) {
-+ err = vfsub_mkdir(h_dir, path, mode);
-+ mnt_drop_write(path->mnt);
-+ }
++ err = vfsub_mkdir(h_dir, path, mode);
+ } else if (S_ISDIR(path->dentry->d_inode->i_mode))
+ err = 0;
+ else
-+ pr_err("unknown %.*s exists\n", AuDLNPair(path->dentry));
++ pr_err("unknown %pd exists\n", path->dentry);
+
+ return err;
+}
+ err = -EEXIST;
+ h_dir = h_root->d_inode;
+ if (!base[AuBrWh_BASE].dentry->d_inode) {
-+ err = mnt_want_write(h_path->mnt);
-+ if (!err) {
-+ h_path->dentry = base[AuBrWh_BASE].dentry;
-+ err = vfsub_create(h_dir, h_path, WH_MASK);
-+ mnt_drop_write(h_path->mnt);
-+ }
++ h_path->dentry = base[AuBrWh_BASE].dentry;
++ err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
+ } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
+ err = 0;
+ else
-+ pr_err("unknown %.*s/%.*s exists\n",
-+ AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
++ pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
+ if (unlikely(err))
+ goto out;
+
+/*
+ * initialize the whiteout base file/dir for @br.
+ */
-+int au_wh_init(struct dentry *h_root, struct au_branch *br,
-+ struct super_block *sb)
++int au_wh_init(struct au_branch *br, struct super_block *sb)
+{
+ int err, i;
+ const unsigned char do_plink
+ = !!au_opt_test(au_mntflags(sb), PLINK);
-+ struct path path = {
-+ .mnt = br->br_mnt
-+ };
+ struct inode *h_dir;
++ struct path path = br->br_path;
++ struct dentry *h_root = path.dentry;
+ struct au_wbr *wbr = br->br_wbr;
+ static const struct qstr base_name[] = {
-+ [AuBrWh_BASE] = {
-+ .name = AUFS_BASE_NAME,
-+ .len = sizeof(AUFS_BASE_NAME) - 1
-+ },
-+ [AuBrWh_PLINK] = {
-+ .name = AUFS_PLINKDIR_NAME,
-+ .len = sizeof(AUFS_PLINKDIR_NAME) - 1
-+ },
-+ [AuBrWh_ORPH] = {
-+ .name = AUFS_ORPHDIR_NAME,
-+ .len = sizeof(AUFS_ORPHDIR_NAME) - 1
-+ }
++ [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
++ sizeof(AUFS_BASE_NAME) - 1),
++ [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
++ sizeof(AUFS_PLINKDIR_NAME) - 1),
++ [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
++ sizeof(AUFS_ORPHDIR_NAME) - 1)
+ };
+ struct au_wh_base base[] = {
+ [AuBrWh_BASE] = {
+ goto out; /* success */
+
+out_err:
-+ pr_err("an error(%d) on the writable branch %.*s(%s)\n",
-+ err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
++ pr_err("an error(%d) on the writable branch %pd(%s)\n",
++ err, h_root, au_sbtype(h_root->d_sb));
+out:
+ for (i = 0; i < AuBrWh_Last; i++)
+ dput(base[i].dentry);
+ struct path h_path;
+ struct reinit_br_wh *a = arg;
+ struct au_wbr *wbr;
-+ struct inode *dir;
++ struct inode *dir, *delegated;
+ struct dentry *h_root;
+ struct au_hinode *hdir;
+
+ dir = a->sb->s_root->d_inode;
+ hdir = au_hi(dir, bindex);
+ h_root = au_h_dptr(a->sb->s_root, bindex);
++ AuDebugOn(h_root != au_br_dentry(a->br));
+
+ au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
+ wbr_wh_write_lock(wbr);
+ err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
+ h_root, a->br);
+ if (!err) {
-+ err = mnt_want_write(a->br->br_mnt);
-+ if (!err) {
-+ h_path.dentry = wbr->wbr_whbase;
-+ h_path.mnt = a->br->br_mnt;
-+ err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
-+ mnt_drop_write(a->br->br_mnt);
++ h_path.dentry = wbr->wbr_whbase;
++ h_path.mnt = au_br_mnt(a->br);
++ delegated = NULL;
++ err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
++ /*force*/0);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
+ }
+ } else {
-+ pr_warning("%.*s is moved, ignored\n",
-+ AuDLNPair(wbr->wbr_whbase));
++ pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
+ err = 0;
+ }
+ dput(wbr->wbr_whbase);
+ wbr->wbr_whbase = NULL;
+ if (!err)
-+ err = au_wh_init(h_root, a->br, a->sb);
++ err = au_wh_init(a->br, a->sb);
+ wbr_wh_write_unlock(wbr);
+ au_hn_imtx_unlock(hdir);
+ di_read_unlock(a->sb->s_root, AuLock_IR);
+ struct au_branch *br;
+ struct au_wbr *wbr;
+ struct dentry *h_parent;
-+ struct inode *h_dir;
++ struct inode *h_dir, *delegated;
+
+ h_parent = wh->d_parent; /* dir inode is locked */
+ h_dir = h_parent->d_inode;
+ IMustLock(h_dir);
+
+ br = au_sbr(sb, bindex);
-+ h_path.mnt = br->br_mnt;
++ h_path.mnt = au_br_mnt(br);
+ wbr = br->br_wbr;
+ wbr_wh_read_lock(wbr);
+ if (wbr->wbr_whbase) {
-+ err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
++ delegated = NULL;
++ err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal link\n");
++ iput(delegated);
++ }
+ if (!err || err != -EMLINK)
+ goto out;
+
+ }
+
+ /* return this error in this context */
-+ err = vfsub_create(h_dir, &h_path, WH_MASK);
++ err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
+
+out:
+ wbr_wh_read_unlock(wbr);
+ sb = dentry->d_sb;
+ br = au_sbr(sb, bindex);
+ h_dentry = au_h_dptr(dentry, bindex);
-+ opq_dentry = au_lkup_one(&diropq_name, h_dentry, br, /*nd*/NULL);
++ opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
+ if (IS_ERR(opq_dentry))
+ goto out;
+
+ } else {
+ struct path tmp = {
+ .dentry = opq_dentry,
-+ .mnt = br->br_mnt
++ .mnt = au_br_mnt(br)
+ };
+ err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
+ if (!err)
+ err = au_wh_name_alloc(&wh_name, base_name);
+ wh_dentry = ERR_PTR(err);
+ if (!err) {
-+ wh_dentry = au_lkup_one(&wh_name, h_parent, br, /*nd*/NULL);
++ wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
+ kfree(wh_name.name);
+ }
+ return wh_dentry;
+ struct qstr wh_name;
+ char *p;
+ struct hlist_head *head;
-+ struct au_vdir_wh *tpos;
-+ struct hlist_node *pos;
++ struct au_vdir_wh *pos;
+ struct au_vdir_destr *str;
+
+ err = -ENOMEM;
-+ p = __getname_gfp(GFP_NOFS);
++ p = (void *)__get_free_page(GFP_NOFS);
+ wh_name.name = p;
+ if (unlikely(!wh_name.name))
+ goto out;
+ n = whlist->nh_num;
+ head = whlist->nh_head;
+ for (ul = 0; !err && ul < n; ul++, head++) {
-+ hlist_for_each_entry(tpos, pos, head, wh_hash) {
-+ if (tpos->wh_bindex != bindex)
++ hlist_for_each_entry(pos, head, wh_hash) {
++ if (pos->wh_bindex != bindex)
+ continue;
+
-+ str = &tpos->wh_str;
++ str = &pos->wh_str;
+ if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
+ memcpy(p, str->name, str->len);
+ wh_name.len = AUFS_WH_PFX_LEN + str->len;
+ break;
+ }
+ }
-+ __putname(wh_name.name);
++ free_page((unsigned long)wh_name.name);
+
+out:
+ return err;
+
+ if (!err) {
+ h_tmp.dentry = wh_dentry;
-+ h_tmp.mnt = br->br_mnt;
++ h_tmp.mnt = au_br_mnt(br);
+ err = vfsub_rmdir(h_dir, &h_tmp);
+ }
+
+ return 0; /* success */
+ }
+
-+ pr_warning("failed removing %.*s(%d), ignored\n",
-+ AuDLNPair(wh_dentry), err);
++ pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
+ return err;
+}
+
+ h_parent = dget_parent(a->wh_dentry);
+ h_dir = h_parent->d_inode;
+ hdir = au_hi(a->dir, bindex);
++ err = vfsub_mnt_want_write(au_br_mnt(a->br));
++ if (unlikely(err))
++ goto out_mnt;
+ au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
+ err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
+ a->br);
-+ if (!err) {
-+ err = mnt_want_write(a->br->br_mnt);
-+ if (!err) {
-+ err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry,
-+ &a->whlist);
-+ mnt_drop_write(a->br->br_mnt);
-+ }
-+ }
++ if (!err)
++ err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
+ au_hn_imtx_unlock(hdir);
++ vfsub_mnt_drop_write(au_br_mnt(a->br));
++
++out_mnt:
+ dput(h_parent);
+ ii_write_unlock(a->dir);
-+
+out:
+ /* mutex_unlock(&a->dir->i_mutex); */
+ au_whtmp_rmdir_free(a);
+ args->wh_dentry = dget(wh_dentry);
+ wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
+ if (unlikely(wkq_err)) {
-+ pr_warning("rmdir error %.*s (%d), ignored\n",
-+ AuDLNPair(wh_dentry), wkq_err);
++ pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
+ au_whtmp_rmdir_free(args);
+ }
+}
diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
--- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/whout.h 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,89 @@
++++ linux/fs/aufs/whout.h 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,86 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/aufs_type.h>
+#include "dir.h"
+
+/* whout.c */
+int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
+int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
+ struct dentry *dentry);
-+int au_wh_init(struct dentry *h_parent, struct au_branch *br,
-+ struct super_block *sb);
++int au_wh_init(struct au_branch *br, struct super_block *sb);
+
+/* diropq flags */
+#define AuDiropq_CREATE 1
+#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 2011-08-24 13:30:24.734646739 +0200
-@@ -0,0 +1,244 @@
++++ linux/fs/aufs/wkq.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,212 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+#include <linux/module.h>
+#include "aufs.h"
+
-+/* internal workqueue named AUFS_WKQ_NAME and AUFS_WKQ_PRE_NAME */
-+enum {
-+ AuWkq_INORMAL,
-+ AuWkq_IPRE
-+};
++/* internal workqueue named AUFS_WKQ_NAME */
+
-+static struct {
-+ char *name;
-+ struct workqueue_struct *wkq;
-+} au_wkq[] = {
-+ [AuWkq_INORMAL] = {
-+ .name = AUFS_WKQ_NAME
-+ },
-+ [AuWkq_IPRE] = {
-+ .name = AUFS_WKQ_PRE_NAME
-+ }
-+};
++static struct workqueue_struct *au_wkq;
+
+struct au_wkinfo {
+ struct work_struct wk;
+{
+ struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
+
-+ AuDebugOn(current_fsuid());
++ AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
+ AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
+
+ wkinfo->func(wkinfo->args);
+ complete(wkinfo->comp);
+ else {
+ kobject_put(wkinfo->kobj);
-+ module_put(THIS_MODULE);
++ module_put(THIS_MODULE); /* todo: ?? */
+ kfree(wkinfo);
+ }
+}
+/*
+ * Since struct completion is large, try allocating it dynamically.
+ */
-+#if defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS)
++#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
+#define AuWkqCompDeclare(name) struct completion *comp = NULL
+
+static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
+
+static void au_wkq_run(struct au_wkinfo *wkinfo)
+{
-+ struct workqueue_struct *wkq;
-+
+ if (au_ftest_wkq(wkinfo->flags, NEST)) {
+ if (au_wkq_test()) {
+ AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
+
+ if (au_ftest_wkq(wkinfo->flags, WAIT)) {
+ INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
-+ wkq = au_wkq[AuWkq_INORMAL].wkq;
-+ if (au_ftest_wkq(wkinfo->flags, PRE))
-+ wkq = au_wkq[AuWkq_IPRE].wkq;
-+ queue_work(wkq, &wkinfo->wk);
++ queue_work(au_wkq, &wkinfo->wk);
+ } else {
+ INIT_WORK(&wkinfo->wk, wkq_func);
+ schedule_work(&wkinfo->wk);
+ wkinfo->args = args;
+ wkinfo->comp = NULL;
+ kobject_get(wkinfo->kobj);
-+ __module_get(THIS_MODULE);
++ __module_get(THIS_MODULE); /* todo: ?? */
+
+ au_wkq_run(wkinfo);
+ } else {
+
+void au_wkq_fin(void)
+{
-+ int i;
-+
-+ for (i = 0; i < ARRAY_SIZE(au_wkq); i++)
-+ if (au_wkq[i].wkq)
-+ destroy_workqueue(au_wkq[i].wkq);
++ destroy_workqueue(au_wkq);
+}
+
+int __init au_wkq_init(void)
+{
-+ int err, i;
++ int err;
+
+ err = 0;
-+ for (i = 0; !err && i < ARRAY_SIZE(au_wkq); i++) {
-+ BUILD_BUG_ON(!WQ_RESCUER);
-+ au_wkq[i].wkq = alloc_workqueue(au_wkq[i].name, !WQ_RESCUER,
-+ WQ_DFL_ACTIVE);
-+ if (IS_ERR(au_wkq[i].wkq))
-+ err = PTR_ERR(au_wkq[i].wkq);
-+ else if (!au_wkq[i].wkq)
-+ err = -ENOMEM;
-+ if (unlikely(err))
-+ au_wkq[i].wkq = NULL;
-+ }
-+ if (unlikely(err))
-+ au_wkq_fin();
++ au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
++ if (IS_ERR(au_wkq))
++ err = PTR_ERR(au_wkq);
++ else if (!au_wkq)
++ err = -ENOMEM;
+
+ return err;
+}
diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
--- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/fs/aufs/wkq.h 2011-08-24 13:30:24.737979976 +0200
-@@ -0,0 +1,101 @@
++++ linux/fs/aufs/wkq.h 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,91 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+
+#ifdef __KERNEL__
+
-+#include <linux/sched.h>
-+#include <linux/wait.h>
-+#include <linux/aufs_type.h>
-+
+struct super_block;
+
+/* ---------------------------------------------------------------------- */
+
+/* wkq flags */
+#define AuWkq_WAIT 1
-+#define AuWkq_PRE (1 << 1)
-+#ifdef CONFIG_AUFS_HNOTIFY
-+#define AuWkq_NEST (1 << 2)
-+#else
-+#define AuWkq_NEST 0
-+#endif
++#define AuWkq_NEST (1 << 1)
+#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
+#define au_fset_wkq(flags, name) \
+ do { (flags) |= AuWkq_##name; } while (0)
+#define au_fclr_wkq(flags, name) \
+ do { (flags) &= ~AuWkq_##name; } while (0)
+
++#ifndef CONFIG_AUFS_HNOTIFY
++#undef AuWkq_NEST
++#define AuWkq_NEST 0
++#endif
++
+/* wkq.c */
+int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
+int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
+ return current->flags & PF_WQ_WORKER;
+}
+
-+static inline int au_wkq_wait_pre(au_wkq_func_t func, void *args)
-+{
-+ return au_wkq_do_wait(AuWkq_WAIT | AuWkq_PRE, func, args);
-+}
-+
+static inline int au_wkq_wait(au_wkq_func_t func, void *args)
+{
+ return au_wkq_do_wait(AuWkq_WAIT, func, args);
+#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 2011-08-24 13:30:24.737979976 +0200
-@@ -0,0 +1,1265 @@
++++ linux/fs/aufs/xino.c 2014-01-30 21:10:02.860815399 +0100
+@@ -0,0 +1,1314 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * external inode number translation table and bitmap
+ */
+
-+#include <linux/file.h>
+#include <linux/seq_file.h>
-+#include <linux/uaccess.h>
++#include <linux/statfs.h>
+#include "aufs.h"
+
++/* todo: unnecessary to support mmap_sem since kernel-space? */
+ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
+ loff_t *pos)
+{
+{
+ struct file *file;
+ struct dentry *base, *parent;
-+ struct inode *dir;
++ struct inode *dir, *delegated;
+ struct qstr *name;
+ struct path path;
+ int err;
+ path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
+ if (IS_ERR(path.dentry)) {
+ file = (void *)path.dentry;
-+ pr_err("%.*s lookup err %ld\n",
-+ AuLNPair(name), PTR_ERR(path.dentry));
++ pr_err("%pd lookup err %ld\n",
++ base, PTR_ERR(path.dentry));
+ goto out;
+ }
+
+ err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
+ if (unlikely(err)) {
+ file = ERR_PTR(err);
-+ pr_err("%.*s create err %d\n", AuLNPair(name), err);
++ pr_err("%pd create err %d\n", base, err);
+ goto out_dput;
+ }
+
-+ path.mnt = base_file->f_vfsmnt;
++ path.mnt = base_file->f_path.mnt;
+ file = vfsub_dentry_open(&path,
+ O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
+ /* | __FMODE_NONOTIFY */);
+ if (IS_ERR(file)) {
-+ pr_err("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
++ pr_err("%pd open err %ld\n", base, PTR_ERR(file));
+ goto out_dput;
+ }
+
-+ err = vfsub_unlink(dir, &file->f_path, /*force*/0);
++ delegated = NULL;
++ err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
++ if (unlikely(err == -EWOULDBLOCK)) {
++ pr_warn("cannot retry for NFSv4 delegation"
++ " for an internal unlink\n");
++ iput(delegated);
++ }
+ if (unlikely(err)) {
-+ pr_err("%.*s unlink err %d\n", AuLNPair(name), err);
++ pr_err("%pd unlink err %d\n", base, err);
+ goto out_fput;
+ }
+
+ if (copy_src) {
+ /* no one can touch copy_src xino */
-+ err = au_copy_file(file, copy_src,
-+ i_size_read(copy_src->f_dentry->d_inode));
++ err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
+ if (unlikely(err)) {
-+ pr_err("%.*s copy err %d\n", AuLNPair(name), err);
++ pr_err("%pd copy err %d\n", base, err);
+ goto out_fput;
+ }
+ }
+int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
+{
+ int err;
++ unsigned long jiffy;
++ blkcnt_t blocks;
+ aufs_bindex_t bi, bend;
++ struct kstatfs *st;
+ struct au_branch *br;
+ struct file *new_xino, *file;
+ struct super_block *h_sb;
+ struct au_xino_lock_dir ldir;
+
++ err = -ENOMEM;
++ st = kzalloc(sizeof(*st), GFP_NOFS);
++ if (unlikely(!st))
++ goto out;
++
+ err = -EINVAL;
+ bend = au_sbend(sb);
+ if (unlikely(bindex < 0 || bend < bindex))
-+ goto out;
++ goto out_st;
+ br = au_sbr(sb, bindex);
+ file = br->br_xino.xi_file;
+ if (!file)
-+ goto out;
++ goto out_st;
++
++ err = vfs_statfs(&file->f_path, st);
++ if (unlikely(err))
++ AuErr1("statfs err %d, ignored\n", err);
++ jiffy = jiffies;
++ blocks = file_inode(file)->i_blocks;
++ pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
++ bindex, (u64)blocks, st->f_bfree, st->f_blocks);
+
+ au_xino_lock_dir(sb, file, &ldir);
+ /* mnt_want_write() is unnecessary here */
+ new_xino = au_xino_create2(file, file);
+ au_xino_unlock_dir(&ldir);
+ err = PTR_ERR(new_xino);
-+ if (IS_ERR(new_xino))
-+ goto out;
++ if (IS_ERR(new_xino)) {
++ pr_err("err %d, ignored\n", err);
++ goto out_st;
++ }
+ err = 0;
+ fput(file);
+ br->br_xino.xi_file = new_xino;
+
-+ h_sb = br->br_mnt->mnt_sb;
++ h_sb = au_br_sb(br);
+ for (bi = 0; bi <= bend; bi++) {
+ if (unlikely(bi == bindex))
+ continue;
+ br = au_sbr(sb, bi);
-+ if (br->br_mnt->mnt_sb != h_sb)
++ if (au_br_sb(br) != h_sb)
+ continue;
+
+ fput(br->br_xino.xi_file);
+ get_file(new_xino);
+ }
+
++ err = vfs_statfs(&new_xino->f_path, st);
++ if (!err) {
++ pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
++ bindex, (u64)file_inode(new_xino)->i_blocks,
++ st->f_bfree, st->f_blocks);
++ if (file_inode(new_xino)->i_blocks < blocks)
++ au_sbi(sb)->si_xino_jiffy = jiffy;
++ } else
++ AuErr1("statfs err %d, ignored\n", err);
++
++out_st:
++ kfree(st);
+out:
+ return err;
+}
+ ii_read_lock_parent(dir);
+ bindex = au_br_index(sb, br->br_id);
+ err = au_xino_trunc(sb, bindex);
-+ if (!err
-+ && br->br_xino.xi_file->f_dentry->d_inode->i_blocks
-+ >= br->br_xino_upper)
-+ br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
-+
+ ii_read_unlock(dir);
+ if (unlikely(err))
-+ pr_warning("err b%d, (%d)\n", bindex, err);
++ pr_warn("err b%d, (%d)\n", bindex, err);
+ atomic_dec(&br->br_xino_running);
+ atomic_dec(&br->br_count);
+ si_write_unlock(sb);
+ kfree(args);
+}
+
++static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
++{
++ int err;
++ struct kstatfs st;
++ struct au_sbinfo *sbinfo;
++
++ /* todo: si_xino_expire and the ratio should be customizable */
++ sbinfo = au_sbi(sb);
++ if (time_before(jiffies,
++ sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
++ return 0;
++
++ /* truncation border */
++ err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
++ if (unlikely(err)) {
++ AuErr1("statfs err %d, ignored\n", err);
++ return 0;
++ }
++ if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
++ return 0;
++
++ return 1;
++}
++
+static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
+{
+ struct xino_do_trunc_args *args;
+ int wkq_err;
+
-+ if (br->br_xino.xi_file->f_dentry->d_inode->i_blocks
-+ < br->br_xino_upper)
++ if (!xino_trunc_test(sb, br))
+ return;
+
+ if (atomic_inc_return(&br->br_xino_running) > 1)
+ h_ino, ino);
+ if (!err) {
+ if (au_opt_test(mnt_flags, TRUNC_XINO)
-+ && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
++ && au_test_fs_trunc_xino(au_br_sb(br)))
+ xino_try_trunc(sb, br);
+ return 0; /* success */
+ }
+
+ pos = pindex;
+ pos *= PAGE_SIZE;
-+ if (i_size_read(xib->f_dentry->d_inode) >= pos + PAGE_SIZE)
++ if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
+ sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
+ else {
+ memset(p, 0, PAGE_SIZE);
+ err = au_xino_do_write(xwrite, br->br_xino.xi_file,
+ h_inode->i_ino, /*ino*/0);
+ if (!err && try_trunc
-+ && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
++ && au_test_fs_trunc_xino(au_br_sb(br)))
+ xino_try_trunc(sb, br);
+ }
+}
+ }
+
+ file = sbinfo->si_xib;
-+ pend = i_size_read(file->f_dentry->d_inode) / PAGE_SIZE;
++ pend = vfsub_f_size_read(file) / PAGE_SIZE;
+ for (ul = pindex + 1; ul <= pend; ul++) {
+ err = xib_pindex(sb, ul);
+ if (unlikely(err))
+ pos *= sizeof(*ino);
+
+ file = au_sbr(sb, bindex)->br_xino.xi_file;
-+ if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*ino))
++ if (vfsub_f_size_read(file) < pos + sizeof(*ino))
+ return 0; /* no ino */
+
+ sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
+ h_dir = h_parent->d_inode;
+ mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
+ /* mnt_want_write() is unnecessary here */
-+ err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
++ /* no delegation since it is just created */
++ err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
+ mutex_unlock(&h_dir->i_mutex);
+ dput(h_parent);
+ if (unlikely(err)) {
+ shared_br = NULL;
+ bend = au_sbend(sb);
+ if (do_test) {
-+ tgt_sb = br->br_mnt->mnt_sb;
++ tgt_sb = au_br_sb(br);
+ for (bindex = 0; bindex <= bend; bindex++) {
+ b = au_sbr(sb, bindex);
-+ if (tgt_sb == b->br_mnt->mnt_sb) {
++ if (tgt_sb == au_br_sb(b)) {
+ shared_br = b;
+ break;
+ }
+ MtxMustLock(&sbinfo->si_xib_mtx);
+ p = sbinfo->si_xib_buf;
+ func = sbinfo->si_xread;
-+ pend = i_size_read(file->f_dentry->d_inode);
++ pend = vfsub_f_size_read(file);
+ pos = 0;
+ while (pos < pend) {
+ sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
+ goto out;
+
+ file = sbinfo->si_xib;
-+ if (i_size_read(file->f_dentry->d_inode) <= PAGE_SIZE)
++ if (vfsub_f_size_read(file) <= PAGE_SIZE)
+ goto out;
+
+ au_xino_lock_dir(sb, file, &ldir);
+{
+ const struct file_operations *fop = h_file->f_op;
+
-+ if (fop) {
-+ if (fop->read)
-+ return fop->read;
-+ if (fop->aio_read)
-+ return do_sync_read;
-+ }
++ if (fop->read)
++ return fop->read;
++ if (fop->aio_read)
++ return do_sync_read;
+ return ERR_PTR(-ENOSYS);
+}
+
+{
+ const struct file_operations *fop = h_file->f_op;
+
-+ if (fop) {
-+ if (fop->write)
-+ return fop->write;
-+ if (fop->aio_write)
-+ return do_sync_write;
-+ }
++ if (fop->write)
++ return fop->write;
++ if (fop->aio_write)
++ return do_sync_write;
+ return ERR_PTR(-ENOSYS);
+}
+
+
+ sbinfo->si_xib_last_pindex = 0;
+ sbinfo->si_xib_next_bit = 0;
-+ if (i_size_read(file->f_dentry->d_inode) < PAGE_SIZE) {
++ if (vfsub_f_size_read(file) < PAGE_SIZE) {
+ pos = 0;
+ err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
+ PAGE_SIZE, &pos);
+ for (bindex = 0; bindex <= bend; bindex++) {
+ br = au_sbr(sb, bindex);
+ if (au_br_writable(br->br_perm)
-+ && !au_test_fs_bad_xino(br->br_mnt->mnt_sb)) {
++ && !au_test_fs_bad_xino(au_br_sb(br))) {
+ bwr = bindex;
+ break;
+ }
+
+ if (bwr >= 0) {
+ file = ERR_PTR(-ENOMEM);
-+ page = __getname_gfp(GFP_NOFS);
++ page = (void *)__get_free_page(GFP_NOFS);
+ if (unlikely(!page))
+ goto out;
-+ path.mnt = br->br_mnt;
++ path.mnt = au_br_mnt(br);
+ path.dentry = au_h_dptr(sb->s_root, bwr);
+ p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
+ file = (void *)p;
+ if (!IS_ERR(file))
+ au_xino_brid_set(sb, br->br_id);
+ }
-+ __putname(page);
++ free_page((unsigned long)page);
+ } else {
+ file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
+ if (IS_ERR(file))
+out:
+ return err;
+}
-diff -urN /usr/share/empty/include/linux/aufs_type.h linux/include/linux/aufs_type.h
---- /usr/share/empty/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux/include/linux/aufs_type.h 2011-10-24 20:52:23.677857076 +0200
-@@ -0,0 +1,220 @@
+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-03-13 19:59:53.391752805 +0100
+@@ -0,0 +1,281 @@
+/*
-+ * Copyright (C) 2005-2011 Junjiro R. Okajima
++ * 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __AUFS_TYPE_H__
+#define __AUFS_TYPE_H__
+
-+#include <linux/ioctl.h>
-+#include <linux/kernel.h>
++#define AUFS_NAME "aufs"
++
++#ifdef __KERNEL__
++/*
++ * define it before including all other headers.
++ * sched.h may use pr_* macros before defining "current", so define the
++ * no-current version first, and re-define later.
++ */
++#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
++#include <linux/sched.h>
++#undef pr_fmt
++#define pr_fmt(fmt) \
++ AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
++ (int)sizeof(current->comm), current->comm, current->pid
++#else
++#include <stdint.h>
++#include <sys/types.h>
++#endif /* __KERNEL__ */
++
+#include <linux/limits.h>
-+#include <linux/types.h>
+
-+#define AUFS_VERSION "3.x-rcN-20111024"
++#define AUFS_VERSION "3.13-20140303"
+
+/* todo? move this to linux-2.6.19/include/magic.h */
+#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
+/* ---------------------------------------------------------------------- */
+
+#ifdef CONFIG_AUFS_BRANCH_MAX_127
-+typedef __s8 aufs_bindex_t;
++typedef int8_t aufs_bindex_t;
+#define AUFS_BRANCH_MAX 127
+#else
-+typedef __s16 aufs_bindex_t;
++typedef int16_t aufs_bindex_t;
+#ifdef CONFIG_AUFS_BRANCH_MAX_511
+#define AUFS_BRANCH_MAX 511
+#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
+
+/* ---------------------------------------------------------------------- */
+
-+#define AUFS_NAME "aufs"
+#define AUFS_FSTYPE AUFS_NAME
+
+#define AUFS_ROOT_INO 2
+#define AUFS_WH_PFX ".wh."
+#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
+#define AUFS_WH_TMP_LEN 4
-+/* a limit for rmdir/rename a dir */
++/* a limit for rmdir/rename a dir and copyup */
+#define AUFS_MAX_NAMELEN (NAME_MAX \
+ - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
+ - 1 /* dot */\
+ - AUFS_WH_TMP_LEN) /* hex */
+#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
+#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
-+#define AUFS_XINO_TRUNC_INIT 64 /* blocks */
-+#define AUFS_XINO_TRUNC_STEP 4 /* blocks */
++#define AUFS_XINO_DEF_SEC 30 /* seconds */
++#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
+#define AUFS_DIRWH_DEF 3
+#define AUFS_RDCACHE_DEF 10 /* seconds */
+#define AUFS_RDCACHE_MAX 3600 /* seconds */
+#define AUFS_RDBLK_DEF 512 /* bytes */
+#define AUFS_RDHASH_DEF 32
+#define AUFS_WKQ_NAME AUFS_NAME "d"
-+#define AUFS_WKQ_PRE_NAME AUFS_WKQ_NAME "_pre"
+#define AUFS_MFS_DEF_SEC 30 /* seconds */
+#define AUFS_MFS_MAX_SEC 3600 /* seconds */
-+#define AUFS_PLINK_WARN 100 /* number of plinks */
++#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
+
+/* pseudo-link maintenace under /proc */
+#define AUFS_PLINK_MAINT_NAME "plink_maint"
+#define AUFS_BRPERM_RR "rr"
+#define AUFS_BRRATTR_WH "wh"
+#define AUFS_BRWATTR_NLWH "nolwh"
++#define AUFS_BRATTR_UNPIN "unpin"
+
+/* ---------------------------------------------------------------------- */
+
+ AuCtl_WBR_FD,
+
+ /* busy inode */
-+ AuCtl_IBUSY
++ AuCtl_IBUSY,
++
++ /* move-down */
++ AuCtl_MVDOWN
+};
+
+/* borrowed from linux/include/linux/kernel.h */
+#endif
+
+struct au_rdu_cookie {
-+ __u64 h_pos;
-+ __s16 bindex;
-+ __u8 flags;
-+ __u8 pad;
-+ __u32 generation;
++ uint64_t h_pos;
++ int16_t bindex;
++ uint8_t flags;
++ uint8_t pad;
++ uint32_t generation;
+} __aligned(8);
+
+struct au_rdu_ent {
-+ __u64 ino;
-+ __s16 bindex;
-+ __u8 type;
-+ __u8 nlen;
-+ __u8 wh;
++ uint64_t ino;
++ int16_t bindex;
++ uint8_t type;
++ uint8_t nlen;
++ uint8_t wh;
+ char name[0];
+} __aligned(8);
+
+{
+ /* include the terminating NULL */
+ return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
-+ sizeof(__u64));
++ sizeof(uint64_t));
+}
+
+union au_rdu_ent_ul {
+ struct au_rdu_ent __user *e;
-+ __u64 ul;
++ uint64_t ul;
+};
+
+enum {
+struct aufs_rdu {
+ /* input */
+ union {
-+ __u64 sz; /* AuCtl_RDU */
-+ __u64 nent; /* AuCtl_RDU_INO */
++ uint64_t sz; /* AuCtl_RDU */
++ uint64_t nent; /* AuCtl_RDU_INO */
+ };
+ union au_rdu_ent_ul ent;
-+ __u16 verify[AufsCtlRduV_End];
++ uint16_t verify[AufsCtlRduV_End];
+
+ /* input/output */
-+ __u32 blk;
++ uint32_t blk;
+
+ /* output */
+ union au_rdu_ent_ul tail;
+ /* number of entries which were added in a single call */
-+ __u64 rent;
-+ __u8 full;
-+ __u8 shwh;
++ uint64_t rent;
++ uint8_t full;
++ uint8_t shwh;
+
+ struct au_rdu_cookie cookie;
+} __aligned(8);
+/* ---------------------------------------------------------------------- */
+
+struct aufs_wbr_fd {
-+ __u32 oflags;
-+ __s16 brid;
++ uint32_t oflags;
++ int16_t brid;
+} __aligned(8);
+
+/* ---------------------------------------------------------------------- */
+
+struct aufs_ibusy {
-+ __u64 ino, h_ino;
-+ __s16 bindex;
++ uint64_t ino, h_ino;
++ int16_t bindex;
++} __aligned(8);
++
++/* ---------------------------------------------------------------------- */
++
++/* error code for move-down */
++/* the actual message strings are implemented in aufs-util.git */
++enum {
++ EAU_MVDOWN_OPAQUE = 1,
++ EAU_MVDOWN_WHITEOUT,
++ EAU_MVDOWN_UPPER,
++ EAU_MVDOWN_BOTTOM,
++ EAU_MVDOWN_NOUPPER,
++ EAU_MVDOWN_NOLOWERBR,
++ EAU_Last
++};
++
++/* flags for move-down */
++#define AUFS_MVDOWN_DMSG 1
++#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
++#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
++#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
++#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
++#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
++#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
++#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
++#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
++/* will be added more */
++
++enum {
++ AUFS_MVDOWN_UPPER,
++ AUFS_MVDOWN_LOWER,
++ AUFS_MVDOWN_NARRAY
++};
++
++struct aufs_mvdown {
++ uint32_t flags;
++ struct {
++ int16_t bindex;
++ int16_t brid;
++ } a[AUFS_MVDOWN_NARRAY];
++ int8_t au_errno;
++ /* will be added more */
+} __aligned(8);
+
+/* ---------------------------------------------------------------------- */
+#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
+ struct aufs_wbr_fd)
+#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
++#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
++ struct aufs_mvdown)
+
+#endif /* __AUFS_TYPE_H__ */
+